mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
move population of image metadata to onAssetRefresh
This commit is contained in:
parent
3d77b59b71
commit
48b512ef73
2 changed files with 48 additions and 41 deletions
|
|
@ -345,6 +345,8 @@ void ImageAsset::initializeAsset(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mImageFile = expandAssetFilePath(mImageFile);
|
mImageFile = expandAssetFilePath(mImageFile);
|
||||||
|
|
||||||
|
populateImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageAsset::onAssetRefresh(void)
|
void ImageAsset::onAssetRefresh(void)
|
||||||
|
|
@ -356,6 +358,8 @@ void ImageAsset::onAssetRefresh(void)
|
||||||
// Call parent.
|
// Call parent.
|
||||||
Parent::onAssetRefresh();
|
Parent::onAssetRefresh();
|
||||||
|
|
||||||
|
populateImage();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
@ -395,46 +399,6 @@ void ImageAsset::setImageFile(StringTableEntry pImageFile)
|
||||||
|
|
||||||
mImageFile = getOwned() ? expandAssetFilePath(pImageFile) : StringTable->insert(pImageFile);
|
mImageFile = getOwned() ? expandAssetFilePath(pImageFile) : StringTable->insert(pImageFile);
|
||||||
|
|
||||||
if (Torque::FS::IsFile(mImageFile))
|
|
||||||
{
|
|
||||||
if (dStrEndsWith(mImageFile, ".dds"))
|
|
||||||
{
|
|
||||||
DDSFile* tempFile = new DDSFile();
|
|
||||||
FileStream* ddsFs;
|
|
||||||
if ((ddsFs = FileStream::createAndOpen(mImageFile, Torque::FS::File::Read)) == NULL)
|
|
||||||
{
|
|
||||||
Con::errorf("ImageAsset::setImageFile Failed to open ddsfile: %s", mImageFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tempFile->readHeader(*ddsFs))
|
|
||||||
{
|
|
||||||
Con::errorf("ImageAsset::setImageFile Failed to read header of ddsfile: %s", mImageFile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mImageWidth = tempFile->mWidth;
|
|
||||||
mImageHeight = tempFile->mHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
ddsFs->close();
|
|
||||||
delete tempFile;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!stbi_info(mImageFile, &mImageWidth, &mImageHeight, &mImageChannels))
|
|
||||||
{
|
|
||||||
StringTableEntry stbErr = stbi_failure_reason();
|
|
||||||
if (stbErr == StringTable->EmptyString())
|
|
||||||
stbErr = "ImageAsset::Unkown Error!";
|
|
||||||
|
|
||||||
Con::errorf("ImageAsset::setImageFile STB Get file info failed: %s", stbErr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we only support 2d textures..... for no ;)
|
|
||||||
mImageDepth = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshAsset();
|
refreshAsset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -675,6 +639,49 @@ void ImageAsset::onTamlCustomRead(const TamlCustomNodes& customNodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageAsset::populateImage(void)
|
||||||
|
{
|
||||||
|
if (Torque::FS::IsFile(mImageFile))
|
||||||
|
{
|
||||||
|
if (dStrEndsWith(mImageFile, ".dds"))
|
||||||
|
{
|
||||||
|
DDSFile* tempFile = new DDSFile();
|
||||||
|
FileStream* ddsFs;
|
||||||
|
if ((ddsFs = FileStream::createAndOpen(mImageFile, Torque::FS::File::Read)) == NULL)
|
||||||
|
{
|
||||||
|
Con::errorf("ImageAsset::setImageFile Failed to open ddsfile: %s", mImageFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tempFile->readHeader(*ddsFs))
|
||||||
|
{
|
||||||
|
Con::errorf("ImageAsset::setImageFile Failed to read header of ddsfile: %s", mImageFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mImageWidth = tempFile->mWidth;
|
||||||
|
mImageHeight = tempFile->mHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
ddsFs->close();
|
||||||
|
delete tempFile;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!stbi_info(mImageFile, &mImageWidth, &mImageHeight, &mImageChannels))
|
||||||
|
{
|
||||||
|
StringTableEntry stbErr = stbi_failure_reason();
|
||||||
|
if (stbErr == StringTable->EmptyString())
|
||||||
|
stbErr = "ImageAsset::Unkown Error!";
|
||||||
|
|
||||||
|
Con::errorf("ImageAsset::setImageFile STB Get file info failed: %s", stbErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we only support 2d textures..... for now ;)
|
||||||
|
mImageDepth = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char* ImageAsset::getImageInfo()
|
const char* ImageAsset::getImageInfo()
|
||||||
{
|
{
|
||||||
if (isAssetValid())
|
if (isAssetValid())
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ public:
|
||||||
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
|
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
|
||||||
static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
|
static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
|
||||||
|
|
||||||
|
void populateImage(void);
|
||||||
const char* getImageInfo();
|
const char* getImageInfo();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue