Can't set position of differents scenes with Collada

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Shomaa
Posts: 15
Joined: Sat Mar 14, 2009 2:28 pm
Location: {Epitech.} Kremlin-Bicetre

Can't set position of differents scenes with Collada

Post by Shomaa »

Hi ,
I've encountered a problem with Irrlicht.
I use a XML for load a Collada scene ,which contains differents elements.
after set the position of each element , i create a bounding box.
But it result that each elements are not totally loaded
(for example my scene contains the same chair and table but at different positions)
the bounding box are visible (for the debug) but the mesh are not visible or in position 0,0,0 , Why ?
i post my code and a snippet of my XML file .

Thanks for the help.

XML file :

Code: Select all

<node type="octTree">

		<String name="Name" value="Sch_Table_AB1" />
		<Int name="Id" value="-1" />
		<vector3d name="Position" value="-10.00717727, 0, 9.614435416" />
		<vector3d name="Rotation" value="0, 0, 0" />
		<vector3d name="Scale" value="1, 1, 1" />
		<String name="Mesh" value="media/pack/Model/Sch_Table_AB.dae" />
		<material Type= "Solid" />

</node>
<node type="octTree">

		<String name="Name" value="Sch_Table_AB2" />
		<Int name="Id" value="-1" />
		<vector3d name="Position" value="-5.978258269, 0, 9.614435416" />
		<vector3d name="Rotation" value="0, 0, 0" />
		<vector3d name="Scale" value="1, 1, 1" />
		<String name="Mesh" value="media/pack/Model/Sch_Table_AB.dae" />
		<material Type= "Solid" />

</node>
<node type="octTree">

		<String name="Name" value="Sch_Table_AB3" />
		<Int name="Id" value="-1" />
		<vector3d name="Position" value="-1.984559006, 0, 9.614435416" />
		<vector3d name="Rotation" value="0, 0, 0" />
		<vector3d name="Scale" value="1, 1, 1" />
		<String name="Mesh" value="media/pack/Model/Sch_Table_AB.dae" />
		<material Type= "Solid" />

</node>
code for loading scene from XML :

Code: Select all

void	Map::LoadXML(std::string pFilename)
{
	Element*	_el;
	std::string temp;
	std::string	pos_;
	std::string rot_;
	std::string sca_;

	vector3df	pos;

	// on charge le fichier XML
	TiXmlDocument doc(pFilename.data());
	if (!doc.LoadFile())
	{
		std::cout << "erreur lors du chargement de la map" << std::endl;
		cerr << "erreur #" << doc.ErrorId() << doc.ErrorDesc()<< std::endl;
	return;
	}
	// on cree une securite dans le cas d'un mauvais formatage du XML et on descend au premier noeud <node>
	TiXmlHandle hdl(&doc);
	TiXmlElement *elem = hdl.FirstChildElement().FirstChildElement().Element();
	// on cree l'element en lui attribuant son nom et un ID factice
	while (elem)
	{
		_el = new Element(elem->Attribute("value"), -1);
	//  on lui attribue son ID
		elem = elem->NextSiblingElement();
	// on lui attribue sa position
		elem = elem->NextSiblingElement();
//		std::cout << elem->Attribute("value") << std::endl;
		temp = elem->Attribute("value");
		pos_ = temp;
	// on lui attribue sa rotation
		elem = elem->NextSiblingElement();
		temp = elem->Attribute("value");
		rot_ = temp;
	// on lui attribue sa dimension
		elem = elem->NextSiblingElement();
		temp = elem->Attribute("value");
		sca_ = temp;
	// on lui attribue le lien du mesh
		elem = elem->NextSiblingElement();
	//	std::cout << elem->Attribute("value") << std::endl;
		_el->SetPathToMesh(elem->Attribute("value"));
	// on regarde de quelle type de material il est compose
		elem = elem->NextSiblingElement();
		std::cout << elem->Attribute("Type") << std::endl;
		_el->SetMaterial(elem->Attribute("Type"));
	// on attribue un node a l'element et on le charge avec le mesh, on lui attribue un mesh de collision
		scene::ITriangleSelector*	_selector = 0;
		scene::IAnimatedMesh* mesh = this->_engine->GetSmgr()->getMesh(_el->GetPathToMesh().data());
		_el->SetNode(this->_engine->GetSmgr()->addAnimatedMeshSceneNode(mesh));
		if (_el->GetTransparency() == "Transparent")
			_el->GetNode()->getMaterial(0).MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;
		_el->GetNode()->setMaterialFlag(irr::video::EMF_LIGHTING,false);

		_el->GetNode()->setTriangleSelector(_selector);
		//_el->_node = this->_engine->GetSmgr()->addOctTreeSceneNode( mesh->getMesh(0),0,-1,512);
		_el->SetNode(this->_engine->GetSmgr()->addMeshSceneNode( mesh->getMesh(0))/*,0,-1,512*/);
	//	_el->_node->setScale(/*_el->GetScale()*/vector3df(1,1,-1));
		_el->GetNode()->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
		_el->GetNode()->setMaterialFlag(video::EMF_FRONT_FACE_CULLING, true);
//		_el->_node->setMaterialFlag(video::EMF_WIREFRAME, true);
		_el->GetNode()->getMaterial(0).EmissiveColor.set(255,0,255,0);

		_el->SetPosition(vector3df(
			atof(this->_engine->getTools2D()->return_substring(pos_,0,',').data()),
			atof(this->_engine->getTools2D()->return_substring(pos_,1,',').data()),
			atof(this->_engine->getTools2D()->return_substring(pos_,2,',').data())));

		_el->SetRotation(vector3df(
			atof(this->_engine->getTools2D()->return_substring(rot_,0,',').data()),
			atof(this->_engine->getTools2D()->return_substring(rot_,1,',').data()),
			atof(this->_engine->getTools2D()->return_substring(rot_,2,',').data())));

		_el->SetScale(vector3df(
			atof(this->_engine->getTools2D()->return_substring(sca_,0,',').data()),
			atof(this->_engine->getTools2D()->return_substring(sca_,1,',').data()),
			atof(this->_engine->getTools2D()->return_substring(sca_,2,',').data())));

		_selector = this->_engine->GetSmgr()->createTriangleSelectorFromBoundingBox(_el->GetNode());
		_meta->addTriangleSelector(_selector);
		_selector->drop();
		_el->GetNode()->setDebugDataVisible(true);

	// on insere l'objet Element dans la liste
		_elementlist.push_back(_el);
	// on passe a l'element suivant
		elem = elem->Parent()->NextSiblingElement();
		if (elem)
			elem = elem->FirstChildElement();
	}
}
and the result :

http://picasaweb.google.com/lh/photo/0o ... directlink
--
Shomaa
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I wouldn't suggest to use Octrees, at least not for Collada models. Those models often have several scene nodes, which does not work in conjunction with octrees at all.
Post Reply