GL Studio C++ Runtime API
gls_serial_morph_mesh.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsSerialMorphMesh class.
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 INCLUDED_GLS_SERIAL_MORPH_MESH_H
42 #define INCLUDED_GLS_SERIAL_MORPH_MESH_H
43 
44 #ifdef _WIN32
45 # include <windows.h>
46 #endif
47 
48 #include "gls_geometry_resource.h"
49 #include "gls_resource_file_mgr.h"
50 #include "group.h"
51 
52 #include "gls_advanced_mesh.h"
53 #include "gls_cpp_lang_support.h"
54 
55 //////////////////// Provides support for creating DLLs ////////////////////////
56 #if( defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLSGEN_IMPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
57  && defined( _MSC_VER )
58 # if defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED )
59 # define GLSGEN_GlsSerialMorphMesh_EXPORT __declspec( dllexport )
60 # else
61 # define GLSGEN_GlsSerialMorphMesh_EXPORT __declspec( dllimport )
62 # endif
63 #else
64 # define GLSGEN_GlsSerialMorphMesh_EXPORT
65 #endif
66 ///////////////////////////////////////////////////////////////////////////////
67 
68 #define LIB_BASE_NAME "gls_advanced_mesh"
69 #include "gls_auto_lib.h"
70 #undef LIB_BASE_NAME
71 
72 namespace disti
73 {
74 #ifdef GLES
75 // Forward Declaration
76 class GlsGloFileAttribute;
77 #endif
78 
79 /**
80  The GlsSerialMorphMesh contains a series of morph targets (keyframes) that make up an animation.
81 */
83 {
84 public:
86  friend class GlsSerialMorphMeshEditor;
87 
88  /** Create a new GlsSerialMorphMesh. */
89  GLSGEN_GlsSerialMorphMesh_EXPORT GlsSerialMorphMesh( void );
90 
91  GLSGEN_GlsSerialMorphMesh_EXPORT GlsSerialMorphMesh( const GlsSerialMorphMesh& that, const bool generateNames );
92 
93  /** Destructs a GlsSerialMorphMesh object */
94  virtual GLSGEN_GlsSerialMorphMesh_EXPORT ~GlsSerialMorphMesh();
95 
96  static GLSGEN_GlsSerialMorphMesh_EXPORT DisplayObject* CreateInstance();
97 
98  //////////////////////////////////////////////////
99  // Overridden base class methods
100  //////////////////////////////////////////////////
101 
102  /* See base class */
103  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void SetAvailableAttributes( unsigned int value );
104  virtual GLSGEN_GlsSerialMorphMesh_EXPORT DisplayObject* CloneObject( bool generateNames = false );
105  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void CopyProperties( DisplayObject* src );
106  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void CopyGeometry( DisplayObject* src );
107 
108 #ifndef GLES
109  virtual GLSGEN_GlsSerialMorphMesh_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
110  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
111 #endif
112 
113  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler );
114  //virtual GLSGEN_GlsSerialMorphMesh_EXPORT void Draw(void);
115 
116  //virtual GLSGEN_GlsSerialMorphMesh_EXPORT void UpdateBoundingVolume(void);
117 
118  //////////////////////////////////////////////////
119  // GlsSerialMorphMesh specific operations
120  //////////////////////////////////////////////////
121 
122  /** Set the number of keyframes in the mesh
123  If this is less than the current number of keyframes, then keyframes >=NumKeyframes() will be released
124  The initial Geometry and Values for new keyframes are undefined, be sure to fill them in before you
125  try to draw/pick/etc.
126  \param count the new number of keyframes
127  */
128  GLSGEN_GlsSerialMorphMesh_EXPORT void SetNumKeyframes( unsigned int count );
129 
130  /** Get the number of keyframes in the mesh
131  \returns the number of keyframes
132  */
133  GLSGEN_GlsSerialMorphMesh_EXPORT unsigned int NumKeyframes();
134 
135  /** Set the geometry for the given keyframe.
136  */
137  GLSGEN_GlsSerialMorphMesh_EXPORT GlsGeometry_Generic* GetKeyframeGeometry( unsigned int index );
138 
139  /** Set the geometry for the given keyframe.
140  * Note that the render geometry Type() is derived from keyframe 0.
141  * If you modify the Type() of the keyframe geometry you must call this method to update the render mesh.
142  * \param keyframeIndex
143  * \param newKeyframeGeometry Pointer to the new geometry to use
144  */
145  GLSGEN_GlsSerialMorphMesh_EXPORT void SetKeyframeGeometry( unsigned int keyframeIndex, GlsGeometry_Generic* newKeyframeGeometry );
146 
147  /** Set the value for the given animation keyframe
148  */
149  GLSGEN_GlsSerialMorphMesh_EXPORT void SetKeyframePercent( unsigned int index, const float& value );
150 
151  /** Get the value for the given animation keyframe
152  * \param index keyframe index
153  * \returns percent
154  */
155  GLSGEN_GlsSerialMorphMesh_EXPORT float GetKeyframePercent( unsigned int index );
156 
157  /** Set the mesh to the given animation value
158  */
159  GLSGEN_GlsSerialMorphMesh_EXPORT void SetMorphPercent( const float& value );
160 
161  /** Get the current animation value
162  * \returns percent animation value
163  */
164  GLSGEN_GlsSerialMorphMesh_EXPORT float GetMorphPercent();
165 
166  /** Set the tension parameter.
167  * Tension affects how the mesh is interpolated between targets.
168  * \param value value to determine what interpolation is used
169  * 0.0 is linear interpolation
170  * higher values use spline interpolation to smooth out the transitions at each target.
171  * Recommended values are 0.0 and 0.5. Other values result in "special effects".
172  */
173  GLSGEN_GlsSerialMorphMesh_EXPORT void SetTension( const float& value );
174 
175  /** Get the current 'tension' value
176  * \returns tension value
177  */
178  GLSGEN_GlsSerialMorphMesh_EXPORT float GetTension();
179 
180  /** Flag the render mesh as dirty so that it will be updated before it is drawn
181  */
182  inline void InvalidateRenderMesh() { _renderMeshIsValid = false; }
183 
184  /** Update the render mesh immeadiately
185  * This is normally done as needed automatically
186  */
187  GLSGEN_GlsSerialMorphMesh_EXPORT void UpdateRenderMesh();
188 
189 protected:
190  /** GlsGeometryResourceMesh override
191  */
192  virtual GLSGEN_GlsSerialMorphMesh_EXPORT GlsGeometryResource* GetRenderMesh();
193 
194 #ifdef GLES
195  /** Set a single attribute from the GLO file.
196  * \param data The attribute to set and its associated data.
197  */
198  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
199 #endif
200 
202  {
203  protected:
204  DistiAttribDict* _attribDict;
205 
206  void SetupAttribDict();
207 
208  public:
209  GlsGeometry_Generic* _geometry;
210  float _value;
211 
212  GLSGEN_GlsSerialMorphMesh_EXPORT Keyframe_Data();
213  GLSGEN_GlsSerialMorphMesh_EXPORT Keyframe_Data( const Keyframe_Data& );
214  GLSGEN_GlsSerialMorphMesh_EXPORT ~Keyframe_Data();
215  GLSGEN_GlsSerialMorphMesh_EXPORT const Keyframe_Data& operator=( const Keyframe_Data& );
216 
217  GLSGEN_GlsSerialMorphMesh_EXPORT void SetGeometry( GlsGeometry_Generic* geom );
218  GLSGEN_GlsSerialMorphMesh_EXPORT GlsGeometry_Generic* GetGeometry();
219 
220  GLSGEN_GlsSerialMorphMesh_EXPORT DistiAttribDict& Attributes();
221  };
222 
223  class KeyframeDataArray : public DynamicArray<Keyframe_Data, false>
224  {
225  public:
226  GlsSerialMorphMesh* _parentMesh;
227 
228  GLSGEN_GlsSerialMorphMesh_EXPORT KeyframeDataArray()
229  : _parentMesh( NULL )
230  {}
231 
232  static void element_read_func( int index, KeyframeDataArray& array, std::istream& instr );
233  static void element_write_func( int index, KeyframeDataArray& array, std::ostream& outstr );
234  };
235 
236  KeyframeDataArray _keyframes;
237 
238  // The current position in the animation
239  float _currentValue;
240 
241  // The interpolation tension value
242  float _tension;
243 
244  unsigned int _last_keyframe_index; // The first keyframe where _value <= _currentValue
245  unsigned int _next_keyframe_index; // The next keyframe after last_keyframe_index where _value > _currentValue. If _value matches _currentValue exactly, then last_keyframe_index == next_keyframe_index
246  float _last_keyframe_weight; // The blend weight for the first keyframe [0,1]
247  float _next_keyframe_weight; // The blend weight for the next keyframe [0,1]
248 
249  bool _renderMeshIsValid;
250  GlsGeometry_Generic* _renderMesh;
251 
252  // Update the _last_keyframe_index, _next_keyframe_index, _last_keyframe_weight and _next_keyframe_weight
253  GLSGEN_GlsSerialMorphMesh_EXPORT void RecalculateKeyframeIndicesAndWeights();
254 
255  // Called by the KeyframeData class when the geometry changes.
256  GLSGEN_GlsSerialMorphMesh_EXPORT void KeyframeGeometryChanged( Keyframe_Data* );
257 
258 private:
259 #ifdef GLES
260  int _gloKeyframeIndex;
261 #endif
262 
263  // Used by constructors
264  GLSGEN_GlsSerialMorphMesh_EXPORT void InitializeMembers();
265 
266  // Disable implicit generated Members
267  GlsSerialMorphMesh& operator=( const GlsSerialMorphMesh& rhs ) DISTI_SPECIAL_MEM_FUN_DELETE;
268  GlsSerialMorphMesh( const GlsSerialMorphMesh& src ) DISTI_SPECIAL_MEM_FUN_DELETE;
269 };
270 
271 } // namespace disti
272 
273 #endif
Definition: cull.h:49
Definition: dynamic_array.h:62
The disti::Group class. Implements groups of objects.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:301
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
Definition: display.h:98
The disti::GlsAdvancedMesh class.
void SetMorphPercent(const float &value)
void InvalidateRenderMesh()
Definition: gls_serial_morph_mesh.h:182
virtual GlsGeometryResource * GetRenderMesh()
Definition: gls_serial_morph_mesh.h:82
Definition: gls_glo_file.h:982
virtual void CopyProperties(DisplayObject *src)
GlsGeometry_Generic * GetKeyframeGeometry(unsigned int index)
Definition: gls_serial_morph_mesh.h:201
Definition: gls_geometry_resource.h:82
Definition: gls_serial_morph_mesh.h:223
unsigned int NumKeyframes()
float GetKeyframePercent(unsigned int index)
virtual DisplayObject * CloneObject(bool generateNames=false)
Definition: disti_metadata.h:660
The gls_auto_lib.
void SetKeyframeGeometry(unsigned int keyframeIndex, GlsGeometry_Generic *newKeyframeGeometry)
Definition: gls_geometry_resource_mesh.h:78
virtual void CopyGeometry(DisplayObject *src)
void SetTension(const float &value)
virtual void SetAvailableAttributes(unsigned int value)
The disti::GlsGeometryResource class.
void SetKeyframePercent(unsigned int index, const float &value)
void SetNumKeyframes(unsigned int count)
Macros and helper code to determine what subset of C++11/14/17 is available.
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
Definition: bmpimage.h:46
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
Definition: gls_geometry_resource.h:453