Example #1
0
void SceneGraphResource::parseNode( XMLNode &xmlNode, SceneNodeTpl *parentTpl )
{
	SceneNodeTpl *nodeTpl = 0x0;

	if( xmlNode.getName() != 0x0 )	// Ignore clear tags like DOCTYPE
	{
		if( strcmp( xmlNode.getName(), "Reference" ) == 0 )
		{
			if( strcmp( xmlNode.getAttribute( "sceneGraph", "" ), "" ) != 0 )
			{
				Resource *res = Modules::resMan().resolveResHandle( Modules::resMan().addResource(
					ResourceTypes::SceneGraph, xmlNode.getAttribute( "sceneGraph" ), 0, false ) );
				if (res != 0x0 ) nodeTpl = new ReferenceNodeTpl( "", (SceneGraphResource *)res );
			}
		}
		else
		{
			NodeRegEntry *entry = Modules::sceneMan().findType( xmlNode.getName() );
			if( entry != 0x0 )
			{
				map< string, string > attribs;
				
				// Parse custom attributes
				XMLAttribute attrib = xmlNode.getFirstAttrib();
				while( !attrib.isEmpty() )
				{
					if( strcmp( attrib.getName(), "name" ) != 0 &&
						strcmp( attrib.getName(), "tx" ) != 0 &&
						strcmp( attrib.getName(), "ty" ) != 0 &&
						strcmp( attrib.getName(), "tz" ) != 0 &&
						strcmp( attrib.getName(), "rx" ) != 0 &&
						strcmp( attrib.getName(), "ry" ) != 0 &&
						strcmp( attrib.getName(), "rz" ) != 0 &&
						strcmp( attrib.getName(), "sx" ) != 0 &&
						strcmp( attrib.getName(), "sy" ) != 0 &&
						strcmp( attrib.getName(), "sz" ) != 0 )
					{
						attribs[attrib.getName()] = attrib.getValue();
					}
					attrib = attrib.getNextAttrib();
				}

				// Call function pointer
				nodeTpl = (*entry->parsingFunc)( attribs );
			}
		}
		
		if( nodeTpl != 0x0 )
		{
			// Parse base attributes
			parseBaseAttributes( xmlNode, *nodeTpl );
			
			// Add to parent
			if( parentTpl != 0x0 )
			{
				parentTpl->children.push_back( nodeTpl );
			}
			else
			{	
				delete _rootNode;	// Delete default root
				_rootNode = nodeTpl;
			}
		}
		else if( strcmp( xmlNode.getName(), "Attachment" ) != 0 )
		{
			Modules::log().writeWarning( "SceneGraph resource '%s': Unknown node type or missing attribute for '%s'",
										 _name.c_str(), xmlNode.getName() );
			return;
		}
	}
	
	// Parse children
	XMLNode xmlNode1 = xmlNode.getFirstChild();
	while( !xmlNode1.isEmpty() )
	{	
		if( xmlNode1.getName() == 0x0 || strcmp( xmlNode1.getName(), "Attachment" ) != 0 )			
			parseNode( xmlNode1, nodeTpl );

		xmlNode1 = xmlNode1.getNextSibling();
	}
}