Added support for preview scale on script templates
This commit is contained in:
parent
7622bb2032
commit
c260e547c9
|
@ -283,6 +283,14 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString&
|
||||||
pAssets->LinkEndChild(pAsset);
|
pAssets->LinkEndChild(pAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preview Scale
|
||||||
|
if (pTemp->mPreviewScale != 1.f)
|
||||||
|
{
|
||||||
|
XMLElement *pPreviewScale = scriptXML.NewElement("preview_scale");
|
||||||
|
pEditor->LinkEndChild(pPreviewScale);
|
||||||
|
pPreviewScale->SetText(pTemp->mPreviewScale);
|
||||||
|
}
|
||||||
|
|
||||||
// Rot/Scale Type
|
// Rot/Scale Type
|
||||||
XMLElement *pRotType = scriptXML.NewElement("rotation_type");
|
XMLElement *pRotType = scriptXML.NewElement("rotation_type");
|
||||||
pEditor->LinkEndChild(pRotType);
|
pEditor->LinkEndChild(pRotType);
|
||||||
|
|
|
@ -385,6 +385,17 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc
|
||||||
pAsset = pAsset->NextSiblingElement();
|
pAsset = pAsset->NextSiblingElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preview Scale
|
||||||
|
tinyxml2::XMLElement *pPreviewScale = pEditor->FirstChildElement("preview_scale");
|
||||||
|
|
||||||
|
if (pPreviewScale)
|
||||||
|
{
|
||||||
|
const char *kpScale = pPreviewScale->GetText();
|
||||||
|
|
||||||
|
if (kpScale)
|
||||||
|
pScript->mPreviewScale = std::stof(kpScale);
|
||||||
|
}
|
||||||
|
|
||||||
// Rotation
|
// Rotation
|
||||||
tinyxml2::XMLElement *pRotType = pEditor->FirstChildElement("rotation_type");
|
tinyxml2::XMLElement *pRotType = pEditor->FirstChildElement("rotation_type");
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ CScriptTemplate::CScriptTemplate(CMasterTemplate *pMaster)
|
||||||
{
|
{
|
||||||
mpMaster = pMaster;
|
mpMaster = pMaster;
|
||||||
mVisible = true;
|
mVisible = true;
|
||||||
|
mPreviewScale = 1.f;
|
||||||
mVolumeShape = eNoShape;
|
mVolumeShape = eNoShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +78,11 @@ CScriptTemplate::EScaleType CScriptTemplate::ScaleType() const
|
||||||
return mScaleType;
|
return mScaleType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float CScriptTemplate::PreviewScale() const
|
||||||
|
{
|
||||||
|
return mPreviewScale;
|
||||||
|
}
|
||||||
|
|
||||||
u32 CScriptTemplate::ObjectID() const
|
u32 CScriptTemplate::ObjectID() const
|
||||||
{
|
{
|
||||||
return mObjectID;
|
return mObjectID;
|
||||||
|
|
|
@ -62,8 +62,6 @@ private:
|
||||||
CMasterTemplate *mpMaster;
|
CMasterTemplate *mpMaster;
|
||||||
std::vector<SPropertySet> mPropertySets;
|
std::vector<SPropertySet> mPropertySets;
|
||||||
std::list<CScriptObject*> mObjectList;
|
std::list<CScriptObject*> mObjectList;
|
||||||
ERotationType mRotationType;
|
|
||||||
EScaleType mScaleType;
|
|
||||||
TString mTemplateName;
|
TString mTemplateName;
|
||||||
TString mSourceFile;
|
TString mSourceFile;
|
||||||
u32 mObjectID;
|
u32 mObjectID;
|
||||||
|
@ -78,6 +76,10 @@ private:
|
||||||
TIDString mLightParametersIDString;
|
TIDString mLightParametersIDString;
|
||||||
std::vector<SEditorAsset> mAssets;
|
std::vector<SEditorAsset> mAssets;
|
||||||
|
|
||||||
|
float mPreviewScale;
|
||||||
|
ERotationType mRotationType;
|
||||||
|
EScaleType mScaleType;
|
||||||
|
|
||||||
// Preview Volume
|
// Preview Volume
|
||||||
EVolumeShape mVolumeShape;
|
EVolumeShape mVolumeShape;
|
||||||
TIDString mVolumeConditionIDString;
|
TIDString mVolumeConditionIDString;
|
||||||
|
@ -100,6 +102,7 @@ public:
|
||||||
u32 NumPropertySets() const;
|
u32 NumPropertySets() const;
|
||||||
ERotationType RotationType() const;
|
ERotationType RotationType() const;
|
||||||
EScaleType ScaleType() const;
|
EScaleType ScaleType() const;
|
||||||
|
float PreviewScale() const;
|
||||||
u32 ObjectID() const;
|
u32 ObjectID() const;
|
||||||
void SetVisible(bool visible);
|
void SetVisible(bool visible);
|
||||||
bool IsVisible() const;
|
bool IsVisible() const;
|
||||||
|
|
|
@ -132,5 +132,5 @@ CLight* CLightNode::Light()
|
||||||
|
|
||||||
CVector2f CLightNode::BillboardScale()
|
CVector2f CLightNode::BillboardScale()
|
||||||
{
|
{
|
||||||
return mScale.xz() * 0.75f;
|
return AbsoluteScale().xz() * 0.75f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ CSceneNode::CSceneNode(CSceneManager *pScene, CSceneNode *pParent)
|
||||||
mPosition = CVector3f::skZero;
|
mPosition = CVector3f::skZero;
|
||||||
mRotation = CQuaternion::skIdentity;
|
mRotation = CQuaternion::skIdentity;
|
||||||
mScale = CVector3f::skOne;
|
mScale = CVector3f::skOne;
|
||||||
|
mScaleMultiplier = CVector3f::skOne;
|
||||||
_mTransformOutdated = true;
|
_mTransformOutdated = true;
|
||||||
|
|
||||||
_mInheritsPosition = true;
|
_mInheritsPosition = true;
|
||||||
|
@ -46,11 +47,6 @@ CSceneNode::~CSceneNode()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************ VIRTUAL ************
|
// ************ VIRTUAL ************
|
||||||
TString CSceneNode::PrefixedName() const
|
|
||||||
{
|
|
||||||
return Name();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSceneNode::DrawSelection()
|
void CSceneNode::DrawSelection()
|
||||||
{
|
{
|
||||||
// Default implementation for virtual function
|
// Default implementation for virtual function
|
||||||
|
@ -68,16 +64,19 @@ void CSceneNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewI
|
||||||
|
|
||||||
bool CSceneNode::IsVisible() const
|
bool CSceneNode::IsVisible() const
|
||||||
{
|
{
|
||||||
|
// Default implementation for virtual function
|
||||||
return mVisible;
|
return mVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
CColor CSceneNode::TintColor(const SViewInfo& ViewInfo) const
|
CColor CSceneNode::TintColor(const SViewInfo& ViewInfo) const
|
||||||
{
|
{
|
||||||
|
// Default implementation for virtual function
|
||||||
return (IsSelected() && !ViewInfo.GameMode ? skSelectionTint : CColor::skWhite);
|
return (IsSelected() && !ViewInfo.GameMode ? skSelectionTint : CColor::skWhite);
|
||||||
}
|
}
|
||||||
|
|
||||||
CColor CSceneNode::WireframeColor() const
|
CColor CSceneNode::WireframeColor() const
|
||||||
{
|
{
|
||||||
|
// Default implementation for virtual function
|
||||||
return CColor::skWhite;
|
return CColor::skWhite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +366,7 @@ CVector3f CSceneNode::LocalScale() const
|
||||||
|
|
||||||
CVector3f CSceneNode::AbsoluteScale() const
|
CVector3f CSceneNode::AbsoluteScale() const
|
||||||
{
|
{
|
||||||
CVector3f ret = mScale;
|
CVector3f ret = mScale * mScaleMultiplier;
|
||||||
|
|
||||||
if ((mpParent) && (InheritsScale()))
|
if ((mpParent) && (InheritsScale()))
|
||||||
ret *= mpParent->AbsoluteScale();
|
ret *= mpParent->AbsoluteScale();
|
||||||
|
|
|
@ -38,7 +38,9 @@ protected:
|
||||||
CVector3f mPosition;
|
CVector3f mPosition;
|
||||||
CQuaternion mRotation;
|
CQuaternion mRotation;
|
||||||
CVector3f mScale;
|
CVector3f mScale;
|
||||||
|
CVector3f mScaleMultiplier;
|
||||||
CAABox mLocalAABox;
|
CAABox mLocalAABox;
|
||||||
|
|
||||||
bool mMouseHovering;
|
bool mMouseHovering;
|
||||||
bool mSelected;
|
bool mSelected;
|
||||||
bool mVisible;
|
bool mVisible;
|
||||||
|
@ -53,7 +55,6 @@ public:
|
||||||
explicit CSceneNode(CSceneManager *pScene, CSceneNode *pParent = 0);
|
explicit CSceneNode(CSceneManager *pScene, CSceneNode *pParent = 0);
|
||||||
virtual ~CSceneNode();
|
virtual ~CSceneNode();
|
||||||
virtual ENodeType NodeType() = 0;
|
virtual ENodeType NodeType() = 0;
|
||||||
virtual TString PrefixedName() const;
|
|
||||||
virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*ViewInfo*/) {}
|
virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*ViewInfo*/) {}
|
||||||
virtual void DrawSelection();
|
virtual void DrawSelection();
|
||||||
virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
|
virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
|
||||||
|
|
|
@ -32,7 +32,10 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje
|
||||||
SetName("[" + pTemp->TemplateName(mpInstance->NumProperties()) + "] " + mpInstance->InstanceName());
|
SetName("[" + pTemp->TemplateName(mpInstance->NumProperties()) + "] " + mpInstance->InstanceName());
|
||||||
|
|
||||||
if (pTemp->ScaleType() == CScriptTemplate::eScaleEnabled)
|
if (pTemp->ScaleType() == CScriptTemplate::eScaleEnabled)
|
||||||
|
{
|
||||||
mScale = mpInstance->Scale();
|
mScale = mpInstance->Scale();
|
||||||
|
mScaleMultiplier = mpInstance->Template()->PreviewScale();
|
||||||
|
}
|
||||||
|
|
||||||
MarkTransformChanged();
|
MarkTransformChanged();
|
||||||
|
|
||||||
|
@ -99,11 +102,6 @@ ENodeType CScriptNode::NodeType()
|
||||||
return eScriptNode;
|
return eScriptNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
TString CScriptNode::PrefixedName() const
|
|
||||||
{
|
|
||||||
return "[" + mpInstance->Template()->TemplateName() + "] " + mpInstance->InstanceName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||||
{
|
{
|
||||||
if (!mpInstance) return;
|
if (!mpInstance) return;
|
||||||
|
@ -474,6 +472,6 @@ CAABox CScriptNode::PreviewVolumeAABox()
|
||||||
|
|
||||||
CVector2f CScriptNode::BillboardScale()
|
CVector2f CScriptNode::BillboardScale()
|
||||||
{
|
{
|
||||||
CVector2f out = (mpInstance->Template()->ScaleType() == CScriptTemplate::eScaleEnabled ? mScale.xz() : CVector2f(1.f));
|
CVector2f out = (mpInstance->Template()->ScaleType() == CScriptTemplate::eScaleEnabled ? AbsoluteScale().xz() : CVector2f(1.f));
|
||||||
return out * 0.5f;
|
return out * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ class CScriptNode : public CSceneNode
|
||||||
public:
|
public:
|
||||||
CScriptNode(CSceneManager *pScene, CSceneNode *pParent = 0, CScriptObject *pObject = 0);
|
CScriptNode(CSceneManager *pScene, CSceneNode *pParent = 0, CScriptObject *pObject = 0);
|
||||||
ENodeType NodeType();
|
ENodeType NodeType();
|
||||||
TString PrefixedName() const;
|
|
||||||
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
|
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
|
||||||
void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo);
|
void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo);
|
||||||
void DrawSelection();
|
void DrawSelection();
|
||||||
|
|
|
@ -180,7 +180,7 @@ void CWorldEditor::UpdateGizmoUI()
|
||||||
if (mGizmoTransforming && mGizmo.HasTransformed())
|
if (mGizmoTransforming && mGizmo.HasTransformed())
|
||||||
spinBoxValue = mGizmo.TotalScale();
|
spinBoxValue = mGizmo.TotalScale();
|
||||||
else if (!mSelection.empty())
|
else if (!mSelection.empty())
|
||||||
spinBoxValue = mSelection.front()->AbsoluteScale();
|
spinBoxValue = mSelection.front()->LocalScale();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,6 +308,7 @@ void CWorldEditor::OnTransformSpinBoxModified(CVector3f value)
|
||||||
|
|
||||||
switch (mGizmo.Mode())
|
switch (mGizmo.Mode())
|
||||||
{
|
{
|
||||||
|
// Use absolute position/rotation, but relative scale. (This way spinbox doesn't show preview multiplier)
|
||||||
case CGizmo::eTranslate:
|
case CGizmo::eTranslate:
|
||||||
{
|
{
|
||||||
CVector3f delta = value - mSelection.front()->AbsolutePosition();
|
CVector3f delta = value - mSelection.front()->AbsolutePosition();
|
||||||
|
@ -324,7 +325,7 @@ void CWorldEditor::OnTransformSpinBoxModified(CVector3f value)
|
||||||
|
|
||||||
case CGizmo::eScale:
|
case CGizmo::eScale:
|
||||||
{
|
{
|
||||||
CVector3f delta = value / mSelection.front()->AbsoluteScale();
|
CVector3f delta = value / mSelection.front()->LocalScale();
|
||||||
mUndoStack.push(new CScaleNodeCommand(this, mSelection, CVector3f::skZero, delta));
|
mUndoStack.push(new CScaleNodeCommand(this, mSelection, CVector3f::skZero, delta));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue