CHAI3D  3.0.0
CMultiMesh.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2015, 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.0.0 $Rev: 1656 $
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_applyToTextures = false,
155  const bool a_affectChildren = false);
156 
157 
158  //-----------------------------------------------------------------------
159  // PUBLIC METHODS - DISPLAY LISTS:
160  //-----------------------------------------------------------------------
161 
162 public:
163 
165  virtual void setUseDisplayList(const bool a_useDisplayList, const bool a_affectChildren = false);
166 
168  virtual void markForUpdate(const bool a_affectChildren = false);
169 
170 
171  //-----------------------------------------------------------------------
172  // PUBLIC METHODS - MATERIAL PROPERTIES:
173  //-----------------------------------------------------------------------
174 
175 public:
176 
178  virtual void setUseMaterial(const bool a_useMaterial, const bool a_affectChildren = true);
179 
181  virtual void setMaterial(cMaterialPtr a_material, const bool a_affectChildren = false);
182 
184  virtual void setMaterial(cMaterial& a_material, const bool a_affectChildren = false);
185 
187  virtual void backupMaterialColors(const bool a_affectChildren = false);
188 
190  virtual void restoreMaterialColors(const bool a_affectChildren = false);
191 
192 
193  //--------------------------------------------------------------------------
194  // PUBLIC METHODS - TEXTURE PROPERTIES:
195  //-----------------------------------------------------------------------
196 
197 public:
198 
200  virtual void setUseTexture(const bool a_useTexture, const bool a_affectChildren = true);
201 
203  virtual void setTexture(cTexture1dPtr, const bool a_affectChildren = false);
204 
205 
206  //-----------------------------------------------------------------------
207  // PUBLIC METHODS - SHADERS:
208  //-----------------------------------------------------------------------
209 
210 public:
211 
213  virtual void setShaderProgram(cShaderProgramPtr a_shaderProgram, const bool a_affectChildren = false);
214 
215 
216  //-----------------------------------------------------------------------
217  // PUBLIC METHODS - BOUNDARY BOX:
218  //-----------------------------------------------------------------------
219 
220 public:
221 
223  virtual void setShowBoundaryBox(const bool a_showBoundaryBox, const bool a_affectChildren = false);
224 
225 
226  //-----------------------------------------------------------------------
227  // PUBLIC METHODS - COLLISION DETECTION:
228  //-----------------------------------------------------------------------
229 
230 public:
231 
233  virtual void deleteCollisionDetector(const bool a_affectChildren = false);
234 
236  virtual bool computeCollisionDetection(const cVector3d& a_segmentPointA,
237  const cVector3d& a_segmentPointB,
238  cCollisionRecorder& a_recorder,
239  cCollisionSettings& a_settings);
240 
242  virtual void setShowCollisionDetector(const bool a_showCollisionDetector,
243  const bool a_affectChildren = false);
244 
246  virtual void setCollisionDetectorProperties(unsigned int a_displayDepth,
247  cColorf& a_color,
248  const bool a_affectChildren = false);
249 
251  virtual void createBruteForceCollisionDetector();
252 
254  virtual void createAABBCollisionDetector(const double a_radius);
255 
256 
257  //-----------------------------------------------------------------------
258  // PUBLIC VIRTUAL METHODS - INTERACTIONS
259  //-----------------------------------------------------------------------
260 
261 public:
262 
264  virtual cVector3d computeInteractions(const cVector3d& a_toolPos,
265  const cVector3d& a_toolVel,
266  const unsigned int a_IDN,
267  cInteractionRecorder& a_interactions);
268 
269 
270  //--------------------------------------------------------------------------
271  // PUBLIC METHODS - MESH PRIMITIVES:
272  //--------------------------------------------------------------------------
273 
274 public:
275 
277  cMesh* newMesh();
278 
280  bool addMesh(cMesh* a_mesh);
281 
283  bool removeMesh(cMesh* a_mesh);
284 
286  bool removeAllMesh();
287 
289  bool deleteMesh(cMesh* a_mesh);
290 
292  bool deleteAllMeshes();
293 
295  int getNumMeshes();
296 
298  cMesh* getMesh(unsigned int a_index);
299 
300 
301  //--------------------------------------------------------------------------
302  // PUBLIC METHODS - VERTICES
303  //--------------------------------------------------------------------------
304 
305 public:
306 
308  bool getVertex(const unsigned int a_index, cMesh*& a_mesh, unsigned int& a_vertexIndex);
309 
311  cVector3d getVertexPos(unsigned int a_index);
312 
314  unsigned int getNumVertices() const;
315 
317  virtual void setUseVertexColors(const bool a_useColors, const bool a_affectChildren=true);
318 
320  void setVertexColor(const cColorf& a_color);
321 
322 
323  //--------------------------------------------------------------------------
324  // PUBLIC METHODS - TRIANGLES
325  //--------------------------------------------------------------------------
326 
327 public:
328 
330  bool getTriangle(const unsigned int a_index, cMesh*& a_mesh, unsigned int& a_triangleIndex);
331 
333  unsigned int getNumTriangles() const;
334 
336  void clear();
337 
339  void setShowTriangles(const bool a_showTriangles);
340 
341 
342  //--------------------------------------------------------------------------
343  // PUBLIC METHODS - EDGES
344  //--------------------------------------------------------------------------
345 
346 public:
347 
349  void computeAllEdges(double a_angleThresholdDeg = 40.0);
350 
352  void clearAllEdges();
353 
355  void setShowEdges(const bool a_showEdges);
356 
358  void setEdgeProperties(const double a_width,
359  const cColorf& a_color);
360 
362  void setEdgeLineWidth(const double a_width);
363 
364 
365  //--------------------------------------------------------------------------
366  // PUBLIC METHODS - SURFACE NORMALS
367  //--------------------------------------------------------------------------
368 
369 public:
370 
372  void setShowNormals(const bool& a_showNormals);
373 
375  void setNormalsProperties(const double a_length, const cColorf& a_color);
376 
378  void setNormalsLength(const double a_length);
379 
381  void computeAllNormals();
382 
384  void reverseAllNormals();
385 
386 
387  //--------------------------------------------------------------------------
388  // PUBLIC VIRTUAL METHODS - FILES:
389  //--------------------------------------------------------------------------
390 
391 public:
392 
394  virtual bool loadFromFile(std::string a_filename);
395 
397  virtual bool saveToFile(std::string a_filename);
398 
399 
400  //--------------------------------------------------------------------------
401  // PUBLIC METHODS - SCALING:
402  //--------------------------------------------------------------------------
403 
404 public:
405 
407  virtual void scale(const double& a_scaleFactor, const bool a_affectChildren = true);
408 
410  void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ);
411 
412 
413  //--------------------------------------------------------------------------
414  // PROTECTED METHODS:
415  //--------------------------------------------------------------------------
416 
417 protected:
418 
420  virtual void render(cRenderOptions& a_options);
421 
423  virtual void updateGlobalPositions(const bool a_frameOnly);
424 
426  virtual void updateBoundaryBox();
427 
430  const bool a_duplicateMaterialData,
431  const bool a_duplicateTextureData,
432  const bool a_duplicateMeshData,
433  const bool a_buildCollisionDetector);
434 
435 
436  //-----------------------------------------------------------------------
437  // PUBLIC MEMBERS
438  //-----------------------------------------------------------------------
439 
440 public:
441 
443  std::vector<cMesh*> *m_meshes;
444 
445 };
446 
447 //------------------------------------------------------------------------------
448 } // namespace chai3d
449 //------------------------------------------------------------------------------
450 
451 //------------------------------------------------------------------------------
452 #endif
453 //------------------------------------------------------------------------------
454 
This class implements a 3D vector.
Definition: CVector3d.h:85
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:435
virtual void setWireMode(const bool a_showWireMode, const bool a_affectChildren=true)
This method returns whether wireframe rendering is enabled.
Definition: CMultiMesh.cpp:363
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:1496
bool removeMesh(cMesh *a_mesh)
This method removes a mesh primitive from the list of meshes.
Definition: CMultiMesh.cpp:1166
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:256
bool addMesh(cMesh *a_mesh)
This method adds an existing mesh primitives to list of meshes.
Definition: CMultiMesh.cpp:1139
bool deleteAllMeshes()
This method deletes all meshes.
Definition: CMultiMesh.cpp:1252
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:1011
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:611
void setEdgeProperties(const double a_width, const cColorf &a_color)
This method sets the graphic properties for edge-rendering.
Definition: CMultiMesh.cpp:1654
unsigned int getNumTriangles() const
This method returns the the number of stored triangles.
Definition: CMultiMesh.cpp:1395
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:639
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:207
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:507
void clear()
This method clears all triangles and vertices of multi-mesh.
Definition: CMultiMesh.cpp:1476
Implements a class to model polygonal meshes.
void computeAllNormals()
This method computes all triangle normals.
Definition: CMultiMesh.cpp:1601
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:387
virtual void setTransparencyLevel(const float a_level, const bool a_applyToTextures=false, const bool a_affectChildren=false)
This method sets the transparency level of the object.
Definition: CMultiMesh.cpp:334
virtual void createAABBCollisionDetector(const double a_radius)
Set up an AABB collision detector for this mesh.
Definition: CMultiMesh.cpp:1846
virtual void updateGlobalPositions(const bool a_frameOnly)
This method update the global position information about this object.
Definition: CMultiMesh.cpp:1725
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:1829
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:1065
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:139
virtual ~cMultiMesh()
Destructor of cMultiMesh.
Definition: CMultiMesh.cpp:89
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:412
virtual void setShaderProgram(cShaderProgramPtr a_shaderProgram, const bool a_affectChildren=false)
Set shader program.
Definition: CMultiMesh.cpp:665
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:1886
cMesh * getMesh(unsigned int a_index)
This method returns a pointer to a mesh primitive by passing its index number.
Definition: CMultiMesh.cpp:1293
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:231
cVector3d getVertexPos(unsigned int a_index)
This method returns the position data of specific vertex.
Definition: CMultiMesh.cpp:1419
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:1040
std::vector< cMesh * > * m_meshes
Array of meshes.
Definition: CMultiMesh.h:443
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:1797
void computeAllEdges(double a_angleThresholdDeg=40.0)
This method creates a list of edges by providing a threshold angle in degrees.
Definition: CMultiMesh.cpp:1692
int getNumMeshes()
This method retrieves the number of meshes that compose this multi-mesh object.
Definition: CMultiMesh.cpp:1277
void setNormalsProperties(const double a_length, const cColorf &a_color)
This method sets the graphic properties for normal-rendering.
Definition: CMultiMesh.cpp:1779
virtual void updateBoundaryBox()
This method updates the boundary box of this object.
Definition: CMultiMesh.cpp:722
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:181
void setEdgeLineWidth(const double a_width)
This method sets the line width of all edges.
Definition: CMultiMesh.cpp:1672
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:982
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:840
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:457
virtual void deleteCollisionDetector(const bool a_affectChildren=false)
This method deletes any existing collision detector.
Definition: CMultiMesh.cpp:807
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:281
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:558
virtual void render(cRenderOptions &a_options)
This method renders this object graphically using OpenGL.
Definition: CMultiMesh.cpp:1863
void setVertexColor(const cColorf &a_color)
This method sets the color of each vertex.
Definition: CMultiMesh.cpp:1744
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:1357
bool deleteMesh(cMesh *a_mesh)
This method deletes a mesh primitive from the list of meshes.
Definition: CMultiMesh.cpp:1222
unsigned int getNumVertices() const
This method returns the the number of stored vertices.
Definition: CMultiMesh.cpp:1457
cMesh * newMesh()
This method creates a new mesh primitive.
Definition: CMultiMesh.cpp:1115
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:529
void clearAllEdges()
This method clears all edges.
Definition: CMultiMesh.cpp:1707
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:108
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:701
void reverseAllNormals()
This method reverses all normals on this model.
Definition: CMultiMesh.cpp:1761
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:483
bool removeAllMesh()
This method removes all mesh primitives.
Definition: CMultiMesh.cpp:1195
void setShowEdges(const bool a_showEdges)
This method enables or disables the rendering of edges.
Definition: CMultiMesh.cpp:1635
void setShowNormals(const bool &a_showNormals)
This method enables or disables the rendering of vertex normals.
Definition: CMultiMesh.cpp:1814
virtual bool saveToFile(std::string a_filename)
This method saves 3D object to a file.
Definition: CMultiMesh.cpp:1551
void setShowTriangles(const bool a_showTriangles)
This method enables or disables the rendering of triangles.
Definition: CMultiMesh.cpp:1618
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:1316
virtual void setUseTransparency(const bool a_useTransparency, const bool a_affectChildren=false)
This method enables or disables transparency.
Definition: CMultiMesh.cpp:306

CHAI3D 3.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2015 - CHAI3D
All Rights Reserved.