Create a Meshlib/3DGrid of scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Liemaeu

I have created multiple scenes in Godot and want to place them as a 3D Grid.

Some example scenes:

When I convert them to an Meshlib only the default cube meshes (1 x 1 x 1 size) are added to it, not like I have created them.

Is there any way to add the scenes as I created them to a 3D Grid? Or do I have to redo all work in Blender?

:bust_in_silhouette: Reply From: Lopy

The “Convert to → MeshLibrary” button always stretches meshes so that their bounds fit exactly in one block. However, this annoying behavior can be avoided, by not using the button.

MeshLibrary extends Resource, and has all the method you need to create it in GDScript.

To create an empty MeshLibrary, just call Once it is filled, use
Make yourself a list of Meshes, (or just iterate over a Directory containing them), then for each one, call my_mesh_library.create_item(), and set:

  • item name
  • item mesh
  • item shape (use my_mesh.create_convex_shape())
  • item preview (use get_editor_interface().make_mesh_previews() in a tool script extending EditorScript).

Writing code to create your MeshLibrary is tedious, but allows for more possibilities, and future Mesh additions are more practical.

Edit: Not to be confused between Mesh and MeshInstance. Mesh is a Resource that contains faces, Materials, etc, whereas MeshInstance is a Spatial that displays a Mesh. (get_node(“Mesh1”).mesh)

Thank you very much!

I created a test file with a couple of meshes, but when I set the mesh: TestMeshlib.set_item_mesh(0, get_node("Mesh1"))

The mesh is not set for a reason. (The node of the type MeshInstance Mesh1 exists).

When I run: print(TestMeshlib.get_item_mesh(0)) it outputs: [Object:null]

The code looks like this at the moment:

func _ready():
    var TestMeshlib =
    TestMeshlib.set_item_name(0, "Box")
    TestMeshlib.set_item_mesh(0, get_node("Mesh1"))"res://TestMeshlib.meshlib", TestMeshlib)

Liemaeu | 2021-02-09 08:59

I tired it with get_node(“Mesh1”).mesh, but then I get the error: Invalid get index ‘mesh’ (on base: ‘null instance’).

My new code (

extends Spatial

func _ready():
    var TestMeshlib =
	TestMeshlib.set_item_name(0, "Box")
	TestMeshlib.set_item_mesh(0, get_node("Mesh1").mesh)"res://TestMeshlib.meshlib", TestMeshlib)

Liemaeu | 2021-02-10 08:22