484#ifdef IMPOSTOR_FILE_SAVE
485 TexturePtr renderTexture;
487 TexturePtr renderTexture(
texture);
491 RenderTexture *renderTarget;
492 Camera *renderCamera;
493 Viewport *renderViewport;
500 renderTexture = TextureManager::getSingleton().createManual(
getUniqueID(
"ImpostorTexture"),
"Impostors",
503 renderTexture->setNumMipmaps(MIP_UNLIMITED);
506 renderTarget = renderTexture->getBuffer()->getRenderTarget();
507 renderTarget->setAutoUpdated(
false);
510 camNode =
sceneMgr->getSceneNode(
"ImpostorPage::cameraNode");
512 camNode->attachObject(renderCamera);
513 renderCamera->setLodBias(1000.0f);
514 renderViewport = renderTarget->addViewport(renderCamera);
515 renderViewport->setOverlaysEnabled(
false);
516 renderViewport->setClearEveryFrame(
true);
517 renderViewport->setShadowsEnabled(
false);
521 SceneNode* node =
sceneMgr->getSceneNode(
"ImpostorPage::renderNode");
523 Ogre::SceneNode* oldSceneNode =
entity->getParentSceneNode();
525 oldSceneNode->detachObject(
entity);
528 node->attachObject(
entity);
536 renderCamera->setAspectRatio(1.0f);
538 renderCamera->setNearClipDistance(nearDist);
539 renderCamera->setFarClipDistance(farDist);
542 MaterialManager *mm = MaterialManager::getSingletonPtr();
543 FilterOptions oldMinFilter = mm->getDefaultTextureFiltering(FT_MIN);
544 FilterOptions oldMagFilter = mm->getDefaultTextureFiltering(FT_MAG);
545 FilterOptions oldMipFilter = mm->getDefaultTextureFiltering(FT_MIP);
546 mm->setDefaultTextureFiltering(FO_POINT, FO_LINEAR, FO_NONE);
549 FogMode oldFogMode =
sceneMgr->getFogMode();
550 ColourValue oldFogColor =
sceneMgr->getFogColour();
551 Real oldFogDensity =
sceneMgr->getFogDensity();
552 Real oldFogStart =
sceneMgr->getFogStart();
553 Real oldFogEnd =
sceneMgr->getFogEnd();
557 Ogre::SceneManager::SpecialCaseRenderQueueMode OldSpecialCaseRenderQueueMode =
sceneMgr->getSpecialCaseRenderQueueMode();
559 sceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_INCLUDE);
562 uint8 oldRenderQueueGroup =
entity->getRenderQueueGroup();
564 bool oldVisible =
entity->getVisible();
566 Ogre::Real oldMaxDistance =
entity->getRenderingDistance();
567 entity->setRenderingDistance(0);
569 bool needsRegen =
true;
570#ifdef IMPOSTOR_FILE_SAVE
574 ResourceGroupManager::getSingleton().addResourceLocation(tempdir,
"FileSystem",
"Impostors");
576 String fileName = StringUtil::format(
"Impostor.%08X.%d", key, textureSize);
582 texture = TextureManager::getSingleton().load(fileName+
".dds",
"Impostors", TEX_TYPE_2D, MIP_UNLIMITED);
586 texture = TextureManager::getSingleton().load(fileName+
".png",
"Impostors", TEX_TYPE_2D, MIP_UNLIMITED);
600#ifdef IMPOSTOR_RENDER_ABOVE_ONLY
601 Radian pitch = Degree((90.0f * o) * yDivFactor);
603 Radian pitch = Degree((180.0f * o) * yDivFactor - 90.0f);
607 Radian yaw = Degree((360.0f * i) * xDivFactor);
610 camNode->setPosition(0, 0, 0);
611 camNode->setOrientation(Quaternion(yaw, Vector3::UNIT_Y) * Quaternion(-pitch, Vector3::UNIT_X));
612 camNode->translate(Vector3(0, 0, objDist), Node::TS_LOCAL);
615 renderViewport->setDimensions((
float)(i) * xDivFactor, (
float)(o) * yDivFactor, xDivFactor, yDivFactor);
616 renderTarget->update();
620#ifdef IMPOSTOR_FILE_SAVE
622 renderTarget->writeContentsToFile(tempdir + fileName+
".png");
624 ResourceGroupManager::getSingleton().removeResourceLocation(tempdir,
"Impostors");
625 ResourceGroupManager::getSingleton().addResourceLocation(tempdir,
"FileSystem",
"Impostors");
628 texture = TextureManager::getSingleton().load(fileName+
".png",
"Impostors", TEX_TYPE_2D, MIP_UNLIMITED);
635 entity->setVisible(oldVisible);
636 entity->setRenderQueueGroup(oldRenderQueueGroup);
637 entity->setRenderingDistance(oldMaxDistance);
641 sceneMgr->setSpecialCaseRenderQueueMode(OldSpecialCaseRenderQueueMode);
644 mm->setDefaultTextureFiltering(oldMinFilter, oldMagFilter, oldMipFilter);
647 sceneMgr->setFog(oldFogMode, oldFogColor, oldFogDensity, oldFogStart, oldFogEnd);
650 renderTarget->removeViewport(0);
651 renderCamera->getSceneManager()->destroyCamera(renderCamera);
654 node->detachAllObjects();
656 oldSceneNode->attachObject(
entity);
659#ifdef IMPOSTOR_FILE_SAVE
661 assert(renderTexture);
663 if (TextureManager::getSingletonPtr())
664 TextureManager::getSingleton().remove(renderTexture);
void addBillboard(const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, const Ogre::Vector3 &scale, const Ogre::ColourValue &color=Ogre::ColourValue::White)
static ImpostorBatch * getBatch(ImpostorPage *group, Ogre::Entity *entity)
The ImpostorPage class renders entities as impostors (billboard images that look just like the real e...
void update()
Do whatever needs to be done to keep the page geometry up-to-date.
void build()
Perform any final steps to make added entities appear in the scene.
static void regenerate(Ogre::Entity *ent)
Regenerates the impostor texture for the specified entity.
static void regenerateAll()
Regenerates all impostor textures currently being used in the scene.
void addEntity(Ogre::Entity *ent, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, const Ogre::Vector3 &scale, const Ogre::ColourValue &color)
Add an entity to the page, at the specified position, rotation, and scale.
void setRegion(Ogre::Real left, Ogre::Real top, Ogre::Real right, Ogre::Real bottom)
Prepare a geometry page for entities.
void setFade(bool enabled, Ogre::Real visibleDist, Ogre::Real invisibleDist)
Sets fade behavior for this page.
void setVisible(bool visible)
Toggle the entire page's visibility.
bool injectImpostorBatch(const Ogre::String &key, ImpostorBatch *injectedBatch)
void removeEntities()
Remove all geometry/entities from the page completely.
void init(PagedGeometry *geom, const Ogre::Any &data)
Prepare a geometry page for use.
Ogre::MaterialPtr material[IMPOSTOR_PITCH_ANGLES][IMPOSTOR_YAW_ANGLES]
static ImpostorTexture * getTexture(ImpostorPage *group, Ogre::Entity *entity)
Returns a pointer to an ImpostorTexture for the specified entity.
static std::map< Ogre::String, ImpostorTexture * > selfList
static void removeTexture(ImpostorTexture *Texture)
remove created texture, note that all of the ImposterTextures must be deleted at once,...
virtual void loadResource(Ogre::Resource *resource)
At load time the texture will be rerendered.
A class providing highly optimized methods for rendering massive amounts of geometry.
Ogre::uint8 getRenderQueue() const
Returns the rendering queue that paged geometry was constructed with.
Ogre::SceneNode * getSceneNode() const
Gets the scene node to which all PagedGeometry geometry is attached.
Ogre::SceneManager * getSceneManager() const
Gets the scene manager which is being used to display the geometry.
Ogre::Camera * getCamera() const
Gets the camera which is used to calculate levels of detail.