1
1
#include " ak_event_3d_gizmo_plugin.h"
2
2
3
+ AkEvent3DGizmoPlugin::AkEvent3DGizmoPlugin ()
4
+ {
5
+ create_icon_material (" ak_event_3d_icon" ,
6
+ EditorInterface::get_singleton ()->get_editor_theme ()->get_icon (
7
+ SNAME (" Gizmo3DSamplePlayer" ), SNAME (" EditorIcons" )));
8
+ create_material (" ak_event_3d_material_billboard" , Color (1 , 1 , 1 ), true , false , true );
9
+ }
10
+
3
11
bool AkEvent3DGizmoPlugin::_has_gizmo (Node3D* for_node_3d) const
4
12
{
5
13
if (for_node_3d)
@@ -13,22 +21,55 @@ String AkEvent3DGizmoPlugin::_get_gizmo_name() const { return "AkEvent3DGizmo";
13
21
14
22
int32_t AkEvent3DGizmoPlugin::_get_priority () const { return -1 ; }
15
23
16
- void AkEvent3DGizmoPlugin::_redraw (const Ref<EditorNode3DGizmo>& gizmo )
24
+ void AkEvent3DGizmoPlugin::_redraw (const Ref<EditorNode3DGizmo>& p_gizmo )
17
25
{
18
- gizmo ->clear ();
26
+ p_gizmo ->clear ();
19
27
20
- if (!texture.is_valid ())
28
+ float r = 0 ;
29
+ AkEvent3D* ak_event = Object::cast_to<AkEvent3D>(p_gizmo->get_node_3d ());
30
+ if (ak_event)
21
31
{
22
- texture = ResourceLoader::get_singleton ()->load (ak_event_speaker_path);
23
-
24
- if (!texture.is_valid ())
32
+ auto event = ak_event->get_event ();
33
+ if (event.is_valid ())
25
34
{
26
- return ;
35
+ auto project_data = WwiseProjectInfo::get_singleton ()->get_data ();
36
+ if (project_data.is_valid ())
37
+ {
38
+ r = project_data->get_event_max_attenuation (event->get_id ());
39
+ }
27
40
}
41
+ }
42
+
43
+ // note (afama): Based on code from:
44
+ // https://github.com/godotengine/godot/blob/4.4/editor/plugins/gizmos/audio_stream_player_3d_gizmo_plugin.cpp
45
+ // Used to resemble the AudioStreamPlayer3D gizmo.
46
+ // License: godotengine.org/license
47
+ const Ref<Material> lines_billboard_material = get_material (" ak_event_3d_material_billboard" , p_gizmo);
48
+
49
+ PackedVector3Array points_billboard;
28
50
29
- create_icon_material (" ak_event_3d_icon_material" , texture);
51
+ for (int i = 0 ; i < 120 ; i++)
52
+ {
53
+ // Create a circle.
54
+ const float ra = Math::deg_to_rad ((float )(i * 3 ));
55
+ const float rb = Math::deg_to_rad ((float )((i + 1 ) * 3 ));
56
+ const Point2 a = Vector2 (Math::sin (ra), Math::cos (ra)) * r;
57
+ const Point2 b = Vector2 (Math::sin (rb), Math::cos (rb)) * r;
58
+
59
+ // Draw a billboarded circle.
60
+ points_billboard.push_back (Vector3 (a.x , a.y , 0 ));
61
+ points_billboard.push_back (Vector3 (b.x , b.y , 0 ));
30
62
}
31
63
32
- Ref<StandardMaterial3D> material = get_material (" ak_event_3d_icon_material" , gizmo);
33
- gizmo->add_unscaled_billboard (material, 0.05 );
64
+ Color color = Color (0.4 , 0.8 , 1 );
65
+
66
+ if (r > CMP_EPSILON)
67
+ {
68
+ color.set_h (color.get_h () + 0.5 );
69
+ }
70
+
71
+ p_gizmo->add_lines (points_billboard, lines_billboard_material, true , color);
72
+
73
+ const Ref<Material> icon = get_material (" ak_event_3d_icon" , p_gizmo);
74
+ p_gizmo->add_unscaled_billboard (icon, 0.05 );
34
75
}
0 commit comments