I for the life of me can’t get meshes to parent to a transform node when using SceneLoader.LoadMeshes. I have tried using mesh.parent = this.rootNode, mesh.setParent(this.rootNode) this.rootNode.setChildren(mesh) and at this point many other non standard ways.
What am I doing wrong? I want all of the meshes loaded from the file to be parented to a transformnode called “this.rootNode” so I can more easily position / scale. Then ideally the meshes are stored in an array. This is like Babylon 101 but I have been beating my head around it and searching for hours trying to figure out what I did wrong.
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader";
import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
import { Vector3 } from "@babylonjs/core/Maths/math";
import { Mesh } from "@babylonjs/core"
export class aNode {
public rootNode;
public name: string;
public s; // scene
public meshArray;
constructor(mediaPath, public nodeName: string, public fileName: string, s){
this.name = fileName;
this.rootNode = new TransformNode("rootNode", s);
this.rootNode.position = new Vector3(0, 0, 0);
this.makeMesh(mediaPath, fileName, s);
}
public makeMesh(mediaPath:string, fileName: string, s){
let meshPath = mediaPath + "models/" + fileName + "/";
let meshName = fileName + ".gltf"
var meshRecord = SceneLoader.ImportMesh("", meshPath, meshName, s, function(newMesh) {
newMesh.forEach(function(mesh){
mesh.setParent(this.rootNode)
})
},
function(meshProgress){
//OnProgress
},
function() {
// onError
})
}
}