comparison Renderer/Engine/SceneGraphRoot.cc @ 1319:31455d34e502 draft

collada file reader minor changes.
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Sun, 18 Dec 2011 09:39:14 +0900
parents a788b093ef79
children bbfcc1652518
comparison
equal deleted inserted replaced
1318:a788b093ef79 1319:31455d34e502
330 } 330 }
331 331
332 /** 332 /**
333 * co 333 * co
334 */ 334 */
335 static SOURCE 335 static SOURCE_P
336 must_match_id(const char *id_1 ,const char *id_2) 336 most_match(const char *id , LIST_P list)
337 { 337 {
338 SOURCE_P src,cur;
338 int tmplength; 339 int tmplength;
339 char *tmpsrc; 340 int strlength;
340 for (int strlength=0;id_1[i+1]==id_2[i];str_length++); 341 for (cur=list->first ;cur!=list->end ;cur=cur->next) {
341 if (tmplength < strlength) { 342 for (strlength=0;id[strlength+1]==cur->id[strlength];strlength++);
342 tmplength = strlength; 343 if (tmplength < strlength) {
343 tmpsrc = cur; 344 tmplength = strlength;
344 } 345 src = cur;
345 return cur; 346 }
346 } 347 }
347 348 return src;
348 static struct collada_state { 349 }
350
351 struct collada_state {
349 int polylist; 352 int polylist;
353
350 const char *polylist_normal; 354 const char *polylist_normal;
355 const char *polylist_vertex;
356
351 xmlChar *pid; 357 xmlChar *pid;
358
359 char *vertex_src;
360 int vertex_offset;
361 int vertex_count;
362
363 char *normal_src;
364 int normal_offset;
365 int normal_count;
366
367 char *pcont;
368
352 float *vcount; 369 float *vcount;
353 float *pcount; 370 float *pcount;
354 const char *polylist_vertex; 371
372 SOURCE_P normal_float;
373 SOURCE_P vertex_float;
374
375 char *vertices_src;
376 int polylist_count;
355 }; 377 };
356 378
357 static void 379 static void
358 xml_walk(SceneGraphRoot* self, xmlNodePtr cur, struct collada_state *s, LIST_P list) 380 xml_walk(SceneGraphRoot* self, xmlNodePtr cur, struct collada_state *s, LIST_P list)
359 { 381 {
362 384
363 printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children); 385 printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children);
364 386
365 387
366 if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) { 388 if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) {
367 int polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"source")); 389
390 s->polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
368 391
369 s->polylist=1; 392 s->polylist=1;
370 in_polylist=1; 393 in_polylist=1;
394
371 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) { 395 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) {
372 char *vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); 396
373 397 s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
374 s->pid = xmlGetProp(cur, (xmlChar*)"id"); 398
375 s->vcount = malloc(sizeof(int)*count); 399 s->pid = xmlGetProp(cur, (xmlChar*)"id");
376 s->pcount = malloc(sizeof(float)*sum); 400 s->vcount = (float*)malloc(sizeof(float)*s->polylist_count);
401 s->pcount = malloc(sizeof(float)*sum);
377 402
378 403
379 } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { 404 } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) {
380 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); 405
381 if (!xmlStrcmp(semantic, "VERTEX")) { 406 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
382 char *vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); 407
383 int vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); 408 if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) {
409
410 s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
411 s->vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
384 412
385 s->vertex_float = get_hash(vertices_src, s->pid) 413 s->vertex_float = most_match(s->vertices_src, list);
386 414
387 } else if (!xmlStrcmp(semantic, "NORMAL")) { 415 } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) {
388 char *normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); 416
389 int normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); 417 s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
418 s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
390 419
391 s->normal_float = get_hash(normal_src, cur->id); 420 s->normal_float = most_match(s->normal_src, list);
392 } 421 }
393 422
394 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) { 423 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
424
395 char *vcont = (char*)xmlNodeGetContent(cur); 425 char *vcont = (char*)xmlNodeGetContent(cur);
396 for (int i=0; vcount!=NULL; i++) { 426
427 for (int i=0; s->vcont!=NULL; i++) {
397 /* store vcount list */ 428 /* store vcount list */
398 vcont = pickup_float(vcont, vcount+i); 429 vcont = pickup_float(vcont, s->vcount+i);
399 } 430 }
400 }
401 431
402 } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) { 432 } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
403 char *pcont = (char*)xmlNodeGetContent(cur); 433
404 for (int i=0; pcont != NULL; i++) { 434 /* input の source="TEXCOORD" がない場合のみ */
405 pcont = pickup_float(pcont, pcount+i); 435
406 } 436 s->pcont = (char*)xmlNodeGetContent(cur);
407 } 437
438 for (int i=0; s->pcont != NULL; i++) {
439 s->pcont = pickup_float(s->pcont, s->pcount+i);
440 }
408 441
409 442 int vertexp[s->vertex_count];
410 get_point(pid, , cur);
411
412 int vertexp[];
413 int normalp[];
414 443
415 float *vertex_table; 444 float *vertex_table;
416 float *normal_table; 445 float *normal_table;
417 446
418 for (int i = 0; i<polylist_count; i++) { 447 /* まだ<p>のidをどう探してこようか検討中 */
419 vertexp[i] = pcount[2*i]; 448 for (int i = 0; i < s->polylist_count; i++) {
420 normalp[i] = pcount[2*i+1]; 449 vertexp[i] = s->pcount[2*i];
450 normal_table[i] = u.array[s->pcount[2*i+1]];
421 } 451 }
422 452
423 for (int i=0; ;i++) { 453 for (int i=0; vertexp[i];i++) {
424 for (int j=0 ; j > vcont[i] ;j++) { 454 if (s->vcount[i] == 4) {
425 if (vcount[i] == 4) { 455 for (int j=0; j > s->vcont[i]; j++) {
426 456 vertex_table[i] = u.array[vertexp[i]];
427 457 vertex_table[i+3] = u.array[vertexp[i+1]];
428 458 i += 2;
429 } else if (vcount[i] == 3) { 459 }
430 vertex_table[i] = vertex; 460 if (s->vcount[i] == 3) {
431 461 for (int j=0; j > s->vcount[i]; j++) {
432 462 vertex_table[i] = u.array[vertexp[i]];
433 } 463 }
434 } 464 }
435 } 465 }
466 /* ここまで */
467
468 s->polylist = 0;
469 in_polylist = 0;
436 470
437
438 } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) { 471 } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
439 472
440 SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE)); 473 SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
441 474
442 char *id = (char*)xmlGetProp(cur, (xmlChar*)"id"); 475 char *id = (char*)xmlGetProp(cur, (xmlChar*)"id");
443 src->id = (char*)xmlGetProp(cur, (xmlChar*)"id"); 476 src->id = (char*)xmlGetProp(cur, (xmlChar*)"id");
444 477
445 int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); 478 int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
446 src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); 479 src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
447 src->array = (float*)malloc(sizeof(float) * src->count); 480 src->u.array = (float*)malloc(sizeof(float) * src->count);
448 481
449 char *cont =(char*)xmlNodeGetContent(cur); 482 char *cont =(char*)xmlNodeGetContent(cur);
450 //const char *id = get_property("id", cur); 483 //const char *id = get_property("id", cur);
451 //int count = atoi(get_property("count", cur)); 484 //int count = atoi(get_property("count", cur));
452 485
453 /* store float inpoint list */ 486 /* store float inpoint list */
454 for (int i = 0; cont != NULL; i++) { 487 for (int i = 0; cont != NULL; i++) {
455 cont = pickup_float(cont, src->array+i); 488 cont = pickup_float(cont, src->u.array+i);
456 } 489 }
457 490
458 src->next = NULL; 491 src->next = NULL;
459 addSource(list, src); 492 addSource(list, src);
460 printf("id:%s count:%d cont:%s\n", id, count, cont); 493 printf("id:%s count:%d cont:%s\n", id, count, cont);
461 494
462 } 495 }
463 496
464 for (cur=cur->children; cur; cur=cur->next){ 497 for (cur=cur->children; cur; cur=cur->next){
465 xml_walk(self, cur, list); 498 xml_walk(self, cur, s, list);
466 } 499 }
467 } 500 }
468 501
469 void 502 void
470 init_list(LIST_P list) { 503 init_list(LIST_P list) {
488 if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){ 521 if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){
489 return ; 522 return ;
490 } 523 }
491 524
492 /* node analyze */ 525 /* node analyze */
493 struct collada_state s={}; 526 struct collada_state *s;
494 for(cur=cur->children; cur; cur=cur->next){ 527 for(cur=cur->children; cur; cur=cur->next){
495 528
496 LIST list; 529 LIST list;
497 init_list(&list); 530 init_list(&list);
498 531
499 xml_walk(this, cur, &list); 532 xml_walk(this, cur, s, &list);
500 } 533 }
501 xmlFreeDoc(doc); 534 xmlFreeDoc(doc);
502 } 535 }
503 536
504 void 537 void