diff Renderer/Engine/Collada.cc @ 1390:b4f6539fecf6 draft

delete vertexp.
author e095732 <e095732@ie.u-ryukyu.ac.jp>
date Fri, 27 Jan 2012 18:15:17 +0900
parents 2247b81dd68f
children 1ea6e4eb2b0a
line wrap: on
line diff
--- a/Renderer/Engine/Collada.cc	Fri Jan 27 17:33:16 2012 +0900
+++ b/Renderer/Engine/Collada.cc	Fri Jan 27 18:15:17 2012 +0900
@@ -48,6 +48,7 @@
 
 	limit = 0;
 	vmember = 0;
+	vtable_size =0;
 
     images_flag=0;
     }
@@ -85,6 +86,7 @@
     int vcsum;
     int limit;
     int vmember;
+    int vtable_size;
 };
 
 /*static const char*
@@ -257,6 +259,11 @@
     for (int i = 0;i < s->polylist_count;i++){
        s->vcsum += s->vcount[i];
        s->vmember = i;
+       if (s->vcount[i]==4){
+	   s->vtable_size +=6;
+       } else {
+           s->vtable_size +=3;
+       }
     }
     s->limit = s->vcsum * 2;
     if (s->texcoord_offset == 2){
@@ -272,11 +279,7 @@
 }
 SceneGraph*
 decode_points(collada_state *s, TaskManager *manager, SceneGraphPtr sg){
-    int *vertexp;
-    vertexp = new int[s->vcsum];
-    for (int i=0;i<s->vcsum;i++){
-       vertexp[i]=0;
-    }
+
     /*
      * vertex_tableだけはpolygonを作る際にvcountが4の場合重複する点が
      * 出てくるのでサイズを2倍用意しておく
@@ -284,14 +287,12 @@
     float *vertex_table;
     float *normal_table;
     float *texcoord_table; 
-    vertex_table = new float[(s->vcsum)*2];
-    normal_table = new float[s->vcsum];
-    texcoord_table = new float[s->vcsum];
-    for (int i=0;i < s->vcsum;i++){
-        vertex_table[i] = 0;
-	normal_table[i] = 0;
-	texcoord_table[i] = 0;
-    }
+    vertex_table = new float[s->vtable_size*3];
+    normal_table = new float[s->vtable_size*3];
+    texcoord_table = new float[s->vtable_size*2];
+    bzero(vertex_table,sizeof(float)*s->vtable_size*3);
+    bzero(normal_table,sizeof(float)*s->vtable_size*3);
+    bzero(texcoord_table,sizeof(float)*s->vtable_size*2);
 
     /**
      * s->vcsum と s->vertex_float->countの値が違うので大きい方をとりあえず使っておく
@@ -300,14 +301,17 @@
     /* p separate vertex position and nomal position. */
     if (s->texcoord_offset == 2){
         for (int i=0,j=0; i < s->limit; i+=3,j++) {
-	    vertexp[j] = (int)s->pcount[i];
-	    normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]];
-	    texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[i+2]];
+	    normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]*3];
+	    normal_table[j+1] = s->normal_float->u.array[(int)s->pcount[i+1]*3+1];
+	    normal_table[j+2] = s->normal_float->u.array[(int)s->pcount[i+1]*3+2];
+	    texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[i+2]*2];
+	    texcoord_table[j+1] = s->texcoord_float->u.array[(int)s->pcount[i+2]*2+1];
 	}
     } else{
         for (int i=0,j=0; i < s->limit; i+=2,j++) {
-	    vertexp[j] = (int)s->pcount[i];
-	    normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]];
+	    normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]*3];
+	    normal_table[j+1] = s->normal_float->u.array[(int)s->pcount[i+1]*3+1];
+	    normal_table[j+2] = s->normal_float->u.array[(int)s->pcount[i+1]*3+2];
 	}
     }
 
@@ -315,18 +319,39 @@
     int k=0,l=0,size=0;
     for (int i=0;i<s->vmember;i++) {
         if (s->vcount[i] == 4) {
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l]];
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l+1]];
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l+2]];
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l+1]];
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l+2]];
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l+3]];
+	    vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[i]*3];
+            vertex_table[k+1] = s->vertex_float->u.array[s->pcount[i]*3+1];
+            vertex_table[k+2] = s->vertex_float->u.array[s->pcount[i]*3+2];
+            vertex_table[k+3] = s->vertex_float->u.array[s->pcount[i+1]*3+0];
+            vertex_table[k+4] = s->vertex_float->u.array[s->pcount[i+1]*3+1];
+            vertex_table[k+5] = s->vertex_float->u.array[s->pcount[i+1]*3+2];
+            vertex_table[k+6] = s->vertex_float->u.array[s->pcount[i+3]*3+0];
+            vertex_table[k+7] = s->vertex_float->u.array[s->pcount[i+3]*3+1];
+            vertex_table[k+8] = s->vertex_float->u.array[s->pcount[i+3]*3+2];
+
+            vertex_table[k+9] = s->vertex_float->u.array[s->pcount[i]*3];
+            vertex_table[k+10] = s->vertex_float->u.array[s->pcount[i]*3+1];
+            vertex_table[k+11] = s->vertex_float->u.array[s->pcount[i]*3+2];
+            vertex_table[k+12] = s->vertex_float->u.array[s->pcount[i+3]*3+0];
+            vertex_table[k+13] = s->vertex_float->u.array[s->pcount[i+3]*3+1];
+            vertex_table[k+14] = s->vertex_float->u.array[s->pcount[i+3]*3+2];
+            vertex_table[k+15] = s->vertex_float->u.array[s->pcount[i+2]*3+0];
+            vertex_table[k+16] = s->vertex_float->u.array[s->pcount[i+2]*3+1];
+            vertex_table[k+17] = s->vertex_float->u.array[s->pcount[i+2]*3+2];
+	    k+=18;
             l+=4;
 	    size +=2;
         } else if (s->vcount[i]==3) {
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l++]];
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l++]];
-            vertex_table[k++] = s->vertex_float->u.array[vertexp[l++]];
+            vertex_table[k] = s->vertex_float->u.array[s->pcount[i]*3];
+            vertex_table[k+1] = s->vertex_float->u.array[s->pcount[i]*3+1];
+            vertex_table[k+2] = s->vertex_float->u.array[s->pcount[i]*3+2];
+            vertex_table[k+3] = s->vertex_float->u.array[s->pcount[i+1]*3+0];
+            vertex_table[k+4] = s->vertex_float->u.array[s->pcount[i+1]*3+1];
+            vertex_table[k+5] = s->vertex_float->u.array[s->pcount[i+1]*3+2];
+            vertex_table[k+6] = s->vertex_float->u.array[s->pcount[i+2]*3+0];
+            vertex_table[k+7] = s->vertex_float->u.array[s->pcount[i+2]*3+1];
+            vertex_table[k+8] = s->vertex_float->u.array[s->pcount[i+2]*3+2];
+	    k+=9;
 	    size++;
         }
     }