I have a model in Blender with multiple parts (meshes).
At the moment it only has 4 different meshes and I call:
scene.getMeshByName(mesh_name).clone(new_mesh_name, parent_node)
on all 4 of them every time I want to make a new instance of this model with its multiple meshes:
function get_mesh (scene: Scene, mesh_name: string, new_mesh_name: string, parent_node: Node)
{
return scene.getMeshByName(mesh_name)?.clone(new_mesh_name, parent_node)!
}
export function create_house (scene: Scene, shadow_generator: ShadowGenerator, position: Vector3, name: string)
{
const house_parent = new TransformNode("house_parent_" + name)
const house_walls = get_mesh(scene, "low_poly_house_2_walls", "house_walls_" + name, house_parent)
const house_roof = get_mesh(scene, "low_poly_house_2_roof", "house_roof_" + name, house_parent)
const house_door_frame = get_mesh(scene, "low_poly_house_2_door_frame", "house_door_frame_" + name, house_parent)
const house_door = get_mesh(scene, "low_poly_house_2_door," "house_door_" + name, house_parent)
...
I can see in the pirate fort example here that the example of the cannon relies on being able to call: cannon = cannonImportResult.meshes[0].getChildren()[0]
.
Even though my 4 meshes are nested under what I think is a top level “Mesh Object” (orange triangle in Blender, with name low_poly_house_2
), when I use the assets_manager.onTaskSuccess
, the task.loadedMeshes[1].getChildren()
returns an empty list despite task.loadedMeshes[1].name === “low_poly_house_2”. And later, using scene.getMeshByName("low_poly_house_2").getChildren()
also returns an empty list…?
Obviously once you get more models and those have more sub meshes, it gets much more brittle & expensive to remember to individually clone all the submeshes to form a model.
Is this something that exporting from Blender to GLTF / GLB affords you that exporting to OBJ does not? Or is there a different way to go about modelling in blender that allows for the BabylonJS import to hold all the child meshes under a single parent mesh?
Demo repo here with specific code in question here and blender model here.