tsPartInstance.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 _TSPARTINSTANCE_H_
  23. #define _TSPARTINSTANCE_H_
  24. #ifndef _TSSHAPEINSTANCE_H_
  25. #include "ts/tsShapeInstance.h"
  26. #endif
  27. class TSPartInstance
  28. {
  29. /// TSPartInstance assumes ownership (or shared ownership) of the source shape. This means that the source
  30. /// shape cannot be deleted so long as the part instance is still around. This also means that any change
  31. /// to source shapes's transforms or other animation properties will affect how the part instance displays.
  32. /// It is ok (even expected), however, to have many part instances accessing the same shape.
  33. TSShapeInstance * mSourceShape;
  34. /// @name Bounding info
  35. /// @{
  36. Box3F mBounds;
  37. Point3F mCenter;
  38. F32 mRadius;
  39. /// @}
  40. /// detail selection uses the table pointed to by this member
  41. ///
  42. /// if this member is blank, then it uses source shape to determine detail...
  43. ///
  44. /// detail 0 draws up until size of shape is less than mSizeCutoffs[0], detail 1 until mSizeCutoffs[1], etc.
  45. F32 * mSizeCutoffs;
  46. S32 * mPolyCount;
  47. S32 mNumDetails;
  48. /// @name Detail Levels
  49. /// detail levels on part instance correspond directly
  50. /// to object details on objects -- this is different
  51. /// from shape instances where dl corresponds to a
  52. /// subtree number and object detail. The reason
  53. /// for this is that partinstances are derived from
  54. /// a single subtree of a shape instance, so the subtree
  55. /// is implied (implied by which objects are in the part instance)...
  56. /// @{
  57. S32 mCurrentObjectDetail;
  58. F32 mCurrentIntraDL;
  59. /// @}
  60. Vector<TSShapeInstance::MeshObjectInstance*> mMeshObjects;
  61. static MRandomR250 smRandom;
  62. void addObject(S32 objectIndex);
  63. void updateBounds();
  64. void renderDetailMap(S32 od);
  65. void renderEnvironmentMap(S32 od);
  66. void renderFog(S32 od);
  67. void init(TSShapeInstance *);
  68. static void breakShape(TSShapeInstance *, TSPartInstance *, S32 currentNode,
  69. Vector<TSPartInstance*> & partList, F32 * probShatter,
  70. F32 * probBreak, S32 probDepth);
  71. /// @name Private Detail Selection Methods
  72. /// @{
  73. void selectCurrentDetail(F32 * sizeCutoffs, S32 numDetails, bool ignoreScale);
  74. void selectCurrentDetail(F32 pixelSize, F32 * sizeCutoffs, S32 numDetails);
  75. void computePolyCount();
  76. /// @}
  77. public:
  78. TSPartInstance(TSShapeInstance * source);
  79. TSPartInstance(TSShapeInstance * source, S32 objectIndex);
  80. ~TSPartInstance();
  81. const TSShape * getShape() { return mSourceShape->getShape(); }
  82. TSShapeInstance * getSourceShapeInstance(){ return mSourceShape; }
  83. static void breakShape(TSShapeInstance *, S32 subShape, Vector<TSPartInstance*> & partList, F32 * probShatter, F32 * probBreak, S32 probDepth);
  84. Point3F & getCenter() { return mCenter; }
  85. Box3F & getBounds() { return mBounds; }
  86. F32 & getRadius() { return mRadius; }
  87. void render( const TSRenderState &rdata ) { render( mCurrentObjectDetail, rdata ); }
  88. void render( S32 dl, const TSRenderState &rdata );
  89. /// choose detail method -- pass in NULL for first parameter to just use shapes data
  90. void setDetailData(F32 * sizeCutoffs, S32 numDetails);
  91. /// @name Detail Selection
  92. /// @{
  93. /*
  94. void selectCurrentDetail(bool ignoreScale = false);
  95. void selectCurrentDetail(F32 pixelSize);
  96. void selectCurrentDetail2(F32 adjustedDist);
  97. */
  98. /// @}
  99. /// @name Detail Information Accessors
  100. /// @{
  101. F32 getDetailSize( S32 dl ) const;
  102. S32 getPolyCount( S32 dl );
  103. S32 getNumDetails() const { return mSizeCutoffs ? mNumDetails : mSourceShape->getShape()->mSmallestVisibleDL+1; }
  104. S32 getCurrentObjectDetail() const { return mCurrentObjectDetail; }
  105. void setCurrentObjectDetail(S32 od) { mCurrentObjectDetail = od; }
  106. F32 getCurrentIntraDetail() const { return mCurrentIntraDL; }
  107. void setCurrentIntraDetail(F32 intra) { mCurrentIntraDL = intra; }
  108. /// @}
  109. void *mData; ///< for use by app
  110. };
  111. #endif