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::eLodType TSShapeConstructorLodType 
typedef domUpAxisType TSShapeConstructorUpAxis 

Public Functions

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         String            argv[10];   // Command arguments
102         S32               argc;       // Number of arguments
103         Command() : type(CmdInvalid), name(0), argc(0) { }
104         Command( const char* _name )
105            : type(CmdInvalid), argc(0)
106         {
107            name = StringTable->insert( _name );
108         }
109
110         // Helper functions to fill in the command arguments
111         inline void addArgs() { }
112
113         template< typename A >
114            inline void addArgs( A a )
115         {
116            argv[argc++] = EngineMarshallData( a );
117         }
118         template< typename A, typename B > void addArgs( A a, B b )
119         {
120            addArgs( a );
121            addArgs( b );
122         } 
123         template< typename A, typename B, typename C >
124            inline void addArgs( A a, B b, C c )
125         {
126            addArgs( a );
127            addArgs( b, c );
128         }
129         template< typename A, typename B, typename C, typename D >
130            inline void addArgs( A a, B b, C c, D d )
131         {
132            addArgs( a );
133            addArgs( b, c, d );
134         }
135         template< typename A, typename B, typename C, typename D, typename E >
136            inline void addArgs( A a, B b, C c, D d, E e )
137         {
138            addArgs( a );
139            addArgs( b, c, d, e );
140         }
141         template< typename A, typename B, typename C, typename D, typename E, typename F >
142            inline void addArgs( A a, B b, C c, D d, E e, F f )
143         {
144            addArgs( a );
145            addArgs( b, c, d, e, f );
146         }
147         template< typename A, typename B, typename C, typename D, typename E, typename F, typename G >
148            inline void addArgs( A a, B b, C c, D d, E e, F f, G g )
149         {
150            addArgs( a );
151            addArgs( b, c, d, e, f, g );
152         }
153         template< typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H >
154            inline void addArgs( A a, B b, C c, D d, E e, F f, G g, H h )
155         {
156            addArgs( a );
157            addArgs( b, c, d, e, f, g, h );
158         }
159         template< typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I >
160            inline void addArgs( A a, B b, C c, D d, E e, F f, G g, H h, I i )
161         {
162            addArgs( a );
163            addArgs( b, c, d, e, f, g, h, i );
164         }
165         template< typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J >
166            inline void addArgs( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j )
167         {
168            addArgs( a );
169            addArgs( b, c, d, e, f, g, h, i, j );
170         }
171      };
172
173      Vector<Command>   mCommands;
174
175      eCommandType getCmdType(const char* name);
176      void clear() { mCommands.clear(); }
177      bool empty() { return mCommands.empty(); }
178
179      void add( Command& cmd );
180
181      // These methods handle change set optimisation based on the newly added command
182      bool addCmd_setNodeParent( const Command& newCmd );
183      bool addCmd_setNodeTransform( const Command& newCmd );
184      bool addCmd_renameNode( const Command& newCmd );
185      bool addCmd_removeNode( const Command& newCmd );
186
187      bool addCmd_setMeshSize( const Command& newCmd );
188      bool addCmd_setMeshType( const Command& newCmd );
189      bool addCmd_setMeshMaterial( const Command& newCmd );
190      bool addCmd_removeMesh( const Command& newCmd );
191
192      bool addCmd_setObjectNode( const Command& newCmd );
193      bool addCmd_renameObject( const Command& newCmd );
194      bool addCmd_removeObject( const Command& newCmd );
195      bool addCmd_setBounds( const Command& newCmd );
196
197      bool addCmd_renameDetailLevel( const Command& newCmd );
198      bool addCmd_removeDetailLevel( const Command& newCmd );
199      bool addCmd_setDetailSize( const Command& newCmd );
200      bool addCmd_addImposter( const Command& newCmd );
201      bool addCmd_removeImposter( const Command& newCmd );
202
203      bool addCmd_addSequence( Command& newCmd );
204      bool addCmd_setSequencePriority( const Command& newCmd );
205      bool addCmd_setSequenceGroundSpeed( const Command& newCmd );
206      bool addCmd_setSequenceCyclic( const Command& newCmd );
207      bool addCmd_setSequenceBlend( const Command& newCmd );
208      bool addCmd_renameSequence( const Command& newCmd );
209      bool addCmd_removeSequence( const Command& newCmd );
210
211      bool addCmd_addTrigger( const Command& newCmd );
212      bool addCmd_removeTrigger( const Command& newCmd );
213
214      void write(TSShape* shape, Stream& stream, const String& savePath);
215   };
216
217   static const S32 MaxLegacySequences = 127;
218
219protected:
220   FileName          mShapePath;
221   Vector<FileName>  mSequences;
222   ChangeSet         mChangeSet;
223
224   // Paths to shapes used by MeshFit
225   static String smCapsuleShapePath;
226   static String smCubeShapePath;
227   static String smSphereShapePath;
228
229   static bool addSequenceFromField( void *obj, const char *index, const char *data );
230   
231   static void       _onTSShapeLoaded( Resource< TSShape>& shape );
232   static void       _onTSShapeUnloaded( const Torque::Path& path, TSShape* shape );
233   
234   static ResourceRegisterPostLoadSignal< TSShape> _smAutoLoad;
235   static ResourceRegisterUnloadSignal< TSShape> _smAutoUnload;
236   
237   /// @name Callbacks
238   ///@{
239   DECLARE_CALLBACK( void, onLoad, () );
240   DECLARE_CALLBACK( void, onUnload, () );
241   ///@}
242
243   virtual void      _onLoad( TSShape* shape );
244   virtual void      _onUnload();
245
246public:
247
248   TSShape*                mShape;        // Edited shape; NULL while not loaded; not a Resource<TSShape> as we don't want it to prevent from unloading.
249   ColladaUtils::ImportOptions   mOptions;
250   bool mLoadingShape;
251
252public:
253
254   TSShapeConstructor();
255   TSShapeConstructor(const String& path) : mShapePath(path) { }
256   ~TSShapeConstructor();
257
258   DECLARE_CONOBJECT(TSShapeConstructor);
259   static void initPersistFields();
260   static void consoleInit();
261   static TSShapeConstructor* findShapeConstructor(const FileName& path);
262
263   bool onAdd();
264
265   void onScriptChanged(const Torque::Path& path);
266   void onActionPerformed();
267
268   bool writeField(StringTableEntry fieldname, const char *value);
269   void writeChangeSet();
270
271   void notifyShapeChanged();
272
273   /// @name Shape paths for MeshFit
274   ///@{
275   static const String& getCapsuleShapePath() { return smCapsuleShapePath; }
276   static const String& getCubeShapePath() { return smCubeShapePath; }
277   static const String& getSphereShapePath() { return smSphereShapePath; }
278   ///@}
279
280   TSShape* getShape() const { return mShape; }
281   const String& getShapePath() const { return mShapePath; }
282
283   /// @name Dumping
284   ///@{
285   void dumpShape( const char* filename );
286   void saveShape( const char* filename );
287   ///@}
288
289   /// @name Nodes
290   ///@{
291   S32 getNodeCount();
292   S32 getNodeIndex( const char* name );
293   const char* getNodeName( S32 index );
294   const char* getNodeParentName( const char* name );
295   bool setNodeParent( const char* name, const char* parentName );
296   S32 getNodeChildCount( const char* name );
297   const char* getNodeChildName( const char* name, S32 index );
298   S32 getNodeObjectCount( const char* name );
299   const char* getNodeObjectName( const char* name, S32 index );
300   TransformF getNodeTransform( const char* name, bool isWorld=false );
301   bool setNodeTransform( const char* name, TransformF txfm, bool isWorld=false );
302   bool renameNode( const char* oldName, const char* newName );
303   bool addNode( const char* name, const char* parentName, TransformF txfm=<a href="/coding/class/classtransformf/#classtransformf_1acb5c27d878efd1962ebed24898457fa3">TransformF::Identity</a>, bool isWorld=false);
304   bool removeNode( const char* name );
305   ///@}
306
307   /// @name Materials
308   ///@{
309   S32 getTargetCount();
310   const char* getTargetName( S32 index );
311   ///@}
312
313   ///@{
314   S32 getObjectCount();
315   const char* getObjectName( S32 index );
316   S32 getObjectIndex( const char* name );
317   const char* getObjectNode( const char* name );
318   bool setObjectNode( const char* objName, const char* nodeName );
319   bool renameObject( const char* oldName, const char* newName );
320   bool removeObject( const char* name );
321   ///@}
322
323   /// @name Meshes
324   ///@{
325   S32 getMeshCount( const char* name );
326   const char* getMeshName( const char* name, S32 index );
327   S32 getMeshSize( const char* name, S32 index );
328   bool setMeshSize( const char* name, S32 size );
329   const char* getMeshType( const char* name );
330   bool setMeshType( const char* name, const char* type );
331   const char* getMeshMaterial( const char* name );
332   bool setMeshMaterial( const char* meshName, const char* matName );
333   bool addMesh( const char* meshName, const char* srcShape, const char* srcMesh );
334   bool addPrimitive( const char* meshName, const char* type, const char* params, TransformF txfm, const char* nodeName );
335   bool removeMesh( const char* name );
336   ///@}
337
338   /// @name Detail Levels
339   ///@{
340   Box3F getBounds();
341   bool setBounds( Box3F bbox );
342   S32 getDetailLevelCount();
343   const char* getDetailLevelName( S32 index );
344   S32 getDetailLevelSize( S32 index);
345   S32 getDetailLevelIndex( S32 size );
346   bool renameDetailLevel( const char* oldName, const char* newName );
347   bool removeDetailLevel( S32 index );
348   S32 setDetailLevelSize( S32 index, S32 newSize );
349   S32 getImposterDetailLevel();
350   const char* getImposterSettings( S32 index );
351   S32 addImposter( S32 size, S32 equatorSteps, S32 polarSteps, S32 dl, S32 dim, bool includePoles, F32 polarAngle );
352   bool removeImposter();
353   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 );
354   ///@}
355
356   /// @name Sequences
357   ///@{
358   S32 getSequenceCount();
359   S32 getSequenceIndex( const char* name);
360   const char* getSequenceName( S32 index );
361   const char* getSequenceSource( const char* name );
362   S32 getSequenceFrameCount( const char* name );
363   F32 getSequencePriority( const char* name );
364   bool setSequencePriority( const char* name, F32 priority );
365   const char* getSequenceGroundSpeed( const char* name );
366   bool setSequenceGroundSpeed( const char* name, Point3F transSpeed, Point3F rotSpeed=<a href="/coding/class/classpoint3f/#classpoint3f_1aeb8504bc663cf40468c4e977aeb96a4c">Point3F::Zero</a> );
367   bool getSequenceCyclic( const char* name );
368   bool setSequenceCyclic( const char* name, bool cyclic );
369   const char* getSequenceBlend( const char* name );
370   bool setSequenceBlend( const char* name, bool blend, const char* blendSeq, S32 blendFrame );
371   bool renameSequence( const char* oldName, const char* newName );
372   bool addSequence( const char* source, const char* name, S32 start=0, S32 end=-1, bool padRot=true, bool padTrans=false );
373   bool removeSequence( const char* name );
374   ///@}
375
376   /// @name Triggers
377   ///@{
378   S32 getTriggerCount( const char* name );
379   const char* getTrigger( const char* name, S32 index );
380   bool addTrigger( const char* name, S32 keyframe, S32 state );
381   bool removeTrigger( const char* name, S32 keyframe, S32 state );
382   ///@}
383};
384
385typedef domUpAxisType TSShapeConstructorUpAxis;
386typedef ColladaUtils::ImportOptions::eLodType TSShapeConstructorLodType;
387
388DefineEnumType( TSShapeConstructorUpAxis );
389DefineEnumType(TSShapeConstructorLodType);
390
391class TSShapeConstructorMethodActionCallback
392{
393   TSShapeConstructor* mObject;
394
395public:
396   TSShapeConstructorMethodActionCallback(TSShapeConstructor *object) : mObject(object) { ; }
397   ~TSShapeConstructorMethodActionCallback() { mObject->onActionPerformed(); }
398};
399
400/* This macro simplifies the definition of a TSShapeConstructor API method. It
401   wraps the actual EngineMethod definition and automatically calls the real
402   class method. It also creates a ChangeSet::Comand (with all arguments stored
403   as strings). The one drawback is that it includes the open brace for the real
404   class method, so to keep the code looking mostly normal, such methods start
405   with another open brace, and end with a double closing brace. Not perfect,
406   but a lot better than having to type out the argument list multiple times for
407   the 50 odd API functions. */
408#define DefineTSShapeConstructorMethod( name, retType, args, defArgs, rawArgs, defRet, usage )  \
409   DefineEngineMethod( TSShapeConstructor, name, retType, args, defArgs, usage )                \
410   {                                                                                            \
411      /* Check that shape is loaded */                                                          \
412      if( !object->getShape() )                                                                 \
413      {                                                                                         \
414         Con::errorf( "TSShapeConstructor::" #name " - shape not loaded" );                     \
415         return defRet;                                                                         \
416      }                                                                                         \
417      TSShapeConstructorMethodActionCallback actionCallback(object);                            \
418      return object->name rawArgs ;                                                             \
419   }                                                                                            \
420   /* Define the real TSShapeConstructor method */                                              \
421   retType TSShapeConstructor::name args                                                        \
422   {                                                                                            \
423      /* Initialise change set command (may or may not be added) */                             \
424      TSShapeConstructor::ChangeSet::Command newCmd( #name );                                   \
425      newCmd.addArgs rawArgs ;                                                                  \
426      TORQUE_UNUSED(newCmd);
427
428
429/* This macro just hides the name of the auto-created ChangeSet::Command from
430   above, so we are free to change the implementation later if needed */
431#define ADD_TO_CHANGE_SET()   mChangeSet.add( newCmd );
432
433
434#endif
435