Clean up use of transforms in scene graph.
This commit is contained in:
parent
3915a40c96
commit
f26ee2ebc4
37 changed files with 238 additions and 242 deletions
|
@ -1,15 +1,27 @@
|
|||
#include "AbstractVisualNode.h"
|
||||
|
||||
AbstractVisualNode::AbstractVisualNode(const Point& location, const std::string& name)
|
||||
: mLocation(location),
|
||||
AbstractVisualNode::AbstractVisualNode(const Transform& transform, const std::string& name)
|
||||
: mTransform(transform),
|
||||
mName(name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AbstractVisualNode::~AbstractVisualNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SceneItem* AbstractVisualNode::getSceneItem(std::size_t idx) const
|
||||
{
|
||||
return mSceneItems[idx].get();
|
||||
if (idx < mSceneItems.size())
|
||||
{
|
||||
return mSceneItems[idx].get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t AbstractVisualNode::getNumSceneItems() const
|
||||
|
@ -22,11 +34,6 @@ void AbstractVisualNode::update(SceneInfo* sceneInfo)
|
|||
|
||||
}
|
||||
|
||||
Image* AbstractVisualNode::getImage() const
|
||||
{
|
||||
return mImage.get();
|
||||
}
|
||||
|
||||
void AbstractVisualNode::syncChildren(const std::vector<AbstractVisualNode*>& children)
|
||||
{
|
||||
mChildren = children;
|
||||
|
@ -47,11 +54,6 @@ void AbstractVisualNode::setIsVisible(bool isVisible)
|
|||
mIsVisible = isVisible;
|
||||
}
|
||||
|
||||
std::size_t AbstractVisualNode::getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setName(const std::string& name)
|
||||
{
|
||||
mName = name;
|
||||
|
@ -67,11 +69,16 @@ bool AbstractVisualNode::getIsVisible() const
|
|||
return mIsVisible;
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setLocation(const Point& loc)
|
||||
const Transform& AbstractVisualNode::getTransform() const
|
||||
{
|
||||
if (mLocation != loc)
|
||||
return mTransform;
|
||||
}
|
||||
|
||||
void AbstractVisualNode::setTransform(const Transform& transform)
|
||||
{
|
||||
if (mTransform != transform)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mLocation = loc;
|
||||
mTransform = transform;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "SceneModel.h"
|
||||
#include "AbstractMesh.h"
|
||||
|
||||
#include "Image.h"
|
||||
#include "Point.h"
|
||||
#include "SceneItem.h"
|
||||
#include "Transform.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct SceneInfo;
|
||||
|
||||
class AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
AbstractVisualNode(const Point& location, const std::string& name = {});
|
||||
AbstractVisualNode(const Transform& transform = {}, const std::string& name = {});
|
||||
|
||||
virtual ~AbstractVisualNode() = default;
|
||||
virtual ~AbstractVisualNode();
|
||||
|
||||
void addChild(AbstractVisualNode* child);
|
||||
|
||||
|
@ -25,30 +22,27 @@ public:
|
|||
|
||||
virtual std::size_t getNumSceneItems() const;
|
||||
|
||||
std::size_t getNumChildren() const;
|
||||
|
||||
const std::vector<AbstractVisualNode*>& getChildren() const;
|
||||
|
||||
const std::string& getName() const;
|
||||
|
||||
Image* getImage() const;
|
||||
|
||||
bool getIsVisible() const;
|
||||
|
||||
const Transform& getTransform() const;
|
||||
|
||||
void syncChildren(const std::vector<AbstractVisualNode*>& children);
|
||||
|
||||
void setIsVisible(bool isVisible);
|
||||
|
||||
void setName(const std::string& name);
|
||||
|
||||
virtual void setLocation(const Point& loc);
|
||||
virtual void setTransform(const Transform& transform);
|
||||
|
||||
virtual void update(SceneInfo* sceneInfo);
|
||||
|
||||
protected:
|
||||
Point mLocation;
|
||||
Transform mTransform;
|
||||
std::vector<std::unique_ptr<SceneItem> > mSceneItems;
|
||||
std::unique_ptr<Image> mImage;
|
||||
|
||||
std::vector<AbstractVisualNode*> mChildren;
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include "SceneInfo.h"
|
||||
#include "SceneModel.h"
|
||||
|
||||
GeometryNode::GeometryNode(const Point& location)
|
||||
: MaterialNode(location),
|
||||
GeometryNode::GeometryNode(const Transform& transform)
|
||||
: MaterialNode(transform),
|
||||
mStrokeThickness(1.0),
|
||||
mType(Type::Path)
|
||||
{
|
||||
|
@ -75,12 +75,6 @@ void GeometryNode::update(SceneInfo* sceneInfo)
|
|||
mGeometryIsDirty = false;
|
||||
}
|
||||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
updateTransform();
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
{
|
||||
updateMaterial();
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
GeometryNode(const Point& location);
|
||||
GeometryNode(const Transform& transform);
|
||||
virtual ~GeometryNode();
|
||||
|
||||
virtual Type getType() = 0;
|
||||
|
@ -34,7 +34,6 @@ public:
|
|||
protected:
|
||||
virtual void createOrUpdateGeometry(SceneInfo* sceneInfo) = 0;
|
||||
virtual void updateMaterial();
|
||||
virtual void updateTransform() = 0;
|
||||
|
||||
double mStrokeThickness{0};
|
||||
Type mType;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "GridNode.h"
|
||||
|
||||
#include "MeshPrimitives.h"
|
||||
#include "SceneModel.h"
|
||||
|
||||
GridNode::GridNode(const Point& location)
|
||||
: MaterialNode(location)
|
||||
GridNode::GridNode(const Transform& transform)
|
||||
: MaterialNode(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -30,7 +31,7 @@ void GridNode::setWidth(double width)
|
|||
{
|
||||
if (mWidth != width)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mGeometryIsDirty = true;
|
||||
mWidth = width;
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +40,7 @@ void GridNode::setHeight(double height)
|
|||
{
|
||||
if (mHeight != height)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mGeometryIsDirty = true;
|
||||
mHeight = height;
|
||||
}
|
||||
}
|
||||
|
@ -124,8 +125,8 @@ void GridNode::update(SceneInfo* sceneInfo)
|
|||
{
|
||||
auto size = mHeight > mWidth ? mWidth : mHeight;
|
||||
|
||||
mBackgroundModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
mOutlineModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
//mBackgroundModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
//mOutlineModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
#include "MaterialNode.h"
|
||||
#include "Color.h"
|
||||
|
||||
class SceneModel;
|
||||
|
||||
class GridNode : public MaterialNode
|
||||
{
|
||||
|
||||
public:
|
||||
GridNode(const Point& location);
|
||||
GridNode(const Transform& transform);
|
||||
|
||||
void setNumX(std::size_t numX);
|
||||
|
||||
|
@ -28,7 +29,10 @@ private:
|
|||
std::size_t mNumberY{5};
|
||||
double mWidth{1};
|
||||
double mHeight{1};
|
||||
|
||||
bool mDataDirty = true;
|
||||
bool mGeometryIsDirty = true;
|
||||
|
||||
std::vector<Color> mData;
|
||||
|
||||
std::unique_ptr<SceneModel> mBackgroundModel;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#include "MaterialNode.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
MaterialNode::MaterialNode(const Point& location)
|
||||
: AbstractVisualNode(location),
|
||||
MaterialNode::MaterialNode(const Transform& transform)
|
||||
: AbstractVisualNode(transform),
|
||||
mFillColor(Color(255, 255, 255)),
|
||||
mStrokeColor(Color(0, 0, 0))
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
class MaterialNode : public AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
MaterialNode(const Point& location);
|
||||
MaterialNode(const Transform& transform);
|
||||
|
||||
const Color& getFillColor() const;
|
||||
const Color& getStrokeColor() const;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "MeshNode.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "SceneModel.h"
|
||||
#include "AbstractMesh.h"
|
||||
|
||||
MeshNode::MeshNode(const Point& location)
|
||||
: MaterialNode(location)
|
||||
MeshNode::MeshNode(const Transform& transform)
|
||||
: MaterialNode(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -69,7 +70,6 @@ void MeshNode::update(SceneInfo* sceneInfo)
|
|||
|
||||
if (mWorkingMesh && mMeshIsDirty)
|
||||
{
|
||||
std::cout << "Updating mesh with " << mWorkingMesh->getNumNodes() << std::endl;
|
||||
mModel->updateMesh(mWorkingMesh);
|
||||
mMeshIsDirty = false;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ void MeshNode::update(SceneInfo* sceneInfo)
|
|||
if (mTransformIsDirty)
|
||||
{
|
||||
auto size = mHeight > mWidth ? mWidth : mHeight;
|
||||
mModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
//mModel->updateTransform({mLocation, static_cast<double>(size), static_cast<double>(size)});
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
#include "MaterialNode.h"
|
||||
|
||||
class SceneModel;
|
||||
class AbstractMesh;
|
||||
|
||||
class MeshNode : public MaterialNode
|
||||
{
|
||||
public:
|
||||
MeshNode(const Point& location);
|
||||
MeshNode(const Transform& transform);
|
||||
void setMesh(AbstractMesh* mesh);
|
||||
|
||||
SceneItem* getSceneItem(std::size_t idx) const override;
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
#include "Path.h"
|
||||
#include "SceneInfo.h"
|
||||
|
||||
PathNode::PathNode(const Point& loc, const std::string& psPath)
|
||||
: GeometryNode(loc),
|
||||
#include "SceneModel.h"
|
||||
|
||||
PathNode::PathNode(const Transform& transform, const std::string& psPath)
|
||||
: GeometryNode(transform),
|
||||
mPathString(psPath)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<PathNode> PathNode::Create(const Point& loc, const std::string& psPath)
|
||||
std::unique_ptr<PathNode> PathNode::Create(const Transform& transform, const std::string& psPath)
|
||||
{
|
||||
return std::make_unique<PathNode>(loc, psPath);
|
||||
return std::make_unique<PathNode>(transform, psPath);
|
||||
}
|
||||
|
||||
GeometryNode::Type PathNode::getType()
|
||||
|
@ -51,9 +53,4 @@ void PathNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|||
mBackgroundItem->updateGeometry(std::move(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PathNode::updateTransform()
|
||||
{
|
||||
mBackgroundItem->updateTransform({ mLocation });
|
||||
}
|
|
@ -7,8 +7,8 @@
|
|||
class PathNode : public GeometryNode
|
||||
{
|
||||
public:
|
||||
PathNode(const Point& loc, const std::string& psPath);
|
||||
static std::unique_ptr<PathNode> Create(const Point& loc, const std::string& psPath);
|
||||
PathNode(const Transform& transform, const std::string& psPath);
|
||||
static std::unique_ptr<PathNode> Create(const Transform& transform, const std::string& psPath);
|
||||
|
||||
GeometryNode::Type getType() override;
|
||||
|
||||
|
@ -18,7 +18,6 @@ public:
|
|||
|
||||
private:
|
||||
void createOrUpdateGeometry(SceneInfo* sceneInfo) override;
|
||||
void updateTransform() override;
|
||||
|
||||
std::string mPathString;
|
||||
};
|
|
@ -6,7 +6,7 @@ class RootNode : public AbstractVisualNode
|
|||
{
|
||||
public:
|
||||
RootNode()
|
||||
: AbstractVisualNode(DiscretePoint(0, 0))
|
||||
: AbstractVisualNode(Transform())
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@
|
|||
|
||||
#include "StringUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TextNode::TextNode(const std::string& content, const Point& loc)
|
||||
: MaterialNode(loc)
|
||||
TextNode::TextNode(const std::string& content, const Transform& transform)
|
||||
: MaterialNode(transform)
|
||||
{
|
||||
mTextData.mContent= content;
|
||||
}
|
||||
|
@ -27,9 +25,9 @@ TextNode::~TextNode()
|
|||
|
||||
}
|
||||
|
||||
std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const Point& loc)
|
||||
std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const Transform& transform)
|
||||
{
|
||||
return std::make_unique<TextNode>(content, loc);
|
||||
return std::make_unique<TextNode>(content, transform);
|
||||
}
|
||||
|
||||
std::string TextNode::getFontLabel() const
|
||||
|
@ -168,10 +166,10 @@ void TextNode::update(SceneInfo* sceneInfo)
|
|||
|
||||
if (mTransformIsDirty)
|
||||
{
|
||||
mTextItem->updateTransform({mLocation});
|
||||
mTextItem->setTextWidth(mWidth);
|
||||
mTextItem->setTextHeight(mHeight);
|
||||
mTransformIsDirty = false;
|
||||
//mTextItem->updateTransform({mLocation});
|
||||
//mTextItem->setTextWidth(mWidth);
|
||||
//mTextItem->setTextHeight(mHeight);
|
||||
//mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
|
|
|
@ -15,11 +15,11 @@ class FontsManager;
|
|||
class TextNode : public MaterialNode
|
||||
{
|
||||
public:
|
||||
TextNode(const std::string& content, const Point& loc);
|
||||
TextNode(const std::string& content, const Transform& transform);
|
||||
|
||||
~TextNode();
|
||||
|
||||
static std::unique_ptr<TextNode> Create(const std::string& content, const Point& loc);
|
||||
static std::unique_ptr<TextNode> Create(const std::string& content, const Transform& transform);
|
||||
|
||||
std::string getContent() const;
|
||||
std::string getFontLabel() const;
|
||||
|
|
|
@ -7,7 +7,7 @@ class TransformNode : public AbstractVisualNode
|
|||
public:
|
||||
|
||||
TransformNode()
|
||||
: AbstractVisualNode(DiscretePoint(0, 0))
|
||||
: AbstractVisualNode(Transform())
|
||||
{
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue