1. Frederic De Groef
  2. ogre-npr

Commits

Frederic De Groef  committed 0dc523d

batching all edges in one big entity: begin() addEntity() ... end()

  • Participants
  • Parent commits 15a7f8e
  • Branches default

Comments (0)

Files changed (5)

File media/npr/NPR.cg

View file
  • Ignore whitespace
 	float EdotN = dot(E,N);
 	float EdotT = dot(E,T);
  
-	float extend =  0.1 * (length(E)/75.0f);
+	float extend =  0.05 * (length(E)/75.0f);
     float3 newPos;
 
     // extend everything by default

File ogre-npr/EdgeGeometryBuilder.cpp

View file
  • Ignore whitespace
 
 
 //-----------------------------------------------------------------------------
-EdgeGeometryBuilder::EdgeGeometryBuilder(Ogre::Log *_log, Ogre::SceneManager *_sceneMgr)
-    :mLog(_log)
+EdgeGeometryBuilder::EdgeGeometryBuilder(const Ogre::String &_name, Ogre::Log *_log, Ogre::SceneManager *_sceneMgr)
+    :mName(_name)
+    ,mLog(_log)
     ,mSceneMgr(_sceneMgr)
     ,mIsBuilding(false)
-    ,mIsVisible(false)
     ,mEdges(NULL)
     ,mRidgeThreshold(40.0f)
 {
 void EdgeGeometryBuilder::begin()
 {
     mIsBuilding = true;
+
+    mEdges = mSceneMgr->createManualObject(mName);
+    mEdges->begin("NPR/EdgeOutliner", Ogre::RenderOperation::OT_TRIANGLE_LIST);
+    mIndex = 0;
+
 }
 //-----------------------------------------------------------------------------
 void EdgeGeometryBuilder::end()
 {
+    mEdges->end();
     mIsBuilding = false;
 }
 //-----------------------------------------------------------------------------
 void EdgeGeometryBuilder::addEdgesForEntity(Ogre::Entity *_ent)
 {
+    assert(mIsBuilding);
+
     mLog->logMessage("Creating edges for entity : " + _ent->getName());
-
     Ogre::MeshPtr mesh = _ent->getMesh();
 
     {
         mLog->logMessage(fmt.str());
     }
 
-    //mesh->getSubMesh(0)->setBuildEdgesEnabled(true);
-    //mesh->getSubMesh(1)->setBuildEdgesEnabled(true);
-
     mesh->buildEdgeList();
 
     Ogre::EdgeData *edgeData = mesh->getEdgeList();
         fmt % edgeData->edgeGroups.size();
         mLog->logMessage(fmt.str());
     }
-
-    mEdges = mSceneMgr->createManualObject(_ent->getName() + "edges");
-    //mMeshData = new MeshData(mesh,  Ogre::Vector3::ZERO, Ogre::Quaternion::IDENTITY, Ogre::Vector3::UNIT_SCALE);
-
     
-
-    mEdges->begin("NPR/EdgeOutliner", Ogre::RenderOperation::OT_TRIANGLE_LIST);
-
-    mIndex = 0;
     for(int edgeGroupIdx = 0 ; edgeGroupIdx < edgeData->edgeGroups.size() ; edgeGroupIdx++)
     {
         {
         }
 
     }
-    mEdges->end();
-
-    //delete mMeshData;
-    //mMeshData = NULL;
 }
 //-----------------------------------------------------------------------------
 void EdgeGeometryBuilder::_addEdgesForEdgeGroup(const Ogre::EdgeData::EdgeGroup &_edgeGroup, const Ogre::EdgeData &edgeData)

File ogre-npr/EdgeGeometryBuilder.hpp

View file
  • Ignore whitespace
 class EdgeGeometryBuilder
 {
 public:
-    EdgeGeometryBuilder(Ogre::Log *_log, Ogre::SceneManager *_sceneMgr);
+    EdgeGeometryBuilder(const Ogre::String &_name, Ogre::Log *_log, Ogre::SceneManager *_sceneMgr);
     ~EdgeGeometryBuilder();
     void begin();
     void addEdgesForEntity(Ogre::Entity *_ent);
     void end();
     void attachToSceneNode(Ogre::SceneNode*);
     void setVisible(bool _visible);
+    bool isVisible(){return mEdges->isVisible();};
 
 
 protected:
 
 
 protected:
+    Ogre::String mName;
     bool mIsBuilding;
-    bool mIsVisible;
     Ogre::ManualObject *mEdges;
     Ogre::Log *mLog;
     Ogre::SceneManager *mSceneMgr;

File ogre-npr/NPRDemoApp.cpp

View file
  • Ignore whitespace
     _populate();
 
     _createDebugOverlay();
-
-
-    mLightNode->detachObject(mLight);
-    //mCameraNode->attachObject(mLight);
-
-    mLightNode->setVisible(true);
-
-
 }
 //-----------------------------------------------------------------------------
 bool NPRDemoApp::frameStarted(const FrameEvent& evt)
 {
     if(mKeyboard->isKeyDown(OIS::KC_H))
     {
-        //BOOST_FOREACH(EdgeGeometryItem item, mEdges)
-        //{
-        //    mEdgesVisible = !mEdgesVisible;
-        //    _setEdgesVisible(item, mEdgesVisible);
-        //}
+        mStaticEdges->setVisible(!mStaticEdges->isVisible());
     }
     return OgreApplication::keyReleased(e);
 }
 
 
 
-    //_loadMesh("ulb_building_BATIMENTS_EST", Vector3(-1200, 0, 0));
-    //_loadMesh("ulb_building_BATIMENTS_TOUT", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_BATIMENTS_EST", Vector3(-1200, 0, 0));
+
     _loadMesh("ulb_building_bat_C", Vector3(-1200, 0, 0));
-    //_loadMesh("ulb_building_bat_C_1", Vector3(-1200, 0, 0));
-    //_loadMesh("ulb_building_bat_C_2", Vector3(-1200, 0, 0));
-
-    //_loadMesh("ulb_building_ASCENCEUR", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_ASCENCEUR", Vector3(-1200, 0, 0));
 
  
     _loadMesh("ulb_building_BAT_NEXT", Vector3(-1200, 0, 0));
     _loadMesh("ulb_building_tour", Vector3(-1200, 0, 0));
     _loadMesh("ulb_building_Z_LAYOUT", Vector3(-1200, 0, 0));
 
-    ////node->translate(0, 0, -1500);
-    //node->scale(0.1, 0.1, 0.1);
+    _buildStaticEdges();
+
 }
 //-----------------------------------------------------------------------------
 void NPRDemoApp::_loadScene(const String &_name, SceneNode* _node)
 	ent->setMaterialName("Shading/PerPixel/Gooch");
     node->attachObject(ent);
 
-    EdgeGeometryBuilder *edges = new EdgeGeometryBuilder(mLog, mSceneMgr);
-    edges->addEdgesForEntity(ent);
-    edges->setVisible(true);
-    edges->attachToSceneNode(node);
+    mScenePairs.push_back(NPRDemoApp::ScenePair(ent, node));
 
     return node;
 }
 //-----------------------------------------------------------------------------
+void NPRDemoApp::_buildStaticEdges()
+{
+    mStaticEdges = new EdgeGeometryBuilder("ULB static edges", mLog, mSceneMgr);
+    mStaticEdges->begin();
 
+    BOOST_FOREACH(NPRDemoApp::ScenePair pair, mScenePairs)
+    {
+        mStaticEdges->addEdgesForEntity(pair.first);
+
+    }
+    mStaticEdges->end();
+
+    mStaticEdges->setVisible(false);
+    Ogre::SceneNode *edgesNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("edges node", Ogre::Vector3(-1200, 0, 0));
+    mStaticEdges->attachToSceneNode(edgesNode);
+}
 //-----------------------------------------------------------------------------
 void NPRDemoApp::_setCelShadingMaterial(Entity *_ent)
 {

File ogre-npr/NPRDemoApp.h

View file
  • Ignore whitespace
 
 class NPRDemoApp : public OgreApplication, public OgreMax::OgreMaxSceneCallback
 {
+protected:
+    typedef std::pair<Ogre::Entity*, Ogre::SceneNode*> ScenePair;
+    typedef std::vector<ScenePair> ScenePairs;
 public:
     NPRDemoApp();
     void createScene();
 
 
     void _loadScene(const String&, SceneNode*);
+    void _buildStaticEdges();
 
 
 
     Billboard *mLightFlare;
     Light *mLight;
     SceneNode *mLightNode;
-
     TextRenderer *mDebugText;
 
     AnimationState *mAnimState;
-    //EdgeGeometryList mEdges;
     bool mEdgesVisible;
 
     Log *mLog;
-    std::list<EdgeGeometryBuilder*> mEdges;
+    EdgeGeometryBuilder* mStaticEdges;
+    ScenePairs mScenePairs;
 };