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 */
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
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.
245#endif
246
247 /** Causes the display list for this object to be recomputed */
249 {
250#ifndef GLES
252#endif
253 }
254
255#ifdef GLES
256 GLS_EXPORT void DirtyTextureData();
257#endif
258
259protected:
260#ifndef GLES
261 /** Contains the actual OpenGL drawing commands to draw the object */
262 virtual GLS_EXPORT void DrawGeometry();
263#endif
264 /// Set up the OpenGL state for texturing.
265 /// \note A mesh can have multiple textures.
266 /// \param textureIndex The first texture to use.
267 /// \return Whether or not the OpenGL state was changed.
268 virtual GLS_EXPORT bool SetupTexture( const int textureIndex );
269
270#ifdef GLES
271 /** Set a single attribute from the GLO file.
272 * \param data The attribute to set and its associated data.
273 */
274 virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
275#endif
276
277private:
278 unsigned int _nFaces; /** Number of faces (triangles) in this mesh */
279
280 GLMeshFace* _faces; /** Array of vertex indices for triangles */
281
282 DynamicArray<int> _newMaterialIndices; /** Intermediate data storage to make the setting of new material indices through the Faces simpler. */
283
284#ifdef GLES
285 /* Resizable array of indices into the faces array where the active texture is different from
286 * the previous face.
287 */
288 DynamicArray<unsigned int> _textureChangeIndices;
289 bool _textureChangesDirty; /** true if _textureSwitchIndices needs to be recomputed */
290
291 /* Utility routine used by Draw. Should only be called when _textureSwitchDirty is true.
292 * Rebuilds the _textureSwitchIndices array by scanning the data in the face array
293 * and taking note when the texture index changes between faces.
294 */
295 void RecalculateTextureChanges();
296#endif
297 /* Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object
298 * but does not guarantee that the collision point returned by Hit is the closest collision point
299 * to the observer
300 * \param point The logical coordinate of the click, relative to the object
301 * \param directionVector The direction of the pick vector
302 * \param collisionPoint Set to the point on the object hit by directionVector
303 * \return boolean indicating if the object was hit by the mouse
304 */
305 bool FirstHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
306
307 /* Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object
308 * and guarantees that the collision point returned by Hit is the closest collision point to the observer.
309 * \param point The logical coordinate of the click, relative to the object
310 * \param directionVector The direction of the pick vector
311 * \param collisionPoint Set to the point on the object hit by directionVector
312 * \return boolean indicating if the object was hit by the mouse
313 */
314 bool BestHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
315
316 /* Utility routines used to detect when the material indices has changed */
317 void OnMatChanged();
318 void OnMatChanged( DynamicArray<int>& a, DynamicArray<int>& b );
319
322
323 void CopyGeometryInternal( GLTriMesh* src );
324 void CopyPropertiesInternal( GLTriMesh* src );
325};
326
327/** The DistiAttributeMeshFaceArray class. Defines metadata for the GlMeshFace type.
328 */
330{
331 GLMeshFace** _attribPtr; ///< Observing pointer to the underlying mesh data.
332 unsigned int* _numFaces; ///< Observing pointer to the underlying mesh face count.
333 bool _inRuntimeMode; ///< Governs the attribute parsing behavior.
334
335public:
336 /// Constructor
337 /// \param callback The callback to call when the attribute changes.
338 /// \param name The name of the new attribute.
339 /// \param attribPtr A pointer to the underlying mesh data.
340 /// \param numFaces A pointer to the underlying mesh face count.
341 /// \param inRuntimeMode Mode for attribute parsing behavior.
342 GLS_EXPORT DistiAttributeMeshFaceArray( CallbackMethodCallerBase* callback, const AttributeName& name, GLMeshFace** attribPtr, unsigned int* numFaces, bool inRuntimeMode );
343
345
347
348 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& ) DISTI_METHOD_OVERRIDE;
349 virtual GLS_EXPORT std::istream& ReadValue( std::istream& ) DISTI_METHOD_OVERRIDE;
350};
351
352} // namespace disti
353
354#endif
Definition: disti_metadata.h:87
Definition: callback_caller_base.h:56
Definition: cull.h:50
Definition: display.h:96
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler)
Definition: disti_metadata.h:220
Definition: gltrimesh.h:330
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 DrawGeometry()
void VaSetFaces(unsigned int numFaces,...)
virtual bool UseDisplayList()
virtual void SetAvailableAttributes(unsigned int value) override
void SetFaces(unsigned int nFaces, GLMeshFace *faces)
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) override
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()
GlsDisplayList _displayList
Definition: gltrimesh.h:120
unsigned int NumberOfFaces()
Definition: gltrimesh.h:161
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) override
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()
virtual void Draw() override
virtual ~GLTriMesh()
virtual void UseDisplayList(const bool &flag)
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:235
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:457
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:214
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.
Force inclusion of the DirectShow library.
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