Exemple #1
0
void World::LoadSceneFile(string sceneFile)
{

    Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_LOW);
    Ogre::SceneNode* worldNode = m_sceneMgr->getRootSceneNode()->createChildSceneNode();
    worldNode->rotate(Ogre::Vector3::UNIT_X, Ogre::Degree(-90.0f));

    string meshName;
    float fDrawDistance;
    bool bIsLod;
    Ogre::Vector3 position;
    Ogre::Quaternion rotation;

    ifstream sceneStream(sceneFile);
    // skip the title and the table title of the file
    string strline;

    int i = 0;
    while (!sceneStream.eof())
    {
        getline(sceneStream, strline);

        if (strline.length() == 0)
            continue;

        std::istringstream ss(strline);
        std::string token;

        getline(ss, token, ',');
        boost::trim(token);
        meshName = token;

        getline(ss, token, ',');
        boost::trim(token);
        fDrawDistance = lexical_cast<float>(token);

        getline(ss, token, ',');
        boost::trim(token);
        bIsLod = lexical_cast<bool>(token);

        getline(ss, token, ',');
        boost::trim(token);
        position.x = lexical_cast<float>(token);
        getline(ss, token, ',');
        boost::trim(token);
        position.y = lexical_cast<float>(token);
        getline(ss, token, ',');
        boost::trim(token);
        position.z = lexical_cast<float>(token);

        getline(ss, token, ',');
        boost::trim(token);
        rotation.w = lexical_cast<float>(token);
        getline(ss, token, ',');
        boost::trim(token);
        rotation.x = lexical_cast<float>(token);
        getline(ss, token, ',');
        boost::trim(token);
        rotation.y = lexical_cast<float>(token);
        getline(ss, token, ',');
        boost::trim(token);
        rotation.z = lexical_cast<float>(token);

		
        Ogre::MeshPtr mesh;
		Ogre::Entity* entity;
	
		Ogre::Entity* realEntity = m_sceneMgr->createEntity(meshName);
		
		if (fDrawDistance > 300.0f && !bIsLod)
			continue;
		
        if (bIsLod)
        {
            mesh = Ogre::MeshManager::getSingleton().createManual(meshName + "lod" + std::to_string(i), "General"); // empty mesh
			mesh->createManualLodLevel(0, "NULL");
			mesh->createManualLodLevel(700, meshName);
			mesh->_setBounds( realEntity->getMesh()->getBounds());
			mesh->_setBoundingSphereRadius(realEntity->getMesh()->getBoundingSphereRadius());
			mesh->load();
			entity->setRenderingDistance(fDrawDistance);
			entity = m_sceneMgr->createEntity(mesh->getName());
        }
        else
        {
            mesh = Ogre::MeshManager::getSingleton().getByName(meshName);
			entity = m_sceneMgr->createEntity(meshName);
			entity->setRenderingDistance(fDrawDistance);
        }
        m_sceneMgr->destroyEntity(realEntity);


        Ogre::SceneNode* sceneNode = worldNode->createChildSceneNode();
        sceneNode->attachObject(entity);

        fix_gta_coord(rotation);

        sceneNode->rotate(rotation);
        sceneNode->setPosition(position);
        i++;
    }

    worldNode->setScale(5.0f, 5.0f, 5.0f);

    sceneStream.close();
    Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_NORMAL);
}