changeset 1319:31455d34e502 draft

collada file reader minor changes.
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Sun, 18 Dec 2011 09:39:14 +0900
parents a788b093ef79
children bbfcc1652518
files Renderer/Engine/SceneGraphRoot.cc
diffstat 1 files changed, 90 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Fri Dec 16 18:16:48 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Sun Dec 18 09:39:14 2011 +0900
@@ -332,26 +332,48 @@
 /**
  * co
  */
-static SOURCE
-must_match_id(const char *id_1 ,const char *id_2)
+static SOURCE_P
+most_match(const char *id , LIST_P list)
 {
+    SOURCE_P src,cur;
     int tmplength;
-    char *tmpsrc;
-    for (int strlength=0;id_1[i+1]==id_2[i];str_length++); 
-    if (tmplength < strlength) {
-         tmplength = strlength;
-         tmpsrc = cur;
+    int strlength;
+    for (cur=list->first ;cur!=list->end ;cur=cur->next) {
+        for (strlength=0;id[strlength+1]==cur->id[strlength];strlength++); 
+        if (tmplength < strlength) {
+            tmplength = strlength;
+            src = cur;
+        }
     }
-    return cur;
+    return src;
 }
 
-static struct collada_state {
+struct collada_state {
     int polylist;
+
     const char *polylist_normal;
+    const char *polylist_vertex;
+
     xmlChar *pid;
+
+    char *vertex_src;
+    int vertex_offset;
+    int vertex_count;
+
+    char *normal_src;
+    int normal_offset;
+    int normal_count;
+
+    char *pcont;
+
     float *vcount;
     float *pcount;
-    const char *polylist_vertex;
+
+    SOURCE_P normal_float;
+    SOURCE_P vertex_float;
+
+    char *vertices_src;
+    int polylist_count;
 };
 
 static void 
@@ -364,77 +386,88 @@
 
 
     if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) {
-        int polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"source"));
+
+        s->polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
 
         s->polylist=1;
         in_polylist=1;
+
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) {
-            char *vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
 
-            s->pid = xmlGetProp(cur, (xmlChar*)"id");
-            s->vcount = malloc(sizeof(int)*count);
-            s->pcount = malloc(sizeof(float)*sum); 
+         s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
+
+         s->pid = xmlGetProp(cur, (xmlChar*)"id");
+         s->vcount = (float*)malloc(sizeof(float)*s->polylist_count);
+         s->pcount = malloc(sizeof(float)*sum); 
 
 
     } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) {
-         char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
-         if (!xmlStrcmp(semantic, "VERTEX")) {
-             char *vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
-             int vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
+
+        char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
+
+        if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) {
+
+             s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
+             s->vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
              
-             s->vertex_float = get_hash(vertices_src, s->pid) 
+             s->vertex_float = most_match(s->vertices_src, list);
+
+         } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) {
 
-         } else if (!xmlStrcmp(semantic, "NORMAL")) {
-            char *normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
-            int normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
+            s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
+            s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
             
-            s->normal_float = get_hash(normal_src, cur->id);
+            s->normal_float = most_match(s->normal_src, list);
          }
                 
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
+
             char *vcont = (char*)xmlNodeGetContent(cur);
-            for (int i=0; vcount!=NULL; i++) {
+
+            for (int i=0; s->vcont!=NULL; i++) {
             /* store vcount list */
-                 vcont = pickup_float(vcont, vcount+i);
+                 vcont = pickup_float(vcont, s->vcount+i);
             }
-        }
         
-    } 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);
-            }
-        }
+    } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
+
+        /* input の source="TEXCOORD" がない場合のみ */
+
+        s->pcont = (char*)xmlNodeGetContent(cur);
+
+        for (int i=0; s->pcont != NULL; i++) {
+            s->pcont = pickup_float(s->pcont, s->pcount+i);
+        } 
         
-
-        get_point(pid, , cur);
-
-        int vertexp[]; 
-        int normalp[];
+        int vertexp[s->vertex_count]; 
 
         float *vertex_table; 
         float *normal_table;
 
-        for (int i = 0; i<polylist_count; i++) {
-            vertexp[i] = pcount[2*i];
-            normalp[i] = pcount[2*i+1];
+        /* まだ<p>のidをどう探してこようか検討中 */
+        for (int i = 0; i < s->polylist_count; i++) {
+            vertexp[i] = s->pcount[2*i];
+            normal_table[i] = u.array[s->pcount[2*i+1]];
         }
 
-        for (int i=0; ;i++) {
-            for (int j=0 ; j > vcont[i] ;j++) {
-                if (vcount[i] == 4) {
-
-
-
-                } else if (vcount[i] == 3) {
-                    vertex_table[i] = vertex;
-
-
+        for (int i=0; vertexp[i];i++) {
+            if (s->vcount[i] == 4) {
+                for (int j=0; j > s->vcont[i]; j++) {
+                    vertex_table[i] =  u.array[vertexp[i]];
+                    vertex_table[i+3] =  u.array[vertexp[i+1]];
+                    i += 2;
+                }
+            if (s->vcount[i] == 3) {
+                for (int j=0; j > s->vcount[i]; j++) {
+                    vertex_table[i] =  u.array[vertexp[i]];
                 }
             }
         }
+        /* ここまで */
+
+        s->polylist = 0;
+        in_polylist = 0;
                
-
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
 
         SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
@@ -444,7 +477,7 @@
         
         int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
         src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
-        src->array = (float*)malloc(sizeof(float) * src->count);
+        src->u.array = (float*)malloc(sizeof(float) * src->count);
         
         char *cont =(char*)xmlNodeGetContent(cur);
         //const char *id = get_property("id", cur);
@@ -452,7 +485,7 @@
 
         /* store float inpoint list */
         for (int i = 0; cont != NULL; i++) {
-            cont = pickup_float(cont, src->array+i);
+            cont = pickup_float(cont, src->u.array+i);
         }
 
         src->next = NULL;
@@ -462,7 +495,7 @@
     }
    
     for (cur=cur->children; cur; cur=cur->next){
-        xml_walk(self, cur, list);
+        xml_walk(self, cur, s, list);
     }    
 }
 
@@ -490,13 +523,13 @@
      }
 
 	/* node analyze */
-    struct collada_state s={};
+    struct collada_state *s;
 	for(cur=cur->children; cur; cur=cur->next){
 
         LIST list;
         init_list(&list);
 
-	    xml_walk(this, cur, &list);
+	    xml_walk(this, cur, s, &list);
     }
 	xmlFreeDoc(doc);
 }