mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 16:14:38 +00:00
Merge pull request #461 from Areloch/ShapeAssetPreviewGen
Implements shape preview caching for shape assets
This commit is contained in:
commit
e2f706cd94
8 changed files with 116 additions and 24 deletions
|
|
@ -46,6 +46,10 @@
|
||||||
#include "platform/profiler.h"
|
#include "platform/profiler.h"
|
||||||
#include "T3D/assets/assetImporter.h"
|
#include "T3D/assets/assetImporter.h"
|
||||||
|
|
||||||
|
#ifdef TORQUE_TOOLS
|
||||||
|
#include "ts/tsLastDetail.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
IMPLEMENT_CONOBJECT(ShapeAsset);
|
IMPLEMENT_CONOBJECT(ShapeAsset);
|
||||||
|
|
@ -505,6 +509,29 @@ ShapeAnimationAsset* ShapeAsset::getAnimation(S32 index)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TORQUE_TOOLS
|
||||||
|
const char* ShapeAsset::generateCachedPreviewImage(S32 resolution)
|
||||||
|
{
|
||||||
|
if (!mShape)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
TSLastDetail* dt = new TSLastDetail(mShape,
|
||||||
|
mFilePath,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
resolution);
|
||||||
|
|
||||||
|
dt->update();
|
||||||
|
|
||||||
|
delete dt;
|
||||||
|
|
||||||
|
return mFilePath;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
DefineEngineMethod(ShapeAsset, getMaterialCount, S32, (), ,
|
DefineEngineMethod(ShapeAsset, getMaterialCount, S32, (), ,
|
||||||
"Gets the number of materials for this shape asset.\n"
|
"Gets the number of materials for this shape asset.\n"
|
||||||
"@return Material count.\n")
|
"@return Material count.\n")
|
||||||
|
|
@ -526,6 +553,21 @@ DefineEngineMethod(ShapeAsset, getAnimation, ShapeAnimationAsset*, (S32 index),
|
||||||
{
|
{
|
||||||
return object->getAnimation(index);
|
return object->getAnimation(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod(ShapeAsset, getShapeFile, const char*, (), ,
|
||||||
|
"Creates a new script asset using the targetFilePath.\n"
|
||||||
|
"@return The bool result of calling exec")
|
||||||
|
{
|
||||||
|
return object->getShapeFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TORQUE_TOOLS
|
||||||
|
DefineEngineMethod(ShapeAsset, generateCachedPreviewImage, const char*, (S32 resolution), (256), "")
|
||||||
|
{
|
||||||
|
return object->generateCachedPreviewImage(resolution);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// GuiInspectorTypeAssetId
|
// GuiInspectorTypeAssetId
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -625,10 +667,3 @@ void GuiInspectorTypeShapeAssetId::consoleInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DefineEngineMethod(ShapeAsset, getShapeFile, const char*, (), ,
|
|
||||||
"Creates a new script asset using the targetFilePath.\n"
|
|
||||||
"@return The bool result of calling exec")
|
|
||||||
{
|
|
||||||
return object->getShapeFilePath();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,10 @@ public:
|
||||||
|
|
||||||
static StringTableEntry getNoShapeAssetId() { return StringTable->insert("Core_Rendering:noshape"); }
|
static StringTableEntry getNoShapeAssetId() { return StringTable->insert("Core_Rendering:noshape"); }
|
||||||
|
|
||||||
|
#ifdef TORQUE_TOOLS
|
||||||
|
const char* generateCachedPreviewImage(S32 resolution);
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void onAssetRefresh(void);
|
virtual void onAssetRefresh(void);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -420,7 +420,10 @@ void NormalsOutFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||||
{
|
{
|
||||||
// Transform the normal to world space.
|
// Transform the normal to world space.
|
||||||
Var *objTrans = getObjTrans( componentList, fd.features[MFT_UseInstancing], meta );
|
Var *objTrans = getObjTrans( componentList, fd.features[MFT_UseInstancing], meta );
|
||||||
meta->addStatement( new GenOp( " @ = mul( @, normalize( @ ) );\r\n", outNormal, objTrans, inNormal ) );
|
if (String::compare((const char*)objTrans->type, "float4x4") == 0)
|
||||||
|
meta->addStatement(new GenOp(" @ = mul( @, normalize( float4(@,0) ) ).xyz;\r\n", outNormal, objTrans, inNormal));
|
||||||
|
else
|
||||||
|
meta->addStatement(new GenOp(" @ = mul( @, normalize( @ ) );\r\n", outNormal, objTrans, inNormal));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -983,8 +983,7 @@ function ImportAssetWindow::ImportAssets(%this)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas.pushDialog( EditorLoadingGui );
|
displayEditorLoadingGui("Importing Assets...");
|
||||||
Canvas.repaint();
|
|
||||||
|
|
||||||
%this.importer.targetModuleId = %moduleName;
|
%this.importer.targetModuleId = %moduleName;
|
||||||
}
|
}
|
||||||
|
|
@ -1000,7 +999,7 @@ function ImportAssetWindow::ImportAssets(%this)
|
||||||
|
|
||||||
%this.importer.resetImportSession(true);
|
%this.importer.resetImportSession(true);
|
||||||
|
|
||||||
Canvas.popDialog( EditorLoadingGui );
|
hideEditorLoadingGui();
|
||||||
|
|
||||||
//do the actual importing, now!
|
//do the actual importing, now!
|
||||||
/*%assetCount = ImportAssetItems.count();
|
/*%assetCount = ImportAssetItems.count();
|
||||||
|
|
|
||||||
|
|
@ -244,10 +244,48 @@ function AssetBrowser::importShapeAsset(%this, %assetItem)
|
||||||
|
|
||||||
function AssetBrowser::buildShapeAssetPreview(%this, %assetDef, %previewData)
|
function AssetBrowser::buildShapeAssetPreview(%this, %assetDef, %previewData)
|
||||||
{
|
{
|
||||||
|
%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getShapeFile())));
|
||||||
|
%previewPath = "tools/resources/shapePreviewCache/" @ %module.moduleId @ "/";
|
||||||
|
|
||||||
|
if(!IsDirectory(%previewPath))
|
||||||
|
{
|
||||||
|
%this.dirHandler.createFolder(%previewPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
%previewPath = %previewPath @ %assetDef.assetName @ "_Preview.png";
|
||||||
|
if(!isFile(%previewPath))
|
||||||
|
{
|
||||||
|
displayEditorLoadingGui("Generating Shape Asset Preview...");
|
||||||
|
|
||||||
|
//This is slightly hacky, but we're going to utilize the imposter/last detail system
|
||||||
|
//to generate our previews for us and then clean up the unneeded bits
|
||||||
|
%oldImposterSetting = $TSLastDetail::dumpImposters;
|
||||||
|
$TSLastDetail::dumpImposters = true;
|
||||||
|
|
||||||
|
%filePath = %assetDef.generateCachedPreviewImage();
|
||||||
|
|
||||||
|
%imposterPath = %filePath @ ".imposter.png";
|
||||||
|
pathCopy(%imposterPath, %previewPath);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
fileDelete(%imposterPath);
|
||||||
|
fileDelete(%filePath @ ".imposter.dds");
|
||||||
|
fileDelete(%filePath @ ".imposter_normals.png");
|
||||||
|
fileDelete(%filePath @ ".imposter_normals.dds");
|
||||||
|
|
||||||
|
$TSLastDetail::dumpImposters = %oldImposterSetting;
|
||||||
|
|
||||||
|
hideEditorLoadingGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Revalidate. If it didn't work, just use the default placeholder one
|
||||||
|
if(!isFile(%previewPath))
|
||||||
|
%previewPath = "tools/assetBrowser/art/genericAssetIcon";
|
||||||
|
|
||||||
%previewData.assetName = %assetDef.assetName;
|
%previewData.assetName = %assetDef.assetName;
|
||||||
%previewData.assetPath = %assetDef.fileName;
|
%previewData.assetPath = %assetDef.fileName;
|
||||||
|
|
||||||
%previewData.previewImage = "tools/assetBrowser/art/genericAssetIcon";//%assetDef.fileName;
|
%previewData.previewImage = %previewPath;//%assetDef.fileName;
|
||||||
|
|
||||||
%previewData.assetFriendlyName = %assetDef.assetName;
|
%previewData.assetFriendlyName = %assetDef.assetName;
|
||||||
%previewData.assetDesc = %assetDef.description;
|
%previewData.assetDesc = %assetDef.description;
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@
|
||||||
isContainer = "0";
|
isContainer = "0";
|
||||||
canSave = "1";
|
canSave = "1";
|
||||||
canSaveDynamicFields = "0";
|
canSaveDynamicFields = "0";
|
||||||
|
internalName = "loadingText";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -73,3 +74,19 @@ function EditorLoadingGui::onWake(%this)
|
||||||
%posY = (%resY / 2) - (%dialogHeight / 2);
|
%posY = (%resY / 2) - (%dialogHeight / 2);
|
||||||
%dialog.setPosition(%posX, %posY);
|
%dialog.setPosition(%posX, %posY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function displayEditorLoadingGui(%displayText)
|
||||||
|
{
|
||||||
|
if(%displayText $= "")
|
||||||
|
%displayText = "Loading the Editor...";
|
||||||
|
|
||||||
|
EditorLoadingGui-->loadingText.setText(%displayText);
|
||||||
|
|
||||||
|
Canvas.pushDialog( EditorLoadingGui );
|
||||||
|
Canvas.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideEditorLoadingGui()
|
||||||
|
{
|
||||||
|
Canvas.popDialog( EditorLoadingGui );
|
||||||
|
}
|
||||||
|
|
@ -261,12 +261,11 @@ function fastLoadWorldEdit(%val)
|
||||||
{
|
{
|
||||||
if(!$Tools::loaded)
|
if(!$Tools::loaded)
|
||||||
{
|
{
|
||||||
canvas.pushDialog( EditorLoadingGui );
|
displayEditorLoadingGui();
|
||||||
canvas.repaint();
|
|
||||||
|
|
||||||
onStart();
|
onStart();
|
||||||
|
|
||||||
canvas.popDialog(EditorLoadingGui);
|
hideEditorLoadingGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
%timerId = startPrecisionTimer();
|
%timerId = startPrecisionTimer();
|
||||||
|
|
@ -304,8 +303,7 @@ function fastLoadWorldEdit(%val)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
canvas.pushDialog( EditorLoadingGui );
|
displayEditorLoadingGui();
|
||||||
canvas.repaint();
|
|
||||||
|
|
||||||
Editor.open();
|
Editor.open();
|
||||||
|
|
||||||
|
|
@ -317,7 +315,7 @@ function fastLoadWorldEdit(%val)
|
||||||
if (theLevelInfo.type $= "DemoScene")
|
if (theLevelInfo.type $= "DemoScene")
|
||||||
commandToServer('dropCameraAtPlayer', true);
|
commandToServer('dropCameraAtPlayer', true);
|
||||||
|
|
||||||
canvas.popDialog(EditorLoadingGui);
|
hideEditorLoadingGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
popInstantGroup();
|
popInstantGroup();
|
||||||
|
|
@ -334,12 +332,11 @@ function fastLoadGUIEdit(%val)
|
||||||
{
|
{
|
||||||
if(!$Tools::loaded)
|
if(!$Tools::loaded)
|
||||||
{
|
{
|
||||||
canvas.pushDialog( EditorLoadingGui );
|
displayEditorLoadingGui();
|
||||||
canvas.repaint();
|
|
||||||
|
|
||||||
onStart();
|
onStart();
|
||||||
|
|
||||||
canvas.popDialog(EditorLoadingGui);
|
hideEditorLoadingGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleGuiEditor(true);
|
toggleGuiEditor(true);
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,7 @@ function toggleEditor(%make)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
canvas.pushDialog( EditorLoadingGui );
|
displayEditorLoadingGui();
|
||||||
canvas.repaint();
|
|
||||||
|
|
||||||
Editor.open();
|
Editor.open();
|
||||||
|
|
||||||
|
|
@ -151,7 +150,7 @@ function toggleEditor(%make)
|
||||||
if (theLevelInfo.type $= "DemoScene")
|
if (theLevelInfo.type $= "DemoScene")
|
||||||
commandToServer('dropCameraAtPlayer', true);
|
commandToServer('dropCameraAtPlayer', true);
|
||||||
|
|
||||||
canvas.popDialog(EditorLoadingGui);
|
hideEditorLoadingGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
popInstantGroup();
|
popInstantGroup();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue