changeset 1284:fe598e9b7f0e draft

improve collada file
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Fri, 25 Nov 2011 18:43:21 +0900
parents fe78feb16a8c
children e38a4f3e238d 6fc9fd03a4fd 90efd2aac2cb
files Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/viewer.h Renderer/Test/Makefile.macosx Renderer/Test/collada.cc
diffstat 4 files changed, 61 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Fri Nov 25 17:20:45 2011 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Fri Nov 25 18:43:21 2011 +0900
@@ -241,6 +241,37 @@
     xmlFreeDoc(doc);
 }
 
+static const char*
+get_property(const char *name, xmlNodePtr cur){
+   xmlAttr *p=cur->properties; 
+   if (p==0) return "";
+   for ( ;p; p=p->next) {
+       if ( xmlStrcmp(p->name, (xmlChar*)name) !=0 ) {
+	   xmlNode* n=p->children;
+	  if ( n==NULL ) return "";
+	  const char * v=(const char*)n->content;
+	  if ( v==NULL ) return "";
+	  return v;
+       }
+   }
+   return "";
+}
+
+static void 
+xml_walk( SceneGraphRoot* self, xmlNodePtr cur)
+{
+	printf("name = %s\n", cur->name);
+	if(xmlStrcmp(cur->name,(xmlChar*)"float_array") != 0){
+	    const char *id = get_property("id", cur);
+	    int count = atoi(get_property("count", cur));
+	    printf("id:%s count:%d\n", id, count);
+	
+	}
+	for (cur=cur->children; cur; cur=cur->next){
+		xml_walk(self, cur);
+	}
+}	
+
 void
 SceneGraphRoot::createFromCOLLADAfile(TaskManager *manager, const char *xmlColladafile)
 {
@@ -258,9 +289,11 @@
        };
 
 	/* node analyze */
-	for(cur=cur->children; cur_images; cur_images=cur_images->next){
+	for(cur=cur->children; cur; cur=cur->next){
 
-	  if(xmlStrcmp(cur->name,(xmlChar*)"library_imeges") != 0){
+	    
+	    xml_walk(this, cur);
+	 /* if(xmlStrcmp(cur->name,(xmlChar*)"library_imeges") != 0){
 	    cur_images = cur;
 	    continue;
 	  }
@@ -275,10 +308,10 @@
 	  if(xmlStrcmp(cur->name,(xmlChar*)"library_visual_scenes")!=0){
 	    cur_visual_scenes = cur;
 	    continue;
-	  }
+	  }*/
 	  
-	  tmp = new SceneGraph(manager, cur);
-	  registSceneGraph(tmp);
+	  //tmp = new SceneGraph(manager, cur);
+	  //registSceneGraph(tmp);
 	}
 	xmlFreeDoc(doc);
 }
--- a/Renderer/Engine/viewer.h	Fri Nov 25 17:20:45 2011 +0900
+++ b/Renderer/Engine/viewer.h	Fri Nov 25 18:43:21 2011 +0900
@@ -139,6 +139,11 @@
 	sgroot->createFromXMLfile(manager, file);
     }
 
+    void createFromCOLLADAfile(const char *file)
+    {
+	sgroot->createFromCOLLADAfile(manager, file);
+    }
+
     Pad * getController()
     {
       return sgroot->getController();
--- a/Renderer/Test/Makefile.macosx	Fri Nov 25 17:20:45 2011 +0900
+++ b/Renderer/Test/Makefile.macosx	Fri Nov 25 18:43:21 2011 +0900
@@ -13,7 +13,7 @@
 %.pb.cc: $(PROTODIR)/%.proto
 	$(PROTO) $(PROTOFLAGS) $<
 
-ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange viewer viewer_2 light_test aquarium network init_aquarium test_linda
+ALL =  collada ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange viewer viewer_2 light_test aquarium network init_aquarium test_linda
 
 all: $(ALL)
 
@@ -21,6 +21,10 @@
 print_string : $(STR_OBJ)
 	$(CC) $(CFLAGS) -o $@ $?   $(LIBS)
 
+COLLADA_OBJ = collada.o
+collada : $(COLLADA_OBJ) 
+	$(CC) $(CFLAGS) -o $@ $?   $(LIBS)
+
 BALL_BOUND_OBJ = ball_bound.o
 ball_bound : $(BALL_BOUND_OBJ) 
 	$(CC) $(CFLAGS) -o $@ $?   $(LIBS)
--- a/Renderer/Test/collada.cc	Fri Nov 25 17:20:45 2011 +0900
+++ b/Renderer/Test/collada.cc	Fri Nov 25 18:43:21 2011 +0900
@@ -106,11 +106,13 @@
   }
 }
 
+static const char *collada_file="collada_file/ball.dae";
+static const char *name="Ball";
+
 MainLoopPtr 
 ball_bound::init(Viewer *sgroot, int screen_w, int screen_h)
 {
     SceneGraphPtr ball;
-    char *collada_file;
     
     // 固定した値で srandom すると、毎回同じ、random() 列が生成される
     // random な値が欲しいなら、man random に方法が書いてあります。
@@ -126,7 +128,7 @@
     light->xyz[1] = screen_h / 2;
     light->xyz[2] = -100;
 
-    ball = sgroot->createSceneGraph("Ball");
+    ball = sgroot->createSceneGraph(name);
     ball->set_move_collision(ball_move, ball_collision);
 
     h0 = screen_h/2;
@@ -156,6 +158,15 @@
 int
 TMmain(TaskManager *manager, int argc, char *argv[])
 {
+    for(int i=1; i<argc; i++){
+        if (argv[i][0] == '-' && argv[i][1] == 's') {
+	    i++;
+	    collada_file=argv[i];
+	} else if (argv[i][0] == '-' && argv[i][1] == 'n') {
+	    i++;
+	    name = argv[i];
+	}
+    }
     task_initialize();
     manager->set_TMend(TMend);
     return init(manager, argc, argv);