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

@ -149,7 +149,8 @@ void ParticleData::initPersistFields()
{
docsURL;
addGroup("Basic");
INITPERSISTFIELD_IMAGEASSET(Texture, ParticleData, "Texture to use for this particle.");
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, ParticleData))
.doc("Texture asset to use for this particle");
addField("useInvAlpha", TYPEID< bool >(), Offset(useInvAlpha, ParticleData),
"@brief Controls how particles blend with the scene.\n\n"
"If true, particles blend like ParticleBlendStyle NORMAL, if false, "
@ -234,7 +235,8 @@ void ParticleData::initPersistFields()
endGroup("Over Time");
addGroup("AFX");
INITPERSISTFIELD_IMAGEASSET(TextureExt, ParticleData, "");
ADD_FIELD("textureExtAsset", TypeImageAssetRef, Offset(mTextureExtAssetRef, ParticleData))
.doc("");
addField("constrainPos", TypeBool, Offset(constrain_pos, ParticleData));
addFieldV("angle", TypeRangedF32, Offset(start_angle, ParticleData), &CommonValidators::DegreeRange);
addFieldV("angleVariance", TypeRangedF32, Offset(angle_variance, ParticleData), &CommonValidators::DegreeRange);
@ -299,7 +301,7 @@ void ParticleData::packData(BitStream* stream)
stream->writeFloat( times[i], 8);
}
PACKDATA_ASSET_REFACTOR(Texture);
AssetDatabase.packDataAsset(stream, mTextureAssetRef.assetId);
for (i = 0; i < 4; i++)
mathWrite(*stream, texCoords[i]);
@ -313,7 +315,7 @@ void ParticleData::packData(BitStream* stream)
stream->writeInt(framesPerSec, 8);
}
PACKDATA_ASSET_REFACTOR(TextureExt);
AssetDatabase.packDataAsset(stream, mTextureExtAssetRef.assetId);
stream->writeFlag(constrain_pos);
stream->writeFloat(start_angle/360.0f, 11);
@ -384,7 +386,7 @@ void ParticleData::unpackData(BitStream* stream)
times[i] = stream->readFloat(8);
}
UNPACKDATA_ASSET_REFACTOR(Texture);
mTextureAssetRef = AssetDatabase.unpackDataAsset(stream);
for (i = 0; i < 4; i++)
mathRead(*stream, &texCoords[i]);
@ -397,7 +399,7 @@ void ParticleData::unpackData(BitStream* stream)
framesPerSec = stream->readInt(8);
}
UNPACKDATA_ASSET_REFACTOR(TextureExt);
mTextureExtAssetRef = AssetDatabase.unpackDataAsset(stream);
constrain_pos = stream->readFlag();
start_angle = 360.0f*stream->readFloat(11);
@ -669,6 +671,10 @@ bool ParticleData::preload(bool server, String &errorStr)
delete [] tokCopy;
numFrames = animTexFrames.size();
}
if (!mTextureAssetRef.isNull())
mTextureAssetRef.assetPtr->load();
}
return !error;
@ -773,12 +779,12 @@ ParticleData::ParticleData(const ParticleData& other, bool temp_clone) : SimData
animTexFramesString = other.animTexFramesString;
animTexFrames = other.animTexFrames; // -- parsed from animTexFramesString
CLONE_ASSET_REFACTOR(Texture);
mTextureAssetRef = other.mTextureAssetRef;
spinBias = other.spinBias;
randomizeSpinDir = other.randomizeSpinDir;
CLONE_ASSET_REFACTOR(TextureExt);
mTextureExtAssetRef = other.mTextureExtAssetRef;
constrain_pos = other.constrain_pos;
start_angle = other.start_angle;
@ -814,7 +820,16 @@ void ParticleData::onPerformSubstitutions()
reload(errorBuffer);
}
DEF_ASSET_BINDS_REFACTOR(ParticleData, Texture);
DefineEngineMethod(ParticleData, getTextureAsset, StringTableEntry, (), ,
"Texture asset reference")
{
return object->mTextureAssetRef.getAssetId();
}
DefineEngineMethod(ParticleData, setTexture, void, (const char* assetName), ,
"Texture assignment.")
{
object->mTextureAssetRef = StringTable->insert(assetName);
}
ConsoleType(stringList, TypeParticleList, Vector<StringTableEntry>, "")
@ -907,8 +922,8 @@ GuiControl* GuiInspectorTypeParticleDataList::constructEditControl()
mNewParticleBtn->setDataField(StringTable->insert("hovertime"), NULL, "1000");
mNewParticleBtn->setDataField(StringTable->insert("tooltip"), NULL, "Add new particle slot");
mNewParticleBtn->setHorizSizing(horizResizeRight);
mNewParticleBtn->mMakeIconSquare = true;
mNewParticleBtn->mFitBitmapToButton = true;
mNewParticleBtn->setMakeIconSquare(true);
mNewParticleBtn->setFitBitmapToButton(true);
mNewParticleBtn->setExtent(20, 20);
char szBuffer[512];
@ -1003,8 +1018,8 @@ GuiControl* GuiInspectorTypeParticleDataList::_buildParticleEntryField(const S32
deleteSlotBtn->setDataField(StringTable->insert("tooltip"), NULL, "Delete this particle slot");
deleteSlotBtn->setHorizSizing(horizResizeRight);
deleteSlotBtn->setInternalName("deleteBtn");
deleteSlotBtn->mMakeIconSquare = true;
deleteSlotBtn->mFitBitmapToButton = true;
deleteSlotBtn->setMakeIconSquare(true);
deleteSlotBtn->setFitBitmapToButton(true);
deleteSlotBtn->setPosition(editExtent.x - 20, 0);
deleteSlotBtn->setExtent(20, 20);

View file

@ -87,7 +87,10 @@ class ParticleData : public SimDataBlock
StringTableEntry animTexFramesString;
Vector<U8> animTexFrames;
DECLARE_IMAGEASSET(ParticleData, Texture, GFXStaticTextureSRGBProfile)
AssetRef<ImageAsset> mTextureAssetRef;
GFXTexHandle getTexture() { return mTextureAssetRef.notNull() ? mTextureAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
AssetPtr<ImageAsset> getTextureAsset() { return mTextureAssetRef.assetPtr; }
static bool protectedSetSizes(void* object, const char* index, const char* data);
static bool protectedSetTimes(void* object, const char* index, const char* data);
@ -115,7 +118,9 @@ public:
F32 spinBias;
bool randomizeSpinDir;
public:
DECLARE_IMAGEASSET(ParticleData, TextureExt,GFXStaticTextureSRGBProfile)
AssetRef<ImageAsset> mTextureExtAssetRef;
GFXTexHandle getTextureExt() { return mTextureExtAssetRef.notNull() ? mTextureExtAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
bool constrain_pos;
F32 start_angle;

View file

@ -142,7 +142,8 @@ void PrecipitationData::initPersistFields()
docsURL;
INITPERSISTFIELD_SOUNDASSET(Sound, PrecipitationData, "Looping SFXProfile effect to play while Precipitation is active.");
INITPERSISTFIELD_IMAGEASSET(Drop, PrecipitationData, "@brief Texture for drop particles.\n\n"
ADD_FIELD("DropAsset", TypeImageAssetRef, Offset(mDropAssetRef, PrecipitationData))
.doc("@brief Texture asset for drop particles.\n\n"
"The drop texture can contain several different drop sub-textures "
"arranged in a grid. There must be the same number of rows as columns. A "
"random frame will be chosen for each drop.");
@ -150,7 +151,8 @@ void PrecipitationData::initPersistFields()
addField( "dropShader", TypeString, Offset(mDropShaderName, PrecipitationData),
"The name of the shader used for raindrops." );
INITPERSISTFIELD_IMAGEASSET(Splash, PrecipitationData, "@brief Texture for splash particles.\n\n"
ADD_FIELD("SplashAsset", TypeImageAssetRef, Offset(mSplashAssetRef, PrecipitationData))
.doc("@brief Texture asset for splash particles.\n\n"
"The splash texture can contain several different splash sub-textures "
"arranged in a grid. There must be the same number of rows as columns. A "
"random frame will be chosen for each splash.");
@ -179,6 +181,12 @@ bool PrecipitationData::preload( bool server, String &errorStr )
{
//return false; -TODO: trigger asset download
}
if (!mDropAssetRef.isNull())
mDropAssetRef.assetPtr->load();
if (!mSplashAssetRef.isNull())
mSplashAssetRef.assetPtr->load();
}
return true;
@ -190,11 +198,11 @@ void PrecipitationData::packData(BitStream* stream)
PACKDATA_ASSET(Sound);
PACKDATA_ASSET_REFACTOR(Drop);
AssetDatabase.packDataAsset(stream, mDropAssetRef.assetId);
stream->writeString(mDropShaderName);
PACKDATA_ASSET_REFACTOR(Splash);
AssetDatabase.packDataAsset(stream, mSplashAssetRef.assetId);
stream->writeString(mSplashShaderName);
stream->write(mDropsPerSide);
@ -207,11 +215,11 @@ void PrecipitationData::unpackData(BitStream* stream)
UNPACKDATA_ASSET(Sound);
UNPACKDATA_ASSET_REFACTOR(Drop);
mDropAssetRef = AssetDatabase.unpackDataAsset(stream);
mDropShaderName = stream->readSTString();
UNPACKDATA_ASSET_REFACTOR(Splash);
mSplashAssetRef = AssetDatabase.unpackDataAsset(stream);
mSplashShaderName = stream->readSTString();
stream->read(&mDropsPerSide);

View file

@ -49,11 +49,17 @@ class PrecipitationData : public GameBaseData
DECLARE_SOUNDASSET(PrecipitationData, Sound);
DECLARE_ASSET_SETGET(PrecipitationData, Sound);
DECLARE_IMAGEASSET(PrecipitationData, Drop, GFXStaticTextureSRGBProfile) ///< Texture for drop particles
AssetRef<ImageAsset> mDropAssetRef;
GFXTexHandle getDrop() { return mDropAssetRef.notNull() ? mDropAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
AssetPtr<ImageAsset> getDropAsset() { return mDropAssetRef.assetPtr; }
StringTableEntry mDropShaderName; ///< The name of the shader used for raindrops
DECLARE_IMAGEASSET(PrecipitationData, Splash, GFXStaticTextureSRGBProfile) ///< Texture for splash particles
AssetRef<ImageAsset> mSplashAssetRef;
GFXTexHandle getSplash() { return mSplashAssetRef.notNull() ? mSplashAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
AssetPtr<ImageAsset> getSplashAsset() { return mSplashAssetRef.assetPtr; }
StringTableEntry mSplashShaderName; ///< The name of the shader used for raindrops

View file

@ -128,7 +128,9 @@ void SplashData::initPersistFields()
addFieldV("times", TypeRangedF32, Offset(times, SplashData), &CommonValidators::NormalizedFloat, NUM_TIME_KEYS, "Times to transition through the splash effect. Up to 4 allowed. Values are 0.0 - 1.0, and corrispond to the life of the particle where 0 is first created and 1 is end of lifespace.\n" );
addField("colors", TypeColorF, Offset(colors, SplashData), NUM_TIME_KEYS, "Color values to set the splash effect, rgba. Up to 4 allowed. Will transition through colors based on values set in the times value. Example: colors[0] = \"0.6 1.0 1.0 0.5\".\n" );
INITPERSISTFIELD_IMAGEASSET_ARRAY(Texture, NUM_TEX, SplashData, "Image to use as the texture for the splash effect.\n");
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, SplashData))
.elements(NUM_TEX)
.doc("Image asset to use as the texture for the splash effect.\n");
addFieldV("texWrap", TypeRangedF32, Offset(texWrap, SplashData), &CommonValidators::NormalizedFloat, "Amount to wrap the texture around the splash ring, 0.0f - 1.0f.\n");
addFieldV("texFactor", TypeRangedF32, Offset(texFactor, SplashData), &CommonValidators::NormalizedFloat, "Factor in which to apply the texture to the splash ring, 0.0f - 1.0f.\n");
@ -195,7 +197,8 @@ void SplashData::packData(BitStream* stream)
stream->writeRangedU32(explosion->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast);
}
PACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX);
for (U32 i = 0; i < NUM_TEX; i++)
AssetDatabase.packDataAsset(stream, mTextureAssetRef[i].assetId);
S32 i;
for( i=0; i<NUM_EMITTERS; i++ )
@ -248,7 +251,8 @@ void SplashData::unpackData(BitStream* stream)
explosionId = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );
}
UNPACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX);
for (U32 i = 0; i < NUM_TEX; i++)
mTextureAssetRef[i] = AssetDatabase.unpackDataAsset(stream);
U32 i;
for( i=0; i<NUM_EMITTERS; i++ )
@ -301,9 +305,9 @@ bool SplashData::preload(bool server, String &errorStr)
for( i=0; i<NUM_TEX; i++ )
{
if (mTextureAsset[i].isNull())
if (!mTextureAssetRef[i].isNull())
{
_setTexture(_getTexture(i), i);
mTextureAssetRef[i].assetPtr->load();
}
}
}

View file

@ -122,7 +122,7 @@ public:
F32 times[ NUM_TIME_KEYS ];
LinearColorF colors[ NUM_TIME_KEYS ];
DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, GFXStaticTextureSRGBProfile, NUM_TEX)
AssetRef<ImageAsset> mTextureAssetRef[NUM_TEX];
ExplosionData* explosion;
S32 explosionId;