Updates ImageAsset usage to utilize AssetRef, and standardizes the setter/getter functions and naming conventions, as well as the ability to use and bind named targets.

This commit is contained in:
JeffR 2026-06-16 17:39:30 -05:00
parent a858d8624e
commit 34e3f78a22
82 changed files with 1451 additions and 951 deletions

View file

@ -181,7 +181,9 @@ void VolumetricFog::initPersistFields()
endGroup("VolumetricFogData");
addGroup("VolumetricFogModulation");
INITPERSISTFIELD_IMAGEASSET(Texture, VolumetricFog, "A texture which contains Fogdensity modulator in the red channel and color with 1-green channel. No texture disables modulation.");
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, VolumetricFog))
.network(FogModulationMask)
.doc("A texture which contains Fogdensity modulator in the red channel and color with 1-green channel. No texture disables modulation.");
addFieldV("tiles", TypeRangedF32, Offset(mTexTiles, VolumetricFog), &CommonValidators::PositiveFloat,
"How many times the texture is mapped to the object.");
@ -329,8 +331,8 @@ void VolumetricFog::handleResize(VolumetricFogRTManager *RTM, bool resize)
// load texture.
getTexture();
mTexScale.x = 2.0f - ((F32)mTextureAsset->getTextureBitmapWidth() / width);
mTexScale.y = 2.0f - ((F32)mTextureAsset->getTextureBitmapHeight() / height);
mTexScale.x = 2.0f - ((F32)mTextureAssetRef.assetPtr->getTextureBitmapWidth() / width);
mTexScale.y = 2.0f - ((F32)mTextureAssetRef.assetPtr->getTextureBitmapHeight() / height);
}
UpdateBuffers(0,true);
@ -545,7 +547,7 @@ U32 VolumetricFog::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
stream->write(mFogDensity);
if (stream->writeFlag(mask & FogModulationMask))
{
PACK_ASSET_REFACTOR(con, Texture);
AssetDatabase.packUpdateAsset(con, mask, stream, mTextureAssetRef.assetId);
mTexTiles = mFabs(mTexTiles);
stream->write(mTexTiles);
stream->write(mStrength);
@ -600,7 +602,7 @@ void VolumetricFog::unpackUpdate(NetConnection *con, BitStream *stream)
MatrixF mat;
VectorF scale;
VectorF mOldScale = getScale();
StringTableEntry oldTextureName = mTextureAsset.getAssetId();
StringTableEntry oldTextureName = mTextureAssetRef.getAssetId();
StringTableEntry oldShapeAsset = mShapeAssetRef.assetId;
StringTableEntry oldShape = mShapeAssetRef.notNull() ? mShapeAssetRef.assetPtr->getShapeFile() : StringTable->EmptyString();
@ -618,7 +620,7 @@ void VolumetricFog::unpackUpdate(NetConnection *con, BitStream *stream)
}
if (stream->readFlag())// Fog Modulation
{
UNPACK_ASSET_REFACTOR(con, Texture);
mTextureAssetRef = AssetDatabase.unpackUpdateAsset(con, stream);
stream->read(&mTexTiles);
mTexTiles = mFabs(mTexTiles);
stream->read(&mStrength);
@ -628,9 +630,9 @@ void VolumetricFog::unpackUpdate(NetConnection *con, BitStream *stream)
if (isProperlyAdded())
{
if (oldTextureName != mTextureAsset.getAssetId())
if (oldTextureName != mTextureAssetRef.getAssetId())
InitTexture();
if (oldTextureName != StringTable->EmptyString() && mTextureAsset.isNull())
if (oldTextureName != StringTable->EmptyString() && mTextureAssetRef.isNull())
{
mIsTextured = false;
}
@ -1219,21 +1221,24 @@ void VolumetricFog::InitTexture()
{
mIsTextured = false;
U32 assetStatus = ImageAsset::getAssetErrCode(mTextureAsset);
if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback)
{
return;
}
if (!mTextureAsset.isNull())
if (!mTextureAssetRef.isNull())
{
mTextureAssetRef.assetPtr->load();
U32 assetStatus = ImageAsset::getAssetErrCode(mTextureAssetRef.assetPtr);
if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback)
{
return;
}
mIsTextured = true;
// load asset.
getTexture();
F32 width = (F32)mPlatformWindow->getClientExtent().x;
F32 height = (F32)mPlatformWindow->getClientExtent().y;
mTexScale.x = 2.0f - ((F32)mTextureAsset->getTextureBitmapWidth() / width);
mTexScale.y = 2.0f - ((F32)mTextureAsset->getTextureBitmapHeight() / height);
mTexScale.x = 2.0f - ((F32)mTextureAssetRef.assetPtr->getTextureBitmapWidth() / width);
mTexScale.y = 2.0f - ((F32)mTextureAssetRef.assetPtr->getTextureBitmapHeight() / height);
}
}

View file

@ -52,7 +52,8 @@
#endif
#ifndef SHAPEASSET_H
#include "T3D/assets/ShapeAsset.h"
#endif
#endif
#include "T3D/assets/ImageAsset.h"
class VolumetricFogRTManager;
@ -161,7 +162,9 @@ class VolumetricFog : public SceneObject
F32 mInvScale;
// Fog Modulation data
DECLARE_IMAGEASSET_NET(VolumetricFog, Texture, GFXStaticTextureSRGBProfile, FogModulationMask)
AssetRef<ImageAsset> mTextureAssetRef;
GFXTexHandle getTexture() { return mTextureAssetRef.notNull() ? mTextureAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
bool mIsTextured;
F32 mTexTiles;

View file

@ -174,7 +174,9 @@ void BasicClouds::initPersistFields()
addField( "layerEnabled", TypeBool, Offset( mLayerEnabled, BasicClouds ), TEX_COUNT,
"Enable or disable rendering of this layer." );
INITPERSISTFIELD_IMAGEASSET_ARRAY(Texture, TEX_COUNT, BasicClouds, "Texture for this layer.");
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, BasicClouds))
.elements(TEX_COUNT)
.doc("Texture asset for this layer.");
addFieldV( "texScale", TypeRangedF32, Offset( mTexScale, BasicClouds ), &CommonValidators::PositiveFloat, TEX_COUNT,
"Texture repeat for this layer." );
@ -212,10 +214,10 @@ U32 BasicClouds::packUpdate( NetConnection *conn, U32 mask, BitStream *stream )
{
U32 retMask = Parent::packUpdate( conn, mask, stream );
PACK_ASSET_ARRAY_REFACTOR(conn, Texture, TEX_COUNT)
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
AssetDatabase.packUpdateAsset( conn, mask, stream, mTextureAssetRef[i].assetId );
stream->writeFlag( mLayerEnabled[i] );
stream->write( mTexScale[i] );
mathWrite( *stream, mTexDirection[i] );
@ -232,10 +234,10 @@ void BasicClouds::unpackUpdate( NetConnection *conn, BitStream *stream )
{
Parent::unpackUpdate( conn, stream );
UNPACK_ASSET_ARRAY_REFACTOR(conn, Texture, TEX_COUNT)
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
mTextureAssetRef[i] = AssetDatabase.unpackUpdateAsset( conn, stream );
mLayerEnabled[i] = stream->readFlag();
stream->read( &mTexScale[i] );
mathRead( *stream, &mTexDirection[i] );
@ -310,14 +312,14 @@ void BasicClouds::renderObject( ObjectRenderInst *ri, SceneRenderState *state, B
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
if ( !mLayerEnabled[i] || mTextureAsset[i].isNull())
if ( !mLayerEnabled[i] || mTextureAssetRef[i].isNull())
continue;
mShaderConsts->setSafe( mTexScaleSC, mTexScale[i] );
mShaderConsts->setSafe( mTexDirectionSC, mTexDirection[i] * mTexSpeed[i] );
mShaderConsts->setSafe( mTexOffsetSC, mTexOffset[i] );
mShaderConsts->setSafe( mTexOffsetSC, mTexOffset[i] );
GFX->setTexture( mDiffuseMapSC->getSamplerRegister(), getTexture(i) );
GFX->setTexture( mDiffuseMapSC->getSamplerRegister(), getTexture(i) );
GFX->setVertexBuffer( mVB[i] );
GFX->drawIndexedPrimitive( GFXTriangleList, 0, 0, smVertCount, 0, smTriangleCount );

View file

@ -94,7 +94,8 @@ protected:
static U32 smVertCount;
static U32 smTriangleCount;
DECLARE_IMAGEASSET_ARRAY_NET(BasicClouds, Texture, GFXStaticTextureSRGBProfile, TEX_COUNT, -1)
AssetRef<ImageAsset> mTextureAssetRef[TEX_COUNT];
GFXTexHandle getTexture(const U32& index) { return mTextureAssetRef[index].notNull() ? mTextureAssetRef[index].assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : GFXTexHandle(); }
GFXStateBlockRef mStateblock;

View file

@ -190,7 +190,9 @@ void CloudLayer::initPersistFields()
docsURL;
addGroup( "CloudLayer" );
INITPERSISTFIELD_IMAGEASSET(Texture, CloudLayer, "An RGBA texture which should contain normals and opacity (density).")
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, CloudLayer))
.network(CloudLayerMask)
.doc("An RGBA texture asset which should contain normals and opacity (density).");
addArray( "Textures", TEX_COUNT );
@ -239,10 +241,8 @@ U32 CloudLayer::packUpdate( NetConnection *conn, U32 mask, BitStream *stream )
{
U32 retMask = Parent::packUpdate( conn, mask, stream );
if (stream->writeFlag(getTexture())) {
NetStringHandle assetIdStr = mTextureAsset.getAssetId(); conn->packNetStringHandleU(stream, assetIdStr);
}
AssetDatabase.packUpdateAsset(conn, mask, stream, mTextureAssetRef.assetId);
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
stream->write( mTexScale[i] );
@ -263,9 +263,7 @@ void CloudLayer::unpackUpdate( NetConnection *conn, BitStream *stream )
{
Parent::unpackUpdate( conn, stream );
if (stream->readFlag()) {
mTextureAsset.setAssetId(_getStringTable()->insert(conn->unpackNetStringHandleU(stream).getString()));
}
mTextureAssetRef = AssetDatabase.unpackUpdateAsset(conn, stream);
for ( U32 i = 0; i < TEX_COUNT; i++ )
{
@ -331,7 +329,7 @@ void CloudLayer::renderObject( ObjectRenderInst *ri, SceneRenderState *state, Ba
{
GFXTransformSaver saver;
if (!mTextureAsset)
if (mTextureAssetRef.isNull())
return;
const Point3F &camPos = state->getCameraPosition();
@ -382,7 +380,7 @@ void CloudLayer::renderObject( ObjectRenderInst *ri, SceneRenderState *state, Ba
mShaderConsts->setSafe( mExposureSC, mExposure );
GFX->setTexture( mNormalHeightMapSC->getSamplerRegister(), mTextureAsset->getTexture(&GFXStaticTextureSRGBProfile));
GFX->setTexture( mNormalHeightMapSC->getSamplerRegister(), mTextureAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile));
GFX->setVertexBuffer( mVB );
GFX->setPrimitiveBuffer( mPB );

View file

@ -98,7 +98,9 @@ protected:
public:
DECLARE_IMAGEASSET_NET(CloudLayer,Texture, GFXStaticTextureSRGBProfile, CloudLayerMask)
AssetRef<ImageAsset> mTextureAssetRef;
GFXTexHandle getTexture() { return mTextureAssetRef.notNull() ? mTextureAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
GFXShaderRef mShader;

View file

@ -297,7 +297,9 @@ void WaterObject::initPersistFields()
addFieldV( "overallWaveMagnitude", TypeRangedF32, Offset( mOverallWaveMagnitude, WaterObject ), &CommonValidators::PositiveFloat, "Master variable affecting entire body"
" of water's undulation" );
INITPERSISTFIELD_IMAGEASSET(RippleTex, WaterObject, "Normal map used to simulate small surface ripples");
ADD_FIELD("rippleTexAsset", TypeImageAssetRef, Offset(mRippleTexAssetRef, WaterObject))
.network(TextureMask)
.doc("Normal map asset used to simulate small surface ripples");
addArray( "Ripples (texture animation)", MAX_WAVES );
@ -311,7 +313,9 @@ void WaterObject::initPersistFields()
addFieldV( "overallRippleMagnitude", TypeRangedF32, Offset( mOverallRippleMagnitude, WaterObject ), &CommonValidators::PositiveFloat, "Master variable affecting entire surface");
INITPERSISTFIELD_IMAGEASSET(FoamTex, WaterObject, "Diffuse texture for foam in shallow water (advanced lighting only)");
ADD_FIELD("foamTexAsset", TypeImageAssetRef, Offset(mFoamTexAssetRef, WaterObject))
.network(TextureMask)
.doc("Diffuse texture asset for foam in shallow water");
addArray( "Foam", MAX_FOAM );
@ -363,7 +367,9 @@ void WaterObject::initPersistFields()
addGroup( "Misc" );
INITPERSISTFIELD_IMAGEASSET(DepthGradientTex, WaterObject, "1D texture defining the base water color by depth");
ADD_FIELD("depthGradientTexAsset", TypeImageAssetRef, Offset(mDepthGradientTexAssetRef, WaterObject))
.network(TextureMask)
.doc("1D texture asset defining the base water color by depth");
addFieldV( "depthGradientMax", TypeRangedF32, Offset( mDepthGradientMax, WaterObject ), &CommonValidators::PositiveFloat, "Depth in world units, the max range of the color gradient texture." );
@ -544,9 +550,9 @@ U32 WaterObject::packUpdate( NetConnection * conn, U32 mask, BitStream *stream )
if ( stream->writeFlag( mask & TextureMask ) )
{
PACK_ASSET_REFACTOR(conn, RippleTex);
PACK_ASSET_REFACTOR(conn, DepthGradientTex);
PACK_ASSET_REFACTOR(conn, FoamTex);
AssetDatabase.packUpdateAsset(conn, mask, stream, mRippleTexAssetRef.assetId);
AssetDatabase.packUpdateAsset(conn, mask, stream, mDepthGradientTexAssetRef.assetId);
AssetDatabase.packUpdateAsset(conn, mask, stream, mFoamTexAssetRef.assetId);
stream->writeString( mCubemapName );
}
@ -666,9 +672,9 @@ void WaterObject::unpackUpdate( NetConnection * conn, BitStream *stream )
// TextureMask
if ( stream->readFlag() )
{
UNPACK_ASSET_REFACTOR(conn, RippleTex);
UNPACK_ASSET_REFACTOR(conn, DepthGradientTex);
UNPACK_ASSET_REFACTOR(conn, FoamTex);
mRippleTexAssetRef = AssetDatabase.unpackUpdateAsset(conn, stream);
mDepthGradientTexAssetRef = AssetDatabase.unpackUpdateAsset(conn, stream);
mFoamTexAssetRef = AssetDatabase.unpackUpdateAsset(conn, stream);
mCubemapName = stream->readSTString();

View file

@ -269,9 +269,14 @@ protected:
F32 mDepthGradientMax;
// Other textures
DECLARE_IMAGEASSET_NET(WaterObject, RippleTex, GFXStaticTextureProfile, TextureMask)
DECLARE_IMAGEASSET_NET(WaterObject, FoamTex, GFXStaticTextureSRGBProfile, TextureMask)
DECLARE_IMAGEASSET_NET(WaterObject, DepthGradientTex, GFXStaticTextureSRGBProfile, TextureMask)
AssetRef<ImageAsset> mRippleTexAssetRef;
GFXTexHandle getRippleTex() { return mRippleTexAssetRef.notNull() ? mRippleTexAssetRef.assetPtr->getTexture(&GFXStaticTextureProfile) : NULL; }
AssetRef<ImageAsset> mFoamTexAssetRef;
GFXTexHandle getFoamTex() { return mFoamTexAssetRef.notNull() ? mFoamTexAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
AssetRef<ImageAsset> mDepthGradientTexAssetRef;
GFXTexHandle getDepthGradientTex() { return mDepthGradientTexAssetRef.notNull() ? mDepthGradientTexAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
StringTableEntry mCubemapName;