コード例 #1
0
SceneGraphViewer::SceneGraphViewer(int numArguments,const char* const arguments[])
	{
	/* Create a node creator: */
	SceneGraph::NodeCreator nodeCreator;
	
	/* Create the scene graph's root node: */
	root=new SceneGraph::GroupNode;
	
	/* Load all VRML files from the command line: */
	for(int i=0;i<numArguments;++i)
		{
		IO::AutoFile inputFile(Vrui::openFile(arguments[i]));
		SceneGraph::VRMLFile vrmlFile(arguments[i],*inputFile,nodeCreator,getMulticastPipeMultiplexer());
		vrmlFile.parse(root);
		}
	}
コード例 #2
0
ファイル: SceneGraphViewer.cpp プロジェクト: jrevote/3DA-Vrui
SceneGraphViewer::SceneGraphViewer(int numArguments,const char* const arguments[])
	{
	/* Create a node creator: */
	SceneGraph::NodeCreator nodeCreator;
	
	/* Create the scene graph's root node: */
	root=new SceneGraph::GroupNode;
	
	/* Load all VRML files from the command line: */
	for(int i=0;i<numArguments;++i)
		{
		Misc::FileCharacterSource inputFile(arguments[i]);
		SceneGraph::VRMLFile vrmlFile(arguments[i],inputFile,nodeCreator);
		vrmlFile.parse(root);
		}
	}
コード例 #3
0
VruiSceneGraphDemo::VruiSceneGraphDemo(int& argc,char**& argv)
	:Vrui::Application(argc,argv),
	 mainMenuPopup(0)
	{
	/* Collect a list of scene graph names to build a menu later: */
	std::vector<std::string> sceneGraphNames;
	
	if(argc>1)
		{
		/*************************************************
		Load scene graphs from one or more VRML 2.0 files:
		*************************************************/
		
		/* Create a node creator to parse the VRML files: */
		SceneGraph::NodeCreator nodeCreator;
		
		/* Load all VRML files from the command line: */
		for(int i=1;i<argc;++i)
			{
			try
				{
				/* Create the new scene graph's root node: */
				SceneGraph::GroupNodePointer root=new SceneGraph::GroupNode;
				
				/* Load and parse the VRML file: */
				SceneGraph::VRMLFile vrmlFile(argv[i],Vrui::openFile(argv[i]),nodeCreator,Vrui::getClusterMultiplexer());
				vrmlFile.parse(root);
				
				/* Add the new scene graph to the list: */
				sceneGraphs.push_back(root);
				sceneGraphEnableds.push_back(true);
				}
			catch(std::runtime_error err)
				{
				/* Print an error message and try the next file: */
				std::cerr<<"Ignoring input file "<<argv[i]<<" due to exception "<<err.what()<<std::endl;
				}
			
			/* Remember the name of this scene graph: */
			const char* start=argv[i];
			const char* end=0;
			for(const char* cPtr=argv[i];*cPtr!='\0';++cPtr)
				{
				if(*cPtr=='/')
					{
					start=cPtr+1;
					end=0;
					}
				if(*cPtr=='.')
					end=cPtr;
				}
			if(end!=0)
				sceneGraphNames.push_back(std::string(start,end));
			else
				sceneGraphNames.push_back(std::string(start));
			}
		}
	else
		{
		/* Create a small scene graph: */
		SceneGraph::TransformNode* transform=new SceneGraph::TransformNode;
		SceneGraph::GroupNodePointer root=transform;
		
		SceneGraph::ShapeNode* shape=new SceneGraph::ShapeNode;
		root->children.appendValue(shape);
		
		SceneGraph::AppearanceNode* appearance=new SceneGraph::AppearanceNode;
		shape->appearance.setValue(appearance);
		
		SceneGraph::MaterialNode* material=new SceneGraph::MaterialNode;
		appearance->material.setValue(material);
		material->ambientIntensity.setValue(1.0f);
		material->diffuseColor.setValue(SceneGraph::Color(1.0f,0.0f,0.0f));
		material->specularColor.setValue(SceneGraph::Color(1.0f,1.0f,1.0f));
		material->shininess.setValue(0.2f);
		material->update();
		
		appearance->update();
		
		SceneGraph::BoxNode* box=new SceneGraph::BoxNode;
		shape->geometry.setValue(box);
		box->size.setValue(SceneGraph::Size(2,2,2));
		box->update();
		
		shape->update();
		
		root->update();
		
		sceneGraphs.push_back(root);
		sceneGraphEnableds.push_back(true);
		sceneGraphNames.push_back("Box");
		}
	
	/* Create a popup shell to hold the main menu: */
	mainMenuPopup=new GLMotif::PopupMenu("MainMenuPopup",Vrui::getWidgetManager());
	mainMenuPopup->setTitle("Scene Graph Viewer");
	
	/* Create the main menu itself: */
	GLMotif::Menu* mainMenu=new GLMotif::Menu("MainMenu",mainMenuPopup,false);
	
	/* Add a toggle button for each scene graph: */
	unsigned int numSceneGraphs=sceneGraphs.size();
	for(unsigned int i=0;i<numSceneGraphs;++i)
		{
		char toggleName[40];
		snprintf(toggleName,sizeof(toggleName),"SceneGraphToggle%u",i);
		GLMotif::ToggleButton* sceneGraphToggle=new GLMotif::ToggleButton(toggleName,mainMenu,sceneGraphNames[i].c_str());
		sceneGraphToggle->setToggle(sceneGraphEnableds[i]);
		sceneGraphToggle->getValueChangedCallbacks().add(this,&VruiSceneGraphDemo::sceneGraphToggleCallback,i);
		}
	
	mainMenu->manageChild();
	Vrui::setMainMenu(mainMenuPopup);
	
	/* Set the navigation transformation: */
	SceneGraph::Box bbox=SceneGraph::Box::empty;
	for(unsigned int i=0;i<numSceneGraphs;++i)
		bbox.addBox(sceneGraphs[i]->calcBoundingBox());
	Vrui::setNavigationTransformation(Geometry::mid(bbox.min,bbox.max),Geometry::dist(bbox.min,bbox.max));
	}
コード例 #4
0
VruiSceneGraphDemo::VruiSceneGraphDemo(int& argc,char**& argv,char**& appDefaults)
	:Vrui::Application(argc,argv,appDefaults)
	{
	if(argc>1)
		{
		/*************************************************
		Load scene graphs from one or more VRML 2.0 files:
		*************************************************/
		
		/* Create a node creator to parse the VRML files: */
		SceneGraph::NodeCreator nodeCreator;
		
		/* Create the scene graph's root node: */
		root=new SceneGraph::GroupNode;
		
		/* Load all VRML files from the command line: */
		for(int i=1;i<argc;++i)
			{
			try
				{
				SceneGraph::VRMLFile vrmlFile(argv[i],Vrui::openFile(argv[i]),nodeCreator,Vrui::getClusterMultiplexer());
				vrmlFile.parse(root);
				}
			catch(std::runtime_error err)
				{
				/* Print an error message and try the next file: */
				std::cerr<<"Ignoring input file "<<argv[i]<<" due to exception "<<err.what()<<std::endl;
				}
			}
		}
	else
		{
		/* Create a small scene graph: */
		SceneGraph::TransformNode* transform=new SceneGraph::TransformNode;
		root=transform;
		
		SceneGraph::ShapeNode* shape=new SceneGraph::ShapeNode;
		root->children.appendValue(shape);
		
		SceneGraph::AppearanceNode* appearance=new SceneGraph::AppearanceNode;
		shape->appearance.setValue(appearance);
		
		SceneGraph::MaterialNode* material=new SceneGraph::MaterialNode;
		appearance->material.setValue(material);
		material->ambientIntensity.setValue(1.0f);
		material->diffuseColor.setValue(SceneGraph::Color(1.0f,0.0f,0.0f));
		material->specularColor.setValue(SceneGraph::Color(1.0f,1.0f,1.0f));
		material->shininess.setValue(0.2f);
		material->update();
		
		appearance->update();
		
		SceneGraph::BoxNode* box=new SceneGraph::BoxNode;
		shape->geometry.setValue(box);
		box->size.setValue(SceneGraph::Size(2,2,2));
		box->update();
		
		shape->update();
		
		root->update();
		}
	
	/* Set the navigation transformation: */
	SceneGraph::Box bbox=root->calcBoundingBox();
	Vrui::setNavigationTransformation(Geometry::mid(bbox.min,bbox.max),Geometry::dist(bbox.min,bbox.max));
	}