Improve the AudioStreamPlayer3D gizmo
This adds more lines to the emission angle cone to give a better feel of depth in the 3D world.
This commit is contained in:
parent
0c3335d1f3
commit
0feff49375
1 changed files with 28 additions and 24 deletions
|
@ -1074,7 +1074,8 @@ AudioStreamPlayer3DSpatialGizmoPlugin::AudioStreamPlayer3DSpatialGizmoPlugin() {
|
|||
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/stream_player_3d", Color(0.4, 0.8, 1));
|
||||
|
||||
create_icon_material("stream_player_3d_icon", SpatialEditor::get_singleton()->get_icon("GizmoSpatialSamplePlayer", "EditorIcons"));
|
||||
create_material("stream_player_3d_material", gizmo_color);
|
||||
create_material("stream_player_3d_material_primary", gizmo_color);
|
||||
create_material("stream_player_3d_material_secondary", gizmo_color * Color(1, 1, 1, 0.35));
|
||||
create_handle_material("handles");
|
||||
}
|
||||
|
||||
|
@ -1160,50 +1161,53 @@ void AudioStreamPlayer3DSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_
|
|||
|
||||
void AudioStreamPlayer3DSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
|
||||
AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node());
|
||||
const AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node());
|
||||
|
||||
p_gizmo->clear();
|
||||
|
||||
Ref<Material> icon = get_material("stream_player_3d_icon", p_gizmo);
|
||||
const Ref<Material> icon = get_material("stream_player_3d_icon", p_gizmo);
|
||||
|
||||
if (player->is_emission_angle_enabled()) {
|
||||
|
||||
Ref<Material> material = get_material("stream_player_3d_material", p_gizmo);
|
||||
const float pc = player->get_emission_angle();
|
||||
const float ofs = -Math::cos(Math::deg2rad(pc));
|
||||
const float radius = Math::sin(Math::deg2rad(pc));
|
||||
|
||||
float pc = player->get_emission_angle();
|
||||
|
||||
Vector<Vector3> points;
|
||||
points.resize(208);
|
||||
|
||||
float ofs = -Math::cos(Math::deg2rad(pc));
|
||||
float radius = Math::sin(Math::deg2rad(pc));
|
||||
Vector<Vector3> points_primary;
|
||||
points_primary.resize(200);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
float a = i * 2.0 * Math_PI / 100.0;
|
||||
float an = (i + 1) * 2.0 * Math_PI / 100.0;
|
||||
const float a = i * 2.0 * Math_PI / 100.0;
|
||||
const float an = (i + 1) * 2.0 * Math_PI / 100.0;
|
||||
|
||||
Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs);
|
||||
Vector3 to(Math::sin(an) * radius, Math::cos(an) * radius, ofs);
|
||||
const Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs);
|
||||
const Vector3 to(Math::sin(an) * radius, Math::cos(an) * radius, ofs);
|
||||
|
||||
points.write[i * 2 + 0] = from;
|
||||
points.write[i * 2 + 1] = to;
|
||||
points_primary.write[i * 2 + 0] = from;
|
||||
points_primary.write[i * 2 + 1] = to;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const Ref<Material> material_primary = get_material("stream_player_3d_material_primary", p_gizmo);
|
||||
p_gizmo->add_lines(points_primary, material_primary);
|
||||
|
||||
float a = i * 2.0 * Math_PI / 4.0;
|
||||
Vector<Vector3> points_secondary;
|
||||
points_secondary.resize(16);
|
||||
|
||||
Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
|
||||
points.write[200 + i * 2 + 0] = from;
|
||||
points.write[200 + i * 2 + 1] = Vector3();
|
||||
const float a = i * 2.0 * Math_PI / 8.0;
|
||||
const Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs);
|
||||
|
||||
points_secondary.write[i * 2 + 0] = from;
|
||||
points_secondary.write[i * 2 + 1] = Vector3();
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(points, material);
|
||||
const Ref<Material> material_secondary = get_material("stream_player_3d_material_secondary", p_gizmo);
|
||||
p_gizmo->add_lines(points_secondary, material_secondary);
|
||||
|
||||
Vector<Vector3> handles;
|
||||
float ha = Math::deg2rad(player->get_emission_angle());
|
||||
const float ha = Math::deg2rad(player->get_emission_angle());
|
||||
handles.push_back(Vector3(Math::sin(ha), 0, -Math::cos(ha)));
|
||||
p_gizmo->add_handles(handles, get_material("handles"));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue