diff options
Diffstat (limited to 'editor/spatial_editor_gizmos.cpp')
-rw-r--r-- | editor/spatial_editor_gizmos.cpp | 79 |
1 files changed, 58 insertions, 21 deletions
diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 722f651959..3f8d93d976 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -211,9 +211,10 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, instances.push_back(ins); } -void EditorSpatialGizmo::add_collision_triangles(const Ref<TriangleMesh> &p_tmesh) { +void EditorSpatialGizmo::add_collision_triangles(const Ref<TriangleMesh> &p_tmesh, const Rect3 &p_bounds) { collision_mesh = p_tmesh; + collision_mesh_bounds = p_bounds; } void EditorSpatialGizmo::add_collision_segments(const Vector<Vector3> &p_lines) { @@ -297,13 +298,24 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi } } -void EditorSpatialGizmo::add_solid_box(Ref<Material> &p_material, Vector3 size) { +void EditorSpatialGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size) { + ERR_FAIL_COND(!spatial_node); + CubeMesh cubem; - cubem.set_size(size); + cubem.set_size(p_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) { @@ -348,6 +360,29 @@ bool EditorSpatialGizmo::intersect_frustum(const Camera *p_camera, const Vector< return false; } + if (collision_mesh_bounds.size != Vector3(0.0, 0.0, 0.0)) { + Transform t = spatial_node->get_global_transform(); + const Plane *p = p_frustum.ptr(); + int fc = p_frustum.size(); + + Vector3 mins = t.xform(collision_mesh_bounds.get_position()); + Vector3 max = t.xform(collision_mesh_bounds.get_position() + collision_mesh_bounds.get_size()); + + bool any_out = false; + + for (int j = 0; j < fc; j++) { + + if (p[j].distance_to(mins) > 0 || p[j].distance_to(max) > 0) { + + any_out = true; + break; + } + } + + if (!any_out) + return true; + } + return false; } @@ -569,7 +604,7 @@ Ref<SpatialMaterial> EditorSpatialGizmo::create_material(const String &p_name, c } if (p_on_top && is_selected()) { - line_material->set_flag(SpatialMaterial::FLAG_ONTOP, true); + line_material->set_on_top_of_alpha(); } line_material->set_albedo(color); @@ -613,7 +648,7 @@ Ref<SpatialMaterial> EditorSpatialGizmo::create_icon_material(const String &p_na icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); if (p_on_top && is_selected()) { - icon->set_flag(SpatialMaterial::FLAG_ONTOP, true); + icon->set_on_top_of_alpha(); } SpatialEditorGizmos::singleton->material_cache[name] = icon; @@ -626,7 +661,7 @@ void EditorSpatialGizmo::_bind_methods() { ClassDB::bind_method(D_METHOD("add_lines", "lines", "material", "billboard"), &EditorSpatialGizmo::add_lines, DEFVAL(false)); ClassDB::bind_method(D_METHOD("add_mesh", "mesh", "billboard", "skeleton"), &EditorSpatialGizmo::add_mesh, DEFVAL(false), DEFVAL(RID())); ClassDB::bind_method(D_METHOD("add_collision_segments", "segments"), &EditorSpatialGizmo::add_collision_segments); - ClassDB::bind_method(D_METHOD("add_collision_triangles", "triangles"), &EditorSpatialGizmo::add_collision_triangles); + ClassDB::bind_method(D_METHOD("add_collision_triangles", "triangles", "bounds"), &EditorSpatialGizmo::add_collision_triangles); ClassDB::bind_method(D_METHOD("add_unscaled_billboard", "material", "default_scale"), &EditorSpatialGizmo::add_unscaled_billboard, DEFVAL(1)); ClassDB::bind_method(D_METHOD("add_handles", "handles", "billboard", "secondary"), &EditorSpatialGizmo::add_handles, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_spatial_node", "node"), &EditorSpatialGizmo::_set_spatial_node); @@ -634,9 +669,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); } @@ -705,7 +744,7 @@ static float _find_closest_angle_to_half_pi_arc(const Vector3 &p_from, const Vec } //min_p = p_arc_xform.affine_inverse().xform(min_p); - float a = Vector2(min_p.x, -min_p.z).angle(); + float a = (Math_PI * 0.5) - Vector2(min_p.x, -min_p.z).angle(); return a * 180.0 / Math_PI; } @@ -854,7 +893,7 @@ void LightSpatialGizmo::redraw() { if (Object::cast_to<SpotLight>(light)) { - Ref<Material> material = create_material("light_spot_material", gizmo_color, true); + Ref<Material> material = create_material("light_spot_material", gizmo_color); Ref<Material> icon = create_icon_material("light_spot_icon", SpatialEditor::get_singleton()->get_icon("GizmoSpotLight", "EditorIcons")); clear(); @@ -873,10 +912,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)); @@ -1238,8 +1273,10 @@ void MeshInstanceSpatialGizmo::redraw() { return; //none Ref<TriangleMesh> tm = m->generate_triangle_mesh(); - if (tm.is_valid()) - add_collision_triangles(tm); + if (tm.is_valid()) { + Rect3 aabb; + add_collision_triangles(tm, aabb); + } } MeshInstanceSpatialGizmo::MeshInstanceSpatialGizmo(MeshInstance *p_mesh) { @@ -3400,7 +3437,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { 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_on_top_of_alpha(); 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); @@ -3415,11 +3452,11 @@ 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->set_on_top_of_alpha(); 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); + handle2_material_billboard->set_on_top_of_alpha(); 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)); @@ -3479,7 +3516,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { skeleton_material = create_line_material(Color(0.6, 1.0, 0.3)); skeleton_material->set_cull_mode(SpatialMaterial::CULL_DISABLED); skeleton_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - skeleton_material->set_flag(SpatialMaterial::FLAG_ONTOP, true); + skeleton_material->set_on_top_of_alpha(); skeleton_material->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_DISABLED); //position 3D Shared mesh |