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:
85  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
88  friend class GlsSerialMorphMeshEditor;
89 
90  /** Create a new GlsSerialMorphMesh. */
91  GLSGEN_GlsSerialMorphMesh_EXPORT GlsSerialMorphMesh( void );
92 
93  GLSGEN_GlsSerialMorphMesh_EXPORT GlsSerialMorphMesh( const GlsSerialMorphMesh& that, const bool generateNames );
94 
95  /** Destructs a GlsSerialMorphMesh object */
96  virtual GLSGEN_GlsSerialMorphMesh_EXPORT ~GlsSerialMorphMesh();
97 
98  static GLSGEN_GlsSerialMorphMesh_EXPORT DisplayObject* CreateInstance();
99 
100  //////////////////////////////////////////////////
101  // Overridden base class methods
102  //////////////////////////////////////////////////
103 
104  /* See base class */
105  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
106  virtual GLSGEN_GlsSerialMorphMesh_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
107  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
108  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
109 
110 #ifndef GLES
111  virtual GLSGEN_GlsSerialMorphMesh_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
112  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
113 #endif
114 
115  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler ) DISTI_METHOD_OVERRIDE;
116  //virtual GLSGEN_GlsSerialMorphMesh_EXPORT void Draw(void);
117 
118  //virtual GLSGEN_GlsSerialMorphMesh_EXPORT void UpdateBoundingVolume(void);
119 
120  //////////////////////////////////////////////////
121  // GlsSerialMorphMesh specific operations
122  //////////////////////////////////////////////////
123 
124  /** Set the number of keyframes in the mesh
125  If this is less than the current number of keyframes, then keyframes >=NumKeyframes() will be released
126  The initial Geometry and Values for new keyframes are undefined, be sure to fill them in before you
127  try to draw/pick/etc.
128  \param count the new number of keyframes
129  */
130  GLSGEN_GlsSerialMorphMesh_EXPORT void SetNumKeyframes( unsigned int count );
131 
132  /** Get the number of keyframes in the mesh
133  \returns the number of keyframes
134  */
135  GLSGEN_GlsSerialMorphMesh_EXPORT unsigned int NumKeyframes();
136 
137  /** Set the geometry for the given keyframe.
138  */
139  GLSGEN_GlsSerialMorphMesh_EXPORT GlsGeometry_Generic* GetKeyframeGeometry( unsigned int index );
140 
141  /** Set the geometry for the given keyframe.
142  * Note that the render geometry Type() is derived from keyframe 0.
143  * If you modify the Type() of the keyframe geometry you must call this method to update the render mesh.
144  * \param keyframeIndex
145  * \param newKeyframeGeometry Pointer to the new geometry to use
146  */
147  GLSGEN_GlsSerialMorphMesh_EXPORT void SetKeyframeGeometry( unsigned int keyframeIndex, GlsGeometry_Generic* newKeyframeGeometry );
148 
149  /** Set the value for the given animation keyframe
150  */
151  GLSGEN_GlsSerialMorphMesh_EXPORT void SetKeyframePercent( unsigned int index, const float& value );
152 
153  /** Get the value for the given animation keyframe
154  * \param index keyframe index
155  * \returns percent
156  */
157  GLSGEN_GlsSerialMorphMesh_EXPORT float GetKeyframePercent( unsigned int index );
158 
159  /** Set the mesh to the given animation value
160  */
161  GLSGEN_GlsSerialMorphMesh_EXPORT void SetMorphPercent( const float& value );
162 
163  /** Get the current animation value
164  * \returns percent animation value
165  */
166  GLSGEN_GlsSerialMorphMesh_EXPORT float GetMorphPercent();
167 
168  /** Set the tension parameter.
169  * Tension affects how the mesh is interpolated between targets.
170  * \param value value to determine what interpolation is used
171  * 0.0 is linear interpolation
172  * higher values use spline interpolation to smooth out the transitions at each target.
173  * Recommended values are 0.0 and 0.5. Other values result in "special effects".
174  */
175  GLSGEN_GlsSerialMorphMesh_EXPORT void SetTension( const float& value );
176 
177  /** Get the current 'tension' value
178  * \returns tension value
179  */
180  GLSGEN_GlsSerialMorphMesh_EXPORT float GetTension();
181 
182  /** Flag the render mesh as dirty so that it will be updated before it is drawn
183  */
184  inline void InvalidateRenderMesh() { _renderMeshIsValid = false; }
185 
186  /** Update the render mesh immeadiately
187  * This is normally done as needed automatically
188  */
189  GLSGEN_GlsSerialMorphMesh_EXPORT void UpdateRenderMesh();
190 
191 protected:
192  /** GlsGeometryResourceMesh override
193  */
194  virtual GLSGEN_GlsSerialMorphMesh_EXPORT GlsGeometryResource* GetRenderMesh() DISTI_METHOD_OVERRIDE;
195 
196 #ifdef GLES
197  /** Set a single attribute from the GLO file.
198  * \param data The attribute to set and its associated data.
199  */
200  virtual GLSGEN_GlsSerialMorphMesh_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
201 #endif
202 
204  {
205  protected:
206  DistiAttribDict* _attribDict;
207 
208  void SetupAttribDict();
209 
210  public:
211  GlsGeometry_Generic* _geometry;
212  float _value;
213 
214  GLSGEN_GlsSerialMorphMesh_EXPORT Keyframe_Data();
215  GLSGEN_GlsSerialMorphMesh_EXPORT Keyframe_Data( const Keyframe_Data& );
216  GLSGEN_GlsSerialMorphMesh_EXPORT ~Keyframe_Data();
217  GLSGEN_GlsSerialMorphMesh_EXPORT const Keyframe_Data& operator=( const Keyframe_Data& );
218 
219  GLSGEN_GlsSerialMorphMesh_EXPORT void SetGeometry( GlsGeometry_Generic* geom );
220  GLSGEN_GlsSerialMorphMesh_EXPORT GlsGeometry_Generic* GetGeometry();
221 
222  GLSGEN_GlsSerialMorphMesh_EXPORT DistiAttribDict& Attributes();
223  };
224 
226  {
227  public:
228  GlsSerialMorphMesh* _parentMesh;
229 
230  GLSGEN_GlsSerialMorphMesh_EXPORT KeyframeDataArray()
231  : _parentMesh( NULL )
232  {}
233 
234  static void element_read_func( int index, KeyframeDataArray& array, std::istream& instr );
235  static void element_write_func( int index, KeyframeDataArray& array, std::ostream& outstr );
236 
237  void Count( unsigned count ) { _keyframes.Count( count ); }
238  unsigned Count() const { return _keyframes.Count(); }
239 
240  void Clear() { _keyframes.Clear(); }
241 
242  Keyframe_Data& operator[]( const std::size_t index ) { return _keyframes[ static_cast<unsigned>( index ) ]; }
243  const Keyframe_Data& operator[]( const std::size_t index ) const { return _keyframes[ static_cast<unsigned>( index ) ]; }
244 
245  private:
246  DynamicArray<Keyframe_Data> _keyframes;
247  };
248 
249  KeyframeDataArray _keyframes;
250 
251  // The current position in the animation
252  float _currentValue;
253 
254  // The interpolation tension value
255  float _tension;
256 
257  unsigned int _last_keyframe_index; // The first keyframe where _value <= _currentValue
258  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
259  float _last_keyframe_weight; // The blend weight for the first keyframe [0,1]
260  float _next_keyframe_weight; // The blend weight for the next keyframe [0,1]
261 
262  bool _renderMeshIsValid;
263  GlsGeometry_Generic* _renderMesh;
264 
265  // Update the _last_keyframe_index, _next_keyframe_index, _last_keyframe_weight and _next_keyframe_weight
266  GLSGEN_GlsSerialMorphMesh_EXPORT void RecalculateKeyframeIndicesAndWeights();
267 
268  // Called by the KeyframeData class when the geometry changes.
269  GLSGEN_GlsSerialMorphMesh_EXPORT void KeyframeGeometryChanged( Keyframe_Data* );
270 
271 private:
272 #ifdef GLES
273  int _gloKeyframeIndex;
274 #endif
275 
276  void CalculateBSplineInterpolation() const;
277 
278  // Used by constructors
279  GLSGEN_GlsSerialMorphMesh_EXPORT void InitializeMembers();
280 
281  // Disable implicit generated Members
282  GlsSerialMorphMesh& operator=( const GlsSerialMorphMesh& rhs ) DISTI_SPECIAL_MEM_FUN_DELETE;
283  GlsSerialMorphMesh( const GlsSerialMorphMesh& src ) DISTI_SPECIAL_MEM_FUN_DELETE;
284 };
285 
286 } // namespace disti
287 
288 #endif
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) DISTI_METHOD_OVERRIDE
Definition: cull.h:49
virtual GlsGeometryResource * GetRenderMesh() DISTI_METHOD_OVERRIDE
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
Definition: dynamic_array.h:66
The disti::Group class. Implements groups of objects.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:473
Definition: display.h:98
The disti::GlsAdvancedMesh class.
virtual void CopyGeometry(DisplayObject *src) DISTI_METHOD_OVERRIDE
virtual void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
void SetMorphPercent(const float &value)
void InvalidateRenderMesh()
Definition: gls_serial_morph_mesh.h:184
Definition: gls_serial_morph_mesh.h:82
virtual void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) DISTI_METHOD_OVERRIDE
Definition: gls_glo_file.h:988
GlsGeometry_Generic * GetKeyframeGeometry(unsigned int index)
Definition: gls_serial_morph_mesh.h:203
Definition: gls_geometry_resource.h:86
Definition: gls_serial_morph_mesh.h:225
unsigned int NumKeyframes()
float GetKeyframePercent(unsigned int index)
Definition: disti_metadata.h:668
The gls_auto_lib.
void SetKeyframeGeometry(unsigned int keyframeIndex, GlsGeometry_Generic *newKeyframeGeometry)
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
Definition: gls_geometry_resource_mesh.h:78
void SetTension(const float &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 DisplayObject * CloneObject(bool generateNames=false) DISTI_METHOD_OVERRIDE
Definition: bmpimage.h:46
Definition: gls_geometry_resource.h:457