Blender export & BoundingBox

Hello Needle,

I’m working on a project where I generate morphTargets, for this I use a python script that automatically generates morphTargets with blender from different files and then exports my final mesh to GLB format for me to import into my 3D scene.

When I import it everything works fine, my model has its target morphs etc
Except: the bounding boxes are completely broken. I understand that Blender and Three JS do not use the same types of x, y, z markers.
I need this bounding box to generate my gradients.
But I don’t understand how to solve this at all, since you are manipulating data from blender to THREE JS, I wanted to know how you would handle this problem on your side?

Original Post on Discord

by user 224464722878005248

An other example :

by user 224464722878005248

The small pheres are supposed to be placed at the maximum (red) vertex and the other at the minimum (green) of the mesh.
But this does not seem to be the real position of the vertices at all.

Here is the code that places them:

computeMeshSize(mesh) {
      let geometry = mesh.geometry;
      let positionAttribute = geometry.attributes.position;
      let min = new THREE.Vector3(Infinity, Infinity, Infinity);
      let max = new THREE.Vector3(-Infinity, -Infinity, -Infinity);
      for (let i = 0; i < positionAttribute.count; i++) {
          let vertex = new THREE.Vector3().fromBufferAttribute(positionAttribute, i);
          // vertex.applyMatrix4(mesh.matrixWorld);

      console.log(, min, max)

      // Create two sphere geometries at min and max
      let minSphere = new THREE.Mesh(new THREE.SphereGeometry(0.5), new THREE.MeshBasicMaterial({color: 0x00ff00})); // Vert
      let maxSphere = new THREE.Mesh(new THREE.SphereGeometry(0.5), new THREE.MeshBasicMaterial({color: 0xff0000})); // Rouge

      // Set the position of the spheres

      // Add the spheres to the scene
      return new THREE.Vector3().subVectors(max, min);

by user 224464722878005248

Hey, the positionAttribute values are in local space. You’ll most likely want to convert them to world space (localToWorld) and use those values for adding stuff to the scene - otherwise you’re mixing up local space calculations and world space placement