Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MCvin opened this issue Nov 18, 2021 · 3 comments

Comments

@MCvin
Copy link

MCvin commented Nov 18, 2021

Here the min and max are initialized with (0, 0, 0), before searching for the bounding box:

three-dxf/src/index.js

Lines 94 to 97 in 20e14cb

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

which doesn't work if the whole dxf is not distributed around the origin.

@MCvin
Copy link
Author

MCvin commented Nov 18, 2021

A solution could be:

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

@oubenruing
Copy link

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);

@MCvin
Copy link
Author

MCvin commented Nov 19, 2021

@oubenruing indeed your solution is way nicer!
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants