Merge pull request #317 from Areloch/ShapeBaseDataAssetify

Implements hook-look-up logic for shape assets to ShapeBaseData including autoimport handling
This commit is contained in:
Brian Roberts 2020-11-27 18:04:16 -06:00 committed by GitHub
commit 6441ecd941
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 6 deletions

View file

@ -158,6 +158,8 @@ ShapeBaseData::ShapeBaseData()
shadowProjectionDistance( 10.0f ),
shadowSphereAdjust( 1.0f ),
shapeName( StringTable->EmptyString() ),
shapeAsset(StringTable->EmptyString()),
shapeAssetId(StringTable->EmptyString()),
cloakTexName( StringTable->EmptyString() ),
cubeDescId( 0 ),
reflectorDesc( NULL ),
@ -212,6 +214,8 @@ ShapeBaseData::ShapeBaseData(const ShapeBaseData& other, bool temp_clone) : Game
shadowProjectionDistance = other.shadowProjectionDistance;
shadowSphereAdjust = other.shadowSphereAdjust;
shapeName = other.shapeName;
shapeAsset = other.shapeAsset;
shapeAssetId = other.shapeAssetId;
cloakTexName = other.cloakTexName;
cubeDescName = other.cubeDescName;
cubeDescId = other.cubeDescId;
@ -356,12 +360,29 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
}
}
//
if (shapeName && shapeName[0]) {
//Legacy catch
if (shapeAssetId == StringTable->EmptyString() && shapeName != StringTable->EmptyString())
{
StringTableEntry assetId = ShapeAsset::getAssetIdByFilename(shapeName);
if (assetId != StringTable->EmptyString())
{
shapeAssetId = assetId;
}
}
if (ShapeAsset::getAssetById(shapeAssetId, &shapeAsset))
{
//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 (shapeAsset.getAssetId() != StringTable->insert("Core_Rendering:noshape"))
{
shapeName = StringTable->EmptyString();
}
S32 i;
// Resolve shapename
mShape = ResourceManager::get().load(shapeName);
mShape = shapeAsset->getShapeResource();
if (bool(mShape) == false)
{
errorStr = String::ToString("ShapeBaseData: Couldn't load shape \"%s\"",shapeName);
@ -574,6 +595,9 @@ void ShapeBaseData::initPersistFields()
addGroup( "Render" );
addField("shapeAsset", TypeShapeAssetId, Offset(shapeAssetId, ShapeBaseData),
"The source shape asset.");
addField( "shapeFile", TypeShapeFilename, Offset(shapeName, ShapeBaseData),
"The DTS or DAE model to use for this object." );
@ -780,6 +804,8 @@ void ShapeBaseData::packData(BitStream* stream)
stream->writeString(shapeName);
stream->writeString(shapeAsset.getAssetId());
stream->writeString(cloakTexName);
if(stream->writeFlag(mass != gShapeBaseDataProto.mass))
stream->write(mass);
@ -857,6 +883,10 @@ void ShapeBaseData::unpackData(BitStream* stream)
stream->read(&shadowSphereAdjust);
shapeName = stream->readSTString();
char buffer[256];
stream->readString(buffer);
cloakTexName = stream->readSTString();
if(stream->readFlag())
stream->read(&mass);

View file

@ -67,6 +67,10 @@
#include "console/dynamicTypes.h"
#endif
#ifndef SHAPEASSET_H
#include "T3D/assets/ShapeAsset.h"
#endif
// Need full definition visible for SimObjectPtr<ParticleEmitter>
#include "T3D/fx/particleEmitter.h"
@ -536,6 +540,10 @@ public:
StringTableEntry shapeName;
AssetPtr<ShapeAsset> shapeAsset;
StringTableEntry shapeAssetId;
StringTableEntry cloakTexName;
String cubeDescName;

View file

@ -50,7 +50,7 @@ function AssetBrowser::buildDatablockPreview(%this, %assetDef, %previewData)
//%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef;
%previewData.tooltip = %assetDef;
%previewData.doubleClickCommand = "AssetBrowser.schedule(10, \"spawnDatablockObject\",\""@ %assetDef @"\");";//browseTo %assetDef.dirPath / %assetDef.assetName
%previewData.doubleClickCommand = "DatablockEditorPlugin.openDatablock(" @ %assetDef @ ");";
}
function spawnDatablockObject(%datablock)
@ -60,8 +60,8 @@ function spawnDatablockObject(%datablock)
%cmd = %class @ "::create(" @ %name @ ");";
%shapePath = ( %datablock.shapeFile !$= "" ) ? %datablock.shapeFile : %datablock.shapeName;
%createCmd = "EWCreatorWindow.createObject( \\\"" @ %cmd @ "\\\" );";
return eval("showImportDialog( \"" @ %shapePath @ "\", \"" @ %createCmd @ "\" );");
%createCmd = "EWCreatorWindow.createObject( \"" @ %cmd @ "\" );";
return eval(%createCmd);
}
function AssetBrowser::renameDatablock(%this, %folderPath, %newFolderName)