Updated TSStatic to utilize the getShapeAsset utility functions, and shifted the loader logic to utilize ShapeAssets exclusively, having straight file names go through the utility function to find/process a relevent asset.

This commit is contained in:
Areloch 2020-03-21 00:36:49 -05:00
parent 6ade6f08ce
commit 7029024b8e
5 changed files with 127 additions and 141 deletions

View file

@ -300,6 +300,7 @@ bool ShapeAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAss
//If possible, see if we can run an in-place import and the get the asset from that
#if TORQUE_DEBUG
Con::warnf("ShapeAsset::getAssetByFilename - Attempted to in-place import a shapefile(%s) that had no associated asset", fileName);
#endif
ConsoleValueRef result = Con::executef("importLooseFile", fileName, true);
@ -315,7 +316,6 @@ bool ShapeAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAss
return true;
}
}
#endif
//Didn't work, so have us fall back to a placeholder asset
shapeAsset->setAssetId(StringTable->insert("Core_Rendering:noshape"));

View file

@ -101,9 +101,6 @@ ConsoleDocClass( TSStatic,
);
TSStatic::TSStatic()
:
cubeDescId( 0 ),
reflectorDesc( NULL )
{
mNetFlags.set(Ghostable | ScopeAlways);
@ -171,7 +168,7 @@ void TSStatic::initPersistFields()
&TSStatic::_setShapeAsset, &defaultProtectedGetFn,
"The source shape asset.");
addProtectedField("shapeName", TypeShapeFilename, Offset( mShapeName, TSStatic ), &TSStatic::_setShape, &defaultProtectedGetFn,
addProtectedField("shapeName", TypeFilename, Offset( mShapeName, TSStatic ), &TSStatic::_setShape, &defaultProtectedGetFn,
"%Path and filename of the model file (.DTS, .DAE) to use for this TSStatic."/*, AbstractClassRep::FieldFlags::FIELD_HideInInspectors*/ );
endGroup("Shape");
@ -219,11 +216,6 @@ void TSStatic::initPersistFields()
endGroup("Rendering");
addGroup( "Reflection" );
addField( "cubeReflectorDesc", TypeRealString, Offset( cubeDescName, TSStatic ),
"References a ReflectorDesc datablock that defines performance and quality properties for dynamic reflections.\n");
endGroup( "Reflection" );
addGroup("Collision");
addField( "collisionType", TypeTSMeshType, Offset( mCollisionType, TSStatic ),
@ -265,18 +257,26 @@ bool TSStatic::_setShape(void* obj, const char* index, const char* data)
{
TSStatic* ts = static_cast<TSStatic*>(obj);// ->setFile(FileName(data));
//before we continue, lets hit up the Asset Database to see if this file is associated to an asset. If so, we grab the asset instead
AssetQuery query;
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, data);
if (foundAssetcount == 0)
if (ShapeAsset::getAssetByFilename(StringTable->insert(data), &ts->mShapeAsset))
{
//didn't find any assets. continue as normal
ts->mShapeName = StringTable->insert(data);
//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
//the TSStatic
if (ts->mShapeAsset.getAssetId() != StringTable->insert("Core_Rendering:noshape"))
{
//ts->mShapeAssetId = ts->mShapeAsset.getAssetId();
ts->mShapeName = StringTable->EmptyString();
}
/*else
{
ts->mShapeAssetId = StringTable->EmptyString();
}*/
ts->_createShape();
}
else
{
ts->setShapeAsset(query.mAssetList[0]);
ts->mShapeName = StringTable->EmptyString();
ts->mShapeAsset = StringTable->EmptyString();
}
return false;
@ -284,9 +284,9 @@ bool TSStatic::_setShape(void* obj, const char* index, const char* data)
bool TSStatic::_setShapeAsset(void* obj, const char* index, const char* data)
{
TSStatic* ts = static_cast<TSStatic*>(obj);// ->setFile(FileName(data));
TSStatic* ts = static_cast<TSStatic*>(obj);
ts->setShapeAsset(StringTable->insert(data));
ts->setShapeAsset(data);
return false;
}
@ -366,14 +366,6 @@ bool TSStatic::onAdd()
addToScene();
if ( isClientObject() )
{
mCubeReflector.unregisterReflector();
if ( reflectorDesc )
mCubeReflector.registerReflector( this, reflectorDesc );
}
_updateShouldTick();
// Accumulation and environment mapping
@ -387,10 +379,23 @@ bool TSStatic::onAdd()
bool TSStatic::setShapeAsset(const StringTableEntry shapeAssetId)
{
mShapeAssetId = shapeAssetId;
if (ShapeAsset::getAssetById(StringTable->insert(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
//the TSStatic
if (mShapeAsset.getAssetId() != StringTable->insert("Core_Rendering:noshape"))
{
mShapeName = StringTable->EmptyString();
}
_createShape();
return true;
_createShape();
return true;
}
else
{
return false;
}
}
bool TSStatic::_createShape()
@ -403,54 +408,30 @@ bool TSStatic::_createShape()
SAFE_DELETE( mPhysicsRep );
SAFE_DELETE( mShapeInstance );
mAmbientThread = NULL;
mShape = NULL;
if (mShapeAssetId != StringTable->EmptyString())
if (mShapeAsset.isNull())
{
mShapeAsset = mShapeAssetId;
if (mShapeAsset.isNull())
{
Con::errorf("[TSStatic] Failed to load shape asset.");
return false;
}
mShape = mShapeAsset->getShapeResource();
if(!mShape)
{
Con::errorf("TSStatic::_createShape() - Shape Asset had no valid shape!");
return false;
}
}
else
{
if (!mShapeName || mShapeName[0] == '\0')
{
Con::errorf("TSStatic::_createShape() - No shape name!");
return false;
}
mShapeHash = _StringTable::hashString(mShapeName);
mShape = ResourceManager::get().load(mShapeName);
Con::errorf("[TSStatic] Failed to load shape asset.");
return false;
}
if ( bool(mShape) == false )
if(!mShapeAsset->getShapeResource())
{
Con::errorf( "TSStatic::_createShape() - Unable to load shape: %s", mShapeName );
Con::errorf("TSStatic::_createShape() - Shape Asset had no valid shape!");
return false;
}
if ( isClientObject() &&
!mShape->preloadMaterialList(mShape.getPath()) &&
!mShapeAsset->getShapeResource()->preloadMaterialList(mShapeAsset->getShapeFile()) &&
NetConnection::filesWereDownloaded() )
return false;
mObjBox = mShape->mBounds;
TSShape* shape = mShapeAsset->getShapeResource();
mObjBox = shape->mBounds;
resetWorldBox();
mShapeInstance = new TSShapeInstance( mShape, isClientObject() );
mShapeInstance = new TSShapeInstance(shape, isClientObject() );
if (isClientObject())
{
mShapeInstance->cloneMaterialList();
@ -468,7 +449,7 @@ bool TSStatic::_createShape()
prepCollision();
// Find the "ambient" animation if it exists
S32 ambientSeq = mShape->findSequence("ambient");
S32 ambientSeq = shape->findSequence("ambient");
if ( ambientSeq > -1 && !mAmbientThread )
mAmbientThread = mShapeInstance->addThread();
@ -476,18 +457,8 @@ bool TSStatic::_createShape()
if ( mAmbientThread )
mShapeInstance->setSequence( mAmbientThread, ambientSeq, 0);
// 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
S32 materialCount = mShape->materialList->getMaterialNameList().size(); //mMeshAsset->getMaterialCount();
S32 materialCount = shape->materialList->getMaterialNameList().size(); //mMeshAsset->getMaterialCount();
if (isServerObject())
{
@ -495,7 +466,7 @@ bool TSStatic::_createShape()
for (U32 i = 0; i < materialCount; i++)
{
StringTableEntry materialname = StringTable->insert(mShape->materialList->getMaterialName(i).c_str());
StringTableEntry materialname = StringTable->insert(shape->materialList->getMaterialName(i).c_str());
dSprintf(matFieldName, 128, "MaterialSlot%d", i);
StringTableEntry matFld = StringTable->insert(matFieldName);
@ -572,22 +543,24 @@ void TSStatic::prepCollision()
mLOSDetails.clear();
mConvexList->nukeList();
TSShape* shape = mShapeAsset->getShapeResource();
if ( mCollisionType == CollisionMesh || mCollisionType == VisibleMesh )
{
mShape->findColDetails( mCollisionType == VisibleMesh, &mCollisionDetails, &mLOSDetails );
shape->findColDetails( mCollisionType == VisibleMesh, &mCollisionDetails, &mLOSDetails );
if ( mDecalType == mCollisionType )
{
mDecalDetailsPtr = &mCollisionDetails;
}
else if ( mDecalType == CollisionMesh || mDecalType == VisibleMesh )
{
mShape->findColDetails( mDecalType == VisibleMesh, &mDecalDetails, 0 );
shape->findColDetails( mDecalType == VisibleMesh, &mDecalDetails, 0 );
mDecalDetailsPtr = &mDecalDetails;
}
}
else if ( mDecalType == CollisionMesh || mDecalType == VisibleMesh )
{
mShape->findColDetails( mDecalType == VisibleMesh, &mDecalDetails, 0 );
shape->findColDetails( mDecalType == VisibleMesh, &mDecalDetails, 0 );
mDecalDetailsPtr = &mDecalDetails;
}
@ -601,16 +574,18 @@ void TSStatic::_updatePhysics()
if ( !PHYSICSMGR || mCollisionType == None )
return;
TSShape* shape = mShapeAsset->getShapeResource();
PhysicsCollision *colShape = NULL;
if ( mCollisionType == Bounds )
{
MatrixF offset( true );
offset.setPosition( mShape->center );
offset.setPosition(shape->center );
colShape = PHYSICSMGR->createCollision();
colShape->addBox( getObjBox().getExtents() * 0.5f * mObjScale, offset );
}
else
colShape = mShape->buildColShape( mCollisionType == VisibleMesh, getScale() );
colShape = shape->buildColShape( mCollisionType == VisibleMesh, getScale() );
if ( colShape )
{
@ -643,8 +618,6 @@ void TSStatic::onRemove()
mShapeInstance = NULL;
mAmbientThread = NULL;
if ( isClientObject() )
mCubeReflector.unregisterReflector();
Parent::onRemove();
}
@ -800,12 +773,6 @@ void TSStatic::prepRenderImage( SceneRenderState* state )
F32 invScale = (1.0f/getMax(getMax(mObjScale.x,mObjScale.y),mObjScale.z));
// If we're currently rendering our own reflection we
// don't want to render ourselves into it.
if ( mCubeReflector.isRendering() )
return;
if ( mForceDetail == -1 )
mShapeInstance->setDetailFromDistance( state, dist * invScale );
else
@ -822,9 +789,6 @@ void TSStatic::prepRenderImage( SceneRenderState* state )
rdata.setFadeOverride( 1.0f );
rdata.setOriginSort( mUseOriginSort );
if ( mCubeReflector.isEnabled() )
rdata.setCubemap( mCubeReflector.getCubemap() );
// Acculumation
rdata.setAccuTex(mAccuTex);
@ -852,20 +816,6 @@ void TSStatic::prepRenderImage( SceneRenderState* state )
mat.scale( mObjScale );
GFX->setWorldMatrix( mat );
if ( state->isDiffusePass() && mCubeReflector.isEnabled() && mCubeReflector.getOcclusionQuery() )
{
RenderPassManager *pass = state->getRenderPass();
OccluderRenderInst *ri = pass->allocInst<OccluderRenderInst>();
ri->type = RenderPassManager::RIT_Occluder;
ri->query = mCubeReflector.getOcclusionQuery();
mObjToWorld.mulP( mObjBox.getCenter(), &ri->position );
ri->scale.set( mObjBox.getExtents() );
ri->orientation = pass->allocUniqueXform( mObjToWorld );
ri->isSphere = false;
state->getRenderPass()->addInst( ri );
}
mShapeInstance->animate();
if(mShapeInstance)
{
@ -969,8 +919,8 @@ U32 TSStatic::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
if (stream->writeFlag(mask & AdvancedStaticOptionsMask))
{
stream->writeString(mShapeAssetId);
stream->writeString(mShapeName);
if(mShapeAsset->isAssetValid())
stream->writeString(mShapeAsset.getAssetId());
stream->write((U32)mDecalType);
@ -1002,11 +952,6 @@ U32 TSStatic::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
if ( mLightPlugin )
retMask |= mLightPlugin->packUpdate(this, AdvancedStaticOptionsMask, con, mask, stream);
if( stream->writeFlag( reflectorDesc != NULL ) )
{
stream->writeRangedU32( reflectorDesc->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast );
}
stream->write(mOverrideColor);
if (stream->writeFlag(mask & MaterialMask))
@ -1081,9 +1026,7 @@ void TSStatic::unpackUpdate(NetConnection *con, BitStream *stream)
{
char buffer[256];
stream->readString(buffer);
mShapeAssetId = StringTable->insert(buffer);
mShapeName = stream->readSTString();
mShapeAsset = StringTable->insert(buffer);
stream->read((U32*)&mDecalType);
@ -1118,11 +1061,6 @@ void TSStatic::unpackUpdate(NetConnection *con, BitStream *stream)
mLightPlugin->unpackUpdate(this, con, stream);
}
if( stream->readFlag() )
{
cubeDescId = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );
}
stream->read(&mOverrideColor);
if (stream->readFlag())
@ -1418,6 +1356,16 @@ void TSStatic::buildConvex(const Box3F& box, Convex* convex)
}
}
Resource<TSShape> TSStatic::getShape() const
{
if (mShapeAsset->isAssetValid())
{
return mShapeAsset->getShapeResource();
}
return nullptr;
}
SceneObject* TSStaticPolysoupConvex::smCurObject = NULL;
TSStaticPolysoupConvex::TSStaticPolysoupConvex()
@ -1586,7 +1534,7 @@ U32 TSStatic::getNumDetails()
void TSStatic::updateMaterials()
{
if (mChangingMaterials.empty() || !mShape)
if (mChangingMaterials.empty() || !mShapeAsset->getShapeResource())
return;
TSMaterialList* pMatList = mShapeInstance->getMaterialList();

View file

@ -43,11 +43,6 @@
#ifndef _TSSHAPE_H_
#include "ts/tsShape.h"
#endif
#ifndef _REFLECTOR_H_
#include "scene/reflector.h"
#endif
#ifndef _ASSET_PTR_H_
#include "assets/assetPtr.h"
#endif
@ -179,18 +174,12 @@ protected:
/// Start or stop processing ticks depending on our state.
void _updateShouldTick();
String cubeDescName;
U32 cubeDescId;
ReflectorDesc *reflectorDesc;
CubeReflector mCubeReflector;
protected:
Convex *mConvexList;
StringTableEntry mShapeName;
U32 mShapeHash;
Resource<TSShape> mShape;
Vector<S32> mCollisionDetails;
Vector<S32> mLOSDetails;
TSShapeInstance *mShapeInstance;
@ -261,7 +250,7 @@ public:
bool allowPlayerStep() const { return mAllowPlayerStep; }
Resource<TSShape> getShape() const { return mShape; }
Resource<TSShape> getShape() const;
StringTableEntry getShapeFileName() { return mShapeName; }
void setShapeFileName(StringTableEntry shapeName) { mShapeName = shapeName; }

View file

@ -135,6 +135,29 @@ function findImageFile(%path, %materialName, %type)
return %path @ "/" @ %materialName @ ".tif";
}
function getAssetTypeByFilename(%filePath)
{
%fileExt = fileExt( %filePath );
//add it to our array!
if(isImageFormat(%fileExt))
return "ImageAsset";
else if( isShapeFormat(%fileExt))
return "ShapeAsset";
else if( isSoundFormat(%fileExt))
return "SoundAsset";
else if( %fileExt $= ".cs" || %fileExt $= ".cs.dso" )
return "ScriptAsset";
else if( %fileExt $= ".gui" || %fileExt $= ".gui.dso" )
return "GUIAsset";
else if (%fileExt $= ".zip")
return "zip";
else if( %fileExt $= "")
return "folder";
return "";
}
function AssetBrowser::onBeginDropFiles( %this )
{
if(!AssetBrowser.isAwake())
@ -405,20 +428,43 @@ function ImportAssetWindow::reloadImportOptionConfigs(%this)
//
function importLooseFile(%filePath, %forceAutoImport)
{
%assetType = getAssetTypeByFilename(%filePath);
if(%forceAutoImport)
{
//If we're attempting to fast-track the import, check that that's even an option
if(ImportAssetWindow.importConfigsList.count() == 0 ||
EditorSettings.value("Assets/AssetImporDefaultConfig") $= "" ||
EditorSettings.value("Assets/AutoImport", false) == false)
{
MessageBoxOK("Unable to AutoImport", "Attempted to import a loose file " @ %filePath @ " with AutoImport but was unable to either due to lacking a valid import config, or the editor settings are not set to auto import.");
return false;
}
if(%assetType $= "folder" || %assetType $= "zip")
{
MessageBoxOK("Unable to AutoImport", "Unable to auto import folders or zips at this time");
return false;
}
if(%assetType $= "")
{
MessageBoxOK("Unable to AutoImport", "Unable to auto import unknown file type for file " @ %filePath);
return false;
}
}
%assetItem = AssetBrowser.addImportingAsset("ImageAsset", %filePath, "", "");
%assetItem = AssetBrowser.addImportingAsset(%assetType, %filePath, "", "");
ImportAssetItems.add(%assetItem);
if(%forceAutoImport)
{
AssetImportTargetModule.text = AssetBrowser.dirHandler.getModuleFromAddress(filePath(%filePath)).ModuleId;
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(filePath(%filePath)).ModuleId;
AssetImportTargetModule.text = %targetModule;
%assetItem.moduleName = %targetModule;
AssetBrowser.dirHandler.currentAddress = filePath(%filePath);
//skip the refresh delay, we'll force it here
ImportAssetWindow.doRefresh();

View file

@ -158,10 +158,13 @@ function AssetBrowser::importShapeAsset(%this, %assetItem)
%assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ %assetName @ ".asset.taml");
//and copy the file into the relevent directory
%doOverwrite = !AssetBrowser.isAssetReImport;
if(!pathCopy(%filePath, %assetFullPath, %doOverwrite))
if(filePath(%filePath) !$= filePath(%assetFullPath))
{
error("Unable to import asset: " @ %filePath);
%doOverwrite = !AssetBrowser.isAssetReImport;
if(!pathCopy(%filePath, %assetFullPath, %doOverwrite))
{
error("Unable to import asset: " @ %filePath);
}
}
%constructor = ShapeEditor.findConstructor( %assetFullPath );