2018-01-28 20:48:02 +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 IMAGE_ASSET_H
# include "ImageAsset.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
2020-03-19 14:47:38 +00:00
# include "gfx/gfxStringEnumTranslate.h"
2021-07-19 06:07:08 +00:00
# include "ImageAssetInspectors.h"
2018-01-28 20:48:02 +00:00
// Debug Profiling.
# include "platform/profiler.h"
2020-07-11 21:20:10 +00:00
# include "T3D/assets/assetImporter.h"
2021-07-19 06:07:08 +00:00
# include "gfx/gfxDrawUtil.h"
//-----------------------------------------------------------------------------
2021-08-22 00:48:26 +00:00
StringTableEntry ImageAsset : : smNoImageAssetFallback = NULL ;
2020-07-11 21:20:10 +00:00
2018-01-28 20:48:02 +00:00
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT ( ImageAsset ) ;
2022-01-30 17:50:16 +00:00
ConsoleType ( ImageAssetPtr , TypeImageAssetPtr , const char * , " " )
2018-01-28 20:48:02 +00:00
//-----------------------------------------------------------------------------
ConsoleGetType ( TypeImageAssetPtr )
{
// Fetch asset Id.
2021-07-19 06:07:08 +00:00
return * ( ( const char * * ) ( dptr ) ) ;
2018-01-28 20:48:02 +00:00
}
//-----------------------------------------------------------------------------
ConsoleSetType ( TypeImageAssetPtr )
{
// 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 ] ) ;
2018-01-28 20:48:02 +00:00
return ;
}
// Warn.
Con : : warnf ( " (TypeImageAssetPtr) - Cannot set multiple args to a single asset. " ) ;
}
2022-01-30 17:50:16 +00:00
ConsoleType ( assetIdString , TypeImageAssetId , const char * , " " )
2020-10-11 03:48:13 +00:00
ConsoleGetType ( TypeImageAssetId )
{
// Fetch asset Id.
return * ( ( const char * * ) ( dptr ) ) ;
}
ConsoleSetType ( TypeImageAssetId )
{
// Was a single argument specified?
if ( argc = = 1 )
{
2021-07-19 06:07:08 +00:00
* ( ( const char * * ) dptr ) = StringTable - > insert ( argv [ 0 ] ) ;
2020-10-11 03:48:13 +00:00
return ;
}
// Warn.
Con : : warnf ( " (TypeAssetId) - Cannot set multiple args to a single asset. " ) ;
}
2018-01-28 20:48:02 +00:00
//-----------------------------------------------------------------------------
2020-02-17 06:32:50 +00:00
ImplementEnumType ( ImageAssetType ,
" Type of mesh data available in a shape. \n "
" @ingroup gameObjects " )
2021-07-19 06:07:08 +00:00
{ ImageAsset : : Albedo , " Albedo " , " " } ,
{ ImageAsset : : Normal , " Normal " , " " } ,
{ ImageAsset : : ORMConfig , " ORMConfig " , " " } ,
{ ImageAsset : : GUI , " GUI " , " " } ,
{ ImageAsset : : Roughness , " Roughness " , " " } ,
{ ImageAsset : : AO , " AO " , " " } ,
{ ImageAsset : : Metalness , " Metalness " , " " } ,
{ ImageAsset : : Glow , " Glow " , " " } ,
{ ImageAsset : : Particle , " Particle " , " " } ,
{ ImageAsset : : Decal , " Decal " , " " } ,
{ ImageAsset : : Cubemap , " Cubemap " , " " } ,
2020-02-17 06:32:50 +00:00
EndImplementEnumType ;
//-----------------------------------------------------------------------------
2021-07-19 06:07:08 +00:00
ImageAsset : : ImageAsset ( ) : AssetBase ( ) , mUseMips ( true ) , mIsHDRImage ( false ) , mIsValidImage ( false ) , mImageType ( Albedo )
2018-01-28 20:48:02 +00:00
{
mImageFileName = StringTable - > EmptyString ( ) ;
2020-08-09 06:32:27 +00:00
mImagePath = StringTable - > EmptyString ( ) ;
2021-07-19 06:07:08 +00:00
mLoadedState = AssetErrCode : : NotLoaded ;
2018-01-28 20:48:02 +00:00
}
//-----------------------------------------------------------------------------
ImageAsset : : ~ ImageAsset ( )
{
}
2021-07-19 06:07:08 +00:00
void ImageAsset : : consoleInit ( )
{
Parent : : consoleInit ( ) ;
Con : : addVariable ( " $Core::NoImageAssetFallback " , TypeString , & smNoImageAssetFallback ,
" The assetId of the texture to display when the requested image asset is missing. \n "
" @ingroup GFX \n " ) ;
2021-10-07 17:16:55 +00:00
2021-08-22 00:48:26 +00:00
smNoImageAssetFallback = StringTable - > insert ( Con : : getVariable ( " $Core::NoImageAssetFallback " ) ) ;
2021-07-19 06:07:08 +00:00
}
2018-01-28 20:48:02 +00:00
//-----------------------------------------------------------------------------
void ImageAsset : : initPersistFields ( )
{
// Call parent.
Parent : : initPersistFields ( ) ;
2019-05-04 16:49:42 +00:00
addProtectedField ( " imageFile " , TypeAssetLooseFilePath , Offset ( mImageFileName , ImageAsset ) ,
& setImageFileName , & getImageFileName , " Path to the image file. " ) ;
2018-01-28 20:48:02 +00:00
addField ( " useMips " , TypeBool , Offset ( mUseMips , ImageAsset ) , " Should the image use mips? (Currently unused). " ) ;
addField ( " isHDRImage " , TypeBool , Offset ( mIsHDRImage , ImageAsset ) , " Is the image in an HDR format? (Currently unused) " ) ;
2020-02-17 06:32:50 +00:00
addField ( " imageType " , TypeImageAssetType , Offset ( mImageType , ImageAsset ) , " What the main use-case for the image is for. " ) ;
2018-01-28 20:48:02 +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 ImageAsset : : getAssetByFilename ( StringTableEntry fileName , AssetPtr < ImageAsset > * imageAsset )
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
imageAsset - > setAssetId ( ImageAsset : : smNoImageAssetFallback ) ;
2020-07-11 21:20:10 +00:00
2021-07-19 06:07:08 +00:00
if ( imageAsset - > isNull ( ) )
2020-07-11 21:20:10 +00:00
{
2021-07-19 06:07:08 +00:00
//Well that's bad, loading the fallback failed.
Con : : warnf ( " ImageAsset::getAssetByFilename - Finding of asset associated with file %s failed with no fallback asset " , fileName ) ;
return AssetErrCode : : Failed ;
2020-07-11 21:20:10 +00:00
}
2021-07-19 06:07:08 +00:00
//handle noshape not being loaded itself
if ( ( * imageAsset ) - > mLoadedState = = BadFileReference )
2020-07-11 21:20:10 +00:00
{
2021-07-19 06:07:08 +00:00
Con : : warnf ( " ImageAsset::getAssetByFilename - Finding of associated with file %s failed, and fallback asset reported error of Bad File Reference. " , fileName ) ;
return AssetErrCode : : BadFileReference ;
2020-07-11 21:20:10 +00:00
}
2021-07-19 06:07:08 +00:00
Con : : warnf ( " ImageAsset::getAssetByFilename - Finding of associated with file %s failed, utilizing fallback asset " , fileName ) ;
2018-01-28 20:48:02 +00:00
2021-07-19 06:07:08 +00:00
( * imageAsset ) - > mLoadedState = AssetErrCode : : UsingFallback ;
return AssetErrCode : : UsingFallback ;
2020-03-19 14:47:38 +00:00
}
else
{
//acquire and bind the asset, and return it out
imageAsset - > setAssetId ( query . mAssetList [ 0 ] ) ;
2021-07-19 06:07:08 +00:00
return ( * imageAsset ) - > mLoadedState ;
2020-03-19 14:47:38 +00:00
}
}
2020-07-11 21:20:10 +00:00
StringTableEntry ImageAsset : : getAssetIdByFilename ( StringTableEntry fileName )
{
2021-07-19 06:07:08 +00:00
if ( fileName = = StringTable - > EmptyString ( ) )
return StringTable - > EmptyString ( ) ;
StringTableEntry imageAssetId = ImageAsset : : smNoImageAssetFallback ;
2020-07-11 21:20:10 +00:00
AssetQuery query ;
S32 foundAssetcount = AssetDatabase . findAssetLooseFile ( & query , fileName ) ;
2021-07-19 06:07:08 +00:00
if ( foundAssetcount ! = 0 )
2020-07-11 21:20:10 +00:00
{
//acquire and bind the asset, and return it out
imageAssetId = query . mAssetList [ 0 ] ;
}
2022-04-10 22:29:55 +00:00
else
{
AssetPtr < ImageAsset > imageAsset = imageAssetId ;
imageAsset - > mLoadedState = AssetErrCode : : BadFileReference ;
}
2020-07-11 21:20:10 +00:00
return imageAssetId ;
}
2021-07-19 06:07:08 +00:00
U32 ImageAsset : : getAssetById ( StringTableEntry assetId , AssetPtr < ImageAsset > * imageAsset )
2020-10-11 03:48:13 +00:00
{
( * imageAsset ) = assetId ;
2021-07-19 06:07:08 +00:00
if ( imageAsset - > notNull ( ) )
{
return ( * imageAsset ) - > mLoadedState ;
}
else
{
if ( imageAsset - > isNull ( ) )
{
//Well that's bad, loading the fallback failed.
Con : : warnf ( " ImageAsset::getAssetById - Finding of asset with id %s failed with no fallback asset " , assetId ) ;
return AssetErrCode : : Failed ;
}
2020-10-11 03:48:13 +00:00
2021-07-19 06:07:08 +00:00
//handle noshape not being loaded itself
if ( ( * imageAsset ) - > mLoadedState = = BadFileReference )
{
Con : : warnf ( " ImageAsset::getAssetById - Finding of asset with id %s failed, and fallback asset reported error of Bad File Reference. " , assetId ) ;
return AssetErrCode : : BadFileReference ;
}
2020-10-11 03:48:13 +00:00
2021-07-19 06:07:08 +00:00
Con : : warnf ( " ImageAsset::getAssetById - Finding of asset with id %s failed, utilizing fallback asset " , assetId ) ;
2020-10-11 03:48:13 +00:00
2021-07-19 06:07:08 +00:00
( * imageAsset ) - > mLoadedState = AssetErrCode : : UsingFallback ;
return AssetErrCode : : UsingFallback ;
}
2020-10-11 03:48:13 +00:00
}
2021-07-19 06:07:08 +00:00
2020-03-19 14:47:38 +00:00
//------------------------------------------------------------------------------
2018-01-28 20:48:02 +00:00
void ImageAsset : : copyTo ( SimObject * object )
{
// Call to parent.
Parent : : copyTo ( object ) ;
}
void ImageAsset : : loadImage ( )
{
2020-10-11 03:48:13 +00:00
if ( mImagePath )
2018-01-28 20:48:02 +00:00
{
2021-07-23 02:27:13 +00:00
if ( ! Torque : : FS : : IsFile ( mImagePath ) )
2018-01-28 20:48:02 +00:00
{
Con : : errorf ( " ImageAsset::initializeAsset: Attempted to load file %s but it was not valid! " , mImageFileName ) ;
2021-07-19 06:07:08 +00:00
mLoadedState = BadFileReference ;
2018-01-28 20:48:02 +00:00
return ;
}
2021-07-19 06:07:08 +00:00
mLoadedState = Ok ;
mIsValidImage = true ;
2021-10-07 17:16:55 +00:00
mChangeSignal . trigger ( ) ;
2021-07-19 06:07:08 +00:00
return ;
2018-01-28 20:48:02 +00:00
}
2021-07-19 06:07:08 +00:00
mLoadedState = BadFileReference ;
2018-01-28 20:48:02 +00:00
mIsValidImage = false ;
}
void ImageAsset : : initializeAsset ( )
{
2021-07-19 06:07:08 +00:00
ResourceManager : : get ( ) . getChangedSignal ( ) . notify ( this , & ImageAsset : : _onResourceChanged ) ;
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
2021-08-22 04:12:37 +00:00
mImagePath = getOwned ( ) ? expandAssetFilePath ( mImageFileName ) : mImagePath ;
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
loadImage ( ) ;
2018-01-28 20:48:02 +00:00
}
void ImageAsset : : onAssetRefresh ( )
{
2021-08-22 04:12:37 +00:00
mImagePath = getOwned ( ) ? expandAssetFilePath ( mImageFileName ) : mImagePath ;
2020-08-09 06:32:27 +00:00
loadImage ( ) ;
2019-05-04 16:49:42 +00:00
}
2021-07-19 06:07:08 +00:00
void ImageAsset : : _onResourceChanged ( const Torque : : Path & path )
{
if ( path ! = Torque : : Path ( mImagePath ) )
return ;
refreshAsset ( ) ;
2021-08-22 04:12:37 +00:00
//loadImage();
2021-07-19 06:07:08 +00:00
}
2019-05-04 16:49:42 +00:00
void ImageAsset : : setImageFileName ( const char * pScriptFile )
{
// Sanity!
AssertFatal ( pScriptFile ! = NULL , " Cannot use a NULL image file. " ) ;
// Update.
2021-08-22 04:12:37 +00:00
mImageFileName = StringTable - > insert ( pScriptFile , true ) ;
// Refresh the asset.
refreshAsset ( ) ;
2019-05-28 22:24:29 +00:00
}
2021-07-19 06:07:08 +00:00
const GBitmap & ImageAsset : : getImage ( )
2020-03-19 14:47:38 +00:00
{
2021-07-19 06:07:08 +00:00
return GBitmap ( ) ; //TODO fix this
}
GFXTexHandle ImageAsset : : getTexture ( GFXTextureProfile * requestedProfile )
{
if ( mResourceMap . contains ( requestedProfile ) )
2020-03-19 14:47:38 +00:00
{
2021-07-19 06:07:08 +00:00
mLoadedState = Ok ;
2020-03-19 14:47:38 +00:00
return mResourceMap . find ( requestedProfile ) - > value ;
}
else
{
//If we don't have an existing map case to the requested format, we'll just create it and insert it in
2021-07-19 06:07:08 +00:00
GFXTexHandle newTex = TEXMGR - > createTexture ( mImagePath , requestedProfile ) ;
if ( newTex )
{
mResourceMap . insert ( requestedProfile , newTex ) ;
mLoadedState = Ok ;
return newTex ;
}
else
mLoadedState = BadFileReference ;
}
2020-03-19 14:47:38 +00:00
2021-07-19 06:07:08 +00:00
//if (mTexture.isValid())
// return mTexture;
2020-10-11 03:48:13 +00:00
2020-03-19 14:47:38 +00:00
return nullptr ;
}
const char * ImageAsset : : getImageInfo ( )
{
if ( mIsValidImage )
{
static const U32 bufSize = 2048 ;
char * returnBuffer = Con : : getReturnBuffer ( bufSize ) ;
2021-07-19 06:07:08 +00:00
GFXTexHandle newTex = TEXMGR - > createTexture ( mImagePath , & GFXStaticTextureSRGBProfile ) ;
if ( newTex )
{
dSprintf ( returnBuffer , bufSize , " %s %d %d %d " , GFXStringTextureFormat [ newTex - > getFormat ( ) ] , newTex - > getHeight ( ) , newTex - > getWidth ( ) , newTex - > getDepth ( ) ) ;
newTex = nullptr ;
}
else
{
dSprintf ( returnBuffer , bufSize , " ImageAsset::getImageInfo() - Failed to get image info for %s " , getAssetId ( ) ) ;
}
2020-03-19 14:47:38 +00:00
return returnBuffer ;
}
return " " ;
}
2020-05-11 07:30:58 +00:00
const char * ImageAsset : : getImageTypeNameFromType ( ImageAsset : : ImageTypes type )
{
// must match ImageTypes order
static const char * _names [ ] = {
2020-07-11 21:20:10 +00:00
" Albedo " ,
" Normal " ,
2020-09-30 18:51:12 +00:00
" ORMConfig " ,
2020-07-11 21:20:10 +00:00
" GUI " ,
" Roughness " ,
" AO " ,
" Metalness " ,
" Glow " ,
" Particle " ,
" Decal " ,
2020-05-11 07:30:58 +00:00
" Cubemap "
} ;
if ( type < 0 | | type > = ImageTypeCount )
{
Con : : errorf ( " ImageAsset::getAdapterNameFromType - Invalid ImageType, defaulting to Albedo " ) ;
return _names [ Albedo ] ;
}
return _names [ type ] ;
}
ImageAsset : : ImageTypes ImageAsset : : getImageTypeFromName ( const char * name )
{
2021-07-19 06:07:08 +00:00
if ( dStrIsEmpty ( name ) )
{
return ( ImageTypes ) Albedo ;
}
2020-05-11 07:30:58 +00:00
S32 ret = - 1 ;
for ( S32 i = 0 ; i < ImageTypeCount ; i + + )
{
if ( ! dStricmp ( getImageTypeNameFromType ( ( ImageTypes ) i ) , name ) )
ret = i ;
}
if ( ret = = - 1 )
{
Con : : errorf ( " ImageAsset::getImageTypeFromName - Invalid ImageType name, defaulting to Albedo " ) ;
ret = Albedo ;
}
return ( ImageTypes ) ret ;
}
2020-08-13 06:35:24 +00:00
DefineEngineMethod ( ImageAsset , getImagePath , const char * , ( ) , ,
Misc Quality of Life and Bug fixes
Added handling for if preview images on image assets fails to generate, will fallback to using the full image
Added handling for double clicking or drag-n-dropping terrain assets to create them
Improved handling of field labels in variable inspector by making the stringtable be case sensitive.
Added editor settings for handling of asset double click behavior. Can now select between Edit Asset and Spawn Asset. Support is asset type dependent.
Added editor setting for auto-importing loose files when navigating to a folder. If on and the user has flagged to also enable auto-import generally, will auto import all unaffiliated loose files in as assets.
Added editor setting for default module to use when creating new assets. Updated various tooling logic so when creating a new material, if this and the 'Always Prompt Module Target' setting is off, it will fill in the target module and target asset path info based on the default module.
Fixed issue with editors that use managedData scripts where if the path didn't exist, the script file wouldn't be made.
Fixed display issue in terrain editor where if you clear the detail map, the normal/macro/orm maps would disable, but not also clear.
Fixed handling of cleared maps in terrain editor so it no longer fills empty maps in with the no image image.
Fixed handling of creating new material where it would fill in the diffuse with a no texture image as the default.
Fixed issue where canceling out of creating a module would still prompt to create the common default folders.
Fixed issue where the Select Module window couldn't be closed via the cancel or x buttons.
Based on feedback, reduced default size of the Text Pad window.
Fixed issue where the Drop At menu list wouldn't correctly display which item was marked after it was changed.
Fixed spawning shape asset handling so it uses whatever the editor's Drop At setting is.
Improved themeing of regular bitmap buttons in the editor.
Based on feedback, flipped layout of Target Module and Target Path in the Create New Asset window.
Improved handling of setting up the Target Path for when creating new assets. If a path is not set, and the user has a Default Module, it will default the path to that module.
2021-08-28 23:51:27 +00:00
" Gets the image filepath of this asset. \n "
" @return File path of the image file. " )
2019-05-28 22:24:29 +00:00
{
2020-08-13 06:35:24 +00:00
return object - > getImagePath ( ) ;
2019-05-04 16:49:42 +00:00
}
2020-03-19 14:47:38 +00:00
DefineEngineMethod ( ImageAsset , getImageInfo , const char * , ( ) , ,
Misc Quality of Life and Bug fixes
Added handling for if preview images on image assets fails to generate, will fallback to using the full image
Added handling for double clicking or drag-n-dropping terrain assets to create them
Improved handling of field labels in variable inspector by making the stringtable be case sensitive.
Added editor settings for handling of asset double click behavior. Can now select between Edit Asset and Spawn Asset. Support is asset type dependent.
Added editor setting for auto-importing loose files when navigating to a folder. If on and the user has flagged to also enable auto-import generally, will auto import all unaffiliated loose files in as assets.
Added editor setting for default module to use when creating new assets. Updated various tooling logic so when creating a new material, if this and the 'Always Prompt Module Target' setting is off, it will fill in the target module and target asset path info based on the default module.
Fixed issue with editors that use managedData scripts where if the path didn't exist, the script file wouldn't be made.
Fixed display issue in terrain editor where if you clear the detail map, the normal/macro/orm maps would disable, but not also clear.
Fixed handling of cleared maps in terrain editor so it no longer fills empty maps in with the no image image.
Fixed handling of creating new material where it would fill in the diffuse with a no texture image as the default.
Fixed issue where canceling out of creating a module would still prompt to create the common default folders.
Fixed issue where the Select Module window couldn't be closed via the cancel or x buttons.
Based on feedback, reduced default size of the Text Pad window.
Fixed issue where the Drop At menu list wouldn't correctly display which item was marked after it was changed.
Fixed spawning shape asset handling so it uses whatever the editor's Drop At setting is.
Improved themeing of regular bitmap buttons in the editor.
Based on feedback, flipped layout of Target Module and Target Path in the Create New Asset window.
Improved handling of setting up the Target Path for when creating new assets. If a path is not set, and the user has a Default Module, it will default the path to that module.
2021-08-28 23:51:27 +00:00
" Gets the info and properties of the image. \n "
" @return The info/properties of the image. " )
2020-03-19 14:47:38 +00:00
{
return object - > getImageInfo ( ) ;
}
2020-10-11 03:48:13 +00:00
2021-07-19 06:07:08 +00:00
# ifdef TORQUE_TOOLS
DefineEngineStaticMethod ( ImageAsset , 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 ImageAsset : : getAssetIdByFilename ( StringTable - > insert ( filePath ) ) ;
}
# endif
2020-10-11 03:48:13 +00:00
//-----------------------------------------------------------------------------
// GuiInspectorTypeAssetId
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT ( GuiInspectorTypeImageAssetPtr ) ;
ConsoleDocClass ( GuiInspectorTypeImageAssetPtr ,
" @brief Inspector field type for Shapes \n \n "
" Editor use only. \n \n "
" @internal "
) ;
void GuiInspectorTypeImageAssetPtr : : consoleInit ( )
{
Parent : : consoleInit ( ) ;
ConsoleBaseType : : getType ( TypeImageAssetPtr ) - > setInspectorFieldType ( " GuiInspectorTypeImageAssetPtr " ) ;
}
GuiControl * GuiInspectorTypeImageAssetPtr : : constructEditControl ( )
{
2021-07-19 06:07:08 +00:00
if ( mInspector - > getInspectObject ( ) = = nullptr )
return nullptr ;
2020-10-11 03:48:13 +00:00
// Create base filename edit controls
GuiControl * retCtrl = Parent : : constructEditControl ( ) ;
if ( retCtrl = = NULL )
return retCtrl ;
2021-07-19 06:07:08 +00:00
retCtrl - > getRenderTooltipDelegate ( ) . bind ( this , & GuiInspectorTypeImageAssetPtr : : renderTooltip ) ;
2020-10-11 03:48:13 +00:00
// Change filespec
char szBuffer [ 512 ] ;
dSprintf ( szBuffer , sizeof ( szBuffer ) , " AssetBrowser.showDialog( \" ImageAsset \" , \" AssetBrowser.changeAsset \" , %s, %s); " ,
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
mInspector - > getIdString ( ) , mCaption ) ;
2020-10-11 03:48:13 +00:00
mBrowseButton - > setField ( " Command " , szBuffer ) ;
setDataField ( StringTable - > insert ( " targetObject " ) , NULL , mInspector - > getInspectObject ( ) - > getIdString ( ) ) ;
// Create "Open in ShapeEditor" button
mImageEdButton = new GuiBitmapButtonCtrl ( ) ;
2021-08-06 06:06:36 +00:00
char bitmapName [ 512 ] = " ToolsModule:GameTSCtrl_image " ;
2021-07-19 06:07:08 +00:00
mImageEdButton - > setBitmap ( StringTable - > insert ( bitmapName ) ) ;
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
mImageEdButton - > setHidden ( true ) ;
2020-10-11 03:48:13 +00:00
mImageEdButton - > setDataField ( StringTable - > insert ( " Profile " ) , NULL , " GuiButtonProfile " ) ;
mImageEdButton - > setDataField ( StringTable - > insert ( " tooltipprofile " ) , NULL , " GuiToolTipProfile " ) ;
mImageEdButton - > setDataField ( StringTable - > insert ( " hovertime " ) , NULL , " 1000 " ) ;
mImageEdButton - > setDataField ( StringTable - > insert ( " tooltip " ) , NULL , " Open this file in the Shape Editor " ) ;
mImageEdButton - > registerObject ( ) ;
addObject ( mImageEdButton ) ;
return retCtrl ;
}
bool GuiInspectorTypeImageAssetPtr : : updateRects ( )
{
S32 dividerPos , dividerMargin ;
mInspector - > getDivider ( dividerPos , dividerMargin ) ;
Point2I fieldExtent = getExtent ( ) ;
Point2I fieldPos = getPosition ( ) ;
mCaptionRect . set ( 0 , 0 , fieldExtent . x - dividerPos - dividerMargin , fieldExtent . y ) ;
mEditCtrlRect . set ( fieldExtent . x - dividerPos + dividerMargin , 1 , dividerPos - dividerMargin - 34 , fieldExtent . y ) ;
bool resized = mEdit - > resize ( mEditCtrlRect . point , mEditCtrlRect . extent ) ;
if ( mBrowseButton ! = NULL )
{
mBrowseRect . set ( fieldExtent . x - 32 , 2 , 14 , fieldExtent . y - 4 ) ;
resized | = mBrowseButton - > resize ( mBrowseRect . point , mBrowseRect . extent ) ;
}
if ( mImageEdButton ! = NULL )
{
RectI shapeEdRect ( fieldExtent . x - 16 , 2 , 14 , fieldExtent . y - 4 ) ;
resized | = mImageEdButton - > resize ( shapeEdRect . point , shapeEdRect . extent ) ;
}
return resized ;
}
2021-07-19 06:07:08 +00:00
bool GuiInspectorTypeImageAssetPtr : : renderTooltip ( const Point2I & hoverPos , const Point2I & cursorPos , const char * tipText )
{
if ( ! mAwake )
return false ;
GuiCanvas * root = getRoot ( ) ;
if ( ! root )
return false ;
AssetPtr < ImageAsset > imgAsset ;
U32 assetState = ImageAsset : : getAssetById ( getData ( ) , & imgAsset ) ;
if ( imgAsset = = NULL | | assetState = = ImageAsset : : Failed )
return false ;
StringTableEntry filename = imgAsset - > getImagePath ( ) ;
if ( ! filename | | ! filename [ 0 ] )
return false ;
2021-11-15 03:39:51 +00:00
StringTableEntry previewFilename = filename ;
if ( Con : : isFunction ( " getAssetPreviewImage " ) )
{
ConsoleValue consoleRet = Con : : executef ( " getAssetPreviewImage " , filename ) ;
previewFilename = StringTable - > insert ( consoleRet . getString ( ) ) ;
if ( AssetDatabase . isDeclaredAsset ( previewFilename ) )
{
ImageAsset * previewAsset = AssetDatabase . acquireAsset < ImageAsset > ( previewFilename ) ;
previewFilename = previewAsset - > getImagePath ( ) ;
}
}
GFXTexHandle texture ( previewFilename , & GFXStaticTextureSRGBProfile , avar ( " %s() - tooltip texture ( line % d ) " , __FUNCTION__, __LINE__)) ;
2021-07-19 06:07:08 +00:00
if ( texture . isNull ( ) )
return false ;
2021-10-07 17:16:55 +00:00
// Render image at a reasonable screen size while
2021-07-19 06:07:08 +00:00
// keeping its aspect ratio...
Point2I screensize = getRoot ( ) - > getWindowSize ( ) ;
Point2I offset = hoverPos ;
Point2I tipBounds ;
U32 texWidth = texture . getWidth ( ) ;
U32 texHeight = texture . getHeight ( ) ;
F32 aspect = ( F32 ) texHeight / ( F32 ) texWidth ;
const F32 newWidth = 150.0f ;
F32 newHeight = aspect * newWidth ;
// Offset below cursor image
offset . y + = 20 ; // TODO: Attempt to fix?: root->getCursorExtent().y;
tipBounds . x = newWidth ;
tipBounds . y = newHeight ;
// Make sure all of the tooltip will be rendered width the app window,
// 5 is given as a buffer against the edge
if ( screensize . x < offset . x + tipBounds . x + 5 )
offset . x = screensize . x - tipBounds . x - 5 ;
if ( screensize . y < offset . y + tipBounds . y + 5 )
offset . y = hoverPos . y - tipBounds . y - 5 ;
RectI oldClip = GFX - > getClipRect ( ) ;
RectI rect ( offset , tipBounds ) ;
GFX - > setClipRect ( rect ) ;
GFXDrawUtil * drawer = GFX - > getDrawUtil ( ) ;
drawer - > clearBitmapModulation ( ) ;
GFX - > getDrawUtil ( ) - > drawBitmapStretch ( texture , rect ) ;
GFX - > setClipRect ( oldClip ) ;
return true ;
}
2020-10-11 03:48:13 +00:00
IMPLEMENT_CONOBJECT ( GuiInspectorTypeImageAssetId ) ;
ConsoleDocClass ( GuiInspectorTypeImageAssetId ,
" @brief Inspector field type for Shapes \n \n "
" Editor use only. \n \n "
" @internal "
) ;
void GuiInspectorTypeImageAssetId : : consoleInit ( )
{
Parent : : consoleInit ( ) ;
ConsoleBaseType : : getType ( TypeImageAssetId ) - > setInspectorFieldType ( " GuiInspectorTypeImageAssetId " ) ;
}