blackears / cyclopsLevelBuilder

A Godot plugin to let you block in levels inside the Godot editor.
MIT License
920 stars 36 forks source link

Occlusion Culling doesn't work with exported cyclops scenes (ArrayMesh requires vertex array and index array) #162

Closed Gamepro5 closed 2 months ago

Gamepro5 commented 2 months ago

Title says it all. Click on a cyclops block and click "export to godot scene". Make an Occluder3D and set the occluder to a box. Make the box take up the entire scene. Enable occlusion culling in your project settings. If you try to Bake Occluders, it will say:

No meshes to bake.
Make sure there is at least one MeshInstance3D node in the scene whose visual layers are part of the OccluderInstance3D's Bake Mask property.

This doesn't make any sense. It doesn't say that when the meshes aren't ArrayMesh.

Edit: After taking to Clay from the Godot rendering team, the ArrayMesh must include both vertices and indices. How are the ArrayMeshes constructed in cyclops?

Calinou commented 2 months ago

I've started looking at automatically generating the index array if it's missing from the source mesh: https://github.com/Calinou/godot/tree/occluderinstance3d-bake-no-index

The code needs to be moved to the right location though as it's not being called properly by the looks of it.

blackears commented 2 months ago

The mesh is being reated in res://addons/cyclops_level_builder/math/convex_volume.gd create_mesh(). Mesh data is being loaded on line 980. The mesh is being created as an Mesh.PRIMITIVE_TRIANGLES, so it is not indexed. None the less, I was able to export my test scene with 'Export as Godot Scene...' and was able open it and add an OccluderInstance3D. I was then able to press the Bake Occluders button and it completed without any errors. I don't know how I'd verify that the occluders are actually working, but as far as I can tell they are working without any bugs.

blackears commented 2 months ago

I'm not familiar with setting up occluders. Why are you setting a box occluder before baking? Is there a way to see the occluder shapes when you're testing to verify that they're the correct shape?

Calinou commented 2 months ago

Why are you setting a box occluder before baking?

This shouldn't be required, as occluder baking will automatically create an ArrayOccluder resource to assign the baked data in.

Is there a way to see the occluder shapes when you're testing to verify that they're the correct shape?

You can see if the shape is correct after baking by enabling occlusion culling in the project settings, then set the debug draw mode to Occlusion Culling Buffer in the 3D viewport's Perspective > Debug Advanced menu. If the shape is correct, the low-resolution buffer you'll see should match the object's shape.

blackears commented 2 months ago

Cyclops is generating indexed meshes now and my tests with baking occluders are working.