dxf-parser
dxf-parser copied to clipboard
How to extract mesh geometry from polylines?
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
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 https://stackblitz.com/edit/js-csuc78?file=index.js You can open downloaded scene.json in the three.js editor
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.
You can load any dxf file
I have added scene.json to project
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.
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
DXF file cannot be uploaded due to 413 Request Entity Too Large
Upload it on other place like pastebin for example.
DXF is too large (about 3MB)
@Serthys https://ufile.io/817ihu0z
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.