1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

Allow CollisionObject to show collision shape meshes

Add an editor gizmo to CollisionObject.
CollisionShape no longer shows collision shapes directly.
This commit is contained in:
trollodel
2021-02-24 21:23:02 +01:00
parent aa7c298788
commit 2da6d82f3b
7 changed files with 125 additions and 34 deletions

View File

@@ -3029,6 +3029,57 @@ void BakedIndirectLightGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
////
CollisionObjectGizmoPlugin::CollisionObjectGizmoPlugin() {
const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
create_material("shape_material", gizmo_color);
const float gizmo_value = gizmo_color.get_v();
const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65);
create_material("shape_material_disabled", gizmo_color_disabled);
}
bool CollisionObjectGizmoPlugin::has_gizmo(Spatial *p_spatial) {
return Object::cast_to<CollisionObject>(p_spatial) != nullptr;
}
String CollisionObjectGizmoPlugin::get_name() const {
return "CollisionObject";
}
int CollisionObjectGizmoPlugin::get_priority() const {
return -1;
}
void CollisionObjectGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
CollisionObject *co = Object::cast_to<CollisionObject>(p_gizmo->get_spatial_node());
p_gizmo->clear();
List<uint32_t> owners;
co->get_shape_owners(&owners);
for (List<uint32_t>::Element *E = owners.front(); E; E = E->next()) {
uint32_t owner_id = E->get();
Transform xform = co->shape_owner_get_transform(owner_id);
Object *owner = co->shape_owner_get_owner(owner_id);
// Exclude CollisionShape and CollisionPolygon as they have their gizmo.
if (!Object::cast_to<CollisionShape>(owner) && !Object::cast_to<CollisionPolygon>(owner)) {
Ref<Material> material = get_material(!co->is_shape_owner_disabled(owner_id) ? "shape_material" : "shape_material_disabled", p_gizmo);
for (int shape_id = 0; shape_id < co->shape_owner_get_shape_count(owner_id); shape_id++) {
Ref<Shape> s = co->shape_owner_get_shape(owner_id, shape_id);
if (s.is_null()) {
continue;
}
SurfaceTool st;
st.append_from(s->get_debug_mesh(), 0, xform);
p_gizmo->add_mesh(st.commit(), false, Ref<SkinReference>(), material);
p_gizmo->add_collision_segments(s->get_debug_mesh_lines());
}
}
}
}
////
CollisionShapeSpatialGizmoPlugin::CollisionShapeSpatialGizmoPlugin() {
const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
create_material("shape_material", gizmo_color);