summaryrefslogtreecommitdiff
path: root/editor/spatial_editor_gizmos.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/spatial_editor_gizmos.cpp')
-rw-r--r--editor/spatial_editor_gizmos.cpp687
1 files changed, 456 insertions, 231 deletions
diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp
index 24be2095ce..c127b9a2f1 100644
--- a/editor/spatial_editor_gizmos.cpp
+++ b/editor/spatial_editor_gizmos.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -36,6 +36,7 @@
#include "scene/resources/capsule_shape.h"
#include "scene/resources/convex_polygon_shape.h"
#include "scene/resources/plane_shape.h"
+#include "scene/resources/primitive_meshes.h"
#include "scene/resources/ray_shape.h"
#include "scene/resources/sphere_shape.h"
#include "scene/resources/surface_tool.h"
@@ -45,6 +46,24 @@
#define HANDLE_HALF_SIZE 0.05
+bool EditorSpatialGizmo::can_draw() const {
+ return is_editable();
+}
+bool EditorSpatialGizmo::is_editable() const {
+
+ ERR_FAIL_COND_V(!spatial_node, false);
+ Node *edited_root = spatial_node->get_tree()->get_edited_scene_root();
+ if (spatial_node == edited_root)
+ return true;
+ if (spatial_node->get_owner() == edited_root)
+ return true;
+
+ if (edited_root->is_editable_instance(spatial_node->get_owner()))
+ return true;
+
+ return false;
+}
+
void EditorSpatialGizmo::clear() {
for (int i = 0; i < instances.size(); i++) {
@@ -112,9 +131,9 @@ void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mat
PoolVector<Color>::Write w = color.write();
for (int i = 0; i < p_lines.size(); i++) {
if (is_selected())
- w[i] = Color(1, 1, 1, 0.6);
+ w[i] = Color(1, 1, 1, 0.8);
else
- w[i] = Color(1, 1, 1, 0.25);
+ w[i] = Color(1, 1, 1, 0.2);
}
}
@@ -157,10 +176,10 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material,
vs.push_back(Vector3(p_scale, -p_scale, 0));
vs.push_back(Vector3(-p_scale, -p_scale, 0));
- uv.push_back(Vector2(1, 0));
uv.push_back(Vector2(0, 0));
- uv.push_back(Vector2(0, 1));
+ uv.push_back(Vector2(1, 0));
uv.push_back(Vector2(1, 1));
+ uv.push_back(Vector2(0, 1));
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
Array a;
@@ -211,7 +230,7 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi
billboard_handle = p_billboard;
- if (!is_selected())
+ if (!is_selected() || !is_editable())
return;
ERR_FAIL_COND(!spatial_node);
@@ -220,7 +239,6 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi
Instance ins;
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
-#if 1
Array a;
a.resize(VS::ARRAY_MAX);
@@ -255,61 +273,6 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi
}
}
-#else
- for (int ih = 0; ih < p_handles.size(); ih++) {
-
- Vector<Vector3> vertices;
- Vector<Vector3> normals;
-
- int vtx_idx = 0;
-
-#define ADD_VTX(m_idx) \
- vertices.push_back((face_points[m_idx] * HANDLE_HALF_SIZE + p_handles[ih])); \
- normals.push_back(normal_points[m_idx]); \
- vtx_idx++;
-
- for (int i = 0; i < 6; i++) {
-
- Vector3 face_points[4];
- Vector3 normal_points[4];
- float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 };
-
- for (int j = 0; j < 4; j++) {
-
- float v[3];
- v[0] = 1.0;
- v[1] = 1 - 2 * ((j >> 1) & 1);
- v[2] = v[1] * (1 - 2 * (j & 1));
-
- for (int k = 0; k < 3; k++) {
-
- if (i < 3)
- face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
- else
- face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
- }
- normal_points[j] = Vector3();
- normal_points[j][i % 3] = (i >= 3 ? -1 : 1);
- }
- //tri 1
- ADD_VTX(0);
- ADD_VTX(1);
- ADD_VTX(2);
- //tri 2
- ADD_VTX(2);
- ADD_VTX(3);
- ADD_VTX(0);
- }
-
- Array d;
- d.resize(VS::ARRAY_MAX);
- d[VisualServer::ARRAY_NORMAL] = normals;
- d[VisualServer::ARRAY_VERTEX] = vertices;
-
- mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES, d);
- mesh->surface_set_material(ih, SpatialEditorGizmos::singleton->handle_material);
- }
-#endif
ins.mesh = mesh;
ins.billboard = p_billboard;
ins.extra_margin = true;
@@ -334,6 +297,26 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi
}
}
+void EditorSpatialGizmo::add_solid_box(Ref<Material> &p_material, Vector3 size) {
+ ERR_FAIL_COND(!spatial_node);
+
+ CubeMesh cubem;
+ cubem.set_size(size);
+ Ref<ArrayMesh> m = memnew(ArrayMesh);
+ m->add_surface_from_arrays(cubem.surface_get_primitive_type(0), cubem.surface_get_arrays(0));
+ m->surface_set_material(0, p_material);
+ add_mesh(m);
+
+ Instance ins;
+ ins.mesh = m;
+ if (valid) {
+ ins.create_instance(spatial_node);
+ VS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform());
+ }
+
+ instances.push_back(ins);
+}
+
void EditorSpatialGizmo::set_spatial_node(Spatial *p_node) {
ERR_FAIL_NULL(p_node);
@@ -560,6 +543,95 @@ void EditorSpatialGizmo::free() {
valid = false;
}
+Ref<SpatialMaterial> EditorSpatialGizmo::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) {
+
+ String name = p_name;
+
+ if (!is_editable()) {
+ name += "@readonly";
+ } else if (is_selected()) {
+ name += "@selected";
+ }
+
+ if (SpatialEditorGizmos::singleton->material_cache.has(name)) {
+ return SpatialEditorGizmos::singleton->material_cache[name];
+ }
+
+ Color color = p_color;
+
+ if (!is_editable()) {
+ color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/instanced");
+ }
+ if (!is_selected()) {
+ color.a *= 0.3;
+ }
+
+ Ref<SpatialMaterial> line_material;
+ line_material.instance();
+ line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
+ line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ if (p_use_vertex_color) {
+ line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
+ line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
+ }
+
+ if (p_billboard) {
+ line_material->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
+ }
+
+ if (p_on_top && is_selected()) {
+ line_material->set_flag(SpatialMaterial::FLAG_ONTOP, true);
+ }
+
+ line_material->set_albedo(color);
+
+ SpatialEditorGizmos::singleton->material_cache[name] = line_material;
+
+ return line_material;
+}
+
+Ref<SpatialMaterial> EditorSpatialGizmo::create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top, const Color &p_albedo) {
+
+ String name = p_name;
+
+ if (!is_editable()) {
+ name += "@readonly";
+ } else if (is_selected()) {
+ name += "@selected";
+ }
+
+ if (SpatialEditorGizmos::singleton->material_cache.has(name)) {
+ return SpatialEditorGizmos::singleton->material_cache[name];
+ }
+
+ Color color = p_albedo;
+
+ if (!is_editable()) {
+ color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/instanced");
+ } else if (!is_selected()) {
+ color.a *= 0.3;
+ }
+
+ Ref<SpatialMaterial> icon;
+ icon.instance();
+ icon->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
+ icon->set_cull_mode(SpatialMaterial::CULL_DISABLED);
+ icon->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_DISABLED);
+ icon->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ icon->set_albedo(color);
+ icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, p_texture);
+ icon->set_flag(SpatialMaterial::FLAG_FIXED_SIZE, true);
+ icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
+
+ if (p_on_top && is_selected()) {
+ icon->set_flag(SpatialMaterial::FLAG_ONTOP, true);
+ }
+
+ SpatialEditorGizmos::singleton->material_cache[name] = icon;
+
+ return icon;
+}
+
void EditorSpatialGizmo::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_lines", "lines", "material", "billboard"), &EditorSpatialGizmo::add_lines, DEFVAL(false));
@@ -573,9 +645,13 @@ void EditorSpatialGizmo::_bind_methods() {
BIND_VMETHOD(MethodInfo("redraw"));
BIND_VMETHOD(MethodInfo(Variant::STRING, "get_handle_name", PropertyInfo(Variant::INT, "index")));
- BIND_VMETHOD(MethodInfo("get_handle_value:Variant", PropertyInfo(Variant::INT, "index")));
- BIND_VMETHOD(MethodInfo("set_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera:Camera"), PropertyInfo(Variant::VECTOR2, "point")));
- MethodInfo cm = MethodInfo("commit_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore:Variant"), PropertyInfo(Variant::BOOL, "cancel"));
+
+ MethodInfo hvget(Variant::NIL, "get_handle_value", PropertyInfo(Variant::INT, "index"));
+ hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
+ BIND_VMETHOD(hvget);
+
+ BIND_VMETHOD(MethodInfo("set_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::VECTOR2, "point")));
+ MethodInfo cm = MethodInfo("commit_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel"));
cm.default_arguments.push_back(false);
BIND_VMETHOD(cm);
}
@@ -660,7 +736,7 @@ void LightSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_
Vector3 s[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
if (p_idx == 0) {
- if (light->cast_to<SpotLight>()) {
+ if (Object::cast_to<SpotLight>(light)) {
Vector3 ra, rb;
Geometry::get_closest_points_between_segments(Vector3(), Vector3(0, 0, -4096), s[0], s[1], ra, rb);
@@ -669,7 +745,7 @@ void LightSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_
d = 0;
light->set_param(Light::PARAM_RANGE, d);
- } else if (light->cast_to<OmniLight>()) {
+ } else if (Object::cast_to<OmniLight>(light)) {
Plane cp = Plane(gt.origin, p_camera->get_transform().basis.get_axis(2));
@@ -713,49 +789,54 @@ void LightSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool
void LightSpatialGizmo::redraw() {
- if (light->cast_to<DirectionalLight>()) {
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/light");
+
+ if (Object::cast_to<DirectionalLight>(light)) {
+
+ Ref<Material> material = create_material("light_directional_material", gizmo_color);
+ Ref<Material> icon = create_icon_material("light_directional_icon", SpatialEditor::get_singleton()->get_icon("GizmoDirectionalLight", "EditorIcons"));
+
+ const int arrow_points = 7;
+ const float arrow_length = 1.5;
- const int arrow_points = 5;
Vector3 arrow[arrow_points] = {
- Vector3(0, 0, 2),
- Vector3(1, 1, 2),
- Vector3(1, 1, -1),
- Vector3(2, 2, -1),
- Vector3(0, 0, -3)
+ 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 = 4;
+ int arrow_sides = 2;
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);
- Basis ma(Vector3(0, 0, 1), Math_PI * 2 * float(i) / arrow_sides);
- Basis mb(Vector3(0, 0, 1), Math_PI * 2 * float(i + 1) / arrow_sides);
-
- for (int j = 1; j < arrow_points - 1; j++) {
+ Vector3 v1 = arrow[j] - Vector3(0, 0, arrow_length);
+ Vector3 v2 = arrow[(j + 1) % arrow_points] - Vector3(0, 0, arrow_length);
- if (j != 2) {
- lines.push_back(ma.xform(arrow[j]));
- lines.push_back(ma.xform(arrow[j + 1]));
- }
- if (j < arrow_points - 1) {
- lines.push_back(ma.xform(arrow[j]));
- lines.push_back(mb.xform(arrow[j]));
- }
+ lines.push_back(ma.xform(v1));
+ lines.push_back(ma.xform(v2));
}
}
- add_lines(lines, SpatialEditorGizmos::singleton->light_material);
+ add_lines(lines, material);
add_collision_segments(lines);
- add_unscaled_billboard(SpatialEditorGizmos::singleton->light_material_directional_icon, 0.05);
+ add_unscaled_billboard(icon, 0.05);
}
- if (light->cast_to<OmniLight>()) {
+ if (Object::cast_to<OmniLight>(light)) {
+ Ref<Material> material = create_material("light_omni_material", gizmo_color, true);
+ Ref<Material> icon = create_icon_material("light_omni_icon", SpatialEditor::get_singleton()->get_icon("GizmoLight", "EditorIcons"));
clear();
- OmniLight *on = light->cast_to<OmniLight>();
+ OmniLight *on = Object::cast_to<OmniLight>(light);
float r = on->get_param(Light::PARAM_RANGE);
@@ -776,22 +857,25 @@ void LightSpatialGizmo::redraw() {
points.push_back(Vector3(b.x, b.y, 0));
}
- add_lines(points, SpatialEditorGizmos::singleton->light_material_omni, true);
+ add_lines(points, material, true);
add_collision_segments(points);
- add_unscaled_billboard(SpatialEditorGizmos::singleton->light_material_omni_icon, 0.05);
+ add_unscaled_billboard(icon, 0.05);
Vector<Vector3> handles;
handles.push_back(Vector3(r, 0, 0));
add_handles(handles, true);
}
- if (light->cast_to<SpotLight>()) {
+ if (Object::cast_to<SpotLight>(light)) {
+
+ Ref<Material> material = create_material("light_spot_material", gizmo_color, true);
+ Ref<Material> icon = create_icon_material("light_spot_icon", SpatialEditor::get_singleton()->get_icon("GizmoSpotLight", "EditorIcons"));
clear();
Vector<Vector3> points;
- SpotLight *on = light->cast_to<SpotLight>();
+ SpotLight *on = Object::cast_to<SpotLight>(light);
float r = on->get_param(Light::PARAM_RANGE);
float w = r * Math::sin(Math::deg2rad(on->get_param(Light::PARAM_SPOT_ANGLE)));
@@ -804,10 +888,6 @@ void LightSpatialGizmo::redraw() {
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w;
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * w;
- /*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, -d));
points.push_back(Vector3(b.x, b.y, -d));
@@ -821,7 +901,7 @@ void LightSpatialGizmo::redraw() {
points.push_back(Vector3(0, 0, -r));
points.push_back(Vector3());
- add_lines(points, SpatialEditorGizmos::singleton->light_material);
+ add_lines(points, material);
Vector<Vector3> handles;
handles.push_back(Vector3(0, 0, -r));
@@ -855,7 +935,7 @@ void LightSpatialGizmo::redraw() {
add_handles(handles);
add_collision_segments(collision_segments);
- add_unscaled_billboard(SpatialEditorGizmos::singleton->light_material_omni_icon, 0.05);
+ add_unscaled_billboard(icon, 0.05);
}
}
@@ -937,7 +1017,13 @@ void AudioStreamPlayer3DSpatialGizmo::redraw() {
clear();
+ Ref<Material> icon = create_icon_material("stream_player_3d_material", SpatialEditor::get_singleton()->get_icon("GizmoSpatialSamplePlayer", "EditorIcons"));
+
if (player->is_emission_angle_enabled()) {
+
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/stream_player_3d");
+ Ref<Material> material = create_material("stream_player_3d_material", gizmo_color);
+
float pc = player->get_emission_angle();
Vector<Vector3> points;
@@ -968,7 +1054,7 @@ void AudioStreamPlayer3DSpatialGizmo::redraw() {
points[200 + i * 2 + 1] = Vector3();
}
- add_lines(points, SpatialEditorGizmos::singleton->car_wheel_material);
+ add_lines(points, material);
add_collision_segments(points);
Vector<Vector3> handles;
@@ -977,7 +1063,7 @@ void AudioStreamPlayer3DSpatialGizmo::redraw() {
add_handles(handles);
}
- add_unscaled_billboard(SpatialEditorGizmos::singleton->sample_player_icon, 0.05);
+ add_unscaled_billboard(icon, 0.05);
}
AudioStreamPlayer3DSpatialGizmo::AudioStreamPlayer3DSpatialGizmo(AudioStreamPlayer3D *p_player) {
@@ -1068,6 +1154,10 @@ void CameraSpatialGizmo::redraw() {
Vector<Vector3> lines;
Vector<Vector3> handles;
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/camera");
+ Ref<Material> material = create_material("camera_material", gizmo_color);
+ Ref<Material> icon = create_icon_material("camera_icon", SpatialEditor::get_singleton()->get_icon("GizmoCamera", "EditorIcons"));
+
switch (camera->get_projection()) {
case Camera::PROJECTION_PERSPECTIVE: {
@@ -1135,8 +1225,9 @@ void CameraSpatialGizmo::redraw() {
} break;
}
- add_lines(lines, SpatialEditorGizmos::singleton->camera_material);
+ add_lines(lines, material);
add_collision_segments(lines);
+ add_unscaled_billboard(icon, 0.05);
add_handles(handles);
}
@@ -1148,9 +1239,12 @@ CameraSpatialGizmo::CameraSpatialGizmo(Camera *p_camera) {
//////
+bool MeshInstanceSpatialGizmo::can_draw() const {
+ return true; //mesh can always draw (even though nothing is displayed)
+}
void MeshInstanceSpatialGizmo::redraw() {
- Ref<ArrayMesh> m = mesh->get_mesh();
+ Ref<Mesh> m = mesh->get_mesh();
if (!m.is_valid())
return; //none
@@ -1194,10 +1288,13 @@ void SkeletonSpatialGizmo::redraw() {
clear();
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/skeleton");
+ Ref<Material> material = create_material("skeleton_material", gizmo_color);
+
Ref<SurfaceTool> surface_tool(memnew(SurfaceTool));
surface_tool->begin(Mesh::PRIMITIVE_LINES);
- surface_tool->set_material(SpatialEditorGizmos::singleton->skeleton_material);
+ surface_tool->set_material(material);
Vector<Transform> grests;
grests.resize(skel->get_bone_count());
@@ -1378,7 +1475,7 @@ SkeletonSpatialGizmo::SkeletonSpatialGizmo(Skeleton *p_skel) {
skel = p_skel;
set_spatial_node(p_skel);
}
-
+#if 0
void RoomSpatialGizmo::redraw() {
clear();
@@ -1481,6 +1578,7 @@ PortalSpatialGizmo::PortalSpatialGizmo(Portal *p_portal) {
portal = p_portal;
}
+#endif
/////
void RayCastSpatialGizmo::redraw() {
@@ -1492,7 +1590,10 @@ void RayCastSpatialGizmo::redraw() {
lines.push_back(Vector3());
lines.push_back(raycast->get_cast_to());
- add_lines(lines, SpatialEditorGizmos::singleton->raycast_material);
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape");
+ Ref<Material> material = create_material("shape_material", gizmo_color);
+
+ add_lines(lines, material);
add_collision_segments(lines);
}
@@ -1550,7 +1651,10 @@ void VehicleWheelSpatialGizmo::redraw() {
points.push_back(Vector3(0, -r, r * 2));
points.push_back(Vector3(-r * 2 * 0.2, -r, r * 2 * 0.8));
- add_lines(points, SpatialEditorGizmos::singleton->car_wheel_material);
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape");
+ Ref<Material> material = create_material("shape_material", gizmo_color);
+
+ add_lines(points, material);
add_collision_segments(points);
}
@@ -1568,22 +1672,22 @@ String CollisionShapeSpatialGizmo::get_handle_name(int p_idx) const {
if (s.is_null())
return "";
- if (s->cast_to<SphereShape>()) {
+ if (Object::cast_to<SphereShape>(*s)) {
return "Radius";
}
- if (s->cast_to<BoxShape>()) {
+ if (Object::cast_to<BoxShape>(*s)) {
return "Extents";
}
- if (s->cast_to<CapsuleShape>()) {
+ if (Object::cast_to<CapsuleShape>(*s)) {
return p_idx == 0 ? "Radius" : "Height";
}
- if (s->cast_to<RayShape>()) {
+ if (Object::cast_to<RayShape>(*s)) {
return "Length";
}
@@ -1596,25 +1700,25 @@ Variant CollisionShapeSpatialGizmo::get_handle_value(int p_idx) const {
if (s.is_null())
return Variant();
- if (s->cast_to<SphereShape>()) {
+ if (Object::cast_to<SphereShape>(*s)) {
Ref<SphereShape> ss = s;
return ss->get_radius();
}
- if (s->cast_to<BoxShape>()) {
+ if (Object::cast_to<BoxShape>(*s)) {
Ref<BoxShape> bs = s;
return bs->get_extents();
}
- if (s->cast_to<CapsuleShape>()) {
+ if (Object::cast_to<CapsuleShape>(*s)) {
Ref<CapsuleShape> cs = s;
return p_idx == 0 ? cs->get_radius() : cs->get_height();
}
- if (s->cast_to<RayShape>()) {
+ if (Object::cast_to<RayShape>(*s)) {
Ref<RayShape> cs = s;
return cs->get_length();
@@ -1636,7 +1740,7 @@ void CollisionShapeSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const P
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
- if (s->cast_to<SphereShape>()) {
+ if (Object::cast_to<SphereShape>(*s)) {
Ref<SphereShape> ss = s;
Vector3 ra, rb;
@@ -1648,7 +1752,7 @@ void CollisionShapeSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const P
ss->set_radius(d);
}
- if (s->cast_to<RayShape>()) {
+ if (Object::cast_to<RayShape>(*s)) {
Ref<RayShape> rs = s;
Vector3 ra, rb;
@@ -1660,7 +1764,7 @@ void CollisionShapeSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const P
rs->set_length(d);
}
- if (s->cast_to<BoxShape>()) {
+ if (Object::cast_to<BoxShape>(*s)) {
Vector3 axis;
axis[p_idx] = 1.0;
@@ -1676,7 +1780,7 @@ void CollisionShapeSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const P
bs->set_extents(he);
}
- if (s->cast_to<CapsuleShape>()) {
+ if (Object::cast_to<CapsuleShape>(*s)) {
Vector3 axis;
axis[p_idx == 0 ? 0 : 2] = 1.0;
@@ -1700,7 +1804,7 @@ void CollisionShapeSpatialGizmo::commit_handle(int p_idx, const Variant &p_resto
if (s.is_null())
return;
- if (s->cast_to<SphereShape>()) {
+ if (Object::cast_to<SphereShape>(*s)) {
Ref<SphereShape> ss = s;
if (p_cancel) {
@@ -1715,7 +1819,7 @@ void CollisionShapeSpatialGizmo::commit_handle(int p_idx, const Variant &p_resto
ur->commit_action();
}
- if (s->cast_to<BoxShape>()) {
+ if (Object::cast_to<BoxShape>(*s)) {
Ref<BoxShape> ss = s;
if (p_cancel) {
@@ -1730,7 +1834,7 @@ void CollisionShapeSpatialGizmo::commit_handle(int p_idx, const Variant &p_resto
ur->commit_action();
}
- if (s->cast_to<CapsuleShape>()) {
+ if (Object::cast_to<CapsuleShape>(*s)) {
Ref<CapsuleShape> ss = s;
if (p_cancel) {
@@ -1755,7 +1859,7 @@ void CollisionShapeSpatialGizmo::commit_handle(int p_idx, const Variant &p_resto
ur->commit_action();
}
- if (s->cast_to<RayShape>()) {
+ if (Object::cast_to<RayShape>(*s)) {
Ref<RayShape> ss = s;
if (p_cancel) {
@@ -1778,7 +1882,10 @@ void CollisionShapeSpatialGizmo::redraw() {
if (s.is_null())
return;
- if (s->cast_to<SphereShape>()) {
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape");
+ Ref<Material> material = create_material("shape_material", gizmo_color);
+
+ if (Object::cast_to<SphereShape>(*s)) {
Ref<SphereShape> sp = s;
float r = sp->get_radius();
@@ -1817,14 +1924,14 @@ void CollisionShapeSpatialGizmo::redraw() {
collision_segments.push_back(Vector3(b.x, b.y, 0));
}
- add_lines(points, SpatialEditorGizmos::singleton->shape_material);
+ add_lines(points, material);
add_collision_segments(collision_segments);
Vector<Vector3> handles;
handles.push_back(Vector3(r, 0, 0));
add_handles(handles);
}
- if (s->cast_to<BoxShape>()) {
+ if (Object::cast_to<BoxShape>(*s)) {
Ref<BoxShape> bs = s;
Vector<Vector3> lines;
@@ -1848,12 +1955,12 @@ void CollisionShapeSpatialGizmo::redraw() {
handles.push_back(ax);
}
- add_lines(lines, SpatialEditorGizmos::singleton->shape_material);
+ add_lines(lines, material);
add_collision_segments(lines);
add_handles(handles);
}
- if (s->cast_to<CapsuleShape>()) {
+ if (Object::cast_to<CapsuleShape>(*s)) {
Ref<CapsuleShape> cs = s;
float radius = cs->get_radius();
@@ -1889,7 +1996,7 @@ void CollisionShapeSpatialGizmo::redraw() {
points.push_back(Vector3(b.y, 0, b.x) + dud);
}
- add_lines(points, SpatialEditorGizmos::singleton->shape_material);
+ add_lines(points, material);
Vector<Vector3> collision_segments;
@@ -1928,7 +2035,7 @@ void CollisionShapeSpatialGizmo::redraw() {
add_handles(handles);
}
- if (s->cast_to<PlaneShape>()) {
+ if (Object::cast_to<PlaneShape>(*s)) {
Ref<PlaneShape> ps = s;
Plane p = ps->get_plane();
@@ -1955,13 +2062,13 @@ void CollisionShapeSpatialGizmo::redraw() {
points.push_back(p.normal * p.d);
points.push_back(p.normal * p.d + p.normal * 3);
- add_lines(points, SpatialEditorGizmos::singleton->shape_material);
+ add_lines(points, material);
add_collision_segments(points);
}
- if (s->cast_to<ConvexPolygonShape>()) {
+ if (Object::cast_to<ConvexPolygonShape>(*s)) {
- PoolVector<Vector3> points = s->cast_to<ConvexPolygonShape>()->get_points();
+ PoolVector<Vector3> points = Object::cast_to<ConvexPolygonShape>(*s)->get_points();
if (points.size() > 3) {
@@ -1977,20 +2084,20 @@ void CollisionShapeSpatialGizmo::redraw() {
points[i * 2 + 1] = md.vertices[md.edges[i].b];
}
- add_lines(points, SpatialEditorGizmos::singleton->shape_material);
+ add_lines(points, material);
add_collision_segments(points);
}
}
}
- if (s->cast_to<RayShape>()) {
+ if (Object::cast_to<RayShape>(*s)) {
Ref<RayShape> rs = s;
Vector<Vector3> points;
points.push_back(Vector3());
points.push_back(Vector3(0, 0, rs->get_length()));
- add_lines(points, SpatialEditorGizmos::singleton->shape_material);
+ add_lines(points, material);
add_collision_segments(points);
Vector<Vector3> handles;
handles.push_back(Vector3(0, 0, rs->get_length()));
@@ -2024,7 +2131,10 @@ void CollisionPolygonSpatialGizmo::redraw() {
lines.push_back(Vector3(points[i].x, points[i].y, -depth));
}
- add_lines(lines, SpatialEditorGizmos::singleton->shape_material);
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape");
+ Ref<Material> material = create_material("shape_material", gizmo_color);
+
+ add_lines(lines, material);
add_collision_segments(lines);
}
@@ -2092,6 +2202,9 @@ void VisibilityNotifierGizmo::commit_handle(int p_idx, const Variant &p_restore,
void VisibilityNotifierGizmo::redraw() {
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/visibility_notifier");
+ Ref<Material> material = create_material("visibility_notifier_material", gizmo_color);
+
clear();
Vector<Vector3> lines;
@@ -2113,7 +2226,7 @@ void VisibilityNotifierGizmo::redraw() {
handles.push_back(ax);
}
- add_lines(lines, SpatialEditorGizmos::singleton->visibility_notifier_material);
+ add_lines(lines, material);
//add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05);
add_collision_segments(lines);
add_handles(handles);
@@ -2238,9 +2351,22 @@ void ParticlesGizmo::redraw() {
lines.push_back(center + ax);
}
- add_lines(lines, SpatialEditorGizmos::singleton->particles_material);
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/particles");
+ Ref<Material> material = create_material("particles_material", gizmo_color);
+ Ref<Material> icon = create_icon_material("particles_icon", SpatialEditor::get_singleton()->get_icon("GizmoParticles", "EditorIcons"));
+
+ add_lines(lines, material);
add_collision_segments(lines);
+
+ if (is_selected()) {
+
+ gizmo_color.a = 0.1;
+ Ref<Material> solid_material = create_material("particles_solid_material", gizmo_color);
+ add_solid_box(solid_material, aabb.get_size());
+ }
+
//add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05);
+ add_unscaled_billboard(icon, 0.05);
add_handles(handles);
}
ParticlesGizmo::ParticlesGizmo(Particles *p_particles) {
@@ -2384,9 +2510,26 @@ void ReflectionProbeGizmo::redraw() {
lines.push_back(orig_handle);
}
- add_lines(lines, SpatialEditorGizmos::singleton->reflection_probe_material);
- add_lines(internal_lines, SpatialEditorGizmos::singleton->reflection_probe_material_internal);
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/reflection_probe");
+ Ref<Material> material = create_material("reflection_probe_material", gizmo_color);
+ Ref<Material> icon = create_icon_material("reflection_probe_icon", SpatialEditor::get_singleton()->get_icon("GizmoReflectionProbe", "EditorIcons"));
+
+ Color gizmo_color_internal = gizmo_color;
+ gizmo_color_internal.a = 0.5;
+ Ref<Material> material_internal = create_material("reflection_internal_material", gizmo_color_internal);
+
+ add_lines(lines, material);
+ add_lines(internal_lines, material_internal);
+
+ if (is_selected()) {
+
+ gizmo_color.a = 0.1;
+ Ref<Material> solid_material = create_material("reflection_probe_solid_material", gizmo_color);
+ add_solid_box(solid_material, probe->get_extents() * 2.0);
+ }
+
//add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05);
+ add_unscaled_billboard(icon, 0.05);
add_collision_segments(lines);
add_handles(handles);
}
@@ -2458,6 +2601,13 @@ void GIProbeGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_can
void GIProbeGizmo::redraw() {
+ Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/gi_probe");
+ Ref<Material> material = create_material("gi_probe_material", gizmo_color);
+ Ref<Material> icon = create_icon_material("gi_probe_icon", SpatialEditor::get_singleton()->get_icon("GizmoGIProbe", "EditorIcons"));
+ Color gizmo_color_internal = gizmo_color;
+ gizmo_color_internal.a = 0.1;
+ Ref<Material> material_internal = create_material("gi_probe_internal_material", gizmo_color_internal);
+
clear();
Vector<Vector3> lines;
@@ -2476,7 +2626,7 @@ void GIProbeGizmo::redraw() {
lines.push_back(b);
}
- add_lines(lines, SpatialEditorGizmos::singleton->gi_probe_material);
+ add_lines(lines, material);
add_collision_segments(lines);
lines.clear();
@@ -2521,7 +2671,7 @@ void GIProbeGizmo::redraw() {
}
}
- add_lines(lines, SpatialEditorGizmos::singleton->gi_probe_material_internal);
+ add_lines(lines, material_internal);
Vector<Vector3> handles;
@@ -2532,6 +2682,14 @@ void GIProbeGizmo::redraw() {
handles.push_back(ax);
}
+ if (is_selected()) {
+
+ gizmo_color.a = 0.1;
+ Ref<Material> solid_material = create_material("gi_probe_solid_material", gizmo_color);
+ add_solid_box(solid_material, aabb.get_size());
+ }
+
+ add_unscaled_billboard(icon, 0.05);
add_handles(handles);
}
GIProbeGizmo::GIProbeGizmo(GIProbe *p_probe) {
@@ -2544,6 +2702,11 @@ GIProbeGizmo::GIProbeGizmo(GIProbe *p_probe) {
void NavigationMeshSpatialGizmo::redraw() {
+ Ref<Material> edge_material = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_edge"));
+ Ref<Material> edge_material_disabled = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_edge_disabled"));
+ Ref<Material> solid_material = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_solid"));
+ Ref<Material> solid_material_disabled = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_solid_disabled"));
+
clear();
Ref<NavigationMesh> navmeshie = navmesh->get_navigation_mesh();
if (navmeshie.is_null())
@@ -2616,14 +2779,14 @@ void NavigationMeshSpatialGizmo::redraw() {
tmesh->create(tmeshfaces);
if (lines.size())
- add_lines(lines, navmesh->is_enabled() ? SpatialEditorGizmos::singleton->navmesh_edge_material : SpatialEditorGizmos::singleton->navmesh_edge_material_disabled);
+ add_lines(lines, navmesh->is_enabled() ? edge_material : edge_material_disabled);
add_collision_triangles(tmesh);
Ref<ArrayMesh> m = memnew(ArrayMesh);
Array a;
a.resize(Mesh::ARRAY_MAX);
a[0] = tmeshfaces;
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a);
- m->surface_set_material(0, navmesh->is_enabled() ? SpatialEditorGizmos::singleton->navmesh_solid_material : SpatialEditorGizmos::singleton->navmesh_solid_material_disabled);
+ m->surface_set_material(0, navmesh->is_enabled() ? solid_material : solid_material_disabled);
add_mesh(m);
add_collision_segments(lines);
}
@@ -2650,7 +2813,10 @@ void PinJointSpatialGizmo::redraw() {
cursor_points.push_back(Vector3(0, 0, +cs));
cursor_points.push_back(Vector3(0, 0, -cs));
add_collision_segments(cursor_points);
- add_lines(cursor_points, SpatialEditorGizmos::singleton->joint_material);
+
+ Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));
+
+ add_lines(cursor_points, material);
}
PinJointSpatialGizmo::PinJointSpatialGizmo(PinJoint *p_p3d) {
@@ -2720,8 +2886,11 @@ void HingeJointSpatialGizmo::redraw() {
cursor_points.push_back(to);
}
}
+
+ Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));
+
add_collision_segments(cursor_points);
- add_lines(cursor_points, SpatialEditorGizmos::singleton->joint_material);
+ add_lines(cursor_points, material);
}
HingeJointSpatialGizmo::HingeJointSpatialGizmo(HingeJoint *p_p3d) {
@@ -2824,8 +2993,11 @@ void SliderJointSpatialGizmo::redraw() {
cursor_points.push_back(to);
}
}
+
+ Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));
+
add_collision_segments(cursor_points);
- add_lines(cursor_points, SpatialEditorGizmos::singleton->joint_material);
+ add_lines(cursor_points, material);
}
SliderJointSpatialGizmo::SliderJointSpatialGizmo(SliderJoint *p_p3d) {
@@ -2896,8 +3068,9 @@ void ConeTwistJointSpatialGizmo::redraw() {
points.push_back(Vector3(cn, b.x, b.y));
}
+ Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));
add_collision_segments(points);
- add_lines(points, SpatialEditorGizmos::singleton->joint_material);
+ add_lines(points, material);
}
ConeTwistJointSpatialGizmo::ConeTwistJointSpatialGizmo(ConeTwistJoint *p_p3d) {
@@ -3080,8 +3253,9 @@ void Generic6DOFJointSpatialGizmo::redraw() {
#undef ADD_VTX
#undef SET_VTX
+ Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));
add_collision_segments(cursor_points);
- add_lines(cursor_points, SpatialEditorGizmos::singleton->joint_material);
+ add_lines(cursor_points, material);
}
Generic6DOFJointSpatialGizmo::Generic6DOFJointSpatialGizmo(Generic6DOFJoint *p_p3d) {
@@ -3098,168 +3272,146 @@ SpatialEditorGizmos *SpatialEditorGizmos::singleton = NULL;
Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) {
- if (p_spatial->cast_to<Light>()) {
+ if (Object::cast_to<Light>(p_spatial)) {
- Ref<LightSpatialGizmo> lsg = memnew(LightSpatialGizmo(p_spatial->cast_to<Light>()));
+ Ref<LightSpatialGizmo> lsg = memnew(LightSpatialGizmo(Object::cast_to<Light>(p_spatial)));
return lsg;
}
- if (p_spatial->cast_to<Camera>()) {
+ if (Object::cast_to<Camera>(p_spatial)) {
- Ref<CameraSpatialGizmo> lsg = memnew(CameraSpatialGizmo(p_spatial->cast_to<Camera>()));
+ Ref<CameraSpatialGizmo> lsg = memnew(CameraSpatialGizmo(Object::cast_to<Camera>(p_spatial)));
return lsg;
}
- if (p_spatial->cast_to<Skeleton>()) {
+ if (Object::cast_to<Skeleton>(p_spatial)) {
- Ref<SkeletonSpatialGizmo> lsg = memnew(SkeletonSpatialGizmo(p_spatial->cast_to<Skeleton>()));
+ Ref<SkeletonSpatialGizmo> lsg = memnew(SkeletonSpatialGizmo(Object::cast_to<Skeleton>(p_spatial)));
return lsg;
}
- if (p_spatial->cast_to<Position3D>()) {
+ if (Object::cast_to<Position3D>(p_spatial)) {
- Ref<Position3DSpatialGizmo> lsg = memnew(Position3DSpatialGizmo(p_spatial->cast_to<Position3D>()));
+ Ref<Position3DSpatialGizmo> lsg = memnew(Position3DSpatialGizmo(Object::cast_to<Position3D>(p_spatial)));
return lsg;
}
- if (p_spatial->cast_to<MeshInstance>()) {
+ if (Object::cast_to<MeshInstance>(p_spatial)) {
- Ref<MeshInstanceSpatialGizmo> misg = memnew(MeshInstanceSpatialGizmo(p_spatial->cast_to<MeshInstance>()));
+ Ref<MeshInstanceSpatialGizmo> misg = memnew(MeshInstanceSpatialGizmo(Object::cast_to<MeshInstance>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<Room>()) {
+ /*if (Object::cast_to<Room>(p_spatial)) {
- Ref<RoomSpatialGizmo> misg = memnew(RoomSpatialGizmo(p_spatial->cast_to<Room>()));
+ Ref<RoomSpatialGizmo> misg = memnew(RoomSpatialGizmo(Object::cast_to<Room>(p_spatial)));
return misg;
- }
+ }*/
- if (p_spatial->cast_to<NavigationMeshInstance>()) {
+ if (Object::cast_to<NavigationMeshInstance>(p_spatial)) {
- Ref<NavigationMeshSpatialGizmo> misg = memnew(NavigationMeshSpatialGizmo(p_spatial->cast_to<NavigationMeshInstance>()));
+ Ref<NavigationMeshSpatialGizmo> misg = memnew(NavigationMeshSpatialGizmo(Object::cast_to<NavigationMeshInstance>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<RayCast>()) {
+ if (Object::cast_to<RayCast>(p_spatial)) {
- Ref<RayCastSpatialGizmo> misg = memnew(RayCastSpatialGizmo(p_spatial->cast_to<RayCast>()));
+ Ref<RayCastSpatialGizmo> misg = memnew(RayCastSpatialGizmo(Object::cast_to<RayCast>(p_spatial)));
return misg;
}
+ /*
+ if (Object::cast_to<Portal>(p_spatial)) {
- if (p_spatial->cast_to<Portal>()) {
-
- Ref<PortalSpatialGizmo> misg = memnew(PortalSpatialGizmo(p_spatial->cast_to<Portal>()));
+ Ref<PortalSpatialGizmo> misg = memnew(PortalSpatialGizmo(Object::cast_to<Portal>(p_spatial)));
return misg;
}
+*/
+ if (Object::cast_to<CollisionShape>(p_spatial)) {
- if (p_spatial->cast_to<CollisionShape>()) {
-
- Ref<CollisionShapeSpatialGizmo> misg = memnew(CollisionShapeSpatialGizmo(p_spatial->cast_to<CollisionShape>()));
+ Ref<CollisionShapeSpatialGizmo> misg = memnew(CollisionShapeSpatialGizmo(Object::cast_to<CollisionShape>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<VisibilityNotifier>()) {
+ if (Object::cast_to<VisibilityNotifier>(p_spatial)) {
- Ref<VisibilityNotifierGizmo> misg = memnew(VisibilityNotifierGizmo(p_spatial->cast_to<VisibilityNotifier>()));
+ Ref<VisibilityNotifierGizmo> misg = memnew(VisibilityNotifierGizmo(Object::cast_to<VisibilityNotifier>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<Particles>()) {
+ if (Object::cast_to<Particles>(p_spatial)) {
- Ref<ParticlesGizmo> misg = memnew(ParticlesGizmo(p_spatial->cast_to<Particles>()));
+ Ref<ParticlesGizmo> misg = memnew(ParticlesGizmo(Object::cast_to<Particles>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<ReflectionProbe>()) {
+ if (Object::cast_to<ReflectionProbe>(p_spatial)) {
- Ref<ReflectionProbeGizmo> misg = memnew(ReflectionProbeGizmo(p_spatial->cast_to<ReflectionProbe>()));
+ Ref<ReflectionProbeGizmo> misg = memnew(ReflectionProbeGizmo(Object::cast_to<ReflectionProbe>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<GIProbe>()) {
+ if (Object::cast_to<GIProbe>(p_spatial)) {
- Ref<GIProbeGizmo> misg = memnew(GIProbeGizmo(p_spatial->cast_to<GIProbe>()));
+ Ref<GIProbeGizmo> misg = memnew(GIProbeGizmo(Object::cast_to<GIProbe>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<VehicleWheel>()) {
+ if (Object::cast_to<VehicleWheel>(p_spatial)) {
- Ref<VehicleWheelSpatialGizmo> misg = memnew(VehicleWheelSpatialGizmo(p_spatial->cast_to<VehicleWheel>()));
+ Ref<VehicleWheelSpatialGizmo> misg = memnew(VehicleWheelSpatialGizmo(Object::cast_to<VehicleWheel>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<PinJoint>()) {
+ if (Object::cast_to<PinJoint>(p_spatial)) {
- Ref<PinJointSpatialGizmo> misg = memnew(PinJointSpatialGizmo(p_spatial->cast_to<PinJoint>()));
+ Ref<PinJointSpatialGizmo> misg = memnew(PinJointSpatialGizmo(Object::cast_to<PinJoint>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<HingeJoint>()) {
+ if (Object::cast_to<HingeJoint>(p_spatial)) {
- Ref<HingeJointSpatialGizmo> misg = memnew(HingeJointSpatialGizmo(p_spatial->cast_to<HingeJoint>()));
+ Ref<HingeJointSpatialGizmo> misg = memnew(HingeJointSpatialGizmo(Object::cast_to<HingeJoint>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<SliderJoint>()) {
+ if (Object::cast_to<SliderJoint>(p_spatial)) {
- Ref<SliderJointSpatialGizmo> misg = memnew(SliderJointSpatialGizmo(p_spatial->cast_to<SliderJoint>()));
+ Ref<SliderJointSpatialGizmo> misg = memnew(SliderJointSpatialGizmo(Object::cast_to<SliderJoint>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<ConeTwistJoint>()) {
+ if (Object::cast_to<ConeTwistJoint>(p_spatial)) {
- Ref<ConeTwistJointSpatialGizmo> misg = memnew(ConeTwistJointSpatialGizmo(p_spatial->cast_to<ConeTwistJoint>()));
+ Ref<ConeTwistJointSpatialGizmo> misg = memnew(ConeTwistJointSpatialGizmo(Object::cast_to<ConeTwistJoint>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<Generic6DOFJoint>()) {
+ if (Object::cast_to<Generic6DOFJoint>(p_spatial)) {
- Ref<Generic6DOFJointSpatialGizmo> misg = memnew(Generic6DOFJointSpatialGizmo(p_spatial->cast_to<Generic6DOFJoint>()));
+ Ref<Generic6DOFJointSpatialGizmo> misg = memnew(Generic6DOFJointSpatialGizmo(Object::cast_to<Generic6DOFJoint>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<CollisionPolygon>()) {
+ if (Object::cast_to<CollisionPolygon>(p_spatial)) {
- Ref<CollisionPolygonSpatialGizmo> misg = memnew(CollisionPolygonSpatialGizmo(p_spatial->cast_to<CollisionPolygon>()));
+ Ref<CollisionPolygonSpatialGizmo> misg = memnew(CollisionPolygonSpatialGizmo(Object::cast_to<CollisionPolygon>(p_spatial)));
return misg;
}
- if (p_spatial->cast_to<AudioStreamPlayer3D>()) {
+ if (Object::cast_to<AudioStreamPlayer3D>(p_spatial)) {
- Ref<AudioStreamPlayer3DSpatialGizmo> misg = memnew(AudioStreamPlayer3DSpatialGizmo(p_spatial->cast_to<AudioStreamPlayer3D>()));
+ Ref<AudioStreamPlayer3DSpatialGizmo> misg = memnew(AudioStreamPlayer3DSpatialGizmo(Object::cast_to<AudioStreamPlayer3D>(p_spatial)));
return misg;
}
return Ref<SpatialEditorGizmo>();
}
-Ref<SpatialMaterial> SpatialEditorGizmos::create_line_material(const Color &p_base_color) {
-
- Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
- line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
- line_material->set_line_width(3.0);
- line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
- //line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
- //->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
- line_material->set_albedo(p_base_color);
-
- return line_material;
-}
-
-Ref<SpatialMaterial> SpatialEditorGizmos::create_solid_material(const Color &p_base_color) {
-
- Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
- line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
- line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
- line_material->set_albedo(p_base_color);
-
- return line_material;
-}
-
SpatialEditorGizmos::SpatialEditorGizmos() {
singleton = this;
handle_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
handle_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
+ handle_material->set_flag(SpatialMaterial::FLAG_ONTOP, true);
handle_material->set_albedo(Color(0.8, 0.8, 0.8));
handle_material_billboard = handle_material->duplicate();
handle_material_billboard->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
@@ -3274,9 +3426,29 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
handle2_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
handle2_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
handle2_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
+ handle2_material->set_flag(SpatialMaterial::FLAG_ONTOP, true);
handle2_material_billboard = handle2_material->duplicate();
handle2_material_billboard->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
-
+ handle2_material_billboard->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
+ handle2_material_billboard->set_flag(SpatialMaterial::FLAG_ONTOP, true);
+
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/light", Color(1, 1, 0.2));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/stream_player_3d", Color(0.4, 0.8, 1));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/camera", Color(0.8, 0.4, 0.8));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/skeleton", Color(1, 0.8, 0.4));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/visibility_notifier", Color(0.8, 0.5, 0.7));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/gi_probe", Color(0.5, 1, 0.6));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_edge", Color(0.5, 1, 1));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_edge_disabled", Color(0.7, 0.7, 0.7));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_solid", Color(0.5, 1, 1, 0.4));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_solid_disabled", Color(0.7, 0.7, 0.7, 0.4));
+ EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.5));
+
+#if 0
light_material = create_line_material(Color(1, 1, 0.2));
light_material_omni = create_line_material(Color(1, 1, 0.2));
light_material_omni->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
@@ -3289,6 +3461,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
light_material_omni_icon->set_albedo(Color(1, 1, 1, 0.9));
light_material_omni_icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, SpatialEditor::get_singleton()->get_icon("GizmoLight", "EditorIcons"));
light_material_omni_icon->set_flag(SpatialMaterial::FLAG_FIXED_SIZE, true);
+ light_material_omni_icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
light_material_directional_icon = Ref<SpatialMaterial>(memnew(SpatialMaterial));
light_material_directional_icon->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
@@ -3297,6 +3470,8 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
light_material_directional_icon->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
light_material_directional_icon->set_albedo(Color(1, 1, 1, 0.9));
light_material_directional_icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, SpatialEditor::get_singleton()->get_icon("GizmoDirectionalLight", "EditorIcons"));
+ light_material_directional_icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED);
+ light_material_directional_icon->set_depth_scale(1);
camera_material = create_line_material(Color(1.0, 0.5, 1.0));
@@ -3377,14 +3552,6 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
listener_line_mesh->surface_set_material(0, mat);
}
- sample_player_icon = Ref<SpatialMaterial>(memnew(SpatialMaterial));
- sample_player_icon->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
- sample_player_icon->set_cull_mode(SpatialMaterial::CULL_DISABLED);
- sample_player_icon->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_DISABLED);
- sample_player_icon->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
- sample_player_icon->set_albedo(Color(1, 1, 1, 0.9));
- sample_player_icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, SpatialEditor::get_singleton()->get_icon("GizmoSpatialSamplePlayer", "EditorIcons"));
-
room_material = create_line_material(Color(1.0, 0.6, 0.9));
portal_material = create_line_material(Color(1.0, 0.8, 0.6));
raycast_material = create_line_material(Color(1.0, 0.8, 0.6));
@@ -3463,4 +3630,62 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
}
shape_material = create_line_material(Color(0.2, 1, 1.0));
+#endif
+
+ pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
+ {
+
+ PoolVector<Vector3> cursor_points;
+ PoolVector<Color> cursor_colors;
+ float cs = 0.25;
+ cursor_points.push_back(Vector3(+cs, 0, 0));
+ cursor_points.push_back(Vector3(-cs, 0, 0));
+ cursor_points.push_back(Vector3(0, +cs, 0));
+ cursor_points.push_back(Vector3(0, -cs, 0));
+ cursor_points.push_back(Vector3(0, 0, +cs));
+ cursor_points.push_back(Vector3(0, 0, -cs));
+ cursor_colors.push_back(Color(1, 0.5, 0.5, 0.7));
+ cursor_colors.push_back(Color(1, 0.5, 0.5, 0.7));
+ cursor_colors.push_back(Color(0.5, 1, 0.5, 0.7));
+ cursor_colors.push_back(Color(0.5, 1, 0.5, 0.7));
+ cursor_colors.push_back(Color(0.5, 0.5, 1, 0.7));
+ cursor_colors.push_back(Color(0.5, 0.5, 1, 0.7));
+
+ Ref<SpatialMaterial> mat = memnew(SpatialMaterial);
+ mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
+ mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
+ mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
+ mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ mat->set_line_width(3);
+ Array d;
+ d.resize(VS::ARRAY_MAX);
+ d[Mesh::ARRAY_VERTEX] = cursor_points;
+ d[Mesh::ARRAY_COLOR] = cursor_colors;
+ pos3d_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, d);
+ pos3d_mesh->surface_set_material(0, mat);
+ }
+
+ listener_line_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
+ {
+
+ PoolVector<Vector3> cursor_points;
+ PoolVector<Color> cursor_colors;
+ cursor_points.push_back(Vector3(0, 0, 0));
+ cursor_points.push_back(Vector3(0, 0, -1.0));
+ cursor_colors.push_back(Color(0.5, 0.5, 0.5, 0.7));
+ cursor_colors.push_back(Color(0.5, 0.5, 0.5, 0.7));
+
+ Ref<SpatialMaterial> mat = memnew(SpatialMaterial);
+ mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
+ mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
+ mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
+ mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ mat->set_line_width(3);
+ Array d;
+ d.resize(VS::ARRAY_MAX);
+ d[Mesh::ARRAY_VERTEX] = cursor_points;
+ d[Mesh::ARRAY_COLOR] = cursor_colors;
+ listener_line_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, d);
+ listener_line_mesh->surface_set_material(0, mat);
+ }
}