-
-
Notifications
You must be signed in to change notification settings - Fork 550
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
Feature Request: Orthographic projection in Visualizer #135
Comments
Adding orthographic projection support is much more difficult than I expected. I took me around two weeks to figure out a solution that can smoothly switch between perspective projection and orthographic projection, and eventually I'm able to work it out. 😆 Here are some notes regarding this issue: How To Fit Camera To Objecthttp://stackoverflow.com/questions/14614252/how-to-fit-camera-to-object Viewporthttps://github.com/cncjs/cncjs/blob/v1.9.0-alpha.5/src/web/widgets/Visualizer/Viewport.js Orthographic Projectionhttp://stackoverflow.com/questions/17558085/three-js-orthographic-camera const zoom = Math.min(visibleWidth / width, visibleHeight / height);
this.camera.setZoom(zoom); Perspective Projectionconst { x, y, z } = this.camera.position;
const eye = new THREE.Vector3(x, y, z);
const target = new THREE.Vector3(0, 0, 0);
// Find the distance from the camera to the closest face of the object
const distance = target.distanceTo(eye);
// The aspect ratio of the canvas (width / height)
const aspect = visibleHeight > 0 ? (visibleWidth / visibleHeight) : 1;
const fov = Math.max(
// to fit the viewport height
2 * Math.atan(height / (2 * distance)) * (180 / Math.PI),
// to fit the viewport width
2 * Math.atan((width / aspect) / (2 * distance)) * (180 / Math.PI)
);
this.camera.setFov(Math.max(fov, FOV_MIN)); CombinedCamera with TrackballControlsif ( _this.object.inOrthographicMode) {
var zoom = _this.object.zoom * (2 - factor);
_this.object.setZoom(zoom);
} else {
_eye.multiplyScalar( factor );
} My modified TrackballControls: |
Wow. Well done. Sorry this was so difficult to implement, but your diligence is amazing. I'll definitely give this a try when I start back cutting again. Might be a couple weeks. |
I went ahead and installed alpha-5, even though I'm not doing any cutting right now. Orthographic view is perfect. It doesn't look like my cut is spilling over the bounds anymore, and the toolhead position lines up with the actual position better (visually). Great job on this enhancement. |
https://threejs.org/docs/api/cameras/OrthographicCamera.html
The visualizer makes the gcode lines appear to be incorrect from top-down view. Using the orthographic camera would offer a more accurate visual representation of the gcode.
Very low priority.
The text was updated successfully, but these errors were encountered: