gdsestimating / three-dxf

A dxf viewer for the browser using three.js
MIT License
551 stars 171 forks source link

Feature Request: Convert arcs to line segments #7

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi

As part of my implementation of your library, as a CNC toolpath generator, it would be soooo much easier if we had the option to handle arcs/circles as line segments.

There is sample code https://github.com/chilipeppr/widget-3dviewer/blob/master/widget.js#L3163 but I am lost with all the math involved :(

bzuillsmith commented 8 years ago

My recommendation is to change your approach a little. Don't customize three-dxf to do cnc stuff. Let three-dxf do only what it is made to do--draw a dxf object to the screen. The steps you need to perform are this

  1. Use DXF parser to parse the file into a dxf object.
  2. Write some custom code to go through the entities of the dxf object and modify them as needed (for example, change arcs to line segments.)
  3. Pass the modified dxf object to three-dxf for viewing
  4. Simultaneously you can pass the dxf object to whatever custom library you have for creating gcode

This allows you to take advantage of

Last, I use three.js for drawing arcs (basically they are partial circles) so I don't have my own implementation of this. I recommend looking at https://github.com/mrdoob/three.js/blob/ddab1fda4fd1e21babf65aa454fc0fe15bfabc33/src/extras/geometries/CircleBufferGeometry.js which is the code in three js that calculates the points of the line segments of an arc. The positions array in the code is what stores the points. You can ignore the normals and uv stuff. With that code, you can formulate a way to convert arcs to line segments in dxf-to-gcode library.

ghost commented 8 years ago

Excellent! Didnt realise three already splits it into sections! This just totally saved my bacon, thanks On 20 Feb 2016 01:22, "Ben Zuill-Smith" notifications@github.com wrote:

My recommendation is to change your approach a little. Don't customize three-dxf to do cnc stuff. Let three-dxf do only what it is made to do--draw a dxf object to the screen. The steps you need to perform are this

  1. Use DXF parser to parse the file into a dxf object.
  2. Write some custom code to go through the entities of the dxf file and modify them as needed (for example, change arcs to line segments.)
  3. Pass the modified dxf object to three-dxf for viewing
  4. Simultaneously you can pass the dxf object to whatever custom library you have for creating gcode

This allows you to take advantage of

  • three-dxf updates without having to adapt them to your own code each update
  • dxf-parser updates
  • your dxf to gcode library could be a small and separate library of your own (if you wish) or could at least be a module in your project for better separation of concerns and testing

Last, I use three.js for drawing arcs (basically they are partial circles) so I don't have my own implementation of this. I recommend looking at https://github.com/mrdoob/three.js/blob/ddab1fda4fd1e21babf65aa454fc0fe15bfabc33/src/extras/geometries/CircleBufferGeometry.js which is the code in three js that calculates the points of the line segments of an arc. The positions array in the code is what stores the points. You can ignore the normals and uv stuff. With that code, you can formulate a way to convert arcs to line segments in your own code.

— Reply to this email directly or view it on GitHub https://github.com/gdsestimating/three-dxf/issues/7#issuecomment-186448613 .

ghost commented 8 years ago

You were correct It totally does work, i simply iterate through the children and they are lines (:

Closing this one then - no need to add any of this to three-dxf

(Now i am just banging my head on world vs local coordinates for circles)