/
ModelScaleManipulator.cpp
146 lines (114 loc) · 3.57 KB
/
ModelScaleManipulator.cpp
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
#include "ModelScaleManipulator.h"
#include "selection/Remap.h"
#include "selection/BestPoint.h"
#include "selection/SelectionPool.h"
#include "render/View.h"
#include "string/convert.h"
namespace selection
{
ModelScaleManipulator::ModelScaleManipulator(ManipulationPivot& pivot) :
_pivot(pivot),
_scaleFree(*this)
{
draw_arrowline(64, &_arrowX.front(), 0);
draw_arrowline(64, &_arrowY.front(), 1);
draw_arrowline(64, &_arrowZ.front(), 2);
draw_quad(16, &_quadScreen.front());
}
ModelScaleManipulator::Type ModelScaleManipulator::getType() const
{
return Type::ModelScale;
}
ModelScaleManipulator::Component* ModelScaleManipulator::getActiveComponent()
{
return &_scaleFree;
}
void ModelScaleManipulator::testSelect(const render::View& view, const Matrix4& pivot2world)
{
_pivot2World.update(_pivot.getMatrix4(), view.GetModelview(), view.GetProjection(), view.GetViewport());
SelectionPool selector;
#if 0
{
Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot2World._worldSpace));
{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowX.front(), best);
selector.addSelectable(best, &_selectableX);
}
{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowY.front(), best);
selector.addSelectable(best, &_selectableY);
}
{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowZ.front(), best);
selector.addSelectable(best, &_selectableZ);
}
}
#endif
{
Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot2World._viewpointSpace));
{
SelectionIntersection best;
Quad_BestPoint(local2view, eClipCullCW, &_quadScreen.front(), best);
selector.addSelectable(best, &_selectableScreen);
}
}
if (!selector.empty())
{
(*selector.begin()).second->setSelected(true);
}
}
void ModelScaleManipulator::setSelected(bool select)
{
_selectableScreen.setSelected(select);
}
bool ModelScaleManipulator::isSelected() const
{
return _selectableScreen.isSelected();
}
void ModelScaleManipulator::render(RenderableCollector& collector, const VolumeTest& volume)
{
_pivot2World.update(_pivot.getMatrix4(), volume.GetModelview(), volume.GetProjection(), volume.GetViewport());
collector.SetState(_lineShader, RenderableCollector::eWireframeOnly);
collector.SetState(_lineShader, RenderableCollector::eFullMaterials);
_renderableAabbs.clear();
foreachSelectedTransformable([&](const scene::INodePtr& node, Entity* entity)
{
_renderableAabbs.push_back(RenderableSolidAABB(node->worldAABB()));
});
for (const RenderableSolidAABB& aabb : _renderableAabbs)
{
collector.addRenderable(aabb, Matrix4::getIdentity());
}
//collector.addRenderable(_arrowX, _pivot2World._worldSpace);
//collector.addRenderable(_arrowY, _pivot2World._worldSpace);
//collector.addRenderable(_arrowZ, _pivot2World._worldSpace);
collector.addRenderable(_quadScreen, _pivot2World._viewpointSpace);
}
void ModelScaleManipulator::scale(const Vector3& scaling)
{
rMessage() << "Scale: " << scaling << std::endl;
foreachSelectedTransformable([&](const scene::INodePtr& node, Entity* entity)
{
// Apply the scaling spawnarg to this entity
entity->setKeyValue("dr_model_scale", string::to_string(scaling));
});
// Update the scene views
SceneChangeNotify();
}
void ModelScaleManipulator::foreachSelectedTransformable(
const std::function<void(const scene::INodePtr&, Entity*)>& functor)
{
GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
{
Entity* entity = Node_getEntity(node);
if (entity && entity->isModel())
{
functor(node, entity);
}
});
}
ShaderPtr ModelScaleManipulator::_lineShader;
}