three-dxf
three-dxf copied to clipboard
The canvas doesn't center on dxf drawings which are not centered around (0, 0, 0)
Here the min and max are initialized with (0, 0, 0), before searching for the bounding box: https://github.com/gdsestimating/three-dxf/blob/20e14cbd13735e16a1b691f7b864936dd688fb74/src/index.js#L94-L97 which doesn't work if the whole dxf is not distributed around the origin.
A solution could be:
var dims = {
min: { x: Infinity, y: Infinity, z: Infinity },
max: { x: -Infinity, y: -Infinity, z: -Infinity }
};
After adding all the 3d objects to the scene, just calculate the bounding box of the scene. Here's how I did it:
for (let i = 0; i < data.entities.length; i++) {
const entity = data.entities[i];
let obj = this.painter.draw(entity, data);
if (obj) {
this.scene.add(obj);
}
obj = null;
}
// ……
const dims = new THREE.Box3().setFromObject(this.scene);
@oubenruing indeed your solution is way nicer! Thanks!