Mercurial > hg > Game > Cerium
annotate Renderer/Engine/Collada.cc @ 2001:3e3cc12096f7 draft
dim_count and self management in multiple TaskList in a TaskArray
author | kkb |
---|---|
date | Fri, 02 May 2014 19:56:25 +0900 |
parents | f40558ec00a8 |
children |
rev | line source |
---|---|
1376 | 1 #include "polygon.h" |
2 #include "SceneGraph.h" | |
3 #include "SceneGraph.cc" | |
4 #include "TextureHash.h" | |
5 #include "xml.h" | |
6 #include "SceneGraphRoot.h" | |
7 #include <iostream> | |
8 #include <SDL_image.h> | |
9 | |
10 using namespace std; | |
11 static TextureHash sgid_hash; | |
12 | |
13 extern int is_bmp(const char* name); | |
14 extern void make_black_alpha(SDL_Surface *texture_image); | |
15 | |
16 typedef struct source { | |
17 char *id; | |
18 union { | |
19 float *array; | |
20 char *alias; | |
21 }u; | |
22 int count; | |
23 struct source *next; | |
24 } SOURCE; | |
25 typedef SOURCE *SOURCE_P; | |
26 | |
27 typedef struct list { | |
28 SOURCE_P first; | |
29 SOURCE_P end; | |
30 } LIST; | |
31 typedef LIST *LIST_P; | |
32 | |
33 struct collada_state { | |
34 collada_state(){ | |
35 polylist = 0; | |
36 | |
37 vertex_offset = -1; | |
38 vertex_count = 0; | |
39 | |
40 normal_offset = -1; | |
41 normal_count = 0; | |
42 | |
43 texcoord_offset = -1; | |
44 texcoord_count = 0; | |
45 | |
46 polylist_count = 0; | |
47 vcsum = 0; | |
48 | |
49 limit = 0; | |
50 vmember = 0; | |
1390 | 51 vtable_size =0; |
1376 | 52 |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
53 images_flag=0; |
1376 | 54 } |
55 int polylist; | |
56 int library_images; | |
57 xmlChar *vertices_id; | |
58 | |
59 char *vertex_src; | |
60 int vertex_offset; | |
61 int vertex_count; | |
62 | |
63 char *normal_src; | |
64 int normal_offset; | |
65 int normal_count; | |
66 | |
67 char *texcoord_src; | |
68 int texcoord_offset; | |
69 int texcoord_count; | |
70 | |
71 float *vcount; | |
72 float *pcount; | |
73 | |
74 SOURCE_P normal_float; | |
75 SOURCE_P vertex_float; | |
76 SOURCE_P texcoord_float; | |
77 | |
78 char *vertices_src; | |
79 int polylist_count; | |
80 | |
81 char *name; | |
82 char *tex_picname; | |
83 | |
84 int images_flag; | |
85 | |
86 int vcsum; | |
87 int limit; | |
88 int vmember; | |
1390 | 89 int vtable_size; |
1376 | 90 }; |
91 | |
92 /*static const char* | |
93 get_property(const char *name, xmlNodePtr cur){ | |
94 xmlAttr *p=cur->properties; | |
95 if (p==0) return ""; | |
96 for ( ;p; p=p->next) { | |
97 if ( xmlStrcmp(p->name, (xmlChar*)name) !=0 ) { | |
98 xmlNode* n=p->children; | |
99 if ( n==NULL ) return ""; | |
100 const char * v=(const char*)n->content; | |
101 if ( v==NULL ) return ""; | |
102 return v; | |
103 } | |
104 } | |
105 return ""; | |
106 }*/ | |
107 | |
108 SDL_Surface* | |
109 load_image(const char *file_name, const char *image_name) | |
110 { | |
111 int alpha_black = is_bmp(file_name); | |
112 /** | |
113 * image を 32bit(RGBA) に変換する | |
114 */ | |
115 SDL_Surface *texture_image = IMG_Load(file_name); | |
116 if (!texture_image) return 0; | |
117 SDL_Surface *tmpImage | |
118 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, | |
119 texture_image->h, 32, redMask, | |
120 greenMask, blueMask, alphaMask); | |
121 //= SDL_CreateRGBSurface(SDL_HWSURFACE, 0, | |
122 // 0, 32, redMask, | |
123 // greenMask, blueMask, alphaMask); | |
124 SDL_Surface *converted; | |
125 converted = SDL_ConvertSurface(texture_image, tmpImage->format, | |
126 SDL_HWSURFACE); | |
127 //SDL_SetAlpha(converted, 0, 0); | |
128 | |
129 if (converted != NULL) { | |
130 SDL_FreeSurface(texture_image); | |
131 texture_image = converted; | |
132 } | |
133 if (alpha_black) { | |
134 make_black_alpha(texture_image); | |
135 } | |
136 // this->gl_tex = SDL_GL_LoadTexture(texture_image); | |
137 return texture_image; | |
138 } | |
139 | |
140 /* add source list */ | |
141 static void | |
142 addSource(LIST_P list, SOURCE_P src) { | |
143 if (list->first == NULL && list->end == NULL) { | |
144 list->first = list->end = src; | |
145 return; | |
146 } | |
147 list->end->next = src; | |
148 list->end = src; | |
149 } | |
150 | |
151 /* compare a with b. Using to compare id */ | |
152 /* | |
153 static int | |
154 strcmp_a(const char *a, const char *b) | |
155 { | |
156 while (*a && *a++ == *b++); | |
157 if (*a) return 0; | |
158 return a[-1] > b[-1] ? 1:-1; | |
159 } | |
160 static float | |
161 get_point(char *id, int position, LIST_P list) | |
162 { | |
163 SOURCE_P cur = list->first; | |
164 for (;cur ; cur=cur->next) { | |
165 if (!strcmp_a(id, cur->id)) { | |
166 if (cur->count == 0) //alias | |
167 return get_point(cur->u.alias, position, list); | |
168 float *a = cur->u.array; | |
169 if (position <= cur->count) { | |
170 return a[position]; | |
171 } | |
172 } | |
173 } | |
174 } | |
175 */ | |
176 | |
177 static SOURCE_P | |
178 most_match(const char *id , LIST_P list) | |
179 { | |
180 SOURCE_P src = NULL; | |
181 SOURCE_P cur = NULL; | |
182 int tmplength = 0; | |
183 int strlength; | |
184 | |
185 for (cur=list->first ;cur!=list->end ;cur=cur->next) { | |
186 for (strlength=0;id[strlength]==cur->id[strlength];strlength++); | |
187 if (tmplength < strlength) { | |
188 tmplength = strlength; | |
189 src = cur; | |
190 } | |
191 } | |
1378 | 192 if (src == NULL){ |
193 fprintf(stderr,"not match"); | |
194 } | |
1376 | 195 return src; |
196 } | |
197 | |
1406 | 198 void get_texture_image(const char *filename, SceneGraphPtr sg, xmlNodePtr cur, TaskManager *manager) |
1376 | 199 { |
1406 | 200 const char image_name[20] = "/tmp/image_XXXXXX"; |
1376 | 201 if (filename == NULL || filename[0] == 0) { |
202 return; | |
203 } | |
204 /** | |
205 * image_name を既に Load していれば何もしない | |
206 */ | |
1391 | 207 int tex_id; |
1376 | 208 /* ball test */ |
1382 | 209 if (sgid_hash.sg_hash_regist(filename, tex_id) == -1) { |
210 SDL_Surface *texture_image = load_image(filename, image_name); | |
211 if (texture_image==0) { | |
1376 | 212 printf("Can't load image %s\n",filename); |
213 exit(0); | |
1382 | 214 } |
1376 | 215 sg->texture_info->texture_id = sg->makeTapestries(manager, texture_image, tex_id); |
1382 | 216 tex_id = sg->texture_info->texture_id; |
1376 | 217 if (unlink(image_name)) { |
1382 | 218 printf("unlink error\n"); |
1376 | 219 } |
220 } else { | |
221 /** | |
222 * 以前に Load されている Texture を共用 | |
223 */ | |
224 sg->texture_info->texture_id = tex_id; | |
225 } | |
1382 | 226 // 微妙に思う、自分で書き換えた感想 by gongo |
227 sg->texture_info->t_w = list[tex_id].t_w; | |
228 sg->texture_info->t_h = list[tex_id].t_h;; | |
229 sg->texture_info->pixels_orig = list[tex_id].pixels_orig; | |
230 sg->texture_info->pixels = list[tex_id].pixels; | |
231 sg->texture_info->scale_max = list[tex_id].scale_max; | |
232 sg->texture_info->texture_image = list[tex_id].texture_image; | |
1376 | 233 } |
234 | |
235 void decode_float_array(xmlNodePtr cur,LIST_P list){ | |
236 SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE)); | |
237 src->id = (char*)xmlGetProp(cur, (xmlChar*)"id"); | |
238 | |
239 src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); | |
240 src->u.array = new float[src->count]; | |
241 char *cont =(char*)xmlNodeGetContent(cur); | |
1384 | 242 |
1376 | 243 /* store float inpoint list */ |
244 for (int i = 0; cont != NULL; i++) { | |
1398 | 245 cont = pickup_float(cont, src->u.array+i); |
1376 | 246 } |
247 | |
248 src->next = NULL; | |
249 addSource(list, src); | |
250 } | |
251 | |
252 | |
253 void | |
254 get_points(xmlNodePtr cur, collada_state *s, TaskManager *manager){ | |
255 char *pcont = (char*)xmlNodeGetContent(cur); | |
256 for (int i = 0;i < s->polylist_count;i++){ | |
257 s->vcsum += s->vcount[i]; | |
258 s->vmember = i; | |
1390 | 259 if (s->vcount[i]==4){ |
260 s->vtable_size +=6; | |
261 } else { | |
262 s->vtable_size +=3; | |
263 } | |
1376 | 264 } |
265 s->limit = s->vcsum * 2; | |
266 if (s->texcoord_offset == 2){ | |
267 s->limit = s->vcsum * 3; | |
268 } | |
269 s->pcount = new float[s->limit]; | |
270 for (int i=0;i<s->limit;i++){ | |
271 s->pcount[i] = 0; | |
272 } | |
273 for (int i=0; pcont != NULL; i++) { | |
274 pcont = pickup_float(pcont, s->pcount+i); | |
275 } | |
276 } | |
277 SceneGraph* | |
278 decode_points(collada_state *s, TaskManager *manager, SceneGraphPtr sg){ | |
1390 | 279 |
1376 | 280 /* |
281 * vertex_tableだけはpolygonを作る際にvcountが4の場合重複する点が | |
282 * 出てくるのでサイズを2倍用意しておく | |
283 */ | |
1399 | 284 |
1376 | 285 float *vertex_table; |
286 float *normal_table; | |
1398 | 287 float *texcoord_table; |
1399 | 288 |
1390 | 289 vertex_table = new float[s->vtable_size*3]; |
290 normal_table = new float[s->vtable_size*3]; | |
291 texcoord_table = new float[s->vtable_size*2]; | |
292 bzero(vertex_table,sizeof(float)*s->vtable_size*3); | |
293 bzero(normal_table,sizeof(float)*s->vtable_size*3); | |
294 bzero(texcoord_table,sizeof(float)*s->vtable_size*2); | |
1392 | 295 /* p separate vertex position and nomal position. */ |
1376 | 296 /* make triangle */ |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
297 int k=0,j=0,l=0,count=0; |
1392 | 298 if (s->texcoord_offset == 2){ |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
299 for (int i=0;i<s->polylist_count;i++) { |
1392 | 300 if (s->vcount[i] == 4) { |
1399 | 301 vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[l]*3]; |
302 vertex_table[k+1] = s->vertex_float->u.array[(int)s->pcount[l]*3+1]; | |
303 vertex_table[k+2] = s->vertex_float->u.array[(int)s->pcount[l]*3+2]; | |
304 vertex_table[k+3] = s->vertex_float->u.array[(int)s->pcount[l+3]*3]; | |
305 vertex_table[k+4] = s->vertex_float->u.array[(int)s->pcount[l+3]*3+1]; | |
306 vertex_table[k+5] = s->vertex_float->u.array[(int)s->pcount[l+3]*3+2]; | |
307 vertex_table[k+6] = s->vertex_float->u.array[(int)s->pcount[l+6]*3]; | |
308 vertex_table[k+7] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+1]; | |
309 vertex_table[k+8] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+2]; | |
310 vertex_table[k+9] = s->vertex_float->u.array[(int)s->pcount[l+6]*3]; | |
311 vertex_table[k+10] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+1]; | |
312 vertex_table[k+11] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+2]; | |
313 vertex_table[k+12] = s->vertex_float->u.array[(int)s->pcount[l+9]*3]; | |
314 vertex_table[k+13] = s->vertex_float->u.array[(int)s->pcount[l+9]*3+1]; | |
315 vertex_table[k+14] = s->vertex_float->u.array[(int)s->pcount[l+9]*3+2]; | |
316 vertex_table[k+15] = s->vertex_float->u.array[(int)s->pcount[l]*3]; | |
317 vertex_table[k+16] = s->vertex_float->u.array[(int)s->pcount[l]*3+1]; | |
318 vertex_table[k+17] = s->vertex_float->u.array[(int)s->pcount[l]*3+2]; | |
319 | |
320 normal_table[k] = s->normal_float->u.array[(int)s->pcount[l+1]*3]; | |
321 normal_table[k+1] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1]; | |
322 normal_table[k+2] = s->normal_float->u.array[(int)s->pcount[l+1]*3*2]; | |
323 normal_table[k+3] = s->normal_float->u.array[(int)s->pcount[l+4]*3]; | |
324 normal_table[k+4] = s->normal_float->u.array[(int)s->pcount[l+4]*3+1]; | |
325 normal_table[k+5] = s->normal_float->u.array[(int)s->pcount[l+4]*3+2]; | |
326 normal_table[k+6] = s->normal_float->u.array[(int)s->pcount[l+7]*3]; | |
327 normal_table[k+7] = s->normal_float->u.array[(int)s->pcount[l+7]*3+1]; | |
328 normal_table[k+8] = s->normal_float->u.array[(int)s->pcount[l+7]*3+2]; | |
329 normal_table[k+9] = s->normal_float->u.array[(int)s->pcount[l+7]*3]; | |
330 normal_table[k+10] = s->normal_float->u.array[(int)s->pcount[l+7]*3+1]; | |
331 normal_table[k+11] = s->normal_float->u.array[(int)s->pcount[l+7]*3+2]; | |
332 normal_table[k+12] = s->normal_float->u.array[(int)s->pcount[l+10]*3]; | |
333 normal_table[k+13] = s->normal_float->u.array[(int)s->pcount[l+10]*3+1]; | |
334 normal_table[k+14] = s->normal_float->u.array[(int)s->pcount[l+10]*3+2]; | |
335 normal_table[k+15] = s->normal_float->u.array[(int)s->pcount[l+1]*3]; | |
336 normal_table[k+16] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1]; | |
337 normal_table[k+17] = s->normal_float->u.array[(int)s->pcount[l+1]*3+2]; | |
338 | |
339 texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[l+2]*2]; | |
340 texcoord_table[j+1] = s->texcoord_float->u.array[(int)s->pcount[l+2]*2+1]; | |
341 texcoord_table[j+2] = s->texcoord_float->u.array[(int)s->pcount[l+5]*2]; | |
342 texcoord_table[j+3] = s->texcoord_float->u.array[(int)s->pcount[l+5]*2+1]; | |
343 texcoord_table[j+4] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2]; | |
344 texcoord_table[j+5] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2+1]; | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
345 |
1399 | 346 texcoord_table[j+6] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2]; |
347 texcoord_table[j+7] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2+1]; | |
348 texcoord_table[j+8] = s->texcoord_float->u.array[(int)s->pcount[l+11]*2]; | |
349 texcoord_table[j+9] = s->texcoord_float->u.array[(int)s->pcount[l+11]*2]; | |
350 texcoord_table[j+10] = s->texcoord_float->u.array[(int)s->pcount[l+14]*2]; | |
351 texcoord_table[j+11] = s->texcoord_float->u.array[(int)s->pcount[l+14]*2]; | |
1392 | 352 |
1399 | 353 l+=12; |
354 j+=12; | |
355 k+=18; | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
356 count +=2; |
1392 | 357 } else if (s->vcount[i]==3) { |
1399 | 358 vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[l]*3]; |
359 vertex_table[k+1] = s->vertex_float->u.array[(int)s->pcount[l]*3+1]; | |
360 vertex_table[k+2] = s->vertex_float->u.array[(int)s->pcount[l]*3+2]; | |
361 vertex_table[k+3] = s->vertex_float->u.array[(int)s->pcount[l+3]*3]; | |
362 vertex_table[k+4] = s->vertex_float->u.array[(int)s->pcount[l+3]*3+1]; | |
363 vertex_table[k+5] = s->vertex_float->u.array[(int)s->pcount[l+3]*3+2]; | |
364 vertex_table[k+6] = s->vertex_float->u.array[(int)s->pcount[l+6]*3]; | |
365 vertex_table[k+7] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+1]; | |
366 vertex_table[k+8] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+2]; | |
367 | |
368 normal_table[k] = s->normal_float->u.array[(int)s->pcount[l+1]*3]; | |
369 normal_table[k+1] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1]; | |
370 normal_table[k+2] = s->normal_float->u.array[(int)s->pcount[l+1]*3*2]; | |
371 normal_table[k+3] = s->normal_float->u.array[(int)s->pcount[l+4]*3]; | |
372 normal_table[k+4] = s->normal_float->u.array[(int)s->pcount[l+4]*3+1]; | |
373 normal_table[k+5] = s->normal_float->u.array[(int)s->pcount[l+4]*3+2]; | |
374 normal_table[k+6] = s->normal_float->u.array[(int)s->pcount[l+7]*3]; | |
375 normal_table[k+7] = s->normal_float->u.array[(int)s->pcount[l+7]*3+1]; | |
376 normal_table[k+8] = s->normal_float->u.array[(int)s->pcount[l+7]*3+2]; | |
377 | |
378 texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[l+2]*2]; | |
379 texcoord_table[j+1] = s->texcoord_float->u.array[(int)s->pcount[l+2]*2+1]; | |
1392 | 380 |
1399 | 381 texcoord_table[j+2] = s->texcoord_float->u.array[(int)s->pcount[l+5]*2]; |
382 texcoord_table[j+3] = s->texcoord_float->u.array[(int)s->pcount[l+5]*2+1]; | |
1398 | 383 |
1399 | 384 texcoord_table[j+4] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2]; |
385 texcoord_table[j+5] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2+1]; | |
1398 | 386 |
1399 | 387 l+=9; |
388 j+=6; | |
389 k+=9; | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
390 count++; |
1392 | 391 } |
392 } | |
393 }else{ | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
394 for (int i=0;i<s->polylist_count;i++) { |
1392 | 395 if (s->vcount[i] == 4) { |
1399 | 396 vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[l]*3]; |
397 vertex_table[k+1] = s->vertex_float->u.array[(int)s->pcount[l]*3+1]; | |
398 vertex_table[k+2] = s->vertex_float->u.array[(int)s->pcount[l]*3+2]; | |
399 vertex_table[k+3] = s->vertex_float->u.array[(int)s->pcount[l+2]*3]; | |
400 vertex_table[k+4] = s->vertex_float->u.array[(int)s->pcount[l+2]*3+1]; | |
401 vertex_table[k+5] = s->vertex_float->u.array[(int)s->pcount[l+2]*3+2]; | |
402 vertex_table[k+6] = s->vertex_float->u.array[(int)s->pcount[l+4]*3]; | |
403 vertex_table[k+7] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+1]; | |
404 vertex_table[k+8] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+2]; | |
405 vertex_table[k+9] = s->vertex_float->u.array[(int)s->pcount[l+4]*3]; | |
406 vertex_table[k+10] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+1]; | |
407 vertex_table[k+11] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+2]; | |
408 vertex_table[k+12] = s->vertex_float->u.array[(int)s->pcount[l+6]*3]; | |
409 vertex_table[k+13] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+1]; | |
410 vertex_table[k+14] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+2]; | |
411 vertex_table[k+15] = s->vertex_float->u.array[(int)s->pcount[l]*3]; | |
412 vertex_table[k+16] = s->vertex_float->u.array[(int)s->pcount[l]*3+1]; | |
413 vertex_table[k+17] = s->vertex_float->u.array[(int)s->pcount[l]*3+2]; | |
414 | |
415 normal_table[k] = s->normal_float->u.array[(int)s->pcount[l+1]*3]; | |
416 normal_table[k+1] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1]; | |
417 normal_table[k+2] = s->normal_float->u.array[(int)s->pcount[l+1]*3+2]; | |
418 normal_table[k+3] = s->normal_float->u.array[(int)s->pcount[l+3]*3]; | |
419 normal_table[k+4] = s->normal_float->u.array[(int)s->pcount[l+3]*3+1]; | |
420 normal_table[k+5] = s->normal_float->u.array[(int)s->pcount[l+3]*3+2]; | |
421 normal_table[k+6] = s->normal_float->u.array[(int)s->pcount[l+5]*3]; | |
422 normal_table[k+7] = s->normal_float->u.array[(int)s->pcount[l+5]*3+1]; | |
423 normal_table[k+8] = s->normal_float->u.array[(int)s->pcount[l+5]*3+2]; | |
424 normal_table[k+9] = s->normal_float->u.array[(int)s->pcount[l+5]*3]; | |
425 normal_table[k+10] = s->normal_float->u.array[(int)s->pcount[l+5]*3+1]; | |
426 normal_table[k+11] = s->normal_float->u.array[(int)s->pcount[l+5]*3+2]; | |
427 normal_table[k+12] = s->normal_float->u.array[(int)s->pcount[l+7]*3]; | |
428 normal_table[k+13] = s->normal_float->u.array[(int)s->pcount[l+7]*3+1]; | |
429 normal_table[k+14] = s->normal_float->u.array[(int)s->pcount[l+7]*3+2]; | |
430 normal_table[k+15] = s->normal_float->u.array[(int)s->pcount[l+1]*3]; | |
431 normal_table[k+16] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1]; | |
432 normal_table[k+17] = s->normal_float->u.array[(int)s->pcount[l+1]*3+2]; | |
433 l+=8; | |
434 k+=18; | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
435 count +=2; |
1392 | 436 } else if (s->vcount[i]==3) { |
1399 | 437 vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[l]*3]; |
438 vertex_table[k+1] = s->vertex_float->u.array[(int)s->pcount[l]*3+1]; | |
439 vertex_table[k+2] = s->vertex_float->u.array[(int)s->pcount[l]*3+2]; | |
440 vertex_table[k+3] = s->vertex_float->u.array[(int)s->pcount[l+2]*3]; | |
441 vertex_table[k+4] = s->vertex_float->u.array[(int)s->pcount[l+2]*3+1]; | |
442 vertex_table[k+5] = s->vertex_float->u.array[(int)s->pcount[l+2]*3+2]; | |
443 vertex_table[k+6] = s->vertex_float->u.array[(int)s->pcount[l+4]*3]; | |
444 vertex_table[k+7] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+1]; | |
445 vertex_table[k+8] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+2]; | |
446 | |
447 normal_table[k] = s->normal_float->u.array[(int)s->pcount[l+1]*3]; | |
448 normal_table[k+1] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1]; | |
449 normal_table[k+2] = s->normal_float->u.array[(int)s->pcount[l+1]*3+22]; | |
450 normal_table[k+3] = s->normal_float->u.array[(int)s->pcount[l+3]*3]; | |
451 normal_table[k+4] = s->normal_float->u.array[(int)s->pcount[l+3]*3+1]; | |
452 normal_table[k+5] = s->normal_float->u.array[(int)s->pcount[l+3]*3+2]; | |
453 normal_table[k+6] = s->normal_float->u.array[(int)s->pcount[l+5]*3]; | |
454 normal_table[k+7] = s->normal_float->u.array[(int)s->pcount[l+5]*3+1]; | |
455 normal_table[k+8] = s->normal_float->u.array[(int)s->pcount[l+5]*3+2]; | |
456 l+=6; | |
457 k+=9; | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
458 count++; |
1392 | 459 } |
460 } | |
1376 | 461 } |
462 | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
463 |
1376 | 464 /** |
465 * (SceneGraph.cc) | |
466 * pickup_normal,pickup_coordinate,pickup_textureの処理 | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
467 * sg->sizeは頂点の数,countは面の数 |
1376 | 468 */ |
1384 | 469 |
1376 | 470 //polygonの作成 |
471 sg->pp_num = (count + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE; | |
472 sg->pp = new PolygonPack[sg->pp_num]; | |
1379
13065ad17328
collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1378
diff
changeset
|
473 sg->name = s->name; |
13065ad17328
collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1378
diff
changeset
|
474 sg->parent_name = "NULL"; |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
475 sg->size = count*3; |
1398 | 476 k = 0; |
1399 | 477 int m = 0; |
1376 | 478 for (int i = 0;i < sg->pp_num; i++ ){ |
1398 | 479 PolygonPackPtr pp = sg->pp; |
1376 | 480 TrianglePackPtr tri = pp[i].tri; |
481 // TrianglePack の size のチェック | |
482 int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; | |
483 pp[i].info.size = tri_size; | |
1398 | 484 /* default texture peste */ |
485 if (s->images_flag==0) { | |
1412
f40558ec00a8
remove duplicated spe task code source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1406
diff
changeset
|
486 const char *default_image = "../Test/xml_file/blend/images/ball.jpg"; // How foolish code is this ... |
1398 | 487 get_texture_image(default_image, sg, (xmlNodePtr)NULL, manager); |
488 } | |
1399 | 489 for (int j = 0; j < tri_size; j++,k+=9) { |
490 tri[j].ver1.x = vertex_table[k]; | |
491 tri[j].ver1.y = vertex_table[k+1]; | |
492 tri[j].ver1.z = vertex_table[k+2]; | |
1376 | 493 |
1399 | 494 tri[j].ver2.x = vertex_table[k+3]; |
495 tri[j].ver2.y = vertex_table[k+4]; | |
496 tri[j].ver2.z = vertex_table[k+5]; | |
1376 | 497 |
1399 | 498 tri[j].ver3.x = vertex_table[k+6]; |
499 tri[j].ver3.y = vertex_table[k+7]; | |
500 tri[j].ver3.z = vertex_table[k+8]; | |
501 | |
502 tri[j].normal1.x = normal_table[k]; | |
503 tri[j].normal1.y = normal_table[k+1]; | |
504 tri[j].normal1.z = normal_table[k+2]; | |
1376 | 505 |
1399 | 506 tri[j].normal2.x = normal_table[k+3]; |
507 tri[j].normal2.y = normal_table[k+4]; | |
508 tri[j].normal2.z = normal_table[k+5]; | |
1376 | 509 |
1399 | 510 tri[j].normal3.x = normal_table[k+6]; |
511 tri[j].normal3.y = normal_table[k+7]; | |
512 tri[j].normal3.z = normal_table[k+8]; | |
513 | |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
514 tri[j].ver1.tex_x = texcoord_table[m]; |
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
515 tri[j].ver1.tex_y = texcoord_table[m+1]; |
1376 | 516 |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
517 tri[j].ver2.tex_x = texcoord_table[m+2]; |
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
518 tri[j].ver2.tex_y = texcoord_table[m+3]; |
1376 | 519 |
1396
ad841dcdbe67
collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents:
1392
diff
changeset
|
520 tri[j].ver3.tex_x = texcoord_table[m+4]; |
1399 | 521 tri[j].ver3.tex_y = texcoord_table[m+5]; |
522 | |
1376 | 523 } |
524 | |
525 } | |
1398 | 526 |
1376 | 527 sg->c_xyz[0] = sg->c_xyz[1] = sg->c_xyz[2] = 0; |
1399 | 528 |
1376 | 529 delete []vertex_table; |
530 delete []normal_table; | |
531 delete []texcoord_table; | |
1399 | 532 |
1376 | 533 /* got out of polylist */ |
534 s->polylist = 0; | |
535 return sg; | |
536 } | |
537 | |
538 static void | |
539 xml_walk(xmlNodePtr cur, struct collada_state *s, LIST_P list,SceneGraphPtr sg, SceneGraphRoot *root) | |
540 { | |
541 int in_polylist=0; | |
542 if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) { | |
543 s->polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); | |
544 s->polylist=1; | |
545 in_polylist=1; | |
546 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) { | |
547 s->vertices_id = xmlGetProp(cur, (xmlChar*)"id"); | |
548 } else if (!xmlStrcmp(cur->name, (xmlChar*)"library_images")) { | |
1378 | 549 s->library_images=1; |
550 //library_images is wrote at texture image name. only use one image file | |
1376 | 551 } else if (s->library_images && !xmlStrcmp(cur->name, (xmlChar*)"init_from")) { |
552 s->tex_picname = (char*)xmlGetProp(cur, (xmlChar*)"init_from"); | |
553 get_texture_image(s->tex_picname, sg, cur , root->tmanager); | |
554 s->library_images=0; | |
555 s->images_flag=1; | |
556 } else if (!s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { | |
557 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); | |
558 if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) { | |
559 s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); | |
560 } | |
561 } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { | |
562 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); | |
563 if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) { | |
564 s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); | |
565 s->vertex_float = most_match(s->vertices_src+1, list); | |
566 } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) { | |
567 s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); | |
568 s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); | |
569 s->normal_float = most_match(s->normal_src+1, list); | |
570 } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"TEXCOORD")) { | |
571 s->texcoord_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); | |
572 s->texcoord_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); | |
573 s->texcoord_float = most_match(s->texcoord_src+1, list); | |
574 } | |
575 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) { | |
576 char *vcont = (char*)xmlNodeGetContent(cur); | |
577 s->vcount = new float[s->polylist_count]; | |
578 for (int i=0; vcont!=NULL; i++) { | |
579 /* store vcount list */ | |
580 vcont = pickup_float(vcont, s->vcount+i); | |
581 } | |
582 } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) { | |
583 get_points(cur,s,root->tmanager); | |
584 in_polylist = 0; | |
585 } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) { | |
586 decode_float_array(cur,list); | |
587 } else if (!xmlStrcmp(cur->name, (xmlChar*)"node" )) { | |
588 s->name = (char*)xmlGetProp(cur, (xmlChar*)"id"); | |
589 } | |
590 for (cur=cur->children; cur; cur=cur->next){ | |
591 xml_walk(cur,s,list,sg,root); | |
592 } | |
593 } | |
594 void | |
595 init_list(LIST_P list) { | |
596 list->first = NULL; | |
597 list->end = NULL; | |
598 } | |
599 | |
600 | |
601 void | |
602 SceneGraphRoot::createFromCOLLADAfile(TaskManager *manager, const char *xmlColladafile) | |
603 { | |
604 /*make parse dom*/ | |
605 xmlDocPtr doc; | |
606 xmlNodePtr cur; | |
607 | |
608 doc = xmlParseFile(xmlColladafile); | |
609 cur = xmlDocGetRootElement(doc); | |
610 | |
611 if (xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){ | |
612 return ; | |
613 } | |
614 | |
615 /* node analyze */ | |
616 struct collada_state s; | |
617 SceneGraphPtr sg = new SceneGraph(manager); | |
618 for (cur=cur->children; cur; cur=cur->next){ | |
619 LIST list; | |
620 init_list(&list); | |
621 xml_walk(cur,&s,&list,sg,this); | |
622 } | |
623 registSceneGraph(decode_points(&s,manager,sg)); | |
624 xmlFreeDoc(doc); | |
625 } |