-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Add CollisionShape3D custom debug colors #90644
Conversation
Honestly I NEED one of those to finally make it in! |
2ae99ba
to
c12d935
Compare
c12d935
to
249f488
Compare
249f488
to
7ce6c06
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally (rebased on top of master
292e50e), the base feature mostly works so far. This is encouraging 🙂
I noticed some issues though:
Testing project: test_pr_90644.zip
- At runtime, instead of following the properties set for each shape in the editor, the collision shape color is defined by the last collision shape that is parented to a PhysicsBody3D in the scene tree:
Editor | Runtime |
---|---|
![]() |
![]() |
- The default shape opacity is lower, which makes their outlines less visible than in
master
;
master |
This PR |
---|---|
![]() |
![]() |
I suggest leaving the default color's opacity at 255 to avoid this. That said, even with opacity set to 255, collision shape lines become slightly less opaque than in master
:
- Trimesh collision shape drawing seems to break under certain conditions, as seen in the above screenshot.
This is an issue I noticed as well, and I did my best to compensate for it. I'll see about fixing it further, but as far as I can tell, this is an issue brought about by using vertex colours as albedo. No matter what I tried, the opacity was always significantly lower, no matter whether I will look into this though, and the other issues are probably easily resolved, too. |
7ce6c06
to
5c15cb4
Compare
Sorry for the immediate double-post, but I think I figured all of these issues out:
This is actually not what was happening. It just appeared that way due to a different issue. The actual problem was that the custom colours were being set properly on the
The issue here seems to just be a mistake I made and never noticed. Debug lines were having their opacity multiplied by 0.25 inside the
I have not been able to reproduce this since making the changes described above, so I think whatever was happening there was related to either the lower-than-intended opacity, or is fixed due to the |
5c15cb4
to
9d78184
Compare
This failed the Linux / Editor w/ Mono check and I am not sure why? Could it be worth to rebase and try another push? |
I recall C# failing on CI a few weeks ago, so a rebase should fix the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is completely fine now. Something similar to this feature has been heavily requested, too.
The PR and commit title should probably be changed, as this PR modifies Shape3D.
#78273 also exists, but it's not as maintained, at all. I am to assume this PR would essentially make it redundant, but there are benefits in tying the debug color to CollisionShape3D, so it's worth keeping in mind.
9d78184
to
b528329
Compare
It would make more sense to keep the colour options in |
b528329
to
4d8fa05
Compare
In light of the recent release of Godot 4.3, I have started working on this again. I finally figured out a method for updating all |
Need to wait for the tests to pass before merge queue adding. |
This allows changing the display colour of a CollisionShape3D node on a per-shape basis. It also adds the ability to display a solid coloured preview of a CollisionShape3D. Closes godotengine/godot-proposals#906
a9220ce
to
0fc082e
Compare
Rebased to solve merge conflicts. |
Thanks! Congratulations on your first merged contribution! 🎉 |
Filled collision shapes are great. This implementation has a fundamental problem in that the meshes don't get occluded. The material should be fixed so it doesn't render on top of everything, or at least have an option that might always be on. Consider this real world scenario. I want to have a collision shape make a death zone in the riverbed. Is the collision shape in the right spot? It's impossible to tell from nearly any angle. My own filled collisionshape script creates a meshinstance with a material that shows me exactly where it is. I can fill out the river in 1/10th the time or less with this. |
Could you share your own script? It may expose the reason for the rendering to behave as is in the current PR. |
Sure. It's probably using Alpha instead of TRANSPARENCY_ALPHA_DEPTH_PRE_PASS. The script only works for boxmesh. I was planning on eventually expanding it to other shapes and make a plugin when I discovered this PR. @tool
class_name FilledCollisionShape3D
extends CollisionShape3D
@export var visible_in_game: bool = false
@export var update: bool = false : set = update_mesh
var mesh_inst: MeshInstance3D
var _timer: Timer
func update_mesh(value:bool = false) -> void:
mesh_inst.mesh.size = shape.size
func _ready() -> void:
if not ( visible_in_game or Engine.is_editor_hint() ):
return
if not shape:
shape = BoxShape3D.new()
shape.size = Vector3(10, 10, 10)
# Setup visualization
mesh_inst = MeshInstance3D.new()
mesh_inst.mesh = BoxMesh.new()
mesh_inst.mesh.size = shape.size
mesh_inst.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
add_child(mesh_inst)
var mat := StandardMaterial3D.new()
mesh_inst.set_surface_override_material(0, mat)
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
mat.albedo_color = Color(.15, .15, .15, .65)
# Update size in editor
if Engine.is_editor_hint():
_timer = Timer.new()
add_child(_timer)
Util.reconnect(_timer.timeout, update_mesh)
_timer.start(1.)
func my_set_shape(new_shape: Shape3D) -> void:
shape = new_shape
func _set(property: StringName, value: Variant) -> bool:
match property:
"shape":
my_set_shape(value)
return true
_:
return false
|
If the only thing that needs to change here is to use |
Other debug has an "x-ray" property for the debug that controls if part of the mesh (e.g. edges only) should have depth cull or not. Might want to go into that direction with settings instead of hard-coding only one material property. With transparency no matter your setting choice you will always create cases where the debug does not render correct depending on what else is going on in that project. So imo it is good to give options for users to fix that for their project. |
We should implement This likely involves exposing a constant depth offset property in BaseMaterial3D. Engines like DarkPlaces use this to prevent Z-fighting when drawing mesh-based decals and shape debug drawing: Normal
|
#100211 implements something akin to the aforementioned |
This allows changing the display colour of a collision shape preview on a per-shape basis. It also adds the ability to display a solid coloured preview of a collision shape.
Closes godotengine/godot-proposals#906
This is a feature that I had been working on independently before realising that #78273 already exists. My implementation is currently more complete, in that all collision shapes are supported, including height maps and convex/concave collision shapes. I was hesitant to make a duplicate pull request for this feature, but I was told I could do so in the comments of the other pull request.