forked from Orillusion/orillusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(BoundingBox): add isBoundChange tag to Entity (Orillusion#257)
Add tags to entity to check for any changes in the bound, and optimize the repeated calculation of the bound
- Loading branch information
Showing
6 changed files
with
123 additions
and
97 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { GUIHelp } from '@orillusion/debug/GUIHelp'; | ||
import { Color, Engine3D, Object3D, Object3DUtil, Transform, View3D, } from '@orillusion/core'; | ||
import { GUIUtil } from '@samples/utils/GUIUtil'; | ||
import { createExampleScene, createSceneParam } from '@samples/utils/ExampleScene'; | ||
|
||
// A sample to show boundingbox | ||
class Sample_BoundingBox { | ||
view: View3D; | ||
box: Object3D; | ||
container: Object3D; | ||
async run() { | ||
// init engine | ||
await Engine3D.init({ renderLoop: () => { this.loop() } }); | ||
GUIHelp.init(); | ||
let param = createSceneParam(); | ||
param.camera.distance = 1; | ||
param.camera.near = 0.01; | ||
param.camera.far = 100; | ||
param.camera.distance = 2; | ||
let exampleScene = createExampleScene(param); | ||
Engine3D.startRenderViews([exampleScene.view]); | ||
Engine3D.getRenderJob(exampleScene.view); | ||
|
||
let box = Object3DUtil.GetSingleCube(0.5, 0.3, 0.8, 1, 1, 1); | ||
box.transform.eventDispatcher.addEventListener(Transform.LOCAL_ONCHANGE, this.logChange, this); | ||
|
||
this.box = box; | ||
this.view = exampleScene.view; | ||
|
||
let parent = this.container = new Object3D(); | ||
parent.addChild(box); | ||
exampleScene.scene.addChild(parent); | ||
|
||
GUIHelp.open(); | ||
GUIHelp.addButton('Remove Box', () => { box.transform.parent && box.removeFromParent(); }) | ||
GUIHelp.addButton('Add Box', () => { !box.transform.parent && parent.addChild(box); }) | ||
|
||
GUIUtil.renderTransform(parent.transform, true, 'Container'); | ||
GUIUtil.renderTransform(box.transform, true, 'Box'); | ||
|
||
} | ||
|
||
logChange() { | ||
console.log('BoudingBox changed'); | ||
} | ||
|
||
red = new Color(1, 0, 0, 1); | ||
gree = new Color(0, 1, 0, 1); | ||
loop() { | ||
this.view.graphic3D.drawBoundingBox(this.box.uuid, this.box.bound as any, this.gree); | ||
this.view.graphic3D.drawBoundingBox(this.container.uuid, this.container.bound as any, this.red); | ||
} | ||
} | ||
|
||
new Sample_BoundingBox().run() |
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
Oops, something went wrong.