Position and scale doesn't persist in export

Hi!
I’ve got a problem, or lack of understanding, with position and scale changes. So, lets go from the beginning:
Meshes are imported in .obj format, then they are merged together (because one “object” is set of multiple smaller meshes) and their position and scale is set ( my resource .obj files are kinda skewed, thats why I have to change the scale ):

BABYLON.SceneLoader.ImportMesh("","objects/", "file_name.obj", scene, 
    function(obj){
        var combined = BABYLON.Mesh.MergeMeshes(obj, false);
        combined.scaling = new BABYLON.Vector3(0.01, 0.01, 0.01);
        combined.position = new BABYLON.Vector3(132, 1, 206);
        combined.id = 'object1';
        combined.computeWorldMatrix(true);
        meshContainer.push(combined);
    });

After that I can move them with pointer events, everything works fine when you look at them in web browser, but problem shows up when I export the whole scene into .obj file.
Imported meshes keep their scale and position ( original one ), and nothing is changed. How can I fix that?

P.S. Export function is BabylonJS objSerializer

Hello! Why not using our ObjExport?

1 Like

Hi!
Had some initial issues with it, but I got it working now.
Still the same issue persists with imported meshes positions and scale

1 Like

Pinging @brianzinn to see if he has some cycles to check

Did you try with baking transformations before exporting? Baking Transformations - Babylon.js Documentation

I have not looked at the exporter before, but hopefully we can get a repro and fix any possible issues. Can you share a .obj file with the issue? We can look at the object center and vertex positions and see what else might be going on then. I will have time next week - been working tonnes of hours the last 6 weeks :slight_smile:

Hi!
I think I did try the Baking transformations, but will try again.
Sure, here’s the file.

1 Like

Thanks for the file! Can you share your export code? I’ll try to setup a repro in the playground and we can see where the issue is. Cheers.

Export function is Babylon’s own ObjExport

1 Like

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

Can you share a Playground?

There is a topic of the_dukeness about this open:

2 Likes

Let s keep the conversation there, thanks a lot @Takemura for the reference.