GL Studio C++ Runtime API
gltrimesh.h
Go to the documentation of this file.
1/// \file gltrimesh.h
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/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<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#ifndef DISTI_INCLUDED_GLTRIMESH_H
40#define DISTI_INCLUDED_GLTRIMESH_H
41
42#include "display.h"
44#ifndef GLES
45# include "gls_display_list.h"
46#endif
47#include "disti_metadata.h"
48#include "glpolygon.h"
49#ifdef GLES
50# include "dynamic_array.h"
51# include "gls_index_array.h"
52#endif
53
54namespace disti
55{
56// Forward Declaration
57class GlsGloFileAttribute;
58
59// SetValue enumerations
60enum
61{
62 GLS_TRIMESH_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
63 GLS_TRIMESH_USE_DISPLAY_LIST, // whether or not to use a display list
64 GLS_TRIMESH_FACES
65};
66
67/**
68 \brief Structure for holding mesh vertex indices
69 */
70typedef struct
71{
72 int a; ///< Vertex indices of the face.
73 int b; ///< Vertex indices of the face.
74 int c; ///< Vertex indices of the face.
75 int texture; ///< Texture index of face.
76 unsigned int material; ///< Material index of face.
78
79/** The GLMeshVertex structure. Defines all of the attributes of a TriMesh vertex. Used in generated code.
80 */
81typedef struct
82{
83 float vertex[ 3 ]; /**< The vertex coordinate */
84 unsigned char color[ 4 ]; /**< The vertex color */
85 float texCoord[ 2 ]; /**< The texture coordinate */
86 float normal[ 3 ]; /**< The vertex normal */
88
89/**
90 \brief The glTriMesh class. Implements Triangle Meshes
91*/
92class GLTriMesh : public GLPolygon
93{
94protected:
95 /// Helper function for underlying solid mesh drawing.
96 /// \note Not normally called by users.
97 /// \param faceOffset Index offset into the face array.
98 /// \param faceCount The number of faces to draw.
99 /// \param textureObject If true, draw with texture.
100 /// \param gouraudShading If true, draw with smooth shading.
101 /// \param perVertexLighting If true, use per vertex lighting.
102 void DrawSolidMesh( unsigned int faceOffset, unsigned int faceCount, bool textureObject, bool gouraudShading, bool perVertexLighting );
103
104 /// Helper function for underlying outline mesh drawing.
105 /// \note Not normally called by users.
107
108public:
109 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
110 typedef GLPolygon _BaseClass; ///< Deprecated typedef for the base class.
111 typedef GLPolygon BaseClass; ///< Typedef for the base class.
112 friend class GLTriMeshEditor;
113
114#ifdef GLES
115 GlsIndexArray _indices; ///< The index array for this mesh.
116#else
117 /** Stores object in display list for faster drawing */
119#endif
120
121 /* Override base class since a mesh can have multiple textures */
123
124 /* Override base class since a mesh can have multiple textures */
126
127 /* Override base class since a mesh can have multiple materials */
129
131
132 /// \deprecated Use the signed int version of MaterialIndex instead.
133 /// \param index The material index to set.
134 DISTI_DEPRECATED( "Use the signed int version of MaterialIndex instead." )
135 void MaterialIndex( unsigned int index ) { MaterialIndex( static_cast<int>( index ) ); }
136
137 /// Override base class since a mesh can have multiple materials.
138 /// \param index The new material index to set on all faces.
140
141 /* Override base class since a mesh can have multiple materials */
143
144 /// \return Access to the faces stored in this mesh.
145 GLMeshFace* Faces() { return _faces; }
146
150 GLS_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
151
152 /// Copies the attributes from an object (possibly a group) to this one. Used by the
153 /// mesh creator to copy properties from the objectrs that were converted into this mesh.
154 /// \param src The object to copy properties from.
156
157 /** Sets the number of faces in the mesh and allocates the face array
158 * \param n The new number of faces for the mesh
159 */
160 GLS_EXPORT void NumberOfFaces( unsigned int n );
161
162 /** \return The number of faces in this mesh */
163 unsigned int NumberOfFaces() { return _nFaces; }
164
165 /** For all faces of the mesh that have the old material, replace that material
166 * with the new material.
167 * \param oldIndex Old material index
168 * \param newIndex New material index
169 */
170 GLS_EXPORT void ReplaceMaterial( unsigned int oldIndex, unsigned int newIndex );
171
172 /** Sets the vertices and texture index of a specific face
173 * \param face
174 * \param a The vertex index for the first vertex of the triangle
175 * \param b The vertex index for the second vertex of the triangle
176 * \param c The vertex index for the third vertex of the triangle
177 * \param tindex The texture index for triangle
178 * \param materialIndex The material index for triangle
179 */
180 GLS_EXPORT void SetFace( unsigned int face, int a, int b, int c, int tindex, unsigned int materialIndex = 0 );
181
182 /** Sets all the faces of the mesh. Used in runtime.
183 * \param numFaces The number of faces that will be passed in
184 * \param ... A variable argument field which will be numFaces instances of a,b,c,tindex,materialIndex
185 */
186 GLS_EXPORT void VaSetFaces( unsigned int numFaces, ... );
187
188 /** Sets all the faces of the mesh. Used in parser
189 * \param nFaces The number of faces that will be set
190 * \param faces An array of GLMeshFaces with nFaces elements
191 */
192 GLS_EXPORT void SetFaces( unsigned int nFaces, GLMeshFace* faces );
193
194 /** Sets all the faces and vertices of the mesh. Used in generated code
195 * \param nVertices Number of vertices
196 * \param vertices Array of initialized vertices
197 * \param nFaces Number of faces
198 * \param faces Array of initialized faces
199 */
200 GLS_EXPORT void SetVerticesAndFaces( unsigned int nVertices, const GLMeshVertex* vertices, unsigned int nFaces, const GLMeshFace* faces );
201
202 /** Creates a GLTriMesh with the vertices specified
203 * \param nVertices The number of vertices in the new polygon
204 * \param vertices The array of vertices for the polygon
205 */
206 GLS_EXPORT GLTriMesh( unsigned int nVertices, Vertex* vertices );
207
208 /// Creates a GLTriMesh with the vertices specified.
209 /// \param nVertices The number of vertices in the new polygon.
210 /// \param vertices The array of vertices for the polygon.
211 /// \param location The location point of the object.
212 GLS_EXPORT GLTriMesh( unsigned int nVertices, Vertex* vertices, Vertex& location );
213
214 /** Allocate a (blank) GLTriMesh object */
216
217 /// Copy constructor
218 /// \param that The object to copy from.
219 /// \param generateNames Whether or not an instance name should be generated for this object.
220 GLS_EXPORT GLTriMesh( const GLTriMesh& that, const bool generateNames );
221
222 /** Destroy a GLTriMesh object */
224
225 /// \return A pointer to a new GLTriMesh object.
227
229
230#ifdef GLES
231 GLS_EXPORT void PreDraw( const OpenGLMatrices& current, Culler& culler ) DISTI_METHOD_OVERRIDE;
232#endif
233
235 GLS_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
236
237#ifndef GLES
240
241 /// Set whether or not the mesh will use a display list, rather than immediate mode.
242 /// \param flag The new display list mode to set.
243 virtual GLS_EXPORT void UseDisplayList( const bool& flag );
244
245 /// \return Whether or not the mesh will use a display list, rather than immediate mode.
247#endif
248
249 /** Causes the display list for this object to be recomputed */
251 {
252#ifndef GLES
254#endif
255 }
256
257protected:
258#ifndef GLES
259 /** Contains the actual OpenGL drawing commands to draw the object */
260 virtual GLS_EXPORT void DrawGeometry();
261#endif
262 /// Set up the OpenGL state for texturing.
263 /// \note A mesh can have multiple textures.
264 /// \param textureIndex The first texture to use.
265 /// \return Whether or not the OpenGL state was changed.
266 virtual GLS_EXPORT bool SetupTexture( const int textureIndex );
267
268#ifdef GLES
269 /** Set a single attribute from the GLO file.
270 * \param data The attribute to set and its associated data.
271 */
272 GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
273#endif
274
275private:
276 unsigned int _nFaces; /** Number of faces (triangles) in this mesh */
277
278 GLMeshFace* _faces; /** Array of vertex indices for triangles */
279
280 DynamicArray<int> _newMaterialIndices; /** Intermediate data storage to make the setting of new material indices through the Faces simpler. */
281
282#ifdef GLES
283 /* Resizable array of indices into the faces array where the active texture is different from
284 * the previous face.
285 */
286 DynamicArray<unsigned int> _textureChangeIndices;
287 bool _textureChangesDirty; /** true if _textureSwitchIndices needs to be recomputed */
288
289 /* Utility routine used by Draw. Should only be called when _textureSwitchDirty is true.
290 * Rebuilds the _textureSwitchIndices array by scanning the data in the face array
291 * and taking note when the texture index changes between faces.
292 */
293 void RecalculateTextureChanges();
294#endif
295 /* Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object
296 * but does not guarantee that the collision point returned by Hit is the closest collision point
297 * to the observer
298 * \param point The logical coordinate of the click, relative to the object
299 * \param directionVector The direction of the pick vector
300 * \param collisionPoint Set to the point on the object hit by directionVector
301 * \return boolean indicating if the object was hit by the mouse
302 */
303 bool FirstHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
304
305 /* Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object
306 * and guarantees that the collision point returned by Hit is the closest collision point to the observer.
307 * \param point The logical coordinate of the click, relative to the object
308 * \param directionVector The direction of the pick vector
309 * \param collisionPoint Set to the point on the object hit by directionVector
310 * \return boolean indicating if the object was hit by the mouse
311 */
312 bool BestHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
313
314 /* Utility routines used to detect when the material indices has changed */
315 void OnMatChanged();
316 void OnMatChanged( DynamicArray<int>& a, DynamicArray<int>& b );
317
320
321 void CopyGeometryInternal( GLTriMesh* src );
322 void CopyPropertiesInternal( GLTriMesh* src );
323};
324
325/** The DistiAttributeMeshFaceArray class. Defines metadata for the GlMeshFace type.
326 */
328{
329 GLMeshFace** _attribPtr; ///< Observing pointer to the underlying mesh data.
330 unsigned int* _numFaces; ///< Observing pointer to the underlying mesh face count.
331 bool _inRuntimeMode; ///< Governs the attribute parsing behavior.
332
333public:
334 /// Constructor
335 /// \param callback The callback to call when the attribute changes.
336 /// \param name The name of the new attribute.
337 /// \param attribPtr A pointer to the underlying mesh data.
338 /// \param numFaces A pointer to the underlying mesh face count.
339 /// \param inRuntimeMode Mode for attribute parsing behavior.
340 GLS_EXPORT DistiAttributeMeshFaceArray( CallbackMethodCallerBase* callback, const AttributeName& name, GLMeshFace** attribPtr, unsigned int* numFaces, bool inRuntimeMode );
341
343
345
346 GLS_EXPORT std::ostream& WriteValue( std::ostream& ) DISTI_METHOD_OVERRIDE;
347 GLS_EXPORT std::istream& ReadValue( std::istream& ) DISTI_METHOD_OVERRIDE;
348
350};
351
352} // namespace disti
353
354#endif
Definition: disti_metadata.h:87
Definition: callback_caller_base.h:55
Definition: cull.h:49
Definition: display.h:95
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler)
Definition: disti_metadata.h:220
Definition: gltrimesh.h:328
bool OkToWrite() const override
std::string Type() const override
std::ostream & WriteValue(std::ostream &) override
DistiAttributeMeshFaceArray(CallbackMethodCallerBase *callback, const AttributeName &name, GLMeshFace **attribPtr, unsigned int *numFaces, bool inRuntimeMode)
std::istream & ReadValue(std::istream &) override
Definition: dynamic_array.h:79
The Polygon class. Implements Polygons.
Definition: glpolygon.h:55
The glTriMesh class. Implements Triangle Meshes.
Definition: gltrimesh.h:93
void SetAvailableAttributes(unsigned int value) override
bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) override
virtual void DrawGeometry()
void VaSetFaces(unsigned int numFaces,...)
void CopyProperties(DisplayObject *src) override
virtual bool UseDisplayList()
void SetFaces(unsigned int nFaces, GLMeshFace *faces)
virtual bool SetupTexture(const int textureIndex)
void CopyGeometry(DisplayObject *src) override
int TextureIndex() override
void SetValue(int spec, va_list &args) override
void SetVerticesAndFaces(unsigned int nVertices, const GLMeshVertex *vertices, unsigned int nFaces, const GLMeshFace *faces)
DynamicArray< int > & MaterialIndices() override
InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) override
void MaterialIndex(unsigned int index)
Definition: gltrimesh.h:135
GLTriMesh(unsigned int nVertices, Vertex *vertices, Vertex &location)
void AssignPropertiesFromGroup(DisplayObject *src)
static DisplayObject * CreateInstance()
GlsDisplayList _displayList
Definition: gltrimesh.h:118
unsigned int NumberOfFaces()
Definition: gltrimesh.h:163
DisplayObject * CloneObject(bool generateNames=false) override
GLTriMesh(unsigned int nVertices, Vertex *vertices)
void DrawOutlineMesh()
void GetCppInterfaceDescriptionFree(InterfaceListType *array) override
virtual ~GLTriMesh()
virtual void UseDisplayList(const bool &flag)
void MaterialIndex(int index) override
GLMeshFace * Faces()
Definition: gltrimesh.h:145
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:250
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)
void Draw() override
Definition: gls_display_list.h:51
void Invalidate()
Definition: gls_display_list.h:85
Definition: gls_glo_file.h:1241
Definition: gls_index_array.h:50
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:540
Definition: vertex.h:84
Definition: vertex.h:419
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:245
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:487
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:221
The disti::GlsDisplayList class.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:50
The disti::GlsIndexArray class, for managing index buffers.
Definition: bmpimage.h:46
Structure for holding mesh vertex indices.
Definition: gltrimesh.h:71
int b
Vertex indices of the face.
Definition: gltrimesh.h:73
int c
Vertex indices of the face.
Definition: gltrimesh.h:74
int texture
Texture index of face.
Definition: gltrimesh.h:75
int a
Vertex indices of the face.
Definition: gltrimesh.h:72
unsigned int material
Material index of face.
Definition: gltrimesh.h:76
Definition: gltrimesh.h:82