changeset 1317:afe66d75f48a draft

destroid collada file reader.
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Fri, 16 Dec 2011 17:45:57 +0900
parents 53f6855985f6
children a788b093ef79
files Renderer/Engine/SceneGraphRoot.cc
diffstat 1 files changed, 37 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Fri Dec 16 16:11:35 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Fri Dec 16 17:45:57 2011 +0900
@@ -319,22 +319,25 @@
     SOURCE_P cur = list->first;
     for (;cur ; cur=cur->next) {
         if (!strcmp_a(id, cur->id)) {
-            if (list->count == 0) //alias 
-                return get_point(list->u.alias, position, list);
+            if (cur->count == 0) //alias 
+                return get_point(cur->u.alias, position, list);
             float *a = cur->u.array;
-            if (position <= list->count) {
+            if (position <= cur->count) {
                 return a[position];
             }
        }
     }
 }
 
+/**
+ * co
+ */
 static SOURCE
-must_mach_id(const char *id_1 ,const char *id_2)
+must_match_id(const char *id_1 ,const char *id_2)
 {
     int tmplength;
     char *tmpsrc;
-    for (int strlength=0;normal_id[i+1]==cur->id[i];str_length++); 
+    for (int strlength=0;id_1[i+1]==id_2[i];str_length++); 
     if (tmplength < strlength) {
          tmplength = strlength;
          tmpsrc = cur;
@@ -342,13 +345,17 @@
     return cur;
 }
 
-static int polylist=0;
-static const char *polylist_normal=0;
-static const char *polylist_vertex=0;
-
+static struct collada_state {
+    int polylist;
+    const char *polylist_normal;
+    xmlChar *pid;
+    float *vcount;
+    float *pcount;
+    const char *polylist_vertex;
+};
 
 static void 
-xml_walk(SceneGraphRoot* self, xmlNodePtr cur, LIST_P list)
+xml_walk(SceneGraphRoot* self, xmlNodePtr cur, struct collada_state *s, LIST_P list)
 {
 
     int in_polylist=0;
@@ -359,53 +366,40 @@
     if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) {
         int polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"source"));
 
-        polylist=1;
+        s->polylist=1;
         in_polylist=1;
-    }
-
-    if (!xmlStrcmp(cur->name, (xmlChar*)"vertices") {
+    } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices") {
             char *vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
 
-            char *pid = (char*)xmlGetProp(cur, (xmlChar*)"id");
-            float *vcount = malloc(sizeof(int)*count);
-            float *pcount = malloc(sizeof(float)*sum); 
+            s->pid = xmlGetProp(cur, (xmlChar*)"id");
+            s->vcount = malloc(sizeof(int)*count);
+            s->pcount = malloc(sizeof(float)*sum); 
 
 
-    }
-    if (polylist && !xmlStrcmp(cur->name, (xmlChar*)"input") {
+    } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input") {
          char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
-         if (semantic == "VERTEX") {
+         if (!xmlStrcmp(semantic, "VERTEX")) {
              char *vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
              int vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
              
-             if (vertex_src == pid) {
-                SOURCE *vertex_float = must_mach_id(vertices_src, pid) 
-             }
+             s->vertex_float = get_hash(vertices_src, s->pid) 
 
-        }
-
-        if (semantic == "NORMAL") {
+         } else if (!xmlStrcmp(semantic, "NORMAL")) {
             char *normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
             int normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
             
-                SOURCE *normal_float = must_mach_id(normal_src, cur->id);
-        }
-    
-        /*
-        if (semantic == "TEXCOORD") {
-             char *normal_src = (char*)xmlGetProp(cur, (xmlChar*)"id");
-             int *normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
-        }
-        */
-        
-        if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
+            s->normal_float = get_hash(normal_src, cur->id);
+         }
+                
+    } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
             char *vcont = (char*)xmlNodeGetContent(cur);
             for (int i=0; vcount!=NULL; i++) {
+            /* store vcount list */
                  vcont = pickup_float(vcont, vcount+i);
             }
         }
         
-        if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
+    } else  if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
             char *pcont = (char*)xmlNodeGetContent(cur);
             for (int i=0; pcont != NULL; i++) {
                 pcont = pickup_float(pcont, pcount+i);
@@ -441,10 +435,7 @@
         }
                
 
-    }       
-            
-            
-    if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
+    } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
 
         SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
         
@@ -459,6 +450,7 @@
         //const char *id = get_property("id", cur);
         //int count = atoi(get_property("count", cur));
 
+        /* store float inpoint list */
         for (int i = 0; cont != NULL; i++) {
             cont = pickup_float(cont, src->array+i);
         }
@@ -468,46 +460,7 @@
         printf("id:%s count:%d cont:%s\n", id, count, cont);
         
     }
-    /*
-    if (!xmlStrcmp(cur->name, (xmlChar*)"vertices") {
-
-            char *pid = (char*)xmlGetProp(cur, (xmlChar*)"id");
-            float *vcount = malloc(sizeof(int)*count);
-            float *pcount = malloc(sizeof(float)*sum); 
-
-            if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
-                char *vcont = (char*)xmlNodeGetContent(cur);
-                    for (int i=0; vcount!=NULL; i++) {
-                        vcont = pickup_float(vcont, vcount+i);
-                    }
-            }
-
-            if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
-                char *pcont = (char*)xmlNodeGetContent(cur);
-                for (int i=0; pcont != NULL; i++) {
-                    pcont = pickup_float(pcont, pcount+i);
-                }
-            }
-        }
-    
-
-        get_point(pid, , cur);
-
-
-        for (SOURCE *iliner = list->first; list->end != iliner; iliner = iliner->next) {
-            if (!strcmp_a(pid, iliner->id)) {
-                if (vcount == 4) {
-
-
-                } else if (vcount == 3) {
-
-                }
-            }
-        }
-    }
-    */
-
-    
+   
     for (cur=cur->children; cur; cur=cur->next){
         xml_walk(self, cur, list);
     }    
@@ -537,32 +490,14 @@
      }
 
 	/* node analyze */
+    struct collada_state s={};
 	for(cur=cur->children; cur; cur=cur->next){
 
         LIST list;
         init_list(&list);
 
 	    xml_walk(this, cur, &list);
-	 /* if(xmlStrcmp(cur->name,(xmlChar*)"library_imeges") != 0){
-	    cur_images = cur;
-	    continue;
-	  }
-	  if(xmlStrcmp(cur->name,(xmlChar*)"library_effects") != 0){
-	    cur_effects = cur;
-	    continue;
-	  }
-	  if(xmlStrcmp(cur->name,(xmlChar*)"library_geometries") != 0){
-	    cur_geometries = cur;
-	    continue;
-	  }
-	  if(xmlStrcmp(cur->name,(xmlChar*)"library_visual_scenes")!=0){
-	    cur_visual_scenes = cur;
-	    continue;
-	  }*/
-	  
-	  //tmp = new SceneGraph(manager, cur);
-	  //registSceneGraph(tmp);
-	}
+    }
 	xmlFreeDoc(doc);
 }