was there any solution found for this?, i think im running into the same issue, except im using the ‘glb’ exporter.
import model ‘gltf’, postion and scale it, export to glb, model does not keep transforms from scene.
iv tried using baketransfroms etc
sorry for the mess but heres my mash up of testing:
BABYLON.SceneLoader.ImportMesh(
undefined,
"/assets/",
halo,/////////////change the model here//////////////////////////////////
scene,
function (
meshes,
particleSystems,
skeletons,
animationList
) {
//ENV
var envTexture = new BABYLON.HDRCubeTexture("/assets/hdr/background2.hdr", scene, 10, false, false, false, true);
scene.createDefaultSkybox(envTexture, true, 0);
//scene.createDefaultCameraOrLight(false);
scene.activeCamera.attachControl(canvas, false);
//model box
let mbox = new BABYLON.Mesh.CreateBox("mbox", 2, scene);
// mbox.scaling = new BABYLON.Vector3(2, 1, 2);
let mat = new BABYLON.StandardMaterial("mat", scene);
mat.alpha = 0;
mbox.material = mat;
mbox.enableEdgesRendering();
mbox.edgesWidth = 1;
mbox.edgesColor = new BABYLON.Color4(1, 0, 1, 0.5);
//model
var model = meshes[0];
console.log(meshes)
let childMeshes = model.getChildMeshes();
let min = childMeshes[0].getBoundingInfo().boundingBox.minimumWorld;
let max = childMeshes[0].getBoundingInfo().boundingBox.maximumWorld;
for (let i = 0; i < childMeshes.length; i++) {
let meshMin = childMeshes[i].getBoundingInfo().boundingBox.minimumWorld;
let meshMax = childMeshes[i].getBoundingInfo().boundingBox.maximumWorld;
min = BABYLON.Vector3.Minimize(min, meshMin);
max = BABYLON.Vector3.Maximize(max, meshMax);
}
model.setBoundingInfo(new BABYLON.BoundingInfo(min, max));
scene.getBoundingBoxRenderer().backColor.set(0, 1, 0);
scene.getBoundingBoxRenderer().frontColor.set(0, 1, 0);
model.showBoundingBox = true;
//model.computeWorldMatrix(true);
//scale
var posX = model.getBoundingInfo().boundingBox.extendSize._x
var posY = model.getBoundingInfo().boundingBox.extendSize._y
var posZ = model.getBoundingInfo().boundingBox.extendSize._z
const findsize = [posX, posY, posZ]
let biggest = 1 / Math.max(...findsize)
model.scaling = new BABYLON.Vector3(biggest, biggest, biggest)
var height2 = model.getBoundingInfo().boundingBox.extendSizeWorld._y
if (height2 <= 0.5) {
model.scaling = new BABYLON.Vector3(biggest * 2, biggest * 2, biggest * 2)
}
if (height2 <= 0.75 && height2 > 0.5) {
model.scaling = new BABYLON.Vector3(biggest * 1.5, biggest * 1.5, biggest * 1.5)
}
//position
var centX = model.getBoundingInfo().boundingBox.centerWorld._x *= -1;
var centY = model.getBoundingInfo().boundingBox.centerWorld._y *= -1;
var centZ = model.getBoundingInfo().boundingBox.centerWorld._z *= -1;
model.position = new BABYLON.Vector3(centX, centY, centZ);
model.bakeTransformIntoVertices(model.computeWorldMatrix(true));
///////////////////DOWNLOAD FUNCTION
//scene.getMeshByName('hdrSkyBox').dispose()
//mbox.dispose();
DownLoad(scene, mbox)
}
just for reference, im trying to do this for any model uploaded by client/user, so the model can not be edited manually, as i say the transforms work exactly as i want them in the scene, but they do not save when exported.
thanks