changeset 1341:fed88ab337b4 draft

minor changes.
author e095732 <e095732@ie.u-ryukyu.ac.jp>
date Wed, 11 Jan 2012 14:25:30 +0900
parents b6ee60edacf0
children a65b98e6e514
files Renderer/Engine/SceneGraphRoot.cc
diffstat 1 files changed, 157 insertions(+), 157 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Tue Jan 10 17:17:13 2012 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Wed Jan 11 14:25:30 2012 +0900
@@ -397,165 +397,168 @@
 
 
 void decode_float_array(xmlNodePtr cur,LIST_P list ){ 
-      
-	
-        SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
-        
-        char *id = (char*)xmlGetProp(cur, (xmlChar*)"id");
-        src->id = (char*)xmlGetProp(cur, (xmlChar*)"id");
-        
-        int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
-        src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
-        src->u.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));
+    SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
+    char *id = (char*)xmlGetProp(cur, (xmlChar*)"id");
+    src->id = (char*)xmlGetProp(cur, (xmlChar*)"id");
+    
+    int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
+    src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
+    //src->u.array = (float*)malloc(sizeof(float)*src->count);
+    src->u.array = new float[src->count];
+    char *cont =(char*)xmlNodeGetContent(cur);
+    //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->u.array+i);
+    }
 
-        /* store float inpoint list */
-        for (int i = 0; cont != NULL; i++) {
-            cont = pickup_float(cont, src->u.array+i);
-        }
-
-        src->next = NULL;
-        addSource(list, src);
-        printf("id:%s count:%d cont:%s\n", id, count, cont);
+    src->next = NULL;
+    addSource(list, src);
+    printf("id:%s count:%d cont:%s\n", id, count, cont);
 }
 
 
 void 
 decode_points(xmlNodePtr cur, collada_state *s, TaskManager *manager){
-        char *pcont = (char*)xmlNodeGetContent(cur);
-        int vcsum = 0;
-	for (int i = 0;i < s->polylist_count;i++){
-	    vcsum += s->vcount[i];
-	}
-        //s->pcount = (float*)malloc(sizeof(float)*vcsum);
-	s->pcount = new float[vcsum];
-        for (int i=0; pcont != NULL; i++) {
-            pcont = pickup_float(pcont, s->pcount+i);
-        }
-	int *vertexp;
-	vertexp = new int[vcsum];
-	for (int i=0;i<vcsum;i++){
-	    vertexp[i]=0;
-	}
-	float *vertex_table;
-	float *normal_table;
-	float *texcoord_table;
-	vertex_table = new float[s->vertex_float->count];
-	//float *vertex_table = (float*)malloc(sizeof(float)*s->vertex_float->count) ;
-	normal_table = new float[s->normal_float->count];
-        //float *normal_table = (float*)malloc(sizeof(float)*s->normal_float->count) ;
-	texcoord_table = new float[s->texcoord_float->count];
-	//float *texcoord_table = (float*)malloc(sizeof(float)*s->texcoord_float->count) ;
+    printf("start decode points\n");
+    char *pcont = (char*)xmlNodeGetContent(cur);
+    int vcsum = 0;
+    for (int i = 0;i < s->polylist_count;i++){
+       vcsum += s->vcount[i];
+    }
+    printf("----------vcsum-------------\n");
+    //s->pcount = (float*)malloc(sizeof(float)*vcsum);
+    s->pcount = new float[vcsum];
+    for (int i=0; pcont != NULL; i++) {
+        pcont = pickup_float(pcont, s->pcount+i);
+    }
+    printf("----------pcount-------------\n");
+    int vertexp[vcsum];
+    for (int i=0;i<vcsum;i++){
+       vertexp[i]=0;
+    }
+    //float *vertex_table;
+    //float *normal_table;
+    //float *texcoord_table;
+    printf("---------v--------------\n");
+    float vertex_table[s->vertex_float->count];
+    //vertex_table = new float[s->vertex_float->count];
+    //float *vertex_table = (float*)malloc(sizeof(float)*s->vertex_float->count) ;
+    printf("---------n--------------\n");
+    float normal_table[s->normal_float->count];
+    //normal_table = new float[s->normal_float->count];
+    //float *normal_table = (float*)malloc(sizeof(float)*s->normal_float->count);
+    printf("---------t--------------\n");
+    float texcoord_table[s->texcoord_float->count];
+    //texcoord_table = new float[s->texcoord_float->count];
+    //float *texcoord_table = (float*)malloc(sizeof(float)*s->texcoord_float->count) ;
 
-	int limit = vcsum * 2;
-	if (s->texcoord_offset == 2){
-	    limit = vcsum * 3;
+    int limit = vcsum * 2;
+    if (s->texcoord_offset == 2){
+        limit = vcsum * 3;
+    }
+    printf("---------separateq--------------\n");
+    /* p separate vertex position and nomal position. */
+    for (int i=0,j=0; i < limit; 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) {
+	    texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[i+2]];
+	    i++;
 	}
-
-        /* p separate vertex position and nomal position. */
-        for (int i=0,j=0; i < limit; 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) {
-	        texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[i+2]];
-		i++;
-            }
-        }
-	delete s->pcount;
-        for (int i=0; vertexp[i];i++) {
-            if (s->vcount[i] == 4) {
-                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;
-                }
-            }else if (s->vcount[i]==3) {
-	       vertex_table[i] = s->vertex_float->u.array[vertexp[i]];
-            }
-        }
-	delete s->vcount;
-	
-	int count = vcsum / 3; 
-      	SceneGraphPtr sg = new SceneGraph(manager);
-        sg->pp_num = (count + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE;
-	sg->pp = (PolygonPack*)malloc(sizeof(PolygonPack)*sg->pp_num);
+    }
+    printf("---------pcount--------------\n");
+    for (int i=0;i<vcsum;i++) {
+        if (s->vcount[i] == 4) {
+	    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;
+	    }
+	}else if (s->vcount[i]==3) {
+	    vertex_table[i] = s->vertex_float->u.array[vertexp[i]];
+	}
+    }
+    printf("----------vcount-------------\n");
+    int count = vcsum / 3; 
+    SceneGraphPtr sg = new SceneGraph(manager);
+    sg->pp_num = (count + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE;
+    sg->pp = (PolygonPack*)malloc(sizeof(PolygonPack)*sg->pp_num);
 	
-	for (int i = 0;i < sg->pp_num; i++ ){
-	    PolygonPackPtr pp = sg->pp;
-            TrianglePackPtr tri =  pp[i].tri;
-         // TrianglePack の size のチェック
-            int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ;
-            pp[i].info.size = tri_size;
-	    int k = 0;
-	    int m = 0;
-	    int n = 0;
-            for (int j = 0; j < tri_size; j++) {
-	      tri[j].normal1.x = normal_table[k++];
-	      tri[j].normal1.y = normal_table[k++];
-      	      tri[j].normal1.z = normal_table[k++];
-
-	      tri[j].normal2.x = normal_table[k++];
-	      tri[j].normal2.y = normal_table[k++];
-      	      tri[j].normal2.z = normal_table[k++];
-
-	      tri[j].normal3.x = normal_table[k++];
-	      tri[j].normal3.y = normal_table[k++];
-      	      tri[j].normal3.z = normal_table[k++];
+    for (int i = 0;i < sg->pp_num; i++ ){
+        PolygonPackPtr pp = sg->pp;
+	TrianglePackPtr tri =  pp[i].tri;
+	// TrianglePack の size のチェック
+	int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ;
+	pp[i].info.size = tri_size;
+	int k = 0;
+	int m = 0;
+	int n = 0;
+	for (int j = 0; j < tri_size; j++) {
+	    tri[j].normal1.x = normal_table[k++];
+	    tri[j].normal1.y = normal_table[k++];
+	    tri[j].normal1.z = normal_table[k++];
+	    
+	    tri[j].normal2.x = normal_table[k++];
+	    tri[j].normal2.y = normal_table[k++];
+	    tri[j].normal2.z = normal_table[k++];
 	    
-	      tri[j].ver1.tex_x = texcoord_table[m++];
-	      tri[j].ver1.tex_y = texcoord_table[m++];
-
-	      tri[j].ver2.tex_x = texcoord_table[m++];
-	      tri[j].ver2.tex_y = texcoord_table[m++];
-
-	      tri[j].ver3.tex_x = texcoord_table[m++];
-	      tri[j].ver3.tex_y = texcoord_table[m++];
+	    tri[j].normal3.x = normal_table[k++];
+	    tri[j].normal3.y = normal_table[k++];
+	    tri[j].normal3.z = normal_table[k++];
+	    
+	    tri[j].ver1.tex_x = texcoord_table[m++];
+	    tri[j].ver1.tex_y = texcoord_table[m++];
+	    
+	    tri[j].ver2.tex_x = texcoord_table[m++];
+	    tri[j].ver2.tex_y = texcoord_table[m++];
+	    
+	    tri[j].ver3.tex_x = texcoord_table[m++];
+	    tri[j].ver3.tex_y = texcoord_table[m++];
+	    
+	    tri[j].ver1.x = vertex_table[n++];
+	    tri[j].ver1.y = vertex_table[n++];
+	    tri[j].ver1.z = vertex_table[n++];
+	    
+	    tri[j].ver2.x = vertex_table[n++];
+	    tri[j].ver2.y = vertex_table[n++];
+	    tri[j].ver2.z = vertex_table[n++];
+	    
+	    tri[j].ver3.x = vertex_table[n++];
+	    tri[j].ver3.y = vertex_table[n++];
+	    tri[j].ver3.z = vertex_table[n++];
 
-	      tri[j].ver1.x = vertex_table[n++];
-	      tri[j].ver1.y = vertex_table[n++];
-	      tri[j].ver1.z = vertex_table[n++];
-
-	      tri[j].ver2.x = vertex_table[n++];
-	      tri[j].ver2.y = vertex_table[n++];
-	      tri[j].ver2.z = vertex_table[n++];
-
-	      tri[j].ver3.x = vertex_table[n++];
-	      tri[j].ver3.y = vertex_table[n++];
-	      tri[j].ver3.z = vertex_table[n++];
-
-	    }
-	    
 	}
-	sg->c_xyz[0] = sg->c_xyz[1] = sg->c_xyz[2] = 0;
-
-	/*TEST*/
-        for (int i=0; i<vcsum; i++) {
-            printf("vertexp = %d\n", vertexp[i]);
-	    // printf("vertex_table= %f\n", vertex_table[i]);
-        } 
-	//free(vertexp);
-	//free(vertex_table);
-        //free(normal_table);
-	//free(texcoord_table);
 	
-	delete vertexp;
-	delete vertex_table;
-	delete normal_table;
-	delete texcoord_table;
-
-        /* got out of polylist */
-        s->polylist = 0;
-        
     }
-
+    sg->c_xyz[0] = sg->c_xyz[1] = sg->c_xyz[2] = 0;
+    
+    /*TEST*/
+    for (int i=0; i<vcsum; i++) {
+        printf("vertexp = %d\n", vertexp[i]);
+        //printf("vertex_table= %f\n", vertex_table[i]);
+    } 
+    //free(vertexp);
+    //free(vertex_table);
+    //free(normal_table);
+    //free(texcoord_table);
+    
+    //delete []vertex_table;
+    //delete []normal_table;
+    //delete []texcoord_table;
+    
+    /* got out of polylist */
+    s->polylist = 0;
+    printf("end decode");
+}
 
 static void 
 xml_walk(xmlNodePtr cur, struct collada_state *s, LIST_P list, SceneGraphRoot *root)
 {
     int in_polylist=0;
+    printf("in xml_walk");
     printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children);
     printf("s->polylist = %d\n",s->polylist);
     if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) {
@@ -567,40 +570,40 @@
     } else if (!s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) {
         char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
         if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) {
-            s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
+	    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")) {
-	     s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
-             s->vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));             
-             s->vertex_float = most_match(s->vertices_src+1, list);
+	    s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
+	    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")) {
             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+1, list);
-       } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"TEXCOORD")) {
+        } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"TEXCOORD")) {
             s->texcoord_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
             s->texcoord_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
             s->texcoord_float = most_match(s->texcoord_src+1, list);
-       }
+	}
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
         char *vcont = (char*)xmlNodeGetContent(cur);
         //s->vcount = (float*)malloc(sizeof(float)*s->polylist_count);
 	s->vcount = new float[s->polylist_count];
         for (int i=0; vcont!=NULL; i++) {
-            /* store vcount list */
-             vcont = pickup_float(vcont, s->vcount+i);
+	    /* store vcount list */
+	    vcont = pickup_float(vcont, s->vcount+i);
         }
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
-      decode_points(cur,s,root->tmanager);
+        decode_points(cur,s,root->tmanager);
 	in_polylist = 0;
     } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
         decode_float_array(cur,list);
     }
     for (cur=cur->children; cur; cur=cur->next){
-      xml_walk(cur, s, list , root);
-    }    
+        xml_walk(cur,s,list,root);
+    }
 }
 
 void
@@ -628,14 +631,11 @@
     /* node analyze */
     struct collada_state s;
     for (cur=cur->children; cur; cur=cur->next){
-  
         LIST list;
         init_list(&list);
-	xml_walk(cur,&s, &list,this);
-
+        xml_walk(cur,&s,&list,this);
     }
-
-    xmlFreeDoc(doc);
+    //xmlFreeDoc(doc);
 }
 
 void
@@ -643,7 +643,7 @@
 {
     xmlDocPtr doc;
     xmlNodePtr cur;
-
+    printf("----------------------------");
     // size は取れるはず、テスト用に mmap したデータを使う
     /* パース DOM生成 */