[Orxonox-commit 2459] r7166 - in code/trunk/src: libraries/core libraries/tools orxonox/graphics

landauf at orxonox.net landauf at orxonox.net
Mon Aug 16 22:56:26 CEST 2010


Author: landauf
Date: 2010-08-16 22:56:26 +0200 (Mon, 16 Aug 2010)
New Revision: 7166

Modified:
   code/trunk/src/libraries/core/ConfigValueIncludes.h
   code/trunk/src/libraries/tools/ParticleInterface.cc
   code/trunk/src/orxonox/graphics/Model.cc
   code/trunk/src/orxonox/graphics/Model.h
Log:
added new macro to ConfigValueIncludes.h, "SetConfigValueExternal" for values with user-defined name AND user-defined section

added new config value for models to enable/disable LOD (aimed towards people which experience crashes when using LOD)
moved config value for the LOD of ParticleInterface to the same section (GraphicsSettings) using the new macro

Modified: code/trunk/src/libraries/core/ConfigValueIncludes.h
===================================================================
--- code/trunk/src/libraries/core/ConfigValueIncludes.h	2010-08-16 18:31:40 UTC (rev 7165)
+++ code/trunk/src/libraries/core/ConfigValueIncludes.h	2010-08-16 20:56:26 UTC (rev 7166)
@@ -95,7 +95,22 @@
 #define SetConfigValueAlias(variable, entryName, defaultValue) \
     orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, this->getIdentifier()->getName(), entryName, defaultValue)
 
+/** Sets a runtime configurable value (simplified macro version of setConfigValueGeneric)
+    If the container for the value doesn't yet exist, a new one is created.
+    Also, the @a varname argument will be modified and set to the new value (default or from ini file).
+ at param variable
+    Variable name as C++ identifier.
+ at param sectionName
+    Name of the section in the ini file (e.g. [MySection])
+ at param entryName
+    Name of the entry in the ini file (e.g. [MySection] myValue)
+ at param defaultValue
+    Value to be used if it cannot be read from the ini file
+*/
+#define SetConfigValueExternal(variable, sectionName, entryName, defaultValue) \
+    orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, sectionName, entryName, defaultValue)
 
+
 namespace orxonox
 {
     /** Resets a runtime configurable value to its default.

Modified: code/trunk/src/libraries/tools/ParticleInterface.cc
===================================================================
--- code/trunk/src/libraries/tools/ParticleInterface.cc	2010-08-16 18:31:40 UTC (rev 7165)
+++ code/trunk/src/libraries/tools/ParticleInterface.cc	2010-08-16 20:56:26 UTC (rev 7166)
@@ -94,8 +94,9 @@
 
     void ParticleInterface::setConfigValues()
     {
-        SetConfigValue(globalDetailLevel_, 2)
-            .description("O: off, 1: low, 2: normal, 3: high").callback(this, &ParticleInterface::detailLevelChanged);
+        SetConfigValueExternal(globalDetailLevel_, "GraphicsSettings", "particlesDetailLevel", 2)
+            .description("O: off, 1: low, 2: normal, 3: high")
+            .callback(this, &ParticleInterface::detailLevelChanged);
     }
 
     Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()

Modified: code/trunk/src/orxonox/graphics/Model.cc
===================================================================
--- code/trunk/src/orxonox/graphics/Model.cc	2010-08-16 18:31:40 UTC (rev 7165)
+++ code/trunk/src/orxonox/graphics/Model.cc	2010-08-16 20:56:26 UTC (rev 7166)
@@ -31,6 +31,7 @@
 #include <OgreEntity.h>
 
 #include "core/CoreIncludes.h"
+#include "core/ConfigValueIncludes.h"
 #include "core/GameMode.h"
 #include "core/XMLPort.h"
 #include "Scene.h"
@@ -46,6 +47,7 @@
     {
         RegisterObject(Model);
 
+        this->setConfigValues();
         this->registerVariables();
     }
 
@@ -55,6 +57,12 @@
             this->detachOgreObject(this->mesh_.getEntity());
     }
 
+    void Model::setConfigValues()
+    {
+        SetConfigValueExternal(bGlobalEnableLod_, "GraphicsSettings", "enableModelLoD", true)
+            .description("Enable level of detail for models");
+    }
+
     void Model::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(Model, XMLPort, xmlelement, mode);
@@ -96,100 +104,106 @@
                 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
                 this->mesh_.setVisible(this->isVisible());
 
+                if (this->bGlobalEnableLod_)
+                    this->enableLod();
+            }
+        }
+    }
 
-                //LOD
-                if( this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1 )
-                {
-                    Level* level = this->getLevel();
+    void Model::changedShadows()
+    {
+        this->mesh_.setCastShadows(this->bCastShadows_);
+    }
 
-                    assert( level != 0 );
+    void Model::changedVisibility()
+    {
+        SUPER(Model, changedVisibility);
 
-                    MeshLodInformation* lodInfo = level->getLodInfo(this->meshSrc_);
-                    if( lodInfo )
-                    {
-                        setLodLevel(lodInfo->getLodLevel());
-                        this->bLodEnabled_ = lodInfo->getEnabled();
-                        this->numLodLevels_ = lodInfo->getNumLevels();
-                        this->lodReductionRate_ = lodInfo->getReductionRate();
-                    }
-                    if( this->numLodLevels_>10 )
-                    {
-                        CCOUT(2) << "More than 10 LoD levels requested. Creating only 10." << endl;
-                        this->numLodLevels_ = 10;
-                    }
-                    if( this->bLodEnabled_ )
-                    {
-                        float volume = this->mesh_.getEntity()->getBoundingBox().volume();
-    //                     float scaleFactor = 1;
+        this->mesh_.setVisible(this->isVisible());
+    }
 
-    //                     BaseObject* creatorPtr = this;
-    //
-    //                     while(creatorPtr!=NULL&&orxonox_cast<WorldEntity*>(creatorPtr))
-    //                     {
-    //                         scaleFactor *= getBiggestScale(((WorldEntity*) creatorPtr)->getScale3D());
-    //                         creatorPtr = creatorPtr->getCreator();
-    //                     }
-    //                     COUT(0) << "name: " << this->meshSrc_ << "scaleFactor: " << scaleFactor << ", volume: " << volume << endl;
+    void Model::enableLod()
+    {
+        //LOD
+        if( this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1 )
+        {
+            Level* level = this->getLevel();
 
-                        COUT(4) << "Setting lodLevel for " << this->meshSrc_<< " with lodLevel_: " << this->lodLevel_ <<" and volume: "<< volume << ":" << std::endl;
+            assert( level != 0 );
 
+            MeshLodInformation* lodInfo = level->getLodInfo(this->meshSrc_);
+            if( lodInfo )
+            {
+                setLodLevel(lodInfo->getLodLevel());
+                this->bLodEnabled_ = lodInfo->getEnabled();
+                this->numLodLevels_ = lodInfo->getNumLevels();
+                this->lodReductionRate_ = lodInfo->getReductionRate();
+            }
+            if( this->numLodLevels_>10 )
+            {
+                CCOUT(2) << "More than 10 LoD levels requested. Creating only 10." << endl;
+                this->numLodLevels_ = 10;
+            }
+            if( this->bLodEnabled_ )
+            {
+                float volume = this->mesh_.getEntity()->getBoundingBox().volume();
+/*
+                float scaleFactor = 1;
+
+                BaseObject* creatorPtr = this;
+
+                while(creatorPtr!=NULL&&orxonox_cast<WorldEntity*>(creatorPtr))
+                {
+                    scaleFactor *= getBiggestScale(((WorldEntity*) creatorPtr)->getScale3D());
+                    creatorPtr = creatorPtr->getCreator();
+                }
+                COUT(0) << "name: " << this->meshSrc_ << "scaleFactor: " << scaleFactor << ", volume: " << volume << endl;
+*/
+                COUT(4) << "Setting lodLevel for " << this->meshSrc_<< " with lodLevel_: " << this->lodLevel_ <<" and volume: "<< volume << ":" << std::endl;
+
 #if OGRE_VERSION >= 0x010700
-                        Ogre::Mesh::LodValueList distList;
+                Ogre::Mesh::LodValueList distList;
 #else
-                        Ogre::Mesh::LodDistanceList distList;
+                Ogre::Mesh::LodDistanceList distList;
 #endif
 
-                        if( lodLevel_>0 )
-                        {
-    //                         float factor = scaleFactor*5/lodLevel_;
-                            float factor = pow(volume, 2.0f / 3.0f) * 15.0f / lodLevel_;
+                if( lodLevel_>0 )
+                {
+//                    float factor = scaleFactor*5/lodLevel_;
+                    float factor = pow(volume, 2.0f / 3.0f) * 15.0f / lodLevel_;
 
-                            COUT(4) << "LodLevel set with factor: " << factor << endl;
+                    COUT(4) << "LodLevel set with factor: " << factor << endl;
 
-                            distList.push_back(70.0f*factor);
-                            distList.push_back(140.0f*factor);
-                            distList.push_back(170.0f*factor);
-                            distList.push_back(200.0f*factor);
-                            distList.push_back(230.0f*factor);
-                            distList.push_back(250.0f*factor);
-                            distList.push_back(270.0f*factor);
-                            distList.push_back(290.0f*factor);
-                            distList.push_back(310.0f*factor);
-                            distList.push_back(330.0f*factor);
-                            while(distList.size()>this->numLodLevels_)
-                                distList.pop_back();
+                    distList.push_back(70.0f*factor);
+                    distList.push_back(140.0f*factor);
+                    distList.push_back(170.0f*factor);
+                    distList.push_back(200.0f*factor);
+                    distList.push_back(230.0f*factor);
+                    distList.push_back(250.0f*factor);
+                    distList.push_back(270.0f*factor);
+                    distList.push_back(290.0f*factor);
+                    distList.push_back(310.0f*factor);
+                    distList.push_back(330.0f*factor);
+                    while(distList.size()>this->numLodLevels_)
+                        distList.pop_back();
 
 
-                            //Generiert LOD-Levels
-                            this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, this->lodReductionRate_);
-                        }
-                        else
-                        {
-                            std::string what;
-                            if(lodLevel_>5)
-                                what = ">5";
-                            else
-                                what = "<0";
+                    //Generiert LOD-Levels
+                    this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, this->lodReductionRate_);
+                }
+                else
+                {
+                    std::string what;
+                    if(lodLevel_>5)
+                        what = ">5";
+                    else
+                        what = "<0";
 
-                            COUT(4)<<"LodLevel not set because lodLevel("<<lodLevel_<<") was "<<what<<"." << endl;
-                        }
-                    }
-                    else
-                        COUT(4) << "LodLevel for " << this->meshSrc_ << " not set because is disabled." << endl;
+                    COUT(4)<<"LodLevel not set because lodLevel("<<lodLevel_<<") was "<<what<<"." << endl;
                 }
             }
+            else
+                COUT(4) << "LodLevel for " << this->meshSrc_ << " not set because is disabled." << endl;
         }
     }
-
-    void Model::changedShadows()
-    {
-        this->mesh_.setCastShadows(this->bCastShadows_);
-    }
-
-    void Model::changedVisibility()
-    {
-        SUPER(Model, changedVisibility);
-
-        this->mesh_.setVisible(this->isVisible());
-    }
 }

Modified: code/trunk/src/orxonox/graphics/Model.h
===================================================================
--- code/trunk/src/orxonox/graphics/Model.h	2010-08-16 18:31:40 UTC (rev 7165)
+++ code/trunk/src/orxonox/graphics/Model.h	2010-08-16 20:56:26 UTC (rev 7166)
@@ -43,6 +43,8 @@
             Model(BaseObject* creator);
             virtual ~Model();
 
+            void setConfigValues();
+
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
 
             virtual void changedVisibility();
@@ -66,6 +68,8 @@
             void changedShadows();
 
             //LoD
+            void enableLod();
+
             inline void setLodLevel(float lodLevel)
                 { this->lodLevel_ =  lodLevel; }
             inline float getLodLevel() const
@@ -77,6 +81,7 @@
             bool bCastShadows_;
 
             //LoD
+            bool bGlobalEnableLod_;
             float lodLevel_;
             bool bLodEnabled_;
             unsigned int numLodLevels_;




More information about the Orxonox-commit mailing list