/
PatchNode.h
160 lines (123 loc) · 5.79 KB
/
PatchNode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#pragma once
#include "irenderable.h"
#include "icomparablenode.h"
#include "iscenegraph.h"
#include "itraceable.h"
#include "imap.h"
#include "Patch.h"
#include "scene/SelectableNode.h"
#include "PatchControlInstance.h"
#include "dragplanes.h"
#include "PatchRenderables.h"
class PatchNode final :
public scene::SelectableNode,
public scene::Cloneable,
public Snappable,
public IdentityTransform,
public IPatchNode,
public SelectionTestable,
public ComponentSelectionTestable,
public ComponentEditable,
public ComponentSnappable,
public PlaneSelectable,
public Transformable,
public ITraceable,
public scene::IComparableNode
{
selection::DragPlanes m_dragPlanes;
// The patch control instances
typedef std::vector<PatchControlInstance> PatchControlInstances;
PatchControlInstances m_ctrl_instances;
Patch m_patch;
// An internal AABB variable to calculate the bounding box of the selected components (has to be mutable)
mutable AABB m_aabb_component;
ShaderPtr _ctrlPointShader;
ShaderPtr _ctrlLatticeShader;
// For pivoted rotations, we need a copy of this lying around
Vector3 _untransformedOrigin;
// If true, the _untransformedOrigin member needs an update
bool _untransformedOriginChanged;
RenderablePatchTesselation<TesselationIndexer_Triangles> _renderableSurfaceSolid;
RenderablePatchTesselation<TesselationIndexer_Quads> _renderableSurfaceWireframe;
RenderablePatchLattice _renderableCtrlLattice; // Wireframe connecting the control points
RenderablePatchControlPoints _renderableCtrlPoints; // the coloured control points
public:
PatchNode(patch::PatchDefType type);
// Copy Constructor
PatchNode(const PatchNode& other);
std::string name() const override;
Type getNodeType() const override;
// IComparableNode implementation
std::string getFingerprint() override;
// Bounded implementation
const AABB& localAABB() const override;
// IPatchNode implementation
Patch& getPatchInternal() override;
IPatch& getPatch() override;
// Snappable implementation
virtual void snapto(float snap) override;
// Test the Patch instance for selection (SelectionTestable)
void testSelect(Selector& selector, SelectionTest& test) override;
// Check if the drag planes pass the given selection test (and select them of course and call the callback)
void selectPlanes(Selector& selector, SelectionTest& test, const PlaneCallback& selectedPlaneCallback) override;
void selectReversedPlanes(Selector& selector, const SelectedPlanes& selectedPlanes) override;
// Returns true if any of the patch components is selected
bool isSelectedComponents() const override;
// Set the components (control points or dragplanes) selection to <select>
void setSelectedComponents(bool select, selection::ComponentSelectionMode mode) override;
// Invert the component selection
void invertSelectedComponents(selection::ComponentSelectionMode mode) override;
// Tests the patch components on selection using the passed SelectionTest
void testSelectComponents(Selector& selector, SelectionTest& test, selection::ComponentSelectionMode mode) override;
// override scene::Inode::onRemoveFromScene to deselect the child components
void onInsertIntoScene(scene::IMapRootNode& root) override;
void onRemoveFromScene(scene::IMapRootNode& root) override;
// Traceable implementation
bool getIntersection(const Ray& ray, Vector3& intersection) override;
// Create the axis aligned bounding box of the selected components
const AABB& getSelectedComponentsBounds() const override;
// Sets all Control Instances to selected = <selected>
void selectCtrl(bool selected);
// Returns true if this patch can be rendered
bool isVisible() const;
// Returns true if the material itself is visible
bool hasVisibleMaterial() const;
// greebo: snaps all the _selected_ components to the grid (should be called "snapSelectedComponents")
void snapComponents(float snap) override;
// Returns true if any of the Control Vertices is selected
bool selectedVertices();
// Clones this node, allocates a new Node on the heap and passes itself to the constructor of the new node
scene::INodePtr clone() const override;
// greebo: This gets called by the ObservedSelectable as soon as its selection state changes
// (see ObservedSelectable and PatchControlInstance)
void selectedChangedComponent(const ISelectable& selectable);
// Renderable implementation
// Render functions, these make sure that all things get rendered properly. The calls are also passed on
// to the contained patch <m_patch>
void onPreRender(const VolumeTest& volume) override;
void renderSolid(IRenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(IRenderableCollector& collector, const VolumeTest& volume) const override;
void renderHighlights(IRenderableCollector& collector, const VolumeTest& volume) override;
void setRenderSystem(const RenderSystemPtr& renderSystem) override;
void evaluateTransform();
std::size_t getHighlightFlags() override;
// Returns the center of the untransformed world AABB
const Vector3& getUntransformedOrigin() override;
void onControlPointsChanged();
void onMaterialChanged();
void onTesselationChanged();
void updateSelectableControls();
protected:
// Gets called by the Transformable implementation whenever
// scale, rotation or translation is changed.
void _onTransformationChanged() override;
// Called by the Transformable implementation before freezing
// or when reverting transformations.
void _applyTransformation() override;
void onVisibilityChanged(bool isVisibleNow) override;
private:
// Transforms the patch components with the given transformation matrix
void transformComponents(const Matrix4& matrix);
};
typedef std::shared_ptr<PatchNode> PatchNodePtr;
typedef std::weak_ptr<PatchNode> PatchNodeWeakPtr;