Ejemplo n.º 1
0
	//---------------------------------------------------------------------
	void MeshElement::_destroyMesh(void)
	{
		if (mEntity)
		{
			assert(mBasicNode);
			Ogre::SceneManager* creator = mBasicNode->getCreator();
			assert(creator);       

			mBasicNode->detachObject(mEntity->getName());
#if ((OGRE_VERSION_MAJOR << 16) | (OGRE_VERSION_MINOR << 8) | OGRE_VERSION_PATCH) >= 0x010100
			creator->destroyMovableObject(mEntity);
#else
			creator->removeEntity(mEntity->getName());
#endif

			mEntity = NULL;
		}
	}
    //-----------------------------------------------------------------------
	void MeshParticleVisualData::modifyMesh(const String &meshName)
	{
		// destroy old entity
		assert(mEntity);

		Ogre::SceneNode* parent = mEntity->getParentSceneNode();
		assert(parent);
		Ogre::SceneManager* creator = parent->getCreator();
		assert(creator);

		parent->detachObject(mEntity->getName());
		creator->destroyMovableObject(mEntity);

		mEntity = NULL;

		// create new entity
		mEntity = creator->createEntity( mSceneNode->getName(), meshName );
		assert (mEntity);

		mSceneNode->attachObject(mEntity);
	}
Ejemplo n.º 3
0
//!
//! 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);
    }
}