Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose get_debug_mesh in Shape3D to scripting API #48315

Merged

Conversation

pouleyKetchoupp
Copy link
Contributor

Can be useful for custom drawing of physics shapes without having to add a collision object node to the tree.

Avoids hacks like this one (in this case, drawing a shape used in a query, not attached to a node):
https://github.com/godotengine/godot-demo-projects/blob/2ce76ff4e5abfa352a5bca4de9b1214567579b8d/3d/physics_tests/test.gd#L48-L70

Can be replaced with:

func add_shape(shape, transform, color):
	var debug_mesh = shape.get_debug_mesh()
	
	var mesh_instance = MeshInstance.new()
	mesh_instance.transform = transform
	mesh_instance.mesh = debug_mesh
	
	var material = SpatialMaterial.new()
	material.flags_unshaded = true
	material.albedo_color = color
	mesh_instance.material_override = material
	
	add_child(mesh_instance)
	_drawn_nodes.push_back(mesh_instance)

This change will also be needed after #48175 is merged, since the debug mesh node won't be available anymore.

Can be useful for custom drawing of physics shapes without having to add
a collision object node to the tree.
@akien-mga akien-mga merged commit e144ff0 into godotengine:master May 5, 2021
@akien-mga
Copy link
Member

Thanks!

@Zireael07
Copy link
Contributor

Wait... am I reading this right that this will let me draw debug stuff (areas/collisions) in DIFFERENT colors? YAAAY!

@pouleyKetchoupp
Copy link
Contributor Author

Wait... am I reading this right that this will let me draw debug stuff (areas/collisions) in DIFFERENT colors? YAAAY!

Yes, that's one of the possibilities, along with any kind of rendering options :)
Although custom debug color will be probably just added as a property in the future since it's very useful for debugging.

@pouleyKetchoupp pouleyKetchoupp deleted the expose-physics-debug-shape branch May 5, 2021 20:38
@Zireael07
Copy link
Contributor

@pouleyKetchoupp: Please please do (remember, I have a proposal open about customizing colors for debug shapes)

@Calinou
Copy link
Member

Calinou commented May 6, 2021

@pouleyKetchoupp: Please please do (remember, I have a proposal open about customizing colors for debug shapes)

There's already a PR and proposal for it: #40123 - godotengine/godot-proposals#906

It's only for 3D though – a separate PR would have to be made for 2D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants