Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
538 changes: 379 additions & 159 deletions Engine/source/T3D/assets/ShapeAsset.cpp

Large diffs are not rendered by default.

318 changes: 37 additions & 281 deletions Engine/source/T3D/assets/ShapeAsset.h

Large diffs are not rendered by default.

54 changes: 30 additions & 24 deletions Engine/source/T3D/debris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ DebrisData::DebrisData()
terminalVelocity = 0.0f;
ignoreWater = true;

mShapeAsset.registerRefreshNotify(this);
shapeAssetRef.assetPtr.registerRefreshNotify(this);
}

//#define TRACK_DEBRIS_DATA_CLONES
Expand Down Expand Up @@ -152,7 +152,7 @@ DebrisData::DebrisData(const DebrisData& other, bool temp_clone) : GameBaseData(
terminalVelocity = other.terminalVelocity;
ignoreWater = other.ignoreWater;

mShapeAsset = other.mShapeAsset;
shapeAssetRef = other.shapeAssetRef;

textureName = other.textureName;
explosionId = other.explosionId; // -- for pack/unpack of explosion ptr
Expand Down Expand Up @@ -190,8 +190,8 @@ DebrisData* DebrisData::cloneAndPerformSubstitutions(const SimObject* owner, S32
}

void DebrisData::onPerformSubstitutions()
{
_setShape(_getShapeAssetId());
{
shapeAssetRef = shapeAssetRef.assetId;
}

bool DebrisData::onAdd()
Expand Down Expand Up @@ -278,17 +278,21 @@ bool DebrisData::preload(bool server, String &errorStr)

if( server ) return true;

if (getShape())
if (!shapeAssetRef.isNull())
{
TSShapeInstance* pDummy = new TSShapeInstance(getShape(), !server);
delete pDummy;
if (!server && !getShape()->preloadMaterialList(getShapeFile()) && NetConnection::filesWereDownloaded())
Resource<TSShape> shape = shapeAssetRef.assetPtr->getShapeResource();
if (shape)
{
TSShapeInstance* pDummy = new TSShapeInstance(shape, !server);
delete pDummy;
if (!server && !shapeAssetRef.assetPtr->preloadMaterialList() && NetConnection::filesWereDownloaded())
return false;
}
else
{
errorStr = String::ToString("DebrisData(%s)::preload: Couldn't load shape \"%s\"", getName(), shapeAssetRef.assetId);
return false;
}
else if (!mShapeAsset.isNull())
{
errorStr = String::ToString("DebrisData::load: Couldn't load shape \"%s\"", _getShapeAssetId());
return false;
}
}

return true;
Expand All @@ -305,7 +309,8 @@ void DebrisData::initPersistFields()
addGroup("Shapes");
addField("texture", TypeString, Offset(textureName, DebrisData),
"@brief Texture imagemap to use for this debris object.\n\nNot used any more.\n", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_SHAPEASSET_REFACTOR(Shape, DebrisData, "Shape to use for this debris object.");
ADD_FIELD("shapeAsset", TypeShapeAssetRef, Offset(shapeAssetRef, DebrisData))
.doc("Shape to use for this debris object.");
endGroup("Shapes");

addGroup("Particle Effects");
Expand Down Expand Up @@ -390,7 +395,7 @@ void DebrisData::packData(BitStream* stream)

stream->writeString( textureName );

PACKDATA_ASSET_REFACTOR(Shape);
AssetDatabase.packDataAsset(stream, shapeAssetRef.assetId);

for( S32 i=0; i<DDC_NUM_EMITTERS; i++ )
{
Expand Down Expand Up @@ -434,7 +439,7 @@ void DebrisData::unpackData(BitStream* stream)

textureName = stream->readSTString();

UNPACKDATA_ASSET_REFACTOR(Shape);
shapeAssetRef = AssetDatabase.unpackDataAsset(stream);

for( S32 i=0; i<DDC_NUM_EMITTERS; i++ )
{
Expand Down Expand Up @@ -677,18 +682,19 @@ bool Debris::onAdd()
mFriction = mDataBlock->friction;

// Setup our bounding box
if( mDataBlock->getShape())
{
mObjBox = mDataBlock->getShape()->mBounds;
}
else
mObjBox = Box3F(Point3F(-1, -1, -1), Point3F(1, 1, 1));

Resource<TSShape> shape;
if( mDataBlock->shapeAssetRef.notNull())
{
mObjBox = Box3F(Point3F(-1, -1, -1), Point3F(1, 1, 1));
shape = mDataBlock->shapeAssetRef.assetPtr->getShapeResource();
if (shape)
mObjBox = shape->mBounds;
}

if( mDataBlock->getShape())
if(shape)
{
mShape = new TSShapeInstance( mDataBlock->getShape(), true);
mShape = new TSShapeInstance(shape, true);
}

if( mPart )
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/debris.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct DebrisData : public GameBaseData, protected AssetPtrCallback
F32 terminalVelocity; // max velocity magnitude
bool ignoreWater;

DECLARE_SHAPEASSET_REFACTOR(DebrisData, Shape)
AssetRef<ShapeAsset> shapeAssetRef;

StringTableEntry textureName;

Expand Down
33 changes: 19 additions & 14 deletions Engine/source/T3D/examples/renderShapeExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
IMPLEMENT_CO_NETOBJECT_V1(RenderShapeExample);

ConsoleDocClass( RenderShapeExample,
"@brief An example scene object which renders a DTS.\n\n"
"@brief An example scene object which renders a shape asset.\n\n"
"This class implements a basic SceneObject that can exist in the world at a "
"3D position and render itself. There are several valid ways to render an "
"object in Torque. This class makes use of the 'TS' (three space) shape "
Expand Down Expand Up @@ -74,7 +74,9 @@ void RenderShapeExample::initPersistFields()
docsURL;
Parent::initPersistFields();
addGroup( "Shapes" );
INITPERSISTFIELD_SHAPEASSET_REFACTOR(Shape, RenderShapeExample, "The path to the shape file.")
ADD_FIELD("shapeAsset", TypeShapeAssetRef, Offset(mShapeAssetRef, RenderShapeExample))
.doc("The shape asset to render.")
.network(UpdateMask);
endGroup( "Shapes" );

// SceneObject already handles exposing the transform
Expand All @@ -83,10 +85,6 @@ void RenderShapeExample::initPersistFields()
void RenderShapeExample::inspectPostApply()
{
Parent::inspectPostApply();

// Flag the network mask to send the updates
// to the client object
setMaskBits( UpdateMask );
}

bool RenderShapeExample::onAdd()
Expand Down Expand Up @@ -146,7 +144,7 @@ U32 RenderShapeExample::packUpdate( NetConnection *conn, U32 mask, BitStream *st
// Write out any of the updated editable properties
if ( stream->writeFlag( mask & UpdateMask ) )
{
PACK_ASSET_REFACTOR(conn, Shape);
AssetDatabase.packUpdateAsset(conn, mask, stream, mShapeAssetRef.assetId);

// Allow the server object a chance to handle a new shape
createShape();
Expand All @@ -170,7 +168,7 @@ void RenderShapeExample::unpackUpdate(NetConnection *conn, BitStream *stream)

if ( stream->readFlag() ) // UpdateMask
{
UNPACK_ASSET_REFACTOR(conn, Shape);
mShapeAssetRef = AssetDatabase.unpackUpdateAsset(conn, stream);

if ( isProperlyAdded() )
createShape();
Expand All @@ -182,28 +180,35 @@ void RenderShapeExample::unpackUpdate(NetConnection *conn, BitStream *stream)
//-----------------------------------------------------------------------------
void RenderShapeExample::createShape()
{
if ( mShapeAsset.isNull() )
return;

// Clean up our previous shape
if ( mShapeInstance )
SAFE_DELETE( mShapeInstance );

if (!mShapeAssetRef.hasAssetId()) //literally nothing to do here
return;

Resource<TSShape> shape;

if (mShapeAssetRef.assetPtr.notNull())
shape = mShapeAssetRef.assetPtr->getShapeResource();
else
shape = ShapeAsset::smNoShapeAssetFallbackAssetPtr->getShapeResource();

// Attempt to preload the Materials for this shape
if ( isClientObject() &&
!getShape()->preloadMaterialList(getShapeFile()) &&
!mShapeAssetRef.assetPtr->preloadMaterialList() &&
NetConnection::filesWereDownloaded() )
{
return;
}

// Update the bounding box
mObjBox = getShape()->mBounds;
mObjBox = shape->mBounds;
resetWorldBox();
setRenderTransform(mObjToWorld);

// Create the TSShapeInstance
mShapeInstance = new TSShapeInstance(getShape(), isClientObject() );
mShapeInstance = new TSShapeInstance(shape, isClientObject() );
}

void RenderShapeExample::prepRenderImage( SceneRenderState *state )
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/examples/renderShapeExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class RenderShapeExample : public SceneObject
//--------------------------------------------------------------------------
// Rendering variables
//--------------------------------------------------------------------------
DECLARE_SHAPEASSET_REFACTOR(RenderShapeExample, Shape)
AssetRef<ShapeAsset> mShapeAssetRef;

// The actual shape instance
TSShapeInstance* mShapeInstance;
Expand Down
Loading
Loading