main.c

来自「gaca源码」· C语言 代码 · 共 1,280 行 · 第 1/3 页

C
1,280
字号
					fprintf(vrml_code, "\tp->%s = gf_list_new();\t\n", bf->name);
				}
			}
			/*special case for SFCommandBuffer: we also create a command list*/
			if (!stricmp(bf->familly, "SFCommandBuffer")) {
				fprintf(vrml_code, "\tp->%s.commandList = gf_list_new();\t\n", bf->name);
			}
		}

		//setup pointers
		fprintf(vrml_code, "\n#ifdef GF_NODE_USE_POINTERS\n\n");
		fprintf(vrml_code, "\t((GF_Node *)p)->sgprivate->name = \"%s\";\n", n->name);
		fprintf(vrml_code, "\t((GF_Node *)p)->sgprivate->node_del = %s_Del;\n", n->name);
		fprintf(vrml_code, "\t((GF_Node *)p)->sgprivate->get_field_count = %s_get_field_count;\n", n->name);
		fprintf(vrml_code, "\t((GF_Node *)p)->sgprivate->get_field = %s_get_field;\n", n->name);

		//check if we have a child node
		for (i=0; i<gf_list_count(n->Fields); i++) {
			bf = gf_list_get(n->Fields, i);
			if ( !strcmp(bf->name, "children") || 
					( !strstr(bf->type, "event") && strstr(bf->familly, "MF") && strstr(bf->familly, "Node")) ) {

				sprintf(n->Child_NDT_Name, "NDT_SF%s", bf->familly+2);
				break;
			}
		}
		fprintf(vrml_code, "\n#endif\n\n");

		fprintf(vrml_code, "\n\t/*default field values*/\n");
		
		for (i=0; i<gf_list_count(n->Fields); i++) {
			bf = gf_list_get(n->Fields, i);

			//nothing on eventIn or Out
			if (!strcmp(bf->type, "eventIn")) continue;
			if (!strcmp(bf->type, "eventOut")) continue;

			if (!strcmp(bf->def, "")) continue;

			//no default on nodes
			if (strstr(bf->familly, "Node")) continue;
			//extract default falue
			
			//
			//		SF Fields
			//
			
			//SFBool
			if (!strcmp(bf->familly, "SFBool")) {
				if (!strcmp(bf->def, "1") || !strcmp(bf->def, "TRUE")) 
					fprintf(vrml_code, "\tp->%s = 1;\n", bf->name);
			}
			//SFFloat
			else if (!strcmp(bf->familly, "SFFloat")) {
				fprintf(vrml_code, "\tp->%s = FLT2FIX(%s);\n", bf->name, bf->def);
			}
			//SFDouble
			else if (!strcmp(bf->familly, "SFDouble")) {
				fprintf(vrml_code, "\tp->%s = (SFDouble) %s;\n", bf->name, bf->def);
			}
			//SFTime
			else if (!strcmp(bf->familly, "SFTime")) {
				fprintf(vrml_code, "\tp->%s = %s;\n", bf->name, bf->def);
			}
			//SFInt32
			else if (!strcmp(bf->familly, "SFInt32")) {
				fprintf(vrml_code, "\tp->%s = %s;\n", bf->name, bf->def);
			}
			//SFColor
			else if (!strcmp(bf->familly, "SFColor")) {
				CurrentLine = bf->def;
				GetNextToken(token, " ");
				TranslateToken(token);

				fprintf(vrml_code, "\tp->%s.red = FLT2FIX(%s);\n", bf->name, token);
				GetNextToken(token, " ");
				fprintf(vrml_code, "\tp->%s.green = FLT2FIX(%s);\n", bf->name, token);
				GetNextToken(token, " ");
				fprintf(vrml_code, "\tp->%s.blue = FLT2FIX(%s);\n", bf->name, token);
			}
			//SFVec2f
			else if (!strcmp(bf->familly, "SFVec2f")) {
				CurrentLine = bf->def;
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.x = FLT2FIX(%s);\n", bf->name, token);
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.y = FLT2FIX(%s);\n", bf->name, token);
			}
			//SFVec2d
			else if (!strcmp(bf->familly, "SFVec2d")) {
				CurrentLine = bf->def;
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.x = (SFDouble) %s;\n", bf->name, token);
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.y = (SFDouble) %s;\n", bf->name, token);
			}
			//SFVec3f
			else if (!strcmp(bf->familly, "SFVec3f")) {
				CurrentLine = bf->def;
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.x = FLT2FIX(%s);\n", bf->name, token);
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.y = FLT2FIX(%s);\n", bf->name, token);
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.z = FLT2FIX(%s);\n", bf->name, token);
			}
			//SFVec3d
			else if (!strcmp(bf->familly, "SFVec3d")) {
				CurrentLine = bf->def;
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.x = (SFDouble) %s;\n", bf->name, token);
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.y = (SFDouble) %s;\n", bf->name, token);
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.z = (SFDouble) %s;\n", bf->name, token);
			}
			//SFVec4f & SFRotation
			else if (!strcmp(bf->familly, "SFVec4f") || !strcmp(bf->familly, "SFRotation")) {
				CurrentLine = bf->def;
				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.x = FLT2FIX(%s);\n", bf->name, token);

				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.y = FLT2FIX(%s);\n", bf->name, token);

				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.z = FLT2FIX(%s);\n", bf->name, token);

				GetNextToken(token, " ");
				TranslateToken(token);
				fprintf(vrml_code, "\tp->%s.q = FLT2FIX(%s);\n", bf->name, token);
			}
			//SFString
			else if (!strcmp(bf->familly, "SFString")) {
				fprintf(vrml_code, "\tp->%s.buffer = malloc(sizeof(char) * %d);\n", bf->name, strlen(bf->def)+1);
				fprintf(vrml_code, "\tstrcpy(p->%s.buffer, \"%s\");\n", bf->name, bf->def);
			}
		
			//
			//		MF Fields
			//
			//MFFloat
			else if (!strcmp(bf->familly, "MFFloat")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, " ,")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFFloat)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, " ,")) go = 0;
					TranslateToken(token);
					fprintf(vrml_code, "\tp->%s.vals[%d] = FLT2FIX(%s);\n", bf->name, j, token);
					j+=1;
				}
			}
			//MFDouble
			else if (!strcmp(bf->familly, "MFDouble")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, " ,")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFFloat)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, " ,")) go = 0;
					TranslateToken(token);
					fprintf(vrml_code, "\tp->%s.vals[%d] = (SFDouble) %s;\n", bf->name, j, token);
					j+=1;
				}
			}
			//MFVec2f
			else if (!strcmp(bf->familly, "MFVec2f")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFVec2f)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].x = FLT2FIX(%s);\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].y = FLT2FIX(%s);\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}
			//MFVec2d
			else if (!strcmp(bf->familly, "MFVec2d")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFVec2f)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].x = (SFDouble) %s;\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].y = (SFDouble) %s;\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}
			//MFVec3f
			else if (!strcmp(bf->familly, "MFVec3f")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFVec3f)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].x = FLT2FIX(%s);\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].y = FLT2FIX(%s);\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].z = FLT2FIX(%s);\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}
			//MFVec3d
			else if (!strcmp(bf->familly, "MFVec3d")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFVec3f)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].x = (SFDouble) %s;\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].y = (SFDouble) %s;\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].z = (SFDouble) %s;\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}
			//MFVec4f & MFRotation
			else if (!strcmp(bf->familly, "MFVec4f") || !strcmp(bf->familly, "MFRotation")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(GF_Vec4)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].x = FLT2FIX(%s);\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].y = FLT2FIX(%s);\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].z = FLT2FIX(%s);\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d].q = FLT2FIX(%s);\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}
			//MFInt32
			else if (!strcmp(bf->familly, "MFInt32")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFInt32)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " ");
					fprintf(vrml_code, "\tp->%s.vals[%d] = %s;\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}
			//MFColor
			else if (!strcmp(bf->familly, "MFColor")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFColor)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " ");
					fprintf(vrml_code, "\tp->%s.vals[%d].red = FLT2FIX(%s);\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					fprintf(vrml_code, "\tp->%s.vals[%d].green = FLT2FIX(%s);\n", bf->name, j, tok);
					GetNextToken(tok, " ");
					fprintf(vrml_code, "\tp->%s.vals[%d].blue = FLT2FIX(%s);\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}
			//MFString
			else if (!strcmp(bf->familly, "MFString")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFString)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " \"");
					fprintf(vrml_code, "\tp->%s.vals[%d] = malloc(sizeof(char) * %d);\n", bf->name, j, strlen(tok)+1);
					fprintf(vrml_code, "\tstrcpy(p->%s.vals[%d], \"%s\");\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}
			//MFTime
			else if (!strcmp(bf->familly, "MFTime")) {
				j = 0;
				CurrentLine = bf->def;
				while (GetNextToken(token, ",")) j++;
				j+=1;
				fprintf(vrml_code, "\tp->%s.vals = malloc(sizeof(SFTime)*%d);\n", bf->name, j);
				fprintf(vrml_code, "\tp->%s.count = %d;\n", bf->name, j);
				j = 0;
				go = 1;
				CurrentLine = bf->def;
				while (go) {
					if (!GetNextToken(token, ",")) go = 0;
					store = CurrentLine;
					CurrentLine = token;
					GetNextToken(tok, " \"");
					TranslateToken(tok);
					fprintf(vrml_code, "\tp->%s.vals[%d] = %s;\n", bf->name, j, tok);
					j+=1;
					CurrentLine = store;
				}
			}

			//other nodes
			else if (!strcmp(bf->familly, "SFImage")) {
				//we currently only have SFImage, with NO texture so do nothing
			}
			//unknown init (for debug)
			else {
				fprintf(vrml_code, "UNKNOWN FIELD (%s);\n", bf->familly);

			}

⌨️ 快捷键说明

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