Fixes the hook-ins so when a shape asset is changed, tsstatics now are correctly triggered for a reload

This commit is contained in:
Areloch 2020-09-13 17:57:19 -05:00
parent 1600bfaf57
commit 8fbad31b43
4 changed files with 28 additions and 6 deletions

View file

@ -211,7 +211,7 @@ void ShapeAsset::setShapeConstructorFile(const char* pShapeConstructorFile)
void ShapeAsset::_onResourceChanged(const Torque::Path &path)
{
if (path != Torque::Path(mFileName) )
if (path != Torque::Path(mFilePath) )
return;
refreshAsset();
@ -313,7 +313,7 @@ bool ShapeAsset::loadShape()
}
}
onShapeChanged.trigger(this);
mChangeSignal.trigger();
return true;
}

View file

@ -76,6 +76,10 @@ protected:
Vector<StringTableEntry> mAnimationAssetIds;
Vector<AssetPtr<ShapeAnimationAsset>> mAnimationAssets;
typedef Signal<void()> ShapeAssetChanged;
ShapeAssetChanged mChangeSignal;
public:
ShapeAsset();
virtual ~ShapeAsset();
@ -122,7 +126,7 @@ public:
void _onResourceChanged(const Torque::Path &path);
Signal< void(ShapeAsset*) > onShapeChanged;
ShapeAssetChanged& getChangedSignal() { return mChangeSignal; }
void setShapeFile(const char* pScriptFile);
inline StringTableEntry getShapeFile(void) const { return mFileName; };

View file

@ -402,7 +402,7 @@ bool TSStatic::onAdd()
setRenderTransform(mObjToWorld);
// Register for the resource change signal.
ResourceManager::get().getChangedSignal().notify(this, &TSStatic::_onResourceChanged);
//ResourceManager::get().getChangedSignal().notify(this, &TSStatic::_onResourceChanged);
addToScene();
@ -427,6 +427,11 @@ bool TSStatic::onAdd()
bool TSStatic::setShapeAsset(const StringTableEntry shapeAssetId)
{
if (!mShapeAsset.isNull())
{
mShapeAsset->getChangedSignal().remove(this, &TSStatic::_onAssetChanged);
}
if (ShapeAsset::getAssetById(shapeAssetId, &mShapeAsset))
{
//Special exception case. If we've defaulted to the 'no shape' mesh, don't save it out, we'll retain the original ids/paths so it doesn't break
@ -434,6 +439,8 @@ bool TSStatic::setShapeAsset(const StringTableEntry shapeAssetId)
if (mShapeAsset.getAssetId() != StringTable->insert("Core_Rendering:noshape"))
{
mShapeName = StringTable->EmptyString();
mShapeAsset->getChangedSignal().notify(this, &TSStatic::_onAssetChanged);
}
_createShape();
@ -658,7 +665,7 @@ void TSStatic::onRemove()
removeFromScene();
// Remove the resource change signal.
ResourceManager::get().getChangedSignal().remove(this, &TSStatic::_onResourceChanged);
//ResourceManager::get().getChangedSignal().remove(this, &TSStatic::_onResourceChanged);
delete mShapeInstance;
mShapeInstance = NULL;
@ -667,6 +674,9 @@ void TSStatic::onRemove()
if (isClientObject())
mCubeReflector.unregisterReflector();
if(!mShapeAsset.isNull())
mShapeAsset->getChangedSignal().remove(this, &TSStatic::_onAssetChanged);
Parent::onRemove();
}
@ -679,6 +689,12 @@ void TSStatic::_onResourceChanged(const Torque::Path& path)
_updateShouldTick();
}
void TSStatic::_onAssetChanged()
{
_createShape();
_updateShouldTick();
}
void TSStatic::setSkinName(const char* name)
{
if (!isGhost())
@ -917,9 +933,10 @@ void TSStatic::prepRenderImage(SceneRenderState* state)
state->getRenderPass()->addInst(ri);
}
mShapeInstance->animate();
if (mShapeInstance)
{
mShapeInstance->animate();
if (mUseAlphaFade || smUseStaticObjectFade)
{
mShapeInstance->setAlphaAlways(mAlphaFade);

View file

@ -172,6 +172,7 @@ protected:
void _renderNormals(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat);
void _onResourceChanged(const Torque::Path& path);
void _onAssetChanged();
// ProcessObject
virtual void processTick(const Move* move);