Merge pull request #1506 from marauder2k9-torque/SoundAsset_Refactor

Shape Asset Refactor and Image Asset fixes and tweaks
This commit is contained in:
Brian Roberts 2025-06-21 21:09:28 -05:00 committed by GitHub
commit f1cf4147a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
78 changed files with 1472 additions and 1182 deletions

View file

@ -151,13 +151,14 @@ TSStatic::TSStatic()
mAnimOffset = 0.0f;
mAnimSpeed = 1.0f;
INIT_ASSET(Shape);
mShapeAsset.registerRefreshNotify(this);
}
TSStatic::~TSStatic()
{
delete mConvexList;
mConvexList = NULL;
mShapeAsset.unregisterRefreshNotify();
}
ImplementEnumType(TSMeshType,
@ -180,11 +181,7 @@ void TSStatic::initPersistFields()
docsURL;
addGroup("Shape");
INITPERSISTFIELD_SHAPEASSET(Shape, TSStatic, "Model to use for this TSStatic");
addProtectedField("shapeName", TypeShapeFilename, Offset(mShapeName, TSStatic),
&TSStatic::_setShapeData, &defaultProtectedGetFn,
"%Path and filename of the model file (.DTS, .DAE) to use for this TSStatic. Legacy field. Any loose files assigned here will attempt to be auto-imported in as an asset.", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_SHAPEASSET_REFACTOR(Shape, TSStatic, "Model to use for this TSStatic");
endGroup("Shape");
@ -393,59 +390,55 @@ bool TSStatic::_createShape()
mAmbientThread = NULL;
//mShape = NULL;
U32 assetStatus = ShapeAsset::getAssetErrCode(mShapeAsset);
if (assetStatus == AssetBase::Ok || assetStatus == AssetBase::UsingFallback)
if (mShapeAsset.notNull())
{
//Special-case handling, usually because we set noShape
mShape = mShapeAsset->getShapeResource();
}
if (!getShape())
{
Con::errorf("TSStatic::_createShape() - Shape Asset %s had no valid shape!", mShapeAsset.getAssetId());
return false;
}
if (!mShape)
{
Con::errorf("TSStatic::_createShape() - Shape Asset %s had no valid shape!", mShapeAsset.getAssetId());
return false;
}
if (isClientObject() &&
!getShape()->preloadMaterialList(getShape().getPath()) &&
NetConnection::filesWereDownloaded())
return false;
if (isClientObject() &&
!mShape->preloadMaterialList(mShape.getPath()) &&
NetConnection::filesWereDownloaded())
return false;
mObjBox = getShape()->mBounds;
resetWorldBox();
mObjBox = mShape->mBounds;
resetWorldBox();
mShapeInstance = new TSShapeInstance(getShape(), isClientObject());
mShapeInstance->resetMaterialList();
mShapeInstance->cloneMaterialList();
mShapeInstance = new TSShapeInstance(mShape, isClientObject());
mShapeInstance->resetMaterialList();
mShapeInstance->cloneMaterialList();
if (isGhost())
{
// Reapply the current skin
mAppliedSkinName = "";
reSkin();
if (isGhost())
{
// Reapply the current skin
mAppliedSkinName = "";
reSkin();
updateMaterials();
}
updateMaterials();
}
prepCollision();
prepCollision();
// Find the "ambient" animation if it exists
S32 ambientSeq = getShape()->findSequence("ambient");
// Find the "ambient" animation if it exists
S32 ambientSeq = mShape->findSequence("ambient");
if (ambientSeq > -1 && !mAmbientThread)
mAmbientThread = mShapeInstance->addThread();
if (ambientSeq > -1 && !mAmbientThread)
mAmbientThread = mShapeInstance->addThread();
if ( mAmbientThread )
mShapeInstance->setSequence(mAmbientThread, ambientSeq, mAnimOffset);
if ( mAmbientThread )
mShapeInstance->setSequence(mAmbientThread, ambientSeq, mAnimOffset);
// Resolve CubeReflectorDesc.
if (cubeDescName.isNotEmpty())
{
Sim::findObject(cubeDescName, reflectorDesc);
}
else if (cubeDescId > 0)
{
Sim::findObject(cubeDescId, reflectorDesc);
// Resolve CubeReflectorDesc.
if (cubeDescName.isNotEmpty())
{
Sim::findObject(cubeDescName, reflectorDesc);
}
else if (cubeDescId > 0)
{
Sim::findObject(cubeDescId, reflectorDesc);
}
}
//Set up the material slot vars for easy manipulation
@ -533,20 +526,20 @@ void TSStatic::prepCollision()
if (mCollisionType == CollisionMesh || mCollisionType == VisibleMesh)
{
mShape->findColDetails(mCollisionType == VisibleMesh, &mCollisionDetails, &mLOSDetails, mCollisionLOD);
getShape()->findColDetails(mCollisionType == VisibleMesh, &mCollisionDetails, &mLOSDetails, mCollisionLOD);
if (mDecalType == mCollisionType)
{
mDecalDetailsPtr = &mCollisionDetails;
}
else if (mDecalType == CollisionMesh || mDecalType == VisibleMesh)
{
mShape->findColDetails(mDecalType == VisibleMesh, &mDecalDetails, 0, mCollisionLOD);
getShape()->findColDetails(mDecalType == VisibleMesh, &mDecalDetails, 0, mCollisionLOD);
mDecalDetailsPtr = &mDecalDetails;
}
}
else if (mDecalType == CollisionMesh || mDecalType == VisibleMesh)
{
mShape->findColDetails(mDecalType == VisibleMesh, &mDecalDetails, 0, mCollisionLOD);
getShape()->findColDetails(mDecalType == VisibleMesh, &mDecalDetails, 0, mCollisionLOD);
mDecalDetailsPtr = &mDecalDetails;
}
@ -564,12 +557,12 @@ void TSStatic::_updatePhysics()
if (mCollisionType == Bounds)
{
MatrixF offset(true);
offset.setPosition(mShape->center);
offset.setPosition(getShape()->center);
colShape = PHYSICSMGR->createCollision();
colShape->addBox(getObjBox().getExtents() * 0.5f * mObjScale, offset);
}
else
colShape = mShape->buildColShape(mCollisionType == VisibleMesh, getScale());
colShape = getShape()->buildColShape(mCollisionType == VisibleMesh, getScale());
if (colShape)
{
@ -958,7 +951,7 @@ U32 TSStatic::packUpdate(NetConnection* con, U32 mask, BitStream* stream)
if (stream->writeFlag(mask & AdvancedStaticOptionsMask))
{
PACK_ASSET(con, Shape);
PACK_ASSET_REFACTOR(con, Shape);
stream->write((U32)mDecalType);
@ -1075,7 +1068,7 @@ void TSStatic::unpackUpdate(NetConnection* con, BitStream* stream)
if (stream->readFlag()) // AdvancedStaticOptionsMask
{
UNPACK_ASSET(con, Shape);
UNPACK_ASSET_REFACTOR(con, Shape);
stream->read((U32*)&mDecalType);
@ -1597,9 +1590,9 @@ void TSStatic::updateMaterials()
String path;
if (mShapeAsset->isAssetValid())
path = mShapeAsset->getShapeFileName();
path = mShapeAsset->getShapeFile();
else
path = mShapeName;
path = mShapeFile;
pMatList->setTextureLookupPath(path);
@ -1781,7 +1774,7 @@ DefineEngineMethod(TSStatic, changeMaterial, void, (const char* mapTo, Material*
return;
}
TSMaterialList* shapeMaterialList = object->getShapeResource()->materialList;
TSMaterialList* shapeMaterialList = object->getShape()->materialList;
// Check the mapTo name exists for this shape
S32 matIndex = shapeMaterialList->getMaterialNameList().find_next(String(mapTo));
@ -1821,7 +1814,7 @@ DefineEngineMethod(TSStatic, getModelFile, const char*, (), ,
"@endtsexample\n"
)
{
return object->getShape();
return object->getShapeFile();
}
void TSStatic::set_special_typing()
@ -1866,14 +1859,14 @@ void TSStatic::setSelectionFlags(U8 flags)
bool TSStatic::hasNode(const char* nodeName)
{
S32 nodeIDx = getShapeResource()->findNode(nodeName);
S32 nodeIDx = getShape()->findNode(nodeName);
return nodeIDx >= 0;
}
void TSStatic::getNodeTransform(const char *nodeName, const MatrixF &xfm, MatrixF *outMat)
{
S32 nodeIDx = getShapeResource()->findNode(nodeName);
S32 nodeIDx = getShape()->findNode(nodeName);
MatrixF nodeTransform(xfm);
const Point3F& scale = getScale();