vagran / dxf-viewer

DXF 2D viewer written in JavaScript
Mozilla Public License 2.0
310 stars 97 forks source link

fix: Remove zScale #7

Closed pbxrt closed 2 years ago

pbxrt commented 2 years ago

Since dxf-viewer is 2D, zScale has no effect on the XY based screen. Below is the problem: In dwg file, the door is in the wall image And in dxf-viewer, the door's x and y become -x and -y: image

You can Reproduce this bug from the attached dxf.tex file. Since github don't support .dxf file, I change the file extension to txt. dxf.txt

vagran commented 2 years ago

As I remember, it was done intentionally. I had some DXF examples which were rendered incorrectly without this code. Despite it is 2D viewer, zScale cannot be completely ignored, as I remember it is used to mirror 2D entities, and is encountered quite often in DXF files. May be such mirrorring should not be applied to block insertion, I will check this fix on all my test samples.

vagran commented 2 years ago

Here is example, which is broken by this fix: Floor plan (mirrorring).dxf.zip

However now I see, that it was not correctly rendered before that as well, so need to figure out proper approach. I use Autodesk online viewer as reference. BTW LibreCAD is not able to display it properly as well.

image image image

pbxrt commented 2 years ago

I see, this fix will cause other problems 😂

pbxrt commented 2 years ago

I think this is the bug of Autodesk. Below is the proof:

In DWG file, the coordinate of the wash basin is { x: -363.54, y: 189.65 } image

Howerer, in the exported DXF file, it's coordinate is { x: 363.54 ,y: 189.65 } image

I was wondering, why autodesk can display the dxf file properly according to the wrong coordinate again.

vagran commented 2 years ago

Probably, it is not a bug, but a feature. The problem is, that it is not documented anywhere. And see a bit below these lines, it also has negative Z extrusion direction, probably that is a hint for proper fix. I already apply this negative extrusion to entities definitions, but not to block insertion, because I did not have an example. Now I will try to account it as well.

vagran commented 2 years ago

Seems you were right, Z-scale does not really matter, only extrusion direction does, like it was done for entities in _MirrorEntityVertices method. I was confused by negative scale for that inserts in my sample, and did not noticed negative extrusion there. I will commit the fix shortly, which will correctly display at least those two files.

vagran commented 2 years ago

Fixed by bcb701aee11b7d74263cf796815c0cc0ad8247ac. I also updated npm package and online demo.

pbxrt commented 2 years ago

Roger that 👍🏻