📄 tsshapeinstance.h
字号:
virtual void render(S32 dl, F32 intraDL = 0.0f, const Point3F * objectScale = NULL);
void renderShadow(S32 dl, const MatrixF & mat, S32 dim, U32 * bits);
static void setupFog(F32 fogAmount, const ColorF & fogColor);
void setupFog(F32 fogAmount, TextureHandle * fogMap, Point4F & s, Point4F & t);
GBitmap * snapshot(U32 width, U32 height, bool mipmap, MatrixF & cameraMatrix, bool hiQuality);
GBitmap * TSShapeInstance::snapshot(U32 width, U32 height, bool mip, MatrixF & cameraPos, S32 dl, F32 intraDL, bool hiQuality);
static GBitmap * snapshot(TSShape *, U32 width, U32 height, bool mipmap, MatrixF & cameraMatrix, S32 dl, F32 intraDL = 0.0f, bool hiQuality = false);
void animate();
void animate(S32 dl);
void animateNodes(S32 ss);
void animateVisibility(S32 ss);
void animateFrame(S32 ss);
void animateMatFrame(S32 ss);
void animateDecals(S32 ss);
void animateIfls();
void animateSubtrees(bool forceFull = true);
void animateNodeSubtrees(bool forceFull = true);
bool hasTranslucency();
bool hasSolid();
/// @name Animation Scale
/// Query about animated scale
/// @{
bool animatesScale() { return (mShape->mFlags & TSShape::AnyScale) != 0; }
bool animatesUniformScale() { return (mShape->mFlags & TSShape::UniformScale) != 0; }
bool animatesAlignedScale() { return (mShape->mFlags & TSShape::AlignedScale) != 0; }
bool animatesArbitraryScale() { return (mShape->mFlags & TSShape::ArbitraryScale) != 0; }
bool scaleCurrentlyAnimated() { return mScaleCurrentlyAnimated; }
/// @}
//
bool inTransition() { return !mTransitionThreads.empty(); }
/// @name Alpha Reflectance Mapping
/// open up mAlphaIsReflectanceMap for custom rendering
/// @{
bool queryAlphaIsReflectanceMap(){ return mAlphaIsReflectanceMap; }
void setAlphaIsReflectanceMap( bool val ){ mAlphaIsReflectanceMap = val; }
/// @}
/// @name Ground Transforms
/// These are hardly ever used. The animator of a model can make the bounding box
/// animate along with the object. Doing so will move the object with the bounding box.
/// The ground transform turns the world bounding box into the post-animation bounding box
/// when such a technique is used. However, few models actually use this technique.
/// @{
void animateGround(); ///< clears previous ground transform
MatrixF & getGroundTransform() { return mGroundTransform; }
void deltaGround(TSThread *, F32 start, F32 end, MatrixF * mat = NULL);
void deltaGround1(TSThread *, F32 start, F32 end, MatrixF& mat);
/// @}
U32 getNumDetails();
S32 getCurrentDetail();
F32 getCurrentIntraDetail();
void setCurrentDetail(S32 dl, F32 intraDL=1.0f);
S32 selectCurrentDetail(bool ignoreScale = false);
S32 selectCurrentDetail(Point3F offset, F32 invScale = 1.0f);
S32 selectCurrentDetail(F32 pixelSize);
S32 selectCurrentDetail2(F32 adjustedDist);
/// fancy detail selection -- uses screen error
S32 selectCurrentDetailEx(bool ignoreScale = false);
S32 selectCurrentDetail2Ex(F32 adjustedDist);
S32 selectCurrentDetailEx(F32 errorTOL);
enum
{
TransformDirty = BIT(0),
VisDirty = BIT(1),
FrameDirty = BIT(2),
MatFrameDirty = BIT(3),
DecalDirty = BIT(4),
IflDirty = BIT(5),
ThreadDirty = BIT(6),
AllDirtyMask = TransformDirty | VisDirty | FrameDirty | MatFrameDirty | DecalDirty | IflDirty | ThreadDirty
};
U32 * mDirtyFlags;
void setDirty(U32 dirty);
void clearDirty(U32 dirty);
//-------------------------------------------------------------------------------------
// collision interface routines
//-------------------------------------------------------------------------------------
public:
bool buildPolyList(AbstractPolyList *, S32 dl);
bool getFeatures(const MatrixF& mat, const Point3F& n, ConvexFeature*, S32 dl);
bool castRay(const Point3F & start, const Point3F & end, RayInfo *,S32 dl);
bool quickLOS(const Point3F & start, const Point3F & end, S32 dl) { return castRay(start,end,NULL,dl); }
Point3F support(const Point3F & v, S32 dl);
void computeBounds(S32 dl, Box3F & bounds); ///< uses current transforms to compute bounding box around a detail level
///< see like named method on shape if you want to use default transforms
//-------------------------------------------------------------------------------------
// Thread Control
//-------------------------------------------------------------------------------------
/// @name Thread Control
/// Threads! In order to animate an object, first you need to have an animation in the object.
/// Then, you need to get the TSShape of the object:
/// @code
/// TSShape* shape = mShapeInstance->getShape());
/// @endcode
/// Next, get the sequence and store::
/// @code
/// S32 seq = shape->findSequence("foo"));
/// @endcode
/// Create a new thread (if needed):
/// @code
/// TSThread* thread = mShapeInstance->addThread();
/// @endcode
/// Finally, set the position in the sequence:
/// @code
/// mShapeInstance->setSequence(thread, seq, 0)
/// @endcode
/// @{
public:
TSThread * addThread(); ///< Create a new thread
TSThread * getThread(S32 threadNumber); ///< @note threads can change order, best to hold
///< onto a thread from the start
void destroyThread(TSThread * thread); ///< Destroy a thread!
U32 threadCount(); ///< How many threads are there?
void setSequence(TSThread *, S32 seq, F32 pos);///< Get the thread a sequence
/// Transition to a sequence
void transitionToSequence(TSThread *, S32 seq, F32 pos, F32 duration, bool continuePlay);
void clearTransition(TSThread *); ///< Stop transitions
U32 getSequence(TSThread *); ///< Get the sequence of the thread
void setBlendEnabled(TSThread *, bool blendOn);///< Set whether or not the thread will blend
bool getBlendEnabled(TSThread *); ///< Does this thread blend?
F32 getTime(TSThread * thread); ///< Get how long the thread has been playing
F32 getPos(TSThread * thread); ///< Get the position in the thread
void setTime(TSThread * thread, F32 time); ///< Set how long into the thread to use
void setPos(TSThread * thread, F32 pos); ///< Set the position of the thread
bool isInTransition(TSThread * thread); ///< Is this thread in transition?
F32 getTimeScale(TSThread * thread); ///< Get the time scale of the thread
void setTimeScale(TSThread * thread, F32); ///< Set the time scale of the thread
F32 getDuration(TSThread * thread); ///< Get the duration of the thread
F32 getScaledDuration(TSThread * thread); ///< Get the duration of the thread with the scale factored in
S32 getKeyframeCount(TSThread * thread); ///< Get the number of keyframes
S32 getKeyframeNumber(TSThread * thread); ///< Get which keyframe the thread is on
/// Set which keyframe the thread is on
void setKeyframeNumber(TSThread * thread, S32 kf);
void advanceTime(F32 delta, TSThread *); ///< advance time on a particular thread
void advanceTime(F32 delta); ///< advance time on all threads
void advancePos(F32 delta, TSThread *); ///< advance pos on a particular thread
void advancePos(F32 delta); ///< advance pos on all threads
/// @}
//-------------------------------------------------------------------------------------
// constructors, destructors, initialization, io
//-------------------------------------------------------------------------------------
TSShapeInstance( const Resource<TSShape> & shape, bool loadMaterials = true);
TSShapeInstance( TSShape * pShape, bool loadMaterials = true);
~TSShapeInstance();
void buildInstanceData(TSShape *, bool loadMaterials);
void dump(Stream &);
void dumpNode(Stream &, S32 level, S32 nodeIndex, Vector<S32> & detailSizes);
void dumpDecals(Stream &, S32 indent, MeshObjectInstance *);
void *mData; ///< available for use by app...initialized to 0
};
inline MatrixF * TSShapeInstance::ObjectInstance::getTransform()
{
return nodeIndex<0 ? NULL : smTransforms + nodeIndex;
}
//-------------------------------------------------------------------------------------
// Thread class
//-------------------------------------------------------------------------------------
/// 3space animation thread.
///
/// An animation thread: runtime data associated with a single sequence that is
/// running (or two sequences if in transition between them).
///
/// A shape instance can have multiple threads running. When multiple threads are running,
/// which thread/sequence controls which node or object is determined based
/// on priority of the sequence.
///
/// @note all thread data and methods are private (but TSShapeInstance is a friend).
/// Users should treat thread pointers like keys -- they are used to ID
/// the thread when interfacing with the shape, but are not manipulated
/// by anything but the TSShapeInstance. See "Thread control" methods
/// for more info on controlling threads.
class TSThread
{
friend class TSShapeInstance;
S32 priority;
TSShapeInstance * mShapeInstance; ///< Instance of the shape that this thread animates
const TSSequence * sequence; ///< Sequence this thread will perform
F32 pos;
F32 timeScale; ///< How fast to play through the sequence
S32 keyNum1; ///< Keyframe at or before current position
S32 keyNum2; ///< Keyframe at or after current position
F32 keyPos;
bool blendDisabled; ///< Blend with other sequences?
/// if in transition...
struct TransitionData
{
bool inTransition;
F32 duration;
F32 pos;
F32 direction;
F32 targetScale; ///< time scale for sequence we are transitioning to (during transition only)
///< this is either 1 or 0 (if 1 target sequence plays as we transition, if 0 it doesn't)
TSIntegerSet oldRotationNodes; ///< nodes controlled by this thread pre-transition
TSIntegerSet oldTranslationNodes; ///< nodes controlled by this thread pre-transition
TSIntegerSet oldScaleNodes; ///< nodes controlled by this thread pre-transition
U32 oldSequence; ///< sequence that was set before transition began
F32 oldPos; ///< position of sequence before transition began
} transitionData;
struct
{
F32 start;
F32 end;
S32 loop;
} path;
bool makePath;
/// given a position on the thread, choose correct keyframes
/// slight difference between one-shot and cyclic sequences -- see comments below for details
void selectKeyframes(F32 pos, const TSSequence * seq, S32 * k1, S32 * k2, F32 * kpos);
void getGround(F32 p, MatrixF * pMat);
/// @name Triggers
/// Triggers are used to do something once a certain animation point has been reached.
///
/// For example, when the player's foot animation hits the ground, a foot puff and
/// foot print are triggered from the thread.
///
/// These are called by advancePos()
/// @{
void animateTriggers();
void activateTriggers(F32 a, F32 b);
/// @}
// methods -- accessible through shape only
void setSequence(S32 seq, F32 pos);
void transitionToSequence(S32 seq, F32 pos, F32 duration, bool continuePlay);
void advanceTime(F32 delta);
void advancePos(F32 delta);
F32 getTime();
F32 getPos();
void setTime(F32);
void setPos(F32);
bool isInTransition();
F32 getTimeScale();
void setTimeScale(F32);
F32 getDuration();
F32 getScaledDuration();
S32 getKeyframeCount();
S32 getKeyframeNumber();
void setKeyframeNumber(S32 kf);
TSThread(TSShapeInstance*);
TSThread() {}
public:
S32 operator<(const TSThread &) const;
};
typedef TSShapeInstance::ObjectInstance TSObjectInstance;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -