⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vrml_tools.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *			GPAC - Multimedia Framework C SDK * *			Copyright (c) Jean Le Feuvre 2000-2005 *					All rights reserved * *  This file is part of GPAC / Scene Graph sub-project * *  GPAC is free software; you can redistribute it and/or modify *  it under the terms of the GNU Lesser General Public License as published by *  the Free Software Foundation; either version 2, or (at your option) *  any later version. *    *  GPAC is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Lesser General Public License for more details. *    *  You should have received a copy of the GNU Lesser General Public *  License along with this library; see the file COPYING.  If not, write to *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  * */#include <gpac/internal/scenegraph_dev.h>/*MPEG4 & X3D tags (for node tables & script handling)*/#include <gpac/nodes_mpeg4.h>#include <gpac/nodes_x3d.h>/*this is not a NodeReplace, thus only the given container is updated - pos is 0-based*/GF_Err gf_node_replace_child(GF_Node *node, GF_ChildNodeItem **container, s32 pos, GF_Node *newNode){	GF_ChildNodeItem *child, *prev;	u32 cur_pos = 0;	child = *container;	prev = NULL;	while (child->next) {		if ((pos<0) || (cur_pos!=(u32)pos)) {			prev = child;			child = child->next;			continue;		}		break;	}	gf_node_unregister(child->node, node);	if (newNode) {		child->node = newNode;	} else {		if (prev) prev->next = child->next;		else *container = child->next;		free(child);	}	return GF_OK;}void gf_sg_destroy_routes(GF_SceneGraph *sg){	while (gf_list_count(sg->routes_to_destroy) ) {		GF_Route *r = (GF_Route *)gf_list_get(sg->routes_to_destroy, 0);		gf_list_rem(sg->routes_to_destroy, 0);		gf_sg_route_unqueue(sg, r);		if (r->name) free(r->name);		free(r);	}}void gf_sg_route_queue(GF_SceneGraph *sg, GF_Route *r){	u32 now;	if (!sg) return;	/*get the top level scene (that's the only reliable one regarding simulatioin tick)*/	while (sg->parent_scene) sg = sg->parent_scene;	/*a single route may not be activated more than once in a simulation tick*/	now = 1 + sg->simulation_tick;	if (r->lastActivateTime >= now) return;	r->lastActivateTime = now;	gf_list_add(sg->routes_to_activate, r);}/*activate all routes in the order they where triggered*/GF_EXPORTvoid gf_sg_activate_routes(GF_SceneGraph *sg){	GF_Route *r;	GF_Node *targ;	if (!sg) return;	sg->simulation_tick++;	while (gf_list_count(sg->routes_to_activate)) {		r = (GF_Route *)gf_list_get(sg->routes_to_activate, 0);		gf_list_rem(sg->routes_to_activate, 0);		if (r) {			targ = r->ToNode;			if (gf_sg_route_activate(r)) {#ifdef GF_SELF_REPLACE_ENABLE				if (sg->graph_has_been_reset) {					sg->graph_has_been_reset = 0;					return;				}#endif				if (r->is_setup) gf_node_changed(targ, &r->ToField);			}		}	}	gf_sg_destroy_routes(sg);}void gf_sg_route_unqueue(GF_SceneGraph *sg, GF_Route *r){	/*get the top level scene*/	while (sg->parent_scene) sg = sg->parent_scene;	/*remove route from queue list*/	gf_list_del_item(sg->routes_to_activate, r);}static void Node_on_add_children(GF_Node *node){	GF_ChildNodeItem *list;	GF_FieldInfo field;	GF_VRMLParent *n = (GF_VRMLParent *)node;	if (n->children) {		list = n->children;		while (list->next) list = list->next;		list->next = n->addChildren;	} else {		n->children = n->addChildren;	}	n->addChildren = NULL;	/*signal children field is modified*/	field.name = "children";	field.eventType = GF_SG_EVENT_EXPOSED_FIELD;	field.fieldType = GF_SG_VRML_MFNODE;	field.NDTtype = 0;	field.fieldIndex = 2;	field.far_ptr = & n->children;	gf_node_changed(node, &field);}static void Node_on_remove_children(GF_Node *node){	GF_ChildNodeItem *list;	GF_FieldInfo field;	GF_VRMLParent *n = (GF_VRMLParent *)node;	if (!n->removeChildren) return;	list = n->removeChildren;	while (list) {		if (gf_node_list_del_child(& n->children, list->node)) {			gf_node_unregister(list->node, node);		}		list = list->next;	}	gf_node_unregister_children(node, n->removeChildren);	n->removeChildren = NULL;	/*signal children field is modified*/	field.name = "children";	field.eventType = GF_SG_EVENT_EXPOSED_FIELD;	field.fieldType = GF_SG_VRML_MFNODE;	field.NDTtype = 0;	field.fieldIndex = 2;	field.far_ptr = & n->children;	gf_node_changed(node, &field);}void gf_sg_vrml_parent_setup(GF_Node *pNode){	GF_VRMLParent *par = (GF_VRMLParent *)pNode;	par->children = NULL;	par->addChildren = NULL;	par->on_addChildren = Node_on_add_children;	par->removeChildren = NULL;	par->on_removeChildren = Node_on_remove_children;	pNode->sgprivate->flags |= GF_SG_CHILD_DIRTY;}void gf_sg_vrml_parent_destroy(GF_Node *pNode){	GF_VRMLParent *par = (GF_VRMLParent *)pNode;	gf_node_unregister_children(pNode, par->children);	gf_node_unregister_children(pNode, par->addChildren);	gf_node_unregister_children(pNode, par->removeChildren);}GF_Err gf_sg_delete_all_protos(GF_SceneGraph *scene){	if (!scene) return GF_BAD_PARAM;	while (gf_list_count(scene->protos)) {		GF_Proto *p = (GF_Proto *)gf_list_get(scene->protos, 0);		gf_sg_proto_del(p);	}	return GF_OK;}GF_EXPORTvoid gf_sg_set_proto_loader(GF_SceneGraph *scene, GF_SceneGraph *(*GetExternProtoLib)(void *SceneCallback, MFURL *lib_url)){	if (!scene) return;	scene->GetExternProtoLib = GetExternProtoLib;}u32 gf_sg_get_next_available_route_id(GF_SceneGraph *sg) {	u32 i, count;	u32 ID = 0;	if (!sg->max_defined_route_id) {		count = gf_list_count(sg->Routes);		/*routes are not sorted*/		for (i=0; i<count; i++) {			GF_Route *r = (GF_Route *)gf_list_get(sg->Routes, i);			if (ID<=r->ID) ID = r->ID;		}		return ID+1;	} else {		sg->max_defined_route_id++;		return sg->max_defined_route_id;	}}void gf_sg_set_max_defined_route_id(GF_SceneGraph *sg, u32 ID){	sg->max_defined_route_id = MAX(sg->max_defined_route_id, ID);}u32 gf_sg_get_next_available_proto_id(GF_SceneGraph *sg) {	u32 i, count;	u32 ID = 0;	count = gf_list_count(sg->protos);	/*protos are not sorted*/	for (i=0; i<count; i++) {		GF_Proto *p = (GF_Proto *)gf_list_get(sg->protos, i);		if (ID<=p->ID) ID = p->ID;	}	count = gf_list_count(sg->unregistered_protos);	for (i=0; i<count; i++) {		GF_Proto *p = (GF_Proto *)gf_list_get(sg->unregistered_protos, i);		if (ID<=p->ID) ID = p->ID;	}	return ID+1;}//adds a child in the children listGF_Err gf_node_insert_child(GF_Node *parent, GF_Node *new_child, s32 Position){	GF_ParentNode *node = (GF_ParentNode *) parent;	if (Position == -1) {		gf_node_list_add_child(& node->children, new_child);	} else {		gf_node_list_insert_child(& node->children, new_child, Position);	}	return GF_OK;}/*for V4Studio...*/GF_Err gf_node_remove_child(GF_Node *parent, GF_Node *toremove_child) {	if (!gf_node_list_del_child(& ((GF_ParentNode *) parent)->children, toremove_child)) return GF_BAD_PARAM;	/*V4Studio doesn't handle DEF/USE properly yet...*/	/*gf_node_unregister(toremove_child, parent);*/	return GF_OK;}void gf_sg_script_load(GF_Node *n){	if (n && n->sgprivate->scenegraph->script_load) n->sgprivate->scenegraph->script_load(n);}GF_Proto *gf_sg_find_proto(GF_SceneGraph *sg, u32 ProtoID, char *name){	GF_Proto *proto;	u32 i;	assert(sg);	/*browse all top-level */	i=0;	while ((proto = (GF_Proto *)gf_list_enum(sg->protos, &i))) {		/*first check on name if given, since parsers use this with ID=0*/		if (name) {			if (proto->Name && !stricmp(name, proto->Name)) return proto;		} else if (proto->ID == ProtoID) return proto;	}	/*browse all top-level unregistered in reverse order*/	for (i=gf_list_count(sg->unregistered_protos); i>0; i--) {		proto = (GF_Proto *)gf_list_get(sg->unregistered_protos, i-1);		if (name) {			if (proto->Name && !stricmp(name, proto->Name)) return proto;		} else if (proto->ID == ProtoID) return proto;	}	return NULL;}u32 gf_bifs_get_child_table(GF_Node *Node){	assert(Node);	return gf_sg_mpeg4_node_get_child_ndt(Node);}GF_Err gf_bifs_get_field_index(GF_Node *Node, u32 inField, u8 IndexMode, u32 *allField){	assert(Node);	switch (Node->sgprivate->tag) {	case TAG_ProtoNode:		return gf_sg_proto_get_field_ind_static(Node, inField, IndexMode, allField);	case TAG_MPEG4_Script: 	case TAG_X3D_Script: 		return gf_sg_script_get_field_index(Node, inField, IndexMode, allField);	default: 		return gf_sg_mpeg4_node_get_field_index(Node, inField, IndexMode, allField);	}}/* QUANTIZATION AND BIFS_Anim Info */GF_EXPORTBool gf_bifs_get_aq_info(GF_Node *Node, u32 FieldIndex, u8 *QType, u8 *AType, Fixed *b_min, Fixed *b_max, u32 *QT13_bits){	switch (Node->sgprivate->tag) {	case TAG_ProtoNode: return gf_sg_proto_get_aq_info(Node, FieldIndex, QType, AType, b_min, b_max, QT13_bits);	default: return gf_sg_mpeg4_node_get_aq_info(Node, FieldIndex, QType, AType, b_min, b_max, QT13_bits);	}}static SFBool *NewSFBool(){	SFBool *tmp = (SFBool *)malloc(sizeof(SFBool));	memset(tmp, 0, sizeof(SFBool));	return tmp;}static SFFloat *NewSFFloat(){	SFFloat *tmp = (SFFloat *)malloc(sizeof(SFFloat));	memset(tmp, 0, sizeof(SFFloat));	return tmp;}static SFDouble *NewSFDouble(){	SFDouble *tmp = (SFDouble *)malloc(sizeof(SFDouble));	memset(tmp, 0, sizeof(SFDouble));	return tmp;}static SFTime *NewSFTime(){	SFTime *tmp = (SFTime *)malloc(sizeof(SFTime));	memset(tmp, 0, sizeof(SFTime));	return tmp;}static SFInt32 *NewSFInt32(){	SFInt32 *tmp = (SFInt32 *)malloc(sizeof(SFInt32));	memset(tmp, 0, sizeof(SFInt32));	return tmp;}static SFString *NewSFString(){	SFString *tmp = (SFString *)malloc(sizeof(SFString));	memset(tmp, 0, sizeof(SFString));	return tmp;}static SFVec3f *NewSFVec3f(){	SFVec3f *tmp = (SFVec3f *)malloc(sizeof(SFVec3f));	memset(tmp, 0, sizeof(SFVec3f));	return tmp;}static SFVec3d *NewSFVec3d(){	SFVec3d *tmp = (SFVec3d *)malloc(sizeof(SFVec3d));	memset(tmp, 0, sizeof(SFVec3d));	return tmp;}static SFVec2f *NewSFVec2f(){	SFVec2f *tmp = (SFVec2f *)malloc(sizeof(SFVec2f));	memset(tmp, 0, sizeof(SFVec2f));	return tmp;}static SFVec2d *NewSFVec2d(){	SFVec2d *tmp = (SFVec2d *)malloc(sizeof(SFVec2d));	memset(tmp, 0, sizeof(SFVec2d));	return tmp;}static SFColor *NewSFColor(){	SFColor *tmp = (SFColor *)malloc(sizeof(SFColor));	memset(tmp, 0, sizeof(SFColor));	return tmp;}static SFColorRGBA *NewSFColorRGBA(){	SFColorRGBA *tmp = (SFColorRGBA *)malloc(sizeof(SFColorRGBA));	memset(tmp, 0, sizeof(SFColorRGBA));	return tmp;}static SFRotation *NewSFRotation(){	SFRotation *tmp = (SFRotation *)malloc(sizeof(SFRotation));	memset(tmp, 0, sizeof(SFRotation));	return tmp;}static SFImage *NewSFImage(){	SFImage *tmp = (SFImage *)malloc(sizeof(SFImage));	memset(tmp, 0, sizeof(SFImage));	return tmp;}static SFURL *NewSFURL(){	SFURL *tmp = (SFURL *)malloc(sizeof(SFURL));	memset(tmp, 0, sizeof(SFURL));	return tmp;}static SFCommandBuffer *NewSFCommandBuffer(){	SFCommandBuffer *tmp = (SFCommandBuffer *)malloc(sizeof(SFCommandBuffer));	memset(tmp, 0, sizeof(SFCommandBuffer));	tmp->commandList = gf_list_new();	return tmp;}static SFScript *NewSFScript(){	SFScript *tmp = (SFScript *)malloc(sizeof(SFScript));	memset(tmp, 0, sizeof(SFScript));	return tmp;}static MFBool *NewMFBool(){	MFBool *tmp = (MFBool *)malloc(sizeof(MFBool));	memset(tmp, 0, sizeof(MFBool));	return tmp;}static MFFloat *NewMFFloat(){	MFFloat *tmp = (MFFloat *)malloc(sizeof(MFFloat));	memset(tmp, 0, sizeof(MFFloat));	return tmp;}static MFTime *NewMFTime(){	MFTime *tmp = (MFTime *)malloc(sizeof(MFTime));	memset(tmp, 0, sizeof(MFTime));	return tmp;}static MFInt32 *NewMFInt32(){	MFInt32 *tmp = (MFInt32 *)malloc(sizeof(MFInt32));	memset(tmp, 0, sizeof(MFInt32));	return tmp;}static MFString *NewMFString(){	MFString *tmp = (MFString *)malloc(sizeof(MFString));	memset(tmp, 0, sizeof(MFString));	return tmp;}static MFVec3f *NewMFVec3f(){	MFVec3f *tmp = (MFVec3f *)malloc(sizeof(MFVec3f));	memset(tmp, 0, sizeof(MFVec3f));	return tmp;}static MFVec3d *NewMFVec3d(){	MFVec3d *tmp = (MFVec3d *)malloc(sizeof(MFVec3d));	memset(tmp, 0, sizeof(MFVec3d));	return tmp;}static MFVec2f *NewMFVec2f(){	MFVec2f *tmp = (MFVec2f *)malloc(sizeof(MFVec2f));	memset(tmp, 0, sizeof(MFVec2f));	return tmp;}static MFVec2d *NewMFVec2d(){	MFVec2d *tmp = (MFVec2d *)malloc(sizeof(MFVec2d));	memset(tmp, 0, sizeof(MFVec2d));	return tmp;}static MFColor *NewMFColor(){	MFColor *tmp = (MFColor *)malloc(sizeof(MFColor));	memset(tmp, 0, sizeof(MFColor));	return tmp;}static MFColorRGBA *NewMFColorRGBA(){	MFColorRGBA *tmp = (MFColorRGBA *)malloc(sizeof(MFColorRGBA));	memset(tmp, 0, sizeof(MFColorRGBA));	return tmp;}static MFRotation *NewMFRotation(){	MFRotation *tmp = (MFRotation *)malloc(sizeof(MFRotation));	memset(tmp, 0, sizeof(MFRotation));	return tmp;}static MFURL *NewMFURL(){	MFURL *tmp = (MFURL *)malloc(sizeof(MFURL));	memset(tmp, 0, sizeof(MFURL));	return tmp;}static MFScript *NewMFScript(){	MFScript *tmp = (MFScript *)malloc(sizeof(MFScript));	memset(tmp, 0, sizeof(MFScript));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -