2015-10-13 20:19:36 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
# ifndef _SHAPE_ASSET_H_
# include "ShapeAsset.h"
# endif
# ifndef _ASSET_MANAGER_H_
# include "assets/assetManager.h"
# endif
# ifndef _CONSOLETYPES_H_
# include "console/consoleTypes.h"
# endif
# ifndef _TAML_
# include "persistence/taml/taml.h"
# endif
# ifndef _ASSET_PTR_H_
# include "assets/assetPtr.h"
# endif
# include "core/resourceManager.h"
// Debug Profiling.
# include "platform/profiler.h"
2020-05-17 06:38:17 +00:00
# include "T3D/assets/assetImporter.h"
2015-10-13 20:19:36 +00:00
2021-01-27 07:54:26 +00:00
# ifdef TORQUE_TOOLS
# include "ts/tsLastDetail.h"
# endif
Adjusted callback handling of asset inspector fields when invoking AB to select asset for more consistent behavior and better handling of updating the objects and inspector
Added logic to forcefully acquire newly imported asset definition to better try and ensure it's loaded immediately after import
Added logic to asset importer so if a file is not found for an importing material asset, if populate maps is on, then it will try and find a matching image asset in the destination module
Added logic to tsStatic to better handle fields being updated via the editor, forcing updates and refreshes of the shape and materialSlots
Fixed handling of guiBitmapButtonCtrl so it will update the bitmap used when edited via the Gui Editor
Updated image ref to the hudFill image asset for the console GUI
Cleaned up names for the default camera model/material
Defaulted import config to utilize the Prune action instead of rename for more predictable default behavior
Added icons next to AB's preview slider bar for additional visual feedback of slider intent
Added missing checkbox to asset import window and cleaned up scaling behavior
Fixed handling of drag-n-drop behavior in GUI editor so it doesn't block further interaction
Added logic for drag-n-drop of image assets to GUI Editor so it will create a GuiBitmapCtrl with the image
Added handling for drag-n-drop import of folders of assets to AB/Asset Import
Added missing asset import config option to indicate if config supported import of sound assets
Added logic when opening asset import config editor, where if there is a default import config set in the settings, it will open that one by default
Hid the collision section of the import config editor, as those options are currently unutilized
Improved behavior for Create New Folder window in the AB, now always pushing to the front, and also selecting the text by default, so the user can just start typing the new name
Also added return and escape key accelerators to Create New Folder window for better UX
Fixed display of editor windows, adding a distinct blue color to highlighted windows' title bar and fixing display of minimize/maximize/window/close buttons
Moved GUIEditor's onControlDropped function to the AB script to match placement of sibling world editor function
Fixed issue with material editor where the ORM Config map slot was getting the normal map instead of the correct ORM map
2021-11-26 22:40:15 +00:00
# include "util/imposterCapture.h"
2021-01-27 07:54:26 +00:00
2021-12-24 23:26:45 +00:00
# include "ts/tsShapeInstance.h"
# include "gfx/bitmap/imageUtils.h"
2021-08-22 00:48:26 +00:00
StringTableEntry ShapeAsset : : smNoShapeAssetFallback = NULL ;
2021-07-19 06:07:08 +00:00
2015-10-13 20:19:36 +00:00
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT ( ShapeAsset ) ;
2025-06-20 14:58:20 +00:00
//-----------------------------------------------------------------------------
// REFACTOR
//-----------------------------------------------------------------------------
IMPLEMENT_STRUCT ( AssetPtr < ShapeAsset > , AssetPtrShapeAsset , , " " )
END_IMPLEMENT_STRUCT
ConsoleType ( ShapeAssetPtr , TypeShapeAssetPtr , AssetPtr < ShapeAsset > , ASSET_ID_FIELD_PREFIX )
2015-10-13 20:19:36 +00:00
ConsoleGetType ( TypeShapeAssetPtr )
{
// Fetch asset Id.
2019-11-18 09:30:04 +00:00
return ( * ( ( AssetPtr < ShapeAsset > * ) dptr ) ) . getAssetId ( ) ;
2015-10-13 20:19:36 +00:00
}
2020-04-15 17:15:12 +00:00
ConsoleSetType ( TypeShapeAssetPtr )
{
// Was a single argument specified?
if ( argc = = 1 )
{
// Yes, so fetch field value.
const char * pFieldValue = argv [ 0 ] ;
2025-06-20 14:58:20 +00:00
// Fetch asset pointer.
AssetPtr < ShapeAsset > * pAssetPtr = dynamic_cast < AssetPtr < ShapeAsset > * > ( ( AssetPtrBase * ) ( dptr ) ) ;
// Is the asset pointer the correct type?
if ( pAssetPtr = = NULL )
{
Con : : warnf ( " (TypeShapeAssetPtr) - Failed to set asset Id '%d'. " , pFieldValue ) ;
return ;
}
2020-04-15 17:15:12 +00:00
2025-06-20 14:58:20 +00:00
// Set asset.
pAssetPtr - > setAssetId ( pFieldValue ) ;
2020-04-15 17:15:12 +00:00
return ;
}
// Warn.
2025-06-20 14:58:20 +00:00
Con : : warnf ( " (TypeShapeAssetPtr) - Cannot set multiple args to a single asset. " ) ;
2020-04-15 17:15:12 +00:00
}
2015-10-13 20:19:36 +00:00
//-----------------------------------------------------------------------------
2021-07-19 06:07:08 +00:00
ConsoleType ( assetIdString , TypeShapeAssetId , const char * , ASSET_ID_FIELD_PREFIX )
2020-04-15 17:15:12 +00:00
ConsoleGetType ( TypeShapeAssetId )
{
// Fetch asset Id.
return * ( ( const char * * ) ( dptr ) ) ;
}
ConsoleSetType ( TypeShapeAssetId )
2015-10-13 20:19:36 +00:00
{
// Was a single argument specified?
if ( argc = = 1 )
{
// Yes, so fetch field value.
2021-07-19 06:07:08 +00:00
* ( ( const char * * ) dptr ) = StringTable - > insert ( argv [ 0 ] ) ;
2015-10-13 20:19:36 +00:00
return ;
}
// Warn.
2018-01-28 20:48:02 +00:00
Con : : warnf ( " (TypeAssetId) - Cannot set multiple args to a single asset. " ) ;
2015-10-13 20:19:36 +00:00
}
2025-06-19 12:34:07 +00:00
//-----------------------------------------------------------------------------
// REFACTOR END
//-----------------------------------------------------------------------------
2023-10-08 18:19:43 +00:00
const String ShapeAsset : : mErrCodeStrings [ ] =
2020-12-03 21:37:51 +00:00
{
" TooManyVerts " ,
" TooManyBones " ,
" MissingAnimatons " ,
" UnKnown "
} ;
//-----------------------------------------------------------------------------
2015-10-13 20:19:36 +00:00
2018-01-28 20:48:02 +00:00
ShapeAsset : : ShapeAsset ( )
2015-10-13 20:19:36 +00:00
{
2025-06-20 14:58:20 +00:00
mShapeFile = StringTable - > EmptyString ( ) ;
Updated path handling for loose asset files for CPP, Image, Level, Material, PostFX, Shape, Terrain, TerrainMat and StateMachine assets to be more predictable in when and how they expando the loose file path into a full, useable path
Fixed loose file bindings for all associated slots in level asset, such as postFX file, decals, etc
Expanded TSStatic onInspect testcase to parse materialSlots and hook-in a specialized material field for editing/quick reference from the inspector
Adjusted expand behavior of guiTree to be more reliable
Added internal name 'stack' to inspectorGroup's stack child objects for easier access to add programatic fields
Removed redundant PreMult translucency type code
Added setting of feature so probes work when in forward/basic lit mode
Corrected indexing error in SQLiteObject class so it properly parses with the updated console API
Tweaked the FOV setting logic in GameConnection::onControlObjectChange to not be spammy
Fixed var when trying to bind the camera to the client
Added project setting field to dictate the default render mode between Forward or Deferred
Integrated MotionBlur PostFX into updated PostFX Editor paradigm and exposed the samples uniform as an editable field
Integrated DOF PostFX into updated PostFX Editor paradigm
Updated setting group name for vignette postFX
Shifted shaderCache to be in data/cache along with other cached files
Added helper function to replace strings in a file
Fixed ExampleCppObject asset to have correct loose file references
Adjusted editor default level logic so it can be modifed and then stored, as well as reset back to the original default
Fixed verve reference to root scene group
Adjusted location of a nonmodal gui profile so it loads at the correct time
Reorganized AssetBrowser loading and refresh logic so it doesn't stack multiple refresh requests back-to-back causing lag
Updated the search behavior to search not just the current address, but all child folders as well, making it far more useful
Initial work into zip and folder drag-and-drop asset importing support
Removed the import config setting for 'always display material maps' as it is redundant with the new importer context menu actions
Updated example asset type file
Ensured all asset types have proper handling for move, rename and delete actions
Fixed double-click behavior on folders in the AB
Fixed CPP asset preview
Added better logic to discern if a top-level folder belongs to a module or not in the AB directory browser
Added ability to convert a non-module top-level folder in the AB into a module
Added initial hooks for being able to generate a new Editor Tool, similar to how the AB can generate modules
Renamed CPP asset template files to have the .template so they aren't accidentally picked up by cmake
Fixed convex editor's material handling to work with AB and reference back properly
Updated AB images for folder up/down navigation buttons, and the breadcrumb divider arrow
Made PostFX Editor properly allow for input pass-through so you can still edit the level with it open
Added some additional common text gui profiles
Disabled calls to old editor settings logic in various editors to remove spam
Added callOnModules call so tools can initialize properly when the world editor is opened
Fixed logic test for visualizers
Added ability for cmake to scan tools directory for any tools that add source files
2020-02-04 07:47:28 +00:00
mConstructorFileName = StringTable - > EmptyString ( ) ;
2021-12-10 06:01:26 +00:00
mDiffuseImposterFileName = StringTable - > EmptyString ( ) ;
mNormalImposterFileName = StringTable - > EmptyString ( ) ;
2020-12-02 01:16:36 +00:00
mLoadedState = AssetErrCode : : NotLoaded ;
2015-10-13 20:19:36 +00:00
}
//-----------------------------------------------------------------------------
ShapeAsset : : ~ ShapeAsset ( )
{
}
//-----------------------------------------------------------------------------
2021-07-19 06:07:08 +00:00
void ShapeAsset : : consoleInit ( )
{
Parent : : consoleInit ( ) ;
Con : : addVariable ( " $Core::NoShapeAssetFallback " , TypeString , & smNoShapeAssetFallback ,
" The assetId of the shape to display when the requested shape asset is missing. \n "
" @ingroup GFX \n " ) ;
2021-08-22 00:48:26 +00:00
smNoShapeAssetFallback = StringTable - > insert ( Con : : getVariable ( " $Core::NoShapeAssetFallback " ) ) ;
2021-07-19 06:07:08 +00:00
}
//-----------------------------------------------------------------------------
2015-10-13 20:19:36 +00:00
void ShapeAsset : : initPersistFields ( )
{
2023-01-27 07:13:15 +00:00
docsURL ;
2015-10-13 20:19:36 +00:00
// Call parent.
Parent : : initPersistFields ( ) ;
2025-06-20 14:58:20 +00:00
addProtectedField ( " fileName " , TypeAssetLooseFilePath , Offset ( mShapeFile , ShapeAsset ) ,
2019-05-04 16:49:42 +00:00
& setShapeFile , & getShapeFile , " Path to the shape file we want to render " ) ;
Updated path handling for loose asset files for CPP, Image, Level, Material, PostFX, Shape, Terrain, TerrainMat and StateMachine assets to be more predictable in when and how they expando the loose file path into a full, useable path
Fixed loose file bindings for all associated slots in level asset, such as postFX file, decals, etc
Expanded TSStatic onInspect testcase to parse materialSlots and hook-in a specialized material field for editing/quick reference from the inspector
Adjusted expand behavior of guiTree to be more reliable
Added internal name 'stack' to inspectorGroup's stack child objects for easier access to add programatic fields
Removed redundant PreMult translucency type code
Added setting of feature so probes work when in forward/basic lit mode
Corrected indexing error in SQLiteObject class so it properly parses with the updated console API
Tweaked the FOV setting logic in GameConnection::onControlObjectChange to not be spammy
Fixed var when trying to bind the camera to the client
Added project setting field to dictate the default render mode between Forward or Deferred
Integrated MotionBlur PostFX into updated PostFX Editor paradigm and exposed the samples uniform as an editable field
Integrated DOF PostFX into updated PostFX Editor paradigm
Updated setting group name for vignette postFX
Shifted shaderCache to be in data/cache along with other cached files
Added helper function to replace strings in a file
Fixed ExampleCppObject asset to have correct loose file references
Adjusted editor default level logic so it can be modifed and then stored, as well as reset back to the original default
Fixed verve reference to root scene group
Adjusted location of a nonmodal gui profile so it loads at the correct time
Reorganized AssetBrowser loading and refresh logic so it doesn't stack multiple refresh requests back-to-back causing lag
Updated the search behavior to search not just the current address, but all child folders as well, making it far more useful
Initial work into zip and folder drag-and-drop asset importing support
Removed the import config setting for 'always display material maps' as it is redundant with the new importer context menu actions
Updated example asset type file
Ensured all asset types have proper handling for move, rename and delete actions
Fixed double-click behavior on folders in the AB
Fixed CPP asset preview
Added better logic to discern if a top-level folder belongs to a module or not in the AB directory browser
Added ability to convert a non-module top-level folder in the AB into a module
Added initial hooks for being able to generate a new Editor Tool, similar to how the AB can generate modules
Renamed CPP asset template files to have the .template so they aren't accidentally picked up by cmake
Fixed convex editor's material handling to work with AB and reference back properly
Updated AB images for folder up/down navigation buttons, and the breadcrumb divider arrow
Made PostFX Editor properly allow for input pass-through so you can still edit the level with it open
Added some additional common text gui profiles
Disabled calls to old editor settings logic in various editors to remove spam
Added callOnModules call so tools can initialize properly when the world editor is opened
Fixed logic test for visualizers
Added ability for cmake to scan tools directory for any tools that add source files
2020-02-04 07:47:28 +00:00
addProtectedField ( " constuctorFileName " , TypeAssetLooseFilePath , Offset ( mConstructorFileName , ShapeAsset ) ,
& setShapeConstructorFile , & getShapeConstructorFile , " Path to the shape file we want to render " ) ;
2021-12-10 06:01:26 +00:00
addProtectedField ( " diffuseImposterFileName " , TypeAssetLooseFilePath , Offset ( mDiffuseImposterFileName , ShapeAsset ) ,
& setDiffuseImposterFile , & getDiffuseImposterFile , " Path to the diffuse imposter file we want to render " ) ;
addProtectedField ( " normalImposterFileName " , TypeAssetLooseFilePath , Offset ( mNormalImposterFileName , ShapeAsset ) ,
2025-06-20 16:13:20 +00:00
& setNormalImposterFile , & getNormalImposterFile , " Path to the normal imposter file we want to render " ) ;
2021-12-10 06:01:26 +00:00
2018-01-28 20:48:02 +00:00
}
2021-07-19 06:07:08 +00:00
void ShapeAsset : : setDataField ( StringTableEntry slotName , StringTableEntry array , StringTableEntry value )
2018-01-28 20:48:02 +00:00
{
Parent : : setDataField ( slotName , array , value ) ;
//Now, if it's a material slot of some fashion, set it up
StringTableEntry matSlotName = StringTable - > insert ( " materialAsset " ) ;
if ( String ( slotName ) . startsWith ( matSlotName ) )
{
StringTableEntry matId = StringTable - > insert ( value ) ;
mMaterialAssetIds . push_back ( matId ) ;
}
2015-10-13 20:19:36 +00:00
}
void ShapeAsset : : initializeAsset ( )
{
// Call parent.
Parent : : initializeAsset ( ) ;
2025-06-20 14:58:20 +00:00
if ( mShapeFile = = StringTable - > EmptyString ( ) )
2019-05-04 16:49:42 +00:00
return ;
ResourceManager : : get ( ) . getChangedSignal ( ) . notify ( this , & ShapeAsset : : _onResourceChanged ) ;
2019-05-12 02:42:27 +00:00
//Ensure our path is expando'd if it isn't already
2025-06-20 14:58:20 +00:00
mShapeFile = getOwned ( ) ? expandAssetFilePath ( mShapeFile ) : mShapeFile ;
mConstructorFileName = getOwned ( ) ? expandAssetFilePath ( mConstructorFileName ) : mConstructorFileName ;
if ( ! Torque : : FS : : IsFile ( mConstructorFileName ) )
Con : : errorf ( " ShapeAsset::initializeAsset (%s) could not find %s! " , getAssetName ( ) , mConstructorFileName ) ;
2019-05-12 02:42:27 +00:00
2025-06-20 14:58:20 +00:00
mDiffuseImposterFileName = getOwned ( ) ? expandAssetFilePath ( mDiffuseImposterFileName ) : mDiffuseImposterFileName ;
if ( mDiffuseImposterFileName = = StringTable - > EmptyString ( ) )
2021-12-10 06:01:26 +00:00
{
2025-06-20 14:58:20 +00:00
String diffusePath = String ( mShapeFile ) + " _imposter.dds " ;
mDiffuseImposterFileName = StringTable - > insert ( diffusePath . c_str ( ) ) ;
2021-12-10 06:01:26 +00:00
}
2025-06-20 14:58:20 +00:00
mNormalImposterFileName = getOwned ( ) ? expandAssetFilePath ( mNormalImposterFileName ) : mNormalImposterFileName ;
if ( mNormalImposterFileName = = StringTable - > EmptyString ( ) )
2021-12-10 06:01:26 +00:00
{
2025-06-20 14:58:20 +00:00
String normalPath = String ( mShapeFile ) + " _imposter_normals.dds " ;
mNormalImposterFileName = StringTable - > insert ( normalPath . c_str ( ) ) ;
2021-12-10 06:01:26 +00:00
}
2019-05-04 16:49:42 +00:00
}
void ShapeAsset : : setShapeFile ( const char * pShapeFile )
{
// Sanity!
AssertFatal ( pShapeFile ! = NULL , " Cannot use a NULL shape file. " ) ;
// Fetch image file.
2021-08-22 04:12:37 +00:00
pShapeFile = StringTable - > insert ( pShapeFile , true ) ;
2019-05-04 16:49:42 +00:00
// Ignore no change,
2025-06-20 14:58:20 +00:00
if ( pShapeFile = = mShapeFile )
2019-05-04 16:49:42 +00:00
return ;
2025-06-20 14:58:20 +00:00
mShapeFile = getOwned ( ) ? expandAssetFilePath ( pShapeFile ) : pShapeFile ;
2019-05-04 16:49:42 +00:00
// Refresh the asset.
refreshAsset ( ) ;
}
Updated path handling for loose asset files for CPP, Image, Level, Material, PostFX, Shape, Terrain, TerrainMat and StateMachine assets to be more predictable in when and how they expando the loose file path into a full, useable path
Fixed loose file bindings for all associated slots in level asset, such as postFX file, decals, etc
Expanded TSStatic onInspect testcase to parse materialSlots and hook-in a specialized material field for editing/quick reference from the inspector
Adjusted expand behavior of guiTree to be more reliable
Added internal name 'stack' to inspectorGroup's stack child objects for easier access to add programatic fields
Removed redundant PreMult translucency type code
Added setting of feature so probes work when in forward/basic lit mode
Corrected indexing error in SQLiteObject class so it properly parses with the updated console API
Tweaked the FOV setting logic in GameConnection::onControlObjectChange to not be spammy
Fixed var when trying to bind the camera to the client
Added project setting field to dictate the default render mode between Forward or Deferred
Integrated MotionBlur PostFX into updated PostFX Editor paradigm and exposed the samples uniform as an editable field
Integrated DOF PostFX into updated PostFX Editor paradigm
Updated setting group name for vignette postFX
Shifted shaderCache to be in data/cache along with other cached files
Added helper function to replace strings in a file
Fixed ExampleCppObject asset to have correct loose file references
Adjusted editor default level logic so it can be modifed and then stored, as well as reset back to the original default
Fixed verve reference to root scene group
Adjusted location of a nonmodal gui profile so it loads at the correct time
Reorganized AssetBrowser loading and refresh logic so it doesn't stack multiple refresh requests back-to-back causing lag
Updated the search behavior to search not just the current address, but all child folders as well, making it far more useful
Initial work into zip and folder drag-and-drop asset importing support
Removed the import config setting for 'always display material maps' as it is redundant with the new importer context menu actions
Updated example asset type file
Ensured all asset types have proper handling for move, rename and delete actions
Fixed double-click behavior on folders in the AB
Fixed CPP asset preview
Added better logic to discern if a top-level folder belongs to a module or not in the AB directory browser
Added ability to convert a non-module top-level folder in the AB into a module
Added initial hooks for being able to generate a new Editor Tool, similar to how the AB can generate modules
Renamed CPP asset template files to have the .template so they aren't accidentally picked up by cmake
Fixed convex editor's material handling to work with AB and reference back properly
Updated AB images for folder up/down navigation buttons, and the breadcrumb divider arrow
Made PostFX Editor properly allow for input pass-through so you can still edit the level with it open
Added some additional common text gui profiles
Disabled calls to old editor settings logic in various editors to remove spam
Added callOnModules call so tools can initialize properly when the world editor is opened
Fixed logic test for visualizers
Added ability for cmake to scan tools directory for any tools that add source files
2020-02-04 07:47:28 +00:00
void ShapeAsset : : setShapeConstructorFile ( const char * pShapeConstructorFile )
{
// Sanity!
AssertFatal ( pShapeConstructorFile ! = NULL , " Cannot use a NULL shape constructor file. " ) ;
// Fetch image file.
2021-08-22 04:12:37 +00:00
pShapeConstructorFile = StringTable - > insert ( pShapeConstructorFile , true ) ;
Updated path handling for loose asset files for CPP, Image, Level, Material, PostFX, Shape, Terrain, TerrainMat and StateMachine assets to be more predictable in when and how they expando the loose file path into a full, useable path
Fixed loose file bindings for all associated slots in level asset, such as postFX file, decals, etc
Expanded TSStatic onInspect testcase to parse materialSlots and hook-in a specialized material field for editing/quick reference from the inspector
Adjusted expand behavior of guiTree to be more reliable
Added internal name 'stack' to inspectorGroup's stack child objects for easier access to add programatic fields
Removed redundant PreMult translucency type code
Added setting of feature so probes work when in forward/basic lit mode
Corrected indexing error in SQLiteObject class so it properly parses with the updated console API
Tweaked the FOV setting logic in GameConnection::onControlObjectChange to not be spammy
Fixed var when trying to bind the camera to the client
Added project setting field to dictate the default render mode between Forward or Deferred
Integrated MotionBlur PostFX into updated PostFX Editor paradigm and exposed the samples uniform as an editable field
Integrated DOF PostFX into updated PostFX Editor paradigm
Updated setting group name for vignette postFX
Shifted shaderCache to be in data/cache along with other cached files
Added helper function to replace strings in a file
Fixed ExampleCppObject asset to have correct loose file references
Adjusted editor default level logic so it can be modifed and then stored, as well as reset back to the original default
Fixed verve reference to root scene group
Adjusted location of a nonmodal gui profile so it loads at the correct time
Reorganized AssetBrowser loading and refresh logic so it doesn't stack multiple refresh requests back-to-back causing lag
Updated the search behavior to search not just the current address, but all child folders as well, making it far more useful
Initial work into zip and folder drag-and-drop asset importing support
Removed the import config setting for 'always display material maps' as it is redundant with the new importer context menu actions
Updated example asset type file
Ensured all asset types have proper handling for move, rename and delete actions
Fixed double-click behavior on folders in the AB
Fixed CPP asset preview
Added better logic to discern if a top-level folder belongs to a module or not in the AB directory browser
Added ability to convert a non-module top-level folder in the AB into a module
Added initial hooks for being able to generate a new Editor Tool, similar to how the AB can generate modules
Renamed CPP asset template files to have the .template so they aren't accidentally picked up by cmake
Fixed convex editor's material handling to work with AB and reference back properly
Updated AB images for folder up/down navigation buttons, and the breadcrumb divider arrow
Made PostFX Editor properly allow for input pass-through so you can still edit the level with it open
Added some additional common text gui profiles
Disabled calls to old editor settings logic in various editors to remove spam
Added callOnModules call so tools can initialize properly when the world editor is opened
Fixed logic test for visualizers
Added ability for cmake to scan tools directory for any tools that add source files
2020-02-04 07:47:28 +00:00
// Ignore no change,
if ( pShapeConstructorFile = = mConstructorFileName )
return ;
2021-08-22 04:12:37 +00:00
mConstructorFileName = getOwned ( ) ? expandAssetFilePath ( pShapeConstructorFile ) : pShapeConstructorFile ;
Updated path handling for loose asset files for CPP, Image, Level, Material, PostFX, Shape, Terrain, TerrainMat and StateMachine assets to be more predictable in when and how they expando the loose file path into a full, useable path
Fixed loose file bindings for all associated slots in level asset, such as postFX file, decals, etc
Expanded TSStatic onInspect testcase to parse materialSlots and hook-in a specialized material field for editing/quick reference from the inspector
Adjusted expand behavior of guiTree to be more reliable
Added internal name 'stack' to inspectorGroup's stack child objects for easier access to add programatic fields
Removed redundant PreMult translucency type code
Added setting of feature so probes work when in forward/basic lit mode
Corrected indexing error in SQLiteObject class so it properly parses with the updated console API
Tweaked the FOV setting logic in GameConnection::onControlObjectChange to not be spammy
Fixed var when trying to bind the camera to the client
Added project setting field to dictate the default render mode between Forward or Deferred
Integrated MotionBlur PostFX into updated PostFX Editor paradigm and exposed the samples uniform as an editable field
Integrated DOF PostFX into updated PostFX Editor paradigm
Updated setting group name for vignette postFX
Shifted shaderCache to be in data/cache along with other cached files
Added helper function to replace strings in a file
Fixed ExampleCppObject asset to have correct loose file references
Adjusted editor default level logic so it can be modifed and then stored, as well as reset back to the original default
Fixed verve reference to root scene group
Adjusted location of a nonmodal gui profile so it loads at the correct time
Reorganized AssetBrowser loading and refresh logic so it doesn't stack multiple refresh requests back-to-back causing lag
Updated the search behavior to search not just the current address, but all child folders as well, making it far more useful
Initial work into zip and folder drag-and-drop asset importing support
Removed the import config setting for 'always display material maps' as it is redundant with the new importer context menu actions
Updated example asset type file
Ensured all asset types have proper handling for move, rename and delete actions
Fixed double-click behavior on folders in the AB
Fixed CPP asset preview
Added better logic to discern if a top-level folder belongs to a module or not in the AB directory browser
Added ability to convert a non-module top-level folder in the AB into a module
Added initial hooks for being able to generate a new Editor Tool, similar to how the AB can generate modules
Renamed CPP asset template files to have the .template so they aren't accidentally picked up by cmake
Fixed convex editor's material handling to work with AB and reference back properly
Updated AB images for folder up/down navigation buttons, and the breadcrumb divider arrow
Made PostFX Editor properly allow for input pass-through so you can still edit the level with it open
Added some additional common text gui profiles
Disabled calls to old editor settings logic in various editors to remove spam
Added callOnModules call so tools can initialize properly when the world editor is opened
Fixed logic test for visualizers
Added ability for cmake to scan tools directory for any tools that add source files
2020-02-04 07:47:28 +00:00
// Refresh the asset.
refreshAsset ( ) ;
}
2021-12-10 06:01:26 +00:00
void ShapeAsset : : setDiffuseImposterFile ( const char * pImageFile )
{
// Sanity!
AssertFatal ( pImageFile ! = NULL , " Cannot use a NULL image file. " ) ;
// Fetch image file.
pImageFile = StringTable - > insert ( pImageFile , true ) ;
// Ignore no change,
if ( pImageFile = = mDiffuseImposterFileName )
return ;
mDiffuseImposterFileName = getOwned ( ) ? expandAssetFilePath ( pImageFile ) : pImageFile ;
// Refresh the asset.
refreshAsset ( ) ;
}
void ShapeAsset : : setNormalImposterFile ( const char * pImageFile )
{
// Sanity!
AssertFatal ( pImageFile ! = NULL , " Cannot use a NULL image file. " ) ;
// Fetch image file.
pImageFile = StringTable - > insert ( pImageFile , true ) ;
// Ignore no change,
if ( pImageFile = = mNormalImposterFileName )
return ;
mNormalImposterFileName = getOwned ( ) ? expandAssetFilePath ( pImageFile ) : pImageFile ;
// Refresh the asset.
refreshAsset ( ) ;
}
2019-05-04 16:49:42 +00:00
void ShapeAsset : : _onResourceChanged ( const Torque : : Path & path )
{
2025-06-20 14:58:20 +00:00
if ( path ! = Torque : : Path ( mShapeFile ) )
2015-10-13 20:19:36 +00:00
return ;
2019-05-12 02:42:27 +00:00
refreshAsset ( ) ;
2015-10-13 20:19:36 +00:00
}
2023-11-12 22:33:17 +00:00
U32 ShapeAsset : : load ( )
2015-10-13 20:19:36 +00:00
{
2023-11-12 22:33:17 +00:00
if ( mLoadedState = = AssetErrCode : : Ok ) return mLoadedState ;
2023-10-08 18:19:43 +00:00
2018-01-28 20:48:02 +00:00
mMaterialAssets . clear ( ) ;
mMaterialAssetIds . clear ( ) ;
//First, load any material, animation, etc assets we may be referencing in our asset
// Find any asset dependencies.
AssetManager : : typeAssetDependsOnHash : : Iterator assetDependenciesItr = mpOwningAssetManager - > getDependedOnAssets ( ) - > find ( mpAssetDefinition - > mAssetId ) ;
// Does the asset have any dependencies?
if ( assetDependenciesItr ! = mpOwningAssetManager - > getDependedOnAssets ( ) - > end ( ) )
{
// Iterate all dependencies.
while ( assetDependenciesItr ! = mpOwningAssetManager - > getDependedOnAssets ( ) - > end ( ) & & assetDependenciesItr - > key = = mpAssetDefinition - > mAssetId )
{
StringTableEntry assetType = mpOwningAssetManager - > getAssetType ( assetDependenciesItr - > value ) ;
if ( assetType = = StringTable - > insert ( " MaterialAsset " ) )
{
2019-05-04 16:49:42 +00:00
mMaterialAssetIds . push_front ( assetDependenciesItr - > value ) ;
2018-01-28 20:48:02 +00:00
//Force the asset to become initialized if it hasn't been already
AssetPtr < MaterialAsset > matAsset = assetDependenciesItr - > value ;
2019-05-04 16:49:42 +00:00
mMaterialAssets . push_front ( matAsset ) ;
2018-01-28 20:48:02 +00:00
}
else if ( assetType = = StringTable - > insert ( " ShapeAnimationAsset " ) )
{
mAnimationAssetIds . push_back ( assetDependenciesItr - > value ) ;
//Force the asset to become initialized if it hasn't been already
AssetPtr < ShapeAnimationAsset > animAsset = assetDependenciesItr - > value ;
mAnimationAssets . push_back ( animAsset ) ;
}
// Next dependency.
assetDependenciesItr + + ;
}
}
2025-06-20 14:58:20 +00:00
mShape = ResourceManager : : get ( ) . load ( mShapeFile ) ;
2015-10-13 20:19:36 +00:00
if ( ! mShape )
{
2020-12-02 01:16:36 +00:00
mLoadedState = BadFileReference ;
2023-11-12 22:33:17 +00:00
return mLoadedState ; //if it failed to load, bail out
2015-10-13 20:19:36 +00:00
}
2022-09-29 07:04:51 +00:00
// Construct billboards if not done already
if ( GFXDevice : : devicePresent ( ) )
2025-06-20 14:58:20 +00:00
mShape - > setupBillboardDetails ( mShapeFile , mDiffuseImposterFileName , mNormalImposterFileName ) ;
2021-12-10 06:01:26 +00:00
//If they exist, grab our imposters here and bind them to our shapeAsset
2018-02-04 20:31:28 +00:00
bool hasBlends = false ;
2018-01-28 20:48:02 +00:00
//Now that we've successfully loaded our shape and have any materials and animations loaded
//we need to set up the animations we're using on our shape
2018-02-04 20:31:28 +00:00
for ( S32 i = mAnimationAssets . size ( ) - 1 ; i > = 0 ; - - i )
2018-01-28 20:48:02 +00:00
{
2018-02-04 20:31:28 +00:00
String srcName = mAnimationAssets [ i ] - > getAnimationName ( ) ;
2018-01-28 20:48:02 +00:00
String srcPath ( mAnimationAssets [ i ] - > getAnimationFilename ( ) ) ;
2018-02-04 20:31:28 +00:00
//SplitSequencePathAndName(srcPath, srcName);
2018-01-28 20:48:02 +00:00
2018-02-04 20:31:28 +00:00
if ( ! mShape - > addSequence ( srcPath , srcName , srcName ,
2018-01-28 20:48:02 +00:00
mAnimationAssets [ i ] - > getStartFrame ( ) , mAnimationAssets [ i ] - > getEndFrame ( ) , mAnimationAssets [ i ] - > getPadRotation ( ) , mAnimationAssets [ i ] - > getPadTransforms ( ) ) )
2020-12-02 01:16:36 +00:00
{
mLoadedState = MissingAnimatons ;
2023-11-12 22:33:17 +00:00
return mLoadedState ;
2020-12-02 01:16:36 +00:00
}
2018-02-04 20:31:28 +00:00
if ( mAnimationAssets [ i ] - > isBlend ( ) )
hasBlends = true ;
}
//if any of our animations are blends, set those up now
if ( hasBlends )
{
for ( U32 i = 0 ; i < mAnimationAssets . size ( ) ; + + i )
{
if ( mAnimationAssets [ i ] - > isBlend ( ) & & mAnimationAssets [ i ] - > getBlendAnimationName ( ) ! = StringTable - > EmptyString ( ) )
{
//gotta do a bit of logic here.
//First, we need to make sure the anim asset we depend on for our blend is loaded
AssetPtr < ShapeAnimationAsset > blendAnimAsset = mAnimationAssets [ i ] - > getBlendAnimationName ( ) ;
2023-10-08 18:19:43 +00:00
U32 assetStatus = ShapeAnimationAsset : : getAssetErrCode ( blendAnimAsset ) ;
if ( assetStatus ! = AssetBase : : Ok )
2018-02-04 20:31:28 +00:00
{
Con : : errorf ( " ShapeAsset::initializeAsset - Unable to acquire reference animation asset %s for asset %s to blend! " , mAnimationAssets [ i ] - > getBlendAnimationName ( ) , mAnimationAssets [ i ] - > getAssetName ( ) ) ;
2020-12-02 01:16:36 +00:00
{
mLoadedState = MissingAnimatons ;
2023-11-12 22:33:17 +00:00
return mLoadedState ;
2020-12-02 01:16:36 +00:00
}
2018-02-04 20:31:28 +00:00
}
String refAnimName = blendAnimAsset - > getAnimationName ( ) ;
if ( ! mShape - > setSequenceBlend ( mAnimationAssets [ i ] - > getAnimationName ( ) , true , blendAnimAsset - > getAnimationName ( ) , mAnimationAssets [ i ] - > getBlendFrame ( ) ) )
{
Con : : errorf ( " ShapeAnimationAsset::initializeAsset - Unable to set animation clip %s for asset %s to blend! " , mAnimationAssets [ i ] - > getAnimationName ( ) , mAnimationAssets [ i ] - > getAssetName ( ) ) ;
2020-12-02 01:16:36 +00:00
{
mLoadedState = MissingAnimatons ;
2023-11-12 22:33:17 +00:00
return mLoadedState ;
2020-12-02 01:16:36 +00:00
}
2018-02-04 20:31:28 +00:00
}
}
}
2018-01-28 20:48:02 +00:00
}
2024-04-06 21:39:31 +00:00
mLoadedState = Ok ;
2023-11-12 22:33:17 +00:00
return mLoadedState ;
2015-10-13 20:19:36 +00:00
}
2020-03-19 14:47:38 +00:00
//------------------------------------------------------------------------------
//Utility function to 'fill out' bindings and resources with a matching asset if one exists
2021-07-19 06:07:08 +00:00
U32 ShapeAsset : : getAssetByFilename ( StringTableEntry fileName , AssetPtr < ShapeAsset > * shapeAsset )
2020-03-19 14:47:38 +00:00
{
AssetQuery query ;
S32 foundAssetcount = AssetDatabase . findAssetLooseFile ( & query , fileName ) ;
if ( foundAssetcount = = 0 )
{
2021-07-19 06:07:08 +00:00
//Didn't work, so have us fall back to a placeholder asset
shapeAsset - > setAssetId ( ShapeAsset : : smNoShapeAssetFallback ) ;
2020-03-19 14:47:38 +00:00
2021-07-19 06:07:08 +00:00
if ( shapeAsset - > isNull ( ) )
2020-03-19 14:47:38 +00:00
{
2021-07-19 06:07:08 +00:00
//Well that's bad, loading the fallback failed.
Con : : warnf ( " ShapeAsset::getAssetByFilename - Finding of asset associated with file %s failed with no fallback asset " , fileName ) ;
return AssetErrCode : : Failed ;
2020-05-17 06:38:17 +00:00
}
2020-03-19 14:47:38 +00:00
2021-07-19 06:07:08 +00:00
//handle noshape not being loaded itself
if ( ( * shapeAsset ) - > mLoadedState = = BadFileReference )
2020-05-17 06:38:17 +00:00
{
2021-07-19 06:07:08 +00:00
Con : : warnf ( " ShapeAsset::getAssetByFilename - Finding of associated with file %s failed, and fallback asset reported error of Bad File Reference. " , fileName ) ;
return AssetErrCode : : BadFileReference ;
2020-03-19 14:47:38 +00:00
}
2021-07-19 06:07:08 +00:00
Con : : warnf ( " ShapeAsset::getAssetByFilename - Finding of associated with file %s failed, utilizing fallback asset " , fileName ) ;
2020-03-19 14:47:38 +00:00
2021-07-19 06:07:08 +00:00
( * shapeAsset ) - > mLoadedState = AssetErrCode : : UsingFallback ;
return AssetErrCode : : UsingFallback ;
2020-03-19 14:47:38 +00:00
}
else
{
//acquire and bind the asset, and return it out
shapeAsset - > setAssetId ( query . mAssetList [ 0 ] ) ;
2021-07-19 06:07:08 +00:00
return ( * shapeAsset ) - > mLoadedState ;
2020-03-19 14:47:38 +00:00
}
}
2020-04-15 17:15:12 +00:00
StringTableEntry ShapeAsset : : getAssetIdByFilename ( StringTableEntry fileName )
{
2020-06-26 04:33:01 +00:00
if ( fileName = = StringTable - > EmptyString ( ) )
return StringTable - > EmptyString ( ) ;
2021-07-19 06:07:08 +00:00
StringTableEntry shapeAssetId = ShapeAsset : : smNoShapeAssetFallback ;
2020-04-15 17:15:12 +00:00
AssetQuery query ;
S32 foundAssetcount = AssetDatabase . findAssetLooseFile ( & query , fileName ) ;
2021-07-19 06:07:08 +00:00
if ( foundAssetcount ! = 0 )
2020-04-15 17:15:12 +00:00
{
//acquire and bind the asset, and return it out
shapeAssetId = query . mAssetList [ 0 ] ;
}
2022-04-10 22:29:55 +00:00
else
{
2025-06-19 12:34:07 +00:00
foundAssetcount = AssetDatabase . findAssetType ( & query , " ShapeAsset " ) ;
if ( foundAssetcount ! = 0 )
{
// loop all image assets and see if we can find one
// using the same image file/named target.
for ( auto shapeAsset : query . mAssetList )
{
AssetPtr < ShapeAsset > temp = shapeAsset ;
if ( temp . notNull ( ) )
{
2025-06-20 14:58:20 +00:00
if ( temp - > getShapeFile ( ) = = fileName )
2025-06-19 12:34:07 +00:00
{
return shapeAsset ;
}
else
{
2025-06-20 14:58:20 +00:00
Torque : : Path temp1 = temp - > getShapeFile ( ) ;
2025-06-19 12:34:07 +00:00
Torque : : Path temp2 = fileName ;
if ( temp1 . getPath ( ) = = temp2 . getPath ( ) & & temp1 . getFileName ( ) = = temp2 . getFileName ( ) )
{
return shapeAsset ;
}
}
}
}
}
else
{
AssetPtr < ShapeAsset > shapeAsset = shapeAssetId ; //ensures the fallback is loaded
}
2022-04-10 22:29:55 +00:00
}
2020-04-15 17:15:12 +00:00
return shapeAssetId ;
}
2020-12-02 01:16:36 +00:00
U32 ShapeAsset : : getAssetById ( StringTableEntry assetId , AssetPtr < ShapeAsset > * shapeAsset )
2020-03-19 14:47:38 +00:00
{
2020-04-15 17:15:12 +00:00
( * shapeAsset ) = assetId ;
2020-12-02 01:16:36 +00:00
if ( shapeAsset - > notNull ( ) )
2021-07-19 06:07:08 +00:00
{
return ( * shapeAsset ) - > mLoadedState ;
}
else
2020-12-14 19:33:49 +00:00
{
2021-01-01 00:54:31 +00:00
//Didn't work, so have us fall back to a placeholder asset
2021-07-19 06:07:08 +00:00
shapeAsset - > setAssetId ( ShapeAsset : : smNoShapeAssetFallback ) ;
if ( shapeAsset - > isNull ( ) )
{
//Well that's bad, loading the fallback failed.
Con : : warnf ( " ShapeAsset::getAssetById - Finding of asset with id %s failed with no fallback asset " , assetId ) ;
return AssetErrCode : : Failed ;
}
2021-01-01 00:54:31 +00:00
//handle noshape not being loaded itself
if ( ( * shapeAsset ) - > mLoadedState = = BadFileReference )
2021-07-19 06:07:08 +00:00
{
Con : : warnf ( " ShapeAsset::getAssetById - Finding of asset with id %s failed, and fallback asset reported error of Bad File Reference. " , assetId ) ;
return AssetErrCode : : BadFileReference ;
}
Con : : warnf ( " ShapeAsset::getAssetById - Finding of asset with id %s failed, utilizing fallback asset " , assetId ) ;
2021-01-01 00:54:31 +00:00
2020-12-14 19:33:49 +00:00
( * shapeAsset ) - > mLoadedState = AssetErrCode : : UsingFallback ;
2020-12-02 01:16:36 +00:00
return AssetErrCode : : UsingFallback ;
2020-12-14 19:33:49 +00:00
}
2020-03-19 14:47:38 +00:00
}
2015-10-13 20:19:36 +00:00
//------------------------------------------------------------------------------
void ShapeAsset : : copyTo ( SimObject * object )
{
// Call to parent.
Parent : : copyTo ( object ) ;
2016-06-07 02:20:00 +00:00
}
void ShapeAsset : : onAssetRefresh ( void )
{
2025-06-20 14:58:20 +00:00
// Ignore if not yet added to the sim.
if ( ! isProperlyAdded ( ) )
2018-01-28 20:48:02 +00:00
return ;
2025-06-20 14:58:20 +00:00
if ( mShapeFile = = StringTable - > EmptyString ( ) )
return ;
// Call parent.
Parent : : onAssetRefresh ( ) ;
2024-04-06 19:48:22 +00:00
load ( ) ;
2018-01-28 20:48:02 +00:00
}
2025-06-20 14:58:20 +00:00
void ShapeAsset : : onTamlPreWrite ( void )
{
// Call parent.
Parent : : onTamlPreWrite ( ) ;
// ensure paths are collapsed.
mShapeFile = collapseAssetFilePath ( mShapeFile ) ;
mConstructorFileName = collapseAssetFilePath ( mConstructorFileName ) ;
mDiffuseImposterFileName = collapseAssetFilePath ( mDiffuseImposterFileName ) ;
mNormalImposterFileName = collapseAssetFilePath ( mNormalImposterFileName ) ;
}
void ShapeAsset : : onTamlPostWrite ( void )
{
// Call parent.
Parent : : onTamlPostWrite ( ) ;
// ensure paths are expanded.
mShapeFile = expandAssetFilePath ( mShapeFile ) ;
mConstructorFileName = expandAssetFilePath ( mConstructorFileName ) ;
mDiffuseImposterFileName = expandAssetFilePath ( mDiffuseImposterFileName ) ;
mNormalImposterFileName = expandAssetFilePath ( mNormalImposterFileName ) ;
}
2018-01-28 20:48:02 +00:00
void ShapeAsset : : SplitSequencePathAndName ( String & srcPath , String & srcName )
{
srcName = " " ;
// Determine if there is a sequence name at the end of the source string, and
// if so, split the filename from the sequence name
S32 split = srcPath . find ( ' ' , 0 , String : : Right ) ;
S32 split2 = srcPath . find ( ' \t ' , 0 , String : : Right ) ;
if ( ( split = = String : : NPos ) | | ( split2 > split ) )
split = split2 ;
if ( split ! = String : : NPos )
{
split2 = split + 1 ;
while ( ( srcPath [ split2 ] ! = ' \0 ' ) & & dIsspace ( srcPath [ split2 ] ) )
split2 + + ;
// now 'split' is at the end of the path, and 'split2' is at the start of the sequence name
srcName = srcPath . substr ( split2 ) ;
srcPath = srcPath . erase ( split , srcPath . length ( ) - split ) ;
}
}
ShapeAnimationAsset * ShapeAsset : : getAnimation ( S32 index )
{
if ( index < mAnimationAssets . size ( ) )
{
return mAnimationAssets [ index ] ;
}
return nullptr ;
}
2021-01-27 07:54:26 +00:00
# ifdef TORQUE_TOOLS
2021-12-24 23:26:45 +00:00
const char * ShapeAsset : : generateCachedPreviewImage ( S32 resolution , String overrideMaterial )
2021-01-27 07:54:26 +00:00
{
if ( ! mShape )
return " " ;
2021-12-24 23:26:45 +00:00
// We're gonna render... make sure we can.
bool sceneBegun = GFX - > canCurrentlyRender ( ) ;
if ( ! sceneBegun )
GFX - > beginScene ( ) ;
// We need to create our own instance to render with.
TSShapeInstance * shape = new TSShapeInstance ( mShape , true ) ;
2022-04-04 01:00:30 +00:00
if ( overrideMaterial . isNotEmpty ( ) )
{
Material * tMat = dynamic_cast < Material * > ( Sim : : findObject ( overrideMaterial ) ) ;
if ( tMat )
shape - > reSkin ( tMat - > mMapTo , mShape - > materialList - > getMaterialName ( 0 ) ) ;
}
2021-12-24 23:26:45 +00:00
// Animate the shape once.
shape - > animate ( 0 ) ;
GBitmap * imposter = NULL ;
GBitmap * imposterNrml = NULL ;
ImposterCapture * imposterCap = new ImposterCapture ( ) ;
static const MatrixF topXfm ( EulerF ( - M_PI_F / 2.0f , 0 , 0 ) ) ;
static const MatrixF bottomXfm ( EulerF ( M_PI_F / 2.0f , 0 , 0 ) ) ;
MatrixF angMat ;
PROFILE_START ( ShapeAsset_generateCachedPreviewImage ) ;
//dMemset(destBmp.getWritableBits(mip), 0, destBmp.getWidth(mip) * destBmp.getHeight(mip) * GFXFormat_getByteSize(format));
F32 rotX = - ( mDegToRad ( 60.0 ) - 0.5f * M_PI_F ) ;
F32 rotZ = - ( mDegToRad ( 45.0 ) - 0.5f * M_PI_F ) ;
// We capture the images in a particular order which must
// match the order expected by the imposter renderer.
imposterCap - > begin ( shape , 0 , resolution , mShape - > mRadius , mShape - > center ) ;
angMat . mul ( MatrixF ( EulerF ( rotX , 0 , 0 ) ) ,
MatrixF ( EulerF ( 0 , 0 , rotZ ) ) ) ;
imposterCap - > capture ( angMat , & imposter , & imposterNrml ) ;
imposterCap - > end ( ) ;
PROFILE_END ( ) ; // ShapeAsset_generateCachedPreviewImage
delete imposterCap ;
delete shape ;
2025-06-20 14:58:20 +00:00
String dumpPath = String ( mShapeFile ) + " .png " ;
2021-12-24 23:26:45 +00:00
2022-01-20 07:14:43 +00:00
char * returnBuffer = Con : : getReturnBuffer ( 128 ) ;
dSprintf ( returnBuffer , 128 , " %s " , dumpPath . c_str ( ) ) ;
2021-12-24 23:26:45 +00:00
2025-05-28 22:47:23 +00:00
imposter - > writeBitmap ( " png " , dumpPath ) ;
2021-12-24 23:26:45 +00:00
delete imposter ;
delete imposterNrml ;
2021-01-27 07:54:26 +00:00
2021-12-24 23:26:45 +00:00
// If we did a begin then end it now.
if ( ! sceneBegun )
GFX - > endScene ( ) ;
2021-01-27 07:54:26 +00:00
2021-12-24 23:26:45 +00:00
return returnBuffer ;
2021-01-27 07:54:26 +00:00
}
# endif
2018-01-28 20:48:02 +00:00
DefineEngineMethod ( ShapeAsset , getMaterialCount , S32 , ( ) , ,
" Gets the number of materials for this shape asset. \n "
" @return Material count. \n " )
{
return object - > getMaterialCount ( ) ;
}
DefineEngineMethod ( ShapeAsset , getAnimationCount , S32 , ( ) , ,
" Gets the number of animations for this shape asset. \n "
" @return Animation count. \n " )
{
return object - > getAnimationCount ( ) ;
}
DefineEngineMethod ( ShapeAsset , getAnimation , ShapeAnimationAsset * , ( S32 index ) , ( 0 ) ,
" Gets a particular shape animation asset for this shape. \n "
" @param animation asset index. \n "
" @return Shape Animation Asset. \n " )
{
return object - > getAnimation ( index ) ;
}
2021-01-27 07:54:26 +00:00
2022-04-04 01:00:30 +00:00
DefineEngineMethod ( ShapeAsset , getShapePath , const char * , ( ) , ,
2021-08-02 09:20:27 +00:00
" Gets the shape's file path \n "
" @return The filename of the shape file " )
2021-01-27 07:54:26 +00:00
{
2025-06-20 14:58:20 +00:00
return object - > getShapeFile ( ) ;
2021-01-27 07:54:26 +00:00
}
2021-08-02 09:20:27 +00:00
DefineEngineMethod ( ShapeAsset , getShapeConstructorFilePath , const char * , ( ) , ,
" Gets the shape's constructor file. \n "
" @return The filename of the shape constructor file " )
{
2025-06-20 14:58:20 +00:00
return object - > getShapeConstructorFile ( ) ;
2021-08-02 09:20:27 +00:00
}
2021-07-19 06:07:08 +00:00
DefineEngineMethod ( ShapeAsset , getStatusString , String , ( ) , , " get status string " ) \
{
return ShapeAsset : : getAssetErrstrn ( object - > getStatus ( ) ) ;
}
2021-01-27 07:54:26 +00:00
# ifdef TORQUE_TOOLS
2021-12-24 23:26:45 +00:00
DefineEngineMethod ( ShapeAsset , generateCachedPreviewImage , const char * , ( S32 resolution , const char * overrideMaterialName ) , ( 256 , " " ) ,
" Generates a baked preview image of the given shapeAsset. Only really used for generating Asset Browser icons. \n "
" @param resolution Optional field for what resolution to bake the preview image at. Must be pow2 \n "
" @param overrideMaterialName Optional field for overriding the material used when rendering the shape for the bake. " )
2021-01-27 07:54:26 +00:00
{
2023-11-12 22:33:17 +00:00
object - > load ( ) ;
2021-12-24 23:26:45 +00:00
return object - > generateCachedPreviewImage ( resolution , overrideMaterialName ) ;
2021-01-27 07:54:26 +00:00
}
2021-07-19 06:07:08 +00:00
DefineEngineStaticMethod ( ShapeAsset , getAssetIdByFilename , const char * , ( const char * filePath ) , ( " " ) ,
" Queries the Asset Database to see if any asset exists that is associated with the provided file path. \n "
" @return The AssetId of the associated asset, if any. " )
{
return ShapeAsset : : getAssetIdByFilename ( StringTable - > insert ( filePath ) ) ;
}
2021-01-27 07:54:26 +00:00
# endif
2022-06-13 17:38:08 +00:00
# ifdef TORQUE_TOOLS
2018-01-28 20:48:02 +00:00
//-----------------------------------------------------------------------------
// GuiInspectorTypeAssetId
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT ( GuiInspectorTypeShapeAssetPtr ) ;
ConsoleDocClass ( GuiInspectorTypeShapeAssetPtr ,
" @brief Inspector field type for Shapes \n \n "
" Editor use only. \n \n "
" @internal "
) ;
void GuiInspectorTypeShapeAssetPtr : : consoleInit ( )
{
Parent : : consoleInit ( ) ;
ConsoleBaseType : : getType ( TypeShapeAssetPtr ) - > setInspectorFieldType ( " GuiInspectorTypeShapeAssetPtr " ) ;
}
GuiControl * GuiInspectorTypeShapeAssetPtr : : constructEditControl ( )
{
// Create base filename edit controls
2022-12-09 02:00:55 +00:00
GuiControl * retCtrl = Parent : : constructEditControl ( ) ;
2018-01-28 20:48:02 +00:00
if ( retCtrl = = NULL )
return retCtrl ;
// Change filespec
char szBuffer [ 512 ] ;
2022-12-09 02:00:55 +00:00
const char * previewImage ;
2022-08-26 20:25:17 +00:00
if ( mInspector - > getInspectObject ( ) ! = nullptr )
{
dSprintf ( szBuffer , sizeof ( szBuffer ) , " AssetBrowser.showDialog( \" ShapeAsset \" , \" AssetBrowser.changeAsset \" , %s, %s); " ,
mInspector - > getIdString ( ) , mCaption ) ;
mBrowseButton - > setField ( " Command " , szBuffer ) ;
2018-01-28 20:48:02 +00:00
2022-08-26 20:25:17 +00:00
setDataField ( StringTable - > insert ( " targetObject " ) , NULL , mInspector - > getInspectObject ( ) - > getIdString ( ) ) ;
2022-12-09 02:00:55 +00:00
previewImage = mInspector - > getInspectObject ( ) - > getDataField ( mCaption , NULL ) ;
2022-08-26 20:25:17 +00:00
}
else
{
//if we don't have a target object, we'll be manipulating the desination value directly
2022-08-30 06:29:39 +00:00
dSprintf ( szBuffer , sizeof ( szBuffer ) , " AssetBrowser.showDialog( \" ShapeAsset \" , \" AssetBrowser.changeAsset \" , %s, \" %s \" ); " ,
2022-08-26 20:25:17 +00:00
mInspector - > getIdString ( ) , mVariableName ) ;
mBrowseButton - > setField ( " Command " , szBuffer ) ;
2022-12-09 02:00:55 +00:00
previewImage = Con : : getVariable ( mVariableName ) ;
2022-08-26 20:25:17 +00:00
}
2018-01-28 20:48:02 +00:00
2022-12-09 02:00:55 +00:00
mLabel = new GuiTextCtrl ( ) ;
mLabel - > registerObject ( ) ;
mLabel - > setControlProfile ( mProfile ) ;
mLabel - > setText ( mCaption ) ;
addObject ( mLabel ) ;
//
GuiTextEditCtrl * editTextCtrl = static_cast < GuiTextEditCtrl * > ( retCtrl ) ;
GuiControlProfile * toolEditProfile ;
if ( Sim : : findObject ( " ToolsGuiTextEditProfile " , toolEditProfile ) )
editTextCtrl - > setControlProfile ( toolEditProfile ) ;
GuiControlProfile * toolDefaultProfile = nullptr ;
Sim : : findObject ( " ToolsGuiDefaultProfile " , toolDefaultProfile ) ;
//
mPreviewImage = new GuiBitmapCtrl ( ) ;
mPreviewImage - > registerObject ( ) ;
if ( toolDefaultProfile )
mPreviewImage - > setControlProfile ( toolDefaultProfile ) ;
updatePreviewImage ( ) ;
addObject ( mPreviewImage ) ;
//
mPreviewBorderButton = new GuiBitmapButtonCtrl ( ) ;
mPreviewBorderButton - > registerObject ( ) ;
if ( toolDefaultProfile )
mPreviewBorderButton - > setControlProfile ( toolDefaultProfile ) ;
mPreviewBorderButton - > _setBitmap ( StringTable - > insert ( " ToolsModule:cubemapBtnBorder_n_image " ) ) ;
mPreviewBorderButton - > setField ( " Command " , szBuffer ) ; //clicking the preview does the same thing as the edit button, for simplicity
addObject ( mPreviewBorderButton ) ;
//
// Create "Open in Editor" button
mEditButton = new GuiBitmapButtonCtrl ( ) ;
2018-01-28 20:48:02 +00:00
2020-04-15 17:15:12 +00:00
dSprintf ( szBuffer , sizeof ( szBuffer ) , " ShapeEditorPlugin.openShapeAssetId(%d.getText()); " , retCtrl - > getId ( ) ) ;
2022-12-09 02:00:55 +00:00
mEditButton - > setField ( " Command " , szBuffer ) ;
2018-01-28 20:48:02 +00:00
2022-12-09 02:00:55 +00:00
mEditButton - > setText ( " Edit " ) ;
mEditButton - > setSizing ( horizResizeLeft , vertResizeAspectTop ) ;
2018-01-28 20:48:02 +00:00
2022-12-09 02:00:55 +00:00
mEditButton - > setDataField ( StringTable - > insert ( " Profile " ) , NULL , " ToolsGuiButtonProfile " ) ;
mEditButton - > setDataField ( StringTable - > insert ( " tooltipprofile " ) , NULL , " GuiToolTipProfile " ) ;
mEditButton - > setDataField ( StringTable - > insert ( " hovertime " ) , NULL , " 1000 " ) ;
2022-12-09 05:45:56 +00:00
mEditButton - > setDataField ( StringTable - > insert ( " tooltip " ) , NULL , " Open this asset in the Shape Editor " ) ;
2018-01-28 20:48:02 +00:00
2022-12-09 02:00:55 +00:00
mEditButton - > registerObject ( ) ;
addObject ( mEditButton ) ;
//
mUseHeightOverride = true ;
mHeightOverride = 72 ;
2018-01-28 20:48:02 +00:00
return retCtrl ;
}
bool GuiInspectorTypeShapeAssetPtr : : updateRects ( )
{
2022-12-09 02:00:55 +00:00
S32 rowSize = 18 ;
2018-01-28 20:48:02 +00:00
S32 dividerPos , dividerMargin ;
mInspector - > getDivider ( dividerPos , dividerMargin ) ;
Point2I fieldExtent = getExtent ( ) ;
Point2I fieldPos = getPosition ( ) ;
2022-12-09 02:00:55 +00:00
mEditCtrlRect . set ( 0 , 0 , fieldExtent . x , fieldExtent . y ) ;
mLabel - > resize ( Point2I ( mProfile - > mTextOffset . x , 0 ) , Point2I ( fieldExtent . x , rowSize ) ) ;
RectI previewRect = RectI ( Point2I ( mProfile - > mTextOffset . x , rowSize ) , Point2I ( 50 , 50 ) ) ;
mPreviewBorderButton - > resize ( previewRect . point , previewRect . extent ) ;
mPreviewImage - > resize ( previewRect . point , previewRect . extent ) ;
2018-01-28 20:48:02 +00:00
2022-12-09 05:45:56 +00:00
S32 editPos = previewRect . point . x + previewRect . extent . x + 10 ;
mEdit - > resize ( Point2I ( editPos , rowSize * 1.5 ) , Point2I ( fieldExtent . x - editPos - 5 , rowSize ) ) ;
2022-12-09 02:00:55 +00:00
2022-12-09 05:45:56 +00:00
mEditButton - > resize ( Point2I ( fieldExtent . x - 105 , previewRect . point . y + previewRect . extent . y - rowSize ) , Point2I ( 100 , rowSize ) ) ;
2022-12-09 02:00:55 +00:00
mBrowseButton - > setHidden ( true ) ;
return true ;
}
void GuiInspectorTypeShapeAssetPtr : : updateValue ( )
{
Parent : : updateValue ( ) ;
updatePreviewImage ( ) ;
}
void GuiInspectorTypeShapeAssetPtr : : updatePreviewImage ( )
{
const char * previewImage ;
if ( mInspector - > getInspectObject ( ) ! = nullptr )
previewImage = mInspector - > getInspectObject ( ) - > getDataField ( mCaption , NULL ) ;
else
previewImage = Con : : getVariable ( mVariableName ) ;
2022-12-09 05:45:56 +00:00
//if what we're working with isn't even a valid asset, don't present like we found a good one
if ( ! AssetDatabase . isDeclaredAsset ( previewImage ) )
{
mPreviewImage - > _setBitmap ( StringTable - > EmptyString ( ) ) ;
return ;
}
2022-12-09 02:00:55 +00:00
String shpPreviewAssetId = String ( previewImage ) + " _PreviewImage " ;
shpPreviewAssetId . replace ( " : " , " _ " ) ;
shpPreviewAssetId = " ToolsModule: " + shpPreviewAssetId ;
if ( AssetDatabase . isDeclaredAsset ( shpPreviewAssetId . c_str ( ) ) )
2018-01-28 20:48:02 +00:00
{
2022-12-09 02:00:55 +00:00
mPreviewImage - > setBitmap ( StringTable - > insert ( shpPreviewAssetId . c_str ( ) ) ) ;
2018-01-28 20:48:02 +00:00
}
2022-12-09 02:00:55 +00:00
if ( mPreviewImage - > getBitmapAsset ( ) . isNull ( ) )
mPreviewImage - > _setBitmap ( StringTable - > insert ( " ToolsModule:genericAssetIcon_image " ) ) ;
}
void GuiInspectorTypeShapeAssetPtr : : setPreviewImage ( StringTableEntry assetId )
{
2022-12-09 05:45:56 +00:00
//if what we're working with isn't even a valid asset, don't present like we found a good one
if ( ! AssetDatabase . isDeclaredAsset ( assetId ) )
{
mPreviewImage - > _setBitmap ( StringTable - > EmptyString ( ) ) ;
return ;
}
2022-12-09 02:00:55 +00:00
String shpPreviewAssetId = String ( assetId ) + " _PreviewImage " ;
shpPreviewAssetId . replace ( " : " , " _ " ) ;
shpPreviewAssetId = " ToolsModule: " + shpPreviewAssetId ;
if ( AssetDatabase . isDeclaredAsset ( shpPreviewAssetId . c_str ( ) ) )
2018-01-28 20:48:02 +00:00
{
2022-12-09 02:00:55 +00:00
mPreviewImage - > setBitmap ( StringTable - > insert ( shpPreviewAssetId . c_str ( ) ) ) ;
2018-01-28 20:48:02 +00:00
}
2022-12-09 02:00:55 +00:00
if ( mPreviewImage - > getBitmapAsset ( ) . isNull ( ) )
mPreviewImage - > _setBitmap ( StringTable - > insert ( " ToolsModule:genericAssetIcon_image " ) ) ;
2019-05-12 02:42:27 +00:00
}
2020-04-15 17:15:12 +00:00
IMPLEMENT_CONOBJECT ( GuiInspectorTypeShapeAssetId ) ;
ConsoleDocClass ( GuiInspectorTypeShapeAssetId ,
" @brief Inspector field type for Shapes \n \n "
" Editor use only. \n \n "
" @internal "
) ;
void GuiInspectorTypeShapeAssetId : : consoleInit ( )
{
Parent : : consoleInit ( ) ;
ConsoleBaseType : : getType ( TypeShapeAssetId ) - > setInspectorFieldType ( " GuiInspectorTypeShapeAssetId " ) ;
}
2020-12-02 01:16:36 +00:00
# endif