Revision: 8524
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8524&view=rev
Author:   natepak
Date:     2010-01-20 16:38:39 +0000 (Wed, 20 Jan 2010)

Log Message:
-----------
Applied patch from John Hsu

Modified Paths:
--------------
    code/gazebo/trunk/server/AssimpLoader.cc
    code/gazebo/trunk/server/Entity.cc
    code/gazebo/trunk/server/MeshManager.cc
    code/gazebo/trunk/server/Model.cc
    code/gazebo/trunk/server/World.cc
    code/gazebo/trunk/server/World.hh
    code/gazebo/trunk/server/gui/MainMenu.cc
    code/gazebo/trunk/server/gui/MainMenu.hh
    code/gazebo/trunk/server/rendering/Light.cc
    code/gazebo/trunk/server/rendering/Light.hh
    code/gazebo/trunk/server/rendering/OgreAdaptor.cc
    code/gazebo/trunk/server/rendering/OgreCreator.cc
    code/gazebo/trunk/server/rendering/OgreCreator.hh

Modified: code/gazebo/trunk/server/AssimpLoader.cc
===================================================================
--- code/gazebo/trunk/server/AssimpLoader.cc    2010-01-20 00:06:34 UTC (rev 
8523)
+++ code/gazebo/trunk/server/AssimpLoader.cc    2010-01-20 16:38:39 UTC (rev 
8524)
@@ -61,7 +61,8 @@
       {
         aiString matName;
         amat->Get(AI_MATKEY_NAME, matName);
-        mat->SetName(matName.data);
+        std::string uniqueMatName = filename + matName.data;
+        mat->SetName(uniqueMatName);
       }
       else if (propKey == "$clr.diffuse")
       {

Modified: code/gazebo/trunk/server/Entity.cc
===================================================================
--- code/gazebo/trunk/server/Entity.cc  2010-01-20 00:06:34 UTC (rev 8523)
+++ code/gazebo/trunk/server/Entity.cc  2010-01-20 16:38:39 UTC (rev 8524)
@@ -70,7 +70,6 @@
       this->visualNode = OgreCreator::Instance()->CreateVisual( 
           visname.str(), NULL, this );
   }
-
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: code/gazebo/trunk/server/MeshManager.cc
===================================================================
--- code/gazebo/trunk/server/MeshManager.cc     2010-01-20 00:06:34 UTC (rev 
8523)
+++ code/gazebo/trunk/server/MeshManager.cc     2010-01-20 16:38:39 UTC (rev 
8524)
@@ -55,7 +55,17 @@
   std::string extension;
 
   if (this->HasMesh(filename))
-    return this->meshes[filename];
+  {
+    //return this->meshes[filename];
+    
+    // erase mesh from this->meshes. This allows a mesh to be modified and
+    // inserted into gazebo again without closing gazebo.
+    std::map<std::string, Mesh*>::iterator iter;
+    iter = this->meshes.find(filename);
+    delete iter->second;
+    iter->second = NULL;
+    this->meshes.erase(iter);
+  }
 
   fullname =  std::string("./")+filename;
   if (stat(fullname.c_str(), &st) == 0)

Modified: code/gazebo/trunk/server/Model.cc
===================================================================
--- code/gazebo/trunk/server/Model.cc   2010-01-20 00:06:34 UTC (rev 8523)
+++ code/gazebo/trunk/server/Model.cc   2010-01-20 16:38:39 UTC (rev 8524)
@@ -145,6 +145,9 @@
     delete this->myBodyNameP;
     this->myBodyNameP = NULL;
   }
+
+  if (this->light)
+    OgreCreator::Instance()->DeleteLight(this->light);
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -1065,7 +1068,7 @@
   if (Simulator::Instance()->GetRenderEngineEnabled() && 
       (childNode = node->GetChild("light")))
   {
-    this->light = new Light(body);
+    this->light = OgreCreator::Instance()->CreateLight(body);
     this->light->Load(childNode);
   }
 

Modified: code/gazebo/trunk/server/World.cc
===================================================================
--- code/gazebo/trunk/server/World.cc   2010-01-20 00:06:34 UTC (rev 8523)
+++ code/gazebo/trunk/server/World.cc   2010-01-20 16:38:39 UTC (rev 8524)
@@ -60,6 +60,7 @@
   this->showBoundingBoxes = false;
   this->showJoints = false;
   this->showContacts = false;
+  this->showLights = false;
   this->wireframe = false;
   this->showPhysics = false;
   this->physicsEngine = NULL;
@@ -729,6 +730,21 @@
 }
 
 
////////////////////////////////////////////////////////////////////////////////
+/// Set whether to show the light source visuals
+void World::SetShowLights(bool show)
+{
+  this->showLights = show;
+  this->showLightsSignal(this->showLights);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get whether to show the light source visuals
+bool World::GetShowLights() const
+{
+  return this->showLights;
+}
+
+////////////////////////////////////////////////////////////////////////////////
 /// Set to view as wireframe
 void World::SetWireframe( bool wire )
 {

Modified: code/gazebo/trunk/server/World.hh
===================================================================
--- code/gazebo/trunk/server/World.hh   2010-01-20 00:06:34 UTC (rev 8523)
+++ code/gazebo/trunk/server/World.hh   2010-01-20 16:38:39 UTC (rev 8524)
@@ -194,6 +194,12 @@
   /// \brief Get whether to show the contacts
   public: bool GetShowContacts() const;
 
+  /// \brief Set whether to show the light source visuals
+  public: void SetShowLights(bool show);
+
+  /// \brief Get whether to show the light source visuals
+  public: bool GetShowLights() const;
+
   /// \brief Set to view as wireframe
   public: void SetWireframe( bool wire );
 
@@ -226,6 +232,8 @@
 
   private: bool showContacts;
 
+  private: bool showLights;
+
   private: bool showPhysics;
 
   private: bool wireframe;
@@ -253,6 +261,13 @@
             addEntitySignal.connect(subscriber);
           }
 
+  /// \brief Connect a boost::slot the the show light source signal
+  public: template<typename T>
+          void ConnectShowLightsSignal( T subscriber )
+          {
+            showLightsSignal.connect(subscriber);
+          }
+
   /// \brif Get the names of interfaces defined in the tree of a model
   private: void GetInterfaceNames(Entity* m, std::vector<std::string>& list);
 
@@ -301,6 +316,7 @@
   private: friend class SingletonT<World>;
 
   private: boost::signal<void (Entity*)> addEntitySignal;
+  private: boost::signal<void (bool)> showLightsSignal;
 
   private: std::deque<WorldState> worldStates;
   private: std::deque<WorldState>::iterator worldStatesInsertIter;

Modified: code/gazebo/trunk/server/gui/MainMenu.cc
===================================================================
--- code/gazebo/trunk/server/gui/MainMenu.cc    2010-01-20 00:06:34 UTC (rev 
8523)
+++ code/gazebo/trunk/server/gui/MainMenu.cc    2010-01-20 16:38:39 UTC (rev 
8524)
@@ -63,6 +63,7 @@
     { "Show Bounding Boxes", 0, &gazebo::MainMenu::ShowBoundingBoxesCB,0, 
FL_MENU_TOGGLE, FL_NORMAL_LABEL, 0, 14, 0},
     { "Show Joints", 0, &gazebo::MainMenu::ShowJointsCB,0, FL_MENU_TOGGLE, 
FL_NORMAL_LABEL, 0, 14, 0},
     { "Show Contacts", 0, &gazebo::MainMenu::ShowContactsCB,0, FL_MENU_TOGGLE, 
FL_NORMAL_LABEL, 0, 14, 0},
+    { "Show Lights", 0, &gazebo::MainMenu::ShowLightsCB,0, FL_MENU_TOGGLE, 
FL_NORMAL_LABEL, 0, 14, 0},
     { 0 },
 
     { 0 }
@@ -159,3 +160,10 @@
 {
   World::Instance()->SetShowContacts( !World::Instance()->GetShowContacts() );
 }
+
+////////////////////////////////////////////////////////////////////////////////
+// View the light source visuals
+void MainMenu::ShowLightsCB(Fl_Widget * /*w*/, void * /*data*/)
+{
+  World::Instance()->SetShowLights( !World::Instance()->GetShowLights() );
+}

Modified: code/gazebo/trunk/server/gui/MainMenu.hh
===================================================================
--- code/gazebo/trunk/server/gui/MainMenu.hh    2010-01-20 00:06:34 UTC (rev 
8523)
+++ code/gazebo/trunk/server/gui/MainMenu.hh    2010-01-20 16:38:39 UTC (rev 
8524)
@@ -57,6 +57,8 @@
 
     public: static void ShowContactsCB(Fl_Widget * /*w*/, void * /*data*/);
 
+    public: static void ShowLightsCB(Fl_Widget * /*w*/, void * /*data*/);
+
   };
 }
 

Modified: code/gazebo/trunk/server/rendering/Light.cc
===================================================================
--- code/gazebo/trunk/server/rendering/Light.cc 2010-01-20 00:06:34 UTC (rev 
8523)
+++ code/gazebo/trunk/server/rendering/Light.cc 2010-01-20 16:38:39 UTC (rev 
8524)
@@ -1,5 +1,7 @@
 #include <Ogre.h>
+#include <boost/bind.hpp>
 
+#include "World.hh"
 #include "Model.hh"
 #include "OgreDynamicLines.hh"
 #include "OgreVisual.hh"
@@ -26,6 +28,8 @@
   this->SetName(stream.str());
 
   this->lightCounter++;
+
+  World::Instance()->ConnectShowLightsSignal( boost::bind(&Light::ShowVisual, 
this, _1) );
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -223,6 +227,9 @@
   this->line->setVisibilityFlags(GZ_LASER_CAMERA);
 
   this->visual->AttachObject(line);
+
+  // turn off light source box visuals by default
+  this->visual->SetVisible(false);
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -237,4 +244,9 @@
     this->line->setMaterial("Gazebo/WhiteEmissive");
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
+// Set whether to show the visual
+void Light::ShowVisual(bool s)
+{
+  this->visual->SetVisible(s);
+}

Modified: code/gazebo/trunk/server/rendering/Light.hh
===================================================================
--- code/gazebo/trunk/server/rendering/Light.hh 2010-01-20 00:06:34 UTC (rev 
8523)
+++ code/gazebo/trunk/server/rendering/Light.hh 2010-01-20 16:38:39 UTC (rev 
8524)
@@ -21,10 +21,10 @@
   class Light : public Entity
   {
     /// \brief Constructor
-    public: Light(Entity *parent);
+    private: Light(Entity *parent);
 
     /// \brief Destructor
-    public: virtual ~Light();
+    private: virtual ~Light();
 
     /// \brief Load the light
     public: void Load(XMLConfigNode *node);
@@ -36,6 +36,9 @@
     ///        the gui
     public: virtual bool SetSelected( bool s );
 
+    /// \brief Set whether to show the visual
+    public: void ShowVisual(bool s);
+
     /// \private Helper node to create a visual representation of the light
     private: void CreateVisual();
 
@@ -47,6 +50,8 @@
     private: OgreDynamicLines *line;
 
     private: static unsigned int lightCounter;
+
+    private: friend class OgreCreator;
   };
 }
 #endif

Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2010-01-20 00:06:34 UTC 
(rev 8523)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2010-01-20 16:38:39 UTC 
(rev 8524)
@@ -365,6 +365,7 @@
     }
     closedir(dir);
 
+    archNames.push_back((*iter)+"/");
     archNames.push_back((*iter)+"/Media");
     archNames.push_back((*iter)+"/Media/fonts");
     archNames.push_back((*iter)+"/Media/materials/programs");

Modified: code/gazebo/trunk/server/rendering/OgreCreator.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreCreator.cc   2010-01-20 00:06:34 UTC 
(rev 8523)
+++ code/gazebo/trunk/server/rendering/OgreCreator.cc   2010-01-20 16:38:39 UTC 
(rev 8524)
@@ -34,6 +34,7 @@
 
 #include "config.h"
 
+#include "Light.hh"
 #include "Material.hh"
 #include "Simulator.hh"
 #include "Global.hh"
@@ -108,109 +109,31 @@
 
 
////////////////////////////////////////////////////////////////////////////////
 /// Create a light source and attach it to the visual node
-/// Note that the properties here are not modified afterwards and thus, 
-/// we don't need a Light class. 
-//std::string OgreCreator::CreateLight(XMLConfigNode *node, OgreVisual *parent)
-//{
-  /*if (!Simulator::Instance()->GetRenderEngineEnabled())
-    return std::string();
+Light *OgreCreator::CreateLight(Entity *parent)
+{
+  Light *newLight = new Light(parent);
+  this->lights.push_back(newLight);
+  return newLight;
+}
 
-  Light *light = new Light(parent);
-  light->Load(node);
-  this->lights.push_back(light);
+////////////////////////////////////////////////////////////////////////////////
+// Remove a light
+void OgreCreator::DeleteLight(Light *light)
+{
+  if (!light)
+    return;
 
-  return light->GetName();
-  */
-
-  /*
-  Vector3 vec;
-  double range,constant,linear,quad;
-  Ogre::Light *light;
-
-  // Create the light
-  std::ostringstream stream;
-  stream << parent->GetName() << "_LIGHT" << lightCounter;
-  lightCounter++;
-
-  try
+  std::list<Light*>::iterator iter;
+  for (iter = this->lights.begin(); iter != this->lights.end(); iter++)
   {
-    light = OgreAdaptor::Instance()->sceneMgr->createLight(stream.str());
-  } 
-  catch (Ogre::Exception e)
-  {
-    gzthrow("Ogre Error:" << e.getFullDescription() << "\n" << \
-             "Unable to create a light on " + parent->GetName());
+    if (*iter == light)
+    {
+      this->lights.erase(iter);
+      break;
+    }
   }
-  
-  // Set the light type
-  std::string lightType = node->GetString("type","point",0);
-  if (lightType == "point")
-  {
-    light->setType(Ogre::Light::LT_POINT);
-  }
-  else if (lightType == "directional")
-  {
-    light->setType(Ogre::Light::LT_DIRECTIONAL);
-  }
-  else if (lightType == "spot")
-  {
-    light->setType(Ogre::Light::LT_SPOTLIGHT);
-  }
+}
 
-  // Set the diffuse color
-  vec = node->GetVector3("diffuseColor",Vector3(1.0, 1.0, 1.0));
-  light->setDiffuseColour(vec.x, vec.y, vec.z);
-
-  // Sets the specular color
-  vec = node->GetVector3("specularColor",Vector3(1.0, 1.0, 1.0));
-  light->setSpecularColour(vec.x, vec.y, vec.z);
-
-  // Set the direction which the light points
-  vec = node->GetVector3("direction", Vector3(0.0, 0.0, -1.0));
-  vec.Normalize();
-  light->setDirection(vec.x, vec.y, vec.z);
-
-  // Absolute range of light in world coordinates
-  range = node->GetDouble("range",0,100);
-
-  // Constant factor. 1.0 means never attenuate, 0.0 is complete attenuation
-  constant = node->GetTupleDouble("attenuation",0,1.0);
-  if (constant < 0)
-    constant = 0;
-  else if (constant > 1.0)
-    constant = 1.0;
-
-  // Linear factor. 1 means attenuate evenly over the distance
-  linear = node->GetTupleDouble("attenuation",1,0);
-  if (linear < 0)
-    linear = 0;
-  else if (linear > 1.0)
-    linear = 1.0;
-
-  // Quadartic factor.adds a curvature to the attenuation formula
-  quad = node->GetTupleDouble("attenuation",2,0);
-
-  // Set attenuation
-  light->setAttenuation(range, constant, linear, quad);
-
-  // TODO: More options for Spot lights, etc.
-  //  options for spotlights
-  if (lightType == "spot")
-  {
-    vec = node->GetVector3("spotCone", Vector3(5.0, 10.0, 1.0));
-    light->setSpotlightRange(Ogre::Radian(Ogre::Degree(vec.x)), 
-        Ogre::Radian(Ogre::Degree(vec.y)), vec.z);
-  }
-
-  light->setCastShadows(node->GetBool("castShadows",true,0));
-
-  parent->AttachObject(light);
-
-  return stream.str();
-  */
-//}
-
-
 
////////////////////////////////////////////////////////////////////////////////
 // Helper function to create a camera
 Ogre::Camera *OgreCreator::CreateCamera(const std::string &name, 
@@ -750,6 +673,7 @@
   for (iter = this->lines.begin(); iter != this->lines.end(); iter++)
     (*iter)->Update();
 
+
   // We only need this loop because we are using threads. The physics engine
   // can't reliably set the pose of the visuals when it's running in a 
   // separate thread.

Modified: code/gazebo/trunk/server/rendering/OgreCreator.hh
===================================================================
--- code/gazebo/trunk/server/rendering/OgreCreator.hh   2010-01-20 00:06:34 UTC 
(rev 8523)
+++ code/gazebo/trunk/server/rendering/OgreCreator.hh   2010-01-20 16:38:39 UTC 
(rev 8524)
@@ -53,6 +53,7 @@
   class OgreVisual;
   class OgreMovableText;
   class OgreDynamicLines;
+  class Light;
 
 /// \addtogroup gazebo_rendering
 /// \{
@@ -76,11 +77,13 @@
                 const Vector2<double> &size, const Vector2<double> &segments, 
                 const Vector2<double> &uvTile, const std::string &material, 
                 bool castShadows, OgreVisual *parent, const std::string &name);
-    
-    /// \brief Create a light source 
-    /// \return The name of the light source
-    //public: static std::string CreateLight(XMLConfigNode *node, OgreVisual 
*parent);
 
+    /// \brief Create a light source and attach it to the visual node
+    public: Light *CreateLight(Entity *parent);
+
+    /// \brief Remove a light
+    public: void DeleteLight(Light *light);
+
     /// \brief Helper function to create a camera
     public: static Ogre::Camera *CreateCamera(const std::string &name, 
                 double nearClip, double farClip, double hfov, 
@@ -162,12 +165,15 @@
     // List of all the movable text
     private: std::list<OgreMovableText*> text;
 
+    // List of all the light sources
+    private: std::list<Light*> lights;
+
     // All the visuals 
     private: std::map<std::string, OgreVisual*> visuals;
 
     // All the windows
     private: std::list<Ogre::RenderWindow *> windows;
- 
+
     private: friend class DestroyerT<OgreCreator>;
     private: friend class SingletonT<OgreCreator>;
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to