comparison Renderer/Engine/SceneGraphRoot.cc @ 1317:afe66d75f48a draft

destroid collada file reader.
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Fri, 16 Dec 2011 17:45:57 +0900
parents 53f6855985f6
children a788b093ef79
comparison
equal deleted inserted replaced
1316:53f6855985f6 1317:afe66d75f48a
317 get_point(char *id, int position, LIST_P list) 317 get_point(char *id, int position, LIST_P list)
318 { 318 {
319 SOURCE_P cur = list->first; 319 SOURCE_P cur = list->first;
320 for (;cur ; cur=cur->next) { 320 for (;cur ; cur=cur->next) {
321 if (!strcmp_a(id, cur->id)) { 321 if (!strcmp_a(id, cur->id)) {
322 if (list->count == 0) //alias 322 if (cur->count == 0) //alias
323 return get_point(list->u.alias, position, list); 323 return get_point(cur->u.alias, position, list);
324 float *a = cur->u.array; 324 float *a = cur->u.array;
325 if (position <= list->count) { 325 if (position <= cur->count) {
326 return a[position]; 326 return a[position];
327 } 327 }
328 } 328 }
329 } 329 }
330 } 330 }
331 331
332 /**
333 * co
334 */
332 static SOURCE 335 static SOURCE
333 must_mach_id(const char *id_1 ,const char *id_2) 336 must_match_id(const char *id_1 ,const char *id_2)
334 { 337 {
335 int tmplength; 338 int tmplength;
336 char *tmpsrc; 339 char *tmpsrc;
337 for (int strlength=0;normal_id[i+1]==cur->id[i];str_length++); 340 for (int strlength=0;id_1[i+1]==id_2[i];str_length++);
338 if (tmplength < strlength) { 341 if (tmplength < strlength) {
339 tmplength = strlength; 342 tmplength = strlength;
340 tmpsrc = cur; 343 tmpsrc = cur;
341 } 344 }
342 return cur; 345 return cur;
343 } 346 }
344 347
345 static int polylist=0; 348 static struct collada_state {
346 static const char *polylist_normal=0; 349 int polylist;
347 static const char *polylist_vertex=0; 350 const char *polylist_normal;
348 351 xmlChar *pid;
352 float *vcount;
353 float *pcount;
354 const char *polylist_vertex;
355 };
349 356
350 static void 357 static void
351 xml_walk(SceneGraphRoot* self, xmlNodePtr cur, LIST_P list) 358 xml_walk(SceneGraphRoot* self, xmlNodePtr cur, struct collada_state *s, LIST_P list)
352 { 359 {
353 360
354 int in_polylist=0; 361 int in_polylist=0;
355 362
356 printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children); 363 printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children);
357 364
358 365
359 if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) { 366 if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) {
360 int polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"source")); 367 int polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"source"));
361 368
362 polylist=1; 369 s->polylist=1;
363 in_polylist=1; 370 in_polylist=1;
364 } 371 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices") {
365
366 if (!xmlStrcmp(cur->name, (xmlChar*)"vertices") {
367 char *vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); 372 char *vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
368 373
369 char *pid = (char*)xmlGetProp(cur, (xmlChar*)"id"); 374 s->pid = xmlGetProp(cur, (xmlChar*)"id");
370 float *vcount = malloc(sizeof(int)*count); 375 s->vcount = malloc(sizeof(int)*count);
371 float *pcount = malloc(sizeof(float)*sum); 376 s->pcount = malloc(sizeof(float)*sum);
372 377
373 378
374 } 379 } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input") {
375 if (polylist && !xmlStrcmp(cur->name, (xmlChar*)"input") {
376 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); 380 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
377 if (semantic == "VERTEX") { 381 if (!xmlStrcmp(semantic, "VERTEX")) {
378 char *vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); 382 char *vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
379 int vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); 383 int vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
380 384
381 if (vertex_src == pid) { 385 s->vertex_float = get_hash(vertices_src, s->pid)
382 SOURCE *vertex_float = must_mach_id(vertices_src, pid) 386
383 } 387 } else if (!xmlStrcmp(semantic, "NORMAL")) {
384
385 }
386
387 if (semantic == "NORMAL") {
388 char *normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); 388 char *normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
389 int normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); 389 int normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
390 390
391 SOURCE *normal_float = must_mach_id(normal_src, cur->id); 391 s->normal_float = get_hash(normal_src, cur->id);
392 } 392 }
393 393
394 /* 394 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
395 if (semantic == "TEXCOORD") {
396 char *normal_src = (char*)xmlGetProp(cur, (xmlChar*)"id");
397 int *normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
398 }
399 */
400
401 if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
402 char *vcont = (char*)xmlNodeGetContent(cur); 395 char *vcont = (char*)xmlNodeGetContent(cur);
403 for (int i=0; vcount!=NULL; i++) { 396 for (int i=0; vcount!=NULL; i++) {
397 /* store vcount list */
404 vcont = pickup_float(vcont, vcount+i); 398 vcont = pickup_float(vcont, vcount+i);
405 } 399 }
406 } 400 }
407 401
408 if (!xmlStrcmp(cur->name, (xmlChar*)"p")) { 402 } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
409 char *pcont = (char*)xmlNodeGetContent(cur); 403 char *pcont = (char*)xmlNodeGetContent(cur);
410 for (int i=0; pcont != NULL; i++) { 404 for (int i=0; pcont != NULL; i++) {
411 pcont = pickup_float(pcont, pcount+i); 405 pcont = pickup_float(pcont, pcount+i);
412 } 406 }
413 } 407 }
439 } 433 }
440 } 434 }
441 } 435 }
442 436
443 437
444 } 438 } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
445
446
447 if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
448 439
449 SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE)); 440 SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
450 441
451 char *id = (char*)xmlGetProp(cur, (xmlChar*)"id"); 442 char *id = (char*)xmlGetProp(cur, (xmlChar*)"id");
452 src->id = (char*)xmlGetProp(cur, (xmlChar*)"id"); 443 src->id = (char*)xmlGetProp(cur, (xmlChar*)"id");
457 448
458 char *cont =(char*)xmlNodeGetContent(cur); 449 char *cont =(char*)xmlNodeGetContent(cur);
459 //const char *id = get_property("id", cur); 450 //const char *id = get_property("id", cur);
460 //int count = atoi(get_property("count", cur)); 451 //int count = atoi(get_property("count", cur));
461 452
453 /* store float inpoint list */
462 for (int i = 0; cont != NULL; i++) { 454 for (int i = 0; cont != NULL; i++) {
463 cont = pickup_float(cont, src->array+i); 455 cont = pickup_float(cont, src->array+i);
464 } 456 }
465 457
466 src->next = NULL; 458 src->next = NULL;
467 addSource(list, src); 459 addSource(list, src);
468 printf("id:%s count:%d cont:%s\n", id, count, cont); 460 printf("id:%s count:%d cont:%s\n", id, count, cont);
469 461
470 } 462 }
471 /* 463
472 if (!xmlStrcmp(cur->name, (xmlChar*)"vertices") {
473
474 char *pid = (char*)xmlGetProp(cur, (xmlChar*)"id");
475 float *vcount = malloc(sizeof(int)*count);
476 float *pcount = malloc(sizeof(float)*sum);
477
478 if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
479 char *vcont = (char*)xmlNodeGetContent(cur);
480 for (int i=0; vcount!=NULL; i++) {
481 vcont = pickup_float(vcont, vcount+i);
482 }
483 }
484
485 if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
486 char *pcont = (char*)xmlNodeGetContent(cur);
487 for (int i=0; pcont != NULL; i++) {
488 pcont = pickup_float(pcont, pcount+i);
489 }
490 }
491 }
492
493
494 get_point(pid, , cur);
495
496
497 for (SOURCE *iliner = list->first; list->end != iliner; iliner = iliner->next) {
498 if (!strcmp_a(pid, iliner->id)) {
499 if (vcount == 4) {
500
501
502 } else if (vcount == 3) {
503
504 }
505 }
506 }
507 }
508 */
509
510
511 for (cur=cur->children; cur; cur=cur->next){ 464 for (cur=cur->children; cur; cur=cur->next){
512 xml_walk(self, cur, list); 465 xml_walk(self, cur, list);
513 } 466 }
514 } 467 }
515 468
535 if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){ 488 if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){
536 return ; 489 return ;
537 } 490 }
538 491
539 /* node analyze */ 492 /* node analyze */
493 struct collada_state s={};
540 for(cur=cur->children; cur; cur=cur->next){ 494 for(cur=cur->children; cur; cur=cur->next){
541 495
542 LIST list; 496 LIST list;
543 init_list(&list); 497 init_list(&list);
544 498
545 xml_walk(this, cur, &list); 499 xml_walk(this, cur, &list);
546 /* if(xmlStrcmp(cur->name,(xmlChar*)"library_imeges") != 0){ 500 }
547 cur_images = cur;
548 continue;
549 }
550 if(xmlStrcmp(cur->name,(xmlChar*)"library_effects") != 0){
551 cur_effects = cur;
552 continue;
553 }
554 if(xmlStrcmp(cur->name,(xmlChar*)"library_geometries") != 0){
555 cur_geometries = cur;
556 continue;
557 }
558 if(xmlStrcmp(cur->name,(xmlChar*)"library_visual_scenes")!=0){
559 cur_visual_scenes = cur;
560 continue;
561 }*/
562
563 //tmp = new SceneGraph(manager, cur);
564 //registSceneGraph(tmp);
565 }
566 xmlFreeDoc(doc); 501 xmlFreeDoc(doc);
567 } 502 }
568 503
569 void 504 void
570 SceneGraphRoot::createFromXMLmemory(TaskManager *manager, SceneGraph *node, char *data, int len) 505 SceneGraphRoot::createFromXMLmemory(TaskManager *manager, SceneGraph *node, char *data, int len)