Getting rid of CylinderLarge, replacing with preview volume scaling support
This commit is contained in:
parent
2a38fb5b09
commit
6e3deb836c
Binary file not shown.
|
@ -319,6 +319,11 @@ public:
|
||||||
memcpy(pOut + 8, &part2, 8);
|
memcpy(pOut + 8, &part2, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float ToFloat() const
|
||||||
|
{
|
||||||
|
return std::stof(mInternalString, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
inline _TStdString ToStdString() const
|
inline _TStdString ToStdString() const
|
||||||
{
|
{
|
||||||
return mInternalString;
|
return mInternalString;
|
||||||
|
|
|
@ -320,7 +320,6 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString&
|
||||||
case eAxisAlignedBoxShape: return "AxisAlignedBox";
|
case eAxisAlignedBoxShape: return "AxisAlignedBox";
|
||||||
case eEllipsoidShape: return "Ellipsoid";
|
case eEllipsoidShape: return "Ellipsoid";
|
||||||
case eCylinderShape: return "Cylinder";
|
case eCylinderShape: return "Cylinder";
|
||||||
case eCylinderLargeShape: return "CylinderLarge";
|
|
||||||
case eConditionalShape: return "Conditional";
|
case eConditionalShape: return "Conditional";
|
||||||
default: return "INVALID";
|
default: return "INVALID";
|
||||||
}
|
}
|
||||||
|
@ -328,6 +327,9 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString&
|
||||||
|
|
||||||
pVolume->SetAttribute("shape", *GetVolumeString(pTemp->mVolumeShape));
|
pVolume->SetAttribute("shape", *GetVolumeString(pTemp->mVolumeShape));
|
||||||
|
|
||||||
|
if (pTemp->mVolumeScale != 1.f)
|
||||||
|
pVolume->SetAttribute("scale", pTemp->mVolumeScale);
|
||||||
|
|
||||||
if (pTemp->mVolumeShape == eConditionalShape)
|
if (pTemp->mVolumeShape == eConditionalShape)
|
||||||
{
|
{
|
||||||
pVolume->SetAttribute("propertyID", *pTemp->mVolumeConditionIDString);
|
pVolume->SetAttribute("propertyID", *pTemp->mVolumeConditionIDString);
|
||||||
|
@ -355,6 +357,7 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString&
|
||||||
XMLElement *pCondition = scriptXML.NewElement("condition");
|
XMLElement *pCondition = scriptXML.NewElement("condition");
|
||||||
pCondition->SetAttribute("value", *strVal);
|
pCondition->SetAttribute("value", *strVal);
|
||||||
pCondition->SetAttribute("shape", *GetVolumeString(it->Shape));
|
pCondition->SetAttribute("shape", *GetVolumeString(it->Shape));
|
||||||
|
if (it->Scale != 1.f) pCondition->SetAttribute("scale", it->Scale);
|
||||||
pVolume->LinkEndChild(pCondition);
|
pVolume->LinkEndChild(pCondition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,7 +437,6 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc
|
||||||
if (strcmp(kpType, "AxisAlignedBox") == 0) return eAxisAlignedBoxShape;
|
if (strcmp(kpType, "AxisAlignedBox") == 0) return eAxisAlignedBoxShape;
|
||||||
if (strcmp(kpType, "Ellipsoid") == 0) return eEllipsoidShape;
|
if (strcmp(kpType, "Ellipsoid") == 0) return eEllipsoidShape;
|
||||||
if (strcmp(kpType, "Cylinder") == 0) return eCylinderShape;
|
if (strcmp(kpType, "Cylinder") == 0) return eCylinderShape;
|
||||||
if (strcmp(kpType, "CylinderLarge") == 0) return eCylinderLargeShape;
|
|
||||||
if (strcmp(kpType, "Conditional") == 0) return eConditionalShape;
|
if (strcmp(kpType, "Conditional") == 0) return eConditionalShape;
|
||||||
return eInvalidShape;
|
return eInvalidShape;
|
||||||
};
|
};
|
||||||
|
@ -447,6 +446,11 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc
|
||||||
if (kpShape)
|
if (kpShape)
|
||||||
pScript->mVolumeShape = GetVolumeType(kpShape);
|
pScript->mVolumeShape = GetVolumeType(kpShape);
|
||||||
|
|
||||||
|
const char *kpScale = pVolume->Attribute("scale");
|
||||||
|
|
||||||
|
if (kpScale)
|
||||||
|
pScript->mVolumeScale = TString(kpScale).ToFloat();
|
||||||
|
|
||||||
// Conditional
|
// Conditional
|
||||||
if (pScript->mVolumeShape == eConditionalShape)
|
if (pScript->mVolumeShape == eConditionalShape)
|
||||||
{
|
{
|
||||||
|
@ -474,6 +478,12 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc
|
||||||
else
|
else
|
||||||
condition.Value = TString(kpConditionValue).ToInt32();
|
condition.Value = TString(kpConditionValue).ToInt32();
|
||||||
|
|
||||||
|
const char *kpConditionScale = pCondition->Attribute("scale");
|
||||||
|
if (kpConditionScale)
|
||||||
|
condition.Scale = TString(kpConditionScale).ToFloat();
|
||||||
|
else
|
||||||
|
condition.Scale = 1.f;
|
||||||
|
|
||||||
pScript->mVolumeConditions.push_back(condition);
|
pScript->mVolumeConditions.push_back(condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ void CScriptObject::EvaluateProperties()
|
||||||
mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
|
mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
|
||||||
mHasInGameModel = mpTemplate->HasInGameModel(mpProperties);
|
mHasInGameModel = mpTemplate->HasInGameModel(mpProperties);
|
||||||
mVolumeShape = mpTemplate->VolumeShape(this);
|
mVolumeShape = mpTemplate->VolumeShape(this);
|
||||||
|
mVolumeScale = mpTemplate->VolumeScale(this);
|
||||||
EvaluateDisplayModel();
|
EvaluateDisplayModel();
|
||||||
EvaluateBillboard();
|
EvaluateBillboard();
|
||||||
EvaluateCollisionModel();
|
EvaluateCollisionModel();
|
||||||
|
@ -224,3 +225,8 @@ EVolumeShape CScriptObject::VolumeShape() const
|
||||||
{
|
{
|
||||||
return mVolumeShape;
|
return mVolumeShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float CScriptObject::VolumeScale() const
|
||||||
|
{
|
||||||
|
return mVolumeScale;
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ class CScriptObject
|
||||||
bool mHasInGameModel;
|
bool mHasInGameModel;
|
||||||
|
|
||||||
EVolumeShape mVolumeShape;
|
EVolumeShape mVolumeShape;
|
||||||
|
float mVolumeScale;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate);
|
CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate);
|
||||||
|
@ -79,6 +80,7 @@ public:
|
||||||
CTexture* GetBillboard() const;
|
CTexture* GetBillboard() const;
|
||||||
CCollisionMeshGroup* GetCollision() const;
|
CCollisionMeshGroup* GetCollision() const;
|
||||||
EVolumeShape VolumeShape() const;
|
EVolumeShape VolumeShape() const;
|
||||||
|
float VolumeScale() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CSCRIPTOBJECT_H
|
#endif // CSCRIPTOBJECT_H
|
||||||
|
|
|
@ -13,6 +13,7 @@ CScriptTemplate::CScriptTemplate(CMasterTemplate *pMaster)
|
||||||
mpMaster = pMaster;
|
mpMaster = pMaster;
|
||||||
mVisible = true;
|
mVisible = true;
|
||||||
mPreviewScale = 1.f;
|
mPreviewScale = 1.f;
|
||||||
|
mVolumeScale = 1.f;
|
||||||
mVolumeShape = eNoShape;
|
mVolumeShape = eNoShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +146,35 @@ EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
|
||||||
return eInvalidShape;
|
return eInvalidShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mVolumeShape == eConditionalShape)
|
||||||
|
{
|
||||||
|
s32 index = CheckVolumeConditions(pObj, true);
|
||||||
|
if (index == -1) return eInvalidShape;
|
||||||
|
else return mVolumeConditions[index].Shape;
|
||||||
|
}
|
||||||
|
else return mVolumeShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
float CScriptTemplate::VolumeScale(CScriptObject *pObj)
|
||||||
|
{
|
||||||
|
if (pObj->Template() != this)
|
||||||
|
{
|
||||||
|
Log::Error(pObj->Template()->TemplateName() + " instance somehow called VolumeScale() on " + TemplateName() + " template");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mVolumeShape == eConditionalShape)
|
||||||
|
{
|
||||||
|
s32 index = CheckVolumeConditions(pObj, false);
|
||||||
|
if (index == -1) return mVolumeScale;
|
||||||
|
else return mVolumeConditions[index].Scale;
|
||||||
|
}
|
||||||
|
else return mVolumeScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
s32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors)
|
||||||
|
{
|
||||||
|
// Private function
|
||||||
if (mVolumeShape == eConditionalShape)
|
if (mVolumeShape == eConditionalShape)
|
||||||
{
|
{
|
||||||
CPropertyBase *pProp = pObj->Properties()->PropertyByIDString(mVolumeConditionIDString);
|
CPropertyBase *pProp = pObj->Properties()->PropertyByIDString(mVolumeConditionIDString);
|
||||||
|
@ -179,17 +209,17 @@ EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test and check whether any of the conditions are true
|
// Test and check whether any of the conditions are true
|
||||||
for (auto it = mVolumeConditions.begin(); it != mVolumeConditions.end(); it++)
|
for (u32 iCon = 0; iCon < mVolumeConditions.size(); iCon++)
|
||||||
{
|
{
|
||||||
if (it->Value == v)
|
if (mVolumeConditions[iCon].Value == v)
|
||||||
return it->Shape;
|
return iCon;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::Error(TemplateName() + " instance " + TString::HexString(pObj->InstanceID(), true, true, 8) + " has unexpected volume shape value of " + TString::HexString((u32) v, true, true));
|
if (LogErrors)
|
||||||
return eInvalidShape;
|
Log::Error(pObj->Template()->TemplateName() + " instance " + TString::HexString(pObj->InstanceID(), true, true, 8) + " has unexpected volume shape value of " + TString::HexString((u32) v, true, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
else return mVolumeShape;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CStringProperty* CScriptTemplate::FindInstanceName(CPropertyStruct *pProperties)
|
CStringProperty* CScriptTemplate::FindInstanceName(CPropertyStruct *pProperties)
|
||||||
|
|
|
@ -81,11 +81,13 @@ private:
|
||||||
|
|
||||||
// Preview Volume
|
// Preview Volume
|
||||||
EVolumeShape mVolumeShape;
|
EVolumeShape mVolumeShape;
|
||||||
|
float mVolumeScale;
|
||||||
TIDString mVolumeConditionIDString;
|
TIDString mVolumeConditionIDString;
|
||||||
|
|
||||||
struct SVolumeCondition {
|
struct SVolumeCondition {
|
||||||
int Value;
|
int Value;
|
||||||
EVolumeShape Shape;
|
EVolumeShape Shape;
|
||||||
|
float Scale;
|
||||||
};
|
};
|
||||||
std::vector<SVolumeCondition> mVolumeConditions;
|
std::vector<SVolumeCondition> mVolumeConditions;
|
||||||
|
|
||||||
|
@ -111,6 +113,7 @@ public:
|
||||||
CStructTemplate* BaseStructByCount(s32 propCount);
|
CStructTemplate* BaseStructByCount(s32 propCount);
|
||||||
CStructTemplate* BaseStructByIndex(u32 index);
|
CStructTemplate* BaseStructByIndex(u32 index);
|
||||||
EVolumeShape VolumeShape(CScriptObject *pObj);
|
EVolumeShape VolumeShape(CScriptObject *pObj);
|
||||||
|
float VolumeScale(CScriptObject *pObj);
|
||||||
CStringProperty* FindInstanceName(CPropertyStruct *pProperties);
|
CStringProperty* FindInstanceName(CPropertyStruct *pProperties);
|
||||||
CVector3Property* FindPosition(CPropertyStruct *pProperties);
|
CVector3Property* FindPosition(CPropertyStruct *pProperties);
|
||||||
CVector3Property* FindRotation(CPropertyStruct *pProperties);
|
CVector3Property* FindRotation(CPropertyStruct *pProperties);
|
||||||
|
@ -129,6 +132,9 @@ public:
|
||||||
void AddObject(CScriptObject *pObject);
|
void AddObject(CScriptObject *pObject);
|
||||||
void RemoveObject(CScriptObject *pObject);
|
void RemoveObject(CScriptObject *pObject);
|
||||||
void SortObjects();
|
void SortObjects();
|
||||||
|
|
||||||
|
private:
|
||||||
|
s32 CheckVolumeConditions(CScriptObject *pObj, bool LogErrors);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CSCRIPTTEMPLATE_H
|
#endif // CSCRIPTTEMPLATE_H
|
||||||
|
|
|
@ -8,7 +8,6 @@ enum EVolumeShape
|
||||||
eBoxShape,
|
eBoxShape,
|
||||||
eEllipsoidShape,
|
eEllipsoidShape,
|
||||||
eCylinderShape,
|
eCylinderShape,
|
||||||
eCylinderLargeShape,
|
|
||||||
eConditionalShape,
|
eConditionalShape,
|
||||||
eInvalidShape
|
eInvalidShape
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,6 +14,7 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje
|
||||||
: CSceneNode(pScene, pParent)
|
: CSceneNode(pScene, pParent)
|
||||||
{
|
{
|
||||||
mpVolumePreviewNode = nullptr;
|
mpVolumePreviewNode = nullptr;
|
||||||
|
mHasVolumePreview = false;
|
||||||
|
|
||||||
// Evaluate instance
|
// Evaluate instance
|
||||||
mpInstance = pObject;
|
mpInstance = pObject;
|
||||||
|
@ -42,29 +43,35 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje
|
||||||
|
|
||||||
// Create preview volume node
|
// Create preview volume node
|
||||||
mHasValidPosition = pTemp->HasPosition();
|
mHasValidPosition = pTemp->HasPosition();
|
||||||
mHasVolumePreview = (pTemp->ScaleType() == CScriptTemplate::eScaleVolume);
|
|
||||||
|
|
||||||
if (mHasVolumePreview)
|
if (pTemp->ScaleType() == CScriptTemplate::eScaleVolume)
|
||||||
{
|
{
|
||||||
EVolumeShape shape = mpInstance->VolumeShape();
|
EVolumeShape shape = mpInstance->VolumeShape();
|
||||||
TResPtr<CModel> pVolumeModel = nullptr;
|
TResPtr<CModel> pVolumeModel = nullptr;
|
||||||
|
|
||||||
if ((shape == eAxisAlignedBoxShape) || (shape == eBoxShape))
|
switch (shape)
|
||||||
|
{
|
||||||
|
case eAxisAlignedBoxShape:
|
||||||
|
case eBoxShape:
|
||||||
pVolumeModel = gResCache.GetResource("../resources/VolumeBox.cmdl");
|
pVolumeModel = gResCache.GetResource("../resources/VolumeBox.cmdl");
|
||||||
|
break;
|
||||||
|
|
||||||
else if (shape == eEllipsoidShape)
|
case eEllipsoidShape:
|
||||||
pVolumeModel = gResCache.GetResource("../resources/VolumeSphere.cmdl");
|
pVolumeModel = gResCache.GetResource("../resources/VolumeSphere.cmdl");
|
||||||
|
break;
|
||||||
|
|
||||||
else if (shape == eCylinderShape)
|
case eCylinderShape:
|
||||||
pVolumeModel = gResCache.GetResource("../resources/VolumeCylinder.cmdl");
|
pVolumeModel = gResCache.GetResource("../resources/VolumeCylinder.cmdl");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
else if (shape == eCylinderLargeShape)
|
mHasVolumePreview = (pVolumeModel != nullptr);
|
||||||
pVolumeModel = gResCache.GetResource("../resources/VolumeCylinderLarge.cmdl");
|
|
||||||
|
|
||||||
if (pVolumeModel)
|
if (mHasVolumePreview)
|
||||||
{
|
{
|
||||||
mpVolumePreviewNode = new CModelNode(pScene, this, pVolumeModel);
|
mpVolumePreviewNode = new CModelNode(pScene, this, pVolumeModel);
|
||||||
mpVolumePreviewNode->SetInheritance(true, (shape != eAxisAlignedBoxShape), true);
|
mpVolumePreviewNode->SetInheritance(true, (shape != eAxisAlignedBoxShape), true);
|
||||||
|
mpVolumePreviewNode->SetScale(mpInstance->VolumeScale());
|
||||||
mpVolumePreviewNode->ForceAlphaEnabled(true);
|
mpVolumePreviewNode->ForceAlphaEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@
|
||||||
<scale_type>volume</scale_type>
|
<scale_type>volume</scale_type>
|
||||||
<preview_volume shape="Conditional" propertyID="0xD5869B0B">
|
<preview_volume shape="Conditional" propertyID="0xD5869B0B">
|
||||||
<condition value="0x00" shape="Ellipsoid"/>
|
<condition value="0x00" shape="Ellipsoid"/>
|
||||||
<condition value="0x01" shape="CylinderLarge"/>
|
<condition value="0x01" shape="Cylinder" scale="2"/>
|
||||||
</preview_volume>
|
</preview_volume>
|
||||||
</editor>
|
</editor>
|
||||||
</ScriptTemplate>
|
</ScriptTemplate>
|
||||||
|
|
Loading…
Reference in New Issue