|
@@ -158,124 +158,133 @@ void Light3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|
p_gizmo->clear();
|
|
p_gizmo->clear();
|
|
|
|
|
|
if (Object::cast_to<DirectionalLight3D>(light)) {
|
|
if (Object::cast_to<DirectionalLight3D>(light)) {
|
|
- Ref<Material> material = get_material("lines_primary", p_gizmo);
|
|
|
|
- Ref<Material> icon = get_material("light_directional_icon", p_gizmo);
|
|
|
|
|
|
+ if (p_gizmo->is_selected()) {
|
|
|
|
+ Ref<Material> material = get_material("lines_primary", p_gizmo);
|
|
|
|
|
|
- const int arrow_points = 7;
|
|
|
|
- const float arrow_length = 1.5;
|
|
|
|
|
|
+ const int arrow_points = 7;
|
|
|
|
+ const float arrow_length = 1.5;
|
|
|
|
|
|
- Vector3 arrow[arrow_points] = {
|
|
|
|
- Vector3(0, 0, -1),
|
|
|
|
- Vector3(0, 0.8, 0),
|
|
|
|
- Vector3(0, 0.3, 0),
|
|
|
|
- Vector3(0, 0.3, arrow_length),
|
|
|
|
- Vector3(0, -0.3, arrow_length),
|
|
|
|
- Vector3(0, -0.3, 0),
|
|
|
|
- Vector3(0, -0.8, 0)
|
|
|
|
- };
|
|
|
|
|
|
+ Vector3 arrow[arrow_points] = {
|
|
|
|
+ Vector3(0, 0, -1),
|
|
|
|
+ Vector3(0, 0.8, 0),
|
|
|
|
+ Vector3(0, 0.3, 0),
|
|
|
|
+ Vector3(0, 0.3, arrow_length),
|
|
|
|
+ Vector3(0, -0.3, arrow_length),
|
|
|
|
+ Vector3(0, -0.3, 0),
|
|
|
|
+ Vector3(0, -0.8, 0)
|
|
|
|
+ };
|
|
|
|
|
|
- int arrow_sides = 2;
|
|
|
|
|
|
+ int arrow_sides = 2;
|
|
|
|
|
|
- Vector<Vector3> lines;
|
|
|
|
|
|
+ Vector<Vector3> lines;
|
|
|
|
|
|
- for (int i = 0; i < arrow_sides; i++) {
|
|
|
|
- for (int j = 0; j < arrow_points; j++) {
|
|
|
|
- Basis ma(Vector3(0, 0, 1), Math_PI * i / arrow_sides);
|
|
|
|
|
|
+ for (int i = 0; i < arrow_sides; i++) {
|
|
|
|
+ for (int j = 0; j < arrow_points; j++) {
|
|
|
|
+ Basis ma(Vector3(0, 0, 1), Math_PI * i / arrow_sides);
|
|
|
|
|
|
- Vector3 v1 = arrow[j] - Vector3(0, 0, arrow_length);
|
|
|
|
- Vector3 v2 = arrow[(j + 1) % arrow_points] - Vector3(0, 0, arrow_length);
|
|
|
|
|
|
+ Vector3 v1 = arrow[j] - Vector3(0, 0, arrow_length);
|
|
|
|
+ Vector3 v2 = arrow[(j + 1) % arrow_points] - Vector3(0, 0, arrow_length);
|
|
|
|
|
|
- lines.push_back(ma.xform(v1));
|
|
|
|
- lines.push_back(ma.xform(v2));
|
|
|
|
|
|
+ lines.push_back(ma.xform(v1));
|
|
|
|
+ lines.push_back(ma.xform(v2));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ p_gizmo->add_lines(lines, material, false, color);
|
|
}
|
|
}
|
|
|
|
|
|
- p_gizmo->add_lines(lines, material, false, color);
|
|
|
|
|
|
+ Ref<Material> icon = get_material("light_directional_icon", p_gizmo);
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
|
}
|
|
}
|
|
|
|
|
|
if (Object::cast_to<OmniLight3D>(light)) {
|
|
if (Object::cast_to<OmniLight3D>(light)) {
|
|
- // Use both a billboard circle and 3 non-billboard circles for a better sphere-like representation
|
|
|
|
- const Ref<Material> lines_material = get_material("lines_secondary", p_gizmo);
|
|
|
|
- const Ref<Material> lines_billboard_material = get_material("lines_billboard", p_gizmo);
|
|
|
|
- const Ref<Material> icon = get_material("light_omni_icon", p_gizmo);
|
|
|
|
|
|
+ if (p_gizmo->is_selected()) {
|
|
|
|
+ // Use both a billboard circle and 3 non-billboard circles for a better sphere-like representation
|
|
|
|
+ const Ref<Material> lines_material = get_material("lines_secondary", p_gizmo);
|
|
|
|
+ const Ref<Material> lines_billboard_material = get_material("lines_billboard", p_gizmo);
|
|
|
|
+
|
|
|
|
+ OmniLight3D *on = Object::cast_to<OmniLight3D>(light);
|
|
|
|
+ const float r = on->get_param(Light3D::PARAM_RANGE);
|
|
|
|
+ Vector<Vector3> points;
|
|
|
|
+ Vector<Vector3> points_billboard;
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < 120; i++) {
|
|
|
|
+ // Create a circle
|
|
|
|
+ const float ra = Math::deg_to_rad((float)(i * 3));
|
|
|
|
+ const float rb = Math::deg_to_rad((float)((i + 1) * 3));
|
|
|
|
+ const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
|
|
|
|
+ const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
|
|
|
|
+
|
|
|
|
+ // Draw axis-aligned circles
|
|
|
|
+ points.push_back(Vector3(a.x, 0, a.y));
|
|
|
|
+ points.push_back(Vector3(b.x, 0, b.y));
|
|
|
|
+ points.push_back(Vector3(0, a.x, a.y));
|
|
|
|
+ points.push_back(Vector3(0, b.x, b.y));
|
|
|
|
+ points.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
+ points.push_back(Vector3(b.x, b.y, 0));
|
|
|
|
+
|
|
|
|
+ // Draw a billboarded circle
|
|
|
|
+ points_billboard.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
+ points_billboard.push_back(Vector3(b.x, b.y, 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ p_gizmo->add_lines(points, lines_material, true, color);
|
|
|
|
+ p_gizmo->add_lines(points_billboard, lines_billboard_material, true, color);
|
|
|
|
|
|
- OmniLight3D *on = Object::cast_to<OmniLight3D>(light);
|
|
|
|
- const float r = on->get_param(Light3D::PARAM_RANGE);
|
|
|
|
- Vector<Vector3> points;
|
|
|
|
- Vector<Vector3> points_billboard;
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < 120; i++) {
|
|
|
|
- // Create a circle
|
|
|
|
- const float ra = Math::deg_to_rad((float)(i * 3));
|
|
|
|
- const float rb = Math::deg_to_rad((float)((i + 1) * 3));
|
|
|
|
- const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
|
|
|
|
- const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
|
|
|
|
-
|
|
|
|
- // Draw axis-aligned circles
|
|
|
|
- points.push_back(Vector3(a.x, 0, a.y));
|
|
|
|
- points.push_back(Vector3(b.x, 0, b.y));
|
|
|
|
- points.push_back(Vector3(0, a.x, a.y));
|
|
|
|
- points.push_back(Vector3(0, b.x, b.y));
|
|
|
|
- points.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
- points.push_back(Vector3(b.x, b.y, 0));
|
|
|
|
-
|
|
|
|
- // Draw a billboarded circle
|
|
|
|
- points_billboard.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
- points_billboard.push_back(Vector3(b.x, b.y, 0));
|
|
|
|
|
|
+ Vector<Vector3> handles;
|
|
|
|
+ handles.push_back(Vector3(r, 0, 0));
|
|
|
|
+ p_gizmo->add_handles(handles, get_material("handles_billboard"), Vector<int>(), true);
|
|
}
|
|
}
|
|
|
|
|
|
- p_gizmo->add_lines(points, lines_material, true, color);
|
|
|
|
- p_gizmo->add_lines(points_billboard, lines_billboard_material, true, color);
|
|
|
|
|
|
+ const Ref<Material> icon = get_material("light_omni_icon", p_gizmo);
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
|
-
|
|
|
|
- Vector<Vector3> handles;
|
|
|
|
- handles.push_back(Vector3(r, 0, 0));
|
|
|
|
- p_gizmo->add_handles(handles, get_material("handles_billboard"), Vector<int>(), true);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (Object::cast_to<SpotLight3D>(light)) {
|
|
if (Object::cast_to<SpotLight3D>(light)) {
|
|
- const Ref<Material> material_primary = get_material("lines_primary", p_gizmo);
|
|
|
|
- const Ref<Material> material_secondary = get_material("lines_secondary", p_gizmo);
|
|
|
|
- const Ref<Material> icon = get_material("light_spot_icon", p_gizmo);
|
|
|
|
-
|
|
|
|
- Vector<Vector3> points_primary;
|
|
|
|
- Vector<Vector3> points_secondary;
|
|
|
|
- SpotLight3D *sl = Object::cast_to<SpotLight3D>(light);
|
|
|
|
|
|
+ if (p_gizmo->is_selected()) {
|
|
|
|
+ const Ref<Material> material_primary = get_material("lines_primary", p_gizmo);
|
|
|
|
+ const Ref<Material> material_secondary = get_material("lines_secondary", p_gizmo);
|
|
|
|
+
|
|
|
|
+ Vector<Vector3> points_primary;
|
|
|
|
+ Vector<Vector3> points_secondary;
|
|
|
|
+ SpotLight3D *sl = Object::cast_to<SpotLight3D>(light);
|
|
|
|
+
|
|
|
|
+ float r = sl->get_param(Light3D::PARAM_RANGE);
|
|
|
|
+ float w = r * Math::sin(Math::deg_to_rad(sl->get_param(Light3D::PARAM_SPOT_ANGLE)));
|
|
|
|
+ float d = r * Math::cos(Math::deg_to_rad(sl->get_param(Light3D::PARAM_SPOT_ANGLE)));
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < 120; i++) {
|
|
|
|
+ // Draw a circle
|
|
|
|
+ const float ra = Math::deg_to_rad((float)(i * 3));
|
|
|
|
+ const float rb = Math::deg_to_rad((float)((i + 1) * 3));
|
|
|
|
+ const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w;
|
|
|
|
+ const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * w;
|
|
|
|
+
|
|
|
|
+ points_primary.push_back(Vector3(a.x, a.y, -d));
|
|
|
|
+ points_primary.push_back(Vector3(b.x, b.y, -d));
|
|
|
|
+
|
|
|
|
+ if (i % 15 == 0) {
|
|
|
|
+ // Draw 8 lines from the cone origin to the sides of the circle
|
|
|
|
+ points_secondary.push_back(Vector3(a.x, a.y, -d));
|
|
|
|
+ points_secondary.push_back(Vector3());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- float r = sl->get_param(Light3D::PARAM_RANGE);
|
|
|
|
- float w = r * Math::sin(Math::deg_to_rad(sl->get_param(Light3D::PARAM_SPOT_ANGLE)));
|
|
|
|
- float d = r * Math::cos(Math::deg_to_rad(sl->get_param(Light3D::PARAM_SPOT_ANGLE)));
|
|
|
|
|
|
+ points_primary.push_back(Vector3(0, 0, -r));
|
|
|
|
+ points_primary.push_back(Vector3());
|
|
|
|
|
|
- for (int i = 0; i < 120; i++) {
|
|
|
|
- // Draw a circle
|
|
|
|
- const float ra = Math::deg_to_rad((float)(i * 3));
|
|
|
|
- const float rb = Math::deg_to_rad((float)((i + 1) * 3));
|
|
|
|
- const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w;
|
|
|
|
- const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * w;
|
|
|
|
|
|
+ p_gizmo->add_lines(points_primary, material_primary, false, color);
|
|
|
|
+ p_gizmo->add_lines(points_secondary, material_secondary, false, color);
|
|
|
|
|
|
- points_primary.push_back(Vector3(a.x, a.y, -d));
|
|
|
|
- points_primary.push_back(Vector3(b.x, b.y, -d));
|
|
|
|
|
|
+ Vector<Vector3> handles = {
|
|
|
|
+ Vector3(0, 0, -r),
|
|
|
|
+ Vector3(w, 0, -d)
|
|
|
|
+ };
|
|
|
|
|
|
- if (i % 15 == 0) {
|
|
|
|
- // Draw 8 lines from the cone origin to the sides of the circle
|
|
|
|
- points_secondary.push_back(Vector3(a.x, a.y, -d));
|
|
|
|
- points_secondary.push_back(Vector3());
|
|
|
|
- }
|
|
|
|
|
|
+ p_gizmo->add_handles(handles, get_material("handles"));
|
|
}
|
|
}
|
|
|
|
|
|
- points_primary.push_back(Vector3(0, 0, -r));
|
|
|
|
- points_primary.push_back(Vector3());
|
|
|
|
-
|
|
|
|
- p_gizmo->add_lines(points_primary, material_primary, false, color);
|
|
|
|
- p_gizmo->add_lines(points_secondary, material_secondary, false, color);
|
|
|
|
-
|
|
|
|
- Vector<Vector3> handles = {
|
|
|
|
- Vector3(0, 0, -r),
|
|
|
|
- Vector3(w, 0, -d)
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- p_gizmo->add_handles(handles, get_material("handles"));
|
|
|
|
|
|
+ const Ref<Material> icon = get_material("light_spot_icon", p_gizmo);
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
|
}
|
|
}
|
|
}
|
|
}
|