dxf-parser icon indicating copy to clipboard operation
dxf-parser copied to clipboard

How to extract mesh geometry from polylines?

Open Ni55aN opened this issue 5 years ago • 12 comments

How should I create faces and vertices from 3D points list? (dxf.entities -> type = 'POLYLINE')

I have tried this:

function addTriangle(g, p, i1, i2, i3) {
    if(Math.max(i1, i2, i3) > p.length - 1) return; 
    let p1 = p[i1];
    let p2 = p[i2];
    let p3 = p[i3];
    g.vertices.push(new THREE.Vector3( p1.x, p1.y, p1.z ))
    g.vertices.push(new THREE.Vector3( p2.x, p2.y, p2.z ))
    g.vertices.push(new THREE.Vector3( p3.x, p3.y, p3.z ))
    g.faces.push(new THREE.Face3(g.vertices.length - 3, g.vertices.length - 2, g.vertices.length - 1))
}

    var g = new THREE.Geometry();


    polylines.map(p => {
        for(let i=0;i<p.length;i+=6) {
            addTriangle(g, p, i, i+1, i+2)
            addTriangle(g, p, i+3, i+1, i)
        }
    })

But several polygons are missed. Moreover, I see a few points with a zero coordinates Kazam_screenshot_00003

Ni55aN avatar Apr 18 '19 16:04 Ni55aN

I don't think there's enough information to help here, can you provide a stackblitz with a basic sample of the problem? Here's a simple template, you should add your dxf file and log the things that give you problems.

Serthys avatar Apr 18 '19 17:04 Serthys

@Serthys https://stackblitz.com/edit/js-csuc78?file=index.js You can open downloaded scene.json in the three.js editor

Ni55aN avatar Apr 18 '19 19:04 Ni55aN

You can open downloaded scene.json in the three.js editor

The scene data on that editor is stored on your browser, I can't see it. Try creating a scene.json file on the stackblitz project and paste the contents you can download there.

Serthys avatar Apr 18 '19 20:04 Serthys

You can load any dxf file

Ni55aN avatar Apr 18 '19 21:04 Ni55aN

I have added scene.json to project

Ni55aN avatar Apr 18 '19 21:04 Ni55aN

Ok, I didn't understand you before. I thought you were trying to load the scene file. The file I need to test what's wrong is the dxf you are parsing, not the result.

Serthys avatar Apr 18 '19 21:04 Serthys

roof.dxf being imported in Blender (using the addon DXF import) correctly

I just uploaded the scene.json to project successfully https://stackblitz.com/edit/js-csuc78?file=scene.json

Ni55aN avatar Apr 18 '19 21:04 Ni55aN

DXF file cannot be uploaded due to 413 Request Entity Too Large

Ni55aN avatar Apr 18 '19 21:04 Ni55aN

Upload it on other place like pastebin for example.

Serthys avatar Apr 18 '19 21:04 Serthys

DXF is too large (about 3MB)

Ni55aN avatar Apr 18 '19 21:04 Ni55aN

@Serthys https://ufile.io/817ihu0z

Ni55aN avatar Apr 18 '19 21:04 Ni55aN

I've checked the dxf source and the zeros are already there, it doesn't look like an error from the parsing.

About how to extract the data and display it in threejs, I've never used the 3D features of dxf some I'm kinda lost there. If you manage to do it feel free to submit a pull request on /gdsestimating/three-dxf.

Serthys avatar Apr 18 '19 22:04 Serthys