Can't center STL on Origin, Possible bug

just a standard box

Hmmm that’s really odd because a box is what I used to originally test.

Maybe we just need an argument for reversing the winding?

Okay, I tested box and sphere,
apart from the mesh data tripling on every export, (can this be avoided?)
both look fine in win10 3d app…

could it be the loader? … but then Bob_R’s head mesh should have problems too… it doesnt until after export from babylon

I’m not sure, there is nothing in the code that would cause that if you look over it.

The logic for stls is really simple, not much that can go wrong. This also is new behavior so I’m wondering what changed that is causing this.

don’t ask me how, but swapping the v.y & v.z values, aswell as negating n vector3 appears to have fixed the export…

let getFaceData = function(indices, vertices, i) {
    let id = [indices[i] * 3, indices[i + 1] * 3, indices[i + 2] * 3];
    let v = [
        new BABYLON.Vector3(vertices[id[0]], vertices[id[0] + 2], vertices[id[0] + 1]),
        new BABYLON.Vector3(vertices[id[1]], vertices[id[1] + 2], vertices[id[1] + 1]),
        new BABYLON.Vector3(vertices[id[2]], vertices[id[2] + 2], vertices[id[2] + 1])
    ];
    let p1p2 = v[0].subtract(v[1]);
    let p3p2 = v[2].subtract(v[1]);
    let n = (BABYLON.Vector3.Cross(p1p2, p3p2)).normalize().negateInPlace();

    return {v, n};
};

Also notised that only the binary export bloats size x3,
not quite sure why…
indices gets bloated and follows the index, 0:0, 1:1, 2:2, 3:3, etc
positions array is filled with 3 0’s for each extra indice.

Edit;
Got it… faceCount was indices.length, should be divided by 3 to get actual count of faces (triangles)


:+1:

Not sure why the binary one does that, maybe @RaananW would know?

It was the faceCount :slight_smile: