Changes
Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
+11
-7
@@ -23,6 +23,13 @@ export async function convertIFCtoGLB(
|
||||
|
||||
ifcApi.StreamAllMeshes(modelID, (mesh: WebIFC.FlatMesh) => {
|
||||
const placedGeometries = mesh.geometries;
|
||||
const expressID = (mesh as unknown as { expressID?: number }).expressID ?? 0;
|
||||
|
||||
// One Group per IfcProduct → represents a single "element" (beam, plate…).
|
||||
// userData is preserved by GLTFExporter as `extras` and survives reload.
|
||||
const elementGroup = new THREE.Group();
|
||||
elementGroup.name = `ifc_${expressID}`;
|
||||
elementGroup.userData = { ifcElement: true, ifcId: expressID };
|
||||
|
||||
for (let i = 0; i < placedGeometries.size(); i++) {
|
||||
const placedGeometry = placedGeometries.get(i);
|
||||
@@ -38,8 +45,6 @@ export async function convertIFCtoGLB(
|
||||
);
|
||||
|
||||
const geometry = new THREE.BufferGeometry();
|
||||
|
||||
// web-ifc vertex format: x, y, z, nx, ny, nz (6 floats per vertex)
|
||||
const positionArray = new Float32Array(verts.length / 2);
|
||||
const normalArray = new Float32Array(verts.length / 2);
|
||||
|
||||
@@ -57,10 +62,8 @@ export async function convertIFCtoGLB(
|
||||
geometry.setAttribute('normal', new THREE.BufferAttribute(normalArray, 3));
|
||||
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||
|
||||
// Get or create material based on color
|
||||
const color = placedGeometry.color;
|
||||
const colorKey = (color.x * 255) << 16 | (color.y * 255) << 8 | (color.z * 255);
|
||||
|
||||
let material = materials.get(colorKey);
|
||||
if (!material) {
|
||||
material = new THREE.MeshStandardMaterial({
|
||||
@@ -75,16 +78,17 @@ export async function convertIFCtoGLB(
|
||||
}
|
||||
|
||||
const mesh3 = new THREE.Mesh(geometry, material);
|
||||
mesh3.userData = { ifcId: expressID };
|
||||
|
||||
// Apply placement transform
|
||||
const matrix = new THREE.Matrix4();
|
||||
matrix.fromArray(placedGeometry.flatTransformation);
|
||||
mesh3.applyMatrix4(matrix);
|
||||
|
||||
scene.add(mesh3);
|
||||
|
||||
elementGroup.add(mesh3);
|
||||
ifcGeometry.delete();
|
||||
}
|
||||
|
||||
if (elementGroup.children.length > 0) scene.add(elementGroup);
|
||||
});
|
||||
|
||||
ifcApi.CloseModel(modelID);
|
||||
|
||||
Reference in New Issue
Block a user