Beispiel #1
0
void CaelumPlugin::loadCaelumSystemFromScript(CaelumSystem* sys, const Ogre::String& objectName, const Ogre::String& groupName)
{
  assert(sys);
  assert(this->isInstalled () && "Must install CaelumPlugin before loading scripts");

  // Fetch raw resource ptr. Attempt to support explicit resource groups currently in Ogre trunk.
#if OGRE_VERSION >= 0x00010700
  Ogre::ResourcePtr res = getPropScriptResourceManager()->getByName(objectName, groupName);
#else
  Ogre::ResourcePtr res = getPropScriptResourceManager ()->getByName (objectName);
#endif

  // Check a PropScriptResource was found.
  PropScriptResource* propRes = static_cast<PropScriptResource*>(res.get());
  if (!propRes) {
    OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Could not find caelum_sky_system " + objectName, "CaelumPlugin::loadCaelumSystemFromScript");
  }

  // Fetch the resource stream. Look in the actual group of the resource!
  const Ogre::String& scriptFileName = propRes->getOrigin();
  const Ogre::String& scriptFileGroup = propRes->getGroup();
  Ogre::DataStreamPtr streamPtr = Ogre::ResourceGroupManager::getSingleton().openResource(scriptFileName, scriptFileGroup, false);

  // Feed it into the compiler.
  this->getScriptTranslatorManager()->getCaelumSystemTranslator()->setTranslationTarget(sys, objectName);
  Ogre::ScriptCompilerManager::getSingleton().parseScript(streamPtr, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
  bool found = this->getScriptTranslatorManager()->getCaelumSystemTranslator()->foundTranslationTarget();

  // This shouldn't normally happen.
  if (!found) {
    OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Could not find caelum_sky_system " + objectName + " in file " + scriptFileName + " on reparsing. "
    "Perhaps information in PropScriptResourceManager is out of date?", "CaelumPlugin::loadCaelumSystemFromScript");
  }
  this->getScriptTranslatorManager()->getCaelumSystemTranslator()->clearTranslationTarget();
}
Beispiel #2
0
Icon* IconManager::getIcon(int, EmberEntity* entity)
{

	std::string key = "entity_" + entity->getId();
	if (mIconStore.hasIcon(key)) {
		return mIconStore.getIcon(key);
	} else {
		IconActionCreator actionCreator(*entity);
		std::unique_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(*entity, actionCreator, &EmberOgre::getSingleton().getWorld()->getView()));
		std::string modelName;
		if (modelMapping.get()) {
			modelMapping->initialize();
			modelName = actionCreator.getModelName();
		}
		//if there's no model defined for this use the placeholder model
		if (modelName == "") {
			modelName = "placeholder";
		}
		Ogre::ResourcePtr modelDefPtr = Model::ModelDefinitionManager::getSingleton().getByName(modelName);
		if (!modelDefPtr.isNull()) {
			Model::ModelDefinition* modelDef = static_cast<Model::ModelDefinition*> (modelDefPtr.get());
			const std::string& iconPath(modelDef->getIconPath());
			if (iconPath != "") {

				Ogre::TexturePtr texPtr;
				try {
					if (Ogre::TextureManager::getSingleton().resourceExists(iconPath)) {
						texPtr = static_cast<Ogre::TexturePtr> (Ogre::TextureManager::getSingleton().getByName(iconPath));
						//try to load it to make sure that's it a working image
						texPtr->load();
					}
					if (texPtr.isNull()) {
						texPtr = Ogre::TextureManager::getSingleton().load(iconPath, "Gui");
					}
				} catch (...) {
					S_LOG_WARNING("Error when trying to load the icon " << iconPath <<". The icon will be rendered dynamically.");
					texPtr.setNull();
				}
				if (!texPtr.isNull()) {
					Icon* icon = mIconStore.createIcon(key, texPtr);
					return icon;
				}
			}
		}
		Icon* icon = mIconStore.createIcon(key);
		if (icon) {
			//update the model preview window
			// 				Model::Model* model = Model::Model::createModel(mIconRenderer.getRenderContext()->getSceneManager(), modelName);
			render(*icon, modelName);
			// 				mIconRenderer.getRenderContext()->getSceneManager()->destroyMovableObject(model);
		}
		return icon;
	}

	return 0;
}
Beispiel #3
0
void LodManager::loadLod(Ogre::MeshPtr mesh)
{
    assert(mesh->getNumLodLevels() == 1);
    std::string lodDefName = convertMeshNameToLodName(mesh->getName());

    try {
        Ogre::ResourcePtr resource = LodDefinitionManager::getSingleton().load(lodDefName, "General");
        const LodDefinition& def = *static_cast<const LodDefinition*>(resource.get());
        loadLod(mesh, def);
    } catch (Ogre::FileNotFoundException ex) {
        // Exception is thrown if a mesh hasn't got a loddef.
        // By default, use the automatic mesh lod management system.
        loadAutomaticLod(mesh);
    }
}
Beispiel #4
0
void TexturePreviewEditor::OpenOgreTexture(const QString& name)
{
    if (name.contains(".dds"))
    {
        LogWarning("currently cannot show .dds files. ");
        // Set black background image that will be replaced once the real image has been received.
        QImage emptyImage = QImage(QSize(256, 256), QImage::Format_ARGB32);
        emptyImage.fill(qRgba(0,0,0,0));
        if ( imageLabel_ != 0)
            imageLabel_->setPixmap(QPixmap::fromImage(emptyImage));

        return;
    }

    Ogre::ResourcePtr res = Ogre::TextureManager::getSingleton().getByName(name.toStdString().c_str());
    Ogre::Texture* tex = static_cast<Ogre::Texture* >(res.get());
    if (!tex)
    {
        LogWarning("Failed to open Ogre texture " + name.toStdString() + " .");
        return;
    }

    int width = tex->getWidth();
    int height = tex->getHeight();
    Ogre::Box bounds(0, 0, width, height);
    Ogre::uchar* pixelData = new Ogre::uchar[width * height * 4];
    Ogre::PixelBox pixels(bounds, Ogre::PF_A8R8G8B8, pixelData);
    tex->getBuffer()->blitToMemory(pixels);
    
    // Create image of texture, and show it into label.

    u8* p = static_cast<u8 *>(pixels.data);
    int widthPixels = pixels.getWidth();
    int heightPixels= pixels.getHeight();
    
    QImage img = ConvertToQImage(p, widthPixels, heightPixels, 4);

    if(!img.isNull() && imageLabel_ != 0)
    {
        imageLabel_->setPixmap(QPixmap::fromImage(img));
        imageLabel_->show();
    }

    delete[] pixelData;
}
Beispiel #5
0
void OgreInfo::diagnose(std::ostream& outputStream)
{
	Ogre::SceneManagerEnumerator::SceneManagerIterator sceneManagerI = Ogre::Root::getSingleton().getSceneManagerIterator();
	while (sceneManagerI.hasMoreElements()) {
		Ogre::SceneManager* sceneManager = sceneManagerI.getNext();
		outputStream << "Scenemanager(" << sceneManager->getTypeName() << ") " << sceneManager->getName() << std::endl;
		outputStream << " Number of scene nodes: " << countNodes(sceneManager->getRootSceneNode()) << std::endl;
		outputStream << " Movable objects:" << std::endl;
		unsigned int movableObjectCounter = 0;
		Ogre::Root::MovableObjectFactoryIterator movableObjectFactoryI = Ogre::Root::getSingleton().getMovableObjectFactoryIterator();
		while (movableObjectFactoryI.hasMoreElements()) {
			Ogre::MovableObjectFactory* factory = movableObjectFactoryI.getNext();
			std::string type(factory->getType());
			{
				Ogre::SceneManager::MovableObjectIterator I = sceneManager->getMovableObjectIterator(type);
				while (I.hasMoreElements()) {
					movableObjectCounter++;
					Ogre::MovableObject* movable = I.getNext();
					if (movable->getMovableType() == "Light") {
						Ogre::Light* light = static_cast<Ogre::Light*> (movable);
						outputStream << "  * Light " << light->getName() << "(" << (light->isInScene() ? "in scene" : "not in scene") << ")" << std::endl;
						outputStream << "   Pos: " << light->getDerivedPosition() << std::endl;
						outputStream << "   Direction: " << light->getDerivedDirection() << std::endl;

					} else {
						std::stringstream ssPosAndOrientation;
						if (movable->getParentSceneNode() && movable->isInScene()) {
							ssPosAndOrientation << " pos: " << movable->getParentSceneNode()->getPosition() << " orientation: " << movable->getParentSceneNode()->getOrientation();
						}
						outputStream << "  * " << type << " " << movable->getName() << "(" << (movable->isInScene() ? "in scene" : "not in scene") << ")" << ssPosAndOrientation.str() << std::endl;
						//					outputStream << "  Pos: " << light->getDerivedPosition() << std::endl;
						//					outputStream << "  Direction: " << light->getDerivedDirection() << std::endl;
					}
				}
			}
		}

		outputStream << " Number of movable objects: " << movableObjectCounter << std::endl;

		outputStream << " Cameras:" << std::endl;
		{
			Ogre::SceneManager::CameraIterator I = sceneManager->getCameraIterator();
			while (I.hasMoreElements()) {
				Ogre::Camera* camera = I.getNext();
				outputStream << "  Camera " << camera->getName() << "(" << (camera->isInScene() ? "in scene" : "not in scene") << ")" << std::endl;
				outputStream << "  Pos: " << camera->getDerivedPosition() << std::endl;
				outputStream << "  Direction: " << camera->getDerivedDirection() << std::endl;
				outputStream << "  Clip distances: " << camera->getNearClipDistance() << " - " << camera->getFarClipDistance() << std::endl;
			}
		}

	}

	size_t resourceMemoryUsage = 0;
	outputStream << "Resource Managers:" << std::endl;
	Ogre::ResourceGroupManager::ResourceManagerIterator I = Ogre::ResourceGroupManager::getSingleton().getResourceManagerIterator();
	while (I.hasMoreElements()) {
		std::string name = I.peekNextKey();
		Ogre::ResourceManager* manager = I.getNext();
		outputStream << " Resource Manager: " << name << std::endl;
		if (manager->getMemoryBudget() == std::numeric_limits<size_t>::max()) {
			outputStream << "  Memory budget: not set" << std::endl;
		} else {
			outputStream << "  Memory budget: " << manager->getMemoryBudget() << " bytes" << std::endl;
		}
		outputStream << "  Memory usage:  " << manager->getMemoryUsage() << " bytes" << std::endl;
		resourceMemoryUsage += manager->getMemoryUsage();

		Ogre::ResourceManager::ResourceMapIterator resourceI = manager->getResourceIterator();
		if (resourceI.hasMoreElements()) {
			outputStream << "  Resources: " << std::endl;
			int resourceCount = 0;
			int loadedResourceCount = 0;
			while (resourceI.hasMoreElements()) {
				Ogre::ResourcePtr resource = resourceI.getNext();
				if (resource->isLoaded()) {
					std::string reloadable = resource->isReloadable() ? " reloadable" : "";
					outputStream << "   " << resource->getName() << " ( " << resource->getSize() << " bytes)" << reloadable;
					Ogre::Texture* texture = dynamic_cast<Ogre::Texture*>(resource.get());
					if (texture) {
						outputStream << texture->getWidth() << "x" << texture->getHeight() << " ";
					}
					outputStream << std::endl;
					loadedResourceCount++;
				}
				resourceCount++;
			}
			outputStream << "  Total number of resources: " << resourceCount << std::endl;
			outputStream << "  Number of loaded resources: " << loadedResourceCount << std::endl;
		}
	}

	outputStream << "Total memory usage for all resource manager: " << resourceMemoryUsage << " bytes" << std::endl;

	outputStream << std::flush;
}
	void run(){
            boost::unique_lock<boost::mutex> lock(OgreFramework::getSingletonPtr()->mutex);
            	OgreFramework::getSingletonPtr()->m_pLog->logMessage("Start main loop...");
                //float fps_limit = 70.0;
                double timeSinceLastFrame = 0;
                double startTime = 0;
                
              OgreFramework::getSingletonPtr()->m_pRenderWnd->resetStatistics();
              lock.unlock();
                while(!m_bShutdown && !OgreFramework::getSingletonPtr()->isOgreToBeShutDown()) 
                {
                    boost::unique_lock<boost::mutex> lock(OgreFramework::getSingletonPtr()->mutex);
                        if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isClosed())m_bShutdown = true;

                        Ogre::WindowEventUtilities::messagePump();

                        if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isActive())
                        {
                                startTime = OgreFramework::getSingletonPtr()->m_pTimer->getMillisecondsCPU();

                                OgreFramework::getSingletonPtr()->m_pKeyboard->capture();
                                OgreFramework::getSingletonPtr()->m_pMouse->capture();
                                
                                
                                OgreFramework::getSingletonPtr()->updateCaption();
                                //update mouse selection to shaders
                                Ogre::ResourcePtr r = Ogre::MaterialManager::getSingletonPtr()->getByName("MultiTextureEditor");
                                if(!r.isNull()){
                                    float mx=OgreFramework::getSingletonPtr()->cursor_x+OgreFramework::getSingletonPtr()->m_pCamera->getPosition().x;
                                    float my=OgreFramework::getSingletonPtr()->cursor_y+OgreFramework::getSingletonPtr()->m_pCamera->getPosition().z;
                                    //float my=OgreFramework::getSingletonPtr()->cursor_y+sqrt(OgreFramework::getSingletonPtr()->m_pCamera->getPosition().z);
                                    /*//std::cout<<((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->getSharedParameters().size()<<"\n";//->setNamedConstant("pointer", Ogre::Vector3(OgreFramework::getSingletonPtr()->cursor_x,OgreFramework::getSingletonPtr()->cursor_y,OgreFramework::getSingletonPtr()->cursor_r));
                                    float mx=(OgreFramework::getSingletonPtr()->cursor_x-OgreFramework::getSingletonPtr()->cursror_e_w/2.0)/OgreFramework::getSingletonPtr()->cursror_e_w;
                                    float my=(-OgreFramework::getSingletonPtr()->cursor_y+OgreFramework::getSingletonPtr()->cursror_e_h/2.0)/OgreFramework::getSingletonPtr()->cursror_e_h;
                                    Ogre::Ray ray=OgreFramework::getSingletonPtr()->m_pCamera->getCameraToViewportRay(mx,my);
                                    Ogre::Vector3 cam = OgreFramework::getSingletonPtr()->m_pCamera->getDirection();
                                    float factor = ray.getDirection().dotProduct(cam) / (cam.length() * ray.getDirection().length());
                                    Ogre::Vector3 point = ray.getPoint(OgreFramework::getSingletonPtr()->m_pCamera->getPosition().y*factor);
                                    */
                                    switch(OgreFramework::getSingletonPtr()->mode){
                                        case 0:
                                                ((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->setNamedConstant("pointer", Ogre::Vector4(mx,my,OgreFramework::getSingletonPtr()->cursor_r,OgreFramework::getSingletonPtr()->cursor_rb));
                                                break;
                                        case 1:
                                            ((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->setNamedConstant("pointer", Ogre::Vector4(mx,my,OgreFramework::getSingletonPtr()->cursor_r,0));
                                            break;
                                        case 2:
                                            ((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->setNamedConstant("pointer", Ogre::Vector4(mx,my,2,0));
                                            break;
                                        default:
                                            ((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->setNamedConstant("pointer", Ogre::Vector4(-20,-20,0,0));
                                    }
                                        
                                }
                                else{
                                    //TODO error!
                                }
                                
                                OgreFramework::getSingletonPtr()->updateOgre(timeSinceLastFrame);
                                OgreFramework::getSingletonPtr()->m_pRoot->renderOneFrame();
                                
                                   /* while(OgreFramework::getSingletonPtr()->chunksToAdd.size()>0){//adding chunks
                                        ChunkAdding* ch = OgreFramework::getSingletonPtr()->chunksToAdd.front();
                                        OgreFramework::getSingletonPtr()->chunksToAdd.pop();
                                        Ogre::ManualObject* ogreMesh =  OgreFramework::getSingletonPtr()->m_pSceneMgr->createManualObject(std::string("Chunk")+(char)ch->x+(char)ch->y+(char)ch->z);
                                        ogreMesh->setDynamic(true);
                                        ogreMesh->setCastShadows(true);
                                        ogreMesh->begin("MultiTexture", Ogre::RenderOperation::OT_TRIANGLE_LIST);
                                        {
                                            for(int i=0;i<ch->size;++i){
                                                ogreMesh->position(ch->pos[i]);
                                                ogreMesh->normal(ch->normal[i]);
                                                ogreMesh->colour(ch->color[i]);
                                            }
                                        }
                                        ogreMesh->end();

                                        Ogre::SceneNode* ogreNode =  OgreFramework::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode(std::string("NChunk")+(char)ch->x+(char)ch->y+(char)ch->z, Ogre::Vector3(0, 0, 0));
                                        ogreNode->setVisible(true);
                                        ogreNode->attachObject(ogreMesh);
                                        ogreNode->setPosition(ch->x*CHUNK_SIZE,ch->z*(CHUNK_SIZE),ch->y*CHUNK_SIZE);
                                        delete ch;
                                    }*/
                                //update chunks
                                /*Pos* pos=NULL;
                                unsigned int chunksUpdated=0;
                                float cx=OgreFramework::getSingletonPtr()->m_pCamera->getPosition().x,cy=OgreFramework::getSingletonPtr()->m_pCamera->getPosition().z;
                                while(chunksUpdated<8 and (pos=OgreFramework::getSingletonPtr()->map->getNextUpdatedChunk())!=NULL){
                                    int xx=pos->x*128-cx;
                                    int yy=pos->y*128-cy;
                                    if(xx*xx+yy*yy<1280){
                                    std::cout<<"Updating chunk\n";
                                    chunksUpdated++;
                                    try{
                                        OgreFramework::getSingletonPtr()->m_pSceneMgr->getSceneNode(std::string("NChunk")+(char)pos->x+(char)pos->y)->removeAndDestroyAllChildren();
                                    }
                                    catch(...){}
                                    OgreFramework::getSingletonPtr()->map->getChunk(pos->x,pos->y);
                                    delete pos;
                                    }
                                    else{
                                        OgreFramework::getSingletonPtr()->map->chunks_q.push(pos);
                                    }
                                }*/
                                float cx=OgreFramework::getSingletonPtr()->m_pCamera->getPosition().x,cy=OgreFramework::getSingletonPtr()->m_pCamera->getPosition().z;
                                int lod = OgreFramework::getSingletonPtr()->m_pCamera->getPosition().y/OgreFramework::getSingletonPtr()->lodFactor;
                                if(lod>4)
                                    lod=4;
                                else if(lod<0)
                                    lod=0;
                                int showY = tan(OgreFramework::getSingletonPtr()->m_pCamera->getFOVy().valueRadians()) * OgreFramework::getSingletonPtr()->m_pCamera->getPosition().y/256.0+1;
                                if(showY>7)
                                    showY=7;
                                int showX=showY*4.0/3.0;
                                try{
                                for(int xx=cx/128-showX;xx<=cx/128+showX;xx++){
                                    for(int yy=cy/128-showY;yy<=cy/128+showY;yy++){
                                        if(xx>=0 and yy>=0 and xx<OgreFramework::getSingletonPtr()->map->x and yy<OgreFramework::getSingletonPtr()->map->y and !OgreFramework::getSingletonPtr()->map->fresh[lod][xx][yy]){
                                            /*try{
                                                OgreFramework::getSingletonPtr()->m_pSceneMgr->getSceneNode(std::string("NChunk")+Map::getPos(xx,yy))->removeAndDestroyAllChildren();
                                            }
                                            catch(...){
                                            //    std::cout<<"Chunk didnt exist\n";
                                            }*/
                                            OgreFramework::getSingletonPtr()->map->getChunk(xx,yy,lod);
                                            //std::cout<<"Updating chunk\n";
                                            throw (int)0;
                                            }
                                    }
                                }
                                }
                                catch(int){}//exit from loop
                                lock.unlock();
                                boost::this_thread::sleep(boost::posix_time::milliseconds(1));
                                timeSinceLastFrame = OgreFramework::getSingletonPtr()->m_pTimer->getMillisecondsCPU() - startTime; 
                        }
                        else
                        {
        #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
                    Sleep(1000);
        #else
                    sleep(1);
        #endif
                        }
                }
                OgreFramework::getSingletonPtr()->m_pLog->logMessage("Autosaving...");
                OgreFramework::getSingletonPtr()->map->save("autosave.map");
                OgreFramework::getSingletonPtr()->m_pLog->logMessage("Main loop quit");
                OgreFramework::getSingletonPtr()->m_pLog->logMessage("Shutdown OGRE...");
        }