/
LightNode.h
154 lines (116 loc) · 5.21 KB
/
LightNode.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
#pragma once
#include "ilightnode.h"
#include "registry/CachedKey.h"
#include "Light.h"
#include "dragplanes.h"
#include "../VertexInstance.h"
#include "../EntityNode.h"
namespace entity
{
class LightNode;
typedef std::shared_ptr<LightNode> LightNodePtr;
/// Scenegraph node representing a light
class LightNode :
public EntityNode,
public ILightNode,
public Snappable,
public ComponentSelectionTestable,
public ComponentEditable,
public ComponentSnappable,
public PlaneSelectable,
public OpenGLRenderable
{
Light _light;
// The (draggable) light center instance
VertexInstance _lightCenterInstance;
VertexInstance _lightTargetInstance;
VertexInstanceRelative _lightRightInstance;
VertexInstanceRelative _lightUpInstance;
VertexInstance _lightStartInstance;
VertexInstance _lightEndInstance;
// dragplanes for lightresizing using mousedrag
selection::DragPlanes _dragPlanes;
// Renderable components of this light
RenderLightRadiiBox _renderableRadius;
RenderLightProjection _renderableFrustum;
// a temporary variable for calculating the AABB of all (selected) components
mutable AABB m_aabb_component;
// Cached rkey to override light volume colour
registry::CachedKey<bool> _overrideColKey;
public:
LightNode(const IEntityClassPtr& eclass);
private:
LightNode(const LightNode& other);
public:
static LightNodePtr Create(const IEntityClassPtr& eclass);
// RenderEntity implementation
virtual float getShaderParm(int parmNum) const override;
// Bounded implementation
virtual const AABB& localAABB() const override;
// override scene::Inode methods to deselect the child components
virtual void onInsertIntoScene(scene::IMapRootNode& root) override;
virtual void onRemoveFromScene(scene::IMapRootNode& root) override;
// Snappable implementation
virtual void snapto(float snap) override;
/** greebo: Returns the AABB of the small diamond representation.
* (use this to select the light against an AABB selectiontest like CompleteTall or similar).
*/
AABB getSelectAABB() const override;
/* greebo: This snaps the components to the grid.
*
* Note: if none are selected, ALL the components are snapped to the grid (I hope this is intentional)
* This function can only be called in Selection::eVertex mode, so I assume that the user wants all components
* to be snapped.
*
* If one or more components is/are selected, ONLY those are snapped to the grid.
*/
void snapComponents(float snap) override;
// PlaneSelectable implementation
void selectPlanes(Selector& selector, SelectionTest& test, const PlaneCallback& selectedPlaneCallback) override;
void selectReversedPlanes(Selector& selector, const SelectedPlanes& selectedPlanes) override;
// Test the light volume for selection, this just passes the call on to the contained Light class
void testSelect(Selector& selector, SelectionTest& test) override;
// greebo: Returns true if drag planes or the light center is selected (both are components)
bool isSelectedComponents() const override;
// greebo: Selects/deselects all components, depending on the chosen componentmode
void setSelectedComponents(bool select, SelectionSystem::EComponentMode mode) override;
void invertSelectedComponents(SelectionSystem::EComponentMode mode) override;
void testSelectComponents(Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode) override;
/**
* greebo: This returns the AABB of all the selectable vertices. This method
* distinguishes between projected and point lights and stretches the AABB accordingly.
*/
// ComponentEditable implementation
const AABB& getSelectedComponentsBounds() const override;
scene::INodePtr clone() const override;
void selectedChangedComponent(const ISelectable& selectable);
// Renderable implementation
void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const override;
void setRenderSystem(const RenderSystemPtr& renderSystem) override;
void renderComponents(RenderableCollector& collector, const VolumeTest& volume) const override;
// OpenGLRenderable implementation
void render(const RenderInfo& info) const override;
const Matrix4& rotation() const;
// Returns the original "origin" value
const Vector3& getUntransformedOrigin() override;
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;
// Override EntityNode::construct()
void construct() override;
private:
void renderInactiveComponents(RenderableCollector& collector, const VolumeTest& volume, const bool selected) const;
void evaluateTransform();
// Render the light volume including bounds and origin
void renderLightVolume(RenderableCollector& collector,
const Matrix4& localToWorld, bool selected) const;
// Update the bounds of the renderable radius box
void updateRenderableRadius() const;
void onLightRadiusChanged();
}; // class LightNode
} // namespace entity