My Project
Loading...
Searching...
No Matches
CMultiMesh.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, 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.3.0
41*/
42//==============================================================================
43
44//------------------------------------------------------------------------------
45#ifndef CMultiMeshH
46#define CMultiMeshH
47//------------------------------------------------------------------------------
48#include "world/CMesh.h"
49//------------------------------------------------------------------------------
50
51//------------------------------------------------------------------------------
52namespace chai3d {
53//------------------------------------------------------------------------------
54
55//==============================================================================
62//==============================================================================
63
64//==============================================================================
79//==============================================================================
81{
82 //--------------------------------------------------------------------------
83 // CONSTRUCTOR & DESTRUCTOR:
84 //--------------------------------------------------------------------------
85
86public:
87
89 cMultiMesh();
90
92 virtual ~cMultiMesh();
93
94
95 //--------------------------------------------------------------------------
96 // PUBLIC METHODS - GENERAL:
97 //--------------------------------------------------------------------------
98
99public:
100
102 virtual std::string getClassName() { return ("MultiMesh"); }
103
105 virtual cMultiMesh* copy(const bool a_duplicateMaterialData = false,
106 const bool a_duplicateTextureData = false,
107 const bool a_duplicateMeshData = false,
108 const bool a_buildCollisionDetector = true);
109
110
111 //-----------------------------------------------------------------------
112 // PUBLIC METHODS - COLLISION DETECTION:
113 //-----------------------------------------------------------------------
114
115public:
116
119
121 virtual void createAABBCollisionDetector(const double a_radius);
122
123
124 //--------------------------------------------------------------------------
125 // PUBLIC METHODS - MESH PRIMITIVES:
126 //--------------------------------------------------------------------------
127
128public:
129
131 cMesh* newMesh();
132
134 bool addMesh(cMesh* a_mesh);
135
137 bool removeMesh(cMesh* a_mesh);
138
140 bool removeAllMesh();
141
143 bool deleteMesh(cMesh* a_mesh);
144
146 bool deleteAllMeshes();
147
149 int getNumMeshes();
150
152 cMesh* getMesh(unsigned int a_index);
153
155 void convertToSingleMesh(cMesh* a_mesh);
156
157
158 //--------------------------------------------------------------------------
159 // PUBLIC METHODS - VERTICES
160 //--------------------------------------------------------------------------
161
162public:
163
165 bool getVertex(const unsigned int a_index, cMesh*& a_mesh, unsigned int& a_vertexIndex);
166
168 cVector3d getVertexPos(unsigned int a_index);
169
171 unsigned int getNumVertices() const;
172
174 virtual void setUseVertexColors(const bool a_useColors, const bool a_affectChildren=true, const bool a_affectComponents=true);
175
177 void setVertexColor(const cColorf& a_color);
178
179
180 //--------------------------------------------------------------------------
181 // PUBLIC METHODS - TRIANGLES
182 //--------------------------------------------------------------------------
183
184public:
185
187 bool getTriangle(const unsigned int a_index, cMesh*& a_mesh, unsigned int& a_triangleIndex);
188
190 unsigned int getNumTriangles() const;
191
193 void setShowTriangles(const bool a_showTriangles);
194
195
196 //--------------------------------------------------------------------------
197 // PUBLIC METHODS - EDGES
198 //--------------------------------------------------------------------------
199
200public:
201
203 void computeAllEdges(double a_angleThresholdDeg = 40.0);
204
206 void clearAllEdges();
207
209 void setShowEdges(const bool a_showEdges);
210
212 void setEdgeProperties(const double a_width,
213 const cColorf& a_color);
214
216 void setEdgeLineWidth(const double a_width);
217
218
219 //--------------------------------------------------------------------------
220 // PUBLIC METHODS - SURFACE NORMALS
221 //--------------------------------------------------------------------------
222
223public:
224
226 void setShowNormals(const bool& a_showNormals);
227
229 void setNormalsProperties(const double a_length, const cColorf& a_color);
230
232 void setNormalsLength(const double a_length);
233
235 void computeAllNormals();
236
238 void reverseAllNormals();
239
241 void computeBTN();
242
244 void setShowTangents(const bool a_showTangents);
245
246
247 //--------------------------------------------------------------------------
248 // PUBLIC VIRTUAL METHODS - FILES:
249 //--------------------------------------------------------------------------
250
251public:
252
254 virtual bool loadFromFile(std::string a_filename);
255
257 virtual bool saveToFile(std::string a_filename);
258
259
260 //--------------------------------------------------------------------------
261 // PUBLIC METHODS - SCALING:
262 //--------------------------------------------------------------------------
263
264public:
265
267 void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ);
268
269
270 //--------------------------------------------------------------------------
271 // PROTECTED METHODS:
272 //--------------------------------------------------------------------------
273
274protected:
275
278 const bool a_duplicateMaterialData,
279 const bool a_duplicateTextureData,
280 const bool a_duplicateMeshData,
281 const bool a_buildCollisionDetector);
282
283
284 //-----------------------------------------------------------------------
285 // PUBLIC MEMBERS
286 //-----------------------------------------------------------------------
287
288public:
289
291 std::vector<cMesh*> *m_meshes;
292};
293
294//------------------------------------------------------------------------------
295} // namespace chai3d
296//------------------------------------------------------------------------------
297
298//------------------------------------------------------------------------------
299#endif
300//------------------------------------------------------------------------------
301
Implements a class to model polygonal meshes.
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition CGenericObject.h:113
This class implements a 3D polygonal mesh.
Definition CMesh.h:109
This class implements a 3D multi-mesh object.
Definition CMultiMesh.h:81
void setNormalsLength(const double a_length)
This method set the length of normals for display purposes.
Definition CMultiMesh.cpp:1012
virtual void createAABBCollisionDetector(const double a_radius)
Set up an AABB collision detector for this mesh.
Definition CMultiMesh.cpp:1061
cMesh * newMesh()
This method creates a new mesh primitive.
Definition CMultiMesh.cpp:251
cVector3d getVertexPos(unsigned int a_index)
This method returns the position data of specific vertex.
Definition CMultiMesh.cpp:565
cMultiMesh()
Constructor of cMultiMesh.
Definition CMultiMesh.cpp:72
bool removeMesh(cMesh *a_mesh)
This method removes a mesh primitive from the list of meshes.
Definition CMultiMesh.cpp:300
virtual bool loadFromFile(std::string a_filename)
This method loads a 3D object from a file.
Definition CMultiMesh.cpp:682
virtual std::string getClassName()
This method returns the name of the object class.
Definition CMultiMesh.h:102
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:462
void setShowTangents(const bool a_showTangents)
This method enables or disables the rendering of tangents and bi-tangents.
Definition CMultiMesh.cpp:836
bool removeAllMesh()
This method removes all mesh primitives.
Definition CMultiMesh.cpp:329
void computeAllEdges(double a_angleThresholdDeg=40.0)
This method creates a list of edges by providing a threshold angle in degrees.
Definition CMultiMesh.cpp:927
void computeAllNormals()
This method computes all triangle normals.
Definition CMultiMesh.cpp:803
bool deleteMesh(cMesh *a_mesh)
This method deletes a mesh primitive from the list of meshes.
Definition CMultiMesh.cpp:359
std::vector< cMesh * > * m_meshes
Array of meshes.
Definition CMultiMesh.h:291
unsigned int getNumVertices() const
This method returns the the number of stored vertices.
Definition CMultiMesh.cpp:603
void setEdgeProperties(const double a_width, const cColorf &a_color)
This method sets the graphic properties for edge-rendering.
Definition CMultiMesh.cpp:889
virtual void setUseVertexColors(const bool a_useColors, const bool a_affectChildren=true, const bool a_affectComponents=true)
This method enables or disables the use of per-vertex colors, optionally propagating the operation to...
Definition CMultiMesh.cpp:175
void computeBTN()
This method computes the normal matrix vectors for all triangles.
Definition CMultiMesh.cpp:818
void setVertexColor(const cColorf &a_color)
This method sets the color of each vertex.
Definition CMultiMesh.cpp:959
void reverseAllNormals()
This method reverses all normals on this model.
Definition CMultiMesh.cpp:976
void setShowTriangles(const bool a_showTriangles)
This method enables or disables the rendering of triangles.
Definition CMultiMesh.cpp:853
virtual ~cMultiMesh()
Destructor of cMultiMesh.
Definition CMultiMesh.cpp:84
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:503
bool addMesh(cMesh *a_mesh)
This method adds an existing mesh primitives to list of meshes.
Definition CMultiMesh.cpp:274
unsigned int getNumTriangles() const
This method returns the the number of stored triangles.
Definition CMultiMesh.cpp:541
void setShowNormals(const bool &a_showNormals)
This method enables or disables the rendering of vertex normals.
Definition CMultiMesh.cpp:1029
void convertToSingleMesh(cMesh *a_mesh)
This method converts this multimesh into a single mesh object.
Definition CMultiMesh.cpp:623
void setNormalsProperties(const double a_length, const cColorf &a_color)
This method sets the graphic properties for normal-rendering.
Definition CMultiMesh.cpp:994
int getNumMeshes()
This method retrieves the number of meshes that compose this multi-mesh object.
Definition CMultiMesh.cpp:423
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:137
cMesh * getMesh(unsigned int a_index)
This method returns a pointer to a mesh primitive by passing its index number.
Definition CMultiMesh.cpp:439
void setEdgeLineWidth(const double a_width)
This method sets the line width of all edges.
Definition CMultiMesh.cpp:907
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:201
void setShowEdges(const bool a_showEdges)
This method enables or disables the rendering of edges.
Definition CMultiMesh.cpp:870
virtual bool saveToFile(std::string a_filename)
This method saves 3D object to a file.
Definition CMultiMesh.cpp:741
void clearAllEdges()
This method clears all edges.
Definition CMultiMesh.cpp:942
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:106
virtual void createBruteForceCollisionDetector()
Set up a brute force collision detector for this mesh and (optionally) for its children.
Definition CMultiMesh.cpp:1044
bool deleteAllMeshes()
This method deletes all meshes.
Definition CMultiMesh.cpp:392
Definition CAudioBuffer.cpp:57
This class defines a color using a GLfloat representation for each component.
Definition CColor.h:139
This class implements a 3D vector.
Definition CVector3d.h:89