Skip to content

Commit

Permalink
Merge pull request #5 from aka-blackboots/bim-tiles-utility-fixes
Browse files Browse the repository at this point in the history
Get Mesh and Sphere for Streamer + Transformation Fix
  • Loading branch information
agviegas authored Feb 7, 2024
2 parents 35b5b0d + 4e6db8e commit 0570e36
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 6 deletions.
Binary file added .DS_Store
Binary file not shown.
32 changes: 32 additions & 0 deletions resources/openbim-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -109626,6 +109626,23 @@ class BoundingBoxes {
parent.add(newBoundingBox);
}
}
getMesh() {
this.mesh.computeBoundingBox();
const { min, max } = this.mesh.boundingBox;
const width = Math.abs(max.x - min.x);
const height = Math.abs(max.y - min.y);
const depth = Math.abs(max.z - min.z);
const center = new THREE$1.Vector3();
center.subVectors(max, min).divideScalar(2).add(min);
const box = new THREE$1.BoxGeometry(width, height, depth);
const boxMesh = new THREE$1.Mesh(box);
boxMesh.position.copy(center);
return boxMesh;
}
getSphere() {
this.mesh.computeBoundingSphere();
return this.mesh.boundingSphere;
}
initializeBoundingBoxes() {
const geometry = new THREE$1.BoxGeometry(1, 1, 1);
geometry.deleteAttribute("uv");
Expand Down Expand Up @@ -109917,6 +109934,7 @@ class FragmentStreamLoader extends Component {
transparent: true,
opacity: 0.5,
});
this.transformation = new THREE$1.Matrix4();
this.notifyFragmentsFound = async (frags) => {
if (!this._isEventFree) {
setTimeout(() => this.notifyFragmentsFound(frags), this._eventDelay);
Expand Down Expand Up @@ -109968,9 +109986,20 @@ class FragmentStreamLoader extends Component {
}
}
this._geometryInstances[group.uuid] = instances;
// Move it to DT
this.culler.needsUpdate = true;
// console.log("----Group----");
// console.log(group);
}
get() { }
update() { }
getMesh() {
const box = this.culler.boxes.getMesh();
return box;
}
getSphere() {
return this.culler.boxes.getSphere();
}
applyTransformation(modelID, transform) {
if (!this.models[modelID]) {
throw new Error(`Model ${modelID} not found!`);
Expand All @@ -109980,6 +110009,7 @@ class FragmentStreamLoader extends Component {
this.culler.applyTransformation(modelID, asset.id, transform);
}
this.culler.boxes.update();
this.transformation.fromArray(transform.elements);
}
async handleSeenGeometries(seen) {
for (const modelID in seen) {
Expand Down Expand Up @@ -110109,6 +110139,8 @@ class FragmentStreamLoader extends Component {
fragment.mesh.setColorAt(i, col);
}
fragment.mesh.instanceColor.needsUpdate = true;
fragment.mesh.applyMatrix4(this.transformation);
fragment.mesh.updateMatrix();
result.push(fragment);
}
}
Expand Down
Binary file added src/fragments/.DS_Store
Binary file not shown.
Binary file added src/fragments/FragmentIfcStreamer/.DS_Store
Binary file not shown.
12 changes: 9 additions & 3 deletions src/fragments/FragmentIfcStreamer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,28 @@
}
})

// await loadModel("test.json");
await loadModel("test-2.json");
await loadModel("test.json");
// await loadModel("test-2.json");
// await loadModel("dm1_riv.json");

fragments.baseCoordinationModel = fragments.groups[0].uuid;
fragments.coordinate();
for(const group of fragments.groups) {
const {uuid, matrix} = group;
loader.applyTransformation(uuid, matrix);
const matrixe = new THREE.Matrix4();
matrixe.setPosition(0, 5, 0);
loader.applyTransformation(uuid, matrixe);
}

console.log(fragments);

components.camera.controls.addEventListener("controlend", () => {
loader.culler.needsUpdate = true;
culler.needsUpdate = true;
});

components.camera.controls.fitToSphere(loader.getSphere(), false);
loader.getMesh();
// loader.culler.renderDebugFrame = true;
// const debugFrame = loader.culler.get().domElement;
// document.body.appendChild(debugFrame);
Expand Down
19 changes: 19 additions & 0 deletions src/fragments/FragmentIfcStreamer/src/bounding-boxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ export class BoundingBoxes {
}
}

getMesh() {
this.mesh.computeBoundingBox();
const { min, max } = this.mesh.boundingBox as THREE.Box3;
const width = Math.abs(max.x - min.x);
const height = Math.abs(max.y - min.y);
const depth = Math.abs(max.z - min.z);
const center = new THREE.Vector3();
center.subVectors(max, min).divideScalar(2).add(min);
const box = new THREE.BoxGeometry(width, height, depth);
const boxMesh = new THREE.Mesh(box);
boxMesh.position.copy(center);
return boxMesh;
}

getSphere() {
this.mesh.computeBoundingSphere();
return this.mesh.boundingSphere;
}

private initializeBoundingBoxes() {
const geometry = new THREE.BoxGeometry(1, 1, 1);
geometry.deleteAttribute("uv");
Expand Down
30 changes: 28 additions & 2 deletions src/fragments/FragmentIfcStreamer/src/fragment-stream-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export class FragmentStreamLoader extends Component<any> {
opacity: 0.5,
});

private transformation = new THREE.Matrix4();

constructor(components: Components) {
super(components);
this.components.tools.add(FragmentStreamLoader.uuid, this);
Expand Down Expand Up @@ -93,7 +95,6 @@ export class FragmentStreamLoader extends Component<any> {

this.culler.add(group.uuid, assets, geometries);
this.models[group.uuid] = { assets, geometries };

const instances: StreamedInstances = {};

for (const asset of assets) {
Expand All @@ -107,12 +108,33 @@ export class FragmentStreamLoader extends Component<any> {
}

this._geometryInstances[group.uuid] = instances;

// Move it to DT
this.culler.needsUpdate = true;

// console.log("----Group----");
// console.log(group);
}

get() {}

update() {}

getMesh(): THREE.Mesh {
const box = this.culler.boxes.getMesh();
if (box) {
// this.components.scene.get().add(box);
// const boundingBox = new THREE.Box3().setFromObject(box);
// // @ts-ignore
// const bHelper = new THREE.Box3Helper(boundingBox, 0xff0000);
// this.components.scene.get().add(bHelper);
}
return box;
}
getSphere() {
return this.culler.boxes.getSphere();
}

applyTransformation(modelID: string, transform: THREE.Matrix4) {
if (!this.models[modelID]) {
throw new Error(`Model ${modelID} not found!`);
Expand All @@ -122,6 +144,8 @@ export class FragmentStreamLoader extends Component<any> {
this.culler.applyTransformation(modelID, asset.id, transform);
}
this.culler.boxes.update();

this.transformation.fromArray(transform.elements);
}

private async handleSeenGeometries(seen: { [modelID: string]: number[] }) {
Expand Down Expand Up @@ -264,7 +288,6 @@ export class FragmentStreamLoader extends Component<any> {

const material = transparent ? this._baseMaterialT : this._baseMaterial;
const fragment = new FRAG.Fragment(geometry, material, instances.length);

group.add(fragment.mesh);
group.items.push(fragment);

Expand All @@ -288,6 +311,9 @@ export class FragmentStreamLoader extends Component<any> {

fragment.mesh.instanceColor!.needsUpdate = true;

fragment.mesh.applyMatrix4(this.transformation);
fragment.mesh.updateMatrix();

result.push(fragment);
}

Expand Down
3 changes: 2 additions & 1 deletion src/fragments/FragmentManager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
const file = await fetch("../../../resources/small.frag");
const data = await file.arrayBuffer();
const buffer = new Uint8Array(data);
fragments.load(buffer);
const group = await fragments.load(buffer);
console.log(group)
// const scene = components.scene.get();
// scene.add(model);
}
Expand Down

0 comments on commit 0570e36

Please sign in to comment.