three-dxf icon indicating copy to clipboard operation
three-dxf copied to clipboard

The canvas doesn't center on dxf drawings which are not centered around (0, 0, 0)

Open MCvin opened this issue 3 years ago • 3 comments

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.

MCvin avatar Nov 18 '21 16:11 MCvin

A solution could be:

    var dims = {
        min: { x: Infinity, y: Infinity, z: Infinity },
        max: { x: -Infinity, y: -Infinity, z: -Infinity }
    };

MCvin avatar Nov 18 '21 16:11 MCvin

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 avatar Nov 19 '21 02:11 oubenruing

@oubenruing indeed your solution is way nicer! Thanks!

MCvin avatar Nov 19 '21 08:11 MCvin