| GL Studio C++ Runtime API

gltrimesh.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::GLTriMesh class. Implements Triangle Meshes.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38
39*/
40
41#ifndef _GL_TRI_MESH_H
42#define _GL_TRI_MESH_H
43
44#include "display.h"
45#include "gls_cpp_lang_support.h"
46#ifndef GLES
47# include "gls_display_list.h"
48#endif
49#include "disti_metadata.h"
50#include "glpolygon.h"
51#ifdef GLES
52# include "dynamic_array.h"
53# include "gls_index_array.h"
54#endif
55
56 namespace disti
57{
58// Forward Declaration
59 class GlsGloFileAttribute;
60
61// SetValue enumerations
62 enum
63{
64 GLS_TRIMESH_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
65 GLS_TRIMESH_USE_DISPLAY_LIST, // whether or not to use a display list
66 GLS_TRIMESH_FACES
67};
68
69/**
70 \brief Structure for holding mesh vertex indices
71 */
72 typedef struct
73{
74 int a; ///< Vertex indices of the face.
75 int b; ///< Vertex indices of the face.
76 int c; ///< Vertex indices of the face.
77 int texture; ///< Texture index of face.
78 unsigned int material; ///< Material index of face.
79} GLMeshFace;
80
81/** The GLMeshVertex structure. Defines all of the attributes of a TriMesh vertex. Used in generated code.
82 */
83 typedef struct
84{
85 float vertex[ 3 ]; /**< The vertex coordinate */
86 unsigned char color[ 4 ]; /**< The vertex color */
87 float texCoord[ 2 ]; /**< The texture coordinate */
88 float normal[ 3 ]; /**< The vertex normal */
89} GLMeshVertex;
90
91/**
92 \brief The glTriMesh class. Implements Triangle Meshes
93*/
94 class GLTriMesh : public GLPolygon
95{
96 protected:
97 /// Helper function for underlying solid mesh drawing.
98 /// \note Not normally called by users.
99 /// \param faceOffset Index offset into the face array.
100 /// \param faceCount The number of faces to draw.
101 /// \param textureObject If true, draw with texture.
102 /// \param gouraudShading If true, draw with smooth shading.
103 /// \param perVertexLighting If true, use per vertex lighting.
104 void DrawSolidMesh( unsigned int faceOffset, unsigned int faceCount, bool textureObject, bool gouraudShading, bool perVertexLighting );
105
106 /// Helper function for underlying outline mesh drawing.
107 /// \note Not normally called by users.
108 void DrawOutlineMesh();
109
110 public:
111 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
112 typedef GLPolygon _BaseClass; ///< Deprecated typedef for the base class.
113 typedef GLPolygon BaseClass; ///< Typedef for the base class.
114 friend class GLTriMeshEditor;
115
116#ifdef GLES
117 GlsIndexArray _indices; ///< The index array for this mesh.
118#else
119 /** Stores object in display list for faster drawing */
120 GlsDisplayList _displayList;
121#endif
122
123 /* Override base class since a mesh can have multiple textures */
124 GLS_EXPORT int TextureIndex() DISTI_METHOD_OVERRIDE;
125
126 /* Override base class since a mesh can have multiple textures */
127 GLS_EXPORT void TextureIndex( int index ) DISTI_METHOD_OVERRIDE;
128
129 /* Override base class since a mesh can have multiple materials */
130 GLS_EXPORT void MaterialIndices( DynamicArray<int> index ) DISTI_METHOD_OVERRIDE;
131
132 GLS_EXPORT DynamicArray<int>& MaterialIndices() DISTI_METHOD_OVERRIDE;
133
134 /// Override base class since a mesh can have multiple materials.
135 /// \note This is technically not an override, GLS-11064.
136 /// \param index The new material index to set on all faces.
137 GLS_EXPORT void MaterialIndex( unsigned int index );
138
139 /* Override base class since a mesh can have multiple materials */
140 GLS_EXPORT int MaterialIndex() DISTI_METHOD_OVERRIDE;
141
142 /// \return Access to the faces stored in this mesh.
143 GLS_EXPORT GLMeshFace* Faces() { return _faces; }
144
145 virtual GLS_EXPORT void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
146 virtual GLS_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
147 virtual GLS_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
148 virtual GLS_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
149
150 /// Copies the attributes from an object (possibly a group) to this one. Used by the
151 /// mesh creator to copy properties from the objectrs that were converted into this mesh.
152 /// \param src The object to copy properties from.
153 GLS_EXPORT void AssignPropertiesFromGroup( DisplayObject* src );
154
155 /** Sets the number of faces in the mesh and allocates the face array
156 * \param n The new number of faces for the mesh
157 */
158 GLS_EXPORT void NumberOfFaces( unsigned int n );
159
160 /** \return The number of faces in this mesh */
161 GLS_EXPORT unsigned int NumberOfFaces() { return _nFaces; }
162
163 /** For all faces of the mesh that have the old material, replace that material
164 * with the new material.
165 * \param oldIndex Old material index
166 * \param newIndex New material index
167 */
168 GLS_EXPORT void ReplaceMaterial( unsigned int oldIndex, unsigned int newIndex );
169
170 /** Sets the vertices and texture index of a specific face
171 * \param face
172 * \param a The vertex index for the first vertex of the triangle
173 * \param b The vertex index for the second vertex of the triangle
174 * \param c The vertex index for the third vertex of the triangle
175 * \param tindex The texture index for triangle
176 * \param materialIndex The material index for triangle
177 */
178 GLS_EXPORT void SetFace( unsigned int face, int a, int b, int c, int tindex, unsigned int materialIndex = 0 );
179
180 /** Sets all the faces of the mesh. Used in runtime.
181 * \param numFaces The number of faces that will be passed in
182 * \param ... A variable argument field which will be numFaces instances of a,b,c,tindex,materialIndex
183 */
184 GLS_EXPORT void VaSetFaces( unsigned int numFaces, ... );
185
186 /** Sets all the faces of the mesh. Used in parser
187 * \param nFaces The number of faces that will be set
188 * \param faces An array of GLMeshFaces with nFaces elements
189 */
190 GLS_EXPORT void SetFaces( unsigned int nFaces, GLMeshFace* faces );
191
192 /** Sets all the faces and vertices of the mesh. Used in generated code
193 * \param nVertices Number of vertices
194 * \param vertices Array of initialized vertices
195 * \param nFaces Number of faces
196 * \param faces Array of initialized faces
197 */
198 GLS_EXPORT void SetVerticesAndFaces( unsigned int nVertices, const GLMeshVertex* vertices, unsigned int nFaces, const GLMeshFace* faces );
199
200 /** Creates a GLTriMesh with the vertices specified
201 * \param nVertices The number of vertices in the new polygon
202 * \param vertices The array of vertices for the polygon
203 */
204 GLS_EXPORT GLTriMesh( unsigned int nVertices, Vertex* vertices );
205
206 /// Creates a GLTriMesh with the vertices specified.
207 /// \param nVertices The number of vertices in the new polygon.
208 /// \param vertices The array of vertices for the polygon.
209 /// \param location The location point of the object.
210 GLS_EXPORT GLTriMesh( unsigned int nVertices, Vertex* vertices, Vertex& location );
211
212 /** Allocate a (blank) GLTriMesh object */
213 GLS_EXPORT GLTriMesh();
214
215 /// Copy constructor
216 /// \param that The object to copy from.
217 /// \param generateNames Whether or not an instance name should be generated for this object.
218 GLS_EXPORT GLTriMesh( const GLTriMesh& that, const bool generateNames );
219
220 /** Destroy a GLTriMesh object */
221 virtual GLS_EXPORT ~GLTriMesh();
222
223 /// \return A pointer to a new GLTriMesh object.
224 static GLS_EXPORT DisplayObject* CreateInstance();
225
226 virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
227
228#ifdef GLES
229 virtual GLS_EXPORT void PreDraw( const OpenGLMatrices& current, Culler& culler ) DISTI_METHOD_OVERRIDE;
230#endif
231
232 virtual GLS_EXPORT void Draw() DISTI_METHOD_OVERRIDE;
233 virtual GLS_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
234
235#ifndef GLES
236 virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
237 virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
238
239 /// Set whether or not the mesh will use a display list, rather than immediate mode.
240 /// \param flag The new display list mode to set.
241 virtual GLS_EXPORT void UseDisplayList( const bool& flag );
242
243 /// \return Whether or not the mesh will use a display list, rather than immediate mode.
244 virtual GLS_EXPORT bool UseDisplayList();
245#endif
246
247 /** Causes the display list for this object to be recomputed */
248 GLS_EXPORT void InvalidateGeometry()
249 {
250#ifndef GLES
251 _displayList.Invalidate();
252#endif
253 }
254
255 protected:
256#ifndef GLES
257 /** Contains the actual OpenGL drawing commands to draw the object */
258 virtual GLS_EXPORT void DrawGeometry();
259#endif
260 /// Set up the OpenGL state for texturing.
261 /// \note A mesh can have multiple textures.
262 /// \param textureIndex The first texture to use.
263 /// \return Whether or not the OpenGL state was changed.
264 virtual GLS_EXPORT bool SetupTexture( const int textureIndex );
265
266#ifdef GLES
267 /** Set a single attribute from the GLO file.
268 * \param data The attribute to set and its associated data.
269 */
270 virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
271#endif
272
273 private:
274 unsigned int _nFaces; /** Number of faces (triangles) in this mesh */
275
276 GLMeshFace* _faces; /** Array of vertex indices for triangles */
277
278 DynamicArray<int> _newMaterialIndices; /** Intermediate data storage to make the setting of new material indices through the Faces simpler. */
279
280#ifdef GLES
281 /* Resizable array of indices into the faces array where the active texture is different from
282 * the previous face.
283 */
284 DynamicArray<unsigned int> _textureChangeIndices;
285 bool _textureChangesDirty; /** true if _textureSwitchIndices needs to be recomputed */
286
287 /* Utility routine used by Draw. Should only be called when _textureSwitchDirty is true.
288 * Rebuilds the _textureSwitchIndices array by scanning the data in the face array
289 * and taking note when the texture index changes between faces.
290 */
291 void RecalculateTextureChanges();
292#endif
293 /* Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object
294 * but does not guarantee that the collision point returned by Hit is the closest collision point
295 * to the observer
296 * \param point The logical coordinate of the click, relative to the object
297 * \param directionVector The direction of the pick vector
298 * \param collisionPoint Set to the point on the object hit by directionVector
299 * \return boolean indicating if the object was hit by the mouse
300 */
301 bool FirstHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
302
303 /* Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object
304 * and guarantees that the collision point returned by Hit is the closest collision point to the observer.
305 * \param point The logical coordinate of the click, relative to the object
306 * \param directionVector The direction of the pick vector
307 * \param collisionPoint Set to the point on the object hit by directionVector
308 * \return boolean indicating if the object was hit by the mouse
309 */
310 bool BestHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
311
312 /* Utility routines used to detect when the material indices has changed */
313 void OnMatChanged();
314 void OnMatChanged( DynamicArray<int>& a, DynamicArray<int>& b );
315
316 GLTriMesh& operator=( const GLTriMesh& ) DISTI_SPECIAL_MEM_FUN_DELETE;
317 GLTriMesh( const GLTriMesh& ) DISTI_SPECIAL_MEM_FUN_DELETE;
318
319 void CopyGeometryInternal( GLTriMesh* src );
320 void CopyPropertiesInternal( GLTriMesh* src );
321};
322
323/** The DistiAttributeMeshFaceArray class. Defines metadata for the GlMeshFace type.
324 */
325 class DistiAttributeMeshFaceArray : public DistiAttributeBase
326{
327 GLMeshFace** _attribPtr; ///< Observing pointer to the underlying mesh data.
328 unsigned int* _numFaces; ///< Observing pointer to the underlying mesh face count.
329 bool _inRuntimeMode; ///< Governs the attribute parsing behavior.
330
331 public:
332 /// Constructor
333 /// \param callback The callback to call when the attribute changes.
334 /// \param name The name of the new attribute.
335 /// \param attribPtr A pointer to the underlying mesh data.
336 /// \param numFaces A pointer to the underlying mesh face count.
337 /// \param inRuntimeMode Mode for attribute parsing behavior.
338 GLS_EXPORT DistiAttributeMeshFaceArray( CallbackMethodCallerBase* callback, const AttributeName& name, GLMeshFace** attribPtr, unsigned int* numFaces, bool inRuntimeMode );
339
340 virtual GLS_EXPORT ~DistiAttributeMeshFaceArray();
341
342 virtual GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
343
344 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& ) DISTI_METHOD_OVERRIDE;
345 virtual GLS_EXPORT std::istream& ReadValue( std::istream& ) DISTI_METHOD_OVERRIDE;
346
347 GLS_EXPORT std::string Type() const DISTI_METHOD_OVERRIDE;
348};
349
350} // namespace disti
351
352#endif
disti::AttributeName
Definition: disti_metadata.h:87
disti::CallbackMethodCallerBase
Definition: callback_caller_base.h:56
disti::Culler
Definition: cull.h:50
disti::DisplayObject
Definition: display.h:96
disti::DistiAttributeBase
Definition: disti_metadata.h:220
disti::DistiAttributeMeshFaceArray
Definition: gltrimesh.h:326
disti::DistiAttributeMeshFaceArray::Type
std::string Type() const override
disti::DistiAttributeMeshFaceArray::ReadValue
virtual std::istream & ReadValue(std::istream &) override
disti::DistiAttributeMeshFaceArray::DistiAttributeMeshFaceArray
DistiAttributeMeshFaceArray(CallbackMethodCallerBase *callback, const AttributeName &name, GLMeshFace **attribPtr, unsigned int *numFaces, bool inRuntimeMode)
disti::DistiAttributeMeshFaceArray::OkToWrite
virtual bool OkToWrite() const override
disti::DistiAttributeMeshFaceArray::WriteValue
virtual std::ostream & WriteValue(std::ostream &) override
disti::DynamicArray
Definition: dynamic_array.h:79
disti::GLPolygon
The Polygon class. Implements Polygons.
Definition: glpolygon.h:56
disti::GLTriMesh
The glTriMesh class. Implements Triangle Meshes.
Definition: gltrimesh.h:95
disti::GLTriMesh::CloneObject
virtual DisplayObject * CloneObject(bool generateNames=false) override
disti::GLTriMesh::SetFromGloData
virtual void SetFromGloData(GlsGloFileAttribute &data) override
disti::GLTriMesh::VaSetFaces
void VaSetFaces(unsigned int numFaces,...)
disti::GLTriMesh::SetAvailableAttributes
virtual void SetAvailableAttributes(unsigned int value) override
disti::GLTriMesh::SetFaces
void SetFaces(unsigned int nFaces, GLMeshFace *faces)
disti::GLTriMesh::SetupTexture
virtual bool SetupTexture(const int textureIndex)
disti::GLTriMesh::SetValue
virtual void SetValue(int spec, va_list &args) override
disti::GLTriMesh::TextureIndex
int TextureIndex() override
disti::GLTriMesh::SetVerticesAndFaces
void SetVerticesAndFaces(unsigned int nVertices, const GLMeshVertex *vertices, unsigned int nFaces, const GLMeshFace *faces)
disti::GLTriMesh::MaterialIndices
DynamicArray< int > & MaterialIndices() override
disti::GLTriMesh::GLTriMesh
GLTriMesh(unsigned int nVertices, Vertex *vertices, Vertex &location)
disti::GLTriMesh::AssignPropertiesFromGroup
void AssignPropertiesFromGroup(DisplayObject *src)
disti::GLTriMesh::CreateInstance
static DisplayObject * CreateInstance()
disti::GLTriMesh::NumberOfFaces
unsigned int NumberOfFaces()
Definition: gltrimesh.h:161
disti::GLTriMesh::GLTriMesh
GLTriMesh(unsigned int nVertices, Vertex *vertices)
disti::GLTriMesh::Hit
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) override
disti::GLTriMesh::CopyProperties
virtual void CopyProperties(DisplayObject *src) override
disti::GLTriMesh::DrawOutlineMesh
void DrawOutlineMesh()
disti::GLTriMesh::_indices
GlsIndexArray _indices
The index array for this mesh.
Definition: gltrimesh.h:117
disti::GLTriMesh::Draw
virtual void Draw() override
disti::GLTriMesh::PreDraw
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler) override
disti::GLTriMesh::~GLTriMesh
virtual ~GLTriMesh()
disti::GLTriMesh::Faces
GLMeshFace * Faces()
Definition: gltrimesh.h:143
disti::GLTriMesh::MaterialIndex
int MaterialIndex() override
disti::GLTriMesh::DrawSolidMesh
void DrawSolidMesh(unsigned int faceOffset, unsigned int faceCount, bool textureObject, bool gouraudShading, bool perVertexLighting)
disti::GLTriMesh::GLTriMesh
GLTriMesh(const GLTriMesh &that, const bool generateNames)
disti::GLTriMesh::InvalidateGeometry
void InvalidateGeometry()
Definition: gltrimesh.h:248
disti::GLTriMesh::GLTriMesh
GLTriMesh()
disti::GLTriMesh::CopyGeometry
virtual void CopyGeometry(DisplayObject *src) override
disti::GLTriMesh::SetFace
void SetFace(unsigned int face, int a, int b, int c, int tindex, unsigned int materialIndex=0)
disti::GLTriMesh::ReplaceMaterial
void ReplaceMaterial(unsigned int oldIndex, unsigned int newIndex)
disti::GlsDisplayList
Definition: gls_display_list.h:51
disti::GlsDisplayList::Invalidate
void Invalidate()
Definition: gls_display_list.h:85
disti::GlsGloFileAttribute
Definition: gls_glo_file.h:1243
disti::GlsIndexArray
Definition: gls_index_array.h:54
disti::OpenGLMatrices
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
disti::VertexNoColor
Definition: vertex.h:85
disti::Vertex
Definition: vertex.h:420
display.h
The disti::DisplayObject class and global enumerations.
disti_metadata.h
The disti metadata.
dynamic_array.h
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
glpolygon.h
The disti::GLPolygon class. Implements Polygons.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_SPECIAL_MEM_FUN_DELETE
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:246
DISTI_DEPRECATED
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
DISTI_METHOD_OVERRIDE
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
gls_display_list.h
The disti::GlsDisplayList class.
GLS_EXPORT
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
gls_index_array.h
The disti::GlsIndexArray class, for managing index buffers.
disti
Definition: bmpimage.h:47
disti::GLMeshFace
Structure for holding mesh vertex indices.
Definition: gltrimesh.h:73
disti::GLMeshFace::b
int b
Vertex indices of the face.
Definition: gltrimesh.h:75
disti::GLMeshFace::c
int c
Vertex indices of the face.
Definition: gltrimesh.h:76
disti::GLMeshFace::texture
int texture
Texture index of face.
Definition: gltrimesh.h:77
disti::GLMeshFace::a
int a
Vertex indices of the face.
Definition: gltrimesh.h:74
disti::GLMeshFace::material
unsigned int material
Material index of face.
Definition: gltrimesh.h:78
disti::GLMeshVertex
Definition: gltrimesh.h:84