-
Notifications
You must be signed in to change notification settings - Fork 12
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
28 additions
and
1 deletion.
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,27 @@ | ||
import { Main, PerspectiveCameraAuto } from '@three.ez/main'; | ||
import { BoxGeometry, DirectionalLight, MeshLambertMaterial, Scene } from 'three'; | ||
import { OrbitControls } from 'three/examples/jsm/Addons.js'; | ||
import { InstancedMesh2 } from '../src/index.js'; | ||
|
||
const camera = new PerspectiveCameraAuto().translateZ(10); | ||
camera.add(new DirectionalLight('white', 3)); | ||
const scene = new Scene(); | ||
const main = new Main(); // init renderer and other stuff | ||
main.createView({ scene, camera, backgroundColor: 'skyblue' }); | ||
const controls = new OrbitControls(camera, main.renderer.domElement); | ||
controls.update(); | ||
|
||
const boxes = new InstancedMesh2(new BoxGeometry(), new MeshLambertMaterial()); | ||
scene.add(boxes); | ||
|
||
boxes.addInstances(20, (obj, index) => { | ||
obj.position.randomDirection().multiplyScalar(Math.random() * 5); | ||
obj.quaternion.random(); | ||
obj.color = Math.random() * 0xfffff; | ||
}); | ||
|
||
boxes.computeBVH(); | ||
|
||
boxes.on('click', (e) => { | ||
boxes.removeInstances(e.intersection.instanceId); | ||
}); |
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