godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.34k stars 21.06k forks source link

Can't create meshlib from CSG #33863

Closed Michael-Kelley closed 4 years ago

Michael-Kelley commented 4 years ago

Godot version: 3.1.1.stable.official

OS/device including version: Windows 10 1903

Issue description: When converting a scene containing only CSG meshes to a mesh library, no meshes are exported.

Steps to reproduce: Create a scene. Add at least one CSG node (can be a child of a Spatial). Convert to Mesh Library.

Minimal reproduction project: Will post if needed.

I'm currently using CSG meshes for prototyping my game and would like to be able to use them in a GridMap for a procedurally generated dungeon. Is this not currently supported, or am I likely doing something wrong?

Calinou commented 4 years ago

Is this not currently supported, or am I likely doing something wrong?

I think it's just not implemented yet, see https://github.com/godotengine/godot/issues/19232#issuecomment-484835224.

novemberist commented 4 years ago

As a temporary hack, you could do something like this in the scene where you have your csg meshes (assuming you have a Spatial Node as root)

extends Spatial
tool

var new_mesh

func _ready():
    for node in get_children():
        if ClassDB.is_parent_class(node.get_class(),"CSGShape"):
            node._update_shape()
            new_mesh = MeshInstance.new()
            new_mesh.mesh = node.get_meshes()[1]
                        new_mesh.visible = false
            add_child(new_mesh)

This will basically just create a MeshInstance for every CSGShape in the tree, using the mesh data from the CSGs, and add them to the tree. If you export as a MeshLib now, the meshes will be present. Haven't tested this with materials though...

Also there would probably be no collisions, but the script could possibly be improved to automatically generate static bodies with appropriate collision shapes.

Michael-Kelley commented 4 years ago

As a temporary hack, you could do something like this in the scene where you have your csg meshes (assuming you have a Spatial Node as root) ...

This did the trick, thank you. A proper fix for this would be nice, but this workaround is good enough for now. I also added new_mesh.create_trimesh_collision() to create collisions. I did notice that I had to restart the Godot editor to get it to correctly show the updated meshlib resource.

mhilbrunner commented 4 years ago

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!