I have JSON data like this. I have to show a 3d polygon with js exactly like the example. Can’t change anything in the data. Need to fix it functionally. Have more similar data.
// 2 features data
{
"type": "FeatureCollection",
"features": [
{
"id": "2",
"type": "Feature",
"properties": {
"type": "wall",
"sf_tilt": 90.0,
"sf_orient": -32.0
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
2683852.4747061506,
1252231.906523199,
432.63800066187565
],
[
2683852.4747061506,
1252231.906523199,
439.65200066187566
],
[
2683852.200003838,
1252232.076997624,
439.39600066187137
],
[
2683852.200003838,
1252232.076997624,
435.1080006618714
],
[
2683850.956000865,
1252232.8489994688,
435.10800066185215
],
[
2683850.956000865,
1252232.8489994688,
433.2940106618521
],
[
2683852.4747061506,
1252231.906523199,
432.63800066187565
]
]
]
}
},
{
"id": "5",
"type": "Feature",
"properties": {
"type": "wall",
"sf_tilt": 90.0,
"sf_orient": 146.0
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
2683853.20506449,
1252236.2645763762,
435.108
],
[
2683854.3609999996,
1252235.484,
435.108
],
[
2683854.3609999996,
1252235.4839999997,
439.3960000002033
],
[
2683854.6319999998,
1252235.301,
439.6550000030672
],
[
2683854.632,
1252235.3009999997,
433.7652148642271
],
[
2683853.2050644904,
1252236.264576376,
433.74104702266015
],
[
2683853.20506449,
1252236.2645763762,
435.108
]
]
]
}
}
]
}
Here I have tried with threejs but not getting satisfied result.
function createBufferGeometry(feature) {
const coordinates = feature.geometry.coordinates[0];
const coords = coordinates.map((coord) => [coord[0] - offsets.x, coord[1] - offsets.y, coord[2] - offsets.z]);
const geometry = new THREE.BufferGeometry();
const vertices = [];
for (const coord of coords) {
vertices.push(coord[0], coord[1], coord[2]);
}
const positionAttribute = new THREE.Float32BufferAttribute(vertices, 3);
geometry.setAttribute("position", positionAttribute);
const indices = [];
for (let i = 0; i < coords.length - 2; i++) {
indices.push(0, i + 1, i + 2);
}
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const meshGeometry = createBufferGeometry(coords);
const mesh = new THREE.Mesh(meshGeometry, meshMaterial);
scene.add(mesh);
My result with threejs, here for id 5 L shape not clear, adding an extra triangle also this tringle blinking.
Result with python from mpl_toolkits.mplot3d.art3d import Poly3DCollection
here L shape clear with same data.
Anyone please can help me with how can I get a similar result?