vagran / dxf-viewer

DXF 2D viewer written in JavaScript
Mozilla Public License 2.0
290 stars 86 forks source link

3D depiction of dxf-data #99

Closed MartinPyka closed 6 months ago

MartinPyka commented 6 months ago

Is it just a matter of adding the proper controls to the web application or is there more to be implemented, if one wants to be able to rotate the 3d-object and look at it from various perspectives!?

vagran commented 6 months ago

Hello, Actually, it is not only about controls. The viewer is designed to be 2D-only. As a consequence, it drops Z-coordinates during scene preparation and uses custom shaders to deal with 2D-only data. This is done to save some memory, which is important for huge DXF files, like construction site drawings. So you will need to make some effort, to preserve Z-coordinates for 3D-entities in DxfScene.js, fix shaders to use them in DxfViewer.js and implement some 3D camera controls in your application.

MartinPyka commented 6 months ago

I just figured out that it is actually pretty easy to get a 3d perspective and rotation into the app. you just need to replace in DxfViewer.js the orthographicCamera with a PerspectiveCamera and in the OrbitControls (Line 406) rotation must be activated, e.g. like this:

        const controls = this.controls = new OrbitControls(this.camera, this.canvas)
        controls.enableRotate = true
        controls.mouseButtons = {
            LEFT: three.MOUSE.PAN,
            MIDDLE: three.MOUSE.DOLLY,
            RIGHT: three.MOUSE.ROTATE
        }

Then it works. Now the question is, where are the height-information removed from the model?