tsShape.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TSSHAPE_H_
  23. #define _TSSHAPE_H_
  24. #ifndef _TSMESH_H_
  25. #include "ts/tsMesh.h"
  26. #endif
  27. #ifndef _TSINTEGERSET_H_
  28. #include "ts/tsIntegerSet.h"
  29. #endif
  30. #ifndef _TSTRANSFORM_H_
  31. #include "ts/tsTransform.h"
  32. #endif
  33. #ifndef _TSSHAPEALLOC_H_
  34. #include "ts/tsShapeAlloc.h"
  35. #endif
  36. #define DTS_EXPORTER_CURRENT_VERSION 124
  37. class TSMaterialList;
  38. class TSLastDetail;
  39. class PhysicsCollision;
  40. //
  41. struct CollisionShapeInfo
  42. {
  43. S32 colNode;
  44. PhysicsCollision *colShape;
  45. };
  46. /// TSShape stores generic data for a 3space model.
  47. ///
  48. /// TSShape and TSShapeInstance act in conjunction to allow the rendering and
  49. /// manipulation of a three dimensional model.
  50. ///
  51. /// @note The material lists are the only thing that is not loaded in TSShape.
  52. /// instead, they are loaded in TSShapeInstance because of a former restriction
  53. /// on the resource manager where only one file could be opened at a time.
  54. /// The resource manager restriction has been resolved, but the material
  55. /// lists are still loaded in TSShapeInstance.
  56. ///
  57. /// @see TSShapeInstance for a further discussion of the 3space system.
  58. class TSShape
  59. {
  60. public:
  61. enum
  62. {
  63. UniformScale = BIT(0),
  64. AlignedScale = BIT(1),
  65. ArbitraryScale = BIT(2),
  66. Blend = BIT(3),
  67. Cyclic = BIT(4),
  68. MakePath = BIT(5),
  69. HasTranslucency= BIT(6),
  70. AnyScale = UniformScale | AlignedScale | ArbitraryScale
  71. };
  72. /// Nodes hold the transforms in the shape's tree. They are the bones of the skeleton.
  73. struct Node
  74. {
  75. S32 nameIndex;
  76. S32 parentIndex;
  77. // computed at runtime
  78. S32 firstObject;
  79. S32 firstChild;
  80. S32 nextSibling;
  81. };
  82. /// Objects hold renderable items (in particular meshes).
  83. ///
  84. /// Each object has a number of meshes associated with it.
  85. /// Each mesh corresponds to a different detail level.
  86. ///
  87. /// meshIndicesIndex points to numMeshes consecutive indices
  88. /// into the meshList and meshType vectors. It indexes the
  89. /// meshIndexList vector (meshIndexList is merely a clearinghouse
  90. /// for the object's mesh lists). Some indices may correspond to
  91. /// no mesh -- which means no mesh will be drawn for the part for
  92. /// the given detail level. See comments on the meshIndexList
  93. /// for how null meshes are coded.
  94. ///
  95. /// @note Things are stored this way so that there are no pointers.
  96. /// This makes serialization to disk dramatically simpler.
  97. struct Object
  98. {
  99. S32 nameIndex;
  100. S32 numMeshes;
  101. S32 startMeshIndex; ///< Index into meshes array.
  102. S32 nodeIndex;
  103. // computed at load
  104. S32 nextSibling;
  105. S32 firstDecal; // DEPRECATED
  106. };
  107. /// A Sequence holds all the information necessary to perform a particular animation (sequence).
  108. ///
  109. /// Sequences index a range of keyframes. Keyframes are assumed to be equally spaced in time.
  110. ///
  111. /// Each node and object is either a member of the sequence or not. If not, they are set to
  112. /// default values when we switch to the sequence unless they are members of some other active sequence.
  113. /// Blended sequences "add" a transform to the current transform of a node. Any object animation of
  114. /// a blended sequence over-rides any existing object state. Blended sequences are always
  115. /// applied after non-blended sequences.
  116. struct Sequence
  117. {
  118. S32 nameIndex;
  119. S32 numKeyframes;
  120. F32 duration;
  121. S32 baseRotation;
  122. S32 baseTranslation;
  123. S32 baseScale;
  124. S32 baseObjectState;
  125. S32 baseDecalState; // DEPRECATED
  126. S32 firstGroundFrame;
  127. S32 numGroundFrames;
  128. S32 firstTrigger;
  129. S32 numTriggers;
  130. F32 toolBegin;
  131. /// @name Bitsets
  132. /// These bitsets code whether this sequence cares about certain aspects of animation
  133. /// e.g., the rotation, translation, or scale of node transforms,
  134. /// or the visibility, frame or material frame of objects.
  135. /// @{
  136. TSIntegerSet rotationMatters; ///< Set of nodes
  137. TSIntegerSet translationMatters; ///< Set of nodes
  138. TSIntegerSet scaleMatters; ///< Set of nodes
  139. TSIntegerSet visMatters; ///< Set of objects
  140. TSIntegerSet frameMatters; ///< Set of objects
  141. TSIntegerSet matFrameMatters; ///< Set of objects
  142. /// @}
  143. S32 priority;
  144. U32 flags;
  145. U32 dirtyFlags; ///< determined at load time
  146. /// @name Source Data
  147. /// Store some information about where the sequence data came from (used by
  148. /// TSShapeConstructor and the Shape Editor)
  149. /// @{
  150. struct SeqSourceData
  151. {
  152. String from; // The source sequence (ie. a DSQ file)
  153. S32 start; // The first frame in the source sequence
  154. S32 end; // The last frame in the source sequence
  155. S32 total; // The total number of frames in the source sequence
  156. String blendSeq; // The blend reference sequence
  157. S32 blendFrame; // The blend reference frame
  158. SeqSourceData() : from("\t"), start(0), end(0), total(0), blendSeq(""), blendFrame(0) { }
  159. } sourceData;
  160. /// @name Flag Tests
  161. /// Each of these tests a different flag against the object's flag list
  162. /// to determine the attributes of the given object.
  163. /// @{
  164. bool testFlags(U32 comp) const { return (flags&comp)!=0; }
  165. bool animatesScale() const { return testFlags(AnyScale); }
  166. bool animatesUniformScale() const { return testFlags(UniformScale); }
  167. bool animatesAlignedScale() const { return testFlags(AlignedScale); }
  168. bool animatesArbitraryScale() const { return testFlags(ArbitraryScale); }
  169. bool isBlend() const { return testFlags(Blend); }
  170. bool isCyclic() const { return testFlags(Cyclic); }
  171. bool makePath() const { return testFlags(MakePath); }
  172. /// @}
  173. /// @name IO
  174. /// @{
  175. void read(Stream *, bool readNameIndex = true);
  176. void write(Stream *, bool writeNameIndex = true) const;
  177. /// @}
  178. };
  179. /// Describes state of an individual object. Includes everything in an object that can be
  180. /// controlled by animation.
  181. struct ObjectState
  182. {
  183. F32 vis;
  184. S32 frameIndex;
  185. S32 matFrameIndex;
  186. };
  187. /// When time on a sequence advances past a certain point, a trigger takes effect and changes
  188. /// one of the state variables to on or off. (State variables found in TSShapeInstance::mTriggerStates)
  189. struct Trigger
  190. {
  191. enum TriggerStates
  192. {
  193. StateOn = BIT(31),
  194. InvertOnReverse = BIT(30),
  195. StateMask = BIT(30)-1
  196. };
  197. U32 state; ///< One of TriggerStates
  198. F32 pos;
  199. };
  200. /// Details are used for render detail selection.
  201. ///
  202. /// As the projected size of the shape changes,
  203. /// a different node structure can be used (subShape) and a different objectDetail can be selected
  204. /// for each object drawn. Either of these two parameters can also stay constant, but presumably
  205. /// not both. If size is negative then the detail level will never be selected by the standard
  206. /// detail selection process. It will have to be selected by name. Such details are "utility
  207. /// details" because they exist to hold data (node positions or collision information) but not
  208. /// normally to be drawn. By default there will always be a "Ground" utility detail.
  209. ///
  210. /// Note that this struct should always be 32bit aligned
  211. /// as its required by assembleShape/disassembleShape.
  212. struct Detail
  213. {
  214. S32 nameIndex;
  215. S32 subShapeNum;
  216. S32 objectDetailNum;
  217. F32 size;
  218. F32 averageError;
  219. F32 maxError;
  220. S32 polyCount;
  221. /// These values are new autobillboard settings stored
  222. /// as part of the Detail struct in version 26 and above.
  223. /// @{
  224. S32 bbDimension; ///< The size of the autobillboard image.
  225. S32 bbDetailLevel; ///< The detail to render as the autobillboard.
  226. U32 bbEquatorSteps; ///< The number of autobillboard images to capture around the equator.
  227. U32 bbPolarSteps; ///< The number of autobillboard images to capture along the pole.
  228. F32 bbPolarAngle; ///< The angle in radians at which the top/bottom autobillboard images should be displayed.
  229. U32 bbIncludePoles; ///< If non-zero then top and bottom images are generated for the autobillboard.
  230. /// @}
  231. };
  232. /// @name Collision Accelerators
  233. ///
  234. /// For speeding up buildpolylist and support calls.
  235. /// @{
  236. struct ConvexHullAccelerator {
  237. S32 numVerts;
  238. Point3F* vertexList;
  239. Point3F* normalList;
  240. U8** emitStrings;
  241. };
  242. ConvexHullAccelerator* getAccelerator(S32 dl);
  243. /// @}
  244. /// @name Shape Vector Data
  245. /// @{
  246. Vector<Node> nodes;
  247. Vector<Object> objects;
  248. Vector<ObjectState> objectStates;
  249. Vector<S32> subShapeFirstNode;
  250. Vector<S32> subShapeFirstObject;
  251. Vector<S32> detailFirstSkin;
  252. Vector<S32> subShapeNumNodes;
  253. Vector<S32> subShapeNumObjects;
  254. Vector<Detail> details;
  255. Vector<Quat16> defaultRotations;
  256. Vector<Point3F> defaultTranslations;
  257. /// @}
  258. /// These are set up at load time, but memory is allocated along with loaded data
  259. /// @{
  260. Vector<S32> subShapeFirstTranslucentObject;
  261. Vector<TSMesh*> meshes;
  262. /// @}
  263. /// @name Alpha Vectors
  264. /// these vectors describe how to transition between detail
  265. /// levels using alpha. "alpha-in" next detail as intraDL goes
  266. /// from alphaIn+alphaOut to alphaOut. "alpha-out" current
  267. /// detail level as intraDL goes from alphaOut to 0.
  268. /// @note
  269. /// - intraDL is at 1 when if shape were any closer to us we'd be at dl-1
  270. /// - intraDL is at 0 when if shape were any farther away we'd be at dl+1
  271. /// @{
  272. Vector<F32> alphaIn;
  273. Vector<F32> alphaOut
  274. ;
  275. /// @}
  276. /// @name Resizeable vectors
  277. /// @{
  278. Vector<Sequence> sequences;
  279. Vector<Quat16> nodeRotations;
  280. Vector<Point3F> nodeTranslations;
  281. Vector<F32> nodeUniformScales;
  282. Vector<Point3F> nodeAlignedScales;
  283. Vector<Quat16> nodeArbitraryScaleRots;
  284. Vector<Point3F> nodeArbitraryScaleFactors;
  285. Vector<Quat16> groundRotations;
  286. Vector<Point3F> groundTranslations;
  287. Vector<Trigger> triggers;
  288. Vector<TSLastDetail*> billboardDetails;
  289. Vector<ConvexHullAccelerator*> detailCollisionAccelerators;
  290. Vector<String> names;
  291. /// @}
  292. TSMaterialList * materialList;
  293. /// @name Bounding
  294. /// @{
  295. F32 radius;
  296. F32 tubeRadius;
  297. Point3F center;
  298. Box3F bounds;
  299. /// @}
  300. // various...
  301. U32 mExporterVersion;
  302. F32 mSmallestVisibleSize; ///< Computed at load time from details vector.
  303. S32 mSmallestVisibleDL; ///< @see mSmallestVisibleSize
  304. S32 mReadVersion; ///< File version that this shape was read from.
  305. U32 mFlags; ///< hasTranslucancy
  306. U32 data; ///< User-defined data storage.
  307. /// If enabled detail selection will use the
  308. /// legacy screen error method for lod.
  309. /// @see setDetailFromScreenError
  310. bool mUseDetailFromScreenError;
  311. // TODO: This would be nice as Tuple<>
  312. struct LodPair
  313. {
  314. S8 level; // -1 to 128
  315. U8 intra; // encoded 0 to 1
  316. inline void set( S32 dl, F32 intraDL )
  317. {
  318. level = (S8)dl;
  319. intra = (S8)( intraDL * 255.0f );
  320. }
  321. inline void get( S32 &dl, F32 &intraDL )
  322. {
  323. dl = level;
  324. intraDL = (F32)intra / 255.0f;
  325. }
  326. };
  327. /// The lod lookup table where we mark down the detail
  328. /// level and intra-detail level for each pixel size.
  329. Vector<LodPair> mDetailLevelLookup;
  330. /// The GFX vertex format for all detail meshes in the shape.
  331. /// @see initVertexFeatures()
  332. GFXVertexFormat mVertexFormat;
  333. /// The GFX vertex size in bytes for all detail meshes in the shape.
  334. /// @see initVertexFeatures()
  335. U32 mVertSize;
  336. /// Is true if this shape contains skin meshes.
  337. bool mHasSkinMesh;
  338. bool mSequencesConstructed;
  339. S8* mShapeData;
  340. U32 mShapeDataSize;
  341. // shape class has few methods --
  342. // just constructor/destructor, io, and lookup methods
  343. // constructor/destructor
  344. TSShape();
  345. ~TSShape();
  346. void init();
  347. void initMaterialList(); ///< you can swap in a new material list, but call this if you do
  348. bool preloadMaterialList(const Torque::Path &path); ///< called to preload and validate the materials in the mat list
  349. void setupBillboardDetails( const String &cachePath );
  350. /// Called from init() to calcuate the GFX vertex features for
  351. /// all detail meshes in the shape.
  352. void initVertexFeatures();
  353. bool getSequencesConstructed() const { return mSequencesConstructed; }
  354. void setSequencesConstructed(const bool c) { mSequencesConstructed = c; }
  355. /// @name Lookup Animation Info
  356. /// indexed by keyframe number and offset (which object/node/decal
  357. /// of the animated objects/nodes/decals you want information for).
  358. /// @{
  359. QuatF & getRotation(const Sequence & seq, S32 keyframeNum, S32 rotNum, QuatF *) const;
  360. const Point3F & getTranslation(const Sequence & seq, S32 keyframeNum, S32 tranNum) const;
  361. F32 getUniformScale(const Sequence & seq, S32 keyframeNum, S32 scaleNum) const;
  362. const Point3F & getAlignedScale(const Sequence & seq, S32 keyframeNum, S32 scaleNum) const;
  363. TSScale & getArbitraryScale(const Sequence & seq, S32 keyframeNum, S32 scaleNum, TSScale *) const;
  364. const ObjectState & getObjectState(const Sequence & seq, S32 keyframeNum, S32 objectNum) const;
  365. /// @}
  366. /// build LOS collision detail
  367. void computeAccelerator(S32 dl);
  368. bool buildConvexHull(S32 dl) const;
  369. void computeBounds(S32 dl, Box3F & bounds) const; // uses default transforms to compute bounding box around a detail level
  370. // see like named method on shapeInstance if you want to use animated transforms
  371. /// Used to find collision detail meshes in the DTS.
  372. ///
  373. /// @param useVisibleMesh If true return the highest visible detail level.
  374. /// @param outDetails The output detail index vector.
  375. /// @param outLOSDetails The optional output LOS detail vector.
  376. ///
  377. void findColDetails( bool useVisibleMesh, Vector<S32> *outDetails, Vector<S32> *outLOSDetails ) const;
  378. /// Builds a physics collision shape at the requested scale.
  379. ///
  380. /// If using the visible mesh one or more triangle meshes are created
  381. /// from the first visible detail level.
  382. ///
  383. /// If using collision meshes we look for mesh names prefixed with the
  384. /// following hints:
  385. //
  386. /// "colbox"
  387. /// "colsphere"
  388. /// "colcapsule"
  389. /// "colmesh"
  390. ///
  391. /// In the case of the primitives the mesh bounding box is used to generate
  392. /// a box, sphere, or capsule collision shape. The "colmesh" will create a
  393. /// concave triangle mesh for collision.
  394. ///
  395. /// Any other named collision shape is interpreted as a regular convex hull.
  396. ///
  397. /// @return The collision object or NULL if no collision data could be generated.
  398. ///
  399. PhysicsCollision* buildColShape( bool useVisibleMesh, const Point3F &scale );
  400. /// Like buildColShape except we build one PhysicsCollision object per
  401. /// collision node.
  402. ///
  403. /// Results are returned by filling in the CollisionShapeInfo Vector, which also
  404. /// specifies the collision node index for each PhysicsCollision built.
  405. ///
  406. void buildColShapes( bool useVisibleMesh, const Point3F &scale, Vector< CollisionShapeInfo > *list );
  407. /// For internal use.
  408. PhysicsCollision* _buildColShapes( bool useVisibleMesh, const Point3F &scale, Vector< CollisionShapeInfo > *list, bool perMesh );
  409. /// @name Lookup Methods
  410. /// @{
  411. /// Returns index into the name vector that equals the passed name.
  412. S32 findName( const String &name ) const;
  413. /// Returns name string at the passed name vector index.
  414. const String& getName( S32 nameIndex ) const;
  415. /// Returns name string for mesh at the passed index.
  416. const String& getMeshName( S32 meshIndex ) const;
  417. /// Returns name string for node at the passed index.
  418. const String& getNodeName( S32 nodeIndex ) const;
  419. /// Returns name string for sequence at the passed index.
  420. const String& getSequenceName( S32 seqIndex ) const;
  421. S32 getTargetCount() const;
  422. const String& getTargetName( S32 mapToNameIndex ) const;
  423. S32 findNode(S32 nameIndex) const;
  424. S32 findNode(const String &name) const { return findNode(findName(name)); }
  425. S32 findObject(S32 nameIndex) const;
  426. S32 findObject(const String &name) const { return findObject(findName(name)); }
  427. S32 findDetail(S32 nameIndex) const;
  428. S32 findDetail(const String &name) const { return findDetail(findName(name)); }
  429. S32 findDetailBySize(S32 size) const;
  430. S32 findSequence(S32 nameIndex) const;
  431. S32 findSequence(const String &name) const { return findSequence(findName(name)); }
  432. S32 getSubShapeForNode(S32 nodeIndex);
  433. S32 getSubShapeForObject(S32 objIndex);
  434. void getSubShapeDetails(S32 subShapeIndex, Vector<S32>& validDetails);
  435. void getNodeWorldTransform(S32 nodeIndex, MatrixF* mat) const;
  436. void getNodeKeyframe(S32 nodeIndex, const TSShape::Sequence& seq, S32 keyframe, MatrixF* mat) const;
  437. void getNodeObjects(S32 nodeIndex, Vector<S32>& nodeObjects);
  438. void getNodeChildren(S32 nodeIndex, Vector<S32>& nodeChildren);
  439. void getObjectDetails(S32 objIndex, Vector<S32>& objDetails);
  440. bool findMeshIndex(const String &meshName, S32& objIndex, S32& meshIndex);
  441. TSMesh* findMesh(const String &meshName);
  442. bool hasTranslucency() const { return (mFlags & HasTranslucency)!=0; }
  443. const GFXVertexFormat* getVertexFormat() const { return &mVertexFormat; }
  444. U32 getVertexSize() const { return mVertSize; }
  445. /// @}
  446. /// @name Alpha Transitions
  447. /// These control default values for alpha transitions between detail levels
  448. /// @{
  449. static F32 smAlphaOutLastDetail;
  450. static F32 smAlphaInBillboard;
  451. static F32 smAlphaOutBillboard;
  452. static F32 smAlphaInDefault;
  453. static F32 smAlphaOutDefault;
  454. /// @}
  455. /// don't load this many of the highest detail levels (although we always
  456. /// load one renderable detail if there is one)
  457. static S32 smNumSkipLoadDetails;
  458. /// by default we initialize shape when we read...
  459. static bool smInitOnRead;
  460. /// @name Version Info
  461. /// @{
  462. /// Most recent version...the one we write
  463. static S32 smVersion;
  464. /// Version currently being read, only valid during read
  465. static S32 smReadVersion;
  466. static const U32 smMostRecentExporterVersion;
  467. ///@}
  468. /// @name Persist Methods
  469. /// Methods for saving/loading shapes to/from streams
  470. /// @{
  471. bool canWriteOldFormat() const;
  472. void write(Stream *, bool saveOldFormat=false);
  473. bool read(Stream *);
  474. void readOldShape(Stream * s, S32 * &, S16 * &, S8 * &, S32 &, S32 &, S32 &);
  475. void writeName(Stream *, S32 nameIndex);
  476. S32 readName(Stream *, bool addName);
  477. /// Initializes our TSShape to be ready to receive put mesh data
  478. void createEmptyShape();
  479. void exportSequences(Stream *);
  480. void exportSequence(Stream * s, const TSShape::Sequence& seq, bool saveOldFormat);
  481. bool importSequences(Stream *, const String& sequencePath);
  482. /// @}
  483. /// @name Persist Helper Functions
  484. /// @{
  485. static TSShapeAlloc smTSAlloc;
  486. void fixEndian(S32 *, S16 *, S8 *, S32, S32, S32);
  487. /// @}
  488. /// @name Memory Buffer Transfer Methods
  489. /// uses TSShape::Alloc structure
  490. /// @{
  491. void assembleShape();
  492. void disassembleShape();
  493. ///@}
  494. /// mem buffer transfer helper (indicate when we don't want to include a particular mesh/decal)
  495. bool checkSkip(S32 meshNum, S32 & curObject, S32 skipDL);
  496. void fixupOldSkins(S32 numMeshes, S32 numSkins, S32 numDetails, S32 * detFirstSkin, S32 * detailNumSkins);
  497. /// @name Shape Editing
  498. /// @{
  499. S32 addName(const String& name);
  500. bool removeName(const String& name);
  501. void updateSmallestVisibleDL();
  502. S32 addDetail(const String& dname, S32 size, S32 subShapeNum);
  503. S32 addImposter( const String& cachePath,
  504. S32 size,
  505. S32 numEquatorSteps,
  506. S32 numPolarSteps,
  507. S32 dl,
  508. S32 dim,
  509. bool includePoles,
  510. F32 polarAngle );
  511. bool removeImposter();
  512. bool renameNode(const String& oldName, const String& newName);
  513. bool renameObject(const String& oldName, const String& newName);
  514. bool renameDetail(const String& oldName, const String& newName);
  515. bool renameSequence(const String& oldName, const String& newName);
  516. bool setNodeTransform(const String& name, const Point3F& pos, const QuatF& rot);
  517. bool addNode(const String& name, const String& parentName, const Point3F& pos, const QuatF& rot);
  518. bool removeNode(const String& name);
  519. S32 addObject(const String& objName, S32 subShapeIndex);
  520. void addMeshToObject(S32 objIndex, S32 meshIndex, TSMesh* mesh);
  521. void removeMeshFromObject(S32 objIndex, S32 meshIndex);
  522. bool setObjectNode(const String& objName, const String& nodeName);
  523. bool removeObject(const String& objName);
  524. TSMesh* copyMesh( const TSMesh* srcMesh ) const;
  525. bool addMesh(TSShape* srcShape, const String& srcMeshName, const String& meshName);
  526. bool addMesh(TSMesh* mesh, const String& meshName);
  527. bool setMeshSize(const String& meshName, S32 size);
  528. bool removeMesh(const String& meshName);
  529. S32 setDetailSize(S32 oldSize, S32 newSize);
  530. bool removeDetail(S32 size);
  531. bool addSequence(const Torque::Path& path, const String& fromSeq, const String& name, S32 startFrame, S32 endFrame, bool padRotKeys, bool padTransKeys);
  532. bool removeSequence(const String& name);
  533. bool addTrigger(const String& seqName, S32 keyframe, S32 state);
  534. bool removeTrigger(const String& seqName, S32 keyframe, S32 state);
  535. bool setSequenceBlend(const String& seqName, bool blend, const String& blendRefSeqName, S32 blendRefFrame);
  536. bool setSequenceGroundSpeed(const String& seqName, const Point3F& trans, const Point3F& rot);
  537. /// @}
  538. };
  539. #define TSNode TSShape::Node
  540. #define TSObject TSShape::Object
  541. #define TSSequence TSShape::Sequence
  542. #define TSDetail TSShape::Detail
  543. inline QuatF & TSShape::getRotation(const Sequence & seq, S32 keyframeNum, S32 rotNum, QuatF * quat) const
  544. {
  545. return nodeRotations[seq.baseRotation + rotNum*seq.numKeyframes + keyframeNum].getQuatF(quat);
  546. }
  547. inline const Point3F & TSShape::getTranslation(const Sequence & seq, S32 keyframeNum, S32 tranNum) const
  548. {
  549. return nodeTranslations[seq.baseTranslation + tranNum*seq.numKeyframes + keyframeNum];
  550. }
  551. inline F32 TSShape::getUniformScale(const Sequence & seq, S32 keyframeNum, S32 scaleNum) const
  552. {
  553. return nodeUniformScales[seq.baseScale + scaleNum*seq.numKeyframes + keyframeNum];
  554. }
  555. inline const Point3F & TSShape::getAlignedScale(const Sequence & seq, S32 keyframeNum, S32 scaleNum) const
  556. {
  557. return nodeAlignedScales[seq.baseScale + scaleNum*seq.numKeyframes + keyframeNum];
  558. }
  559. inline TSScale & TSShape::getArbitraryScale(const Sequence & seq, S32 keyframeNum, S32 scaleNum, TSScale * scale) const
  560. {
  561. nodeArbitraryScaleRots[seq.baseScale + scaleNum*seq.numKeyframes + keyframeNum].getQuatF(&scale->mRotate);
  562. scale->mScale = nodeArbitraryScaleFactors[seq.baseScale + scaleNum*seq.numKeyframes + keyframeNum];
  563. return *scale;
  564. }
  565. inline const TSShape::ObjectState & TSShape::getObjectState(const Sequence & seq, S32 keyframeNum, S32 objectNum) const
  566. {
  567. return objectStates[seq.baseObjectState + objectNum*seq.numKeyframes + keyframeNum];
  568. }
  569. #endif