void OgreSample13App::createStaticGeom() { Entity * ent = mSceneMgr->createEntity(meshes[mSelectedMesh],meshes[mSelectedMesh] + ".mesh"); renderStatic.reserve(mNumRendered); renderStatic.resize(mNumRendered); StaticGeometry * geom = new StaticGeometry(mSceneMgr,meshes[mSelectedMesh] + "s"); geom->setRegionDimensions(Vector3(1000000,1000000,1000000)); size_t k=0; size_t y=0; for(size_t i=0;i<mNumMeshes;i++) { if (y == maxObjectsPerBatch) { y=0; k++; } geom->addEntity(ent,posMatrices[k][y]); y++; } geom->setCastShadows(true); geom->build(); renderStatic[0] = geom; mSceneMgr->destroyEntity(ent); }
Entity* LevelGeometryFactory::useFactory(FactoryParameters* _parameters) { //g_AIManager.addStaticGeometry(&points[0],points.size()); StaticGeometry* entity = new StaticGeometry; entity->baseInit(skinFactory->use(_parameters, entity)); BodyPart* body = bodyFactory->use(_parameters, entity); entity->setRootBody(body); return entity; }
//------------------------------------------------------------------------ // Purpose : Push the Static Geometry into Manager from Text File //------------------------------------------------------------------------ void StaticGeometryManager::AddToStaticGeometryList(const std::string& fileName, const Helper::StaticGeomData& data) { StaticGeometry* tempGeom = new StaticGeometry(); if (tempGeom != NULL) { if(tempGeom->Initialize(data)) m_GeomList.insert(std::make_pair(tempGeom, fileName)); } }
//------------------------------------------------------------------------ // Purpose : Push the Static Geometry into Manager //------------------------------------------------------------------------ void StaticGeometryManager::AddToStaticGeometryList(const std::string& fileName, const std::string& meshName) { StaticGeometry* tempGeom = new StaticGeometry(); if (tempGeom != NULL) { tempGeom->Initialize(fileName); m_GeomList.insert(std::make_pair(tempGeom, meshName)); } }
void DumpVisitor::ApplyStaticGeometry(StaticGeometry &g) { if (g.GetNodeMask() & NODE_TRANSPARENT) m_stats.transGeomCount++; else m_stats.opaqueGeomCount++; for (unsigned int i = 0; i < g.GetNumMeshes(); i++) m_stats.triangles += g.GetMeshAt(i).indexBuffer->GetSize() / 3; ApplyNode(static_cast<Node&>(g)); }
// ------------------------------------------------------------------------- RigidBody *OgreBulletListener::addStaticPlane( const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction) { // Use a load of meshes to represent the floor int i = 0; StaticGeometry* s; s = mSceneMgr->createStaticGeometry("StaticFloor"); s->setRegionDimensions(Ogre::Vector3(160.0, 100.0, 160.0)); // Set the region origin so the center is at 0 world s->setOrigin(Ogre::Vector3::ZERO); for (Real z = -80.0;z <= 80.0;z += 20.0) { for (Real x = -80.0;x <= 80.0;x += 20.0) { String name = String("Plane_") + StringConverter::toString(i++); Entity* entity = mSceneMgr->createEntity(name, "plane.mesh"); entity->setMaterialName("BulletPlane"); entity->setQueryFlags (STATIC_GEOMETRY_QUERY_MASK); //entity->setUserObject(_plane); entity->setCastShadows(false); s->addEntity(entity, Ogre::Vector3(x,0,z)); } } s->build(); //SceneNode* mPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(name); CollisionShape *Shape = new StaticPlaneCollisionShape (Ogre::Vector3(0,1,0), 0); RigidBody *defaultPlaneBody = new RigidBody( "Plane" + StringConverter::toString(mNumEntitiesInstanced), mWorld); defaultPlaneBody->setStaticShape (Shape, bodyRestitution, bodyFriction); mBodies.push_back(defaultPlaneBody); mShapes.push_back(Shape); mNumEntitiesInstanced++; return defaultPlaneBody; }
/* * Create Pacman Level * */ void PlayState::createLevel(){ StaticGeometry* stage = _sceneMgr->createStaticGeometry("SG"); Entity* entLevel = _sceneMgr-> createEntity("level1.mesh"); entLevel->setCastShadows(true); stage->addEntity(entLevel, Vector3(0,0,0)); stage->build(); StaticMeshToShapeConverter *trimeshConverter = new StaticMeshToShapeConverter(entLevel); TriangleMeshCollisionShape *trackTrimesh = trimeshConverter->createTrimesh(); RigidBody *rigidLevel = new RigidBody("level", _world,COL_WALL,COL_PILL | COL_PACMAN); rigidLevel->setStaticShape(trackTrimesh, 0.0, 0.0, Vector3::ZERO, Quaternion::IDENTITY); std::string fileName = "./blender/level1.xml"; graphLevel = new graphml_boost(); graphLevel->cargaGrafo(fileName); paintPills(false); paintPills(true); createPacman(); createPhantoms(); }
StaticGeometry *StaticGeometry::Load(NodeDatabase &db) { using namespace Graphics; StaticGeometry *sg = new StaticGeometry(db.loader->GetRenderer()); Serializer::Reader &rd = *db.rd; sg->m_blendMode = static_cast<Graphics::BlendMode>(rd.Int32()); sg->m_boundingBox.min = rd.Vector3d(); sg->m_boundingBox.max = rd.Vector3d(); Graphics::RenderStateDesc rsd; rsd.blendMode = sg->m_blendMode; rsd.depthWrite = rsd.blendMode == Graphics::BLEND_SOLID; sg->SetRenderState(sg->GetRenderer()->CreateRenderState(rsd)); const Uint32 numMeshes = rd.Int32(); for (Uint32 mesh = 0; mesh < numMeshes; mesh++) { //material RefCountedPtr<Graphics::Material> material; const std::string matName = rd.String(); if (starts_with(matName, "decal_")) { const unsigned int di = atoi(matName.substr(6).c_str()); material = db.loader->GetDecalMaterial(di); } else material = db.model->GetMaterialByName(matName); //vertex format check const Uint32 vtxFormat = db.rd->Int32(); if (vtxFormat != (ATTRIB_POSITION | ATTRIB_NORMAL | ATTRIB_UV0)) throw LoadingError("Unsupported vertex format"); //vertex buffer Graphics::VertexBufferDesc vbDesc; vbDesc.attrib[0].semantic = Graphics::ATTRIB_POSITION; vbDesc.attrib[0].format = Graphics::ATTRIB_FORMAT_FLOAT3; vbDesc.attrib[1].semantic = Graphics::ATTRIB_NORMAL; vbDesc.attrib[1].format = Graphics::ATTRIB_FORMAT_FLOAT3; vbDesc.attrib[2].semantic = Graphics::ATTRIB_UV0; vbDesc.attrib[2].format = Graphics::ATTRIB_FORMAT_FLOAT2; vbDesc.usage = Graphics::BUFFER_USAGE_STATIC; vbDesc.numVertices = db.rd->Int32(); RefCountedPtr<Graphics::VertexBuffer> vtxBuffer(db.loader->GetRenderer()->CreateVertexBuffer(vbDesc)); const Uint32 posOffset = vtxBuffer->GetDesc().GetOffset(Graphics::ATTRIB_POSITION); const Uint32 nrmOffset = vtxBuffer->GetDesc().GetOffset(Graphics::ATTRIB_NORMAL); const Uint32 uv0Offset = vtxBuffer->GetDesc().GetOffset(Graphics::ATTRIB_UV0); const Uint32 stride = vtxBuffer->GetDesc().stride; Uint8 *vtxPtr = vtxBuffer->Map<Uint8>(BUFFER_MAP_WRITE); for (Uint32 i = 0; i < vbDesc.numVertices; i++) { *reinterpret_cast<vector3f*>(vtxPtr + i * stride + posOffset) = db.rd->Vector3f(); *reinterpret_cast<vector3f*>(vtxPtr + i * stride + nrmOffset) = db.rd->Vector3f(); const float uvx = db.rd->Float(); const float uvy = db.rd->Float(); *reinterpret_cast<vector2f*>(vtxPtr + i * stride + uv0Offset) = vector2f(uvx, uvy); } vtxBuffer->Unmap(); //index buffer const Uint32 numIndices = db.rd->Int32(); RefCountedPtr<Graphics::IndexBuffer> idxBuffer(db.loader->GetRenderer()->CreateIndexBuffer(numIndices, Graphics::BUFFER_USAGE_STATIC)); Uint16 *idxPtr = idxBuffer->Map(BUFFER_MAP_WRITE); for (Uint32 i = 0; i < numIndices; i++) idxPtr[i] = db.rd->Int16(); idxBuffer->Unmap(); sg->AddMesh(vtxBuffer, idxBuffer, material); } return sg; }
void ArtifexLoader::staticsLoader(Ogre::String which, float renderDistance) { Ogre::String meshName="", meshFile="", xPos="", yPos="", zPos="", rot="", tmp="", typeName="", entName="", scale="", rotX="", rotZ=""; int counter=1; if (which.empty()) typeName = "static"; else typeName = which; StaticGeometry *staticGeometry; staticGeometry = mSceneMgr->createStaticGeometry((string)mZoneName+typeName); staticGeometry->setRenderingDistance(renderDistance); Ogre::String filename = mZonePath+mZoneName+"/spawns_" + typeName + ".cfg"; std::ifstream fp; fp.open(filename.c_str(), std::ios::in | std::ios::binary); if(!fp) return; DataStreamPtr stream(new FileStreamDataStream(filename, &fp, false)); Ogre::String line; do { for (int a=0;a<=10;a++) { line = stream->getLine(); if(stream->eof()) break; tmp = line; line = ""; Ogre::StringUtil::trim(tmp); if (Ogre::StringUtil::startsWith(tmp,"//",false) || tmp.empty()) { a--; continue; } else { switch (a) { case 0: meshName = tmp; break; case 1: // bracket break; case 2: meshFile = tmp; break; case 3: xPos = tmp; break; case 4: yPos = tmp; break; case 5: zPos = tmp; break; case 6: rot = tmp; break; case 7: scale = tmp; break; case 8: rotX = tmp; break; case 9: rotZ = tmp; break; case 10: // bracket close break; default: break; } tmp = ""; } } try { //*************************** entName = meshName; //*************************** Entity *newModel = mSceneMgr->createEntity((string) entName, (string) meshFile); newModel->setQueryFlags(ENTITY_MASK); //**************************** float x=0,y=0,z=0,r=0,s=0,rx=0,rz=0; x = Ogre::StringConverter::parseReal(xPos); y = Ogre::StringConverter::parseReal(yPos); z = Ogre::StringConverter::parseReal(zPos); r = Ogre::StringConverter::parseReal(rot); s = Ogre::StringConverter::parseReal(scale); rx = Ogre::StringConverter::parseReal(rotX); rz = Ogre::StringConverter::parseReal(rotZ); // auto drop models on terrain if (y==0) { float tmpY = getMeshYAdjust(meshFile)* s; //y = (float) mTerrainInfo->getHeightAt(x,z)+tmpY; y = getHeightAt(x,z)+tmpY; } //**************************** staticGeometry->addEntity(newModel,Ogre::Vector3(x,y,z),Quaternion ((Degree(r)), Vector3::UNIT_Y), Vector3(s,s,s)); mSceneMgr->destroyEntity(newModel); //*************************** } catch (Exception &e){ cout << "Troubles adding entity " << entName.c_str() << " to static geometry :" << e.what() << "\n"; }; counter ++; } while (!stream->eof() && !StringUtil::startsWith(tmp,"[END]",false)); staticGeometry->build(); }
table::table ( Ogre::SceneManager * SceneMgr ) { Scene * _mScene = mWorld->getScenes()->getFirst(); NxOgre::Material * RubberMat = mScene->createMaterial("Wood"); RubberMat->setRestitution(.3); RubberMat->setStaticFriction(.1); RubberMat->setDynamicFriction(.1); _mainTable = _mScene->createBody("table_collision", new NxOgre::TriangleMeshShape("table_collision.mesh","Group:TableGroup, material: Wood"), Vector3(0,0,0),"static: yes"); _mainTable->getNxActor()->setName("Table"); loadinganimation::getSingleton()->increment("Building(10)"); Entity * Posts = SceneMgr->createEntity("posts", "posts.mesh"); loadinganimation::getSingleton()->increment("Building(9)"); Entity * Bands = SceneMgr->createEntity("bands", "Bands.mesh"); loadinganimation::getSingleton()->increment("Building(8)"); Entity * Covers = SceneMgr->createEntity("covers", "covers.mesh"); loadinganimation::getSingleton()->increment("Building(7)"); Entity * Floor = SceneMgr->createEntity("floor", "floor.mesh"); loadinganimation::getSingleton()->increment("Building(6)"); Entity * Walls = SceneMgr->createEntity("walls", "walls.mesh"); loadinganimation::getSingleton()->increment("Building(5)"); Entity * ScrewsRails = SceneMgr->createEntity("screws_rails", "metal.mesh"); loadinganimation::getSingleton()->increment("Building(4)"); Entity * LaneCovers = SceneMgr->createEntity("lanecovers", "lane_covers.mesh"); loadinganimation::getSingleton()->increment("Building(3)"); Entity * Targets = SceneMgr->createEntity("targets", "targets.mesh"); //Entity * LightMap = SceneMgr->createEntity("light_map","fulltable_lightmap3.mesh"); //LightMap->setMaterialName("tablelightbake.material"); loadinganimation::getSingleton()->increment("Building(2)"); Posts->setMaterialName("Gile[s]_posts"); Bands->setMaterialName("Gile[s]_bands"); Covers->setMaterialName("Gile[s]_covers"); Floor->setMaterialName("Gile[s]_floor"); Walls->setMaterialName("Gile[s]_walls"); ScrewsRails->setMaterialName("Gile[s]_metals"); LaneCovers->setMaterialName("Gile[s]_lanecovers"); Targets->setMaterialName("Gile[s]_targets"); Posts->setCastShadows(false); Covers->setCastShadows(false); Floor->setCastShadows(false); Bands->setCastShadows(false); Walls->setCastShadows(false); ScrewsRails->setCastShadows(false); LaneCovers->setCastShadows(false); Targets->setCastShadows(false); const Vector3 _default(0,0,0); StaticGeometry * sg = SceneMgr->createStaticGeometry("TableParts"); const int size=50; const int amount = 8; sg->setRegionDimensions(Vector3(20,10,60)); sg->setOrigin(Vector3(10,0,30)); sg->addEntity(Posts,_default); sg->addEntity(Bands,_default); sg->addEntity(Covers,_default); sg->addEntity(Floor,_default); sg->addEntity(Walls,_default); sg->addEntity(ScrewsRails,_default); sg->addEntity(LaneCovers,_default); sg->addEntity(Targets,_default); //sg->addEntity(LightMap,_default); sg->build(); loadinganimation::getSingleton()->increment("Building(1)"); }