Merge pull request #1782 from Areloch/matAndTerrMatAssetConvert
Some checks failed
Linux Build / Ubuntu GCC Latest (push) Has been cancelled
Linux Build / Ubuntu GCC 13 (push) Has been cancelled
MacOSX Build / macOS ARM Clang Ninja (push) Has been cancelled
MacOSX Build / macOS ARM Xcode (push) Has been cancelled
Windows Build / Windows MSVC Ninja (push) Has been cancelled
Windows Build / Windows MSVC Visual Studio 2022 (push) Has been cancelled
Windows Build / Windows MSVC Visual Studio 2026 (push) Has been cancelled

Update MaterialAsset and TerrainAsset to AssetRef standardization
This commit is contained in:
Brian Roberts 2026-07-04 13:02:46 -05:00 committed by GitHub
commit 451f0f09b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 583 additions and 698 deletions

View file

@ -459,25 +459,6 @@ void ImageAsset::initializeAsset(void)
Torque::FS::AddChangeNotification(mImageFile, this, &ImageAsset::_onResourceChanged); Torque::FS::AddChangeNotification(mImageFile, this, &ImageAsset::_onResourceChanged);
populateImage(); populateImage();
//Make sure our fallbacks are valid
if (smNoImageAssetFallbackAssetPtr.isNull())
{
smNoImageAssetFallbackAssetPtr = smNoImageAssetFallback;
if (smNoImageAssetFallbackAssetPtr.isNull())
Con::errorf("ImageAsset::initializeAsset could not find fallback asset %s!", smNoImageAssetFallback);
else
smNoImageAssetFallbackAssetPtr->load();
}
if (smNamedTargetAssetFallbackAssetPtr.isNull())
{
smNamedTargetAssetFallbackAssetPtr = smNamedTargetAssetFallback;
if (smNamedTargetAssetFallbackAssetPtr.isNull())
Con::errorf("ImageAsset::initializeAsset could not find named target fallback asset %s!", smNamedTargetAssetFallback);
else
smNamedTargetAssetFallbackAssetPtr->load();
}
} }
void ImageAsset::onAssetRefresh(void) void ImageAsset::onAssetRefresh(void)
@ -860,6 +841,45 @@ DefineEngineMethod(ImageAsset, isNamedTarget, bool, (), ,
return object->isNamedTarget(); return object->isNamedTarget();
} }
DefineEngineFunction(loadImageAssetFallback, S32, (), ,
"Forces the loading of the ImageAsset fallback asset.\n"
"@return Load status code.")
{
if (ImageAsset::smNoImageAssetFallbackAssetPtr.isNull())
{
ImageAsset::smNoImageAssetFallbackAssetPtr = ImageAsset::smNoImageAssetFallback;
if (ImageAsset::smNoImageAssetFallbackAssetPtr.isNull())
Con::errorf("loadImageAssetFallback could not find fallback asset %s!", ImageAsset::smNoImageAssetFallback);
else
return (S32)ImageAsset::smNoImageAssetFallbackAssetPtr->load();
}
else
{
return (S32)ImageAsset::smNoImageAssetFallbackAssetPtr->getStatus();
}
return AssetBase::Failed;
}
DefineEngineFunction(loadNamedTargetFallback, S32, (), ,
"Forces the loading of the ImageAsset Named Target fallback asset.\n"
"@return Load status code.")
{
if (ImageAsset::smNamedTargetAssetFallbackAssetPtr.isNull())
{
ImageAsset::smNamedTargetAssetFallbackAssetPtr = ImageAsset::smNamedTargetAssetFallback;
if (ImageAsset::smNamedTargetAssetFallbackAssetPtr.isNull())
Con::errorf("loadNamedTargetFallback could not find fallback asset %s!", ImageAsset::smNamedTargetAssetFallback);
else
return (S32)ImageAsset::smNamedTargetAssetFallbackAssetPtr->load();
}
else
{
return (S32)ImageAsset::smNamedTargetAssetFallbackAssetPtr->getStatus();
}
return AssetBase::Failed;
}
#ifdef TORQUE_TOOLS #ifdef TORQUE_TOOLS
DefineEngineStaticMethod(ImageAsset, getAssetIdByFilename, const char*, (const char* filePath), (""), DefineEngineStaticMethod(ImageAsset, getAssetIdByFilename, const char*, (const char* filePath), (""),

View file

@ -44,6 +44,7 @@
#include "T3D/assets/assetImporter.h" #include "T3D/assets/assetImporter.h"
StringTableEntry MaterialAsset::smNoMaterialAssetFallback = NULL; StringTableEntry MaterialAsset::smNoMaterialAssetFallback = NULL;
AssetPtr<MaterialAsset> MaterialAsset::smNoMaterialAssetFallbackAssetPtr = NULL;
const String MaterialAsset::mErrCodeStrings[] = const String MaterialAsset::mErrCodeStrings[] =
{ {
@ -56,6 +57,9 @@ const String MaterialAsset::mErrCodeStrings[] =
IMPLEMENT_CONOBJECT(MaterialAsset); IMPLEMENT_CONOBJECT(MaterialAsset);
IMPLEMENT_STRUCT(AssetRef<MaterialAsset>, AssetRefMaterialAsset, , "")
END_IMPLEMENT_STRUCT
ConsoleType(MaterialAssetPtr, TypeMaterialAssetPtr, MaterialAsset, ASSET_ID_FIELD_PREFIX) ConsoleType(MaterialAssetPtr, TypeMaterialAssetPtr, MaterialAsset, ASSET_ID_FIELD_PREFIX)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -126,6 +130,43 @@ ConsoleSetType(TypeMaterialAssetId)
// Warn. // Warn.
Con::warnf("(TypeMaterialAssetId) - Cannot set multiple args to a single asset."); Con::warnf("(TypeMaterialAssetId) - Cannot set multiple args to a single asset.");
} }
//-----------------------------------------------------------------------------
ConsoleType(MaterialAssetRef, TypeMaterialAssetRef, AssetRef<MaterialAsset>, ASSET_ID_FIELD_PREFIX)
ConsoleGetType(TypeMaterialAssetRef)
{
AssetRef<MaterialAsset>& ref = *((AssetRef<MaterialAsset>*)dptr);
if (ref.assetPtr.isNull())
return ref.assetId;
else
return ref.assetPtr.getAssetId();
}
ConsoleSetType(TypeMaterialAssetRef)
{
if (argc == 1)
{
const char* pFieldValue = argv[0];
AssetRef<MaterialAsset>* pAssetRef = (AssetRef<MaterialAsset>*)(dptr);
if (pAssetRef == NULL)
{
Con::warnf("(TypeMaterialAssetRef) - Failed to set asset Id '%d'.", pFieldValue);
return;
}
*pAssetRef = pFieldValue;
return;
}
Con::warnf("(TypeMaterialAssetRef) - Cannot set multiple args to a single asset.");
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
MaterialAsset::MaterialAsset() MaterialAsset::MaterialAsset()
@ -245,12 +286,34 @@ void MaterialAsset::setScriptFile(const char* pScriptFile)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
U32 MaterialAsset::load() StringTableEntry MaterialAsset::getMaterialName()
{ {
if (mMaterialDefinition) if (mMaterialDefinition)
{ return mMatDefinitionName;
mMaterialDefinition->safeDeleteObject();
} if (smNoMaterialAssetFallbackAssetPtr.notNull())
return smNoMaterialAssetFallbackAssetPtr->getMaterialName();
return StringTable->EmptyString();
}
SimObjectPtr<Material> MaterialAsset::getMaterial()
{
if (mMaterialDefinition)
return mMaterialDefinition;
if (smNoMaterialAssetFallbackAssetPtr.notNull())
return smNoMaterialAssetFallbackAssetPtr->getMaterial();
return NULL;
}
//------------------------------------------------------------------------------
U32 MaterialAsset::load()
{
if (mLoadedState == AssetErrCode::Ok)
return mLoadedState;
if (mLoadedState == EmbeddedDefinition) if (mLoadedState == EmbeddedDefinition)
{ {
@ -333,7 +396,7 @@ U32 MaterialAsset::getAssetByMaterialName(StringTableEntry matName, AssetPtr<Mat
for (U32 i = 0; i < foundAssetcount; i++) for (U32 i = 0; i < foundAssetcount; i++)
{ {
MaterialAsset* tMatAsset = AssetDatabase.acquireAsset<MaterialAsset>(query.mAssetList[i]); MaterialAsset* tMatAsset = AssetDatabase.acquireAsset<MaterialAsset>(query.mAssetList[i]);
if (tMatAsset && tMatAsset->getMaterialDefinitionName() == matName) if (tMatAsset && tMatAsset->getMaterialName() == matName)
{ {
matAsset->setAssetId(query.mAssetList[i]); matAsset->setAssetId(query.mAssetList[i]);
AssetDatabase.releaseAsset(query.mAssetList[i]); AssetDatabase.releaseAsset(query.mAssetList[i]);
@ -366,7 +429,7 @@ StringTableEntry MaterialAsset::getAssetIdByMaterialName(StringTableEntry matNam
MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(query.mAssetList[i]); MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(query.mAssetList[i]);
if (matAsset) if (matAsset)
{ {
if (matAsset->getMaterialDefinitionName() == matName) if (matAsset->getMaterialName() == matName)
materialAssetId = matAsset->getAssetId(); materialAssetId = matAsset->getAssetId();
AssetDatabase.releaseAsset(query.mAssetList[i]); AssetDatabase.releaseAsset(query.mAssetList[i]);
@ -422,6 +485,26 @@ SimObjectPtr<Material> MaterialAsset::findMaterialDefinitionByAssetId(StringTabl
return NULL; return NULL;
} }
DefineEngineFunction(loadMaterialAssetFallback, S32, (), ,
"Forces the loading of the MaterialAsset fallback asset.\n"
"@return Load status code.")
{
if (MaterialAsset::smNoMaterialAssetFallbackAssetPtr.isNull())
{
MaterialAsset::smNoMaterialAssetFallbackAssetPtr = MaterialAsset::smNoMaterialAssetFallback;
if (MaterialAsset::smNoMaterialAssetFallbackAssetPtr.isNull())
Con::errorf("loadMaterialAssetFallback could not find fallback asset %s!", MaterialAsset::smNoMaterialAssetFallback);
else
return (S32)MaterialAsset::smNoMaterialAssetFallbackAssetPtr->load();
}
else
{
return (S32)MaterialAsset::smNoMaterialAssetFallbackAssetPtr->getStatus();
}
return AssetBase::Failed;
}
#ifdef TORQUE_TOOLS #ifdef TORQUE_TOOLS
DefineEngineStaticMethod(MaterialAsset, getAssetIdByMaterialName, const char*, (const char* materialName), (""), DefineEngineStaticMethod(MaterialAsset, getAssetIdByMaterialName, const char*, (const char* materialName), (""),
"Queries the Asset Database to see if any asset exists that is associated with the provided material name.\n" "Queries the Asset Database to see if any asset exists that is associated with the provided material name.\n"
@ -623,14 +706,14 @@ void GuiInspectorTypeMaterialAssetPtr::updatePreviewImage()
AssetPtr<MaterialAsset> matAssetDef = matAssetId; AssetPtr<MaterialAsset> matAssetDef = matAssetId;
if (matAssetDef.isNull() || matAssetDef->getStatus() != AssetBase::AssetErrCode::Ok || if (matAssetDef.isNull() || matAssetDef->getStatus() != AssetBase::AssetErrCode::Ok ||
matAssetDef->getMaterialDefinitionName() == StringTable->EmptyString()) matAssetDef->getMaterialName() == StringTable->EmptyString())
{ {
mPreviewImage->_setBitmap(StringTable->insert("Core_Rendering:WarningMaterial")); mPreviewImage->_setBitmap(StringTable->insert("Core_Rendering:WarningMaterial"));
return; return;
} }
Material* matDef; Material* matDef;
if (!Sim::findObject(matAssetDef->getMaterialDefinitionName(), matDef)) if (!Sim::findObject(matAssetDef->getMaterialName(), matDef))
{ {
mPreviewImage->_setBitmap(StringTable->insert("Core_Rendering:WarningMaterial")); mPreviewImage->_setBitmap(StringTable->insert("Core_Rendering:WarningMaterial"));
return; return;
@ -683,9 +766,9 @@ void GuiInspectorTypeMaterialAssetPtr::setPreviewImage(StringTableEntry assetId)
if (AssetDatabase.isDeclaredAsset(assetId)) if (AssetDatabase.isDeclaredAsset(assetId))
{ {
MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(assetId); MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(assetId);
if (matAsset && matAsset->getMaterialDefinition()) if (matAsset && matAsset->getMaterial())
{ {
mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->getDiffuseMapAssetId(0)); mPreviewImage->_setBitmap(matAsset->getMaterial()->getDiffuseMapAssetId(0));
} }
} }
} }
@ -708,4 +791,21 @@ void GuiInspectorTypeMaterialAssetId::consoleInit()
ConsoleBaseType::getType(TypeMaterialAssetId)->setInspectorFieldType("GuiInspectorTypeMaterialAssetId"); ConsoleBaseType::getType(TypeMaterialAssetId)->setInspectorFieldType("GuiInspectorTypeMaterialAssetId");
} }
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(GuiInspectorTypeMaterialAssetRef);
ConsoleDocClass(GuiInspectorTypeMaterialAssetRef,
"@brief Inspector field type for AssetRef<MaterialAsset> fields\n\n"
"Editor use only.\n\n"
"@internal"
);
void GuiInspectorTypeMaterialAssetRef::consoleInit()
{
Parent::consoleInit();
ConsoleBaseType::getType(TypeMaterialAssetRef)->setInspectorFieldType("GuiInspectorTypeMaterialAssetRef");
}
#endif #endif

View file

@ -74,6 +74,7 @@ class MaterialAsset : public AssetBase
public: public:
static StringTableEntry smNoMaterialAssetFallback; static StringTableEntry smNoMaterialAssetFallback;
static AssetPtr<MaterialAsset> smNoMaterialAssetFallbackAssetPtr;
enum MaterialAssetErrCode enum MaterialAssetErrCode
{ {
@ -106,8 +107,8 @@ public:
U32 load() override; U32 load() override;
StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; } StringTableEntry getMaterialName();
SimObjectPtr<Material> getMaterialDefinition() { return mMaterialDefinition; } SimObjectPtr<Material> getMaterial();
void setScriptFile(const char* pScriptFile); void setScriptFile(const char* pScriptFile);
inline StringTableEntry getScriptFile(void) const { return mScriptFile; }; inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
@ -143,6 +144,8 @@ protected:
DefineConsoleType(TypeMaterialAssetPtr, MaterialAsset) DefineConsoleType(TypeMaterialAssetPtr, MaterialAsset)
DefineConsoleType(TypeMaterialAssetId, String) DefineConsoleType(TypeMaterialAssetId, String)
DECLARE_STRUCT(AssetRef<MaterialAsset>)
DefineConsoleType(TypeMaterialAssetRef, AssetRef<MaterialAsset>)
#ifdef TORQUE_TOOLS #ifdef TORQUE_TOOLS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// TypeAssetId GuiInspectorField Class // TypeAssetId GuiInspectorField Class
@ -177,142 +180,16 @@ public:
DECLARE_CONOBJECT(GuiInspectorTypeMaterialAssetId); DECLARE_CONOBJECT(GuiInspectorTypeMaterialAssetId);
static void consoleInit(); static void consoleInit();
}; };
class GuiInspectorTypeMaterialAssetRef : public GuiInspectorTypeMaterialAssetPtr
{
typedef GuiInspectorTypeMaterialAssetPtr Parent;
public:
DECLARE_CONOBJECT(GuiInspectorTypeMaterialAssetRef);
static void consoleInit();
};
#endif #endif
#pragma region Singular Asset Macros
//Singular assets
/// <Summary>
/// Declares an material asset
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
/// </Summary>
#define DECLARE_MATERIALASSET(className, name) public: \
StringTableEntry m##name##Name;\
StringTableEntry m##name##AssetId;\
AssetPtr<MaterialAsset> m##name##Asset;\
SimObjectPtr<Material> m##name;\
public: \
const StringTableEntry get##name##File() const { return m##name##Name; }\
void set##name##Name(const FileName &_in) { m##name##Name = StringTable->insert(_in.c_str());}\
const AssetPtr<MaterialAsset> & get##name##Asset() const { return m##name##Asset; }\
void set##name##Asset(const AssetPtr<MaterialAsset> &_in) { m##name##Asset = _in;}\
\
bool _set##name(StringTableEntry _in)\
{\
if(m##name##AssetId != _in || m##name##Name != _in)\
{\
if (_in == NULL || _in == StringTable->EmptyString())\
{\
m##name##Name = StringTable->EmptyString();\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
m##name = NULL;\
return true;\
}\
\
if (AssetDatabase.isDeclaredAsset(_in))\
{\
m##name##AssetId = _in;\
\
U32 assetState = MaterialAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
\
if (MaterialAsset::Ok == assetState)\
{\
m##name##Name = StringTable->EmptyString();\
}\
}\
else\
{\
StringTableEntry assetId = MaterialAsset::getAssetIdByMaterialName(_in);\
if (assetId != StringTable->EmptyString())\
{\
m##name##AssetId = assetId;\
if (MaterialAsset::getAssetById(m##name##AssetId, &m##name##Asset) == MaterialAsset::Ok)\
{\
m##name##Name = StringTable->EmptyString();\
}\
}\
else\
{\
m##name##Name = _in;\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
}\
}\
}\
if (get##name() != StringTable->EmptyString() && m##name##Asset.notNull())\
{\
if (m##name && String(m##name##Asset->getMaterialDefinitionName()).equal(m##name->getName(), String::NoCase))\
return false;\
\
Material* tempMat = NULL;\
\
if (!Sim::findObject(m##name##Asset->getMaterialDefinitionName(), tempMat))\
Con::errorf("%s::_set%s() - Material %s was not found.", macroText(className), macroText(name), m##name##Asset->getMaterialDefinitionName());\
m##name = tempMat;\
}\
else\
{\
m##name = NULL;\
}\
\
if(get##name() == StringTable->EmptyString())\
return true;\
\
if (m##name##Asset.notNull() && m##name##Asset->getStatus() != MaterialAsset::Ok)\
{\
Con::errorf("%s::_set%s() - material asset failure\"%s\" due to [%s]", macroText(className), macroText(name), _in, MaterialAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
return false; \
}\
else if (!m##name)\
{\
Con::errorf("%s::_set%s() - Couldn't load material \"%s\"", macroText(className), macroText(name), _in);\
return false;\
}\
return true;\
}\
\
const StringTableEntry get##name() const\
{\
if (m##name##Asset && (m##name##Asset->getMaterialDefinitionName() != StringTable->EmptyString()))\
return m##name##Asset->getMaterialDefinitionName();\
else if (m##name##AssetId != StringTable->EmptyString())\
return m##name##AssetId;\
else if (m##name##Name != StringTable->EmptyString())\
return m##name##Name;\
else\
return StringTable->EmptyString();\
}\
SimObjectPtr<Material> get##name##Resource() \
{\
return m##name;\
}\
bool is##name##Valid() {return (get##name() != StringTable->EmptyString() && m##name##Asset->getStatus() == AssetBase::Ok); }
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
#define INITPERSISTFIELD_MATERIALASSET(name, consoleClass, docs) \
addProtectedField(#name, TypeMaterialName, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn,assetDoc(name, docs)); \
addProtectedField(assetText(name, Asset), TypeMaterialAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
#else
#define INITPERSISTFIELD_MATERIALASSET(name, consoleClass, docs) \
addProtectedField(#name, TypeMaterialName, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn,assetDoc(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
addProtectedField(assetText(name, Asset), TypeMaterialAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
#endif // SHOW_LEGACY_FILE_FIELDS
#define LOAD_MATERIALASSET(name)\
if (m##name##AssetId != StringTable->EmptyString())\
{\
S32 assetState = MaterialAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
if (assetState == MaterialAsset::Ok )\
{\
m##name##Name = StringTable->EmptyString();\
}\
else Con::warnf("Warning: %s::LOAD_MATERIALASSET(%s)-%s", mClassName, m##name##AssetId, MaterialAsset::getAssetErrstrn(assetState).c_str());\
}
#pragma endregion
#endif // _ASSET_BASE_H_ #endif // _ASSET_BASE_H_

View file

@ -263,16 +263,6 @@ void ShapeAsset::initializeAsset()
String normalPath = String(mShapeFile) + "_imposter_normals.dds"; String normalPath = String(mShapeFile) + "_imposter_normals.dds";
mNormalImposterFileName = StringTable->insert(normalPath.c_str()); mNormalImposterFileName = StringTable->insert(normalPath.c_str());
} }
//Make sure our fallback is valid
if (smNoShapeAssetFallbackAssetPtr.isNull())
{
smNoShapeAssetFallbackAssetPtr = smNoShapeAssetFallback;
if (smNoShapeAssetFallbackAssetPtr.isNull())
Con::errorf("ShapeAsset::initializeAsset could not find fallback asset %s!", smNoShapeAssetFallback);
else
smNoShapeAssetFallbackAssetPtr->load();
}
} }
void ShapeAsset::setShapeFile(const char* pShapeFile) void ShapeAsset::setShapeFile(const char* pShapeFile)
@ -775,6 +765,26 @@ DefineEngineMethod(ShapeAsset, getStatusString, String, (), , "get status string
return ShapeAsset::getAssetErrstrn(object->getStatus()); return ShapeAsset::getAssetErrstrn(object->getStatus());
} }
DefineEngineFunction(loadShapeAssetFallback, S32, (), ,
"Forces the loading of the ShapeAsset fallback asset.\n"
"@return Load status code.")
{
if (ShapeAsset::smNoShapeAssetFallbackAssetPtr.isNull())
{
ShapeAsset::smNoShapeAssetFallbackAssetPtr = ShapeAsset::smNoShapeAssetFallback;
if (ShapeAsset::smNoShapeAssetFallbackAssetPtr.isNull())
Con::errorf("loadShapeAssetFallback could not find fallback asset %s!", ShapeAsset::smNoShapeAssetFallback);
else
return (S32)ShapeAsset::smNoShapeAssetFallbackAssetPtr->load();
}
else
{
return (S32)ShapeAsset::smNoShapeAssetFallbackAssetPtr->getStatus();
}
return AssetBase::Failed;
}
#ifdef TORQUE_TOOLS #ifdef TORQUE_TOOLS
DefineEngineMethod(ShapeAsset, generateCachedPreviewImage, const char*, (S32 resolution, const char* overrideMaterialName), (256, ""), DefineEngineMethod(ShapeAsset, generateCachedPreviewImage, const char*, (S32 resolution, const char* overrideMaterialName), (256, ""),
"Generates a baked preview image of the given shapeAsset. Only really used for generating Asset Browser icons.\n" "Generates a baked preview image of the given shapeAsset. Only really used for generating Asset Browser icons.\n"

View file

@ -44,6 +44,7 @@
#include "T3D/assets/assetImporter.h" #include "T3D/assets/assetImporter.h"
StringTableEntry TerrainMaterialAsset::smNoTerrainMaterialAssetFallback = NULL; StringTableEntry TerrainMaterialAsset::smNoTerrainMaterialAssetFallback = NULL;
AssetPtr<TerrainMaterialAsset> TerrainMaterialAsset::smNoTerrainMaterialAssetFallbackAssetPtr = NULL;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -52,6 +53,9 @@ IMPLEMENT_CONOBJECT(TerrainMaterialAsset);
IMPLEMENT_STRUCT(AssetPtr<TerrainMaterialAsset>, AssetPtrTerrainMaterialAsset, , "") IMPLEMENT_STRUCT(AssetPtr<TerrainMaterialAsset>, AssetPtrTerrainMaterialAsset, , "")
END_IMPLEMENT_STRUCT END_IMPLEMENT_STRUCT
IMPLEMENT_STRUCT(AssetRef<TerrainMaterialAsset>, AssetRefTerrainMaterialAsset, , "")
END_IMPLEMENT_STRUCT
ConsoleType(TerrainMaterialAssetPtr, TypeTerrainMaterialAssetPtr, AssetPtr<TerrainMaterialAsset>, ASSET_ID_FIELD_PREFIX) ConsoleType(TerrainMaterialAssetPtr, TypeTerrainMaterialAssetPtr, AssetPtr<TerrainMaterialAsset>, ASSET_ID_FIELD_PREFIX)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -122,6 +126,43 @@ ConsoleSetType(TypeTerrainMaterialAssetId)
// Warn. // Warn.
Con::warnf("(TypeTerrainMaterialAssetId) - Cannot set multiple args to a single asset."); Con::warnf("(TypeTerrainMaterialAssetId) - Cannot set multiple args to a single asset.");
} }
//-----------------------------------------------------------------------------
ConsoleType(TerrainMaterialAssetRef, TypeTerrainMaterialAssetRef, AssetRef<TerrainMaterialAsset>, ASSET_ID_FIELD_PREFIX)
ConsoleGetType(TypeTerrainMaterialAssetRef)
{
AssetRef<TerrainMaterialAsset>& ref = *((AssetRef<TerrainMaterialAsset>*)dptr);
if (ref.assetPtr.isNull())
return ref.assetId;
else
return ref.assetPtr.getAssetId();
}
ConsoleSetType(TypeTerrainMaterialAssetRef)
{
if (argc == 1)
{
const char* pFieldValue = argv[0];
AssetRef<TerrainMaterialAsset>* pAssetRef = (AssetRef<TerrainMaterialAsset>*)(dptr);
if (pAssetRef == NULL)
{
Con::warnf("(TypeTerrainMaterialAssetRef) - Failed to set asset Id '%d'.", pFieldValue);
return;
}
*pAssetRef = pFieldValue;
return;
}
Con::warnf("(TypeTerrainMaterialAssetRef) - Cannot set multiple args to a single asset.");
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
TerrainMaterialAsset::TerrainMaterialAsset() TerrainMaterialAsset::TerrainMaterialAsset()
@ -254,12 +295,34 @@ void TerrainMaterialAsset::setScriptFile(const char* pScriptFile)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
U32 TerrainMaterialAsset::load() StringTableEntry TerrainMaterialAsset::getMaterialName()
{ {
if (mMaterialDefinition) if (mMaterialDefinition)
mMaterialDefinition->safeDeleteObject(); return mMatDefinitionName;
if (mFXMaterialDefinition)
mFXMaterialDefinition->safeDeleteObject(); if (smNoTerrainMaterialAssetFallbackAssetPtr.notNull())
return smNoTerrainMaterialAssetFallbackAssetPtr->getMaterialName();
return StringTable->EmptyString();
}
SimObjectPtr<TerrainMaterial> TerrainMaterialAsset::getMaterial()
{
if (mMaterialDefinition)
return mMaterialDefinition;
if (smNoTerrainMaterialAssetFallbackAssetPtr.notNull())
return smNoTerrainMaterialAssetFallbackAssetPtr->getMaterial();
return NULL;
}
//------------------------------------------------------------------------------
U32 TerrainMaterialAsset::load()
{
if (mLoadedState == AssetErrCode::Ok)
return mLoadedState;
if (mLoadedState == EmbeddedDefinition) if (mLoadedState == EmbeddedDefinition)
{ {
@ -355,7 +418,7 @@ U32 TerrainMaterialAsset::getAssetByMaterialName(StringTableEntry matName, Asset
for (U32 i = 0; i < foundAssetcount; i++) for (U32 i = 0; i < foundAssetcount; i++)
{ {
TerrainMaterialAsset* tMatAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(query.mAssetList[i]); TerrainMaterialAsset* tMatAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(query.mAssetList[i]);
if (tMatAsset && tMatAsset->getMaterialDefinitionName() == matName) if (tMatAsset && tMatAsset->getMaterialName() == matName)
{ {
matAsset->setAssetId(query.mAssetList[i]); matAsset->setAssetId(query.mAssetList[i]);
AssetDatabase.releaseAsset(query.mAssetList[i]); AssetDatabase.releaseAsset(query.mAssetList[i]);
@ -388,7 +451,7 @@ StringTableEntry TerrainMaterialAsset::getAssetIdByMaterialName(StringTableEntry
TerrainMaterialAsset* matAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(query.mAssetList[i]); TerrainMaterialAsset* matAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(query.mAssetList[i]);
if (matAsset) if (matAsset)
{ {
if (matAsset->getMaterialDefinitionName() == matName) if (matAsset->getMaterialName() == matName)
materialAssetId = matAsset->getAssetId(); materialAssetId = matAsset->getAssetId();
AssetDatabase.releaseAsset(query.mAssetList[i]); AssetDatabase.releaseAsset(query.mAssetList[i]);
@ -467,11 +530,11 @@ DefineEngineMethod(TerrainMaterialAsset, getScriptPath, const char*, (), ,
return object->getScriptPath(); return object->getScriptPath();
} }
DefineEngineMethod(TerrainMaterialAsset, getMaterialDefinition, S32, (), , DefineEngineMethod(TerrainMaterialAsset, getMaterial, S32, (), ,
"Queries the Asset Database to see if any asset exists that is associated with the provided material name.\n" "Queries the Asset Database to see if any asset exists that is associated with the provided material name.\n"
"@return The AssetId of the associated asset, if any.") "@return The AssetId of the associated asset, if any.")
{ {
SimObjectPtr<TerrainMaterial> mat = object->getMaterialDefinition(); SimObjectPtr<TerrainMaterial> mat = object->getMaterial();
if (mat.isValid()) if (mat.isValid())
return mat->getId(); return mat->getId();
else else
@ -488,6 +551,26 @@ DefineEngineMethod(TerrainMaterialAsset, getFXMaterialDefinition, S32, (), ,
else else
return 0; return 0;
} }
DefineEngineFunction(loadTerrainMaterialAssetFallback, S32, (), ,
"Forces the loading of the TerrainMaterialAsset fallback asset.\n"
"@return Load status code.")
{
if (TerrainMaterialAsset::smNoTerrainMaterialAssetFallbackAssetPtr.isNull())
{
TerrainMaterialAsset::smNoTerrainMaterialAssetFallbackAssetPtr = TerrainMaterialAsset::smNoTerrainMaterialAssetFallback;
if (TerrainMaterialAsset::smNoTerrainMaterialAssetFallbackAssetPtr.isNull())
Con::errorf("loadTerrainMaterialAssetFallback could not find fallback asset %s!", TerrainMaterialAsset::smNoTerrainMaterialAssetFallback);
else
return (S32)TerrainMaterialAsset::smNoTerrainMaterialAssetFallbackAssetPtr->load();
}
else
{
return (S32)TerrainMaterialAsset::smNoTerrainMaterialAssetFallbackAssetPtr->getStatus();
}
return AssetBase::Failed;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// GuiInspectorTypeAssetId // GuiInspectorTypeAssetId
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -591,4 +674,18 @@ void GuiInspectorTypeTerrainMaterialAssetId::consoleInit()
ConsoleBaseType::getType(TypeTerrainMaterialAssetId)->setInspectorFieldType("GuiInspectorTypeTerrainMaterialAssetId"); ConsoleBaseType::getType(TypeTerrainMaterialAssetId)->setInspectorFieldType("GuiInspectorTypeTerrainMaterialAssetId");
} }
IMPLEMENT_CONOBJECT(GuiInspectorTypeTerrainMaterialAssetRef);
ConsoleDocClass(GuiInspectorTypeTerrainMaterialAssetRef,
"@brief Inspector field type for AssetRef<TerrainMaterialAsset> fields\n\n"
"Editor use only.\n\n"
"@internal"
);
void GuiInspectorTypeTerrainMaterialAssetRef::consoleInit()
{
Parent::consoleInit();
ConsoleBaseType::getType(TypeTerrainMaterialAssetRef)->setInspectorFieldType("GuiInspectorTypeTerrainMaterialAssetRef");
}
#endif #endif

View file

@ -70,7 +70,8 @@ class TerrainMaterialAsset : public AssetBase
public: public:
static StringTableEntry smNoTerrainMaterialAssetFallback; static StringTableEntry smNoTerrainMaterialAssetFallback;
static AssetPtr<TerrainMaterialAsset> smNoTerrainMaterialAssetFallbackAssetPtr;
enum TerrainMaterialAssetErrCode enum TerrainMaterialAssetErrCode
{ {
ScriptLoaded = AssetErrCode::Extended, ScriptLoaded = AssetErrCode::Extended,
@ -91,8 +92,8 @@ public:
U32 load() override; U32 load() override;
StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; } StringTableEntry getMaterialName();
SimObjectPtr<TerrainMaterial> getMaterialDefinition() { return mMaterialDefinition; } SimObjectPtr<TerrainMaterial> getMaterial();
SimObjectPtr<Material> getFXMaterialDefinition() { return mFXMaterialDefinition; } SimObjectPtr<Material> getFXMaterialDefinition() { return mFXMaterialDefinition; }
@ -131,181 +132,11 @@ protected:
DECLARE_STRUCT(AssetPtr<TerrainMaterialAsset>) DECLARE_STRUCT(AssetPtr<TerrainMaterialAsset>)
DefineConsoleType(TypeTerrainMaterialAssetPtr, AssetPtr<TerrainMaterialAsset>) DefineConsoleType(TypeTerrainMaterialAssetPtr, AssetPtr<TerrainMaterialAsset>)
#define DECLARE_TERRAINMATERIALASSET(className, name) \
private: \
AssetPtr<TerrainMaterialAsset> m##name##Asset; \
StringTableEntry m##name##File = {StringTable->EmptyString() }; \
public: \
void _set##name(StringTableEntry _in){ \
if (m##name##Asset.getAssetId() == _in) \
return; \
if(_in == NULL || !String::compare(_in,StringTable->EmptyString())) \
{ \
m##name##Asset = NULL; \
m##name##File = ""; \
return; \
} \
if (!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry terMatAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
terMatAssetId = query.mAssetList[0]; \
} \
m##name##Asset = terMatAssetId; \
m##name##File = _in; \
} \
else \
{ \
m##name##Asset = _in; \
m##name##File = get##name##File(); \
} \
}; \
\
inline StringTableEntry _get##name##AssetId() const { return m##name##Asset.getAssetId(); } \
TerrainMaterial* get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getMaterialDefinition(); else return NULL; } \
AssetPtr<TerrainMaterialAsset> get##name##Asset() { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false;}\
StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getScriptFile() : ""; }
#define DECLARE_TERRAINMATERIALASSET_NET(className, name, mask) \
private: \
AssetPtr<TerrainMaterialAsset> m##name##Asset; \
StringTableEntry m##name##File = {StringTable->EmptyString() }; \
public: \
void _set##name(StringTableEntry _in){ \
if (m##name##Asset.getAssetId() == _in) \
return; \
if(_in == NULL || !String::compare(_in,StringTable->EmptyString())) \
{ \
m##name##Asset = NULL; \
m##name##File = ""; \
return; \
} \
if (!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry terMatAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
terMatAssetId = query.mAssetList[0]; \
} \
m##name##Asset = terMatAssetId; \
m##name##File = _in; \
} \
else \
{ \
m##name##Asset = _in; \
m##name##File = get##name##File(); \
} \
}; \
\
inline StringTableEntry _get##name##AssetId() const { return m##name##Asset.getAssetId(); } \
TerrainMaterial* get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getMaterialDefinition(); else return NULL; } \
AssetPtr<TerrainMaterialAsset> get##name##Asset() { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data)\
{\
static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data));\
static_cast<className*>(obj)->setMaskBits(mask); \
return false;\
}\
StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getScriptFile() : ""; }
#define INITPERSISTFIELD_TERRAINMATERIALASSET(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeTerrainMaterialAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));\
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.), AbstractClassRep::FIELD_HideInInspectors);
#define DECLARE_TERRAINMATERIALASSET_ARRAY(className, name, max) \
private: \
AssetPtr<TerrainMaterialAsset> m##name##Asset[max]; \
StringTableEntry m##name##File[max] = {StringTable->EmptyString() }; \
public: \
void _set##name(StringTableEntry _in, const U32& index){ \
if (m##name##Asset[index].getAssetId() == _in) \
return; \
if(_in == NULL || !String::compare(_in,StringTable->EmptyString())) \
{ \
m##name##Asset[index] = NULL; \
m##name##File[index] = ""; \
return; \
} \
if (!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry terMatAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
terMatAssetId = query.mAssetList[0]; \
} \
m##name##Asset[index] = terMatAssetId; \
m##name##File[index] = _in; \
} \
else \
{ \
m##name##Asset[index] = _in; \
m##name##File[index] = get##name##File(index); \
} \
}; \
\
inline StringTableEntry _get##name##AssetId(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
TerrainMaterial* get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getMaterialDefinition(); else return NULL; } \
AssetPtr<TerrainMaterialAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getScriptFile() : ""; }
#define DECLARE_TERRAINMATERIALASSET_NET_ARRAY(className, name, max, mask) \
private: \
AssetPtr<TerrainMaterialAsset> m##name##Asset[max]; \
StringTableEntry m##name##File[max] = {StringTable->EmptyString() }; \
public: \
void _set##name(StringTableEntry _in, const U32& index){ \
if (m##name##Asset[index].getAssetId() == _in) \
return; \
if(_in == NULL || !String::compare(_in,StringTable->EmptyString())) \
{ \
m##name##Asset[index] = NULL; \
m##name##File[index] = ""; \
return; \
} \
if (!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry terMatAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
terMatAssetId = query.mAssetList[0]; \
} \
m##name##Asset[index] = terMatAssetId; \
m##name##File[index] = _in; \
} \
else \
{ \
m##name##Asset[index] = _in; \
m##name##File[index] = get##name##File(index); \
} \
}; \
\
inline StringTableEntry _get##name##AssetId(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
TerrainMaterial* get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getMaterialDefinition(); else return NULL; } \
AssetPtr<TerrainMaterialAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data)\
{\
static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index));\
static_cast<className*>(obj)->setMaskBits(mask); \
return false;\
}\
StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getScriptFile() : ""; }
#define INITPERSISTFIELD_TERRAINMATERIALASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeTerrainMaterialAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));\
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.), AbstractClassRep::FIELD_HideInInspectors);
DefineConsoleType(TypeTerrainMaterialAssetId, String) DefineConsoleType(TypeTerrainMaterialAssetId, String)
DECLARE_STRUCT(AssetRef<TerrainMaterialAsset>)
DefineConsoleType(TypeTerrainMaterialAssetRef, AssetRef<TerrainMaterialAsset>)
#ifdef TORQUE_TOOLS #ifdef TORQUE_TOOLS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// TypeAssetId GuiInspectorField Class // TypeAssetId GuiInspectorField Class
@ -331,6 +162,13 @@ public:
DECLARE_CONOBJECT(GuiInspectorTypeTerrainMaterialAssetId); DECLARE_CONOBJECT(GuiInspectorTypeTerrainMaterialAssetId);
static void consoleInit(); static void consoleInit();
}; };
class GuiInspectorTypeTerrainMaterialAssetRef : public GuiInspectorTypeTerrainMaterialAssetPtr
{
typedef GuiInspectorTypeTerrainMaterialAssetPtr Parent;
public:
DECLARE_CONOBJECT(GuiInspectorTypeTerrainMaterialAssetRef);
static void consoleInit();
};
#endif #endif
#endif // _ASSET_BASE_H_ #endif // _ASSET_BASE_H_

View file

@ -261,9 +261,11 @@ bool ConvexShape::protectedSetSurfaceTexture(void *object, const char *index, co
surfaceMaterial surface; surfaceMaterial surface;
surface._setMaterial(StringTable->insert(data)); surface.mMaterialAssetRef = StringTable->insert( data );
shape->mSurfaceTextures.push_back(surface); shape->mSurfaceTextures.push_back(surface);
shape->setMaskBits(UpdateMask);
return false; return false;
} }
@ -287,7 +289,6 @@ ConvexShape::ConvexShape()
mSurfaceUVs.clear(); mSurfaceUVs.clear();
mSurfaceTextures.clear(); mSurfaceTextures.clear();
INIT_ASSET(Material);
} }
ConvexShape::~ConvexShape() ConvexShape::~ConvexShape()
@ -310,7 +311,9 @@ void ConvexShape::initPersistFields()
docsURL; docsURL;
addGroup( "Rendering" ); addGroup( "Rendering" );
INITPERSISTFIELD_MATERIALASSET(Material, ConvexShape, "Default material used to render the ConvexShape surface."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, ConvexShape ) )
.network( UpdateMask )
.doc( "Default material asset used to render the ConvexShape surface." );
endGroup( "Rendering" ); endGroup( "Rendering" );
@ -461,9 +464,9 @@ void ConvexShape::writeFields( Stream &stream, U32 tabStop )
char buffer[1024]; char buffer[1024];
dMemset(buffer, 0, 1024); dMemset(buffer, 0, 1024);
dSprintf(buffer, 1024, "surfaceTexture = \"%s\";", mSurfaceTextures[i].getMaterial()); dSprintf( buffer, 1024, "surfaceTexture = \"%s\";", mSurfaceTextures[i].mMaterialAssetRef.getAssetId() );
stream.writeLine((const U8*)buffer); stream.writeLine( (const U8*)buffer );
} }
for ( U32 i = 0; i < count; i++ ) for ( U32 i = 0; i < count; i++ )
@ -541,9 +544,9 @@ const char* ConvexShape::getSpecialFieldOut(StringTableEntry fieldName, const U3
char buffer[1024]; char buffer[1024];
dMemset(buffer, 0, 1024); dMemset(buffer, 0, 1024);
dSprintf(buffer, 1024, "surfaceTexture = \"%s\";", mSurfaceTextures[index].getMaterial()); dSprintf( buffer, 1024, "surfaceTexture = \"%s\";", mSurfaceTextures[index].mMaterialAssetRef.getAssetId() );
return StringTable->insert(buffer); return StringTable->insert( buffer );
} }
return NULL; return NULL;
@ -577,7 +580,7 @@ U32 ConvexShape::packUpdate( NetConnection *conn, U32 mask, BitStream *stream )
if ( stream->writeFlag( mask & UpdateMask ) ) if ( stream->writeFlag( mask & UpdateMask ) )
{ {
PACK_ASSET(conn, Material); AssetDatabase.packDataAsset( stream, mMaterialAssetRef.getAssetId() );
U32 surfCount = mSurfaces.size(); U32 surfCount = mSurfaces.size();
stream->writeInt( surfCount, 32 ); stream->writeInt( surfCount, 32 );
@ -604,14 +607,8 @@ U32 ConvexShape::packUpdate( NetConnection *conn, U32 mask, BitStream *stream )
stream->writeInt( surfaceTex, 32 ); stream->writeInt( surfaceTex, 32 );
//next check for any texture coord or scale mods //next check for any texture coord or scale mods
for(U32 i=0; i < surfaceTex; i++) for(U32 i=0; i < surfaceTex; i++)
{ {
if (stream->writeFlag(mSurfaceTextures[i].mMaterialAsset.notNull())) AssetDatabase.packDataAsset( stream, mSurfaceTextures[i].mMaterialAssetRef.getAssetId() );
{
NetStringHandle assetIdStr = mSurfaceTextures[i].mMaterialAsset.getAssetId();
conn->packNetStringHandleU(stream, assetIdStr);
}
else
stream->writeString(mSurfaceTextures[i].mMaterialName);
} }
} }
@ -633,7 +630,7 @@ void ConvexShape::unpackUpdate( NetConnection *conn, BitStream *stream )
if ( stream->readFlag() ) // UpdateMask if ( stream->readFlag() ) // UpdateMask
{ {
UNPACK_ASSET(conn, Material); mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
mSurfaces.clear(); mSurfaces.clear();
mSurfaceUVs.clear(); mSurfaceUVs.clear();
@ -673,13 +670,7 @@ void ConvexShape::unpackUpdate( NetConnection *conn, BitStream *stream )
{ {
mSurfaceTextures.increment(); mSurfaceTextures.increment();
if (stream->readFlag()) mSurfaceTextures[i].mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
{
mSurfaceTextures[i].mMaterialAssetId = StringTable->insert(conn->unpackNetStringHandleU(stream).getString());
mSurfaceTextures[i]._setMaterial(mSurfaceTextures[i].mMaterialAssetId);
}
else
mSurfaceTextures[i].mMaterialName = stream->readSTString();
} }
if (isProperlyAdded()) if (isProperlyAdded())
@ -1255,43 +1246,49 @@ void ConvexShape::_updateMaterial()
//update our custom surface materials //update our custom surface materials
for (U32 i = 0; i<mSurfaceTextures.size(); i++) for (U32 i = 0; i<mSurfaceTextures.size(); i++)
{ {
mSurfaceTextures[i]._setMaterial(mSurfaceTextures[i].getMaterial()); if ( !mSurfaceTextures[i].mMaterialAssetRef.notNull() )
//If we already have the material inst and it hasn't changed, skip
if (mSurfaceTextures[i].materialInst &&
mSurfaceTextures[i].getMaterialAsset()->getMaterialDefinitionName() == mSurfaceTextures[i].materialInst->getMaterial()->getName() &&
mSurfaceTextures[i].materialInst->getVertexFormat() == getGFXVertexFormat<VertexType>())
continue; continue;
SAFE_DELETE(mSurfaceTextures[i].materialInst); Material* surfMat = mSurfaceTextures[i].mMaterialAssetRef.assetPtr->getMaterial();
Material* material = mSurfaceTextures[i].getMaterialResource(); //If we already have the material inst and it hasn't changed, skip
if ( mSurfaceTextures[i].materialInst &&
if (material == NULL) surfMat &&
surfMat->getName() == mSurfaceTextures[i].materialInst->getMaterial()->getName() &&
mSurfaceTextures[i].materialInst->getVertexFormat() == getGFXVertexFormat<VertexType>() )
continue; continue;
mSurfaceTextures[i].materialInst = material->createMatInstance(); SAFE_DELETE( mSurfaceTextures[i].materialInst );
if ( surfMat == NULL )
continue;
mSurfaceTextures[i].materialInst = surfMat->createMatInstance();
FeatureSet features = MATMGR->getDefaultFeatures(); FeatureSet features = MATMGR->getDefaultFeatures();
mSurfaceTextures[i].materialInst->init( features, getGFXVertexFormat<VertexType>() );
mSurfaceTextures[i].materialInst->init(features, getGFXVertexFormat<VertexType>()); if ( !mSurfaceTextures[i].materialInst->isValid() )
SAFE_DELETE( mSurfaceTextures[i].materialInst );
if (!mSurfaceTextures[i].materialInst->isValid())
{
SAFE_DELETE(mSurfaceTextures[i].materialInst);
}
} }
_setMaterial(getMaterial()); if ( !mMaterialAssetRef.notNull() )
{
SAFE_DELETE( mMaterialInst );
return;
}
Material* material = mMaterialAssetRef.assetPtr->getMaterial();
// If the material name matches then don't bother updating it. // If the material name matches then don't bother updating it.
if (mMaterialInst && getMaterialAsset()->getMaterialDefinitionName() == mMaterialInst->getMaterial()->getName() && if ( mMaterialInst && material &&
mMaterialInst->getVertexFormat() == getGFXVertexFormat<VertexType>()) material->getName() == mMaterialInst->getMaterial()->getName() &&
mMaterialInst->getVertexFormat() == getGFXVertexFormat<VertexType>() )
return; return;
SAFE_DELETE( mMaterialInst ); SAFE_DELETE( mMaterialInst );
Material* material = getMaterialResource(); if ( material == NULL )
if (material == NULL)
return; return;
mMaterialInst = material->createMatInstance(); mMaterialInst = material->createMatInstance();
@ -2112,4 +2109,16 @@ void ConvexShape::Geometry::generate(const Vector< PlaneF > &planes, const Vecto
} }
} }
DEF_ASSET_BINDS(ConvexShape, Material); DefineEngineMethod( ConvexShape, getMaterial, String, (), , "Returns the primary material asset id." )
{
return object->getMaterial();
}
DefineEngineMethod( ConvexShape, getMaterialAsset, String, (), , "Returns the primary material asset id." )
{
return object->getMaterial();
}
DefineEngineMethod( ConvexShape, setMaterial, bool, ( const char* assetName ), , "Sets the primary material asset id." )
{
object->setMaterial( StringTable->insert( assetName ) );
return true;
}

View file

@ -137,19 +137,15 @@ public:
struct surfaceMaterial struct surfaceMaterial
{ {
// The name of the Material we will use for rendering // The name of the Material we will use for rendering
DECLARE_MATERIALASSET(surfaceMaterial, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_SETGET(surfaceMaterial, Material);
// The actual Material instance // The actual Material instance
BaseMatInstance* materialInst; BaseMatInstance* materialInst;
surfaceMaterial() surfaceMaterial() : materialInst( NULL ) {}
{
INIT_ASSET(Material);
materialInst = NULL; StringTableEntry getMaterial() const { return mMaterialAssetRef.getAssetId(); }
} void setMaterial( const char* assetId ) { mMaterialAssetRef = StringTable->insert( assetId ); }
}; };
struct surfaceUV struct surfaceUV
@ -248,7 +244,9 @@ public:
/// @} /// @}
String getMaterialName() { return mMaterialName; } StringTableEntry getMaterial() const { return mMaterialAssetRef.getAssetId(); }
String getMaterialName() const { return String( mMaterialAssetRef.getAssetId() ); }
void setMaterial( StringTableEntry assetId ) { mMaterialAssetRef = assetId; }
protected: protected:
@ -268,8 +266,7 @@ protected:
protected: protected:
DECLARE_MATERIALASSET(ConvexShape, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_SETGET(ConvexShape, Material);
// The actual Material instance // The actual Material instance
BaseMatInstance* mMaterialInst; BaseMatInstance* mMaterialInst;

View file

@ -76,7 +76,6 @@ ConsoleDocClass( DecalData,
DecalData::DecalData() DecalData::DecalData()
{ {
size = 5; size = 5;
INIT_ASSET(Material);
lifeSpan = 5000; lifeSpan = 5000;
fadeTime = 1000; fadeTime = 1000;
@ -144,7 +143,7 @@ void DecalData::initPersistFields()
addFieldV( "size", TypeRangedF32, Offset( size, DecalData ), &CommonValidators::PositiveFloat, addFieldV( "size", TypeRangedF32, Offset( size, DecalData ), &CommonValidators::PositiveFloat,
"Width and height of the decal in meters before scale is applied." ); "Width and height of the decal in meters before scale is applied." );
INITPERSISTFIELD_MATERIALASSET(Material, DecalData, "Material to use for this decal."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, DecalData ) ).doc( "Material asset to use for this decal." );
addFieldV( "lifeSpan", TypeRangedS32, Offset( lifeSpan, DecalData ), &CommonValidators::PositiveInt, addFieldV( "lifeSpan", TypeRangedS32, Offset( lifeSpan, DecalData ), &CommonValidators::PositiveInt,
"Time (in milliseconds) before this decal will be automatically deleted." ); "Time (in milliseconds) before this decal will be automatically deleted." );
@ -223,9 +222,9 @@ void DecalData::onStaticModified( const char *slotName, const char *newValue )
return; return;
// To allow changing materials live. // To allow changing materials live.
if ( dStricmp( slotName, "material" ) == 0 ) if ( dStricmp( slotName, "materialAsset" ) == 0 )
{ {
_setMaterial(newValue); mMaterialAssetRef = StringTable->insert( newValue );
_updateMaterial(); _updateMaterial();
} }
// To allow changing name live. // To allow changing name live.
@ -259,7 +258,7 @@ void DecalData::packData( BitStream *stream )
stream->write( lookupName ); stream->write( lookupName );
stream->write( size ); stream->write( size );
PACKDATA_ASSET(Material); AssetDatabase.packDataAsset( stream, mMaterialAssetRef.getAssetId() );
stream->write( lifeSpan ); stream->write( lifeSpan );
stream->write( fadeTime ); stream->write( fadeTime );
@ -288,8 +287,8 @@ void DecalData::unpackData( BitStream *stream )
assignName(lookupName); assignName(lookupName);
stream->read( &size ); stream->read( &size );
UNPACKDATA_ASSET(Material); mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
_updateMaterial(); _updateMaterial();
stream->read( &lifeSpan ); stream->read( &lifeSpan );
stream->read( &fadeTime ); stream->read( &fadeTime );
@ -314,11 +313,9 @@ void DecalData::_initMaterial()
{ {
SAFE_DELETE( matInst ); SAFE_DELETE( matInst );
_setMaterial(getMaterial()); if ( mMaterialAssetRef.notNull() && mMaterialAssetRef.assetPtr->getStatus() == MaterialAsset::Ok )
if (mMaterialAsset.notNull() && mMaterialAsset->getStatus() == MaterialAsset::Ok)
{ {
matInst = getMaterialResource()->createMatInstance(); matInst = mMaterialAssetRef.assetPtr->getMaterial()->createMatInstance();
} }
else else
matInst = MATMGR->createMatInstance( "WarningMaterial" ); matInst = MATMGR->createMatInstance( "WarningMaterial" );
@ -329,42 +326,42 @@ void DecalData::_initMaterial()
matInst->addStateBlockDesc( desc ); matInst->addStateBlockDesc( desc );
matInst->init( MATMGR->getDefaultFeatures(), getGFXVertexFormat<DecalVertex>() ); matInst->init( MATMGR->getDefaultFeatures(), getGFXVertexFormat<DecalVertex>() );
if( !matInst->isValid() ) if ( !matInst->isValid() )
{ {
Con::errorf( "DecalData::_initMaterial - failed to create material instance for '%s'", mMaterialAssetId ); Con::errorf( "DecalData::_initMaterial - failed to create material instance for '%s'", mMaterialAssetRef.getAssetId() );
SAFE_DELETE( matInst ); SAFE_DELETE( matInst );
matInst = MATMGR->createMatInstance( "WarningMaterial" ); matInst = MATMGR->createMatInstance( "WarningMaterial" );
matInst->init( MATMGR->getDefaultFeatures(), getGFXVertexFormat< DecalVertex >() ); matInst->init( MATMGR->getDefaultFeatures(), getGFXVertexFormat<DecalVertex>() );
} }
} }
void DecalData::_updateMaterial() void DecalData::_updateMaterial()
{ {
U32 assetStatus = MaterialAsset::getAssetErrCode(mMaterialAsset); U32 assetStatus = MaterialAsset::getAssetErrCode( mMaterialAssetRef.assetPtr );
if (assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback) if ( assetStatus != AssetBase::Ok && assetStatus != AssetBase::UsingFallback )
{
return; return;
}
// Only update material instance if we have one allocated. // Only update material instance if we have one allocated.
if ( matInst ) if ( matInst )
_initMaterial(); _initMaterial();
} }
Material* DecalData::getMaterialDefinition() Material* DecalData::getMaterial()
{ {
if ( !getMaterialResource() ) if ( !mMaterialAssetRef.notNull() )
{ {
_updateMaterial(); _updateMaterial();
if ( !mMaterial ) if ( !mMaterialAssetRef.notNull() )
mMaterial = static_cast<Material*>( Sim::findObject("WarningMaterial") ); return static_cast<Material*>( Sim::findObject( "WarningMaterial" ) );
} }
return mMaterial; return mMaterialAssetRef.assetPtr->getMaterial();
} }
BaseMatInstance* DecalData::getMaterialInstance() BaseMatInstance* DecalData::getMaterialInstance()
{ {
if ( !mMaterial || !matInst || matInst->getMaterial() != mMaterial) Material* matDef = mMaterialAssetRef.notNull() ? mMaterialAssetRef.assetPtr->getMaterial() : nullptr;
if ( !matDef || !matInst || matInst->getMaterial() != matDef )
_initMaterial(); _initMaterial();
return matInst; return matInst;

View file

@ -77,9 +77,8 @@ class DecalData : public SimDataBlock
F32 fadeStartPixelSize; F32 fadeStartPixelSize;
F32 fadeEndPixelSize; F32 fadeEndPixelSize;
DECLARE_MATERIALASSET(DecalData, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_SETGET(DecalData, Material);
/// Material instance for decal. /// Material instance for decal.
BaseMatInstance *matInst; BaseMatInstance *matInst;
@ -112,7 +111,7 @@ class DecalData : public SimDataBlock
void packData( BitStream* ) override; void packData( BitStream* ) override;
void unpackData( BitStream* ) override; void unpackData( BitStream* ) override;
Material* getMaterialDefinition(); Material* getMaterial();
BaseMatInstance* getMaterialInstance(); BaseMatInstance* getMaterialInstance();
static SimSet* getSet(); static SimSet* getSet();

View file

@ -206,9 +206,7 @@ bool DecalDataFile::read( Stream &stream )
data->lookupName = name; data->lookupName = name;
data->registerObject(name); data->registerObject(name);
Sim::getRootGroup()->addObject( data ); Sim::getRootGroup()->addObject( data );
data->mMaterialName = "WarningMaterial";
data->mMaterial = dynamic_cast<Material*>(Sim::findObject("WarningMaterial"));
Con::errorf( "DecalDataFile::read() - DecalData %s does not exist! Temporarily created %s_missing.", lookupName.c_str(), lookupName.c_str()); Con::errorf( "DecalDataFile::read() - DecalData %s does not exist! Temporarily created %s_missing.", lookupName.c_str(), lookupName.c_str());
} }
} }

View file

@ -186,7 +186,7 @@ S32 QSORT_CALLBACK cmpDecalRenderOrder( const void *p1, const void *p2 )
if ( (*pd2)->mFlags & SaveDecal ) if ( (*pd2)->mFlags & SaveDecal )
{ {
S32 id = ( (*pd1)->mDataBlock->getMaterialDefinition()->getId() - (*pd2)->mDataBlock->getMaterialDefinition()->getId() ); S32 id = ( (*pd1)->mDataBlock->getMaterial()->getId() - (*pd2)->mDataBlock->getMaterial()->getId() );
if ( id != 0 ) if ( id != 0 )
return id; return id;
@ -1181,7 +1181,7 @@ void DecalManager::prepRenderImage( SceneRenderState* state )
{ {
DecalInstance *decal = mDecalQueue[i]; DecalInstance *decal = mDecalQueue[i];
DecalData *data = decal->mDataBlock; DecalData *data = decal->mDataBlock;
Material *mat = data->getMaterialDefinition(); Material *mat = data->getMaterial();
if ( currentBatch == NULL ) if ( currentBatch == NULL )
{ {

View file

@ -59,7 +59,6 @@ RenderMeshExample::RenderMeshExample()
// Set it as a "static" object that casts shadows // Set it as a "static" object that casts shadows
mTypeMask |= StaticObjectType | StaticShapeObjectType; mTypeMask |= StaticObjectType | StaticShapeObjectType;
INIT_ASSET(Material);
mMaterialInst = NULL; mMaterialInst = NULL;
} }
@ -76,7 +75,9 @@ void RenderMeshExample::initPersistFields()
{ {
docsURL; docsURL;
addGroup( "Rendering" ); addGroup( "Rendering" );
INITPERSISTFIELD_MATERIALASSET(Material, RenderMeshExample, "The material used to render the mesh."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, RenderMeshExample ) )
.network(UpdateMask)
.doc( "Material asset used to render the mesh." );
endGroup( "Rendering" ); endGroup( "Rendering" );
// SceneObject already handles exposing the transform // SceneObject already handles exposing the transform
@ -145,7 +146,7 @@ U32 RenderMeshExample::packUpdate( NetConnection *conn, U32 mask, BitStream *str
// Write out any of the updated editable properties // Write out any of the updated editable properties
if (stream->writeFlag(mask & UpdateMask)) if (stream->writeFlag(mask & UpdateMask))
{ {
PACK_ASSET(conn, Material); AssetDatabase.packDataAsset( stream, mMaterialAssetRef.getAssetId() );
} }
return retMask; return retMask;
@ -166,7 +167,7 @@ void RenderMeshExample::unpackUpdate(NetConnection *conn, BitStream *stream)
if ( stream->readFlag() ) // UpdateMask if ( stream->readFlag() ) // UpdateMask
{ {
UNPACK_ASSET(conn, Material); mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
if ( isProperlyAdded() ) if ( isProperlyAdded() )
updateMaterial(); updateMaterial();
@ -248,17 +249,17 @@ void RenderMeshExample::createGeometry()
void RenderMeshExample::updateMaterial() void RenderMeshExample::updateMaterial()
{ {
if (mMaterialAsset.notNull()) if (mMaterialAssetRef.notNull())
{ {
if (mMaterialInst && String(mMaterialAsset->getMaterialDefinitionName()).equal(mMaterialInst->getMaterial()->getName(), String::NoCase)) if (mMaterialInst && String(mMaterialAssetRef.assetPtr->getMaterialName()).equal(mMaterialInst->getMaterial()->getName(), String::NoCase))
return; return;
SAFE_DELETE(mMaterialInst); SAFE_DELETE(mMaterialInst);
mMaterialInst = MATMGR->createMatInstance(mMaterialAsset->getMaterialDefinitionName(), getGFXVertexFormat< VertexType >()); mMaterialInst = MATMGR->createMatInstance(mMaterialAssetRef.assetPtr->getMaterialName(), getGFXVertexFormat< VertexType >());
if (!mMaterialInst) if (!mMaterialInst)
Con::errorf("RenderMeshExample::updateMaterial - no Material called '%s'", mMaterialAsset->getMaterialDefinitionName()); Con::errorf("RenderMeshExample::updateMaterial - no Material called '%s'", mMaterialAssetRef.assetPtr->getMaterialName());
} }
} }

View file

@ -73,8 +73,7 @@ class RenderMeshExample : public SceneObject
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
BaseMatInstance* mMaterialInst; BaseMatInstance* mMaterialInst;
DECLARE_MATERIALASSET(RenderMeshExample, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_NET_SETGET(RenderMeshExample, Material, UpdateMask);
// The GFX vertex and primitive buffers // The GFX vertex and primitive buffers
GFXVertexBufferHandle< VertexType > mVertexBuffer; GFXVertexBufferHandle< VertexType > mVertexBuffer;

View file

@ -460,7 +460,6 @@ GroundCover::GroundCover()
mRandomSeed = 1; mRandomSeed = 1;
INIT_ASSET(Material);
mMaterialInst = NULL; mMaterialInst = NULL;
mMatParams = NULL; mMatParams = NULL;
@ -510,8 +509,6 @@ GroundCover::GroundCover()
mMinElevation[i] = -99999.0f; mMinElevation[i] = -99999.0f;
mMaxElevation[i] = 99999.0f; mMaxElevation[i] = 99999.0f;
mLayerAsset[i] = NULL;
mLayerFile[i] = StringTable->EmptyString();
mInvertLayer[i] = NULL; mInvertLayer[i] = NULL;
@ -545,7 +542,9 @@ void GroundCover::initPersistFields()
docsURL; docsURL;
addGroup( "GroundCover General" ); addGroup( "GroundCover General" );
INITPERSISTFIELD_MATERIALASSET(Material, GroundCover, "Material used by all GroundCover segments."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, GroundCover ) )
.network( InitialUpdateMask )
.doc( "Material asset used by all GroundCover segments." );
addFieldV( "radius", TypeRangedF32, Offset( mRadius, GroundCover ), &CommonValidators::PositiveFloat, "Outer generation radius from the current camera position." ); addFieldV( "radius", TypeRangedF32, Offset( mRadius, GroundCover ), &CommonValidators::PositiveFloat, "Outer generation radius from the current camera position." );
addFieldV( "dissolveRadius", TypeRangedF32, Offset( mFadeRadius, GroundCover ), &CommonValidators::PositiveFloat, "This is less than or equal to radius and defines when fading of cover elements begins." ); addFieldV( "dissolveRadius", TypeRangedF32, Offset( mFadeRadius, GroundCover ), &CommonValidators::PositiveFloat, "This is less than or equal to radius and defines when fading of cover elements begins." );
@ -570,10 +569,10 @@ void GroundCover::initPersistFields()
.doc("The cover shape. [Optional]") .doc("The cover shape. [Optional]")
.network(-1); .network(-1);
INITPERSISTFIELD_TERRAINMATERIALASSET_ARRAY(Layer, MAX_COVERTYPES, GroundCover, "Terrain material assetId to limit coverage to, or blank to not limit."); ADD_FIELD( "layerAsset", TypeTerrainMaterialAssetRef, Offset( mLayerAssetRef, GroundCover ) )
.elements( MAX_COVERTYPES )
//Legacy field .network( InitialUpdateMask )
addProtectedField("layer", TypeTerrainMaterialAssetPtr, Offset(mLayerAsset, GroundCover), &_setLayerData, &defaultProtectedGetFn, MAX_COVERTYPES, "Terrain material assetId to limit coverage to, or blank to not limit.", AbstractClassRep::FIELD_HideInInspectors); .doc( "Terrain material asset to limit coverage to, or blank to not limit." );
addField( "invertLayer", TypeBool, Offset( mInvertLayer, GroundCover ), MAX_COVERTYPES, "Indicates that the terrain material index given in 'layer' is an exclusion mask." ); addField( "invertLayer", TypeBool, Offset( mInvertLayer, GroundCover ), MAX_COVERTYPES, "Indicates that the terrain material index given in 'layer' is an exclusion mask." );
@ -722,7 +721,7 @@ U32 GroundCover::packUpdate( NetConnection *connection, U32 mask, BitStream *str
// TODO: We could probably optimize a few of these // TODO: We could probably optimize a few of these
// based on reasonable units at some point. // based on reasonable units at some point.
PACK_ASSET(connection, Material); AssetDatabase.packDataAsset( stream, mMaterialAssetRef.getAssetId() );
stream->write( mRadius ); stream->write( mRadius );
stream->write( mZOffset ); stream->write( mZOffset );
@ -777,7 +776,8 @@ U32 GroundCover::packUpdate( NetConnection *connection, U32 mask, BitStream *str
AssetDatabase.packUpdateAsset(connection, mask, stream, mShapeAssetRef[i].assetId); AssetDatabase.packUpdateAsset(connection, mask, stream, mShapeAssetRef[i].assetId);
} }
PACK_ASSET_ARRAY_REFACTOR(connection, Layer, MAX_COVERTYPES) for ( U32 i = 0; i < MAX_COVERTYPES; i++ )
AssetDatabase.packUpdateAsset( connection, mask, stream, mLayerAssetRef[i].getAssetId() );
stream->writeFlag( mDebugRenderCells ); stream->writeFlag( mDebugRenderCells );
stream->writeFlag( mDebugNoBillboards ); stream->writeFlag( mDebugNoBillboards );
@ -794,7 +794,7 @@ void GroundCover::unpackUpdate( NetConnection *connection, BitStream *stream )
if (stream->readFlag()) if (stream->readFlag())
{ {
UNPACK_ASSET(connection, Material); mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
stream->read( &mRadius ); stream->read( &mRadius );
stream->read( &mZOffset ); stream->read( &mZOffset );
@ -849,7 +849,8 @@ void GroundCover::unpackUpdate( NetConnection *connection, BitStream *stream )
mShapeAssetRef[i] = AssetDatabase.unpackUpdateAsset(connection, stream); mShapeAssetRef[i] = AssetDatabase.unpackUpdateAsset(connection, stream);
} }
UNPACK_ASSET_ARRAY_REFACTOR(connection, Layer, MAX_COVERTYPES) for ( U32 i = 0; i < MAX_COVERTYPES; i++ )
mLayerAssetRef[i] = AssetDatabase.unpackUpdateAsset( connection, stream );
mDebugRenderCells = stream->readFlag(); mDebugRenderCells = stream->readFlag();
mDebugNoBillboards = stream->readFlag(); mDebugNoBillboards = stream->readFlag();
@ -873,8 +874,8 @@ void GroundCover::_initMaterial()
{ {
SAFE_DELETE(mMaterialInst); SAFE_DELETE(mMaterialInst);
if (mMaterialAsset.notNull() && mMaterialAsset->getStatus() == MaterialAsset::Ok) if (mMaterialAssetRef.notNull() && mMaterialAssetRef.assetPtr->getStatus() == MaterialAsset::Ok)
mMaterialInst = mMaterial->createMatInstance(); mMaterialInst = mMaterialAssetRef.assetPtr->getMaterial()->createMatInstance();
else else
mMaterialInst = MATMGR->createMatInstance("WarningMaterial"); mMaterialInst = MATMGR->createMatInstance("WarningMaterial");
@ -1195,9 +1196,7 @@ GroundCoverCell* GroundCover::_generateCell( const Point2I& index,
const Box3F typeShapeBounds = typeIsShape ? mShapeInstances[ type ]->getShape()->mBounds : Box3F(); const Box3F typeShapeBounds = typeIsShape ? mShapeInstances[ type ]->getShape()->mBounds : Box3F();
const F32 typeWindScale = mWindScale[type]; const F32 typeWindScale = mWindScale[type];
StringTableEntry typeLayer = StringTable->EmptyString(); StringTableEntry typeLayer = mLayerAssetRef[type].getAssetId();
if (mLayerAsset[type].notNull())
typeLayer = mLayerAsset[type]->getAssetId();
const bool typeInvertLayer = mInvertLayer[type]; const bool typeInvertLayer = mInvertLayer[type];
// We can set this once here... all the placements for this are the same. // We can set this once here... all the placements for this are the same.

View file

@ -273,8 +273,7 @@ protected:
BaseMatInstance* mMaterialInst; BaseMatInstance* mMaterialInst;
DECLARE_MATERIALASSET(GroundCover, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_NET_SETGET(GroundCover, Material, InitialUpdateMask);
GroundCoverShaderConstData mShaderConstData; GroundCoverShaderConstData mShaderConstData;
@ -319,7 +318,8 @@ protected:
/// Terrain material assetId to limit coverage to, or /// Terrain material assetId to limit coverage to, or
/// left empty to cover entire terrain. /// left empty to cover entire terrain.
DECLARE_TERRAINMATERIALASSET_NET_ARRAY(GroundCover, Layer, MAX_COVERTYPES, -1) AssetRef<TerrainMaterialAsset> mLayerAssetRef[MAX_COVERTYPES];
StringTableEntry getLayerAssetId( U32 index ) const { return mLayerAssetRef[index].getAssetId(); }
/// Inverts the data layer test making the /// Inverts the data layer test making the
/// layer an exclusion mask. /// layer an exclusion mask.

View file

@ -75,7 +75,6 @@ GroundPlane::GroundPlane()
: mSquareSize( 128.0f ), : mSquareSize( 128.0f ),
mScaleU( 1.0f ), mScaleU( 1.0f ),
mScaleV( 1.0f ), mScaleV( 1.0f ),
mMaterial( NULL ),
mMaterialInst(NULL), mMaterialInst(NULL),
mPhysicsRep( NULL ), mPhysicsRep( NULL ),
mMin( 0.0f, 0.0f ), mMin( 0.0f, 0.0f ),
@ -87,13 +86,10 @@ GroundPlane::GroundPlane()
mConvexList = new Convex; mConvexList = new Convex;
mTypeMask |= TerrainLikeObjectType; mTypeMask |= TerrainLikeObjectType;
INIT_ASSET(Material);
} }
GroundPlane::~GroundPlane() GroundPlane::~GroundPlane()
{ {
mMaterial = NULL;
if(mMaterialInst) if(mMaterialInst)
SAFE_DELETE(mMaterialInst); SAFE_DELETE(mMaterialInst);
@ -110,7 +106,9 @@ void GroundPlane::initPersistFields()
addFieldV( "scaleU", TypeRangedF32, Offset( mScaleU, GroundPlane ), &CommonValidators::PositiveFloat, "Scale of texture repeat in the U direction." ); addFieldV( "scaleU", TypeRangedF32, Offset( mScaleU, GroundPlane ), &CommonValidators::PositiveFloat, "Scale of texture repeat in the U direction." );
addFieldV( "scaleV", TypeRangedF32, Offset( mScaleV, GroundPlane ), &CommonValidators::PositiveFloat, "Scale of texture repeat in the V direction." ); addFieldV( "scaleV", TypeRangedF32, Offset( mScaleV, GroundPlane ), &CommonValidators::PositiveFloat, "Scale of texture repeat in the V direction." );
INITPERSISTFIELD_MATERIALASSET(Material, GroundPlane, "The material used to render the ground plane."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, GroundPlane ) )
.network(-1)
.doc( "Material asset used to render the ground plane." );
endGroup( "Plane" ); endGroup( "Plane" );
@ -157,9 +155,9 @@ bool GroundPlane::onAdd()
void GroundPlane::onRemove() void GroundPlane::onRemove()
{ {
U32 assetStatus = MaterialAsset::getAssetErrCode(mMaterialAsset); U32 assetStatus = MaterialAsset::getAssetErrCode(mMaterialAssetRef.assetPtr);
if (assetStatus == AssetBase::Ok) if (assetStatus == AssetBase::Ok)
AssetDatabase.releaseAsset(mMaterialAsset.getAssetId()); AssetDatabase.releaseAsset(mMaterialAssetRef.getAssetId());
//SAFE_DELETE(mMaterialInst); //SAFE_DELETE(mMaterialInst);
@ -201,7 +199,7 @@ U32 GroundPlane::packUpdate( NetConnection* connection, U32 mask, BitStream* str
stream->write( mScaleU ); stream->write( mScaleU );
stream->write( mScaleV ); stream->write( mScaleV );
PACK_ASSET(connection, Material); AssetDatabase.packDataAsset( stream, mMaterialAssetRef.getAssetId() );
return retMask; return retMask;
} }
@ -214,7 +212,7 @@ void GroundPlane::unpackUpdate( NetConnection* connection, BitStream* stream )
stream->read( &mScaleU ); stream->read( &mScaleU );
stream->read( &mScaleV ); stream->read( &mScaleV );
UNPACK_ASSET(connection, Material); mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
// If we're added then something possibly changed in // If we're added then something possibly changed in
// the editor... do an update of the material and the // the editor... do an update of the material and the
@ -228,17 +226,17 @@ void GroundPlane::unpackUpdate( NetConnection* connection, BitStream* stream )
void GroundPlane::_updateMaterial() void GroundPlane::_updateMaterial()
{ {
if (mMaterialAsset.notNull()) if (mMaterialAssetRef.notNull())
{ {
if (mMaterialInst && String(mMaterialAsset->getMaterialDefinitionName()).equal(mMaterialInst->getMaterial()->getName(), String::NoCase)) if (mMaterialInst && String(mMaterialAssetRef.assetPtr->getMaterialName()).equal(mMaterialInst->getMaterial()->getName(), String::NoCase))
return; return;
SAFE_DELETE(mMaterialInst); SAFE_DELETE(mMaterialInst);
mMaterialInst = MATMGR->createMatInstance(mMaterialAsset->getMaterialDefinitionName(), getGFXVertexFormat< VertexType >()); mMaterialInst = MATMGR->createMatInstance(mMaterialAssetRef.assetPtr->getMaterialName(), getGFXVertexFormat< VertexType >());
if (!mMaterialInst) if (!mMaterialInst)
Con::errorf("GroundPlane::_updateMaterial - no Material called '%s'", mMaterialAsset->getMaterialDefinitionName()); Con::errorf("GroundPlane::_updateMaterial - no Material called '%s'", mMaterialAssetRef.assetPtr->getMaterialName());
} }
} }
@ -356,7 +354,7 @@ void GroundPlane::prepRenderImage( SceneRenderState* state )
// TODO: Should we skip rendering the ground plane into // TODO: Should we skip rendering the ground plane into
// the shadows? Its not like you can ever get under it. // the shadows? Its not like you can ever get under it.
if ( !mMaterial ) if (mMaterialAssetRef.isNull())
return; return;
// If we don't have a material instance after the override then // If we don't have a material instance after the override then
@ -592,10 +590,10 @@ void GroundPlane::generateGrid( U32 width, U32 height, F32 squareSize,
void GroundPlane::getUtilizedAssets(Vector<StringTableEntry>* usedAssetsList) void GroundPlane::getUtilizedAssets(Vector<StringTableEntry>* usedAssetsList)
{ {
U32 assetStatus = MaterialAsset::getAssetErrCode(mMaterialAsset); U32 assetStatus = MaterialAsset::getAssetErrCode(mMaterialAssetRef.assetPtr);
if (assetStatus == AssetBase::Ok) if (assetStatus == AssetBase::Ok)
{ {
usedAssetsList->push_back_unique(mMaterialAsset->getAssetId()); usedAssetsList->push_back_unique(mMaterialAssetRef.getAssetId());
} }
} }

View file

@ -108,8 +108,7 @@ private:
BaseMatInstance* mMaterialInst; BaseMatInstance* mMaterialInst;
DECLARE_MATERIALASSET(GroundPlane, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_NET_SETGET(GroundPlane, Material, -1);
PhysicsBody *mPhysicsRep; PhysicsBody *mPhysicsRep;

View file

@ -679,7 +679,7 @@ void TSStatic::_updateShouldTick()
void TSStatic::prepRenderImage(SceneRenderState* state) void TSStatic::prepRenderImage(SceneRenderState* state)
{ {
if (!mShapeAssetRef.isValid() || !mShapeInstance) if (!mShapeInstance)
return; return;
Point3F cameraOffset; Point3F cameraOffset;
@ -1582,7 +1582,7 @@ void TSStatic::updateMaterials()
if (mChangingMaterials[m].slot == i) if (mChangingMaterials[m].slot == i)
{ {
//Fetch the actual material asset //Fetch the actual material asset
pMatList->renameMaterial(i, mChangingMaterials[m].matAsset->getMaterialDefinitionName()); pMatList->renameMaterial(i, mChangingMaterials[m].matAsset->getMaterialName());
found = true; found = true;
break; break;
} }

View file

@ -288,8 +288,6 @@ DecalRoad::DecalRoad()
mTypeMask |= StaticObjectType | StaticShapeObjectType; mTypeMask |= StaticObjectType | StaticShapeObjectType;
mNetFlags.set(Ghostable); mNetFlags.set(Ghostable);
INIT_ASSET(Material);
mMaterialInst = NULL; mMaterialInst = NULL;
} }
@ -307,7 +305,9 @@ void DecalRoad::initPersistFields()
docsURL; docsURL;
addGroup( "DecalRoad" ); addGroup( "DecalRoad" );
INITPERSISTFIELD_MATERIALASSET(Material, DecalRoad, "Material used for rendering."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, DecalRoad ) )
.network( DecalRoadMask )
.doc( "Material asset used for rendering." );
addProtectedFieldV("textureLength", TypeRangedF32, Offset(mTextureLength, DecalRoad), &DecalRoad::ptSetTextureLength, &defaultProtectedGetFn, &drTextureLengthV, addProtectedFieldV("textureLength", TypeRangedF32, Offset(mTextureLength, DecalRoad), &DecalRoad::ptSetTextureLength, &defaultProtectedGetFn, &drTextureLengthV,
"The length in meters of textures mapped to the DecalRoad" ); "The length in meters of textures mapped to the DecalRoad" );
@ -522,8 +522,7 @@ U32 DecalRoad::packUpdate(NetConnection * con, U32 mask, BitStream * stream)
if ( stream->writeFlag( mask & DecalRoadMask ) ) if ( stream->writeFlag( mask & DecalRoadMask ) )
{ {
// Write Texture Name. AssetDatabase.packDataAsset( stream, mMaterialAssetRef.getAssetId() );
PACK_ASSET(con, Material);
stream->write( mBreakAngle ); stream->write( mBreakAngle );
@ -612,7 +611,7 @@ void DecalRoad::unpackUpdate( NetConnection *con, BitStream *stream )
// DecalRoadMask // DecalRoadMask
if ( stream->readFlag() ) if ( stream->readFlag() )
{ {
UNPACK_ASSET(con, Material); mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
if (isProperlyAdded()) if (isProperlyAdded())
_initMaterial(); _initMaterial();
@ -1078,29 +1077,21 @@ bool DecalRoad::addNodeFromField( void *object, const char *index, const char *d
void DecalRoad::_initMaterial() void DecalRoad::_initMaterial()
{ {
_setMaterial(getMaterial()); if (mMaterialAssetRef.notNull())
if (mMaterialAsset.notNull())
{ {
if (mMaterialInst && String(mMaterialAsset->getMaterialDefinitionName()).equal(mMaterialInst->getMaterial()->getName(), String::NoCase)) if (mMaterialInst && String(mMaterialAssetRef.assetPtr->getMaterialName()).equal(mMaterialInst->getMaterial()->getName(), String::NoCase))
return; return;
SAFE_DELETE(mMaterialInst); SAFE_DELETE(mMaterialInst);
Material* tMat = NULL; Material* tMat = mMaterialAssetRef.assetPtr->getMaterial();
if (tMat)
if (!Sim::findObject(mMaterialAsset->getMaterialDefinitionName(), tMat)) mMaterialInst = tMat->createMatInstance();
Con::errorf("DecalRoad::_initMaterial - Material %s was not found.", mMaterialAsset->getMaterialDefinitionName());
mMaterial = tMat;
if (mMaterial)
mMaterialInst = mMaterial->createMatInstance();
else else
mMaterialInst = MATMGR->createMatInstance("WarningMaterial"); mMaterialInst = MATMGR->createMatInstance("WarningMaterial");
if (!mMaterialInst) if (!mMaterialInst)
Con::errorf("DecalRoad::_initMaterial - no Material called '%s'", mMaterialAsset->getMaterialDefinitionName()); Con::errorf("DecalRoad::_initMaterial - no Material called '%s'", mMaterialAssetRef.assetPtr->getMaterialName());
} }
if (!mMaterialInst) if (!mMaterialInst)

View file

@ -246,8 +246,8 @@ protected:
BaseMatInstance* mMaterialInst; BaseMatInstance* mMaterialInst;
DECLARE_MATERIALASSET(DecalRoad, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_NET_SETGET(DecalRoad, Material, DecalRoadMask); StringTableEntry getMaterialAssetId() const { return mMaterialAssetRef.getAssetId(); }
S16 mRenderPriority; S16 mRenderPriority;

View file

@ -97,13 +97,9 @@ GuiMeshRoadEditorCtrl::GuiMeshRoadEditorCtrl()
mHoverNodeColor( 255,255,255,255 ), mHoverNodeColor( 255,255,255,255 ),
mHasCopied( false ) mHasCopied( false )
{ {
INIT_ASSET(TopMaterial); mTopMaterialAssetRef = Con::getVariable( "$MeshRoadEditor::defaultTopMaterialAsset" );
INIT_ASSET(BottomMaterial); mBottomMaterialAssetRef = Con::getVariable( "$MeshRoadEditor::defaultBottomMaterialAsset" );
INIT_ASSET(SideMaterial); mSideMaterialAssetRef = Con::getVariable( "$MeshRoadEditor::defaultSideMaterialAsset" );
mTopMaterialAssetId = Con::getVariable("$MeshRoadEditor::defaultTopMaterialAsset");
mBottomMaterialAssetId = Con::getVariable("$MeshRoadEditor::defaultBottomMaterialAsset");
mSideMaterialAssetId = Con::getVariable("$MeshRoadEditor::defaultSideMaterialAsset");
} }
GuiMeshRoadEditorCtrl::~GuiMeshRoadEditorCtrl() GuiMeshRoadEditorCtrl::~GuiMeshRoadEditorCtrl()
@ -222,10 +218,10 @@ void GuiMeshRoadEditorCtrl::initPersistFields()
addField( "SelectedSplineColor", TypeColorI, Offset( mSelectedSplineColor, GuiMeshRoadEditorCtrl ) ); addField( "SelectedSplineColor", TypeColorI, Offset( mSelectedSplineColor, GuiMeshRoadEditorCtrl ) );
addField( "HoverNodeColor", TypeColorI, Offset( mHoverNodeColor, GuiMeshRoadEditorCtrl ) ); addField( "HoverNodeColor", TypeColorI, Offset( mHoverNodeColor, GuiMeshRoadEditorCtrl ) );
addField( "isDirty", TypeBool, Offset( mIsDirty, GuiMeshRoadEditorCtrl ) ); addField( "isDirty", TypeBool, Offset( mIsDirty, GuiMeshRoadEditorCtrl ) );
INITPERSISTFIELD_MATERIALASSET(TopMaterial, GuiMeshRoadEditorCtrl, "Default Material used by the Mesh Road Editor on upper surface road creation."); ADD_FIELD( "topMaterialAsset", TypeMaterialAssetRef, Offset( mTopMaterialAssetRef, GuiMeshRoadEditorCtrl ) ).doc( "Default material asset used by the Mesh Road Editor on upper surface road creation." );
INITPERSISTFIELD_MATERIALASSET(BottomMaterial, GuiMeshRoadEditorCtrl, "Default Material used by the Mesh Road Editor on bottom surface road creation."); ADD_FIELD( "bottomMaterialAsset", TypeMaterialAssetRef, Offset( mBottomMaterialAssetRef, GuiMeshRoadEditorCtrl ) ).doc( "Default material asset used by the Mesh Road Editor on bottom surface road creation." );
INITPERSISTFIELD_MATERIALASSET(SideMaterial, GuiMeshRoadEditorCtrl, "Default Material used by the Mesh Road Editor on side surface road creation."); ADD_FIELD( "sideMaterialAsset", TypeMaterialAssetRef, Offset( mSideMaterialAssetRef, GuiMeshRoadEditorCtrl ) ).doc( "Default material asset used by the Mesh Road Editor on side surface road creation." );
//addField( "MoveNodeCursor", TYPEID< SimObject >(), Offset( mMoveNodeCursor, GuiMeshRoadEditorCtrl) ); //addField( "MoveNodeCursor", TYPEID< SimObject >(), Offset( mMoveNodeCursor, GuiMeshRoadEditorCtrl) );
//addField( "AddNodeCursor", TYPEID< SimObject >(), Offset( mAddNodeCursor, GuiMeshRoadEditorCtrl) ); //addField( "AddNodeCursor", TYPEID< SimObject >(), Offset( mAddNodeCursor, GuiMeshRoadEditorCtrl) );
@ -627,12 +623,12 @@ void GuiMeshRoadEditorCtrl::on3DMouseDown(const Gui3DMouseEvent & event)
MeshRoad *newRoad = new MeshRoad; MeshRoad *newRoad = new MeshRoad;
if(mTopMaterialAsset.notNull()) if ( mTopMaterialAssetRef.notNull() )
newRoad->_setTopMaterial(mTopMaterialAssetId); newRoad->mTopMaterialAssetRef = mTopMaterialAssetRef.getAssetId();
if (mBottomMaterialAsset.notNull()) if ( mBottomMaterialAssetRef.notNull() )
newRoad->_setBottomMaterial(mBottomMaterialAssetId); newRoad->mBottomMaterialAssetRef = mBottomMaterialAssetRef.getAssetId();
if (mSideMaterialAsset.notNull()) if ( mSideMaterialAssetRef.notNull() )
newRoad->_setSideMaterial(mSideMaterialAssetId); newRoad->mSideMaterialAssetRef = mSideMaterialAssetRef.getAssetId();
newRoad->registerObject(); newRoad->registerObject();

View file

@ -159,14 +159,9 @@ class GuiMeshRoadEditorCtrl : public EditTSCtrl
bool mHasCopied; bool mHasCopied;
public: public:
DECLARE_MATERIALASSET(GuiMeshRoadEditorCtrl, TopMaterial); AssetRef<MaterialAsset> mTopMaterialAssetRef;
DECLARE_ASSET_SETGET(GuiMeshRoadEditorCtrl, TopMaterial); AssetRef<MaterialAsset> mBottomMaterialAssetRef;
AssetRef<MaterialAsset> mSideMaterialAssetRef;
DECLARE_MATERIALASSET(GuiMeshRoadEditorCtrl, BottomMaterial);
DECLARE_ASSET_SETGET(GuiMeshRoadEditorCtrl, BottomMaterial);
DECLARE_MATERIALASSET(GuiMeshRoadEditorCtrl, SideMaterial);
DECLARE_ASSET_SETGET(GuiMeshRoadEditorCtrl, SideMaterial);
}; };
class GuiMeshRoadEditorUndoAction : public UndoAction class GuiMeshRoadEditorUndoAction : public UndoAction

View file

@ -85,7 +85,7 @@ GuiRoadEditorCtrl::GuiRoadEditorCtrl()
mSavedDrag = false; mSavedDrag = false;
mIsDirty = false; mIsDirty = false;
mMaterialAssetId = Con::getVariable("$DecalRoadEditor::defaultMaterialAsset"); mMaterialAssetRef = Con::getVariable( "$DecalRoadEditor::defaultMaterialAsset" );
} }
GuiRoadEditorCtrl::~GuiRoadEditorCtrl() GuiRoadEditorCtrl::~GuiRoadEditorCtrl()
@ -100,7 +100,7 @@ void GuiRoadEditorUndoAction::undo()
return; return;
// Temporarily save the roads current data. // Temporarily save the roads current data.
String materialAssetId = road->mMaterialAssetId; StringTableEntry materialAssetId = road->getMaterialAssetId();
F32 textureLength = road->mTextureLength; F32 textureLength = road->mTextureLength;
F32 breakAngle = road->mBreakAngle; F32 breakAngle = road->mBreakAngle;
F32 segmentsPerBatch = road->mSegmentsPerBatch; F32 segmentsPerBatch = road->mSegmentsPerBatch;
@ -108,7 +108,7 @@ void GuiRoadEditorUndoAction::undo()
nodes.merge( road->mNodes ); nodes.merge( road->mNodes );
// Restore the Road properties saved in the UndoAction // Restore the Road properties saved in the UndoAction
road->_setMaterial(materialAssetId); road->mMaterialAssetRef = mMaterialAssetId;
road->mBreakAngle = breakAngle; road->mBreakAngle = breakAngle;
road->mSegmentsPerBatch = segmentsPerBatch; road->mSegmentsPerBatch = segmentsPerBatch;
road->mTextureLength = textureLength; road->mTextureLength = textureLength;
@ -165,7 +165,7 @@ void GuiRoadEditorCtrl::initPersistFields()
addField( "HoverNodeColor", TypeColorI, Offset( mHoverNodeColor, GuiRoadEditorCtrl ) ); addField( "HoverNodeColor", TypeColorI, Offset( mHoverNodeColor, GuiRoadEditorCtrl ) );
addField( "isDirty", TypeBool, Offset( mIsDirty, GuiRoadEditorCtrl ) ); addField( "isDirty", TypeBool, Offset( mIsDirty, GuiRoadEditorCtrl ) );
INITPERSISTFIELD_MATERIALASSET(Material, GuiRoadEditorCtrl, "Default Material used by the Road Editor on road creation."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, GuiRoadEditorCtrl ) ).doc( "Default material asset used by the Road Editor on road creation." );
//addField( "MoveNodeCursor", TYPEID< SimObject >(), Offset( mMoveNodeCursor, GuiRoadEditorCtrl) ); //addField( "MoveNodeCursor", TYPEID< SimObject >(), Offset( mMoveNodeCursor, GuiRoadEditorCtrl) );
//addField( "AddNodeCursor", TYPEID< SimObject >(), Offset( mAddNodeCursor, GuiRoadEditorCtrl) ); //addField( "AddNodeCursor", TYPEID< SimObject >(), Offset( mAddNodeCursor, GuiRoadEditorCtrl) );
@ -407,8 +407,8 @@ void GuiRoadEditorCtrl::on3DMouseDown(const Gui3DMouseEvent & event)
DecalRoad *newRoad = new DecalRoad; DecalRoad *newRoad = new DecalRoad;
if (mMaterialAsset.notNull()) if ( mMaterialAssetRef.notNull() )
newRoad->_setMaterial(mMaterialAssetId); newRoad->mMaterialAssetRef = mMaterialAssetRef.getAssetId();
newRoad->registerObject(); newRoad->registerObject();
@ -1029,7 +1029,7 @@ void GuiRoadEditorCtrl::submitUndo( const UTF8 *name )
action->mObjId = mSelRoad->getId(); action->mObjId = mSelRoad->getId();
action->mBreakAngle = mSelRoad->mBreakAngle; action->mBreakAngle = mSelRoad->mBreakAngle;
action->mMaterialAssetId = mSelRoad->mMaterialAssetId; action->mMaterialAssetId = mSelRoad->getMaterialAssetId();
action->mSegmentsPerBatch = mSelRoad->mSegmentsPerBatch; action->mSegmentsPerBatch = mSelRoad->mSegmentsPerBatch;
action->mTextureLength = mSelRoad->mTextureLength; action->mTextureLength = mSelRoad->mTextureLength;
action->mRoadEditor = this; action->mRoadEditor = this;

View file

@ -103,8 +103,8 @@ class GuiRoadEditorCtrl : public EditTSCtrl
public: public:
DECLARE_MATERIALASSET(GuiRoadEditorCtrl, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_SETGET(GuiRoadEditorCtrl, Material); StringTableEntry getMaterialAssetId() const { return mMaterialAssetRef.getAssetId(); }
protected: protected:

View file

@ -920,10 +920,6 @@ MeshRoad::MeshRoad()
mTriangleCount[i] = 0; mTriangleCount[i] = 0;
} }
INIT_ASSET(TopMaterial);
INIT_ASSET(BottomMaterial);
INIT_ASSET(SideMaterial);
mSideProfile.mRoad = this; mSideProfile.mRoad = this;
} }
@ -939,9 +935,15 @@ void MeshRoad::initPersistFields()
docsURL; docsURL;
addGroup( "MeshRoad" ); addGroup( "MeshRoad" );
INITPERSISTFIELD_MATERIALASSET(TopMaterial, MeshRoad, "Material for the upper surface of the road."); ADD_FIELD( "topMaterialAsset", TypeMaterialAssetRef, Offset( mTopMaterialAssetRef, MeshRoad ) )
INITPERSISTFIELD_MATERIALASSET(BottomMaterial, MeshRoad, "Material for the bottom surface of the road."); .network( MeshRoadMask )
INITPERSISTFIELD_MATERIALASSET(SideMaterial, MeshRoad, "Material for the side surface of the road."); .doc( "Material asset for the upper surface of the road." );
ADD_FIELD( "bottomMaterialAsset", TypeMaterialAssetRef, Offset( mBottomMaterialAssetRef, MeshRoad ) )
.network( MeshRoadMask )
.doc( "Material asset for the bottom surface of the road." );
ADD_FIELD( "sideMaterialAsset", TypeMaterialAssetRef, Offset( mSideMaterialAssetRef, MeshRoad ) )
.network( MeshRoadMask )
.doc( "Material asset for the side surface of the road." );
addFieldV( "textureLength", TypeRangedF32, Offset( mTextureLength, MeshRoad ), &mrTextureLengthV, addFieldV( "textureLength", TypeRangedF32, Offset( mTextureLength, MeshRoad ), &mrTextureLengthV,
"The length in meters of textures mapped to the MeshRoad." ); "The length in meters of textures mapped to the MeshRoad." );
@ -1320,18 +1322,12 @@ void MeshRoad::prepRenderImage( SceneRenderState* state )
void MeshRoad::_initMaterial() void MeshRoad::_initMaterial()
{ {
if (mTopMaterialAsset.notNull()) if (mTopMaterialAssetRef.notNull())
{ {
if (!mMatInst[Top] || !String(mTopMaterialAsset->getMaterialDefinitionName()).equal(mMatInst[Top]->getMaterial()->getName(), String::NoCase)) if (!mMatInst[Top] || !String(mTopMaterialAssetRef.assetPtr->getMaterialName()).equal(mMatInst[Top]->getMaterial()->getName(), String::NoCase))
{ {
SAFE_DELETE(mMatInst[Top]); SAFE_DELETE(mMatInst[Top]);
mMaterial[Top] = mTopMaterialAssetRef.assetPtr->getMaterial();
Material* tMat = NULL;
if (!Sim::findObject(mTopMaterialAsset->getMaterialDefinitionName(), tMat))
Con::errorf("MeshRoad::_initMaterial - Material %s was not found.", mTopMaterialAsset->getMaterialDefinitionName());
mMaterial[Top] = tMat;
if (mMaterial[Top]) if (mMaterial[Top])
mMatInst[Top] = mMaterial[Top]->createMatInstance(); mMatInst[Top] = mMaterial[Top]->createMatInstance();
else else
@ -1341,19 +1337,12 @@ void MeshRoad::_initMaterial()
} }
} }
if (mBottomMaterialAsset.notNull()) if (mBottomMaterialAssetRef.notNull())
{ {
if (!mMatInst[Bottom] || !String(mBottomMaterialAsset->getMaterialDefinitionName()).equal(mMatInst[Bottom]->getMaterial()->getName(), String::NoCase)) if (!mMatInst[Bottom] || !String(mBottomMaterialAssetRef.assetPtr->getMaterialName()).equal(mMatInst[Bottom]->getMaterial()->getName(), String::NoCase))
{ {
SAFE_DELETE(mMatInst[Bottom]); SAFE_DELETE(mMatInst[Bottom]);
mMaterial[Bottom] = mBottomMaterialAssetRef.assetPtr->getMaterial();
Material* tMat = NULL;
if (!Sim::findObject(mBottomMaterialAsset->getMaterialDefinitionName(), tMat))
Con::errorf("MeshRoad::_initMaterial - Material %s was not found.", mBottomMaterialAsset->getMaterialDefinitionName());
mMaterial[Bottom] = tMat;
if (mMaterial[Bottom]) if (mMaterial[Bottom])
mMatInst[Bottom] = mMaterial[Bottom]->createMatInstance(); mMatInst[Bottom] = mMaterial[Bottom]->createMatInstance();
else else
@ -1363,18 +1352,12 @@ void MeshRoad::_initMaterial()
} }
} }
if (mSideMaterialAsset.notNull()) if (mSideMaterialAssetRef.notNull())
{ {
if (!mMatInst[Side] || !String(mSideMaterialAsset->getMaterialDefinitionName()).equal(mMatInst[Side]->getMaterial()->getName(), String::NoCase)) if (!mMatInst[Side] || !String(mSideMaterialAssetRef.assetPtr->getMaterialName()).equal(mMatInst[Side]->getMaterial()->getName(), String::NoCase))
{ {
SAFE_DELETE(mMatInst[Side]); SAFE_DELETE(mMatInst[Side]);
mMaterial[Side] = mSideMaterialAssetRef.assetPtr->getMaterial();
Material* tMat = NULL;
if (!Sim::findObject(mSideMaterialAsset->getMaterialDefinitionName(), tMat))
Con::errorf("MeshRoad::_initMaterial - Material %s was not found.", mSideMaterialAsset->getMaterialDefinitionName());
mMaterial[Side] = tMat;
if (mMaterial[Side]) if (mMaterial[Side])
mMatInst[Side] = mMaterial[Side]->createMatInstance(); mMatInst[Side] = mMaterial[Side]->createMatInstance();
else else
@ -1472,9 +1455,9 @@ U32 MeshRoad::packUpdate(NetConnection * con, U32 mask, BitStream * stream)
stream->writeAffineTransform( mObjToWorld ); stream->writeAffineTransform( mObjToWorld );
// Write Materials // Write Materials
PACK_ASSET(con, TopMaterial); AssetDatabase.packDataAsset( stream, mTopMaterialAssetRef.getAssetId() );
PACK_ASSET(con, BottomMaterial); AssetDatabase.packDataAsset( stream, mBottomMaterialAssetRef.getAssetId() );
PACK_ASSET(con, SideMaterial); AssetDatabase.packDataAsset( stream, mSideMaterialAssetRef.getAssetId() );
stream->write( mTextureLength ); stream->write( mTextureLength );
stream->write( mBreakAngle ); stream->write( mBreakAngle );
@ -1571,9 +1554,9 @@ void MeshRoad::unpackUpdate(NetConnection * con, BitStream * stream)
stream->readAffineTransform(&ObjectMatrix); stream->readAffineTransform(&ObjectMatrix);
Parent::setTransform(ObjectMatrix); Parent::setTransform(ObjectMatrix);
UNPACK_ASSET(con, TopMaterial); mTopMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
UNPACK_ASSET(con, BottomMaterial); mBottomMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
UNPACK_ASSET(con, SideMaterial); mSideMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
if ( isProperlyAdded() ) if ( isProperlyAdded() )
_initMaterial(); _initMaterial();

View file

@ -625,14 +625,9 @@ protected:
GFXVertexBufferHandle<GFXVertexPNTT> mVB[SurfaceCount]; GFXVertexBufferHandle<GFXVertexPNTT> mVB[SurfaceCount];
GFXPrimitiveBufferHandle mPB[SurfaceCount]; GFXPrimitiveBufferHandle mPB[SurfaceCount];
DECLARE_MATERIALASSET(MeshRoad, TopMaterial); AssetRef<MaterialAsset> mTopMaterialAssetRef;
DECLARE_ASSET_NET_SETGET(MeshRoad, TopMaterial, MeshRoadMask); AssetRef<MaterialAsset> mBottomMaterialAssetRef;
AssetRef<MaterialAsset> mSideMaterialAssetRef;
DECLARE_MATERIALASSET(MeshRoad, BottomMaterial);
DECLARE_ASSET_NET_SETGET(MeshRoad, BottomMaterial, MeshRoadMask);
DECLARE_MATERIALASSET(MeshRoad, SideMaterial);
DECLARE_ASSET_NET_SETGET(MeshRoad, SideMaterial, MeshRoadMask);
//String mMaterialName[SurfaceCount]; //String mMaterialName[SurfaceCount];
SimObjectPtr<Material> mMaterial[SurfaceCount]; SimObjectPtr<Material> mMaterial[SurfaceCount];

View file

@ -170,7 +170,6 @@ ScatterSky::ScatterSky()
mNightCubemapName = StringTable->EmptyString(); mNightCubemapName = StringTable->EmptyString();
mSunSize = 1.0f; mSunSize = 1.0f;
INIT_ASSET(MoonMat);
mMoonMatInst = NULL; mMoonMatInst = NULL;
@ -413,7 +412,9 @@ void ScatterSky::initPersistFields()
addField( "moonEnabled", TypeBool, Offset( mMoonEnabled, ScatterSky ), addField( "moonEnabled", TypeBool, Offset( mMoonEnabled, ScatterSky ),
"Enable or disable rendering of the moon sprite during night." ); "Enable or disable rendering of the moon sprite during night." );
INITPERSISTFIELD_MATERIALASSET(MoonMat, ScatterSky, "Material for the moon sprite."); ADD_FIELD( "moonMatAsset", TypeMaterialAssetRef, Offset( mMoonMatAssetRef, ScatterSky ) )
.network( UpdateMask )
.doc( "Material asset for the moon sprite." );
addFieldV( "moonScale", TypeRangedF32, Offset( mMoonScale, ScatterSky ), &CommonValidators::PositiveFloat, addFieldV( "moonScale", TypeRangedF32, Offset( mMoonScale, ScatterSky ), &CommonValidators::PositiveFloat,
"Controls size the moon sprite renders, specified as a fractional amount of the screen height." ); "Controls size the moon sprite renders, specified as a fractional amount of the screen height." );
@ -506,7 +507,7 @@ U32 ScatterSky::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
stream->writeFlag( mMoonEnabled ); stream->writeFlag( mMoonEnabled );
PACK_ASSET(con, MoonMat); AssetDatabase.packDataAsset( stream, mMoonMatAssetRef.getAssetId() );
stream->write( mMoonScale ); stream->write( mMoonScale );
stream->write( mMoonTint ); stream->write( mMoonTint );
@ -620,7 +621,7 @@ void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream)
mMoonEnabled = stream->readFlag(); mMoonEnabled = stream->readFlag();
UNPACK_ASSET(con, MoonMat); mMoonMatAssetRef = AssetDatabase.unpackDataAsset( stream );
stream->read( &mMoonScale ); stream->read( &mMoonScale );
stream->read( &mMoonTint ); stream->read( &mMoonTint );
@ -914,14 +915,14 @@ void ScatterSky::_initMoon()
if ( mMoonMatInst ) if ( mMoonMatInst )
SAFE_DELETE( mMoonMatInst ); SAFE_DELETE( mMoonMatInst );
if (mMoonMatAsset.notNull()) if (mMoonMatAssetRef.notNull())
{ {
FeatureSet features = MATMGR->getDefaultFeatures(); FeatureSet features = MATMGR->getDefaultFeatures();
features.removeFeature(MFT_RTLighting); features.removeFeature(MFT_RTLighting);
features.removeFeature(MFT_Visibility); features.removeFeature(MFT_Visibility);
features.removeFeature(MFT_ReflectionProbes); features.removeFeature(MFT_ReflectionProbes);
features.addFeature(MFT_isBackground); features.addFeature(MFT_isBackground);
mMoonMatInst = MATMGR->createMatInstance(mMoonMatAsset->getMaterialDefinitionName(), features, getGFXVertexFormat<GFXVertexPCT>()); mMoonMatInst = MATMGR->createMatInstance(mMoonMatAssetRef.assetPtr->getMaterialName(), features, getGFXVertexFormat<GFXVertexPCT>());
GFXStateBlockDesc desc; GFXStateBlockDesc desc;
desc.setBlend(true); desc.setBlend(true);

View file

@ -233,8 +233,7 @@ protected:
bool mMoonEnabled; bool mMoonEnabled;
DECLARE_MATERIALASSET(ScatterSky, MoonMat); AssetRef<MaterialAsset> mMoonMatAssetRef;
DECLARE_ASSET_NET_SETGET(ScatterSky, MoonMat, UpdateMask);
BaseMatInstance *mMoonMatInst; BaseMatInstance *mMoonMatInst;
F32 mMoonScale; F32 mMoonScale;

View file

@ -56,7 +56,6 @@ SkyBox::SkyBox()
mTypeMask |= EnvironmentObjectType | StaticObjectType; mTypeMask |= EnvironmentObjectType | StaticObjectType;
mNetFlags.set(Ghostable | ScopeAlways); mNetFlags.set(Ghostable | ScopeAlways);
INIT_ASSET(Material);
mMatInstance = NULL; mMatInstance = NULL;
mIsVBDirty = false; mIsVBDirty = false;
@ -117,7 +116,9 @@ void SkyBox::initPersistFields()
docsURL; docsURL;
addGroup( "Sky Box" ); addGroup( "Sky Box" );
INITPERSISTFIELD_MATERIALASSET(Material, SkyBox, "The name of a cubemap material for the sky box."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, SkyBox ) )
.network(-1)
.doc( "The material asset for a cubemap material for the sky box." );
addField( "drawBottom", TypeBool, Offset( mDrawBottom, SkyBox ), addField( "drawBottom", TypeBool, Offset( mDrawBottom, SkyBox ),
"If false the bottom of the skybox is not rendered." ); "If false the bottom of the skybox is not rendered." );
@ -140,7 +141,7 @@ U32 SkyBox::packUpdate( NetConnection *conn, U32 mask, BitStream *stream )
{ {
U32 retMask = Parent::packUpdate( conn, mask, stream ); U32 retMask = Parent::packUpdate( conn, mask, stream );
PACK_ASSET(conn, Material); AssetDatabase.packDataAsset( stream, mMaterialAssetRef.getAssetId() );
stream->writeFlag( mDrawBottom ); stream->writeFlag( mDrawBottom );
stream->write( mFogBandHeight ); stream->write( mFogBandHeight );
@ -152,9 +153,9 @@ void SkyBox::unpackUpdate( NetConnection *conn, BitStream *stream )
{ {
Parent::unpackUpdate( conn, stream ); Parent::unpackUpdate( conn, stream );
StringTableEntry oldMatName = getMaterial(); StringTableEntry oldMatId = mMaterialAssetRef.getAssetId();
UNPACK_ASSET(conn, Material); mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
if (oldMatName != getMaterial()) if ( oldMatId != mMaterialAssetRef.getAssetId() )
{ {
_updateMaterial(); _updateMaterial();
} }
@ -594,8 +595,8 @@ void SkyBox::_initMaterial()
if ( mMatInstance ) if ( mMatInstance )
SAFE_DELETE( mMatInstance ); SAFE_DELETE( mMatInstance );
if ( mMaterial ) if (mMaterialAssetRef.notNull())
mMatInstance = mMaterial->createMatInstance(); mMatInstance = mMaterialAssetRef.assetPtr->getMaterial()->createMatInstance();
else else
mMatInstance = MATMGR->createMatInstance( "WarningMaterial" ); mMatInstance = MATMGR->createMatInstance( "WarningMaterial" );
@ -621,21 +622,13 @@ void SkyBox::_initMaterial()
void SkyBox::_updateMaterial() void SkyBox::_updateMaterial()
{ {
if (!getMaterialResource().isValid()) if (mMaterialAssetRef.notNull())
{
//If our materialDef isn't valid, try setting it
_setMaterial(getMaterial());
}
if (getMaterialResource().isValid())
{
_initMaterial(); _initMaterial();
}
} }
BaseMatInstance* SkyBox::_getMaterialInstance() BaseMatInstance* SkyBox::_getMaterialInstance()
{ {
if ( !mMaterial || !mMatInstance || mMatInstance->getMaterial() != mMaterial ) if (!mMaterialAssetRef.notNull() || !mMatInstance || mMatInstance->getMaterial() != mMaterialAssetRef.assetPtr->getMaterial().getPointer())
_initMaterial(); _initMaterial();
if ( !mMatInstance ) if ( !mMatInstance )

View file

@ -102,8 +102,7 @@ public:
protected: protected:
// Material // Material
DECLARE_MATERIALASSET(SkyBox, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_NET_SETGET(SkyBox, Material, -1);
BaseMatInstance *mMatInstance; BaseMatInstance *mMatInstance;
SkyMatParams mMatParamHandle; SkyMatParams mMatParamHandle;

View file

@ -55,7 +55,6 @@ SkySphere::SkySphere()
mTypeMask |= EnvironmentObjectType | StaticObjectType; mTypeMask |= EnvironmentObjectType | StaticObjectType;
mNetFlags.set(Ghostable | ScopeAlways); mNetFlags.set(Ghostable | ScopeAlways);
INIT_ASSET(Material);
mMatInstance = NULL; mMatInstance = NULL;
mIsVBDirty = false; mIsVBDirty = false;
@ -116,7 +115,9 @@ void SkySphere::initPersistFields()
docsURL; docsURL;
addGroup("Sky Sphere"); addGroup("Sky Sphere");
INITPERSISTFIELD_MATERIALASSET(Material, SkySphere, "The name of a cubemap material for the sky box."); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, SkySphere ) )
.network(-1)
.doc( "The material asset of a cubemap for the sky box." );
addFieldV("fogBandHeight", TypeRangedF32, Offset(mFogBandHeight, SkySphere), &CommonValidators::NormalizedFloat, addFieldV("fogBandHeight", TypeRangedF32, Offset(mFogBandHeight, SkySphere), &CommonValidators::NormalizedFloat,
"The height (0-1) of the fog band from the horizon to the top of the SkySphere."); "The height (0-1) of the fog band from the horizon to the top of the SkySphere.");
@ -136,7 +137,7 @@ U32 SkySphere::packUpdate(NetConnection* conn, U32 mask, BitStream* stream)
{ {
U32 retMask = Parent::packUpdate(conn, mask, stream); U32 retMask = Parent::packUpdate(conn, mask, stream);
PACK_ASSET(conn, Material); AssetDatabase.packDataAsset( stream, mMaterialAssetRef.getAssetId() );
stream->write(mFogBandHeight); stream->write(mFogBandHeight);
@ -147,9 +148,9 @@ void SkySphere::unpackUpdate(NetConnection* conn, BitStream* stream)
{ {
Parent::unpackUpdate(conn, stream); Parent::unpackUpdate(conn, stream);
StringTableEntry oldMatName = getMaterial(); StringTableEntry oldMatId = mMaterialAssetRef.getAssetId();
UNPACK_ASSET(conn, Material); mMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
if (oldMatName != getMaterial()) if ( oldMatId != mMaterialAssetRef.getAssetId() )
{ {
_updateMaterial(); _updateMaterial();
} }
@ -589,8 +590,8 @@ void SkySphere::_initMaterial()
if (mMatInstance) if (mMatInstance)
SAFE_DELETE(mMatInstance); SAFE_DELETE(mMatInstance);
if (mMaterial) if (mMaterialAssetRef.notNull())
mMatInstance = mMaterial->createMatInstance(); mMatInstance = mMaterialAssetRef.assetPtr->getMaterial()->createMatInstance();
else else
mMatInstance = MATMGR->createMatInstance("WarningMaterial"); mMatInstance = MATMGR->createMatInstance("WarningMaterial");
@ -615,21 +616,13 @@ void SkySphere::_initMaterial()
void SkySphere::_updateMaterial() void SkySphere::_updateMaterial()
{ {
if (!getMaterialResource().isValid()) if (mMaterialAssetRef.notNull())
{
//If our materialDef isn't valid, try setting it
_setMaterial(getMaterial());
}
if (getMaterialResource().isValid())
{
_initMaterial(); _initMaterial();
}
} }
BaseMatInstance* SkySphere::_getMaterialInstance() BaseMatInstance* SkySphere::_getMaterialInstance()
{ {
if (!mMaterial || !mMatInstance || mMatInstance->getMaterial() != mMaterial) if (!mMaterialAssetRef.notNull() || !mMatInstance || mMatInstance->getMaterial() != mMaterialAssetRef.assetPtr->getMaterial().getPointer())
_initMaterial(); _initMaterial();
if (!mMatInstance) if (!mMatInstance)

View file

@ -142,8 +142,7 @@ public:
protected: protected:
// Material // Material
DECLARE_MATERIALASSET(SkySphere, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_NET_SETGET(SkySphere, Material, -1);
BaseMatInstance* mMatInstance; BaseMatInstance* mMatInstance;
SkyMatParams mMatParamHandle; SkyMatParams mMatParamHandle;

View file

@ -91,8 +91,6 @@ Sun::Sun()
mCoronaUseLightColor = true; mCoronaUseLightColor = true;
mCoronaMatInst = NULL; mCoronaMatInst = NULL;
INIT_ASSET(CoronaMaterial);
mMatrixSet = reinterpret_cast<MatrixSet *>(dMalloc_aligned(sizeof(MatrixSet), 16)); mMatrixSet = reinterpret_cast<MatrixSet *>(dMalloc_aligned(sizeof(MatrixSet), 16));
constructInPlace(mMatrixSet); constructInPlace(mMatrixSet);
@ -181,7 +179,9 @@ void Sun::initPersistFields()
addField( "coronaEnabled", TypeBool, Offset( mCoronaEnabled, Sun ), addField( "coronaEnabled", TypeBool, Offset( mCoronaEnabled, Sun ),
"Enable or disable rendering of the corona sprite." ); "Enable or disable rendering of the corona sprite." );
INITPERSISTFIELD_MATERIALASSET(CoronaMaterial, Sun, "Material for the corona sprite."); ADD_FIELD( "coronaMaterialAsset", TypeMaterialAssetRef, Offset( mCoronaMaterialAssetRef, Sun ) )
.network( UpdateMask )
.doc( "Material asset for the corona sprite." );
addFieldV( "coronaScale", TypeRangedF32, Offset( mCoronaScale, Sun ), &CommonValidators::PositiveFloat, addFieldV( "coronaScale", TypeRangedF32, Offset( mCoronaScale, Sun ), &CommonValidators::PositiveFloat,
"Controls size the corona sprite renders, specified as a fractional amount of the screen height." ); "Controls size the corona sprite renders, specified as a fractional amount of the screen height." );
@ -242,7 +242,7 @@ U32 Sun::packUpdate(NetConnection *conn, U32 mask, BitStream *stream )
stream->writeFlag( mCoronaEnabled ); stream->writeFlag( mCoronaEnabled );
PACK_ASSET(conn, CoronaMaterial); AssetDatabase.packDataAsset( stream, mCoronaMaterialAssetRef.getAssetId() );
stream->write( mCoronaScale ); stream->write( mCoronaScale );
stream->write( mCoronaTint ); stream->write( mCoronaTint );
@ -288,7 +288,7 @@ void Sun::unpackUpdate( NetConnection *conn, BitStream *stream )
mCoronaEnabled = stream->readFlag(); mCoronaEnabled = stream->readFlag();
UNPACK_ASSET(conn, CoronaMaterial); mCoronaMaterialAssetRef = AssetDatabase.unpackDataAsset( stream );
stream->read( &mCoronaScale ); stream->read( &mCoronaScale );
stream->read( &mCoronaTint ); stream->read( &mCoronaTint );
@ -453,7 +453,7 @@ void Sun::_initCorona()
SAFE_DELETE( mCoronaMatInst ); SAFE_DELETE( mCoronaMatInst );
if (mCoronaMaterialAsset.notNull()) if (mCoronaMaterialAssetRef.notNull())
{ {
FeatureSet features = MATMGR->getDefaultFeatures(); FeatureSet features = MATMGR->getDefaultFeatures();
features.removeFeature(MFT_RTLighting); features.removeFeature(MFT_RTLighting);
@ -462,7 +462,7 @@ void Sun::_initCorona()
features.addFeature(MFT_isBackground); features.addFeature(MFT_isBackground);
features.addFeature(MFT_VertLit); features.addFeature(MFT_VertLit);
mCoronaMatInst = MATMGR->createMatInstance(mCoronaMaterialAsset->getMaterialDefinitionName(), features, getGFXVertexFormat<GFXVertexPCT>()); mCoronaMatInst = MATMGR->createMatInstance(mCoronaMaterialAssetRef.assetPtr->getMaterialName(), features, getGFXVertexFormat<GFXVertexPCT>());
GFXStateBlockDesc desc; GFXStateBlockDesc desc;
desc.setBlend(true); desc.setBlend(true);

View file

@ -78,8 +78,7 @@ protected:
bool mCoronaEnabled; bool mCoronaEnabled;
DECLARE_MATERIALASSET(Sun, CoronaMaterial); AssetRef<MaterialAsset> mCoronaMaterialAssetRef;
DECLARE_ASSET_NET_SETGET(Sun, CoronaMaterial, UpdateMask);
BaseMatInstance *mCoronaMatInst; BaseMatInstance *mCoronaMatInst;
MatrixSet *mMatrixSet; MatrixSet *mMatrixSet;

View file

@ -45,15 +45,13 @@ ConsoleDocClass( GuiMaterialCtrl,
GuiMaterialCtrl::GuiMaterialCtrl() GuiMaterialCtrl::GuiMaterialCtrl()
: mMaterialInst( NULL ) : mMaterialInst( NULL )
{ {
INIT_ASSET(Material);
} }
void GuiMaterialCtrl::initPersistFields() void GuiMaterialCtrl::initPersistFields()
{ {
docsURL; docsURL;
addGroup( "Material" ); addGroup( "Material" );
INITPERSISTFIELD_MATERIALASSET(Material, GuiMaterialCtrl, ""); ADD_FIELD( "materialAsset", TypeMaterialAssetRef, Offset( mMaterialAssetRef, GuiMaterialCtrl ) ).doc( "Material asset to display in this control." );
addProtectedField( "materialName", TypeStringFilename, Offset( mMaterialName, GuiMaterialCtrl ), &GuiMaterialCtrl::_setMaterialData, &defaultProtectedGetFn, "", AbstractClassRep::FIELD_HideInInspectors );
endGroup( "Material" ); endGroup( "Material" );
Parent::initPersistFields(); Parent::initPersistFields();
@ -65,7 +63,7 @@ bool GuiMaterialCtrl::onWake()
return false; return false;
setActive( true ); setActive( true );
setMaterial( getMaterial() ); setMaterial( mMaterialAssetRef.assetId );
return true; return true;
} }
@ -77,22 +75,26 @@ void GuiMaterialCtrl::onSleep()
Parent::onSleep(); Parent::onSleep();
} }
bool GuiMaterialCtrl::_setMaterial( void *object, const char *index, const char *data )
{
static_cast<GuiMaterialCtrl *>( object )->setMaterial( data );
// Return false to keep the caller from setting the field.
return false;
}
bool GuiMaterialCtrl::setMaterial( const String &materialName ) bool GuiMaterialCtrl::setMaterial( const String &materialName )
{ {
SAFE_DELETE( mMaterialInst ); SAFE_DELETE( mMaterialInst );
_setMaterial(StringTable->insert(materialName.c_str())); StringTableEntry matId = StringTable->insert( materialName.c_str() );
if ( matId == StringTable->EmptyString() || AssetDatabase.isDeclaredAsset( matId ))
{
mMaterialAssetRef = matId;
}
else
{
StringTableEntry assetId = MaterialAsset::getAssetIdByMaterialName( matId );
if ( assetId != StringTable->EmptyString() )
mMaterialAssetRef = assetId;
}
if ( getMaterial() != StringTable->EmptyString() && isAwake() ) if ( mMaterialAssetRef.notNull() && isAwake() )
mMaterialInst = MATMGR->createMatInstance( getMaterial(), getGFXVertexFormat<GFXVertexPCT>() ); mMaterialInst = MATMGR->createMatInstance(
mMaterialAssetRef.assetPtr->getMaterialName(),
getGFXVertexFormat<GFXVertexPCT>() );
return true; return true;
} }

View file

@ -40,12 +40,8 @@ private:
protected: protected:
DECLARE_MATERIALASSET(GuiMaterialCtrl, Material); AssetRef<MaterialAsset> mMaterialAssetRef;
DECLARE_ASSET_SETGET(GuiMaterialCtrl, Material); BaseMatInstance* mMaterialInst;
BaseMatInstance *mMaterialInst;
static bool _setMaterial( void *object, const char *index, const char *data );
public: public:

View file

@ -253,13 +253,13 @@ void GuiConvexEditorCtrl::setVisible( bool val )
//Set the texture to a representatory one so we know what's what //Set the texture to a representatory one so we know what's what
if (isTrigger) if (isTrigger)
proxyShape->_setMaterial(StringTable->insert("ToolsModule:TriggerProxyMaterial")); proxyShape->setMaterial(StringTable->insert("ToolsModule:TriggerProxyMaterial"));
else if (isPortal) else if (isPortal)
proxyShape->_setMaterial(StringTable->insert("ToolsModule:PortalProxyMaterial")); proxyShape->setMaterial(StringTable->insert("ToolsModule:PortalProxyMaterial"));
else if (isZone) else if (isZone)
proxyShape->_setMaterial(StringTable->insert("ToolsModule:ZoneProxyMaterial")); proxyShape->setMaterial(StringTable->insert("ToolsModule:ZoneProxyMaterial"));
else if (isOccluder) else if (isOccluder)
proxyShape->_setMaterial(StringTable->insert("ToolsModule:OccluderProxyMaterial")); proxyShape->setMaterial(StringTable->insert("ToolsModule:OccluderProxyMaterial"));
proxyShape->_updateMaterial(); proxyShape->_updateMaterial();
@ -533,7 +533,7 @@ void GuiConvexEditorCtrl::on3DMouseDragged(const Gui3DMouseEvent & event)
setupShape( newShape ); setupShape( newShape );
newShape->_setMaterial(mConvexSEL->getMaterial()); newShape->setMaterial(mConvexSEL->getMaterial());
submitUndo( CreateShape, newShape ); submitUndo( CreateShape, newShape );
@ -1462,7 +1462,7 @@ bool GuiConvexEditorCtrl::isShapeValid( ConvexShape *shape )
void GuiConvexEditorCtrl::setupShape( ConvexShape *shape ) void GuiConvexEditorCtrl::setupShape( ConvexShape *shape )
{ {
shape->registerObject(); shape->registerObject();
shape->_setMaterial(mMaterialName); shape->setMaterial(mMaterialName);
updateShape( shape ); updateShape( shape );
Scene* scene = Scene::getRootScene(); Scene* scene = Scene::getRootScene();
@ -1992,7 +1992,7 @@ void GuiConvexEditorCtrl::setSelectedFaceMaterial(const char* materialName)
{ {
//add a new one //add a new one
ConvexShape::surfaceMaterial newMat; ConvexShape::surfaceMaterial newMat;
newMat._setMaterial(materialName); newMat.setMaterial(materialName);
mConvexSEL->mSurfaceTextures.push_back(newMat); mConvexSEL->mSurfaceTextures.push_back(newMat);
@ -2286,7 +2286,7 @@ ConvexEditorTool::EventResult ConvexEditorCreateTool::on3DMouseDown( const Gui3D
mNewConvex->registerObject(); mNewConvex->registerObject();
mNewConvex->_setMaterial(Parent::mEditor->mMaterialName); mNewConvex->setMaterial(Parent::mEditor->mMaterialName);
mPlaneSizes.set( 0.1f, 0.1f, 0.1f ); mPlaneSizes.set( 0.1f, 0.1f, 0.1f );
mNewConvex->resizePlanes( mPlaneSizes ); mNewConvex->resizePlanes( mPlaneSizes );
@ -2510,7 +2510,7 @@ ConvexShape* ConvexEditorCreateTool::extrudeShapeFromFace( ConvexShape *inShape,
} }
//newShape->setField( "material", Parent::mEditor->mMaterialName ); //newShape->setField( "material", Parent::mEditor->mMaterialName );
newShape->_setMaterial(inShape->getMaterial()); newShape->setMaterial(inShape->getMaterial());
newShape->registerObject(); newShape->registerObject();
mEditor->updateShape( newShape ); mEditor->updateShape( newShape );

View file

@ -100,7 +100,6 @@ ProjectedShadow::ProjectedShadow( SceneObject *object )
Sim::findObject( "BL_ProjectedShadowMaterial", customMat ); Sim::findObject( "BL_ProjectedShadowMaterial", customMat );
if ( customMat ) if ( customMat )
{ {
mDecalData->mMaterial = customMat;
mDecalData->matInst = customMat->createMatInstance(); mDecalData->matInst = customMat->createMatInstance();
} }
else else

View file

@ -493,7 +493,7 @@ bool TerrainBlock::saveAsset()
{ {
StringTableEntry intMatName = terr->mFile->mMaterials[m]->getInternalName(); StringTableEntry intMatName = terr->mFile->mMaterials[m]->getInternalName();
StringTableEntry assetMatDefName = terrMatAsset->getMaterialDefinitionName(); StringTableEntry assetMatDefName = terrMatAsset->getMaterialName();
if (assetMatDefName == intMatName) if (assetMatDefName == intMatName)
{ {
mTerrainAsset->addAssetDependencyField("terrainMaterailAsset", terrMatAsset.getAssetId()); mTerrainAsset->addAssetDependencyField("terrainMaterailAsset", terrMatAsset.getAssetId());
@ -1005,7 +1005,7 @@ void TerrainBlock::addMaterial( const String &name, U32 insertAt )
for (U32 i = 0; i < foundCount; i++) for (U32 i = 0; i < foundCount; i++)
{ {
TerrainMaterialAsset* terrMatAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(aq->mAssetList[i]); TerrainMaterialAsset* terrMatAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(aq->mAssetList[i]);
if (terrMatAsset && terrMatAsset->getMaterialDefinitionName() == terrMatName) if (terrMatAsset && terrMatAsset->getMaterialName() == terrMatName)
{ {
//Do iterative logic to find the next available slot and write to it with our new mat field //Do iterative logic to find the next available slot and write to it with our new mat field
mTerrainAsset->setDataField(StringTable->insert("terrainMaterialAsset"), NULL, aq->mAssetList[i]); mTerrainAsset->setDataField(StringTable->insert("terrainMaterialAsset"), NULL, aq->mAssetList[i]);

View file

@ -190,7 +190,7 @@ TerrainMaterial* TerrainMaterial::findOrCreate( const char *nameOrPath )
TerrainMaterialAsset* terrMatAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(assetId); TerrainMaterialAsset* terrMatAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(assetId);
if (terrMatAsset) if (terrMatAsset)
{ {
mat = terrMatAsset->getMaterialDefinition(); mat = terrMatAsset->getMaterial();
if (mat) if (mat)
return mat; return mat;
} }

View file

@ -39,6 +39,13 @@ function Core_Rendering::onDestroy(%this)
function Core_Rendering::initClient(%this) function Core_Rendering::initClient(%this)
{ {
//Lets init our fallback assets
loadImageAssetFallback();
loadNamedTargetFallback();
loadMaterialAssetFallback();
loadTerrainMaterialAssetFallback();
loadShapeAssetFallback();
// Start rendering and stuff. // Start rendering and stuff.
initRenderManager(); initRenderManager();
initLightingSystems("Advanced Lighting"); initLightingSystems("Advanced Lighting");