Code

Changeset 158:40e5a0b0b15a

commit 158
40e5a0b0b15a
parent 157
bec01916f29a
branch
default
Removed experimental terrain cutting code

diff --git a/Plugins/OgModularZone/PortalEditor.cpp b/Plugins/OgModularZone/PortalEditor.cpp --- a/Plugins/OgModularZone/PortalEditor.cpp +++ b/Plugins/OgModularZone/PortalEditor.cpp @@ -46,9 +46,6 @@ mConnected(0), mLinked(false), mFreeMove(false) -#ifdef TERRAIN_CUT - ,mTerrainCut(0) -#endif //TERRAIN_CUT { mHandle = 0; mUsesGizmos = true; @@ -147,15 +144,6 @@ mPortalOutline = 0; } - #ifdef TERRAIN_CUT - if(mTerrainCut) - { - mTerrainCut->cleanup(); - delete mTerrainCut; - } - #endif //TERRAIN_CUT - - return Ogitors::CNodeEditor::unLoad(); } @@ -185,20 +173,7 @@ menuitems.push_back(OTR("Link")); } } -#ifdef TERRAIN_CUT - else - { - if(!mTerrainCut) - { - menuitems.push_back(OTR("Cut Terrain")); - } - else - { - menuitems.push_back(OTR("Refresh Terrain Cut")); - menuitems.push_back(OTR("Remove Terrain Cut")); - } - } -#endif //TERRAIN_CUT + } //possible feature -> snap-to ->portal_name. @@ -263,24 +238,7 @@ } } } -#ifdef TERRAIN_CUT - else - { - if(menuresult == 0) - { - //Carve tunnel thru terrain - //(or update an existing tunnel if zone has been moved etc) - carveTerrainTunnel(); - } - else if(menuresult == 1) - { - //remove the terrain cut - mTerrainCut->cleanup(); - delete mTerrainCut; - mTerrainCut = 0; - } - } -#endif //TERRAIN_CUT + } @@ -556,33 +514,8 @@ pDestination->SetAttribute("zone", mConnected->mParentZone->getName().c_str()); pDestination->SetAttribute("portal",mConnected->getName().c_str()); } -#ifdef TERRAIN_CUT - if(this->mTerrainCut) - { - //export terrain tunnel mesh and stencil cut - PROJECTOPTIONS* options = OgitorsRoot::getSingletonPtr()->GetProjectOptions(); - Ogre::String tunnelname = mTerrainCut->mTunnel->getName()+".mesh"; - Ogre::String stencilname = mTerrainCut->mStencil->getName()+".mesh"; - - Ogre::MeshPtr tunnel = mTerrainCut->mTunnel->convertToMesh(tunnelname); - Ogre::MeshPtr stencil = mTerrainCut->mStencil->convertToMesh(stencilname); - - Ogre::MeshSerializer meshexp; - meshexp.exportMesh(tunnel.get(),options->ProjectDir+"Zones/"+tunnelname); - meshexp.exportMesh(stencil.get(),options->ProjectDir+"Zones/"+stencilname); - - TiXmlElement *pTerrainCut = pNode->InsertEndChild(TiXmlElement("terrain_cut"))->ToElement(); - - pTerrainCut->SetAttribute("tunnel", tunnelname.c_str()); - pTerrainCut->SetAttribute("stencil",stencilname.c_str()); - - - - } -#endif //TERRAIN_CUT - return pNode; } @@ -632,346 +565,3 @@ } //---------------------------------------------------------------------------------------- -#ifdef TERRAIN_CUT -void PortalEditor::updateTerrainCut(void) -{ - if(this->mTerrainCut) - { - mTerrainCut->update(this->getDerivedPosition(),this->getDerivedOrientation(),mWidth->get(),mHeight->get()); - } -} - -bool PortalEditor::carveTerrainTunnel(void) -{ - //Make sure the Zones directory exists, and is part of project - //so dotScene exporter will handle this. - //(PortalEditor::exportDotScene needs to know where to put the - //generated meshes) - if(!createMZPDirectory())return false; - - try - { - - if(!mTerrainCut) - { - mTerrainCut = new TerrainCut(); - mTerrainCut->create(getName(),this->getDerivedPosition(),this->getDerivedOrientation(),mWidth->get(),mHeight->get()); - - Ogre::SceneNode* stencilNode = OgitorsRoot::getSingletonPtr()->GetSceneManager()->getRootSceneNode()->createChildSceneNode(mTerrainCut->getStencilOffset()); - stencilNode->attachObject(mTerrainCut->mStencil); - mTerrainCut->setStencilNode(stencilNode); - - //@ the moment I haven't got a separate offset for tunnel set up - using stencil - Ogre::SceneNode* tunnelNode = OgitorsRoot::getSingletonPtr()->GetSceneManager()->getRootSceneNode()->createChildSceneNode(mTerrainCut->getStencilOffset()); - tunnelNode->attachObject(mTerrainCut->mTunnel); - mTerrainCut->setTunnelNode(tunnelNode); - - } - else - { - mTerrainCut->update(this->getDerivedPosition(),this->getDerivedOrientation(),mWidth->get(),mHeight->get()); - } - } - catch(Ogre::Exception &e) - { - QMessageBox::information(QApplication::activeWindow(),"MZP",e.getDescription().c_str(),QMessageBox::Ok); - } - - - return true; -} -//---------------------------------------------------------------------------------------- -void TerrainCut::cleanup(void) -{ - if(mTunnel) - { - OgitorsRoot::getSingletonPtr()->GetSceneManager()->destroyManualObject(mTunnel); - } - if(mStencil) - { - OgitorsRoot::getSingletonPtr()->GetSceneManager()->destroyManualObject(mStencil); - } - if(mTunnelNode) - { - OgitorsRoot::getSingletonPtr()->GetSceneManager()->destroySceneNode(mTunnelNode); - - } - if(mStencilNode) - { - OgitorsRoot::getSingletonPtr()->GetSceneManager()->destroySceneNode(mStencilNode); - - } -} -//---------------------------------------------------------------------------------------- -void TerrainCut::create(Ogre::String name, Ogre::Vector3 position,Ogre::Quaternion orientation,Ogre::Real width,Ogre::Real height) -{ - //create mesh for stencil cut: - PROJECTOPTIONS* options = OgitorsRoot::getSingletonPtr()->GetProjectOptions(); - Ogre::ResourceManager::ResourceCreateOrRetrieveResult result = Ogre::MaterialManager::getSingletonPtr()->createOrRetrieve("MZP_StencilMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - - if(result.second) - { - Ogre::MaterialPtr stencilMaterial = result.first; - stencilMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(); - stencilMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setColourOperationEx( Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue( 0, 0, 0, 1) ); - - stencilMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SceneBlendType::SBT_TRANSPARENT_COLOUR); - stencilMaterial->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CompareFunction::CMPF_GREATER_EQUAL, 1); - stencilMaterial->getTechnique(0)->getPass(0)->setDepthBias(3.5f, 3.5f); - Ogre::MaterialSerializer matexp; - matexp.exportMaterial(stencilMaterial,options->ProjectDir+"/Zones/MZP_StencilMat.material"); - } - - mStencil = OgitorsRoot::getSingletonPtr()->GetSceneManager()->createManualObject(name + "Stencil"); - mStencil->begin("MZP_StencilMat", Ogre::RenderOperation::OT_TRIANGLE_LIST); - for(int p = 0;p<9;++p) - { - //just some initial values so beginUpdate doesn't spit the dummy - mStencil->position(Ogre::Vector3(0,0,0)); - mStencil->textureCoord(0.0,1.0); - } - mStencil->quad(0,7,8,1); - mStencil->quad(1,8,3,2); - mStencil->quad(8,5,4,3); - mStencil->quad(7,6,5,8); - mStencil->end(); - - mTunnel = OgitorsRoot::getSingletonPtr()->GetSceneManager()->createManualObject(name + "Tunnel"); - - Ogre::String tunnelMat = "MZP_TunnelMat"; - result = Ogre::MaterialManager::getSingletonPtr()->createOrRetrieve("MZP_TunnelMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - if(result.second) - { - Ogre::MaterialPtr tunnelMaterial = result.first; - tunnelMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("desert_2_diffuse.png"); - Ogre::MaterialSerializer matexp; - matexp.exportMaterial(tunnelMaterial,options->ProjectDir+"/Zones/MZP_TunnelMat.material"); - } - - for(int face = 0;face<4;++face)//set up 4 sides of tunnel - { - mTunnel->begin(tunnelMat, Ogre::RenderOperation::OT_TRIANGLE_LIST); - for(int pt = 0;pt<5;++pt) - { - mTunnel->position(Ogre::Vector3(0,0,0)); - mTunnel->textureCoord(0.0,0.0); - } - mTunnel->triangle(0,3,1); - mTunnel->triangle(1,3,4); - mTunnel->triangle(1,4,2); - mTunnel->end(); - } - - mTunnel->setRenderQueueGroup(Ogre::RENDER_QUEUE_WORLD_GEOMETRY_1); - update(position,orientation,width,height); -} -//---------------------------------------------------------------------------------------- -bool TerrainCut::update(Ogre::Vector3 position,Ogre::Quaternion orientation,Ogre::Real width,Ogre::Real height) -{ - //retrieve terrain - ITerrainEditor * terrain = OgitorsRoot::getSingletonPtr()->GetTerrainEditor(); - if(!terrain)return false; //no terrain - //calc portal corners & midpoints in local space - - //std::vector<Ogre::Vector3> points; - std::vector<Ogre::Vector2> tex; - const Ogre::Real left = -width/2; - const Ogre::Real right = width/2; - const Ogre::Real top = height/2; - const Ogre::Real bottom = -height/2; - - Ogre::Vector3 points[13]; - points[0]=(Ogre::Vector3(left,top,0.0));//1st point top left - points[1]=(Ogre::Vector3(0.0,top,0.0));//top middle - points[2]=(Ogre::Vector3(right,top,0.0));//top right - points[3]=(Ogre::Vector3(right,0.0,0.0));//mid right - points[4]=(Ogre::Vector3(right,bottom,0.0));//bottom right - points[5]=(Ogre::Vector3(0.0,bottom,0.0));//bottom middle - points[6]=(Ogre::Vector3(left,bottom,0.0));//bottom left - points[7]=(Ogre::Vector3(left,0.0,0.0));//middle left - points[8]=(Ogre::Vector3(0.0,0.0,0.0));//centre - - points[9]=(Ogre::Vector3(left,top,0.0));//1st point top left - points[10]=(Ogre::Vector3(right,top,0.0));//top right - points[11]=(Ogre::Vector3(right,bottom,0.0));//bottom right - points[12]=(Ogre::Vector3(left,bottom,0.0));//bottom left - - //update pos/orientation - for(int i = 0;i<13;++i) - { - //apply orientation - points[i] = orientation*points[i]; - //convert to world coords - points[i] = position + points[i]; - - } - - updateStencil(orientation,points); - updateTunnel(orientation,points,width,height); - - Ogre::String tunnelname = mTunnel->getName()+".mesh"; - Ogre::String stencilname = mStencil->getName()+".mesh"; - - Ogre::MeshPtr tunnel = mTunnel->convertToMesh(tunnelname); - Ogre::MeshPtr stencil = mStencil->convertToMesh(stencilname); - - //add Zones directory if not present - OFS::OfsPtr& ofsFile = OgitorsRoot::getSingletonPtr()->GetProjectFile(); - ofsFile->createDirectory("Zones"); - - Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr(); - Ogre::String zones_directory = OgitorsRoot::getSingletonPtr()->GetProjectFile()->getFileSystemName() + "::/Zones/"; - mngr->addResourceLocation(zones_directory,"Ofs","MESH_EXPORT_TEST"); - mngr->initialiseResourceGroup("MESH_EXPORT_TEST"); - - Ogre::DataStreamPtr meshFileStream = - mngr->createResource(tunnelname,"MESH_EXPORT_TEST",true,zones_directory);//zones_directory); - - - Ogre::MeshSerializer meshSerialiser; - meshSerialiser.exportMesh(tunnel.get(),meshFileStream); - meshFileStream->close();//important, close stream - - meshFileStream = - Ogre::Root::getSingletonPtr()->createFileStream(stencilname,"MESH_EXPORT_TEST",true,zones_directory); - - meshSerialiser.exportMesh(stencil.get(),meshFileStream); - meshFileStream->close();//important, close stream - - - return true; -} -//---------------------------------------------------------------------------------------- -bool TerrainCut::updateStencil(Ogre::Quaternion orientation,Ogre::Vector3 points[13]) -{ - if(!mStencil)return false;//stencil mesh not ready, abort - //retrieve terrain - ITerrainEditor * terrain = OgitorsRoot::getSingletonPtr()->GetTerrainEditor(); - if(!terrain)return false; //no terrain - - //UVs - Ogre::Vector2 texture[9]={ - Ogre::Vector2(0.0,0.0), - Ogre::Vector2(0.5,0.0), - Ogre::Vector2(1.0,0.0), - Ogre::Vector2(1.0,0.5), - Ogre::Vector2(1.0,1.0), - Ogre::Vector2(0.5,1.0), - Ogre::Vector2(0.0,1.0), - Ogre::Vector2(0.0,0.5), - Ogre::Vector2(0.5,0.5)}; - - - //fix the origin of mesh: - - Ogre::Ray ray(points[8], orientation * Ogre::Vector3::UNIT_Z ); - if(!terrain->hitTest(ray,&mStencilOffset)){return false;}//if no hit, abort - if(mStencilNode)mStencilNode->setPosition(mStencilOffset); - - - mStencil->beginUpdate(0); - //project points onto terrain - for(int i = 0;i < 9;++i) - { - Ogre::Ray ray(points[i], orientation * Ogre::Vector3::UNIT_Z ); - //Ogre::Vector3 point; - if(!terrain->hitTest(ray,&points[i]/*&point*/)) - {return false;}//if no hit, abort - points[i].y+=0.1; //TODO: replace this epsilon value with - //one moved along the ray - mStencil->position(points[i]-mStencilOffset); - mStencil->textureCoord(texture[i].x,texture[i].y); - } - - //update indices: - mStencil->quad(0,7,8,1); - mStencil->quad(1,8,3,2); - mStencil->quad(8,5,4,3); - mStencil->quad(7,6,5,8); - - mStencil->end(); - - return true; -} -//---------------------------------------------------------------------------------------- -bool TerrainCut::updateTunnel(Ogre::Quaternion orientation,Ogre::Vector3 points[13],Ogre::Real width,Ogre::Real height) -{ - //update vertices - if(mTunnelNode)mTunnelNode->setPosition(mStencilOffset); - - mTunnel->beginUpdate(0);//top - mTunnel->position(points[0]-mStencilOffset);//TODO U,V - mTunnel->textureCoord(points[0].distance(points[9]),points[9].distance(points[10])); - mTunnel->position(points[1]-mStencilOffset);//the UVs for this point are tricky ... - Ogre::Real U = std::sqrt(std::pow(points[1].distance(points[10]),2)-std::pow(width/2,2)); - mTunnel->textureCoord( U ,width/2); - mTunnel->position(points[2]-mStencilOffset); - mTunnel->textureCoord(points[2].distance(points[10]),0.0); - mTunnel->position(points[9]-mStencilOffset); - mTunnel->textureCoord(0.0,width); - mTunnel->position(points[10]-mStencilOffset); - mTunnel->textureCoord(0.0,0.0); - mTunnel->triangle(0,3,1); - mTunnel->triangle(1,3,4); - mTunnel->triangle(1,4,2); - mTunnel->end(); - - mTunnel->beginUpdate(1);//side - mTunnel->position(points[2]-mStencilOffset); - mTunnel->textureCoord(points[2].distance(points[10]),points[10].distance(points[11])); - mTunnel->position(points[3]-mStencilOffset);//the UVs for this point are tricky ... - U = std::sqrt(std::pow(points[3].distance(points[10]),2)-std::pow(height/2,2)); - mTunnel->textureCoord( U ,height/2); - mTunnel->position(points[4]-mStencilOffset); - mTunnel->textureCoord(points[4].distance(points[11]),0.0); - mTunnel->position(points[10]-mStencilOffset); - mTunnel->textureCoord(0.0,height); - mTunnel->position(points[11]-mStencilOffset); - mTunnel->textureCoord(0.0,0.0); - mTunnel->triangle(0,3,1); - mTunnel->triangle(1,3,4); - mTunnel->triangle(1,4,2); - mTunnel->end(); - - mTunnel->beginUpdate(2);//bottom - mTunnel->position(points[4]-mStencilOffset); - mTunnel->textureCoord(points[4].distance(points[11]),points[11].distance(points[12])); - mTunnel->position(points[5]-mStencilOffset);//the UVs for this point are tricky ... - U = std::sqrt(std::pow(points[5].distance(points[11]),2)-std::pow(width/2,2)); - mTunnel->textureCoord( U ,width/2); - mTunnel->position(points[6]-mStencilOffset); - mTunnel->textureCoord(points[6].distance(points[12]),0.0); - mTunnel->position(points[11]-mStencilOffset); - mTunnel->textureCoord(0.0,width); - mTunnel->position(points[12]-mStencilOffset); - mTunnel->textureCoord(0.0,0.0); - mTunnel->triangle(0,3,1); - mTunnel->triangle(1,3,4); - mTunnel->triangle(1,4,2); - mTunnel->end(); - - mTunnel->beginUpdate(3); - mTunnel->position(points[6]-mStencilOffset); - mTunnel->textureCoord(points[6].distance(points[12]),points[12].distance(points[9])); - mTunnel->position(points[7]-mStencilOffset);//the UVs for this point are tricky ... - U = std::sqrt(std::pow(points[7].distance(points[12]),2)-std::pow(height/2,2)); - mTunnel->textureCoord( U ,height/2); - mTunnel->position(points[0]-mStencilOffset); - mTunnel->textureCoord(points[0].distance(points[9]),0.0); - mTunnel->position(points[12]-mStencilOffset); - mTunnel->textureCoord(0.0,height); - mTunnel->position(points[9]-mStencilOffset); - mTunnel->textureCoord(0.0,0.0); - mTunnel->triangle(0,3,1); - mTunnel->triangle(1,3,4); - mTunnel->triangle(1,4,2); - mTunnel->end(); - - - return true; - -} - -#endif //TERRAIN_CUT - -//---------------------------------------------------------------------------------------- \ No newline at end of file
Up To File-list
diff --git a/Plugins/OgModularZone/PortalEditor.h b/Plugins/OgModularZone/PortalEditor.h --- a/Plugins/OgModularZone/PortalEditor.h +++ b/Plugins/OgModularZone/PortalEditor.h @@ -27,12 +27,10 @@ #include "PortalOutlineRenderable.h" using namespace Ogitors; -//#define TERRAIN_CUT namespace MZP { class ModularZoneEditor; - class TerrainCut; class PortalEditor : public CNodeEditor { @@ -105,49 +103,8 @@ bool _setDestination(OgitorsPropertyBase* property, const Ogre::String& value); bool _setWidth(OgitorsPropertyBase* property, const Ogre::Real& value); bool _setHeight(OgitorsPropertyBase* property, const Ogre::Real& value); -#ifdef TERRAIN_CUT - TerrainCut* mTerrainCut; - bool carveTerrainTunnel(void); - public: void updateTerrainCut(void); -#endif //TERRAIN_CUT - - }; - -#ifdef TERRAIN_CUT - class TerrainCut - { - public: - TerrainCut():mStencil(0),mTunnel(0),mStencilNode(0),mTunnelNode(0){} - ~TerrainCut(){} - Ogre::ManualObject* mStencil; - Ogre::ManualObject* mTunnel; - - private: - std::vector<Ogre::Vector3> points; - Ogre::Vector3 mStencilOffset; - Ogre::Vector3 mTunnelOffset; - Ogre::SceneNode* mStencilNode; - Ogre::SceneNode* mTunnelNode; - - - Ogre::MaterialPtr mBlendMaterial; - - public: - void create(Ogre::String name, Ogre::Vector3 position,Ogre::Quaternion orientation,Ogre::Real width,Ogre::Real height); - bool update(Ogre::Vector3 position,Ogre::Quaternion orientation,Ogre::Real width,Ogre::Real height); - bool TerrainCut::updateStencil(Ogre::Quaternion orientation,Ogre::Vector3 points[13]); - bool updateTunnel(Ogre::Quaternion orientation,Ogre::Vector3 points[13],Ogre::Real width,Ogre::Real height); - void cleanup(void); - const Ogre::Vector3 getStencilOffset(void){return mStencilOffset;} - const Ogre::Vector3 getTunnelOffset(void){return mTunnelOffset;} - Ogre::SceneNode* getStencilNode(void){return mStencilNode;} - Ogre::SceneNode* getTunnelNode(void){return mTunnelNode;} - void setStencilNode(Ogre::SceneNode* node){mStencilNode = node;} - void setTunnelNode(Ogre::SceneNode* node){mTunnelNode = node;} - }; -#endif //TERRAIN_CUT } #endif
Up To File-list