mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-02 12:03:51 +00:00
Merge branch 'Preview4_0' of https://github.com/TorqueGameEngines/Torque3D into BugfixQOL_20210909
This commit is contained in:
commit
dec9f54a9b
322 changed files with 10473 additions and 10241 deletions
|
|
@ -40,6 +40,10 @@
|
|||
#include "assets/assetPtr.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SFXSOURCE_H_
|
||||
#include "sfx/sfxSource.h"
|
||||
#endif
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
#include "sfx/sfxTypes.h"
|
||||
|
|
@ -159,7 +163,7 @@ void SoundAsset::initPersistFields()
|
|||
addField("maxDistance", TypeF32, Offset(mProfileDesc.mMaxDistance, SoundAsset), "Max distance for sound.");
|
||||
addField("coneInsideAngle", TypeS32, Offset(mProfileDesc.mConeInsideAngle, SoundAsset), "Cone inside angle.");
|
||||
addField("coneOutsideAngle", TypeS32, Offset(mProfileDesc.mConeOutsideAngle, SoundAsset), "Cone outside angle.");
|
||||
addField("coneOutsideVolume", TypeS32, Offset(mProfileDesc.mConeOutsideVolume, SoundAsset), "Cone outside volume.");
|
||||
addField("coneOutsideVolume", TypeF32, Offset(mProfileDesc.mConeOutsideVolume, SoundAsset), "Cone outside volume.");
|
||||
addField("rolloffFactor", TypeF32, Offset(mProfileDesc.mRolloffFactor, SoundAsset), "Rolloff factor.");
|
||||
addField("scatterDistance", TypePoint3F, Offset(mProfileDesc.mScatterDistance, SoundAsset), "Randomization to the spacial position of the sound.");
|
||||
addField("sourceGroup", TypeSFXSourceName, Offset(mProfileDesc.mSourceGroup, SoundAsset), "Group that sources playing with this description should be put into.");
|
||||
|
|
@ -181,13 +185,7 @@ void SoundAsset::initializeAsset(void)
|
|||
if (mSoundFile == StringTable->EmptyString())
|
||||
return;
|
||||
|
||||
//ResourceManager::get().getChangedSignal.notify(this, &SoundAsset::_onResourceChanged);
|
||||
|
||||
//Ensure our path is expando'd if it isn't already
|
||||
mSoundPath = getOwned() ? expandAssetFilePath(mSoundFile) : mSoundPath;
|
||||
|
||||
mSoundPath = expandAssetFilePath(mSoundPath);
|
||||
|
||||
loadSound();
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +206,6 @@ void SoundAsset::onAssetRefresh(void)
|
|||
|
||||
//Update
|
||||
mSoundPath = getOwned() ? expandAssetFilePath(mSoundFile) : mSoundPath;
|
||||
|
||||
loadSound();
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +222,7 @@ bool SoundAsset::loadSound()
|
|||
else
|
||||
{// = new SFXProfile(mProfileDesc, mSoundFile, mPreload);
|
||||
mSFXProfile.setDescription(&mProfileDesc);
|
||||
mSFXProfile.setSoundFileName(mSoundFile);
|
||||
mSFXProfile.setSoundFileName(mSoundPath);
|
||||
mSFXProfile.setPreload(mPreload);
|
||||
}
|
||||
|
||||
|
|
@ -254,11 +251,106 @@ void SoundAsset::setSoundFile(const char* pSoundFile)
|
|||
refreshAsset();
|
||||
}
|
||||
|
||||
StringTableEntry SoundAsset::getAssetIdByFileName(StringTableEntry fileName)
|
||||
{
|
||||
if (fileName == StringTable->EmptyString())
|
||||
return StringTable->EmptyString();
|
||||
|
||||
StringTableEntry materialAssetId = "";
|
||||
|
||||
AssetQuery query;
|
||||
U32 foundCount = AssetDatabase.findAssetType(&query, "SoundAsset");
|
||||
if (foundCount != 0)
|
||||
{
|
||||
for (U32 i = 0; i < foundCount; i++)
|
||||
{
|
||||
SoundAsset* soundAsset = AssetDatabase.acquireAsset<SoundAsset>(query.mAssetList[i]);
|
||||
if (soundAsset && soundAsset->getSoundPath() == fileName)
|
||||
{
|
||||
materialAssetId = soundAsset->getAssetId();
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]);
|
||||
break;
|
||||
}
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return materialAssetId;
|
||||
}
|
||||
|
||||
U32 SoundAsset::getAssetById(StringTableEntry assetId, AssetPtr<SoundAsset>* materialAsset)
|
||||
{
|
||||
(*materialAsset) = assetId;
|
||||
|
||||
if (materialAsset->notNull())
|
||||
{
|
||||
return (*materialAsset)->mLoadedState;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Well that's bad, loading the fallback failed.
|
||||
Con::warnf("MaterialAsset::getAssetById - Finding of asset with id %s failed with no fallback asset", assetId);
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
}
|
||||
|
||||
U32 SoundAsset::getAssetByFileName(StringTableEntry fileName, AssetPtr<SoundAsset>* soundAsset)
|
||||
{
|
||||
AssetQuery query;
|
||||
U32 foundAssetcount = AssetDatabase.findAssetType(&query, "SoundAsset");
|
||||
if (foundAssetcount == 0)
|
||||
{
|
||||
//Well that's bad, loading the fallback failed.
|
||||
Con::warnf("MaterialAsset::getAssetByMaterialName - Finding of asset associated with filename %s failed with no fallback asset", fileName);
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (U32 i = 0; i < foundAssetcount; i++)
|
||||
{
|
||||
SoundAsset* tSoundAsset = AssetDatabase.acquireAsset<SoundAsset>(query.mAssetList[i]);
|
||||
if (tSoundAsset && tSoundAsset->getSoundPath() == fileName)
|
||||
{
|
||||
soundAsset->setAssetId(query.mAssetList[i]);
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]);
|
||||
return (*soundAsset)->mLoadedState;
|
||||
}
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]); //cleanup if that's not the one we needed
|
||||
}
|
||||
}
|
||||
|
||||
//No good match
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
|
||||
DefineEngineMethod(SoundAsset, getSoundPath, const char*, (), , "")
|
||||
{
|
||||
return object->getSoundPath();
|
||||
}
|
||||
|
||||
DefineEngineMethod(SoundAsset, playSound, S32, (Point3F position), (Point3F::Zero),
|
||||
"Gets the number of materials for this shape asset.\n"
|
||||
"@return Material count.\n")
|
||||
{
|
||||
if (object->getSfxProfile())
|
||||
{
|
||||
MatrixF transform;
|
||||
transform.setPosition(position);
|
||||
SFXSource* source = SFX->playOnce(object->getSfxProfile(), &transform, NULL, -1);
|
||||
return source->getId();
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_TOOLS
|
||||
DefineEngineStaticMethod(SoundAsset, 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 SoundAsset::getAssetIdByFileName(StringTable->insert(filePath));
|
||||
}
|
||||
#endif
|
||||
IMPLEMENT_CONOBJECT(GuiInspectorTypeSoundAssetPtr);
|
||||
|
||||
ConsoleDocClass(GuiInspectorTypeSoundAssetPtr,
|
||||
|
|
@ -276,12 +368,63 @@ void GuiInspectorTypeSoundAssetPtr::consoleInit()
|
|||
|
||||
GuiControl * GuiInspectorTypeSoundAssetPtr::constructEditControl()
|
||||
{
|
||||
return nullptr;
|
||||
// Create base filename edit controls
|
||||
GuiControl* retCtrl = Parent::constructEditControl();
|
||||
if (retCtrl == NULL)
|
||||
return retCtrl;
|
||||
|
||||
// Change filespec
|
||||
char szBuffer[512];
|
||||
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"SoundAsset\", \"AssetBrowser.changeAsset\", %s, \"\");",
|
||||
getIdString());
|
||||
mBrowseButton->setField("Command", szBuffer);
|
||||
|
||||
setDataField(StringTable->insert("targetObject"), NULL, mInspector->getInspectObject()->getIdString());
|
||||
|
||||
// Create "Open in Editor" button
|
||||
mEditButton = new GuiBitmapButtonCtrl();
|
||||
|
||||
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.editAsset(%d.getText());", retCtrl->getId());
|
||||
mEditButton->setField("Command", szBuffer);
|
||||
|
||||
char bitmapName[512] = "ToolsModule:SFXEmitter_image";
|
||||
mEditButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mEditButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mEditButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
mEditButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
|
||||
mEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Test play this sound");
|
||||
|
||||
mEditButton->registerObject();
|
||||
addObject(mEditButton);
|
||||
|
||||
return retCtrl;
|
||||
}
|
||||
|
||||
bool GuiInspectorTypeSoundAssetPtr::updateRects()
|
||||
{
|
||||
return false;
|
||||
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 (mEditButton != NULL)
|
||||
{
|
||||
RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4);
|
||||
resized |= mEditButton->resize(shapeEdRect.point, shapeEdRect.extent);
|
||||
}
|
||||
|
||||
return resized;
|
||||
}
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiInspectorTypeSoundAssetId);
|
||||
|
|
|
|||
|
|
@ -122,6 +122,9 @@ public:
|
|||
bool isLoop() { return mProfileDesc.mIsLooping; }
|
||||
bool is3D() { return mProfileDesc.mIs3D; }
|
||||
|
||||
static StringTableEntry getAssetIdByFileName(StringTableEntry fileName);
|
||||
static U32 getAssetById(StringTableEntry assetId, AssetPtr<SoundAsset>* materialAsset);
|
||||
static U32 getAssetByFileName(StringTableEntry fileName, AssetPtr<SoundAsset>* matAsset);
|
||||
|
||||
protected:
|
||||
virtual void initializeAsset(void);
|
||||
|
|
@ -143,7 +146,7 @@ class GuiInspectorTypeSoundAssetPtr : public GuiInspectorTypeFileName
|
|||
typedef GuiInspectorTypeFileName Parent;
|
||||
public:
|
||||
|
||||
GuiBitmapButtonCtrl* mSoundButton;
|
||||
GuiBitmapButtonCtrl* mEditButton;
|
||||
|
||||
DECLARE_CONOBJECT(GuiInspectorTypeSoundAssetPtr);
|
||||
static void consoleInit();
|
||||
|
|
@ -168,14 +171,14 @@ public:
|
|||
/// Declares a sound asset
|
||||
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
|
||||
/// </Summary>
|
||||
#define DECLARE_SOUNDASSET(className, name, profile) public: \
|
||||
#define DECLARE_SOUNDASSET(className, name) public: \
|
||||
Resource<SFXResource> m##name;\
|
||||
StringTableEntry m##name##Name; \
|
||||
StringTableEntry m##name##AssetId;\
|
||||
AssetPtr<SoundAsset> m##name##Asset = NULL;\
|
||||
SFXProfile* m##name##Profile = &profile;\
|
||||
SFXProfile* m##name##Profile = NULL;\
|
||||
public: \
|
||||
const StringTableEntry get##name##File() const { return m##name##Name); }\
|
||||
const StringTableEntry get##name##File() const { return m##name##Name; }\
|
||||
void set##name##File(const FileName &_in) { m##name##Name = StringTable->insert(_in.c_str());}\
|
||||
const AssetPtr<SoundAsset> & get##name##Asset() const { return m##name##Asset; }\
|
||||
void set##name##Asset(const AssetPtr<SoundAsset> &_in) { m##name##Asset = _in;}\
|
||||
|
|
@ -206,7 +209,7 @@ public: \
|
|||
}\
|
||||
else\
|
||||
{\
|
||||
StringTableEntry assetId = SoundAsset::getAssetIdByFilename(_in);\
|
||||
StringTableEntry assetId = SoundAsset::getAssetIdByFileName(_in);\
|
||||
if (assetId != StringTable->EmptyString())\
|
||||
{\
|
||||
m##name##AssetId = assetId;\
|
||||
|
|
@ -232,9 +235,9 @@ public: \
|
|||
m##name = NULL;\
|
||||
}\
|
||||
\
|
||||
if (m##name##Asset.notNull() && m##name##Asset->getStatus() != ShapeAsset::Ok)\
|
||||
if (m##name##Asset.notNull() && m##name##Asset->getStatus() != SoundAsset::Ok)\
|
||||
{\
|
||||
Con::errorf("%s(%s)::_set%s() - sound asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, ShapeAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
|
||||
Con::errorf("%s(%s)::_set%s() - sound asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, SoundAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
|
||||
return false; \
|
||||
}\
|
||||
else if (m##name)\
|
||||
|
|
|
|||
|
|
@ -1382,32 +1382,32 @@ void AssetImporter::processImportAssets(AssetImportObject* assetItem)
|
|||
if (item->assetName != item->cleanAssetName)
|
||||
item->assetName = item->cleanAssetName;
|
||||
|
||||
//handle special pre-processing here for any types that need it
|
||||
|
||||
//process the asset items
|
||||
if (item->assetType == String("ImageAsset"))
|
||||
{
|
||||
processImageAsset(item);
|
||||
}
|
||||
else if (item->assetType == String("ShapeAsset"))
|
||||
{
|
||||
processShapeAsset(item);
|
||||
}
|
||||
/*else if (item->assetType == String("SoundAsset"))
|
||||
SoundAsset::prepareAssetForImport(this, item);*/
|
||||
else if (item->assetType == String("MaterialAsset"))
|
||||
{
|
||||
processMaterialAsset(item);
|
||||
}
|
||||
/*else if (item->assetType == String("ShapeAnimationAsset"))
|
||||
ShapeAnimationAsset::prepareAssetForImport(this, item);*/
|
||||
else
|
||||
{
|
||||
String processCommand = "process";
|
||||
processCommand += item->assetType;
|
||||
if(isMethod(processCommand.c_str()))
|
||||
Con::executef(this, processCommand.c_str(), item);
|
||||
}
|
||||
//process the asset items
|
||||
if (item->assetType == String("ImageAsset"))
|
||||
{
|
||||
processImageAsset(item);
|
||||
}
|
||||
else if (item->assetType == String("ShapeAsset"))
|
||||
{
|
||||
processShapeAsset(item);
|
||||
}
|
||||
else if (item->assetType == String("SoundAsset"))
|
||||
{
|
||||
processSoundAsset(item);
|
||||
}
|
||||
else if (item->assetType == String("MaterialAsset"))
|
||||
{
|
||||
processMaterialAsset(item);
|
||||
}
|
||||
/*else if (item->assetType == String("ShapeAnimationAsset"))
|
||||
ShapeAnimationAsset::prepareAssetForImport(this, item);*/
|
||||
else
|
||||
{
|
||||
String processCommand = "process";
|
||||
processCommand += item->assetType;
|
||||
if(isMethod(processCommand.c_str()))
|
||||
Con::executef(this, processCommand.c_str(), item);
|
||||
}
|
||||
|
||||
item->importStatus == AssetImportObject::Processed;
|
||||
|
||||
|
|
@ -1975,93 +1975,12 @@ void AssetImporter::processShapeMaterialInfo(AssetImportObject* assetItem, S32 m
|
|||
|
||||
void AssetImporter::processSoundAsset(AssetImportObject* assetItem)
|
||||
{
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Preparing Image for Import: %s", assetItem->assetName.c_str());
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Preparing Sound for Import: %s", assetItem->assetName.c_str());
|
||||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
if ((activeImportConfig->GenerateMaterialOnImport && assetItem->parentAssetItem == nullptr)/* || assetItem->parentAssetItem != nullptr*/)
|
||||
{
|
||||
//find our suffix match, if any
|
||||
String noSuffixName = assetItem->assetName;
|
||||
String suffixType;
|
||||
String suffix = parseImageSuffixes(assetItem->assetName, &suffixType);
|
||||
if (suffix.isNotEmpty())
|
||||
{
|
||||
assetItem->imageSuffixType = suffixType;
|
||||
S32 suffixPos = assetItem->assetName.find(suffix, 0, String::NoCase | String::Left);
|
||||
noSuffixName = assetItem->assetName.substr(0, suffixPos);
|
||||
}
|
||||
|
||||
//We try to automatically populate materials under the naming convention: materialName: Rock, image maps: Rock_Albedo, Rock_Normal, etc
|
||||
|
||||
AssetImportObject* materialAsset = findImportingAssetByName(noSuffixName);
|
||||
if (materialAsset != nullptr && materialAsset->assetType != String("MaterialAsset"))
|
||||
{
|
||||
//We may have a situation where an asset matches the no-suffix name, but it's not a material asset. Ignore this
|
||||
//asset item for now
|
||||
|
||||
materialAsset = nullptr;
|
||||
}
|
||||
|
||||
//If we didn't find a matching material asset in our current items, we'll make one now
|
||||
if (materialAsset == nullptr)
|
||||
{
|
||||
if (!assetItem->filePath.isEmpty())
|
||||
{
|
||||
materialAsset = addImportingAsset("MaterialAsset", assetItem->filePath, nullptr, noSuffixName);
|
||||
}
|
||||
}
|
||||
|
||||
//Not that, one way or another, we have the generated material asset, lets move on to associating our image with it
|
||||
if (materialAsset != nullptr && materialAsset != assetItem->parentAssetItem)
|
||||
{
|
||||
if (assetItem->parentAssetItem != nullptr)
|
||||
{
|
||||
//If the image had an existing parent, it gets removed from that parent's child item list
|
||||
assetItem->parentAssetItem->childAssetItems.remove(assetItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
//If it didn't have one, we're going to pull it from the importingAssets list
|
||||
importingAssets.remove(assetItem);
|
||||
}
|
||||
|
||||
//Now we can add it to the correct material asset
|
||||
materialAsset->childAssetItems.push_back(assetItem);
|
||||
assetItem->parentAssetItem = materialAsset;
|
||||
|
||||
assetHeirarchyChanged = true;
|
||||
}
|
||||
|
||||
//Now to do some cleverness. If we're generating a material, we can parse like assets being imported(similar filenames) but different suffixes
|
||||
//If we find these, we'll just populate into the original's material
|
||||
|
||||
//if we need to append the diffuse suffix and indeed didn't find a suffix on the name, do that here
|
||||
if (suffixType.isEmpty())
|
||||
{
|
||||
if (activeImportConfig->UseDiffuseSuffixOnOriginImage)
|
||||
{
|
||||
String diffuseToken = StringUnit::getUnit(activeImportConfig->DiffuseTypeSuffixes, 0, ",;\t");
|
||||
assetItem->assetName = assetItem->assetName + diffuseToken;
|
||||
assetItem->cleanAssetName = assetItem->assetName;
|
||||
}
|
||||
else
|
||||
{
|
||||
//We need to ensure that our image asset doesn't match the same name as the material asset, so if we're not trying to force the diffuse suffix
|
||||
//we'll give it a generic one
|
||||
if ((materialAsset && materialAsset->assetName.compare(assetItem->assetName) == 0) || activeImportConfig->AlwaysAddImageSuffix)
|
||||
{
|
||||
assetItem->assetName = assetItem->assetName + activeImportConfig->AddedImageSuffix;
|
||||
assetItem->cleanAssetName = assetItem->assetName;
|
||||
}
|
||||
}
|
||||
|
||||
//Assume for abledo if it has no suffix matches
|
||||
assetItem->imageSuffixType = "Albedo";
|
||||
}
|
||||
}
|
||||
|
||||
assetItem->importStatus = AssetImportObject::Processed;
|
||||
}
|
||||
|
||||
//
|
||||
// Validation
|
||||
//
|
||||
|
|
@ -2514,6 +2433,8 @@ void AssetImporter::importAssets(AssetImportObject* assetItem)
|
|||
|
||||
if (!refreshSuccess)
|
||||
{
|
||||
const char* importReturnVal = Con::executef(this, processCommand.c_str(), childItem).getString();
|
||||
assetPath = Torque::Path(importReturnVal);
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Failed to refresh reimporting asset %s.", item->assetName.c_str());
|
||||
activityLog.push_back(importLogBuffer);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue