Exemple #1
0
osg::ref_ptr<osg::Node> osgDB::readRefNodeFile(const std::string& filename,const Options* options)
{
    ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename,options);
    if (rr.validNode()) return osg::ref_ptr<osg::Node>(rr.getNode());
    if (rr.error()) OSG_WARN << rr.message() << std::endl;
    return NULL;
}
void TouchDesigner::preFrame() {
	string data = "";

	//	cerr << "painting\t" << endl;
	if (ComController::instance()->isMaster()) // head node
	{
		data = st->getSerializedScene();
		dsize = data.size();

		//		cerr << "in master doing nothing" << endl;
		ComController::instance()->sendSlaves(&dsize, sizeof(int));
		ComController::instance()->sendSlaves(&data[0], dsize);
		ComController::instance()->sendSlaves(&received, sizeof(bool));
	} else // rendering nodes
	{
		//		cerr<<"slave node"<<endl;	
		ComController::instance()->readMaster(&dsize, sizeof(int));
		recvData.resize(dsize);
		ComController::instance()->readMaster(&recvData[0], dsize);
		data = recvData;
		ComController::instance()->readMaster(&received, sizeof(bool));
	}



		//cerr << "data size\t" << dsize << endl;
	std::stringstream ss(data);
	osgDB::ReaderWriter * readerwriter =
		Registry::instance()->getReaderWriterForExtension("ive");
	ReaderWriter::ReadResult result = readerwriter->readNode(ss);

	if (result.validNode()) {
		//printf("Node valid\n");
		//cerr<<"Valid Node"<<endl;
		Node * node = result.getNode();
		/*			
		osg::Geode * geode = dynamic_cast<osg::Geode* > (node);

		if( geode )
		{
		for(int i = 0; i < geode->getNumDrawables(); i++)
		{
		osg::Geometry* geom = dynamic_cast<osg::Geometry*> (geode->getDrawable(i));

		if( geom )
		{
		osg::Vec3Array* array = dynamic_cast<osg::Vec3Array *> (geom->getVertexArray());

		for(int j =0; j < array->size(); j++)
		{
		cerr << array->at(0)[0] << " " << array->at(0)[1] << " " << array->at(0)[2] << endl;
		}
		}
		}	
		}
		*/
		osg::Group * objectRoot = SceneManager::instance()->getObjectsRoot();

		// remove all children and add new node
	  objectRoot->addChild(node);

		if (prevNode)
			objectRoot->removeChild(prevNode);

		prevNode = node;
		


		// lets see if directly reassigning the entire thing works?
		// TODO err, is there a way to assign the root object as node?
		//SceneManager::instance()->getObjectsRoot() = node->asGroup();

	}

	//cerr << "" << endl;

}