Ogre::Light* LuaScriptUtilities::GetLight( lua_State* const luaVM, const int stackIndex) { Ogre::SceneNode* const node = GetSceneNode(luaVM, stackIndex); if (node) { Ogre::SceneNode::ObjectIterator it = node->getAttachedObjectIterator(); while (it.hasMoreElements()) { const Ogre::String movableType = it.current()->second->getMovableType(); if (movableType == Ogre::LightFactory::FACTORY_TYPE_NAME) { return static_cast<Ogre::Light*>(it.current()->second); } it.getNext(); } } return NULL; }
//----------------------------------------------------------------------------------------- bool CSceneManagerEditor::_setSkydomeActive(OgitorsPropertyBase* property, const bool& value) { if(value && mSkyBoxActive->get()) mSkyBoxActive->set(false); if(value && mSkyDomeMaterial->get() == "") { mSystem->DisplayMessageDialog(OTR("You must first define a SkyDome Material!"), DLGTYPE_OK); return false; } if(mHandle) { try { mHandle->setSkyDome(value ,mSkyDomeMaterial->get()); if(value) { Ogre::SceneNode *node = mHandle->getSkyDomeNode(); Ogre::SceneNode::ObjectIterator it = node->getAttachedObjectIterator(); while(it.hasMoreElements()) { Ogre::MovableObject *object = it.getNext(); object->setVisibilityFlags(0x7F000000); } } } catch(...) { mSystem->DisplayMessageDialog(OTR("The Material supplied is not compatible with Sky Dome!"), DLGTYPE_OK); return false; } } return true; }
void OLMeshTracker::UpdateSubNodes(Ogre::Node* regionNode, Ogre::Node* node, bool recurse, Ogre::MeshPtr meshP) { if (recurse && node->numChildren() > 0) { // if node has more children nodes, visit them recursivily Ogre::SceneNode::ChildNodeIterator nodeChildIterator = node->getChildIterator(); while (nodeChildIterator.hasMoreElements()) { Ogre::Node* nodeChild = nodeChildIterator.getNext(); // 'false' causes it to not visit sub-children which are included in parent and pos relative to parent UpdateSubNodes(regionNode, nodeChild, true, meshP); } } // children taken care of... check for attached objects to this node Ogre::SceneNode* snode = (Ogre::SceneNode*)node; Ogre::SceneNode::ObjectIterator snodeObjectIterator = snode->getAttachedObjectIterator(); while (snodeObjectIterator.hasMoreElements()) { Ogre::MovableObject* snodeObject = snodeObjectIterator.getNext(); if (snodeObject->getMovableType() == "Entity") { Ogre::Entity* snodeEntity = (Ogre::Entity*)snodeObject; Ogre::MeshPtr entityMesh = snodeEntity->getMesh(); if (entityMesh == meshP) { snode->needUpdate(true); // LG::Log("OLMeshTracker::UpdateSubNodes: setting node update for %s", snode->getName().c_str()); } } } return; }
bool CombatSetupWnd::ValidPlacement(Ship* ship, const Ogre::Vector3& point) const { bool retval = false; std::size_t i = GroupIndexOfShip(m_setup_groups, ship); if (i != m_setup_groups.size()) { const CombatSetupGroup& group = m_setup_groups[i]; retval = !group.m_allow; for (std::size_t j = 0; j < group.m_regions.size(); ++j) { double point_d[2] = { point.x, point.y }; if (PointInRegion(point_d, group.m_regions[j])) { retval = !retval; break; } } } if (retval) { // verify that this placement is not too near to other ships for (std::map<int, Ogre::SceneNode*>::const_iterator it = m_placed_nodes.begin(); it != m_placed_nodes.end(); ++it) { Ship* this_ship = *Ogre::any_cast<Ship*>(&it->second->getUserAny()); if (this_ship == ship) continue; Ogre::SceneNode::ObjectIterator iterator = it->second->getAttachedObjectIterator(); assert(iterator.hasMoreElements()); const Ogre::Sphere& sphere = boost::polymorphic_downcast<Ogre::Entity*>(iterator.getNext())->getWorldBoundingSphere(); if (sphere.intersects(point)) { retval = false; break; } } } return retval; }
//! //! Returns the first movable object of the given type name contained in //! the given scene node. //! //! \param sceneNode The scene node to find the first object in. //! \param typeName The name of the type of objects to look for. //! \return The first movable object of the given type name contained in the given scene node. //! Ogre::MovableObject * OgreTools::findFirstObject ( Ogre::SceneNode *sceneNode, const QString &typeName ) { // make sure the given scene node is valid if (!sceneNode) { Log::error("The given scene node is invalid.", "OgreTools::findFirstObject"); return 0; } // iterate over the list of attached objects Ogre::SceneNode::ObjectIterator objectIterator = sceneNode->getAttachedObjectIterator(); while (objectIterator.hasMoreElements()) { Ogre::MovableObject *movableObject = objectIterator.getNext(); if (movableObject && QString::compare(movableObject->getMovableType().c_str(), typeName) == 0) return movableObject; } // iterate over the list of child nodes Ogre::SceneNode::ChildNodeIterator childIter = sceneNode->getChildIterator(); while( childIter.hasMoreElements() ) { Ogre::SceneNode *childSceneNode = (Ogre::SceneNode *) childIter.getNext(); return findFirstObject(childSceneNode, typeName); } return 0; }
void CObject::changeState(EEntityStateTypes eState) { switch (m_uiType) { case OBJECT_GREEN_BUSH: case OBJECT_LIGHT_STONE: if (eState == EST_LIFTED) { btRigidBody *pRB = btRigidBody::upcast(this->getCollisionObject()); ASSERT(pRB); m_pMap->getPhysicsManager()->getWorld()->removeCollisionObject(pRB); m_pMap->getPhysicsManager()->getWorld()->addRigidBody(pRB, COL_DAMAGE_P, MASK_DAMAGE_P_COLLIDES_WITH); // Entities now cast shadows Ogre::SceneNode::ObjectIterator itObject = this->getSceneNode()->getAttachedObjectIterator(); while (itObject.hasMoreElements()) { Ogre::MovableObject* pObject = static_cast<Ogre::MovableObject*>(itObject.getNext()); pObject->setCastShadows(true); } } else if (eState == EST_THROWN) { btRigidBody *pRB = btRigidBody::upcast(this->getCollisionObject()); ASSERT(pRB); pRB->setLinearFactor(btVector3(1, 1, 1)); pRB->setAngularFactor(0); pRB->activate(); } break; } CWorldEntity::changeState(eState); }
//============================================================================= // NodeMaterialOrig //============================================================================= NodeMaterialOrig::NodeMaterialOrig( Ogre::SceneNode* sceneNode ) : NodeMaterial(), _sceneNode( sceneNode ) { for( Ogre::SceneNode::ObjectIterator it = sceneNode->getAttachedObjectIterator() ; it.hasMoreElements() ; it.moveNext() ) { Ogre::MovableObject * currentMO = it.peekNextValue() ; if ( currentMO->getMovableType() == Ogre::EntityFactory::FACTORY_TYPE_NAME ) { //OMTRACEID( "DEBUG", "Create entity " << currentMO->getName() ) ; _entities[ it.peekNextKey() ] = new EntityMaterialOrig( static_cast< Ogre::Entity *> ( currentMO ) ) ; } } for( Ogre::Node::ChildNodeIterator it = sceneNode->getChildIterator() ; it.hasMoreElements() ; it.moveNext() ) { Ogre::SceneNode* childSceneNode = static_cast< Ogre::SceneNode* >( it.peekNextValue() ) ; //OMTRACEID( "DEBUG", "Create ChildSceneNode " << childSceneNode->getName() ) ; NodeMaterialOrig* child = new NodeMaterialOrig( childSceneNode ) ; _childs.push_back( child ) ; } }
void MergeBounds(Ogre::SceneNode* node, Ogre::SceneNode* rootNode, const Ogre::Matrix4& parentTransform, Ogre::AxisAlignedBox& aabb) { // Get this nodes current transform Ogre::Matrix4 currentTransform = parentTransform; if (node != rootNode) { Ogre::Matrix4 localTransform(node->getOrientation()); localTransform.setTrans(node->getPosition()); currentTransform = currentTransform * localTransform; } // Merge this nodes objects Ogre::SceneNode::ObjectIterator object = node->getAttachedObjectIterator(); while (object.hasMoreElements()) { Ogre::AxisAlignedBox localAABB = object.getNext()->getBoundingBox(); localAABB.transform(currentTransform); aabb.merge(localAABB); } // Iterate through all children and call this function on them Ogre::SceneNode::ChildNodeIterator child = node->getChildIterator(); while (child.hasMoreElements()) { MergeBounds(static_cast<Ogre::SceneNode*>(child.getNext()), rootNode, currentTransform, aabb); } }
/** @brief get all the crusaders animations and stick em in the vector for easier reference */ void Animation::extractAnimations(Ogre::SceneNode* a_scene_node) { // get animation states from all entities for (size_t i = 0; i < num_of_animations; ++i) { Ogre::SceneNode::ObjectIterator it = a_scene_node->getAttachedObjectIterator(); while (it.hasMoreElements()) { // get the mesh attached to the scene node Ogre::Entity* anim_entity = static_cast<Ogre::Entity*>(it.getNext()); // safeguard for ommited anims if (NULL != anim_entity->getAllAnimationStates()) { // stick the animation state in the array later indexed by animation type enum Animations[i].push_back(anim_entity->getAnimationState(animation_names[i])); // reset the animation Animations[i].back()->setTimePosition(0); if (i == CurrentAnim) { Animations[i].back()->setEnabled(true); } } } } // recurse into child scene nodes Ogre::SceneNode::ChildNodeIterator it2 = a_scene_node->getChildIterator(); while (it2.hasMoreElements()) { extractAnimations(static_cast<Ogre::SceneNode*>(it2.getNext())); } }
CDebugDraw::CDebugDraw( Ogre::SceneManager* Scene, btDynamicsWorld* World ) : World( World ), IsActive( true ) { // generate a unit sphere std::size_t CircleSubdivs = 12; UnitCircle.reserve( CircleSubdivs+1 ); for ( std::size_t i = 0; i < CircleSubdivs; ++i ) { float Angle = (M_PI * 2.f * i) / CircleSubdivs; UnitCircle.push_back( Ogre::Vector2( std::cos( Angle ), std::sin( Angle ) ) ); } UnitCircle.push_back( UnitCircle.front() ); // setup rendering properties DebugLineDrawer = new CDynamicLineDrawer(); if ( !Scene->hasSceneNode("DebugDrawer") ) DebugDrawerNode = Scene->getRootSceneNode()->createChildSceneNode("DebugDrawer"); else { DebugDrawerNode = Scene->getSceneNode("DebugDrawer"); Ogre::SceneNode::ObjectIterator Iter = DebugDrawerNode->getAttachedObjectIterator(); while( Iter.hasMoreElements() ) Scene->destroyEntity( dynamic_cast<Ogre::Entity*>( Iter.getNext() ) ); } DebugDrawerNode->attachObject( DebugLineDrawer ); DebugLineDrawer->setMaterial("DebugLines"); World->setDebugDrawer( this ); }
void Actor::setCastShadows(bool hasShadows) { assert(mNode); Ogre::SceneNode::ObjectIterator it = mNode->getAttachedObjectIterator(); while(it.hasMoreElements()) { Ogre::MovableObject* obj = static_cast<Ogre::MovableObject*>(it.getNext()); obj->setCastShadows(hasShadows); } }
void MiniMapManager::deleteEntity(Ogre::SceneNode* node) { Ogre::SceneNode::ObjectIterator itObject = node->getAttachedObjectIterator(); while ( itObject.hasMoreElements() ) { Ogre::MovableObject* pObject = static_cast<Ogre::MovableObject*>(itObject.getNext()); node->getCreator()->destroyMovableObject( pObject ); } node->removeAndDestroyAllChildren(); mSceneMgr->destroySceneNode(node); }
//! //! Creates a deep copy of the given scene node. //! //! \param sceneNode The scene node to copy. //! \param sceneNodeCopy The scene node to add the copied objects to (will be created if 0). //! \param namePrefix The prefix to use for names of copied objects. //! \param sceneManager The scene manager to use for creating the object. //! void OgreTools::deepCopySceneNode ( Ogre::SceneNode *sceneNode, Ogre::SceneNode *&sceneNodeCopy, const QString &namePrefix, Ogre::SceneManager *sceneManager /* = 0 */ ) { // make sure the given scene node is valid if (!sceneNode) { Log::error("The given scene node is invalid.", "OgreTools::deepCopySceneNode"); return; } // make sure a valid scene manager is available if (!sceneManager) sceneManager = sceneNode->getCreator(); if (!sceneManager) { Log::error("No valid scene manager available.", "OgreTools::deepCopySceneNode"); return; } // create the target scene node if it doesn't exist yet if (!sceneNodeCopy) { QString sceneNodeCopyName = QString("%1_%2Copy").arg(namePrefix).arg(sceneNode->getName().c_str()); sceneNodeCopy = copySceneNode(sceneNode, sceneNodeCopyName, sceneManager); if (!sceneNodeCopy) { Log::error("The scene node could not be copied.", "OgreTools::deepCopySceneNode"); return; } } // iterate over the list of attached objects Ogre::SceneNode::ObjectIterator objectIterator = sceneNode->getAttachedObjectIterator(); while (objectIterator.hasMoreElements()) { Ogre::MovableObject *movableObject = objectIterator.getNext(); if (movableObject) { QString entityCopyName = QString("%1_%2Copy").arg(namePrefix).arg(movableObject->getName().c_str()); Ogre::MovableObject *movableObjectCopy = cloneMovableObject(movableObject, entityCopyName, sceneManager); if (movableObjectCopy) sceneNodeCopy->attachObject(movableObjectCopy); } } // iterate over the list of child nodes Ogre::SceneNode::ChildNodeIterator childNodeIterator = sceneNode->getChildIterator(); while (childNodeIterator.hasMoreElements() ) { Ogre::SceneNode *childSceneNode = (Ogre::SceneNode *) childNodeIterator.getNext(); QString childSceneNodeCopyName = QString("%1_%2Copy").arg(namePrefix).arg(childSceneNode->getName().c_str()); Ogre::SceneNode *childSceneNodeCopy = copySceneNode(childSceneNode, childSceneNodeCopyName, sceneManager); if (childSceneNodeCopy) { sceneNodeCopy->addChild(childSceneNodeCopy); deepCopySceneNode(childSceneNode, childSceneNodeCopy, namePrefix, sceneManager); } } }
bool Actor::isVisible() const { assert(mNode); Ogre::SceneNode::ObjectIterator it = mNode->getAttachedObjectIterator(); while(it.hasMoreElements()) { Ogre::MovableObject* obj = static_cast<Ogre::MovableObject*>(it.getNext()); if(!obj->isVisible()) { return false; } } return true; }
void CSVRender::Object::clearSceneNode (Ogre::SceneNode *node) { for (Ogre::SceneNode::ObjectIterator iter = node->getAttachedObjectIterator(); iter.hasMoreElements(); ) { Ogre::MovableObject* object = dynamic_cast<Ogre::MovableObject*> (iter.getNext()); node->getCreator()->destroyMovableObject (object); } for (Ogre::SceneNode::ChildNodeIterator iter = node->getChildIterator(); iter.hasMoreElements(); ) { Ogre::SceneNode* childNode = dynamic_cast<Ogre::SceneNode*> (iter.getNext()); clearSceneNode (childNode); node->getCreator()->destroySceneNode (childNode); } }
void Factory::destroyModel(Ogre::SceneNode* sceneNode) { Ogre::SceneNode::ObjectIterator it = sceneNode->getAttachedObjectIterator(); while (it.hasMoreElements()) { Ogre::MovableObject* movableEntity = static_cast<Ogre::MovableObject*>(it.getNext()); sceneNode->getCreator()->destroyMovableObject(movableEntity); } //destroy children if any Ogre::SceneNode::ChildNodeIterator it2 = sceneNode->getChildIterator(); while (it2.hasMoreElements()) { Ogre::SceneNode* childNode = static_cast<Ogre::SceneNode*>(it2.getNext()); destroyModel(childNode); } //at last remove the scene node Game::scene->destroySceneNode(sceneNode); }
void OgreColladaContentImporter::sceneNodeCreated(Ogre::SceneNode* pNode, FCDSceneNode* pFColladaSceneNode) { NxOgre::ActorParams actorParams; NxOgre::ShapeParams shapeParams; Ogre::Vector3 boxSize; Ogre::Vector3 scale; Ogre::Entity *pEntity; std::list<Ogre::Entity*> entityList; std::list<Ogre::Entity*>::iterator entityListIter; NxVec3 row; pEntity = NULL; Ogre::SceneNode::ObjectIterator iter = pNode->getAttachedObjectIterator(); while (iter.hasMoreElements()) { pEntity = dynamic_cast<Ogre::Entity*>(iter.getNext()); if (pEntity != NULL) { entityList.push_back(pEntity); } } shapeParams.setToDefault(); //scale = pNode->_getDerivedScale(); //shapeParams.mMeshScale = NxVec3(scale.x, scale.y, scale.z); for (entityListIter = entityList.begin(); entityListIter != entityList.end(); ++entityListIter) { pEntity = *entityListIter; boxSize = pEntity->getBoundingBox().getSize(); pNode->detachObject(pEntity); actorParams.setToDefault(); actorParams.mMass = 0.0f; actorParams.mBodyFlags |= NX_BF_KINEMATIC; GameObjectFactory::getSingleton().makeBody(pEntity->getName(), pNode, pEntity, scene ,new NxOgre::CubeShape(boxSize.x, boxSize.y, boxSize.z, shapeParams), actorParams); } sceneNodes.push_back(pNode); }
void DestroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode ) { if (!i_pSceneNode ) return; // Destroy all the attached objects Ogre::SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator(); while (itObject.hasMoreElements() ) { Ogre::MovableObject* pObject = static_cast<Ogre::MovableObject*>(itObject.getNext()); i_pSceneNode->getCreator()->destroyMovableObject(pObject); } // Recurse to child SceneNodes Ogre::SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator(); while (itChild.hasMoreElements() ) { Ogre::SceneNode* pChildNode = static_cast<Ogre::SceneNode*>(itChild.getNext()); DestroyAllAttachedMovableObjects(pChildNode); } }
/// From http://www.ogre3d.org/forums/viewtopic.php?f=2&t=53647 inline void destroyAllAttachedMovableObjects(Ogre::SceneNode *node) { if(!node) return; // Destroy all the attached objects Ogre::SceneNode::ObjectIterator itObject = node->getAttachedObjectIterator(); // FIXME segmentation fault while (itObject.hasMoreElements()) node->getCreator()->destroyMovableObject(itObject.getNext()); // Recurse to child SceneNodes Ogre::SceneNode::ChildNodeIterator itChild = node->getChildIterator(); while ( itChild.hasMoreElements() ) { Ogre::SceneNode* pChildNode = boost::polymorphic_cast<Ogre::SceneNode*>(itChild.getNext()); destroyAllAttachedMovableObjects(pChildNode); } }
void SceneNodeWrapper::destroyAllAttachedMovableObjects( Ogre::SceneNode* node ) { if(!node) return; // Destroy all the attached objects Ogre::SceneNode::ObjectIterator itObject = node->getAttachedObjectIterator(); while ( itObject.hasMoreElements() ) node->getCreator()->destroyMovableObject(itObject.getNext()); // Recurse to child SceneNode auto itChild = node->getChildIterator(); while ( itChild.hasMoreElements() ) { Ogre::SceneNode* pChildNode = static_cast<Ogre::SceneNode*>(itChild.getNext()); destroyAllAttachedMovableObjects(pChildNode); } }
/* Removes all the entities of a sceneNode (recursively) */ void Util::removeAllEntities(Ogre::SceneNode *node) { ASSERT(node); // Destroy all the attached objects Ogre::SceneNode::ObjectIterator itObject = node->getAttachedObjectIterator(); while (itObject.hasMoreElements()) { Ogre::MovableObject* pObject = static_cast<Ogre::MovableObject*> (itObject.getNext()); node->getCreator()->destroyMovableObject(pObject); } // Recurse to child SceneNodes Ogre::SceneNode::ChildNodeIterator itChild = node->getChildIterator(); while (itChild.hasMoreElements()) { Ogre::SceneNode* pChildNode = static_cast<Ogre::SceneNode*> (itChild.getNext()); removeAllEntities(pChildNode); } }
void CameraMan::setAnchor(Ogre::SceneNode* anchor, Ogre::Vector3 offset, bool hideAnchor) { // Clear previous anchor if (mAnchor) { // Show all objects in anchor node Ogre::SceneNode::ObjectIterator it = mAnchor->getParentSceneNode()->getAttachedObjectIterator(); while (it.hasMoreElements()) { it.getNext()->setVisible(true); } Ogre::Vector3 position = mCamera->getRealPosition(); Ogre::Quaternion orientation = mCamera->getRealOrientation(); mAnchor->detachObject(mCamera); mAnchor->getParentSceneNode()->removeAndDestroyChild("CameraManAnchor"); mAnchor = NULL; mCamera->setPosition(position); mCamera->setOrientation(orientation); } if (anchor) { // Hide all objects in anchor node Ogre::SceneNode::ObjectIterator it = anchor->getAttachedObjectIterator(); if (hideAnchor) { while (it.hasMoreElements()) { it.getNext()->setVisible(false); } } // Create anchor mAnchor = anchor->createChildSceneNode("CameraManAnchor"); // if(mCamera->getParentSceneNode()) // mCamera->getParentSceneNode()->detachObject(mCamera); mAnchor->attachObject(mCamera); mAnchor->setInheritOrientation(false); mCamera->setPosition(offset); } }
void CombatSetupWnd::HandleMouseMoves(const GG::Pt& pt) { if (Ogre::SceneNode* node = PlaceableShipNode()) { std::pair<bool, Ogre::Vector3> intersection = m_intersect_mouse_with_ecliptic(pt); if (intersection.first) { Ship* ship = *Ogre::any_cast<Ship*>(&node->getUserAny()); bool valid_location = ValidPlacement(ship, intersection.second); node->setVisible(true); node->setPosition(intersection.second); node->setOrientation(StarwardOrientationForPosition(intersection.second)); if (valid_location) { Ogre::SceneNode::ObjectIterator iterator = node->getAttachedObjectIterator(); assert(iterator.hasMoreElements()); Ogre::Entity* entity = boost::polymorphic_downcast<Ogre::Entity*>(iterator.getNext()); entity->setMaterialName(ShipMaterialName(*ship->Design(), ship->Owner())); entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN); } else { std::string base_material_name = ShipMaterialName(*ship->Design(), ship->Owner()); std::string material_name = UNPLACEABLE_MATERIAL_PREFIX + base_material_name; if (!Ogre::MaterialManager::getSingleton().resourceExists(material_name)) { Ogre::MaterialPtr unmodified_material = Ogre::MaterialManager::getSingleton().getByName(base_material_name); Ogre::MaterialPtr material = unmodified_material->clone(material_name); Ogre::Pass* pass = material->getTechnique(0)->getPass(1); assert(pass->hasFragmentProgram()); pass->getFragmentProgramParameters()->setNamedConstant("alpha", 0.25f); } Ogre::SceneNode::ObjectIterator iterator = node->getAttachedObjectIterator(); assert(iterator.hasMoreElements()); Ogre::Entity* entity = boost::polymorphic_downcast<Ogre::Entity*>(iterator.getNext()); entity->setMaterialName(material_name); entity->setRenderQueueGroup(ALPHA_OBJECTS_QUEUE); } } else { node->setVisible(false); } } }
// BETWEEN FRAME OPERATION void VisCalcFrustDist::calculateEntityVisibility(Ogre::Node* regionNode, Ogre::Node* node, bool recurse) { if (recurse && node->numChildren() > 0) { // if node has more children nodes, visit them recursivily Ogre::SceneNode::ChildNodeIterator nodeChildIterator = node->getChildIterator(); while (nodeChildIterator.hasMoreElements()) { Ogre::Node* nodeChild = nodeChildIterator.getNext(); // 'false' causes it to not visit sub-children which are included in parent and pos relative to parent calculateEntityVisibility(regionNode, nodeChild, false); visChildren++; } } visNodes++; // children taken care of... check fo attached objects to this node Ogre::SceneNode* snode = (Ogre::SceneNode*)node; // the camera needs to be made relative to the region // Ogre::Vector3 relCameraPos = LG::RendererOgre::Instance()->m_camera->getPosition() - regionNode->getPosition(); // float snodeDistance = LG::RendererOgre::Instance()->m_camera->getPosition().distance(snode->_getWorldAABB().getCenter()); // float snodeDistance = relCameraPos.distance(snode->getPosition()); float snodeDistance = LG::RendererOgre::Instance()->m_camera->getDistanceFromCamera(regionNode, snode->getPosition()); Ogre::SceneNode::ObjectIterator snodeObjectIterator = snode->getAttachedObjectIterator(); while (snodeObjectIterator.hasMoreElements()) { Ogre::MovableObject* snodeObject = snodeObjectIterator.getNext(); if (snodeObject->getMovableType() == "Entity") { visEntities++; Ogre::Entity* snodeEntity = (Ogre::Entity*)snodeObject; // check it's visibility if it's not world geometry (terrain and ocean) if ((snodeEntity->getQueryFlags() & Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK) == 0) { // computation if it should be visible // Note: this call is overridden by derived classes that do fancier visibility rules bool shouldBeVisible = this->CalculateVisibilityImpl(LG::RendererOgre::Instance()->m_camera, snodeEntity, snodeDistance); if (snodeEntity->isVisible()) { // we currently think this object is visible. make sure it should stay that way if (shouldBeVisible) { // it should stay visible visVisToVis++; } else { // not visible any more... make invisible nad unload it` /* Ogre::Vector3 cPos = LG::RendererOgre::Instance()->m_camera->getPosition(); Ogre::Vector3 rPos = regionNode->getPosition(); Ogre::Vector3 sPos = snode->getPosition(); LG::Log("VisToInVis: cPos=<%f,%f,%f>, rPos=<%f,%f,%f>, sPos(%s)=<%f,%f,%f>, d=%f", cPos.x, cPos.y, cPos.z, rPos.x, rPos.y, rPos.z, snode->getName().c_str(), sPos.x, sPos.y, sPos.z, snodeDistance); */ snodeEntity->setVisible(false); snode->needUpdate(true); visVisToInvis++; if (!snodeEntity->getMesh().isNull()) { queueMeshUnload(snodeEntity->getMesh()); } } } else { // the entity currently thinks it's not visible. // check to see if it should be visible by checking a fake bounding box if (shouldBeVisible) { // it should become visible again if (!snodeEntity->getMesh().isNull()) { // queueMeshLoad(snodeEntity, snodeEntity->getMesh()); LG::OLMeshTracker::Instance()->MakeLoaded(snodeEntity->getMesh()->getName(), Ogre::String(""), Ogre::String("visible"), snodeEntity); } // snodeEntity->setVisible(true); // must happen after mesh loaded visInvisToVis++; } else { visInvisToInvis++; } } } } } }
void CSaveSceneView::SceneNodeExplore(Ogre::SceneNode *SceneNode) { Ogre::Entity *Entity = NULL; Ogre::Camera *Camera = NULL; Ogre::Light *Light = NULL; Ogre::ParticleSystem *ParticleSystem = NULL; Ogre::ManualObject *ManualObject = NULL; Ogre::BillboardSet *BillboardSet = NULL; xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "SceneNode"); Ogre::String SceneNodeName = SceneNode->getName(); xmlTextWriterWriteAttribute(m_XmlWriter, BAD_CAST "SceneNodeName", BAD_CAST SceneNodeName.c_str()); Ogre::SceneNode::ObjectIterator obji = SceneNode->getAttachedObjectIterator(); while (obji.hasMoreElements()) { Ogre::MovableObject* mobj = obji.getNext(); Ogre::String Type = mobj->getMovableType(); if (Type == "Entity") { Entity = (Ogre::Entity *)(mobj); Ogre::String EntityName = Entity->getName(); xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Entity"); xmlTextWriterWriteAttribute(m_XmlWriter, BAD_CAST "EntityName", BAD_CAST EntityName.c_str()); Ogre::MeshPtr Mesh = Entity->getMesh(); Ogre::String MeshName = Mesh->getName(); xmlTextWriterWriteAttribute(m_XmlWriter, BAD_CAST "MeshName", BAD_CAST MeshName.c_str()); xmlTextWriterEndElement(m_XmlWriter); } if (Type == "Camera") { Camera = (Ogre::Camera *)(mobj); Ogre::String CameraName = Camera->getName(); xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Camera"); xmlTextWriterWriteAttribute(m_XmlWriter, BAD_CAST "CameraName", BAD_CAST CameraName.c_str()); Ogre::Vector3 CameraPosition = Camera->getPosition(); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "XPosition", "%f",CameraPosition.x); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "YPosition", "%f",CameraPosition.y); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "ZPosition", "%f",CameraPosition.z); Ogre::Vector3 CameraDirection = Camera->getDirection(); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "XDirection", "%f",CameraDirection.x); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "YDirection", "%f",CameraDirection.y); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "ZDirection", "%f",CameraDirection.z); xmlTextWriterEndElement(m_XmlWriter); } if (Type == "Light") { Light = (Ogre::Light *)(mobj); } if (Type == "ParticleSystem") { ParticleSystem = (Ogre::ParticleSystem *)(mobj); } if (Type == "ManualObject") { ManualObject = (Ogre::ManualObject *)(mobj); } if (Type == "BillboardSet") { BillboardSet = (Ogre::BillboardSet *)(mobj); } } Ogre::Node::ChildNodeIterator nodei = SceneNode->getChildIterator(); while (nodei.hasMoreElements()) { Ogre::SceneNode* node = (Ogre::SceneNode*)(nodei.getNext()); // Add this subnode and its children... SceneNodeExplore(node); } xmlTextWriterEndElement(m_XmlWriter); //end SceneNode }
//! //! Deletes a whole scene node tree (including attached objects). //! //! \param sceneNode The scene node containing the tree to delete. //! \param sceneManager The scene manager to use for destroying the scene node. //! \param deleteRoot Flag to control whether to delete the given scene node. //! void OgreTools::deepDeleteSceneNode ( Ogre::SceneNode *sceneNode, Ogre::SceneManager *sceneManager /* = 0 */, bool deleteRoot /* = false */ ) { // make sure the given scene node is valid if (!sceneNode) { Log::error("The given scene node is invalid.", "OgreTools::deepDeleteSceneNode"); return; } // make sure a valid scene manager is available if (!sceneManager) sceneManager = sceneNode->getCreator(); if (!sceneManager) { Log::error("No valid scene manager available.", "OgreTools::deepDeleteSceneNode"); return; } // iterate over the list of attached objects Ogre::SceneNode::ObjectIterator objectIterator = sceneNode->getAttachedObjectIterator(); while (objectIterator.hasMoreElements()) { Ogre::MovableObject *movableObject = objectIterator.getNext(); sceneNode->detachObject(movableObject); Ogre::SceneManager *movableSceneManager = movableObject->_getManager(); if (!movableSceneManager) { Log::error("The Ogre scene manager could not be obtained.", "OgreTools::deepDeleteSceneNode"); return; } Ogre::Any customData = movableObject->getUserAny(); if (!customData.isEmpty()) { OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData); if (ogreContainer) { delete ogreContainer; ogreContainer = 0; } } movableSceneManager->destroyMovableObject(movableObject); } // iterate over the list of child nodes Ogre::SceneNode::ChildNodeIterator childNodeIterator = sceneNode->getChildIterator(); while (childNodeIterator.hasMoreElements()) { Ogre::SceneNode *childSceneNode = dynamic_cast<Ogre::SceneNode *>(childNodeIterator.getNext()); if (childSceneNode) { Ogre::Any customData = childSceneNode->getUserAny(); if (!customData.isEmpty()) { OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData); if (ogreContainer) { delete ogreContainer; ogreContainer = 0; } else { CameraInfo *cameraInfo = Ogre::any_cast<CameraInfo *>(customData); if (cameraInfo) { delete cameraInfo; cameraInfo = 0; } } } deepDeleteSceneNode(childSceneNode, sceneManager); } } // destroy all child nodes of the given scene node sceneNode->removeAndDestroyAllChildren(); // check if the given scene node should be destroyed as well if (deleteRoot) { Ogre::Any customData = sceneNode->getUserAny(); if (!customData.isEmpty()) { OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData); if (ogreContainer) { delete ogreContainer; ogreContainer = 0; } else { CameraInfo *cameraInfo = Ogre::any_cast<CameraInfo *>(customData); if (cameraInfo) { delete cameraInfo; cameraInfo = 0; } } } sceneManager->destroySceneNode(sceneNode); } }