-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy patheditortool.cpp
More file actions
138 lines (116 loc) · 3.68 KB
/
Copy patheditortool.cpp
File metadata and controls
138 lines (116 loc) · 3.68 KB
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
#include "editor/editortool.h"
#include "components/actor.h"
#include "components/transform.h"
#include "components/renderable.h"
#include "components/camera.h"
#include "editor/viewport/handletools.h"
EditorTool::Select::Select() :
uuid(0),
object(nullptr),
renderable(nullptr) {
}
EditorTool::EditorTool(EditorTool::SelectList &selection) :
m_selected(selection),
m_cursor(Qt::ArrowCursor),
m_snap(0.0f) {
}
QString EditorTool::toolTip() const {
return QString();
}
QString EditorTool::shortcut() const {
return QString();
}
float EditorTool::snap() const {
return m_snap;
}
void EditorTool::setSnap(float snap) {
m_snap = snap;
}
void EditorTool::update(bool center, bool local, bool snap) {
A_UNUSED(center);
A_UNUSED(local);
A_UNUSED(snap);
}
void EditorTool::beginControl() {
m_propertiesCache.clear();
for(auto &it : m_selected) {
Transform *t = it.object->transform();
it.position = t->position();
it.scale = t->scale();
it.euler = t->rotation();
it.quat = t->quaternion();
VariantMap components;
for(auto &child : it.object->getChildren()) {
Component *component = dynamic_cast<Component *>(child);
if(component) {
VariantMap properies;
const MetaObject *meta = component->metaObject();
for(int i = 0; i < meta->propertyCount(); i++) {
MetaProperty property = meta->property(i);
properies[property.name()] = property.read(component);
}
components[to_string(component->uuid())] = properies;
}
}
m_propertiesCache.push_back(components);
}
}
void EditorTool::endControl() {
}
void EditorTool::cancelControl() {
auto cache = m_propertiesCache.begin();
for(auto &it : m_selected) {
VariantMap components = (*cache).toMap();
for(auto &child : it.object->getChildren()) {
Component *component = dynamic_cast<Component *>(child);
if(component) {
VariantMap properties = components[to_string(component->uuid())].toMap();
const MetaObject *meta = component->metaObject();
for(int i = 0; i < meta->propertyCount(); i++) {
MetaProperty property = meta->property(i);
property.write(component, properties[property.name()]);
}
}
}
++cache;
}
}
Qt::CursorShape EditorTool::cursor() const {
return m_cursor;
}
Vector3 EditorTool::objectPosition() {
if(m_selected.size() == 1) {
return m_selected.front().object->transform()->worldPosition();
}
return objectBound().center;
}
AABBox EditorTool::objectBound() {
AABBox result;
result.extent = Vector3(-1.0f);
if(!m_selected.empty()) {
bool first = true;
for(auto &it : m_selected) {
if(it.renderable == nullptr) {
it.renderable = dynamic_cast<Renderable *>(it.object->component("Renderable"));
}
if(it.renderable) {
if(first) {
result = it.renderable->bound();
first = false;
} else {
result.encapsulate(it.renderable->bound());
}
} else {
if(first) {
result.center = it.object->transform()->worldPosition();
} else {
result.encapsulate(it.object->transform()->worldPosition());
}
}
}
}
return result;
}
const VariantList &EditorTool::cache() const {
return m_propertiesCache;
}