Center the SVG to the viewport of threejs

This commit is contained in:
Tyler Marques 2025-03-05 15:20:50 -05:00
parent 9dc6972b75
commit 00a5f5d179
No known key found for this signature in database
GPG key ID: 7672EFD79378341C
2 changed files with 46 additions and 140 deletions

View file

@ -576,6 +576,16 @@
}
// This rotates the SVG the "correct" way round, and scales it down
group.scale.set(0.5, -0.5, 0.5)
// After adding all meshes to the group, update its matrix:
group.updateMatrixWorld(true);
// Compute the bounding box of the group:
const box = new THREE.Box3().setFromObject(group);
const center = new THREE.Vector3();
box.getCenter(center);
// Offset the group's position by subtracting the center:
group.position.sub(center);
scene.add(group);
},