2012-09-19 15:15:01 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
2017-07-26 21:05:04 +00:00
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
2012-09-19 15:15:01 +00:00
# ifndef _TSSTATIC_H_
# define _TSSTATIC_H_
# ifndef _SCENEOBJECT_H_
# include "scene/sceneObject.h"
# endif
# ifndef _CONVEX_H_
# include "collision/convex.h"
# endif
# ifndef __RESOURCE_H__
# include "core/resource.h"
# endif
# ifndef _NETSTRINGTABLE_H_
2020-04-15 17:15:12 +00:00
# include "sim/netStringTable.h"
2012-09-19 15:15:01 +00:00
# endif
# ifndef _TSSHAPE_H_
# include "ts/tsShape.h"
# endif
2020-04-15 17:15:12 +00:00
# ifndef _REFLECTOR_H_
# include "scene/reflector.h"
# endif
2020-06-13 17:08:01 +00:00
# ifndef _COLLADA_UTILS_H_
# include "ts/collada/colladaUtils.h"
# endif
2019-11-18 09:30:04 +00:00
# ifndef _ASSET_PTR_H_
# include "assets/assetPtr.h"
# endif
# ifndef SHAPEASSET_H
# include "T3D/assets/ShapeAsset.h"
# endif
2012-09-19 15:15:01 +00:00
class TSShapeInstance ;
class TSThread ;
class TSStatic ;
class PhysicsBody ;
struct ObjectRenderInst ;
class TSStaticPolysoupConvex : public Convex
{
typedef Convex Parent ;
friend class TSMesh ;
public :
TSStaticPolysoupConvex ( ) ;
~ TSStaticPolysoupConvex ( ) { } ;
public :
2015-03-04 00:55:30 +00:00
Box3F box ;
Point3F verts [ 4 ] ;
PlaneF normal ;
S32 idx ;
2020-04-15 17:15:12 +00:00
TSMesh * mesh ;
2012-09-19 15:15:01 +00:00
static SceneObject * smCurObject ;
public :
// Returns the bounding box in world coordinates
Box3F getBoundingBox ( ) const ;
Box3F getBoundingBox ( const MatrixF & mat , const Point3F & scale ) const ;
2020-04-15 17:15:12 +00:00
void getFeatures ( const MatrixF & mat , const VectorF & n , ConvexFeature * cf ) ;
2012-09-19 15:15:01 +00:00
// This returns a list of convex faces to collide against
void getPolyList ( AbstractPolyList * list ) ;
// This returns the furthest point from the input vector
Point3F support ( const VectorF & v ) const ;
} ;
/// A simple mesh shape with optional ambient animation.
class TSStatic : public SceneObject
{
typedef SceneObject Parent ;
static U32 smUniqueIdentifier ;
2020-04-15 17:15:12 +00:00
enum MaskBits
2012-09-19 15:15:01 +00:00
{
2020-04-15 17:15:12 +00:00
TransformMask = Parent : : NextFreeMask < < 0 ,
AdvancedStaticOptionsMask = Parent : : NextFreeMask < < 1 ,
UpdateCollisionMask = Parent : : NextFreeMask < < 2 ,
SkinMask = Parent : : NextFreeMask < < 3 ,
MaterialMask = Parent : : NextFreeMask < < 4 ,
NextFreeMask = Parent : : NextFreeMask < < 5
2012-09-19 15:15:01 +00:00
} ;
public :
2014-11-20 13:00:26 +00:00
void setAlphaFade ( bool enable , F32 start , F32 end , bool inverse )
2014-11-06 13:54:49 +00:00
{
2020-04-15 17:15:12 +00:00
mUseAlphaFade = enable ;
mAlphaFadeStart = start ;
mAlphaFadeEnd = end ;
mInvertAlphaFade = inverse ;
2014-11-06 13:54:49 +00:00
}
2020-04-15 17:15:12 +00:00
2012-09-19 15:15:01 +00:00
/// The different types of mesh data types
enum MeshType
{
None = 0 , ///< No mesh
Bounds = 1 , ///< Bounding box of the shape
CollisionMesh = 2 , ///< Specifically designated collision meshes
VisibleMesh = 3 ///< Rendered mesh polygons
} ;
2020-04-15 17:15:12 +00:00
2012-09-19 15:15:01 +00:00
protected :
2014-11-20 13:00:26 +00:00
bool mUseAlphaFade ;
F32 mAlphaFadeStart ;
F32 mAlphaFadeEnd ;
F32 mAlphaFade ;
bool mInvertAlphaFade ;
2012-09-19 15:15:01 +00:00
2019-12-06 02:42:47 +00:00
struct matMap
{
MaterialAsset * matAsset ;
String assetId ;
U32 slot ;
} ;
Vector < matMap > mChangingMaterials ;
Vector < matMap > mMaterials ;
2012-09-19 15:15:01 +00:00
bool onAdd ( ) ;
void onRemove ( ) ;
// Collision
void prepCollision ( ) ;
2020-04-15 17:15:12 +00:00
bool castRay ( const Point3F & start , const Point3F & end , RayInfo * info ) ;
bool castRayRendered ( const Point3F & start , const Point3F & end , RayInfo * info ) ;
bool buildPolyList ( PolyListContext context , AbstractPolyList * polyList , const Box3F & box , const SphereF & sphere ) ;
bool buildExportPolyList ( ColladaUtils : : ExportData * exportData , const Box3F & box , const SphereF & ) ;
2012-09-19 15:15:01 +00:00
void buildConvex ( const Box3F & box , Convex * convex ) ;
2019-11-18 09:30:04 +00:00
2012-09-19 15:15:01 +00:00
bool _createShape ( ) ;
2020-04-15 17:15:12 +00:00
2012-09-19 15:15:01 +00:00
void _updatePhysics ( ) ;
2020-04-15 17:15:12 +00:00
void _renderNormals ( ObjectRenderInst * ri , SceneRenderState * state , BaseMatInstance * overrideMat ) ;
2012-09-19 15:15:01 +00:00
2020-04-15 17:15:12 +00:00
void _onResourceChanged ( const Torque : : Path & path ) ;
2021-07-19 06:07:08 +00:00
void onShapeChanged ( ) ;
2012-09-19 15:15:01 +00:00
// ProcessObject
2020-04-15 17:15:12 +00:00
virtual void processTick ( const Move * move ) ;
virtual void interpolateTick ( F32 delta ) ;
virtual void advanceTime ( F32 dt ) ;
2012-09-19 15:15:01 +00:00
2019-12-06 02:42:47 +00:00
virtual void onDynamicModified ( const char * slotName , const char * newValue ) ;
2012-09-19 15:15:01 +00:00
/// Start or stop processing ticks depending on our state.
void _updateShouldTick ( ) ;
2020-04-15 17:15:12 +00:00
String cubeDescName ;
U32 cubeDescId ;
ReflectorDesc * reflectorDesc ;
CubeReflector mCubeReflector ;
2012-09-19 15:15:01 +00:00
protected :
2020-04-15 17:15:12 +00:00
Convex * mConvexList ;
2012-09-19 15:15:01 +00:00
2021-07-19 06:07:08 +00:00
DECLARE_SHAPEASSET ( TSStatic , Shape , onShapeChanged ) ;
2021-10-03 07:56:26 +00:00
DECLARE_ASSET_NET_SETGET ( TSStatic , Shape , AdvancedStaticOptionsMask ) ;
2021-07-19 06:07:08 +00:00
2012-09-19 15:15:01 +00:00
U32 mShapeHash ;
Vector < S32 > mCollisionDetails ;
Vector < S32 > mLOSDetails ;
2020-04-15 17:15:12 +00:00
TSShapeInstance * mShapeInstance ;
2012-09-19 15:15:01 +00:00
NetStringHandle mSkinNameHandle ;
String mAppliedSkinName ;
bool mPlayAmbient ;
2020-06-13 17:08:01 +00:00
TSThread * mAmbientThread ;
F32 mAnimOffset ;
F32 mAnimSpeed ;
2012-09-19 15:15:01 +00:00
/// The type of mesh data to return for collision queries.
MeshType mCollisionType ;
/// The type of mesh data to return for decal polylist queries.
MeshType mDecalType ;
bool mAllowPlayerStep ;
/// If true each submesh within the TSShape is culled
/// against the object space frustum.
bool mMeshCulling ;
/// If true the shape is sorted by the origin of the
/// model instead of the nearest point of the bounds.
bool mUseOriginSort ;
2020-04-15 17:15:12 +00:00
PhysicsBody * mPhysicsRep ;
2012-09-19 15:15:01 +00:00
2017-10-17 13:48:31 +00:00
LinearColorF mOverrideColor ;
2012-09-19 15:15:01 +00:00
// Debug stuff
F32 mRenderNormalScalar ;
S32 mForceDetail ;
public :
TSStatic ( ) ;
~ TSStatic ( ) ;
DECLARE_CONOBJECT ( TSStatic ) ;
2023-11-09 02:42:47 +00:00
DECLARE_CATEGORY ( " Object \t Simple " ) ;
2012-09-19 15:15:01 +00:00
static void initPersistFields ( ) ;
2023-05-23 17:35:07 +00:00
/// returns the shape asset used for this object
StringTableEntry getTypeHint ( ) const override { return ( getShapeAsset ( ) ) ? getShapeAsset ( ) - > getAssetName ( ) : StringTable - > EmptyString ( ) ; }
2020-08-03 03:33:10 +00:00
static void consoleInit ( ) ;
2020-04-15 17:15:12 +00:00
static bool _setFieldSkin ( void * object , const char * index , const char * data ) ;
static const char * _getFieldSkin ( void * object , const char * data ) ;
2012-09-19 15:15:01 +00:00
// Skinning
2020-04-15 17:15:12 +00:00
void setSkinName ( const char * name ) ;
2012-09-19 15:15:01 +00:00
void reSkin ( ) ;
// NetObject
2020-04-15 17:15:12 +00:00
U32 packUpdate ( NetConnection * conn , U32 mask , BitStream * stream ) ;
void unpackUpdate ( NetConnection * conn , BitStream * stream ) ;
2012-09-19 15:15:01 +00:00
// SceneObject
2020-04-15 17:15:12 +00:00
void setTransform ( const MatrixF & mat ) ;
2012-09-19 15:15:01 +00:00
void onScaleChanged ( ) ;
2020-04-15 17:15:12 +00:00
void prepRenderImage ( SceneRenderState * state ) ;
2012-09-19 15:15:01 +00:00
void inspectPostApply ( ) ;
2020-04-15 17:15:12 +00:00
virtual void onMount ( SceneObject * obj , S32 node ) ;
virtual void onUnmount ( SceneObject * obj , S32 node ) ;
2012-09-19 15:15:01 +00:00
/// The type of mesh data use for collision queries.
MeshType getCollisionType ( ) const { return mCollisionType ; }
bool allowPlayerStep ( ) const { return mAllowPlayerStep ; }
TSShapeInstance * getShapeInstance ( ) const { return mShapeInstance ; }
2018-03-01 07:51:18 +00:00
U32 getNumDetails ( ) ;
2012-09-19 15:15:01 +00:00
const Vector < S32 > & getCollisionDetails ( ) const { return mCollisionDetails ; }
const Vector < S32 > & getLOSDetails ( ) const { return mLOSDetails ; }
2020-06-13 17:08:01 +00:00
bool hasAnim ( ) { return mAmbientThread ! = NULL ; }
2022-06-13 17:38:08 +00:00
# ifdef TORQUE_TOOLS
2019-11-18 09:30:04 +00:00
virtual void onInspect ( GuiInspector * ) ;
2022-06-13 17:38:08 +00:00
# endif
2019-12-06 02:42:47 +00:00
void updateMaterials ( ) ;
2020-08-16 07:16:19 +00:00
bool isAnimated ( ) { return mPlayAmbient ; }
2022-08-07 20:55:42 +00:00
bool hasNode ( const char * nodeName ) ;
2021-11-04 02:15:00 +00:00
void getNodeTransform ( const char * nodeName , const MatrixF & xfm , MatrixF * outMat ) ;
2020-08-16 07:16:19 +00:00
2020-08-19 23:30:42 +00:00
virtual void getUtilizedAssets ( Vector < StringTableEntry > * usedAssetsList ) ;
2017-07-26 21:05:04 +00:00
private :
2020-04-15 17:15:12 +00:00
virtual void onStaticModified ( const char * slotName , const char * newValue = NULL ) ;
2017-07-26 21:05:04 +00:00
protected :
Vector < S32 > mDecalDetails ;
2020-04-15 17:15:12 +00:00
Vector < S32 > * mDecalDetailsPtr ;
2020-08-03 03:33:10 +00:00
///Indicates if all statics should utilize the distance-based object fadeout logic
static bool smUseStaticObjectFade ;
///Distance at which static object fading begins if smUseStaticObjectFade is on
static F32 smStaticObjectFadeStart ;
///Distance at which static object fading should have fully faded if smUseStaticObjectFade is on
static F32 smStaticObjectFadeEnd ;
///Size of object where if the bounds is at or bigger than this, it will be ignored in the smUseStaticObjectFade logic. Useful for very large, distance-important objects
static F32 smStaticObjectUnfadeableSize ;
2017-07-26 21:05:04 +00:00
public :
bool mIgnoreZodiacs ;
bool mHasGradients ;
bool mInvertGradientRange ;
Point2F mGradientRangeUser ;
Point2F mGradientRange ;
private :
void set_special_typing ( ) ;
2017-07-26 22:48:29 +00:00
virtual void setSelectionFlags ( U8 flags ) ;
2012-09-19 15:15:01 +00:00
} ;
typedef TSStatic : : MeshType TSMeshType ;
2020-04-15 17:15:12 +00:00
DefineEnumType ( TSMeshType ) ;
2012-09-19 15:15:01 +00:00
# endif // _H_TSSTATIC