-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
36 deletions.
There are no files selected for viewing
67 changes: 36 additions & 31 deletions
67
packages/front/src/measurement/FaceMeasurement/example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,72 @@ | ||
// Set up scene (see SimpleScene tutorial) | ||
/* eslint import/no-extraneous-dependencies: 0 */ | ||
|
||
import * as THREE from "three"; | ||
import Stats from "stats.js"; | ||
import * as OBC from "../.."; | ||
import * as THREE from "three"; | ||
import * as OBC from "@thatopen/components"; | ||
import * as OBCF from "../.."; | ||
|
||
const container = document.getElementById("container")!; | ||
|
||
const components = new OBC.Components(); | ||
|
||
const sceneComponent = new OBC.SimpleScene(components); | ||
sceneComponent.setup(); | ||
components.scene = sceneComponent; | ||
const worlds = components.get(OBC.Worlds); | ||
|
||
const rendererComponent = new OBC.PostproductionRenderer(components, container); | ||
components.renderer = rendererComponent; | ||
const world = worlds.create< | ||
OBC.SimpleScene, | ||
OBC.SimpleCamera, | ||
OBCF.PostproductionRenderer | ||
>(); | ||
|
||
const cameraComponent = new OBC.SimpleCamera(components); | ||
components.camera = cameraComponent; | ||
|
||
components.raycaster = new OBC.SimpleRaycaster(components); | ||
world.scene = new OBC.SimpleScene(components); | ||
world.renderer = new OBCF.PostproductionRenderer(components, container); | ||
world.camera = new OBC.SimpleCamera(components); | ||
|
||
components.init(); | ||
|
||
rendererComponent.postproduction.enabled = true; | ||
world.camera.controls.setLookAt(5, 5, 5, 0, 0, 0); | ||
|
||
cameraComponent.controls.setLookAt(10, 10, 10, 0, 0, 0); | ||
world.scene.setup(); | ||
|
||
const grid = new OBC.SimpleGrid(components, new THREE.Color(0x666666)); | ||
const effects = rendererComponent.postproduction.customEffects; | ||
effects.excludedMeshes.push(grid.get()); | ||
const grids = components.get(OBC.Grids); | ||
grids.create(world); | ||
|
||
const dimensions = new OBC.FaceMeasurement(components); | ||
const dimensions = new OBCF.FaceMeasurement(components); | ||
dimensions.world = world; | ||
dimensions.enabled = true; | ||
|
||
const fragments = new OBC.FragmentsManager(components); | ||
const file = await fetch("../../../resources/small.frag"); | ||
const file = await fetch("../../../../../resources/small.frag"); | ||
const data = await file.arrayBuffer(); | ||
const buffer = new Uint8Array(data); | ||
fragments.load(buffer); | ||
const model = fragments.load(buffer); | ||
world.scene.three.add(model); | ||
|
||
for (const child of model.children) { | ||
if (child instanceof THREE.Mesh) { | ||
world.meshes.add(child); | ||
} | ||
} | ||
|
||
let saved: OBCF.SerializedAreaMeasure[]; | ||
|
||
let saved: OBC.SerializedAreaMeasure[]; | ||
window.addEventListener("keydown", (event) => { | ||
if (event.code === "KeyO") { | ||
dimensions.delete(); | ||
} else if (event.code === "KeyS") { | ||
saved = dimensions.get(); | ||
dimensions.deleteAll(); | ||
} else if (event.code === "KeyL") { | ||
if (saved) dimensions.set(saved); | ||
if (saved) { | ||
dimensions.set(saved); | ||
} | ||
} | ||
}); | ||
|
||
const mainToolbar = new OBC.Toolbar(components, { | ||
name: "Main Toolbar", | ||
position: "bottom", | ||
}); | ||
mainToolbar.addChild(dimensions.uiElement.get("main")); | ||
components.ui.addToolbar(mainToolbar); | ||
|
||
// Set up stats | ||
|
||
const stats = new Stats(); | ||
stats.showPanel(2); | ||
document.body.append(stats.dom); | ||
stats.dom.style.left = "0px"; | ||
rendererComponent.onBeforeUpdate.add(() => stats.begin()); | ||
rendererComponent.onAfterUpdate.add(() => stats.end()); | ||
world.renderer.onBeforeUpdate.add(() => stats.begin()); | ||
world.renderer.onAfterUpdate.add(() => stats.end()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters