changeset 1321:a6b11345939c draft

collada file reader except error. but can't move.
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Tue, 20 Dec 2011 00:10:30 +0900
parents bbfcc1652518
children 2b4e3fc1c800
files Renderer/Engine/SceneGraphRoot.cc
diffstat 1 files changed, 35 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Sun Dec 18 09:44:01 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Tue Dec 20 00:10:30 2011 +0900
@@ -364,8 +364,6 @@
     int normal_offset;
     int normal_count;
 
-    char *pcont;
-
     float *vcount;
     float *pcount;
 
@@ -374,6 +372,8 @@
 
     char *vertices_src;
     int polylist_count;
+
+
 };
 
 static void 
@@ -394,15 +394,16 @@
 
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) {
 
-         s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
+        s->pid = xmlGetProp(cur, (xmlChar*)"id");
+
+    } else if (!xmlStrcmp(cur->name, (xmlChar*)"input")) {
 
-         s->pid = xmlGetProp(cur, (xmlChar*)"id");
-         s->vcount = (float*)malloc(sizeof(float)*s->polylist_count);
-         s->pcount = malloc(sizeof(float)*sum); 
-
+        char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
+        if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) {
+            s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
+        }
 
     } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) {
-
         char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
 
         if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) {
@@ -412,31 +413,34 @@
              
              s->vertex_float = most_match(s->vertices_src, list);
 
-         } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) {
+        } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) {
 
             s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
             s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
             
             s->normal_float = most_match(s->normal_src, list);
-         }
+        }
                 
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
+        char *vcont = (char*)xmlNodeGetContent(cur);
 
-            char *vcont = (char*)xmlNodeGetContent(cur);
+        s->vcount = (float*)malloc(sizeof(float)*s->polylist_count);
 
-            for (int i=0; s->vcont!=NULL; i++) {
+        for (int i=0; vcont!=NULL; i++) {
             /* store vcount list */
-                 vcont = pickup_float(vcont, s->vcount+i);
-            }
+             vcont = pickup_float(vcont, s->vcount+i);
+        }
         
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
 
         /* only case is nothing input of source="TEXCOORD" */
 
-        s->pcont = (char*)xmlNodeGetContent(cur);
+        char *pcont = (char*)xmlNodeGetContent(cur);
+        
+        s->pcount = (float*)malloc(sizeof(float)*(int)s->polylist_count); 
 
-        for (int i=0; s->pcont != NULL; i++) {
-            s->pcont = pickup_float(s->pcont, s->pcount+i);
+        for (int i=0; pcont != NULL; i++) {
+            pcont = pickup_float(pcont, s->pcount+i);
         } 
         
         int vertexp[s->vertex_count]; 
@@ -444,29 +448,27 @@
         float *vertex_table; 
         float *normal_table;
 
-        /* まだ<p>のidをどう探してこようか検討中
-         * u.array の前を未記入
-         */
+        /* p separate vertex position and nomal position. */
         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]];
+            normal_table[i] = s->normal_float->u.array[(int)s->pcount[2*i+1]];
         }
 
         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]];
+                for (int j=0; j > s->vcount[i]; j++) {
+                    vertex_table[i] =  s->vertex_float->u.array[vertexp[i]];
+                    vertex_table[i+3] =  s->vertex_float->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]];
-                }
             }
         }
-        /* ここまで */
+        for (int i=0; vertex_table; i++) {
+            printf("normal_table= %f\n", normal_table[i]);
+            printf("vertex_table= %f\n", vertex_table[i]);
+        } 
 
+        /* got out of polylist */
         s->polylist = 0;
         in_polylist = 0;
                
@@ -519,19 +521,20 @@
 	doc = xmlParseFile(xmlColladafile);
 	cur = xmlDocGetRootElement(doc);
 
-	/*エラー処理……だけど何書けばいいのか謎。とりあえず-1返してみる*/
 	if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){
 		return ;
      }
 
 	/* node analyze */
-    struct collada_state *s;
+    struct collada_state s;
+    s.polylist=0;
+
 	for(cur=cur->children; cur; cur=cur->next){
 
         LIST list;
         init_list(&list);
 
-	    xml_walk(this, cur, s, &list);
+	    xml_walk(this, cur,&s, &list);
     }
 	xmlFreeDoc(doc);
 }