I have couple hundred objects that I want to bring in, doing this manually would take me a while both export and import.
All these objects are separate objects in Blender. I select them and export them as GLTF. It is all good, but when I import them in to Godot (drag n drop) they come in as one single object, I put it in the viewport they are all like a single object. I want to be able to modify them individually in Godot.
If I import that gltf file back into Blender, I see that they are all individual objects so it does not look like these are combined during the export.
I can definitely see legit use cases of having multiple objects within a single blend file.
At least for importing, recently I needed to do something similar where I packed the different pieces into a single scene that was then saved to disk. This was for creating a group of rigid bodies but you can hopefully get the general idea of creating single scenes out of multiple models.
@tool
extends EditorScript
func _run():
var root = Node3D.new()
root.name = "BridgeGlassPieces"
root.set_script(load("res://scripts/bridge_glass_pieces.gd"))
var box_shape = BoxShape3D.new()
box_shape.size = Vector3(0.2, 0.02, 0.2)
for i in 12:
var glb_scene = load("res://models/bridge_glass_pieces_" + str(i + 1) + ".glb")
var glb_instance = glb_scene.instantiate()
var glb_mesh_instance = glb_instance.get_child(0)
var mesh_instance = MeshInstance3D.new()
mesh_instance.mesh = glb_mesh_instance.mesh
mesh_instance.name = "MeshInstance3D"
var collision_shape = CollisionShape3D.new()
collision_shape.shape = box_shape
collision_shape.name = "CollisionShape3D"
var rigid_body = RigidBody3D.new()
rigid_body.can_sleep = false
rigid_body.position = glb_mesh_instance.position
rigid_body.name = "GlassPiece" + str(i)
rigid_body.add_child(mesh_instance)
rigid_body.add_child(collision_shape)
root.add_child(rigid_body)
rigid_body.owner = root
mesh_instance.owner = root
collision_shape.owner = root
var packed_scene = PackedScene.new()
packed_scene.pack(root)
var scene_path = "res://scenes/bridge_glass_pieces.tscn"
var error = ResourceSaver.save(packed_scene, scene_path)
if not error:
print("Saving scene: " + scene_path)
You’d still need to export them individually or use the Blender addon mentioned.
Does your script create the necessary nodes in the actual editor or this is just a runtime access script?
I am moving to Godot slowly so I do not know all the stuff. Do we have some kind of automation scripting in Godot (not sure if I can use Gdscript to automate in editor stuff atm) ? So that I can maybe automate the import process?
This script would be something you run in the editor to create the scene resources themselves. Then you can use them however you want such as creating them in the editor or via a script at run time.
Here’s the docs on EditorScripts
Instead of attaching the script to a node, you can either go File > Run or press Ctrl + Shift + X to run it.