CMultiMesh.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 2161 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CMultiMeshH
46 #define CMultiMeshH
47 //------------------------------------------------------------------------------
48 #include "world/CMesh.h"
49 //------------------------------------------------------------------------------
50 
51 //------------------------------------------------------------------------------
52 namespace chai3d {
53 //------------------------------------------------------------------------------
54 
55 //==============================================================================
62 //==============================================================================
63 
64 //==============================================================================
79 //==============================================================================
80 class cMultiMesh : public cGenericObject
81 {
82  //--------------------------------------------------------------------------
83  // CONSTRUCTOR & DESTRUCTOR:
84  //--------------------------------------------------------------------------
85 
86 public:
87 
89  cMultiMesh();
90 
92  virtual ~cMultiMesh();
93 
94 
95  //--------------------------------------------------------------------------
96  // PUBLIC METHODS - GENERAL:
97  //--------------------------------------------------------------------------
98 
99 public:
100 
102  virtual void setEnabled(bool a_enabled,
103  const bool a_affectChildren = false);
104 
106  virtual cMultiMesh* copy(const bool a_duplicateMaterialData = false,
107  const bool a_duplicateTextureData = false,
108  const bool a_duplicateMeshData = false,
109  const bool a_buildCollisionDetector = true);
110 
111 
112  //-----------------------------------------------------------------------
113  // PUBLIC METHODS - HAPTIC PROPERTIES:
114  //-----------------------------------------------------------------------
115 
116 public:
117 
119  virtual void setHapticEnabled(const bool a_hapticEnabled,
120  const bool a_affectChildren = false);
121 
123  virtual void setStiffness(const double a_stiffness,
124  const bool a_affectChildren = false);
125 
127  virtual void setFriction(double a_staticFriction,
128  double a_dynamicFriction,
129  const bool a_affectChildren = false);
130 
131 
132  //-----------------------------------------------------------------------
133  // PUBLIC METHODS - GRAPHIC PROPERTIES:
134  //-----------------------------------------------------------------------
135 
136 public:
137 
139  virtual void setShowEnabled(const bool a_show, const bool a_affectChildren = false);
140 
142  virtual void setWireMode(const bool a_showWireMode,
143  const bool a_affectChildren = true);
144 
146  virtual void setUseCulling(const bool a_useCulling,
147  const bool a_affectChildren=true);
148 
150  virtual void setUseTransparency(const bool a_useTransparency, const bool a_affectChildren = false);
151 
153  virtual void setTransparencyLevel(const float a_level,
154  const bool a_applyToVertices = false,
155  const bool a_applyToTextures = false,
156  const bool a_affectChildren = false);
157 
158 
159  //-----------------------------------------------------------------------
160  // PUBLIC METHODS - DISPLAY LISTS:
161  //-----------------------------------------------------------------------
162 
163 public:
164 
166  virtual void setUseDisplayList(const bool a_useDisplayList, const bool a_affectChildren = false);
167 
169  virtual void markForUpdate(const bool a_affectChildren = false);
170 
171 
172  //-----------------------------------------------------------------------
173  // PUBLIC METHODS - MATERIAL PROPERTIES:
174  //-----------------------------------------------------------------------
175 
176 public:
177 
179  virtual void setUseMaterial(const bool a_useMaterial, const bool a_affectChildren = true);
180 
182  virtual void setMaterial(cMaterialPtr a_material, const bool a_affectChildren = false);
183 
185  virtual void setMaterial(cMaterial& a_material, const bool a_affectChildren = false);
186 
188  virtual void backupMaterialColors(const bool a_affectChildren = false);
189 
191  virtual void restoreMaterialColors(const bool a_affectChildren = false);
192 
193 
194  //--------------------------------------------------------------------------
195  // PUBLIC METHODS - TEXTURE PROPERTIES:
196  //-----------------------------------------------------------------------
197 
198 public:
199 
201  virtual void setUseTexture(const bool a_useTexture, const bool a_affectChildren = true);
202 
204  virtual void setTexture(cTexture1dPtr, const bool a_affectChildren = false);
205 
206 
207  //-----------------------------------------------------------------------
208  // PUBLIC METHODS - SHADERS:
209  //-----------------------------------------------------------------------
210 
211 public:
212 
214  virtual void setShaderProgram(cShaderProgramPtr a_shaderProgram, const bool a_affectChildren = false);
215 
216 
217  //-----------------------------------------------------------------------
218  // PUBLIC METHODS - BOUNDARY BOX:
219  //-----------------------------------------------------------------------
220 
221 public:
222 
224  virtual void setShowBoundaryBox(const bool a_showBoundaryBox, const bool a_affectChildren = false);
225 
226 
227  //-----------------------------------------------------------------------
228  // PUBLIC METHODS - COLLISION DETECTION:
229  //-----------------------------------------------------------------------
230 
231 public:
232 
234  virtual void deleteCollisionDetector(const bool a_affectChildren = false);
235 
237  virtual bool computeCollisionDetection(const cVector3d& a_segmentPointA,
238  const cVector3d& a_segmentPointB,
239  cCollisionRecorder& a_recorder,
240  cCollisionSettings& a_settings);
241 
243  virtual void setShowCollisionDetector(const bool a_showCollisionDetector,
244  const bool a_affectChildren = false);
245 
247  virtual void setCollisionDetectorProperties(unsigned int a_displayDepth,
248  cColorf& a_color,
249  const bool a_affectChildren = false);
250 
252  virtual void createBruteForceCollisionDetector();
253 
255  virtual void createAABBCollisionDetector(const double a_radius);
256 
257 
258  //-----------------------------------------------------------------------
259  // PUBLIC VIRTUAL METHODS - INTERACTIONS
260  //-----------------------------------------------------------------------
261 
262 public:
263 
265  virtual cVector3d computeInteractions(const cVector3d& a_toolPos,
266  const cVector3d& a_toolVel,
267  const unsigned int a_IDN,
268  cInteractionRecorder& a_interactions);
269 
270 
271  //--------------------------------------------------------------------------
272  // PUBLIC METHODS - MESH PRIMITIVES:
273  //--------------------------------------------------------------------------
274 
275 public:
276 
278  cMesh* newMesh();
279 
281  bool addMesh(cMesh* a_mesh);
282 
284  bool removeMesh(cMesh* a_mesh);
285 
287  bool removeAllMesh();
288 
290  bool deleteMesh(cMesh* a_mesh);
291 
293  bool deleteAllMeshes();
294 
296  int getNumMeshes();
297 
299  cMesh* getMesh(unsigned int a_index);
300 
302  void convertToSingleMesh(cMesh* a_mesh);
303 
304 
305  //--------------------------------------------------------------------------
306  // PUBLIC METHODS - VERTICES
307  //--------------------------------------------------------------------------
308 
309 public:
310 
312  bool getVertex(const unsigned int a_index, cMesh*& a_mesh, unsigned int& a_vertexIndex);
313 
315  cVector3d getVertexPos(unsigned int a_index);
316 
318  unsigned int getNumVertices() const;
319 
321  virtual void setUseVertexColors(const bool a_useColors, const bool a_affectChildren=true);
322 
324  void setVertexColor(const cColorf& a_color);
325 
326 
327  //--------------------------------------------------------------------------
328  // PUBLIC METHODS - TRIANGLES
329  //--------------------------------------------------------------------------
330 
331 public:
332 
334  bool getTriangle(const unsigned int a_index, cMesh*& a_mesh, unsigned int& a_triangleIndex);
335 
337  unsigned int getNumTriangles() const;
338 
340  void clear();
341 
343  void setShowTriangles(const bool a_showTriangles);
344 
345 
346  //--------------------------------------------------------------------------
347  // PUBLIC METHODS - EDGES
348  //--------------------------------------------------------------------------
349 
350 public:
351 
353  void computeAllEdges(double a_angleThresholdDeg = 40.0);
354 
356  void clearAllEdges();
357 
359  void setShowEdges(const bool a_showEdges);
360 
362  void setEdgeProperties(const double a_width,
363  const cColorf& a_color);
364 
366  void setEdgeLineWidth(const double a_width);
367 
368 
369  //--------------------------------------------------------------------------
370  // PUBLIC METHODS - SURFACE NORMALS
371  //--------------------------------------------------------------------------
372 
373 public:
374 
376  void setShowNormals(const bool& a_showNormals);
377 
379  void setNormalsProperties(const double a_length, const cColorf& a_color);
380 
382  void setNormalsLength(const double a_length);
383 
385  void computeAllNormals();
386 
388  void reverseAllNormals();
389 
391  void computeBTN();
392 
394  void setShowTangents(const bool a_showTangents);
395 
396 
397  //--------------------------------------------------------------------------
398  // PUBLIC VIRTUAL METHODS - FILES:
399  //--------------------------------------------------------------------------
400 
401 public:
402 
404  virtual bool loadFromFile(std::string a_filename);
405 
407  virtual bool saveToFile(std::string a_filename);
408 
409 
410  //--------------------------------------------------------------------------
411  // PUBLIC METHODS - SCALING:
412  //--------------------------------------------------------------------------
413 
414 public:
415 
417  virtual void scale(const double& a_scaleFactor, const bool a_affectChildren = true);
418 
420  void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ);
421 
422 
423  //--------------------------------------------------------------------------
424  // PROTECTED METHODS:
425  //--------------------------------------------------------------------------
426 
427 protected:
428 
430  virtual void render(cRenderOptions& a_options);
431 
433  virtual void updateGlobalPositions(const bool a_frameOnly);
434 
436  virtual void updateBoundaryBox();
437 
440  const bool a_duplicateMaterialData,
441  const bool a_duplicateTextureData,
442  const bool a_duplicateMeshData,
443  const bool a_buildCollisionDetector);
444 
445 
446  //-----------------------------------------------------------------------
447  // PUBLIC MEMBERS
448  //-----------------------------------------------------------------------
449 
450 public:
451 
453  std::vector<cMesh*> *m_meshes;
454 
455 };
456 
457 //------------------------------------------------------------------------------
458 } // namespace chai3d
459 //------------------------------------------------------------------------------
460 
461 //------------------------------------------------------------------------------
462 #endif
463 //------------------------------------------------------------------------------
464 
This class implements a 3D vector.
Definition: CVector3d.h:88
virtual void backupMaterialColors(const bool a_affectChildren=false)
This method creates a backup of the material colors of this object, optionally propagating the operat...
Definition: CMultiMesh.cpp:433
virtual void setWireMode(const bool a_showWireMode, const bool a_affectChildren=true)
This method returns whether wireframe rendering is enabled.
Definition: CMultiMesh.cpp:361
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
virtual bool loadFromFile(std::string a_filename)
This method loads a 3D object from a file.
Definition: CMultiMesh.cpp:1550
bool removeMesh(cMesh *a_mesh)
This method removes a mesh primitive from the list of meshes.
Definition: CMultiMesh.cpp:1165
virtual void setFriction(double a_staticFriction, double a_dynamicFriction, const bool a_affectChildren=false)
This method sets the static and dynamic friction properties (polygonal models only), optionally recursively affecting children.
Definition: CMultiMesh.cpp:253
bool addMesh(cMesh *a_mesh)
This method adds an existing mesh primitives to list of meshes.
Definition: CMultiMesh.cpp:1138
bool deleteAllMeshes()
This method deletes all meshes.
Definition: CMultiMesh.cpp:1251
virtual void setCollisionDetectorProperties(unsigned int a_displayDepth, cColorf &a_color, const bool a_affectChildren=false)
This method sets the collision detector graphic display properties.
Definition: CMultiMesh.cpp:1009
This class implements a 3D multi-mesh object.
Definition: CMultiMesh.h:80
virtual void setUseTexture(const bool a_useTexture, const bool a_affectChildren=true)
This method enables or disables the use of texture-mapping, optionally propagating the operation to i...
Definition: CMultiMesh.cpp:609
void setEdgeProperties(const double a_width, const cColorf &a_color)
This method sets the graphic properties for edge-rendering.
Definition: CMultiMesh.cpp:1741
void convertToSingleMesh(cMesh *a_mesh)
This method converts this multimesh into a single mesh object.
Definition: CMultiMesh.cpp:1491
unsigned int getNumTriangles() const
This method returns the the number of stored triangles.
Definition: CMultiMesh.cpp:1394
virtual void setTexture(cTexture1dPtr, const bool a_affectChildren=false)
This method sets a texture to this object, optionally propagating the operation to its children...
Definition: CMultiMesh.cpp:637
virtual void setHapticEnabled(const bool a_hapticEnabled, const bool a_affectChildren=false)
This method enables or disables haptic perception of this object, optionally propagating the change t...
Definition: CMultiMesh.cpp:204
virtual void markForUpdate(const bool a_affectChildren=false)
This method invalidates any existing display lists, optionally propagating the operation to its child...
Definition: CMultiMesh.cpp:505
void clear()
This method clears all triangles and vertices of multi-mesh.
Definition: CMultiMesh.cpp:1475
Implements a class to model polygonal meshes.
void computeAllNormals()
This method computes all triangle normals.
Definition: CMultiMesh.cpp:1655
virtual void setUseCulling(const bool a_useCulling, const bool a_affectChildren=true)
Enable or disabling face-culling, optionally propagating the operation to my children.
Definition: CMultiMesh.cpp:385
virtual void createAABBCollisionDetector(const double a_radius)
Set up an AABB collision detector for this mesh.
Definition: CMultiMesh.cpp:1933
void setShowTangents(const bool a_showTangents)
This method enables or disables the rendering of tangents and bi-tangents.
Definition: CMultiMesh.cpp:1688
virtual void updateGlobalPositions(const bool a_frameOnly)
This method update the global position information about this object.
Definition: CMultiMesh.cpp:1812
std::shared_ptr< cTexture1d > cTexture1dPtr
Definition: CTexture1d.h:67
virtual void createBruteForceCollisionDetector()
Set up a brute force collision detector for this mesh and (optionally) for its children.
Definition: CMultiMesh.cpp:1916
std::shared_ptr< cMaterial > cMaterialPtr
Definition: CMaterial.h:67
void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ)
This method scales this object by using different factors along X,Y and Z axes.
Definition: CMultiMesh.cpp:1064
void copyMultiMeshProperties(cMultiMesh *a_obj, const bool a_duplicateMaterialData, const bool a_duplicateTextureData, const bool a_duplicateMeshData, const bool a_buildCollisionDetector)
This method copies all properties of this multi-mesh object to another.
Definition: CMultiMesh.cpp:136
virtual ~cMultiMesh()
Destructor of cMultiMesh.
Definition: CMultiMesh.cpp:83
virtual void setUseVertexColors(const bool a_useColors, const bool a_affectChildren=true)
This method enables or disables the use of per-vertex colors, optionally propagating the operation to...
Definition: CMultiMesh.cpp:410
virtual void setShaderProgram(cShaderProgramPtr a_shaderProgram, const bool a_affectChildren=false)
Set shader program.
Definition: CMultiMesh.cpp:663
virtual cVector3d computeInteractions(const cVector3d &a_toolPos, const cVector3d &a_toolVel, const unsigned int a_IDN, cInteractionRecorder &a_interactions)
Computer haptic interaction.
Definition: CMultiMesh.cpp:1973
cMesh * getMesh(unsigned int a_index)
This method returns a pointer to a mesh primitive by passing its index number.
Definition: CMultiMesh.cpp:1292
virtual void setStiffness(const double a_stiffness, const bool a_affectChildren=false)
This method sets the haptic stiffness of the object, optionally recursively affecting children...
Definition: CMultiMesh.cpp:228
cVector3d getVertexPos(unsigned int a_index)
This method returns the position data of specific vertex.
Definition: CMultiMesh.cpp:1418
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition: CGenericObject.h:112
virtual void scale(const double &a_scaleFactor, const bool a_affectChildren=true)
This method scales this object by a_scaleFactor (uniform scale).
Definition: CMultiMesh.cpp:1038
std::vector< cMesh * > * m_meshes
Array of meshes.
Definition: CMultiMesh.h:453
This class implements a collision detection recorder that stores all collision events that are report...
Definition: CCollisionBasics.h:185
void setNormalsLength(const double a_length)
This method set the length of normals for display purposes.
Definition: CMultiMesh.cpp:1884
void computeAllEdges(double a_angleThresholdDeg=40.0)
This method creates a list of edges by providing a threshold angle in degrees.
Definition: CMultiMesh.cpp:1779
int getNumMeshes()
This method retrieves the number of meshes that compose this multi-mesh object.
Definition: CMultiMesh.cpp:1276
void setNormalsProperties(const double a_length, const cColorf &a_color)
This method sets the graphic properties for normal-rendering.
Definition: CMultiMesh.cpp:1866
virtual void updateBoundaryBox()
This method updates the boundary box of this object.
Definition: CMultiMesh.cpp:720
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition: CCollisionBasics.h:242
virtual void setEnabled(bool a_enabled, const bool a_affectChildren=false)
This method enables or disables this object. When an object is disabled, both haptic and graphic rend...
Definition: CMultiMesh.cpp:178
void setEdgeLineWidth(const double a_width)
This method sets the line width of all edges.
Definition: CMultiMesh.cpp:1759
This class models material properties.
Definition: CMaterial.h:100
virtual void setShowCollisionDetector(const bool a_showCollisionDetector, const bool a_affectChildren=false)
This method enables or disables the display of the collision detector, optionally propagating the cha...
Definition: CMultiMesh.cpp:980
This class implements a 3D polygonal mesh.
Definition: CMesh.h:108
virtual bool computeCollisionDetection(const cVector3d &a_segmentPointA, const cVector3d &a_segmentPointB, cCollisionRecorder &a_recorder, cCollisionSettings &a_settings)
This method computes any collision between a segment and this object.
Definition: CMultiMesh.cpp:838
virtual void restoreMaterialColors(const bool a_affectChildren=false)
This method restores the material color properties of this object from a previous backup...
Definition: CMultiMesh.cpp:455
virtual void deleteCollisionDetector(const bool a_affectChildren=false)
This method deletes any existing collision detector.
Definition: CMultiMesh.cpp:805
virtual void setShowEnabled(const bool a_show, const bool a_affectChildren=false)
This method enables or disables the graphic display of this object, optionally propagating the change...
Definition: CMultiMesh.cpp:278
This class defines a color using a GLfloat representation for each component.
Definition: CColor.h:138
virtual void setMaterial(cMaterialPtr a_material, const bool a_affectChildren=false)
This method sets the material properties of this object, optionally propagating the operation to its ...
Definition: CMultiMesh.cpp:556
virtual void render(cRenderOptions &a_options)
This method renders this object graphically using OpenGL.
Definition: CMultiMesh.cpp:1950
void setVertexColor(const cColorf &a_color)
This method sets the color of each vertex.
Definition: CMultiMesh.cpp:1831
This class stores a list of interaction events.
Definition: CInteractionBasics.h:133
std::shared_ptr< cShaderProgram > cShaderProgramPtr
Definition: CShaderProgram.h:70
cMultiMesh()
Constructor of cMultiMesh.
Definition: CMultiMesh.cpp:71
bool getVertex(const unsigned int a_index, cMesh *&a_mesh, unsigned int &a_vertexIndex)
This method returns the index number and mesh of a specific vertex that is part of this multi-mesh...
Definition: CMultiMesh.cpp:1356
bool deleteMesh(cMesh *a_mesh)
This method deletes a mesh primitive from the list of meshes.
Definition: CMultiMesh.cpp:1221
unsigned int getNumVertices() const
This method returns the the number of stored vertices.
Definition: CMultiMesh.cpp:1456
cMesh * newMesh()
This method creates a new mesh primitive.
Definition: CMultiMesh.cpp:1114
Definition: CAudioBuffer.cpp:56
virtual void setUseMaterial(const bool a_useMaterial, const bool a_affectChildren=true)
This method enables or disables the use of material properties, optionally propagating the operation ...
Definition: CMultiMesh.cpp:527
void clearAllEdges()
This method clears all edges.
Definition: CMultiMesh.cpp:1794
virtual cMultiMesh * copy(const bool a_duplicateMaterialData=false, const bool a_duplicateTextureData=false, const bool a_duplicateMeshData=false, const bool a_buildCollisionDetector=true)
This method creates a copy of itself.
Definition: CMultiMesh.cpp:105
virtual void setShowBoundaryBox(const bool a_showBoundaryBox, const bool a_affectChildren=false)
This method enables or disabled the graphic display of the boundary box for this object, optionally propagating the change to its children.
Definition: CMultiMesh.cpp:699
void reverseAllNormals()
This method reverses all normals on this model.
Definition: CMultiMesh.cpp:1848
virtual void setUseDisplayList(const bool a_useDisplayList, const bool a_affectChildren=false)
This method enabled or disables the use of a display list for rendering, optionally propagating the o...
Definition: CMultiMesh.cpp:481
bool removeAllMesh()
This method removes all mesh primitives.
Definition: CMultiMesh.cpp:1194
void setShowEdges(const bool a_showEdges)
This method enables or disables the rendering of edges.
Definition: CMultiMesh.cpp:1722
void setShowNormals(const bool &a_showNormals)
This method enables or disables the rendering of vertex normals.
Definition: CMultiMesh.cpp:1901
virtual void setTransparencyLevel(const float a_level, const bool a_applyToVertices=false, const bool a_applyToTextures=false, const bool a_affectChildren=false)
This method sets the transparency level of the object.
Definition: CMultiMesh.cpp:332
void computeBTN()
This method computes the normal matrix vectors for all triangles.
Definition: CMultiMesh.cpp:1670
virtual bool saveToFile(std::string a_filename)
This method saves 3D object to a file.
Definition: CMultiMesh.cpp:1605
void setShowTriangles(const bool a_showTriangles)
This method enables or disables the rendering of triangles.
Definition: CMultiMesh.cpp:1705
bool getTriangle(const unsigned int a_index, cMesh *&a_mesh, unsigned int &a_triangleIndex)
This method returns the index number and mesh of a specific triangle that is part of this multi-mesh...
Definition: CMultiMesh.cpp:1315
virtual void setUseTransparency(const bool a_useTransparency, const bool a_affectChildren=false)
This method enables or disables transparency.
Definition: CMultiMesh.cpp:303