Revision: 8385 http://playerstage.svn.sourceforge.net/playerstage/?rev=8385&view=rev Author: natepak Date: 2009-11-10 22:37:51 +0000 (Tue, 10 Nov 2009)
Log Message: ----------- Another performance improvement to trimeshes Modified Paths: -------------- code/gazebo/trunk/server/physics/TrimeshShape.cc code/gazebo/trunk/server/physics/TrimeshShape.hh code/gazebo/trunk/server/physics/ode/ODETrimeshShape.cc code/gazebo/trunk/server/physics/ode/ODETrimeshShape.hh code/gazebo/trunk/server/rendering/OgreCreator.cc Modified: code/gazebo/trunk/server/physics/TrimeshShape.cc =================================================================== --- code/gazebo/trunk/server/physics/TrimeshShape.cc 2009-11-10 21:55:39 UTC (rev 8384) +++ code/gazebo/trunk/server/physics/TrimeshShape.cc 2009-11-10 22:37:51 UTC (rev 8385) @@ -43,10 +43,11 @@ this->scaleP = new ParamT<Vector3>("scale",Vector3(1,1,1),0); Param::End(); - this->numVertices = 0; + /*this->numVertices = 0; this->numIndices = 0; this->vertices = NULL; this->indices = NULL; + */ } @@ -67,8 +68,10 @@ this->meshNameP->Load(node); this->scaleP->Load(node); - const Mesh *mesh = meshManager->Load( **this->meshNameP ); + this->mesh = meshManager->Load( **this->meshNameP ); + /*const Mesh *mesh = meshManager->Load( **this->meshNameP ); + if (!mesh) gzthrow("Invalid mesh"); @@ -83,6 +86,7 @@ this->vertices[i*3+1] = this->vertices[i*3+1] * (**this->scaleP).y; this->vertices[i*3+2] = this->vertices[i*3+2] * (**this->scaleP).z; } + */ } ////////////////////////////////////////////////////////////////////////////// Modified: code/gazebo/trunk/server/physics/TrimeshShape.hh =================================================================== --- code/gazebo/trunk/server/physics/TrimeshShape.hh 2009-11-10 21:55:39 UTC (rev 8384) +++ code/gazebo/trunk/server/physics/TrimeshShape.hh 2009-11-10 22:37:51 UTC (rev 8385) @@ -31,6 +31,8 @@ namespace gazebo { + class Mesh; + /// \addtogroup gazebo_physics_geom /// \{ /** \defgroup gazebo_trimesh_geom Triangle Mesh geom @@ -87,11 +89,14 @@ protected: ParamT<std::string> *meshNameP; protected: ParamT<Vector3> *scaleP; - +/* protected: unsigned int numVertices; protected: unsigned int numIndices; protected: float *vertices; protected: unsigned int *indices; + */ + + protected: const Mesh *mesh; }; /// \} Modified: code/gazebo/trunk/server/physics/ode/ODETrimeshShape.cc =================================================================== --- code/gazebo/trunk/server/physics/ode/ODETrimeshShape.cc 2009-11-10 21:55:39 UTC (rev 8384) +++ code/gazebo/trunk/server/physics/ode/ODETrimeshShape.cc 2009-11-10 22:37:51 UTC (rev 8385) @@ -24,6 +24,7 @@ * SVN: $Id$ */ +#include "Mesh.hh" #include "GazeboError.hh" #include "World.hh" #include "ODEGeom.hh" @@ -95,20 +96,50 @@ TrimeshShape::Load(node); - /// This will hold the vertex data of the triangle mesh - this->odeData = dGeomTriMeshDataCreate(); + mass = this->parent->GetMass(); - // Build the ODE triangle mesh - dGeomTriMeshDataBuildSingle( this->odeData, - (float*)this->vertices, 3*sizeof(float), this->numVertices, - (int*)this->indices, this->numIndices, 3*sizeof(int)); + for (unsigned int i=0; i < this->mesh->GetSubMeshCount(); i++) + { + dTriMeshDataID odeData; - pgeom->SetGeom( dCreateTriMesh( pgeom->GetSpaceId(), this->odeData,0,0,0 ), true ); + const SubMesh *subMesh = mesh->GetSubMesh(i); + if (subMesh->GetVertexCount() < 3) + continue; - mass = this->parent->GetMass(); + /// This will hold the vertex data of the triangle mesh + odeData = dGeomTriMeshDataCreate(); - dMassSetTrimeshTotal(&odeMass, mass.GetAsDouble(), pgeom->GetGeomId()); + unsigned int numVertices = 0; + unsigned int numIndices = 0; + float *vertices = NULL; + unsigned int *indices = NULL; + subMesh->FillArrays(&vertices, &indices); + + numIndices = subMesh->GetIndexCount(); + numVertices = subMesh->GetVertexCount(); + + for (unsigned int j=0; j < numVertices; j++) + { + vertices[j*3+0] = vertices[j*3+0] * (**this->scaleP).x; + vertices[j*3+1] = vertices[j*3+1] * (**this->scaleP).y; + vertices[j*3+2] = vertices[j*3+2] * (**this->scaleP).z; + } + + // Build the ODE triangle mesh + dGeomTriMeshDataBuildSingle( odeData, + (float*)vertices, 3*sizeof(float), numVertices, + (int*)indices, numIndices, 3*sizeof(int)); + + pgeom->SetGeom( dCreateTriMesh( pgeom->GetSpaceId(), odeData,0,0,0 ), true ); + + if (!pgeom->IsStatic()) + { + double massV = mass.GetAsDouble()/this->mesh->GetSubMeshCount(); + dMassSetTrimeshTotal(&odeMass, massV , pgeom->GetGeomId()); + } + } + physics->ConvertMass(&mass, &odeMass); this->parent->SetMass(mass); Modified: code/gazebo/trunk/server/physics/ode/ODETrimeshShape.hh =================================================================== --- code/gazebo/trunk/server/physics/ode/ODETrimeshShape.hh 2009-11-10 21:55:39 UTC (rev 8384) +++ code/gazebo/trunk/server/physics/ode/ODETrimeshShape.hh 2009-11-10 22:37:51 UTC (rev 8385) @@ -80,7 +80,7 @@ /// \brief Load the trimesh protected: virtual void Load(XMLConfigNode *node); - private: dTriMeshDataID odeData; + //private: dTriMeshDataID odeData; private: dReal matrix_dblbuff[16*2]; private: int last_matrix_index; Modified: code/gazebo/trunk/server/rendering/OgreCreator.cc =================================================================== --- code/gazebo/trunk/server/rendering/OgreCreator.cc 2009-11-10 21:55:39 UTC (rev 8384) +++ code/gazebo/trunk/server/rendering/OgreCreator.cc 2009-11-10 22:37:51 UTC (rev 8385) @@ -1006,8 +1006,6 @@ Vector3 max = mesh->GetMax(); Vector3 min = mesh->GetMin(); - std::cout << "Max[" << max << "] Min[" << min << "]\n"; - if (!max.IsFinite()) gzthrow("Max bounding box is not finite[" << max << "]\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit