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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -62,8 +62,6 @@ private:
|
|||
CMasterTemplate *mpMaster;
|
||||
std::vector<SPropertySet> mPropertySets;
|
||||
std::list<CScriptObject*> mObjectList;
|
||||
ERotationType mRotationType;
|
||||
EScaleType mScaleType;
|
||||
TString mTemplateName;
|
||||
TString mSourceFile;
|
||||
u32 mObjectID;
|
||||
|
@ -78,6 +76,10 @@ private:
|
|||
TIDString mLightParametersIDString;
|
||||
std::vector<SEditorAsset> 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;
|
||||
|
|
|
@ -132,5 +132,5 @@ CLight* CLightNode::Light()
|
|||
|
||||
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;
|
||||
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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue