changeset 1298:bb8b7f179f31 draft

improve collada file.
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Fri, 02 Dec 2011 18:57:10 +0900
parents f20e6e6500db
children f0e805c09ed6
files Renderer/Engine/SceneGraphRoot.cc
diffstat 1 files changed, 53 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Fri Dec 02 15:33:53 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Fri Dec 02 18:57:10 2011 +0900
@@ -276,35 +276,75 @@
    }
    return "";
 }*/
+typedef struct source {
+    char *id;
+    int count;
+    float *array;
+    struct source *next;
+} SOURCE;
+typedef SOURCE *SOURCE_P;
+
+typedef struct list {
+    SOURCE_P first;
+    SOURCE_P end;
+} LIST;
+typedef LIST *LIST_P;
+
+static void
+addSource(LIST_P list, SOURCE_P src) {
+    if (list->first == NULL && list->end == NULL) {
+        list->first = list->end = src;
+        return;
+    }
+    list->end->next = src;
+    list->end = src;
+}
 
 static void 
-xml_walk( SceneGraphRoot* self, xmlNodePtr cur)
+xml_walk( SceneGraphRoot* self, xmlNodePtr cur, LIST_P list)
 {
 
         /*get float array.*/
 	printf("name = %s, child:%s\n", cur->name, cur->children);
 	if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
 
-	    char *cont =(char*)xmlNodeGetContent(cur);
-	    //const char *id = get_property("id", cur);
+        SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
 
 	    char *id = (char*)xmlGetProp(cur, (xmlChar*)"id");
-	    //int count = atoi(get_property("count", cur));
+        src->id = (char*)xmlGetProp(cur, (xmlChar*)"id");
 
 	    int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
-	    
+        src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
+        src->array = (float*)malloc(sizeof(float) * src->count);
+
+	    char *cont =(char*)xmlNodeGetContent(cur);
+	    //const char *id = get_property("id", cur);
+	    //int count = atoi(get_property("count", cur));
+        for (int i = 0; cont != NULL; i++) {
+            cont = pickup_float(cont, src->array+1);
+        }
+
+        src->next = NULL;
+        addSource(list, src);
 	    printf("id:%s count:%d cont:%s\n", id, count, cont);
 
-	    if (cur->children == "(null)") {
-	        return;
+	    if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
+            char *p = (char*)xmlNodeGetContent(cur);
+            printf("p:%s", p);
 	    }
 	
 	}
 	for (cur=cur->children; cur; cur=cur->next){
-            xml_walk(self, cur);
+            xml_walk(self, cur, list);
 	}
 
-}	
+}
+
+void
+init_list(LIST_P list) {
+      list->first = NULL;
+        list->end = NULL;
+}
 
 void
 SceneGraphRoot::createFromCOLLADAfile(TaskManager *manager, const char *xmlColladafile)
@@ -326,8 +366,10 @@
 	/* node analyze */
 	for(cur=cur->children; cur; cur=cur->next){
 
-	    
-	    xml_walk(this, cur);
+        LIST list;
+        init_list(&list);
+
+	    xml_walk(this, cur, &list);
 	 /* if(xmlStrcmp(cur->name,(xmlChar*)"library_imeges") != 0){
 	    cur_images = cur;
 	    continue;