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