changeset 1330:615555d5bfa0 draft

minor changes.
author e095732 <e095732@ie.u-ryukyu.ac.jp>
date Wed, 21 Dec 2011 04:17:24 +0900
parents e5894cf1d2ca
children 1dd2b2f5e2e9
files Renderer/Engine/SceneGraphRoot.cc
diffstat 1 files changed, 68 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Tue Dec 20 20:11:54 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Wed Dec 21 04:17:24 2011 +0900
@@ -334,8 +334,9 @@
 static SOURCE_P
 most_match(const char *id , LIST_P list)
 {
-    SOURCE_P src,cur;
-    int tmplength;
+    SOURCE_P src = NULL;
+    SOURCE_P cur = NULL;;
+    int tmplength = 0;
     int strlength;
     for (cur=list->first ;cur!=list->end ;cur=cur->next) {
         for (strlength=0;id[strlength]==cur->id[strlength];strlength++); 
@@ -344,14 +345,30 @@
             src = cur;
         }
     }
+    
+    if (src == NULL){
+      fprintf(stderr,"not match");
+    }
     return src;
 }
 
 struct collada_state {
-    int polylist;
+    collada_state(){
+        polylist = 0;
+
+        vertex_offset = -1;
+        vertex_count = 0;
 
-    const char *polylist_normal;
-    const char *polylist_vertex;
+	normal_offset = -1;
+	normal_count = 0;
+
+	texcoord_offset = -1;
+	texcoord_count = 0; 
+	
+	polylist_count = 0;
+
+    }
+    int polylist;
 
     xmlChar *pid;
 
@@ -376,12 +393,10 @@
 
     char *vertices_src;
     int polylist_count;
-
-
 };
 
 static void 
-xml_walk(SceneGraphRoot* self, xmlNodePtr cur, struct collada_state *s, LIST_P list)
+xml_walk(xmlNodePtr cur, struct collada_state *s, LIST_P list)
 {
 
     int in_polylist=0;
@@ -411,9 +426,9 @@
 	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_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));             
              s->vertex_float = most_match(s->vertices_src+1, list);
 
         } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) {
@@ -444,29 +459,37 @@
         /* only case is nothing input of source="TEXCOORD" */
 
         char *pcont = (char*)xmlNodeGetContent(cur);
-        
-        s->pcount = (float*)malloc(sizeof(float)*(int)s->polylist_count); 
+        int vcsum = 0;
+	
+	for (int i = 0;i < s->polylist_count;i++){
+	    vcsum += s->vcount[i];
+	}
+	
+        s->pcount = (float*)malloc(sizeof(float)*vcsum); 
 
         for (int i=0; pcont != NULL; i++) {
             pcont = pickup_float(pcont, s->pcount+i);
         } 
         
-        int vertexp[s->vertex_count]; 
+        int vertexp[vcsum]; 
+	for (int i = 0;i < vcsum;i++){
+	    vertexp[i]=0;
+	}
 
         float *vertex_table = (float*)malloc(sizeof(float)*s->vertex_float->count) ;
         float *normal_table = (float*)malloc(sizeof(float)*s->normal_float->count) ;
 	float *texcoord_table = (float*)malloc(sizeof(float)*s->texcoord_float->count) ;
 
         /* p separate vertex position and nomal position. */
-        for (int i = 0; i < s->polylist_count; i+=2) {
-            vertexp[i] = s->pcount[i];
-            normal_table[i] = s->normal_float->u.array[(int)s->pcount[i+1]];
+        for (int i = 0,j=0; i < s->polylist_count; i+=2,j++) {
+	    vertexp[j] = s->pcount[i];
+            normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]];
             if (s->texcoord_offset == 2) {
-	        i++;
-	        texcoord_table[i] = s->texcoord_float->u.array[(int)s->pcount[i+1]];
+	        texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[i+2]];
+		i++;
             }
         }
-
+	/* */
         for (int i=0; vertexp[i];i++) {
             if (s->vcount[i] == 4) {
                 for (int j=0; j > s->vcount[i]; j++) {
@@ -474,19 +497,23 @@
                     vertex_table[i+3] = s->vertex_float->u.array[vertexp[i+1]];
                     i += 2;
                 }
-            }
-            if (s->vcount[i]==3) {
-                    vertex_table[i] = s->vertex_float->u.array[vertexp[i]];
+            }else if (s->vcount[i]==3) {
+	       vertex_table[i] = s->vertex_float->u.array[vertexp[i]];
             }
         }
 	/*TEST*/
         for (int i=0; vertex_table==0; i++) {
             printf("normal_table= %f\n", normal_table[i]);
-            printf("vertex_table= %f\n", vertex_table[i]);
+	    // printf("vertex_table= %f\n", vertex_table[i]);
         } 
 
+	for (int i=0;i<vcsum;i++){
+	  printf("vertexp = %d\n",vertexp[i]);
+	}
+	
         free(vertex_table);
         free(normal_table);
+	free(texcoord_table);
 
         /* got out of polylist */
         s->polylist = 0;
@@ -519,7 +546,7 @@
     }
    
     for (cur=cur->children; cur; cur=cur->next){
-        xml_walk(self, cur, s, list);
+        xml_walk(cur, s, list);
     }    
 }
 
@@ -532,31 +559,28 @@
 void
 SceneGraphRoot::createFromCOLLADAfile(TaskManager *manager, const char *xmlColladafile)
 {
-	/*make parse dom*/
-	xmlDocPtr doc;
-	xmlNodePtr cur;
-	//,cur_images,cur_effects,cur_geometries,cur_visual_scenes;
-	//SceneGraphPtr tmp;
-
-	doc = xmlParseFile(xmlColladafile);
-	cur = xmlDocGetRootElement(doc);
+    /*make parse dom*/
+    xmlDocPtr doc;
+    xmlNodePtr cur;
+    //,cur_images,cur_effects,cur_geometries,cur_visual_scenes;
+    //SceneGraphPtr tmp;
+    
+    doc = xmlParseFile(xmlColladafile);
+    cur = xmlDocGetRootElement(doc);
+    
+    if (xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){
+        return ;
+    }
 
-	if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){
-		return ;
-     }
-
-	/* node analyze */
+    /* node analyze */
     struct collada_state s;
-    s.polylist=0;
-
-	for(cur=cur->children; cur; cur=cur->next){
-
+    for (cur=cur->children; cur; cur=cur->next){
+  
         LIST list;
         init_list(&list);
-
-	    xml_walk(this, cur,&s, &list);
+	xml_walk(cur,&s, &list);
     }
-	xmlFreeDoc(doc);
+    xmlFreeDoc(doc);
 }
 
 void