I have imported a teeth object which has around 64 meshes. I want to create a cube object on front face of all the meshes. I’m able to do this with scene.pick when clicking on the scene. But I want to do this on loading all the meshes without binding any actions to it. I have tried mesh.getBoundingInfo but it adds the cube in the spherical centre of the object. Any thoughts would greatly help. Thanks in advance!
function addBracketsForAllTooth() {
if(teethRoot){
const tooth = teethRoot.getChildMeshes();
tooth.map((mesh) => {
const name = mesh.name.split('_')[0];
if(name.slice(name.length - 1) !== 'r'){
if (mesh._children && mesh._children[0] && mesh._children[0].name.includes('picker_cube')) {
// alert('Bracket already present');
return false;
}
else{
var mat = new BABYLON.StandardMaterial('mat1', this.scene);
mat.diffuseColor = new BABYLON.Color3(1, 0, 0);
var cube = BABYLON.MeshBuilder.CreateBox(
'picker_cube' + bracketCount,
{ size: 0.20, height: 0.20 },
scene
);
cube.position = mesh.getBoundingInfo().boundingSphere.center;
cube.parent = mesh;
cube.metadata = {'type': 'bracket'};
bracketCount ++;
cube.material = mat;
/* Rotating the cube -- Start */
/*var axis1 = pickResult.getNormal();
var axis2 = BABYLON.Vector3.Up();
var axis3 = BABYLON.Vector3.Up();
var start = new BABYLON.Vector3(Math.PI / 2, Math.PI / 2, 0); //camera.position
BABYLON.Vector3.CrossToRef(start, axis1, axis2);
BABYLON.Vector3.CrossToRef(axis2, axis1, axis3);
var tmpVec = BABYLON.Vector3.RotationFromAxis(axis3.negate(), axis1, axis2);
var quat = BABYLON.Quaternion.RotationYawPitchRoll(tmpVec.y, tmpVec.x, tmpVec.z);
cube.rotationQuaternion = quat;*/
/* Rotating the cube -- End */
}
}
});
}
}
