📄 tsshapeinstance.h
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#ifndef _TSSHAPEINSTANCE_H_
#define _TSSHAPEINSTANCE_H_
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#endif
#ifndef _TSSHAPE_H_
#include "ts/tsShape.h"
#endif
#ifndef _TSINTEGERSET_H_
#include "ts/tsIntegerSet.h"
#endif
#ifndef _CONSOLE_H_
#include "console/console.h"
#endif
#ifndef _GBITMAP_H_
#include "dgl/gBitmap.h"
#endif
#ifndef _NETSTRINGTABLE_H_
#include "sim/netStringTable.h"
#endif
#ifdef TGE_RPG
#ifndef _RPG__RPGDEFINEBASE_H_
#include "rpg/RPGDefineBase.h"
#endif
#endif
class RenderItem;
class TSThread;
class TSLastDetail;
class ConvexFeature;
//-------------------------------------------------------------------------------------
// Instance versions of shape objects
//-------------------------------------------------------------------------------------
struct TSVertex
{
Point3F p; ///< Position
ColorI color; ///< Color
Point2F t1; ///< Texture coordinate 1
Point2F t2; ///< Texture coordinate 2
};
/// An instance of a 3space shape.
///
/// @section TSShapeInstance_intro Introduction
///
/// A 3space model represents a significant amount of data. There are multiple meshes,
/// skeleton information, as well as animation data. Some of this, like the skeletal
/// transforms, are unique for each instance of the model (as different instances are
/// likely to be in different states of animation), while most of it, like texturing
/// information and vertex data, is the same amongst all instances of the shape.
///
/// To keep this data from being replicated for every instance of a 3shape object, Torque
/// uses the ResManager to instantiate and track TSShape objects. TSShape handles reading
/// and writing 3space models, as well as keeping track of static model data, as discussed
/// above. TSShapeInstance keeps track of all instance specific data, such as the currently
/// playing sequences or the active node transforms.
///
/// TSShapeInstance contains all the functionality for 3space models, while TSShape acts as
/// a repository for common data.
///
/// @section TSShapeInstance_functionality What Does TSShapeInstance Do?
///
/// TSShapeInstance handles several areas of functionality:
/// - Collision.
/// - Rendering.
/// - Animation.
/// - Updating skeletal transforms.
/// - Ballooning (see setShapeBalloon() and getShapeBalloon())
///
/// For an excellent example of how to render a TSShape in game, see TSStatic. For examples
/// of how to procedurally animate models, look at Player::updateLookAnimation().
class TSShapeInstance
{
public:
struct ObjectInstance;
friend class TSThread;
friend class TSLastDetail;
friend class TSPartInstance;
static void init();
static void destroy();
#ifdef TGE_RPG
//skin modifier
enum Constants {
MaxSkinModifiers = RPG::EQUIP_SLOTNUM
};
#endif
/// Base class for all renderable objects, including mesh objects and decal objects.
///
/// An ObjectInstance points to the renderable items in the shape...
struct ObjectInstance
{
/// this needs to be set before using an objectInstance...tells us where to
/// look for the transforms...gets set be shape instance 'setStatics' method
static MatrixF * smTransforms;
S32 nodeIndex;
/// Gets the transform of this object
MatrixF * getTransform();
/// @name Render Functions
/// @{
/// Render! This draws the base-textured object.
virtual void render(S32 objectDetail, TSMaterialList *);
/// Renders the environment map
virtual void renderEnvironmentMap(S32 objectDetail, TSMaterialList *);
/// Renders the detail map
virtual void renderDetailMap(S32 objectDetail, TSMaterialList *);
/// Renders the fog texture
virtual void renderFog(S32 objectDetail, TSMaterialList*);
/// @}
/// @name Collision Routines
/// @{
virtual bool buildPolyList(S32 objectDetail, AbstractPolyList *, U32 & surfaceKey);
virtual bool getFeatures(S32 objectDetail, const MatrixF& mat, const Point3F& n, ConvexFeature*, U32 & surfaceKey);
virtual void support(S32 od, const Point3F& v, F32* currMaxDP, Point3F* currSupport);
/// Ray cast for collision detection
virtual bool castRay(S32 objectDetail, const Point3F & start, const Point3F & end, RayInfo *);
/// @}
};
/// These are set up by default based on shape data
struct MeshObjectInstance : ObjectInstance
{
TSMesh * const * meshList; ///< one mesh per detail level... Null entries allowed.
const TSObject * object;
S32 frame;
S32 matFrame;
F32 visible;
S32 getSizeVB(S32 size);
bool hasMergeIndices();
/// @name Vertex Buffer functions
/// Fills in the mesh's vertex buffer
/// @{
void fillVB(S32 vb, TSMaterialList *materials);
void morphVB(S32 vb, S32 &previousMerge, S32 objectDetail, TSMaterialList *materials);
void renderVB(S32 vb, S32 objectDetail, TSMaterialList *materials);
/// @}
/// @name Render Methods
/// This just selects the right detail level (mesh) and calls mesh's render
/// @{
void render(S32 objectDetail, TSMaterialList *);
void renderEnvironmentMap(S32 objectDetail, TSMaterialList *);
void renderDetailMap(S32 objectDetail, TSMaterialList *);
void renderShadow(S32 objectDetail, const MatrixF & mat, S32 dim, U32 * bits, TSMaterialList *);
void renderFog(S32 objectDetail, TSMaterialList*);
/// @}
/// Gets the mesh with specified detail level
TSMesh * getMesh(S32 num) const { return num<object->numMeshes ? *(meshList+num) : NULL; }
/// @name Collision Routines
/// @{
bool buildPolyList(S32 objectDetail, AbstractPolyList *, U32 & surfaceKey);
bool getFeatures(S32 objectDetail, const MatrixF& mat, const Point3F& n, ConvexFeature*, U32 & surfaceKey);
void support(S32 od, const Point3F& v, F32* currMaxDP, Point3F* currSupport);
bool castRay(S32 objectDetail, const Point3F & start, const Point3F & end, RayInfo *);
/// @}
};
/// Also set up based on shape data...they refer to mesh object instances
struct DecalObjectInstance : ObjectInstance
{
TSDecalMesh * const * decalList;
const MeshObjectInstance * targetObject;
const TSShape::Decal * decalObject;
S32 frame;
void render(S32 objectDetail, TSMaterialList *);
TSDecalMesh * getDecalMesh(S32 num) const { return num<decalObject->numMeshes ? *(decalList+num) : NULL; }
// we don't do these things...
// void renderEnvironmentMap(S32,TSMaterialList*) {}
// void renderDecalMap(S32,TSMaterialList*) {}
// bool getFeatures(S32 objectDetail, const MatrixF& mat, const Point3F& n, ConvexFeature*, U32 & surfaceKey);
bool buildPolyList(S32, AbstractPolyList *, U32 &) { return false; }
bool castRay(S32, const Point3F &, const Point3F &, RayInfo *) { return false; }
};
/// IFL objects ... controlled by animation but also can be controlled by user
struct IflMaterialInstance
{
const TSShape::IflMaterial * iflMaterial;
S32 frame;
};
//-------------------------------------------------------------------------------------
// Lists used for storage of transforms, nodes, objects, etc...
//-------------------------------------------------------------------------------------
public:
Vector<MeshObjectInstance> mMeshObjects;
Vector<DecalObjectInstance> mDecalObjects;
Vector<IflMaterialInstance> mIflMaterialInstances;
/// storage space for node transforms
Vector<MatrixF> mNodeTransforms;
/// @name Reference Transform Vectors
/// unused until first transition
/// @{
Vector<Quat16> mNodeReferenceRotations;
Vector<Point3F> mNodeReferenceTranslations;
Vector<F32> mNodeReferenceUniformScales;
Vector<Point3F> mNodeReferenceScaleFactors;
Vector<Quat16> mNodeReferenceArbitraryScaleRots;
/// @}
/// @name Workspace for Node Transforms
/// @{
static Vector<QuatF> smNodeCurrentRotations;
static Vector<Point3F> smNodeCurrentTranslations;
static Vector<F32> smNodeCurrentUniformScales;
static Vector<Point3F> smNodeCurrentAlignedScales;
static Vector<TSScale> smNodeCurrentArbitraryScales;
/// @}
/// @name Threads
/// keep track of who controls what on currently animating shape
/// @{
static Vector<TSThread*> smRotationThreads;
static Vector<TSThread*> smTranslationThreads;
static Vector<TSThread*> smScaleThreads;
/// @}
//-------------------------------------------------------------------------------------
// Misc.
//-------------------------------------------------------------------------------------
protected:
/// @name Ground Transform Data
/// @{
MatrixF mGroundTransform;
TSThread * mGroundThread;
/// @}
bool mScaleCurrentlyAnimated;
S32 mCurrentDetailLevel;
/// 0-1, how far along from current to next (higher) detail level...
///
/// 0=at this dl, 1=at higher detail level, where higher means bigger size on screen
/// for dl=0, we use twice detail level 0's size as the size of the "next" dl
F32 mCurrentIntraDetailLevel;
Resource<TSShape> hShape;
TSShape * mShape;
TSMaterialList* mMaterialList; ///< by default, points to hShape material list
bool mOwnMaterialList; ///< Does this own the material list pointer?
TextureHandle mEnvironmentMap;
bool mEnvironmentMapOn;
F32 mEnvironmentMapAlpha;
bool mAllowTwoPassEnvironmentMap;
bool mAlphaIsReflectanceMap;
bool mAllowTwoPassDetailMap;
S32 mMaxEnvironmentMapDL;
S32 mMaxDetailMapDL;
bool mAlphaAlways;
F32 mAlphaAlwaysValue;
bool mDrawFog;
bool mBalloonShape; ///< Is this shape ballooned?
F32 mBalloonValue; ///< How much is it ballooned?
bool mUseOverrideTexture;
TextureHandle mOverrideTexture;
U32 debrisRefCount;
// the threads...
Vector<TSThread*> mThreadList;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -