Пример #1
0
void loadScript(std::string fileName)
{
    DataStreamPtr pStream = ResourceGroupManager::getSingleton().openResource(
                fileName,
                "LuaScripts");

    String data = pStream.getPointer()->getAsString();
    interpret(data.c_str());
    pStream.getPointer()->close();
    pStream.setNull();
}
Пример #2
0
//Implementation---------------------------------------------------------------
void OgreMaxUtilities::LoadXmlDocument(const String& fileName, TiXmlDocument& document, const String& resourceGroupName)
{
    //Open the file
    DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource(fileName, resourceGroupName);
    if (stream.isNull())
    {
        StringUtil::StrStreamType errorMessage;
        errorMessage << "Could not open XML file: " << fileName;

        OGRE_EXCEPT
            (
            Exception::ERR_FILE_NOT_FOUND,
		    errorMessage.str(), 
		    "OgreMaxUtilities::LoadXmlDocument"
            );
    }

    //Get the file contents
    String data = stream->getAsString();
    
    //Parse the XML document
    document.Parse(data.c_str());
    stream.setNull();
    if (document.Error())
    {
        StringUtil::StrStreamType errorMessage;
        errorMessage << "There was an error with the XML file: " << fileName;

        OGRE_EXCEPT
            (
            Exception::ERR_INVALID_STATE,
		    errorMessage.str(), 
		    "OgreMaxUtilities::LoadXmlDocument"
            );
    }
}
Пример #3
0
void DotSceneLoader::parseDotScene(const String &SceneName, const String &groupName, SceneManager *yourSceneMgr, SceneNode *pAttachNode, const String &sPrependNode)
{
    // set up shared object values
    m_sGroupName = groupName;
    mSceneMgr = yourSceneMgr;
    m_sPrependNode = sPrependNode;
    staticObjects.clear();
    dynamicObjects.clear();
 
    TiXmlDocument   *XMLDoc = 0;
    TiXmlElement   *XMLRoot;
 
    try
    {
        // Strip the path
        Ogre::String basename, path;
        Ogre::StringUtil::splitFilename(SceneName, basename, path);
 
        DataStreamPtr pStream = ResourceGroupManager::getSingleton().
            openResource( basename, groupName );
 
        //DataStreamPtr pStream = ResourceGroupManager::getSingleton().
        //    openResource( SceneName, groupName );
 
        String data = pStream->getAsString();
        // Open the .scene File
        XMLDoc = new TiXmlDocument();
        XMLDoc->Parse( data.c_str() );
        pStream->close();
        pStream.setNull();
 
        if( XMLDoc->Error() )
        {
            //We'll just log, and continue on gracefully
            LogManager::getSingleton().logMessage("[DotSceneLoader] The TiXmlDocument reported an error");
            delete XMLDoc;
            return;
        }
    }
    catch(...)
    {
        //We'll just log, and continue on gracefully
        LogManager::getSingleton().logMessage("[DotSceneLoader] Error creating TiXmlDocument");
        delete XMLDoc;
        return;
    }
 
    // Validate the File
    XMLRoot = XMLDoc->RootElement();
    if( String( XMLRoot->Value()) != "scene"  ) {
        LogManager::getSingleton().logMessage( "[DotSceneLoader] Error: Invalid .scene File. Missing <scene>" );
        delete XMLDoc;      
        return;
    }
 
    // figure out where to attach any nodes we create
    mAttachNode = pAttachNode;
    if(!mAttachNode)
        mAttachNode = mSceneMgr->getRootSceneNode();
 
    // Process the scene
    processScene(XMLRoot);
 
    // Close the XML File
    delete XMLDoc;
}
Пример #4
0
void DotSceneLoader::parseDotScene(const String &SceneName, const String &groupName, SceneManager *yourSceneMgr, CPhysicsManager *pPhysicsManager, SceneNode *pAttachNode, const String &sPrependNode)
{
	cleanup();

    Ogre::LogManager::getSingleton().logMessage("Loading dot scene: " + SceneName);
    // set up shared object values
    m_sGroupName = groupName;
    mSceneMgr = yourSceneMgr;
	m_pPhysicsManager = pPhysicsManager;
    m_sPrependNode = sPrependNode;


	mStaticSceneNode = pAttachNode->createChildSceneNode(sPrependNode + "StaticSceneNode");

    XMLDocument   *XMLDoc = 0;
    XMLElement   *XMLRoot;

    try
    {
        // Strip the path
        Ogre::String basename, path;
        Ogre::StringUtil::splitFilename(SceneName, basename, path);

        // Do not look in other groups but the given one
        DataStreamPtr pStream = ResourceGroupManager::getSingleton().
            openResource( basename, groupName, false );

        //DataStreamPtr pStream = ResourceGroupManager::getSingleton().
        //    openResource( SceneName, groupName );

        String data = pStream->getAsString();
        // Open the .scene File
        XMLDoc = new XMLDocument();
        XMLDoc->Parse( data.c_str() );
        pStream->close();
        pStream.setNull();

        if( XMLDoc->Error() )
        {
            //We'll just log, and continue on gracefully
            LogManager::getSingleton().logMessage("[DotSceneLoader] The TiXmlDocument reported an error");
            delete XMLDoc;
            return;
        }
    }
    catch(...)
    {
        //We'll just log, and continue on gracefully
        LogManager::getSingleton().logMessage("[DotSceneLoader] Error creating TiXmlDocument");
        delete XMLDoc;
        return;
    }

    // Validate the File
    XMLRoot = XMLDoc->RootElement();
    if( String( XMLRoot->Value()) != "scene"  ) {
        LogManager::getSingleton().logMessage( "[DotSceneLoader] Error: Invalid .scene File. Missing <scene>" );
        delete XMLDoc;
        return;
    }

    // figure out where to attach any nodes we create
    mAttachNode = pAttachNode;
    if(!mAttachNode)
        mAttachNode = mSceneMgr->getRootSceneNode();

    // Process the scene
    processScene(XMLRoot);

	/*for (auto &m : m_mStaticGeometryMap) {
		m.second->build();
	}*/

	/*for (auto &s : mStaticObjects) {
		for (auto &cb : m_lCallbacks){
			cb->staticObjectAdded(s);
		}
	}
	// remove static geometry entities
	destroySceneNode(mStaticSceneNode);*/


	// apply manually material data
	// ===============================

	// dont cull grass
	auto mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("CS_Grass"));
	if (!mat.isNull() && mat->getBestTechnique()) {
		mat->getBestTechnique()->setCullingMode(Ogre::CullingMode::CULL_NONE);
	}

	// make water transparent, add textures
	mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("Water"));
	if (!mat.isNull() && mat->getBestTechnique()) {
		mat->getBestTechnique()->setCullingMode(Ogre::CullingMode::CULL_NONE);
		mat->getBestTechnique()->getPass(0)->setDepthCheckEnabled(true);
		mat->getBestTechnique()->getPass(0)->setDepthWriteEnabled(false);
		mat->getBestTechnique()->getPass(0)->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE);
		mat->getBestTechnique()->getPass(0)->getTextureUnitState(0)->setTransformAnimation(
			Ogre::TextureUnitState::TT_TRANSLATE_U, Ogre::WFT_SINE, 0, 0.25, 0, 0.125);
		mat->getBestTechnique()->getPass(0)->getTextureUnitState(0)->setColourOperation(Ogre::LBO_MODULATE);
		mat->getBestTechnique()->getPass(0)->getTextureUnitState(1)->setTransformAnimation(
			Ogre::TextureUnitState::TT_TRANSLATE_V, Ogre::WFT_SINE, 0.1, 0.25, 0.1, 0.125);
		mat->getBestTechnique()->getPass(0)->getTextureUnitState(1)->setTextureRotate(Ogre::Degree(90));
		mat->getBestTechnique()->getPass(0)->getTextureUnitState(1)->setColourOperation(Ogre::LBO_MODULATE);
		mat->getBestTechnique()->getPass(0)->setDiffuse(1, 1, 1, 0.8);
	}

	/*for (auto &m : m_lEntityBufferMap) {
		mSceneMgr->destroyEntity(m.second);
	}*/

    // Close the XML File
    delete XMLDoc;

	// remove callbacks
	m_lCallbacks.clear();
  cleanup();
}