From c260e547c9082c46b8ffc446e39bf8cf49e07b85 Mon Sep 17 00:00:00 2001 From: parax0 Date: Sun, 29 Nov 2015 04:28:10 -0700 Subject: [PATCH] Added support for preview scale on script templates --- Resource/cooker/CTemplateWriter.cpp | 8 ++++++++ Resource/factory/CTemplateLoader.cpp | 11 +++++++++++ Resource/script/CScriptTemplate.cpp | 6 ++++++ Resource/script/CScriptTemplate.h | 7 +++++-- Scene/CLightNode.cpp | 2 +- Scene/CSceneNode.cpp | 11 +++++------ Scene/CSceneNode.h | 3 ++- Scene/CScriptNode.cpp | 10 ++++------ Scene/CScriptNode.h | 1 - UI/CWorldEditor.cpp | 5 +++-- 10 files changed, 45 insertions(+), 19 deletions(-) diff --git a/Resource/cooker/CTemplateWriter.cpp b/Resource/cooker/CTemplateWriter.cpp index 0a8a0c7a..974f394d 100644 --- a/Resource/cooker/CTemplateWriter.cpp +++ b/Resource/cooker/CTemplateWriter.cpp @@ -283,6 +283,14 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString& 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 XMLElement *pRotType = scriptXML.NewElement("rotation_type"); pEditor->LinkEndChild(pRotType); diff --git a/Resource/factory/CTemplateLoader.cpp b/Resource/factory/CTemplateLoader.cpp index 00f8f31c..6ee962cb 100644 --- a/Resource/factory/CTemplateLoader.cpp +++ b/Resource/factory/CTemplateLoader.cpp @@ -385,6 +385,17 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc 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 tinyxml2::XMLElement *pRotType = pEditor->FirstChildElement("rotation_type"); diff --git a/Resource/script/CScriptTemplate.cpp b/Resource/script/CScriptTemplate.cpp index 74271cc5..296f5a73 100644 --- a/Resource/script/CScriptTemplate.cpp +++ b/Resource/script/CScriptTemplate.cpp @@ -11,6 +11,7 @@ CScriptTemplate::CScriptTemplate(CMasterTemplate *pMaster) { mpMaster = pMaster; mVisible = true; + mPreviewScale = 1.f; mVolumeShape = eNoShape; } @@ -77,6 +78,11 @@ CScriptTemplate::EScaleType CScriptTemplate::ScaleType() const return mScaleType; } +float CScriptTemplate::PreviewScale() const +{ + return mPreviewScale; +} + u32 CScriptTemplate::ObjectID() const { return mObjectID; diff --git a/Resource/script/CScriptTemplate.h b/Resource/script/CScriptTemplate.h index 8ab65dc6..a7851ef0 100644 --- a/Resource/script/CScriptTemplate.h +++ b/Resource/script/CScriptTemplate.h @@ -62,8 +62,6 @@ private: CMasterTemplate *mpMaster; std::vector mPropertySets; std::list mObjectList; - ERotationType mRotationType; - EScaleType mScaleType; TString mTemplateName; TString mSourceFile; u32 mObjectID; @@ -78,6 +76,10 @@ private: TIDString mLightParametersIDString; std::vector mAssets; + float mPreviewScale; + ERotationType mRotationType; + EScaleType mScaleType; + // Preview Volume EVolumeShape mVolumeShape; TIDString mVolumeConditionIDString; @@ -100,6 +102,7 @@ public: u32 NumPropertySets() const; ERotationType RotationType() const; EScaleType ScaleType() const; + float PreviewScale() const; u32 ObjectID() const; void SetVisible(bool visible); bool IsVisible() const; diff --git a/Scene/CLightNode.cpp b/Scene/CLightNode.cpp index 225cca5b..cff8dfc3 100644 --- a/Scene/CLightNode.cpp +++ b/Scene/CLightNode.cpp @@ -132,5 +132,5 @@ CLight* CLightNode::Light() CVector2f CLightNode::BillboardScale() { - return mScale.xz() * 0.75f; + return AbsoluteScale().xz() * 0.75f; } diff --git a/Scene/CSceneNode.cpp b/Scene/CSceneNode.cpp index ab3ca52a..030bd5c9 100644 --- a/Scene/CSceneNode.cpp +++ b/Scene/CSceneNode.cpp @@ -21,6 +21,7 @@ CSceneNode::CSceneNode(CSceneManager *pScene, CSceneNode *pParent) mPosition = CVector3f::skZero; mRotation = CQuaternion::skIdentity; mScale = CVector3f::skOne; + mScaleMultiplier = CVector3f::skOne; _mTransformOutdated = true; _mInheritsPosition = true; @@ -46,11 +47,6 @@ CSceneNode::~CSceneNode() } // ************ VIRTUAL ************ -TString CSceneNode::PrefixedName() const -{ - return Name(); -} - void CSceneNode::DrawSelection() { // Default implementation for virtual function @@ -68,16 +64,19 @@ void CSceneNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewI bool CSceneNode::IsVisible() const { + // Default implementation for virtual function return mVisible; } CColor CSceneNode::TintColor(const SViewInfo& ViewInfo) const { + // Default implementation for virtual function return (IsSelected() && !ViewInfo.GameMode ? skSelectionTint : CColor::skWhite); } CColor CSceneNode::WireframeColor() const { + // Default implementation for virtual function return CColor::skWhite; } @@ -367,7 +366,7 @@ CVector3f CSceneNode::LocalScale() const CVector3f CSceneNode::AbsoluteScale() const { - CVector3f ret = mScale; + CVector3f ret = mScale * mScaleMultiplier; if ((mpParent) && (InheritsScale())) ret *= mpParent->AbsoluteScale(); diff --git a/Scene/CSceneNode.h b/Scene/CSceneNode.h index 740c3df3..eb5c7475 100644 --- a/Scene/CSceneNode.h +++ b/Scene/CSceneNode.h @@ -38,7 +38,9 @@ protected: CVector3f mPosition; CQuaternion mRotation; CVector3f mScale; + CVector3f mScaleMultiplier; CAABox mLocalAABox; + bool mMouseHovering; bool mSelected; bool mVisible; @@ -53,7 +55,6 @@ public: explicit CSceneNode(CSceneManager *pScene, CSceneNode *pParent = 0); virtual ~CSceneNode(); virtual ENodeType NodeType() = 0; - virtual TString PrefixedName() const; virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*ViewInfo*/) {} virtual void DrawSelection(); virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); diff --git a/Scene/CScriptNode.cpp b/Scene/CScriptNode.cpp index 6631130b..8e17ce20 100644 --- a/Scene/CScriptNode.cpp +++ b/Scene/CScriptNode.cpp @@ -32,7 +32,10 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje SetName("[" + pTemp->TemplateName(mpInstance->NumProperties()) + "] " + mpInstance->InstanceName()); if (pTemp->ScaleType() == CScriptTemplate::eScaleEnabled) + { mScale = mpInstance->Scale(); + mScaleMultiplier = mpInstance->Template()->PreviewScale(); + } MarkTransformChanged(); @@ -99,11 +102,6 @@ ENodeType CScriptNode::NodeType() return eScriptNode; } -TString CScriptNode::PrefixedName() const -{ - return "[" + mpInstance->Template()->TemplateName() + "] " + mpInstance->InstanceName(); -} - void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) { if (!mpInstance) return; @@ -474,6 +472,6 @@ CAABox CScriptNode::PreviewVolumeAABox() 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; } diff --git a/Scene/CScriptNode.h b/Scene/CScriptNode.h index bb1209a7..728e381e 100644 --- a/Scene/CScriptNode.h +++ b/Scene/CScriptNode.h @@ -27,7 +27,6 @@ class CScriptNode : public CSceneNode public: CScriptNode(CSceneManager *pScene, CSceneNode *pParent = 0, CScriptObject *pObject = 0); ENodeType NodeType(); - TString PrefixedName() const; void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); void DrawSelection(); diff --git a/UI/CWorldEditor.cpp b/UI/CWorldEditor.cpp index 1eb7babb..b829f956 100644 --- a/UI/CWorldEditor.cpp +++ b/UI/CWorldEditor.cpp @@ -180,7 +180,7 @@ void CWorldEditor::UpdateGizmoUI() if (mGizmoTransforming && mGizmo.HasTransformed()) spinBoxValue = mGizmo.TotalScale(); else if (!mSelection.empty()) - spinBoxValue = mSelection.front()->AbsoluteScale(); + spinBoxValue = mSelection.front()->LocalScale(); break; } } @@ -308,6 +308,7 @@ void CWorldEditor::OnTransformSpinBoxModified(CVector3f value) switch (mGizmo.Mode()) { + // Use absolute position/rotation, but relative scale. (This way spinbox doesn't show preview multiplier) case CGizmo::eTranslate: { CVector3f delta = value - mSelection.front()->AbsolutePosition(); @@ -324,7 +325,7 @@ void CWorldEditor::OnTransformSpinBoxModified(CVector3f value) case CGizmo::eScale: { - CVector3f delta = value / mSelection.front()->AbsoluteScale(); + CVector3f delta = value / mSelection.front()->LocalScale(); mUndoStack.push(new CScaleNodeCommand(this, mSelection, CVector3f::skZero, delta)); break; }