/
GenericEntityNode.cpp
158 lines (122 loc) · 3.82 KB
/
GenericEntityNode.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
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "GenericEntityNode.h"
#include "math/Frustum.h"
namespace entity {
GenericEntityNode::GenericEntityNode(const IEntityClassPtr& eclass) :
EntityNode(eclass),
m_contained(*this),
_solidAABBRenderMode(SolidBoxes)
{}
GenericEntityNode::GenericEntityNode(const GenericEntityNode& other) :
EntityNode(other),
Snappable(other),
m_contained(other.m_contained, *this),
_solidAABBRenderMode(other._solidAABBRenderMode)
{}
GenericEntityNodePtr GenericEntityNode::Create(const IEntityClassPtr& eclass)
{
GenericEntityNodePtr instance(new GenericEntityNode(eclass));
instance->construct();
return instance;
}
void GenericEntityNode::construct()
{
EntityNode::construct();
m_contained.construct();
}
// Snappable implementation
void GenericEntityNode::snapto(float snap) {
m_contained.snapto(snap);
}
// Bounded implementation
const AABB& GenericEntityNode::localAABB() const {
return m_contained.localAABB();
}
void GenericEntityNode::testSelect(Selector& selector, SelectionTest& test)
{
EntityNode::testSelect(selector, test);
m_contained.testSelect(selector, test, localToWorld());
}
scene::INodePtr GenericEntityNode::clone() const
{
GenericEntityNodePtr node(new GenericEntityNode(*this));
node->construct();
node->constructClone(*this);
return node;
}
GenericEntityNode::SolidAAABBRenderMode GenericEntityNode::getSolidAABBRenderMode() const
{
return _solidAABBRenderMode;
}
void GenericEntityNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
{
EntityNode::renderSolid(collector, volume);
m_contained.renderSolid(collector, volume, localToWorld());
}
void GenericEntityNode::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const
{
EntityNode::renderWireframe(collector, volume);
m_contained.renderWireframe(collector, volume, localToWorld());
}
const Vector3& GenericEntityNode::getDirection() const
{
// Return the direction as specified by the angle/rotation keys
return m_contained.getDirection();
}
void GenericEntityNode::_onTransformationChanged()
{
if (getType() == TRANSFORM_PRIMITIVE)
{
m_contained.revertTransform();
m_contained.translate(getTranslation());
m_contained.rotate(getRotation());
m_contained.updateTransform();
}
}
void GenericEntityNode::_applyTransformation()
{
if (getType() == TRANSFORM_PRIMITIVE)
{
m_contained.revertTransform();
m_contained.translate(getTranslation());
m_contained.rotate(getRotation());
m_contained.freezeTransform();
}
}
const Vector3& GenericEntityNode::getUntransformedOrigin()
{
return m_contained.getUntransformedOrigin();
}
void GenericEntityNode::onChildAdded(const scene::INodePtr& child)
{
EntityNode::onChildAdded(child);
_solidAABBRenderMode = SolidBoxes;
// Check if this node has any actual models/particles as children
Node::foreachNode([&](const scene::INodePtr& node)
{
// We consider all non-path-connection childnodes as "models"
if (child->getNodeType() != scene::INode::Type::EntityConnection)
{
_solidAABBRenderMode = WireFrameOnly;
return false; // stop traversal
}
return true;
});
}
void GenericEntityNode::onChildRemoved(const scene::INodePtr& child)
{
EntityNode::onChildRemoved(child);
_solidAABBRenderMode = SolidBoxes;
// Check if this node has any actual models/particles as children
Node::foreachNode([&](const scene::INodePtr& node)
{
// We consider all non-path-connection childnodes as "models"
// Ignore the child itself as this event is raised before the node is actually removed.
if (node != child && child->getNodeType() != scene::INode::Type::EntityConnection)
{
_solidAABBRenderMode = WireFrameOnly;
return false; // stop traversal
}
return true;
});
}
} // namespace entity