vagran / dxf-viewer

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

Drawing function #61

Open kamildul opened 1 year ago

kamildul commented 1 year ago

Hi everyone! i have a question: It is possible add function for drawing line, polyline or other elements? Thanks!

vagran commented 1 year ago

Hi! You can use DxfViewer.GetScene() method to obtain three.js scene object which can be used to add any additional objects to render. To match model space coordinates you should subtract scene origin from your objects coordinates. The origin can be obtained by DxfViewer.GetOrigin() method.

kamildul commented 1 year ago

Hi Vagran,

thanks for your response, where is tutorial for instalation without node, i want install only javascript+html version.

When i install via node cmd with command : npm install dxf-viewer I get the result:

obraz

I dont see example version in HTML + Javascript :-(

vagran commented 1 year ago

There is currently no any bundle build. You can find usage example in typical full-featured web application here.

kamildul commented 1 year ago

Will this compilation be available?

vagran commented 1 year ago

Currently it is not planned for this version. Bundle building is planned for next major release which will be rewritten in TypeScript.

kamildul commented 1 year ago

I understand, can you help me run your solution from the simplest version without node to open a dxf file? Only html and js?

vagran commented 1 year ago

I doubt I can help there, since I am not really familiar with modern web application build toolchain, so I also need to spend some time for some research. You may invest your time in learning some of web building tools (like rollup, webpack, esbuild etc.) and producing a bundle. Then check the code in the example mentioned above to get basic understanding how the library is used.

kamildul commented 1 year ago

Ok, where i find documentation?

vagran commented 1 year ago

The library API is documented by JsDoc comments in the source code.

kamildul commented 1 year ago

Thanks, but still i dont know how i can run this library, i need simple example only index.html where i add patch to the dxf file, and finally in browser index.html show dxf file...

Syngenex commented 3 days ago

@vagran Hello, I also need to add some text or image markers in the model, but I haven't implemented them according to the code below. Is there a problem with my coordinate settings

  let scene = this.dxfViewer.GetScene()
  let origin = new THREE.Vector2
  origin = this.dxfViewer.GetOrigin()

  const loader = new FontLoader()
  loader.load('./static/ThreeFont/Alibaba PuHuiTi_Regular.json', (font) => {
    const textGeometry = new TextGeometry('测试', {
      font: font,
      size: size,
      height: 1000,
      curveSegments: 1,
      bevelEnabled: false,
      bevelThickness: 0.1,
      bevelSize: 0.1,
      bevelSegments: 3
    })
    const textMaterial = new THREE.MeshBasicMaterial({color: color})
    const textMesh = new THREE.Mesh(textGeometry, textMaterial)

    textMesh.position.set(0-origin.x,0-origin.y,0)
    scene.add(textMesh)
  })
vagran commented 3 days ago

@vagran Hello, I also need to add some text or image markers in the model, but I haven't implemented them according to the code below. Is there a problem with my coordinate settings

  let scene = this.dxfViewer.GetScene()
  let origin = new THREE.Vector2
  origin = this.dxfViewer.GetOrigin()

  const loader = new FontLoader()
  loader.load('./static/ThreeFont/Alibaba PuHuiTi_Regular.json', (font) => {
    const textGeometry = new TextGeometry('测试', {
      font: font,
      size: size,
      height: 1000,
      curveSegments: 1,
      bevelEnabled: false,
      bevelThickness: 0.1,
      bevelSize: 0.1,
      bevelSegments: 3
    })
    const textMaterial = new THREE.MeshBasicMaterial({color: color})
    const textMesh = new THREE.Mesh(textGeometry, textMaterial)

    textMesh.position.set(0-origin.x,0-origin.y,0)
    scene.add(textMesh)
  })

Hello, your code looks good at first glance. Coordinates 0-origin.x,0-origin.y,0 assume that you are adding text to the 0;0 coordinates of the model space. Are you sure your model is defined near the model space origin? In some cases (e.g. georeferenced models) it might be far from origin. Also check that size and color is visible. Also you might want to check it on some very simple synthetic DXF (e.g. with single line near origin) before trying on real one.