Skip to content

Commit

Permalink
fix: correct highlihgter update
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Feb 23, 2024
1 parent 32a188e commit d976752
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openbim-components",
"version": "1.4.0",
"version": "1.4.2",
"main": "src/index.js",
"author": "harry collin, antonio gonzalez viegas",
"license": "MIT",
Expand Down
9 changes: 6 additions & 3 deletions resources/openbim-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -101925,6 +101925,7 @@ class FragmentHighlighter extends Component {
this.onBeforeUpdate = new Event();
/** {@link Updateable.onAfterUpdate} */
this.onAfterUpdate = new Event();
this.needsUpdate = false;
/** {@link Configurable.isSetup} */
this.isSetup = false;
this.enabled = true;
Expand Down Expand Up @@ -102062,10 +102063,9 @@ class FragmentHighlighter extends Component {
onHighlight: new Event(),
onClear: new Event(),
};
await this.update();
await this.updateHighlight();
}
/** {@link Updateable.update} */
async update() {
async updateHighlight() {
if (!this.fillEnabled) {
return;
}
Expand All @@ -102077,6 +102077,9 @@ class FragmentHighlighter extends Component {
const outlinedMesh = this._outlinedMeshes[fragmentID];
if (outlinedMesh) {
fragment.mesh.updateMatrixWorld(true);
outlinedMesh.position.set(0, 0, 0);
outlinedMesh.rotation.set(0, 0, 0);
outlinedMesh.scale.set(1, 1, 1);
outlinedMesh.applyMatrix4(fragment.mesh.matrixWorld);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/SimpleClipper/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
which is simply an array of all the meshes in the Scene 🗄️.
*/
scene.add(cube);
components.meshes.push(cube);
components.meshes.add(cube);

/*MD
### ⚙️ Adding Simple Clipper
Expand Down
2 changes: 1 addition & 1 deletion src/fragments/FragmentHighlighter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
const dataBlob = await file.arrayBuffer();
const buffer = new Uint8Array(dataBlob);
fragments.load(buffer);
highlighter.update();
highlighter.updateHighlight();

components.renderer.postproduction.customEffects.outlineEnabled = true;
highlighter.outlinesEnabled = true;
Expand Down
12 changes: 8 additions & 4 deletions src/fragments/FragmentHighlighter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface FragmentHighlighterConfig {

export class FragmentHighlighter
extends Component<HighlightMaterials>
implements Disposable, Updateable, Configurable<FragmentHighlighterConfig>
implements Disposable, Configurable<FragmentHighlighterConfig>
{
static readonly uuid = "cb8a76f2-654a-4b50-80c6-66fd83cafd77" as const;

Expand All @@ -52,6 +52,8 @@ export class FragmentHighlighter
/** {@link Updateable.onAfterUpdate} */
readonly onAfterUpdate = new Event<FragmentHighlighter>();

needsUpdate = false;

/** {@link Configurable.isSetup} */
isSetup = false;

Expand Down Expand Up @@ -203,11 +205,10 @@ export class FragmentHighlighter
onClear: new Event(),
};

await this.update();
await this.updateHighlight();
}

/** {@link Updateable.update} */
async update() {
async updateHighlight() {
if (!this.fillEnabled) {
return;
}
Expand All @@ -219,6 +220,9 @@ export class FragmentHighlighter
const outlinedMesh = this._outlinedMeshes[fragmentID];
if (outlinedMesh) {
fragment.mesh.updateMatrixWorld(true);
outlinedMesh.position.set(0, 0, 0);
outlinedMesh.rotation.set(0, 0, 0);
outlinedMesh.scale.set(1, 1, 1);
outlinedMesh.applyMatrix4(fragment.mesh.matrixWorld);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fragments/FragmentPlans/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
const canvas = renderer.get().domElement;
canvas.addEventListener("click", () => highlighter.clear("default"))

highlighter.update();
highlighter.updateHighlight();

/*MD
And let's add these features to the floorplans as extra commands
Expand Down
20 changes: 16 additions & 4 deletions src/fragments/FragmentTree/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@
*/
const fragments = new OBC.FragmentManager(components);

const file = await fetch("../../../resources/small.frag");
const data = await file.arrayBuffer();
const buffer = new Uint8Array(data);
const model = await fragments.load(buffer);

const file2 = await fetch("../../../resources/small2.frag");
const data2 = await file2.arrayBuffer();
const buffer2 = new Uint8Array(data2);
const model2 = await fragments.load(buffer2);

/*MD
### 🕹 Selection of Fragments
Expand Down Expand Up @@ -130,7 +136,7 @@
components.renderer.postproduction.customEffects.outlineEnabled = true;
highlighter.outlinesEnabled = true;

highlighter.update();
highlighter.updateHighlight();

/*MD
Expand All @@ -154,9 +160,12 @@
*/

const properties = await fetch("../../../resources/bbbb.json");
const properties = await fetch("../../../resources/small.json");
model.setLocalProperties(await properties.json());

const properties2 = await fetch("../../../resources/small2.json");
model2.setLocalProperties(await properties2.json());

/*MD
Now that we have the properties, we will pass the model to classifier and use `classifier.byStorey()` which will group the Fragments according to Floors.
Expand All @@ -165,8 +174,11 @@
*/

classifier.byStorey(model);
classifier.byEntity(model);
// classifier.byStorey(model);
// classifier.byEntity(model);

classifier.byStorey(model2);
classifier.byEntity(model2);

/*MD
Expand Down
2 changes: 1 addition & 1 deletion src/measurement/AngleMeasurement/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
*/

scene.add(cube);
components.meshes.push(cube);
components.meshes.add(cube);

/*MD
Expand Down
2 changes: 1 addition & 1 deletion src/measurement/AreaMeasurement/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
*/

scene.add(cube);
components.meshes.push(cube);
components.meshes.add(cube);

/*MD
Expand Down
2 changes: 1 addition & 1 deletion src/measurement/LengthMeasurement/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
*/

scene.add(cube);
components.meshes.push(cube);
components.meshes.add(cube);

/*MD
Expand Down
2 changes: 1 addition & 1 deletion src/measurement/VolumeMeasurement/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

const highlighter = new OBC.FragmentHighlighter(components, fragments);
highlighter.setup();
highlighter.update();
highlighter.updateHighlight();

highlighter.events.select.onHighlight.add((event) => {
const fragmentIDs = Object.keys(event);
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/CubeMap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
cube.position.set(0, 1.5, 0);
scene.add(cube);

components.meshes.push(cube);
components.meshes.add(cube);

const directionalLight = new THREE.DirectionalLight();
directionalLight.position.set(5, 10, 3);
Expand Down
4 changes: 2 additions & 2 deletions src/navigation/EdgesClipper/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@
const cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube.position.set(-2, 1.5, 0);
scene.add(cube);
components.meshes.push(cube);
components.meshes.add(cube);

const cube2 = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube2.position.set(2, 1.5, 0);
scene.add(cube2);
components.meshes.push(cube2);
components.meshes.add(cube2);

/*MD
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/OrthoPerspectiveCamera/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
*/
scene.add(cube);
components.meshes.push(cube);
components.meshes.add(cube);

/*MD
### 🎞️ Developing an OrthoPerspective Camera
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/ShadowDropper/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

scene.background = new THREE.Color("gray");
scene.add(cube);
components.meshes.push(cube);
components.meshes.add(cube);

/*MD
### 🌚 Adding Beautiful Shadow
Expand Down

0 comments on commit d976752

Please sign in to comment.