mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-16 00:17:14 +00:00
Added support for attaching assets from properties to locator bones in the World Editor
This commit is contained in:
@@ -9,8 +9,6 @@ CScriptObject::CScriptObject(u32 InstanceID, CGameArea *pArea, CScriptLayer *pLa
|
||||
, mpLayer(pLayer)
|
||||
, mVersion(0)
|
||||
, mInstanceID(InstanceID)
|
||||
, mpDisplayModel(nullptr)
|
||||
, mpCollision(nullptr)
|
||||
, mHasInGameModel(false)
|
||||
, mIsCheckingNearVisibleActivation(false)
|
||||
{
|
||||
@@ -37,21 +35,14 @@ CScriptObject::~CScriptObject()
|
||||
mpScale = mpTemplate->FindScale(mpProperties);
|
||||
mpActive = mpTemplate->FindActive(mpProperties);
|
||||
mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
|
||||
mHasInGameModel = mpTemplate->HasInGameModel(mpProperties);
|
||||
EvaluateDisplayModel();
|
||||
EvaluateBillboard();
|
||||
EvaluateDisplayAsset();
|
||||
EvaluateCollisionModel();
|
||||
EvaluateVolume();
|
||||
}
|
||||
|
||||
void CScriptObject::EvaluateDisplayModel()
|
||||
void CScriptObject::EvaluateDisplayAsset()
|
||||
{
|
||||
mpDisplayModel = mpTemplate->FindDisplayModel(mpProperties);
|
||||
}
|
||||
|
||||
void CScriptObject::EvaluateBillboard()
|
||||
{
|
||||
mpBillboard = mpTemplate->FindBillboardTexture(mpProperties);
|
||||
mpDisplayAsset = mpTemplate->FindDisplayAsset(mpProperties, mActiveCharIndex, mActiveAnimIndex, mHasInGameModel);
|
||||
}
|
||||
|
||||
void CScriptObject::EvaluateCollisionModel()
|
||||
|
||||
@@ -38,9 +38,10 @@ class CScriptObject
|
||||
TVector3Property *mpScale;
|
||||
TBoolProperty *mpActive;
|
||||
CPropertyStruct *mpLightParameters;
|
||||
TResPtr<CModel> mpDisplayModel;
|
||||
TResPtr<CTexture> mpBillboard;
|
||||
TResPtr<CResource> mpDisplayAsset;
|
||||
TResPtr<CCollisionMeshGroup> mpCollision;
|
||||
u32 mActiveCharIndex;
|
||||
u32 mActiveAnimIndex;
|
||||
bool mHasInGameModel;
|
||||
|
||||
EVolumeShape mVolumeShape;
|
||||
@@ -54,8 +55,7 @@ public:
|
||||
~CScriptObject();
|
||||
|
||||
void EvaluateProperties();
|
||||
void EvaluateDisplayModel();
|
||||
void EvaluateBillboard();
|
||||
void EvaluateDisplayAsset();
|
||||
void EvaluateCollisionModel();
|
||||
void EvaluateVolume();
|
||||
bool IsEditorProperty(IProperty *pProp);
|
||||
@@ -89,8 +89,9 @@ public:
|
||||
bool IsActive() const { return mpActive ? mpActive->Get() : false; }
|
||||
bool HasInGameModel() const { return mHasInGameModel; }
|
||||
CPropertyStruct* LightParameters() const { return mpLightParameters; }
|
||||
CModel* DisplayModel() const { return mpDisplayModel; }
|
||||
CTexture* Billboard() const { return mpBillboard; }
|
||||
CResource* DisplayAsset() const { return mpDisplayAsset; }
|
||||
u32 ActiveCharIndex() const { return mActiveCharIndex; }
|
||||
u32 ActiveAnimIndex() const { return mActiveAnimIndex; }
|
||||
CCollisionMeshGroup* Collision() const { return mpCollision; }
|
||||
EVolumeShape VolumeShape() const { return mVolumeShape; }
|
||||
float VolumeScale() const { return mVolumeScale; }
|
||||
|
||||
@@ -152,12 +152,14 @@ CPropertyStruct* CScriptTemplate::FindLightParameters(CPropertyStruct *pProperti
|
||||
return TFetchProperty<CPropertyStruct*, eStructProperty>(pProperties, mLightParametersIDString);
|
||||
}
|
||||
|
||||
// todo: merge these four functions, they have near-identical code
|
||||
CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties)
|
||||
CResource* CScriptTemplate::FindDisplayAsset(CPropertyStruct *pProperties, u32& rOutCharIndex, u32& rOutAnimIndex, bool& rOutIsInGame)
|
||||
{
|
||||
rOutCharIndex = -1;
|
||||
rOutAnimIndex = -1;
|
||||
rOutIsInGame = false;
|
||||
|
||||
for (auto it = mAssets.begin(); it != mAssets.end(); it++)
|
||||
{
|
||||
if ((it->AssetType != SEditorAsset::eModel) && (it->AssetType != SEditorAsset::eAnimParams)) continue;
|
||||
CResource *pRes = nullptr;
|
||||
|
||||
// File
|
||||
@@ -172,58 +174,34 @@ CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties)
|
||||
{
|
||||
IProperty *pProp = pProperties->PropertyByIDString(it->AssetLocation);
|
||||
|
||||
if (pProp->Type() == eFileProperty)
|
||||
if (it->AssetType == SEditorAsset::eAnimParams && pProp->Type() == eCharacterProperty)
|
||||
{
|
||||
TFileProperty *pFile = static_cast<TFileProperty*>(pProp);
|
||||
pRes = pFile->Get().Load();
|
||||
TCharacterProperty *pChar = static_cast<TCharacterProperty*>(pProp);
|
||||
pRes = pChar->Get().AnimSet();
|
||||
|
||||
if (pRes)
|
||||
{
|
||||
rOutCharIndex = (it->ForceNodeIndex >= 0 ? it->ForceNodeIndex : pChar->Get().CharacterIndex());
|
||||
rOutAnimIndex = pChar->Get().AnimIndex();
|
||||
}
|
||||
}
|
||||
|
||||
else if (pProp->Type() == eCharacterProperty)
|
||||
{
|
||||
TCharacterProperty *pParams = static_cast<TCharacterProperty*>(pProp);
|
||||
pRes = pParams->Get().GetCurrentModel(it->ForceNodeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Verify resource exists + is correct type
|
||||
if (pRes && (pRes->Type() == eModel))
|
||||
return static_cast<CModel*>(pRes);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CTexture* CScriptTemplate::FindBillboardTexture(CPropertyStruct *pProperties)
|
||||
{
|
||||
for (auto it = mAssets.begin(); it != mAssets.end(); it++)
|
||||
{
|
||||
if (it->AssetType != SEditorAsset::eBillboard) continue;
|
||||
CResource *pRes = nullptr;
|
||||
|
||||
// File
|
||||
if (it->AssetSource == SEditorAsset::eFile)
|
||||
{
|
||||
TString path = "../resources/" + it->AssetLocation;
|
||||
pRes = gResCache.GetResource(path);
|
||||
}
|
||||
|
||||
// Property
|
||||
else
|
||||
{
|
||||
IProperty *pProp = pProperties->PropertyByIDString(it->AssetLocation);
|
||||
|
||||
if (pProp->Type() == eFileProperty)
|
||||
else
|
||||
{
|
||||
TFileProperty *pFile = static_cast<TFileProperty*>(pProp);
|
||||
pRes = pFile->Get().Load();
|
||||
}
|
||||
}
|
||||
|
||||
// Verify resource exists + is correct type
|
||||
if (pRes && (pRes->Type() == eTexture))
|
||||
return static_cast<CTexture*>(pRes);
|
||||
// If we have a valid resource, return
|
||||
if (pRes)
|
||||
{
|
||||
rOutIsInGame = (pRes->Type() != eTexture && it->AssetSource == SEditorAsset::eProperty);
|
||||
return pRes;
|
||||
}
|
||||
}
|
||||
|
||||
// None are valid - no display asset
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -261,35 +239,6 @@ CCollisionMeshGroup* CScriptTemplate::FindCollision(CPropertyStruct *pProperties
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CScriptTemplate::HasInGameModel(CPropertyStruct *pProperties)
|
||||
{
|
||||
for (auto it = mAssets.begin(); it != mAssets.end(); it++)
|
||||
{
|
||||
if ((it->AssetType != SEditorAsset::eModel) && (it->AssetType != SEditorAsset::eAnimParams)) continue;
|
||||
if (it->AssetSource == SEditorAsset::eFile) continue;
|
||||
CResource *pRes = nullptr;
|
||||
|
||||
IProperty *pProp = pProperties->PropertyByIDString(it->AssetLocation);
|
||||
|
||||
if (pProp->Type() == eFileProperty)
|
||||
{
|
||||
TFileProperty *pFile = static_cast<TFileProperty*>(pProp);
|
||||
pRes = pFile->Get().Load();
|
||||
}
|
||||
|
||||
else if (pProp->Type() == eCharacterProperty)
|
||||
{
|
||||
TCharacterProperty *pParams = static_cast<TCharacterProperty*>(pProp);
|
||||
pRes = pParams->Get().GetCurrentModel(it->ForceNodeIndex);
|
||||
}
|
||||
|
||||
// Verify resource exists + is correct type
|
||||
if (pRes && (pRes->Type() == eModel))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ************ OBJECT TRACKING ************
|
||||
u32 CScriptTemplate::NumObjects() const
|
||||
|
||||
@@ -16,6 +16,12 @@ class CScriptObject;
|
||||
|
||||
typedef TString TIDString;
|
||||
|
||||
struct SAttachment
|
||||
{
|
||||
TIDString AttachProperty; // Must point to a CMDL!
|
||||
TString LocatorName;
|
||||
};
|
||||
|
||||
/*
|
||||
* CScriptTemplate is a class that encases the data contained in one of the XML templates.
|
||||
* It essentially sets the layout of any given script object.
|
||||
@@ -68,6 +74,7 @@ private:
|
||||
TIDString mActiveIDString;
|
||||
TIDString mLightParametersIDString;
|
||||
std::vector<SEditorAsset> mAssets;
|
||||
std::vector<SAttachment> mAttachments;
|
||||
|
||||
ERotationType mRotationType;
|
||||
EScaleType mScaleType;
|
||||
@@ -99,10 +106,8 @@ public:
|
||||
TVector3Property* FindScale(CPropertyStruct *pProperties);
|
||||
TBoolProperty* FindActive(CPropertyStruct *pProperties);
|
||||
CPropertyStruct* FindLightParameters(CPropertyStruct *pProperties);
|
||||
CModel* FindDisplayModel(CPropertyStruct *pProperties);
|
||||
CTexture* FindBillboardTexture(CPropertyStruct *pProperties);
|
||||
CResource* FindDisplayAsset(CPropertyStruct *pProperties, u32& rOutCharIndex, u32& rOutAnimIndex, bool& rOutIsInGame);
|
||||
CCollisionMeshGroup* FindCollision(CPropertyStruct *pProperties);
|
||||
bool HasInGameModel(CPropertyStruct *pProperties);
|
||||
|
||||
// Accessors
|
||||
inline CMasterTemplate* MasterTemplate() const { return mpMaster; }
|
||||
@@ -114,6 +119,8 @@ public:
|
||||
inline bool IsVisible() const { return mVisible; }
|
||||
inline TString SourceFile() const { return mSourceFile; }
|
||||
inline CStructTemplate* BaseStruct() const { return mpBaseStruct; }
|
||||
inline u32 NumAttachments() const { return mAttachments.size(); }
|
||||
const SAttachment& Attachment(u32 Index) const { return mAttachments[Index]; }
|
||||
|
||||
inline bool HasName() const { return !mNameIDString.IsEmpty(); }
|
||||
inline bool HasPosition() const { return !mPositionIDString.IsEmpty(); }
|
||||
|
||||
Reference in New Issue
Block a user