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
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State 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"
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
56namespace disti
57{
58// Forward Declaration
59class GlsGloFileAttribute;
60
61// SetValue enumerations
62enum
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 */
72typedef 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.
80
81/** The GLMeshVertex structure. Defines all of the attributes of a TriMesh vertex. Used in generated code.
82 */
83typedef 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 */
90
91/**
92 \brief The glTriMesh class. Implements Triangle Meshes
93*/
94class GLTriMesh : public GLPolygon
95{
96protected:
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.
109
110public:
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 */
125
126 /* Override base class since a mesh can have multiple textures */
128
129 /* Override base class since a mesh can have multiple materials */
131
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 */
141
142 /// \return Access to the faces stored in this mesh.
143 GLS_EXPORT GLMeshFace* Faces() { return _faces; }
144
146 virtual GLS_EXPORT DisplayObject* CloneObject( bool generateNames = false ) 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.
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 */
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 */
222
223 /// \return A pointer to a new GLTriMesh object.
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
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 */
249 {
250#ifndef GLES
251 _displayList.Invalidate();
252#endif
253 }
254
255protected:
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 */
271#endif
272
273private:
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
318
319 void CopyGeometryInternal( GLTriMesh* src );
320 void CopyPropertiesInternal( GLTriMesh* src );
321};
322
323/** The DistiAttributeMeshFaceArray class. Defines metadata for the GlMeshFace type.
324 */
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
331public:
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
341
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
348};
349
350} // namespace disti
351
352#endif
Definition: disti_metadata.h:87
Definition: callback_caller_base.h:56
Definition: cull.h:50
Definition: display.h:96
Definition: disti_metadata.h:220
Definition: gltrimesh.h:326
std::string Type() const override
virtual std::istream & ReadValue(std::istream &) override
DistiAttributeMeshFaceArray(CallbackMethodCallerBase *callback, const AttributeName &name, GLMeshFace **attribPtr, unsigned int *numFaces, bool inRuntimeMode)
virtual bool OkToWrite() const override
virtual std::ostream & WriteValue(std::ostream &) override
Definition: dynamic_array.h:79
The Polygon class. Implements Polygons.
Definition: glpolygon.h:56
The glTriMesh class. Implements Triangle Meshes.
Definition: gltrimesh.h:95
virtual DisplayObject * CloneObject(bool generateNames=false) override
virtual void SetFromGloData(GlsGloFileAttribute &data) override
void VaSetFaces(unsigned int numFaces,...)
virtual void SetAvailableAttributes(unsigned int value) override
void SetFaces(unsigned int nFaces, GLMeshFace *faces)
virtual bool SetupTexture(const int textureIndex)
virtual void SetValue(int spec, va_list &args) override
int TextureIndex() override
void SetVerticesAndFaces(unsigned int nVertices, const GLMeshVertex *vertices, unsigned int nFaces, const GLMeshFace *faces)
DynamicArray< int > & MaterialIndices() override
GLTriMesh(unsigned int nVertices, Vertex *vertices, Vertex &location)
void AssignPropertiesFromGroup(DisplayObject *src)
static DisplayObject * CreateInstance()
unsigned int NumberOfFaces()
Definition: gltrimesh.h:161
GLTriMesh(unsigned int nVertices, Vertex *vertices)
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) override
virtual void CopyProperties(DisplayObject *src) override
void DrawOutlineMesh()
GlsIndexArray _indices
The index array for this mesh.
Definition: gltrimesh.h:117
virtual void Draw() override
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler) override
virtual ~GLTriMesh()
GLMeshFace * Faces()
Definition: gltrimesh.h:143
int MaterialIndex() override
void DrawSolidMesh(unsigned int faceOffset, unsigned int faceCount, bool textureObject, bool gouraudShading, bool perVertexLighting)
GLTriMesh(const GLTriMesh &that, const bool generateNames)
void InvalidateGeometry()
Definition: gltrimesh.h:248
virtual void CopyGeometry(DisplayObject *src) override
void SetFace(unsigned int face, int a, int b, int c, int tindex, unsigned int materialIndex=0)
void ReplaceMaterial(unsigned int oldIndex, unsigned int newIndex)
Definition: gls_display_list.h:51
void Invalidate()
Definition: gls_display_list.h:85
Definition: gls_glo_file.h:1243
Definition: gls_index_array.h:54
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
Definition: vertex.h:85
Definition: vertex.h:420
The disti::DisplayObject class and global enumerations.
The disti metadata.
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
The disti::GLPolygon class. Implements Polygons.
Macros and helper code to determine what subset of C++11/14/17 is available.
#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
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
#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
The disti::GlsDisplayList class.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
The disti::GlsIndexArray class, for managing index buffers.
Definition: bmpimage.h:47
Structure for holding mesh vertex indices.
Definition: gltrimesh.h:73
int b
Vertex indices of the face.
Definition: gltrimesh.h:75
int c
Vertex indices of the face.
Definition: gltrimesh.h:76
int texture
Texture index of face.
Definition: gltrimesh.h:77
int a
Vertex indices of the face.
Definition: gltrimesh.h:74
unsigned int material
Material index of face.
Definition: gltrimesh.h:78
Definition: gltrimesh.h:84