コード例 #1
0
	Object* ObjectManager::collision(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, 
		float collisionRadius, int queryMask)
	{
			Ogre::Entity* entity = mCollision->collidesWithObject(fromPoint, toPoint, collisionRadius, queryMask);
		if (entity && entity->isVisible())
			return getObject(entity->getName());

		return 0;
	}
コード例 #2
0
ファイル: SSAOApp.cpp プロジェクト: sevas/ogre-ssao
//-----------------------------------------------------------------------------
Ogre::SceneNode* SSAOApp::_loadMesh(const Ogre::String &_name, const Ogre::Vector3 &_pos)
{
    std::string entityName = _name+Ogre::StringConverter::toString(mScenePairs.size());

    Ogre::Entity *ent = mSceneMgr->createEntity(entityName, _name+".mesh");
    Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode(ent->getName()+"Node", _pos);


    ent->setMaterialName("SSAO/DiffuseLight_GBuffer");
    node->attachObject(ent);

    mScenePairs.push_back(SSAOApp::ScenePair(ent, node));


    return node;
}
コード例 #3
0
	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);
	}
コード例 #4
0
	void RenderBoxWrap::synchronizeSceneNode(Ogre::SceneNode* _newNode, Ogre::SceneNode* _fromNode)
	{
		if (_newNode == nullptr || _fromNode == nullptr)
		{
			MYGUI_ASSERT(_newNode == nullptr || _fromNode == nullptr,"Synchronize scene node error.");
			return;
		}

		_newNode->setPosition(_fromNode->getPosition());
		_newNode->setOrientation(_fromNode->getOrientation());

		int i = 0;

		while (i < _newNode->numAttachedObjects())
		{
			Ogre::MovableObject * object = _newNode->getAttachedObject(i);
			Ogre::Entity* entity = object->getMovableType() == "Entity" ? static_cast<Ogre::Entity*>(object) : nullptr;

			if(entity)
			{
				object = findMovableObject(_fromNode, entity->getName());
				Ogre::Entity* oldEntity = (object != nullptr && object->getMovableType() == "Entity") ? static_cast<Ogre::Entity*>(object) : nullptr;

				if(!oldEntity)
				{
					removeEntity(entity->getName());
					continue;
				}
			}
			i++;
		}

		for(i = 0; i < _fromNode->numAttachedObjects(); i++)
		{
			Ogre::MovableObject * object = _fromNode->getAttachedObject(i);
			Ogre::Entity* entity = object->getMovableType() == "Entity" ? static_cast<Ogre::Entity*>(object) : nullptr;

			if(entity)
			{
				object = findMovableObject(_newNode, entity->getName());
				Ogre::Entity* newEntity = (object != nullptr && object->getMovableType() == "Entity") ? static_cast<Ogre::Entity*>(object) : nullptr;

				if(!newEntity)
				{
					//System::Console::WriteLine("create new entity {0}", gcnew System::String(entity->getName().c_str()));

					newEntity = mScene->createEntity(entity->getName(), entity->getMesh()->getName());//new Ogre::Entity(entity->getName(), (Ogre::MeshPtr)entity->getMesh().get()->getHandle());
					_newNode->attachObject(newEntity);

					mVectorEntity.push_back(newEntity);

					if(mEntity == nullptr)
					{
						mEntity = newEntity;
					}
				}
			}
		}

		i = 0;

		while (i < _newNode->numChildren())
		{
			Ogre::SceneNode* oldNode = findSceneNodeObject(_fromNode, _newNode->getChild(i)->getName());

			if(!oldNode)
			{
				Ogre::SceneNode* forDelete = (Ogre::SceneNode*)_newNode->getChild(i);

				removeNode(forDelete);
			}else
			{
				i++;
			}
		}

		for(i = 0; i < _fromNode->numChildren(); i++)
		{
			if(_fromNode->getChild(i)->numChildren() != 0 &&
				((Ogre::SceneNode*)_fromNode->getChild(i))->numAttachedObjects() != 0)
			{
				Ogre::SceneNode* newChildNode = findSceneNodeObject(_newNode, _fromNode->getChild(i)->getName());

				if(!newChildNode)
				{
					//System::Console::WriteLine("create new node {0}", gcnew System::String(_fromNode->getChild(i)->getName().c_str()));
					newChildNode = _newNode->createChildSceneNode(_fromNode->getChild(i)->getName(), _fromNode->getChild(i)->getPosition(), _fromNode->getChild(i)->getOrientation());
				}

				synchronizeSceneNode(newChildNode, (Ogre::SceneNode*)_fromNode->getChild(i));
			}
		}
	}
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
}
コード例 #6
0
ファイル: OgreRecast.cpp プロジェクト: arrian/3d-engine
void OgreRecast::update()
{
    // Fully rebuild static geometry after a reset (when tiles should be removed)
    if(m_rebuildSg) {
        m_sg->reset();

        // Add navmesh tiles (polys) to static geometry
        Ogre::SceneManager::MovableObjectIterator iterator = m_pSceneMgr->getMovableObjectIterator("Entity");
        while(iterator.hasMoreElements())
        {
            Ogre::Entity* ent = static_cast<Ogre::Entity*>(iterator.getNext());
            // Add all navmesh poly debug entities
            if(Ogre::StringUtil::startsWith(ent->getName(), "ent_recastmowalk_"))
                m_sg->addEntity(ent, Ogre::Vector3::ZERO);
        }
        m_sg->build();


        // Batch all lines together in one single manualObject (since we cannot use staticGeometry for lines)
        if(m_pSceneMgr->hasManualObject("AllNeighbourLines")) {
            m_pRecastSN->detachObject("AllNeighbourLines") ;
            m_pSceneMgr->destroyManualObject("AllNeighbourLines");
        }
        if(m_pSceneMgr->hasManualObject("AllBoundaryLines")) {
            m_pRecastSN->detachObject("AllBoundaryLines") ;
            m_pSceneMgr->destroyManualObject("AllBoundaryLines");
        }

        Ogre::ManualObject *allNeighbourLines = m_pSceneMgr->createManualObject("AllNeighbourLines");
        allNeighbourLines->begin("recastdebug", Ogre::RenderOperation::OT_LINE_LIST);
        allNeighbourLines->colour(m_navmeshNeighbourEdgeCol);

        Ogre::ManualObject *allBoundaryLines = m_pSceneMgr->createManualObject("AllBoundaryLines");
        allBoundaryLines->begin("recastdebug", Ogre::RenderOperation::OT_LINE_LIST);
        allBoundaryLines->colour(m_navmeshOuterEdgeCol);

        iterator = m_pSceneMgr->getMovableObjectIterator("ManualObject");
        while(iterator.hasMoreElements())
        {
            Ogre::ManualObject* man = static_cast<Ogre::ManualObject*>(iterator.getNext());

            if(Ogre::StringUtil::startsWith(man->getName(), "recastmoneighbour_")) {
                std::vector<Ogre::Vector3> verts = getManualObjectVertices(man);

                for(std::vector<Ogre::Vector3>::iterator iter = verts.begin(); iter != verts.end(); iter++) {
                    allNeighbourLines->position(*iter);
                }
            } else if(Ogre::StringUtil::startsWith(man->getName(), "recastmoboundary_")) {
                std::vector<Ogre::Vector3> verts = getManualObjectVertices(man);

                for(std::vector<Ogre::Vector3>::iterator iter = verts.begin(); iter != verts.end(); iter++) {
                    allBoundaryLines->position(*iter);
                }
            }
        }
        allNeighbourLines->end();
        allBoundaryLines->end();

        m_pRecastSN->attachObject(allNeighbourLines);
        m_pRecastSN->attachObject(allBoundaryLines);


        m_rebuildSg = false;
    }
}
コード例 #7
0
ファイル: Map.cpp プロジェクト: Alex-G/MuOnline
void Map::Load(std::string sceneFile)
{
	this->mLoader = new Utilities::DotSceneLoader();
	this->mLoader->parseDotScene(sceneFile, "General", GameFramework::getSingletonPtr()->sceneManager);

	std::vector<Ogre::Entity*> mNavmeshEnts;
			/*Ogre::Entity* mapE = GameFramework::getSingletonPtr()->sceneManager->createEntity("Map", "dungeon.mesh");
			Ogre::SceneNode* mapNode = GameFramework::getSingletonPtr()->sceneManager->getRootSceneNode()->createChildSceneNode("MapNode");
			mapNode->scale(Vector3(2,2,2));
			mapNode->attachObject(mapE);
			mNavmeshEnts.push_back(mapE);*/

			mRecast = new OgreRecast(GameFramework::getSingletonPtr()->sceneManager); 
			mDetourTileCache = new OgreDetourTileCache(mRecast);

			if (this->mLoader != 0)
			{
				if (this->mLoader->entityList->size() > 0)
				{
					ConfigFile cf;
					std::vector<Ogre::Entity*> srcMeshes;// =  std::vector<Ogre::Entity*>(this->mLoader->entityList->begin(), this->mLoader->entityList->end());
					bool could_find_plane = false;
					for (int i = 0; i < this->mLoader->entityList->size(); i++	)
					{
						Ogre::Entity* ent = this->mLoader->entityList->at(i);
						if (ent->getName() == "Plane#0")
						{
							//ent->setMaterialName("MyMaterial");
							ent->setMaterialName("PlaneMaterial");
							ent->setCastShadows(false);
							//ent->setVisible(false);
							//ent->getParentSceneNode()->setPosition(Vector3(0,0,0));
							srcMeshes.clear();
							srcMeshes.push_back(ent);
							could_find_plane = true;
						}
					}

					if (could_find_plane)
					{
						inputGeom = new InputGeom(srcMeshes);
					}
					else
					{
						//srcMeshes =  std::vector<Ogre::Entity*>(this->mLoader->entityList->begin(), this->mLoader->entityList->end());
						if (this->mLoader->getTerrainGroup() != 0)
						{
							inputGeom = new InputGeom(this->mLoader->getTerrainGroup(), srcMeshes);
						}
						else
						{
							inputGeom = new InputGeom(srcMeshes);
						}
					}
					

					

					if(mDetourTileCache->TileCacheBuild(inputGeom)) 
					{
						mDetourTileCache->drawNavMesh();
					} 
					else 
					{
						Ogre::LogManager::getSingletonPtr()->logMessage("ERROR: could not generate useable navmesh from mesh using detourTileCache.");
						return;
					}
				}
			}

			Ogre::SceneNode* mNavMeshNode = (Ogre::SceneNode*)GameFramework::getSingletonPtr()->sceneManager->getRootSceneNode()->getChild("RecastSN");
			int ttt = mNavMeshNode->numAttachedObjects();
			//mNavMeshNode->setVisible(true);
			for (int i = 0; i < mNavMeshNode->numAttachedObjects(); i++) 
			{
				Ogre::MovableObject *obj = mNavMeshNode->getAttachedObject(i);
				obj->setVisible(false);
				obj->setQueryFlags(QueryFlags::NAVMESH_MASK);
			}

			

	this->isLoaded = true;
}