Debian Codegraph @

editor/scene/3d/gizmos/fog_volume_gizmo_plugin.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* fog_volume_gizmo_plugin.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "fog_volume_gizmo_plugin.h"
32
33 #include "editor/editor_node.h"
34 #include "editor/editor_string_names.h"
35 #include "editor/scene/3d/gizmos/gizmo_3d_helper.h"
36 #include "editor/settings/editor_settings.h"
37 #include "scene/3d/fog_volume.h"
38
39 FogVolumeGizmoPlugin::FogVolumeGizmoPlugin() {
40 helper.instantiate();
41 Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/fog_volume");
42 create_material("shape_material", gizmo_color);
43 gizmo_color.a = 0.15;
44 create_material("shape_material_internal", gizmo_color);
45
46 create_icon_material("fog_volume_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoFogVolume"), EditorStringName(EditorIcons)));
47
48 create_handle_material("handles");
49 }
50
51 bool FogVolumeGizmoPlugin::has_gizmo(Node3D *p_spatial) {
52 return (Object::cast_to<FogVolume>(p_spatial) != nullptr);
53 }
54
55 String FogVolumeGizmoPlugin::get_gizmo_name() const {
56 return "FogVolume";
57 }
58
59 int FogVolumeGizmoPlugin::get_priority() const {
60 return -1;
61 }
62
63 String FogVolumeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
64 return helper->box_get_handle_name(p_id);
65 }
66
67 Variant FogVolumeGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
68 return Vector3(p_gizmo->get_node_3d()->call("get_size"));
69 }
70
71 void FogVolumeGizmoPlugin::begin_handle_action(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) {
72 helper->initialize_handle_action(get_handle_value(p_gizmo, p_id, p_secondary), p_gizmo->get_node_3d()->get_global_transform());
73 }
74
75 void FogVolumeGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {
76 FogVolume *fog_volume = Object::cast_to<FogVolume>(p_gizmo->get_node_3d());
77 Vector3 size = fog_volume->get_size();
78
79 Vector3 sg[2];
80 helper->get_segment(p_camera, p_point, sg);
81
82 Vector3 position;
83 helper->box_set_handle(sg, p_id, size, position);
84 fog_volume->set_size(size);
85 fog_volume->set_global_position(position);
86 }
87
88 void FogVolumeGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {
89 helper->box_commit_handle(TTR("Change FogVolume Size"), p_cancel, p_gizmo->get_node_3d());
90 }
91
92 void FogVolumeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
93 FogVolume *fog_volume = Object::cast_to<FogVolume>(p_gizmo->get_node_3d());
94
95 p_gizmo->clear();
96
97 if (fog_volume->get_shape() != RS::FOG_VOLUME_SHAPE_WORLD) {
98 const Ref<Material> material =
99 get_material("shape_material", p_gizmo);
100 const Ref<Material> material_internal =
101 get_material("shape_material_internal", p_gizmo);
102
103 Ref<Material> handles_material = get_material("handles");
104
105 Vector<Vector3> lines;
106 AABB aabb;
107 aabb.size = fog_volume->get_size();
108 aabb.position = aabb.size / -2;
109
110 for (int i = 0; i < 12; i++) {
111 Vector3 a, b;
112 aabb.get_edge(i, a, b);
113 lines.push_back(a);
114 lines.push_back(b);
115 }
116
117 Vector<Vector3> handles = helper->box_get_handles(fog_volume->get_size());
118
119 p_gizmo->add_lines(lines, material);
120 p_gizmo->add_collision_segments(lines);
121 const Ref<Material> icon = get_material("fog_volume_icon", p_gizmo);
122 p_gizmo->add_unscaled_billboard(icon, 0.05);
123 p_gizmo->add_handles(handles, handles_material);
124 }
125 }