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