Torque3D Documentation / _generateds / tsShapeConstruct.h

tsShapeConstruct.h

Engine/source/ts/tsShapeConstruct.h

More...

Classes:

class

This class allows an artist to export their animations for the model into the .dsq format.

Public Defines

define
ADD_TO_CHANGE_SET() mChangeSet.add( newCmd );
define
DefineTSShapeConstructorMethod(name, retType, args, defArgs, rawArgs, defRet, usage)    ( , name, retType, args, defArgs, usage )                \
   {                                                                                            \
      /* Check that shape is loaded */                                                          \
      ( !object->getShape() )                                                                 \
      {                                                                                         \
         ( "TSShapeConstructor::" #name " - shape not loaded" );                     \
         return defRet;                                                                         \
      }                                                                                         \
       actionCallback(object);                            \
      return object->name rawArgs ;                                                             \
   }                                                                                            \
   /* Define the real  method */                                              \
   retType TSShapeConstructor::name args                                                        \
   {                                                                                            \
      /* Initialise change set command (may or may not be added) */                             \
       newCmd( #name );                                   \
      newCmd.addArgs rawArgs ;                                                                  \
      (newCmd);

Public Typedefs

TSShapeConstructorLodType 
domUpAxisType
TSShapeConstructorUpAxis 

Detailed Description

Public Defines

ADD_TO_CHANGE_SET() mChangeSet.add( newCmd );
DefineTSShapeConstructorMethod(name, retType, args, defArgs, rawArgs, defRet, usage)    ( , name, retType, args, defArgs, usage )                \
   {                                                                                            \
      /* Check that shape is loaded */                                                          \
      ( !object->getShape() )                                                                 \
      {                                                                                         \
         ( "TSShapeConstructor::" #name " - shape not loaded" );                     \
         return defRet;                                                                         \
      }                                                                                         \
       actionCallback(object);                            \
      return object->name rawArgs ;                                                             \
   }                                                                                            \
   /* Define the real  method */                                              \
   retType TSShapeConstructor::name args                                                        \
   {                                                                                            \
      /* Initialise change set command (may or may not be added) */                             \
       newCmd( #name );                                   \
      newCmd.addArgs rawArgs ;                                                                  \
      (newCmd);

Public Typedefs

typedef ColladaUtils::ImportOptions::eAnimTimingType TSShapeConstructorAnimType 
typedef ColladaUtils::ImportOptions::eLodType TSShapeConstructorLodType 
typedef domUpAxisType TSShapeConstructorUpAxis 

Public Functions

DefineEnumType(TSShapeConstructorAnimType )

DefineEnumType(TSShapeConstructorLodType )

DefineEnumType(TSShapeConstructorUpAxis )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _TSSHAPECONSTRUCT_H_
 25#define _TSSHAPECONSTRUCT_H_
 26
 27#ifndef __RESOURCE_H__
 28#include "core/resource.h"
 29#endif
 30#ifndef _MTRANSFORM_H_
 31#include "math/mTransform.h"
 32#endif
 33#ifndef _TSSHAPE_H_
 34#include "ts/tsShape.h"
 35#endif
 36#ifndef _SIMBASE_H_
 37#include "console/simBase.h"
 38#endif
 39#ifndef _COLLADA_UTILS_H_
 40#include "ts/collada/colladaUtils.h"
 41#endif
 42#ifndef _ENGINEAPI_H_
 43#include "console/engineAPI.h"
 44#endif
 45
 46/// This class allows an artist to export their animations for the model
 47/// into the .dsq format.  This class in particular matches up the model
 48/// with the .dsqs to create a nice animated model.
 49class TSShapeConstructor : public SimObject
 50{
 51   typedef SimObject Parent;
 52
 53public:
 54   struct ChangeSet
 55   {
 56      enum eCommandType
 57      {
 58         CmdAddNode,
 59         CmdRemoveNode,
 60         CmdRenameNode,
 61         CmdSetNodeTransform,
 62         CmdSetNodeParent,
 63
 64         CmdAddMesh,
 65         CmdAddPrimitive,
 66         CmdRemoveMesh,
 67         CmdSetMeshSize,
 68         CmdSetMeshType,
 69         CmdSetMeshMaterial,
 70
 71         CmdRemoveObject,
 72         CmdRenameObject,
 73         CmdSetObjectNode,
 74         CmdSetBounds,
 75
 76         CmdRenameDetailLevel,
 77         CmdRemoveDetailLevel,
 78         CmdSetDetailLevelSize,
 79         CmdAddImposter,
 80         CmdRemoveImposter,
 81         CmdAddCollisionDetail,
 82
 83         CmdAddSequence,
 84         CmdRemoveSequence,
 85         CmdRenameSequence,
 86         CmdSetSequenceCyclic,
 87         CmdSetSequenceBlend,
 88         CmdSetSequencePriority,
 89         CmdSetSequenceGroundSpeed,
 90
 91         CmdAddTrigger,
 92         CmdRemoveTrigger,
 93
 94         CmdInvalid
 95      };
 96
 97      struct Command
 98      {
 99         eCommandType      type;       // Command type
100         StringTableEntry  name;       // Command name
101         static const U32 MAX_ARGS = 10;
102         String            argv[MAX_ARGS];   // Command arguments
103         S32               argc;       // Number of arguments
104         Command() : type(CmdInvalid), name(0), argc(0) { }
105         Command( const char* _name )
106            : type(CmdInvalid), argc(0)
107         {
108            name = StringTable->insert( _name );
109         }
110        
111        // Helper functions to fill in the command arguments
112        template<typename ...ArgTs> inline void addArgs(ArgTs ...args){
113           using Helper = engineAPI::detail::MarshallHelpers<String>;
114           Helper::marshallEach(argc, argv, args...);
115        }
116      };
117
118      Vector<Command>   mCommands;
119
120      eCommandType getCmdType(const char* name);
121      void clear() { mCommands.clear(); }
122      bool empty() { return mCommands.empty(); }
123
124      void add( Command& cmd );
125
126      // These methods handle change set optimisation based on the newly added command
127      bool addCmd_setNodeParent( const Command& newCmd );
128      bool addCmd_setNodeTransform( const Command& newCmd );
129      bool addCmd_renameNode( const Command& newCmd );
130      bool addCmd_removeNode( const Command& newCmd );
131
132      bool addCmd_setMeshSize( const Command& newCmd );
133      bool addCmd_setMeshType( const Command& newCmd );
134      bool addCmd_setMeshMaterial( const Command& newCmd );
135      bool addCmd_removeMesh( const Command& newCmd );
136
137      bool addCmd_setObjectNode( const Command& newCmd );
138      bool addCmd_renameObject( const Command& newCmd );
139      bool addCmd_removeObject( const Command& newCmd );
140      bool addCmd_setBounds( const Command& newCmd );
141
142      bool addCmd_renameDetailLevel( const Command& newCmd );
143      bool addCmd_removeDetailLevel( const Command& newCmd );
144      bool addCmd_setDetailSize( const Command& newCmd );
145      bool addCmd_addImposter( const Command& newCmd );
146      bool addCmd_removeImposter( const Command& newCmd );
147
148      bool addCmd_addSequence( Command& newCmd );
149      bool addCmd_setSequencePriority( const Command& newCmd );
150      bool addCmd_setSequenceGroundSpeed( const Command& newCmd );
151      bool addCmd_setSequenceCyclic( const Command& newCmd );
152      bool addCmd_setSequenceBlend( const Command& newCmd );
153      bool addCmd_renameSequence( const Command& newCmd );
154      bool addCmd_removeSequence( const Command& newCmd );
155
156      bool addCmd_addTrigger( const Command& newCmd );
157      bool addCmd_removeTrigger( const Command& newCmd );
158
159      void write(TSShape* shape, Stream& stream, const String& savePath);
160   };
161
162   static const S32 MaxLegacySequences = 127;
163
164protected:
165   FileName          mShapePath;
166   Vector<FileName>  mSequences;
167   ChangeSet         mChangeSet;
168
169   // Paths to shapes used by MeshFit
170   static String smCapsuleShapePath;
171   static String smCubeShapePath;
172   static String smSphereShapePath;
173
174   static bool addSequenceFromField( void *obj, const char *index, const char *data );
175   
176   static void       _onTSShapeLoaded( Resource< TSShape>& shape );
177   static void       _onTSShapeUnloaded( const Torque::Path& path, TSShape* shape );
178   
179   static ResourceRegisterPostLoadSignal< TSShape> _smAutoLoad;
180   static ResourceRegisterUnloadSignal< TSShape> _smAutoUnload;
181   
182   /// @name Callbacks
183   ///@{
184   DECLARE_CALLBACK( void, onLoad, () );
185   DECLARE_CALLBACK( void, onUnload, () );
186   ///@}
187
188   virtual void      _onLoad( TSShape* shape );
189   virtual void      _onUnload();
190
191public:
192
193   TSShape*                mShape;        // Edited shape; NULL while not loaded; not a Resource<TSShape> as we don't want it to prevent from unloading.
194   ColladaUtils::ImportOptions   mOptions;
195   bool mLoadingShape;
196
197public:
198
199   TSShapeConstructor();
200   TSShapeConstructor(const String& path) : mShapePath(path), mShape(NULL), mLoadingShape(false){ }
201   ~TSShapeConstructor();
202
203   DECLARE_CONOBJECT(TSShapeConstructor);
204   static void initPersistFields();
205   static void consoleInit();
206   static TSShapeConstructor* findShapeConstructor(const FileName& path);
207
208   bool onAdd();
209
210   void onScriptChanged(const Torque::Path& path);
211   void onActionPerformed();
212
213   bool writeField(StringTableEntry fieldname, const char *value);
214   void writeChangeSet();
215
216   void notifyShapeChanged();
217
218   /// @name Shape paths for MeshFit
219   ///@{
220   static const String& getCapsuleShapePath() { return smCapsuleShapePath; }
221   static const String& getCubeShapePath() { return smCubeShapePath; }
222   static const String& getSphereShapePath() { return smSphereShapePath; }
223   ///@}
224
225   TSShape* getShape() const { return mShape; }
226   const String& getShapePath() const { return mShapePath; }
227
228   /// @name Dumping
229   ///@{
230   void dumpShape( const char* filename );
231   void saveShape( const char* filename );
232   ///@}
233
234   /// @name Nodes
235   ///@{
236   S32 getNodeCount();
237   S32 getNodeIndex( const char* name );
238   const char* getNodeName( S32 index );
239   const char* getNodeParentName( const char* name );
240   bool setNodeParent( const char* name, const char* parentName );
241   S32 getNodeChildCount( const char* name );
242   const char* getNodeChildName( const char* name, S32 index );
243   S32 getNodeObjectCount( const char* name );
244   const char* getNodeObjectName( const char* name, S32 index );
245   TransformF getNodeTransform( const char* name, bool isWorld=false );
246   bool setNodeTransform( const char* name, TransformF txfm, bool isWorld=false );
247   bool renameNode( const char* oldName, const char* newName );
248   bool addNode( const char* name, const char* parentName, TransformF txfm=<a href="/coding/class/classtransformf/#classtransformf_1acb5c27d878efd1962ebed24898457fa3">TransformF::Identity</a>, bool isWorld=false);
249   bool removeNode( const char* name );
250   ///@}
251
252   /// @name Materials
253   ///@{
254   S32 getTargetCount();
255   const char* getTargetName( S32 index );
256   ///@}
257
258   ///@{
259   S32 getObjectCount();
260   const char* getObjectName( S32 index );
261   S32 getObjectIndex( const char* name );
262   const char* getObjectNode( const char* name );
263   bool setObjectNode( const char* objName, const char* nodeName );
264   bool renameObject( const char* oldName, const char* newName );
265   bool removeObject( const char* name );
266   ///@}
267
268   /// @name Meshes
269   ///@{
270   S32 getMeshCount( const char* name );
271   const char* getMeshName( const char* name, S32 index );
272   S32 getMeshSize( const char* name, S32 index );
273   bool setMeshSize( const char* name, S32 size );
274   const char* getMeshType( const char* name );
275   bool setMeshType( const char* name, const char* type );
276   const char* getMeshMaterial( const char* name );
277   bool setMeshMaterial( const char* meshName, const char* matName );
278   bool addMesh( const char* meshName, const char* srcShape, const char* srcMesh );
279   bool addPrimitive( const char* meshName, const char* type, const char* params, TransformF txfm, const char* nodeName );
280   bool removeMesh( const char* name );
281   ///@}
282
283   /// @name Detail Levels
284   ///@{
285   Box3F getBounds();
286   bool setBounds( Box3F bbox );
287   S32 getDetailLevelCount();
288   const char* getDetailLevelName( S32 index );
289   S32 getDetailLevelSize( S32 index);
290   S32 getDetailLevelIndex( S32 size );
291   bool renameDetailLevel( const char* oldName, const char* newName );
292   bool removeDetailLevel( S32 index );
293   S32 setDetailLevelSize( S32 index, S32 newSize );
294   S32 getImposterDetailLevel();
295   const char* getImposterSettings( S32 index );
296   S32 addImposter( S32 size, S32 equatorSteps, S32 polarSteps, S32 dl, S32 dim, bool includePoles, F32 polarAngle );
297   bool removeImposter();
298   bool addCollisionDetail( S32 size, const char* type, const char* target, S32 depth=4, F32 merge=30.0f, F32 concavity=30.0f, S32 maxVerts=32, F32 boxMaxError=0, F32 sphereMaxError=0, F32 capsuleMaxError=0 );
299   ///@}
300
301   /// @name Sequences
302   ///@{
303   S32 getSequenceCount();
304   S32 getSequenceIndex( const char* name);
305   const char* getSequenceName( S32 index );
306   const char* getSequenceSource( const char* name );
307   S32 getSequenceFrameCount( const char* name );
308   F32 getSequencePriority( const char* name );
309   bool setSequencePriority( const char* name, F32 priority );
310   const char* getSequenceGroundSpeed( const char* name );
311   bool setSequenceGroundSpeed( const char* name, Point3F transSpeed, Point3F rotSpeed=<a href="/coding/class/classpoint3f/#classpoint3f_1aeb8504bc663cf40468c4e977aeb96a4c">Point3F::Zero</a> );
312   bool getSequenceCyclic( const char* name );
313   bool setSequenceCyclic( const char* name, bool cyclic );
314   const char* getSequenceBlend( const char* name );
315   bool setSequenceBlend( const char* name, bool blend, const char* blendSeq, S32 blendFrame );
316   bool renameSequence( const char* oldName, const char* newName );
317   bool addSequence( const char* source, const char* name, S32 start=0, S32 end=-1, bool padRot=true, bool padTrans=false );
318   bool removeSequence( const char* name );
319   ///@}
320
321   /// @name Triggers
322   ///@{
323   S32 getTriggerCount( const char* name );
324   const char* getTrigger( const char* name, S32 index );
325   bool addTrigger( const char* name, S32 keyframe, S32 state );
326   bool removeTrigger( const char* name, S32 keyframe, S32 state );
327   ///@}
328};
329
330typedef domUpAxisType TSShapeConstructorUpAxis;
331typedef ColladaUtils::ImportOptions::eLodType TSShapeConstructorLodType;
332typedef ColladaUtils::ImportOptions::eAnimTimingType TSShapeConstructorAnimType;
333
334DefineEnumType( TSShapeConstructorUpAxis );
335DefineEnumType(TSShapeConstructorLodType);
336DefineEnumType(TSShapeConstructorAnimType);
337
338class TSShapeConstructorMethodActionCallback
339{
340   TSShapeConstructor* mObject;
341
342public:
343   TSShapeConstructorMethodActionCallback(TSShapeConstructor *object) : mObject(object) { ; }
344   ~TSShapeConstructorMethodActionCallback() { mObject->onActionPerformed(); }
345};
346
347/* This macro simplifies the definition of a TSShapeConstructor API method. It
348   wraps the actual EngineMethod definition and automatically calls the real
349   class method. It also creates a ChangeSet::Comand (with all arguments stored
350   as strings). The one drawback is that it includes the open brace for the real
351   class method, so to keep the code looking mostly normal, such methods start
352   with another open brace, and end with a double closing brace. Not perfect,
353   but a lot better than having to type out the argument list multiple times for
354   the 50 odd API functions. */
355#define DefineTSShapeConstructorMethod( name, retType, args, defArgs, rawArgs, defRet, usage )  \
356   DefineEngineMethod( TSShapeConstructor, name, retType, args, defArgs, usage )                \
357   {                                                                                            \
358      /* Check that shape is loaded */                                                          \
359      if( !object->getShape() )                                                                 \
360      {                                                                                         \
361         Con::errorf( "TSShapeConstructor::" #name " - shape not loaded" );                     \
362         return defRet;                                                                         \
363      }                                                                                         \
364      TSShapeConstructorMethodActionCallback actionCallback(object);                            \
365      return object->name rawArgs ;                                                             \
366   }                                                                                            \
367   /* Define the real TSShapeConstructor method */                                              \
368   retType TSShapeConstructor::name args                                                        \
369   {                                                                                            \
370      /* Initialise change set command (may or may not be added) */                             \
371      TSShapeConstructor::ChangeSet::Command newCmd( #name );                                   \
372      newCmd.addArgs rawArgs ;                                                                  \
373      TORQUE_UNUSED(newCmd);
374
375
376/* This macro just hides the name of the auto-created ChangeSet::Command from
377   above, so we are free to change the implementation later if needed */
378#define ADD_TO_CHANGE_SET()   mChangeSet.add( newCmd );
379
380
381#endif
382