Skip to content

Commit df3b15e

Browse files
committed
RoomEnvironment: Use InstancedMesh.
1 parent dd26821 commit df3b15e

File tree

1 file changed

+48
-35
lines changed

1 file changed

+48
-35
lines changed

examples/jsm/environments/RoomEnvironment.js

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {
22
BackSide,
33
BoxGeometry,
4+
InstancedMesh,
45
Mesh,
56
MeshBasicMaterial,
67
MeshStandardMaterial,
78
PointLight,
89
Scene,
10+
Object3D,
911
} from 'three';
1012

1113
/**
@@ -49,41 +51,52 @@ class RoomEnvironment extends Scene {
4951
room.scale.set( 31.713, 28.305, 28.591 );
5052
this.add( room );
5153

52-
const box1 = new Mesh( geometry, boxMaterial );
53-
box1.position.set( - 10.906, 2.009, 1.846 );
54-
box1.rotation.set( 0, - 0.195, 0 );
55-
box1.scale.set( 2.328, 7.905, 4.651 );
56-
this.add( box1 );
57-
58-
const box2 = new Mesh( geometry, boxMaterial );
59-
box2.position.set( - 5.607, - 0.754, - 0.758 );
60-
box2.rotation.set( 0, 0.994, 0 );
61-
box2.scale.set( 1.970, 1.534, 3.955 );
62-
this.add( box2 );
63-
64-
const box3 = new Mesh( geometry, boxMaterial );
65-
box3.position.set( 6.167, 0.857, 7.803 );
66-
box3.rotation.set( 0, 0.561, 0 );
67-
box3.scale.set( 3.927, 6.285, 3.687 );
68-
this.add( box3 );
69-
70-
const box4 = new Mesh( geometry, boxMaterial );
71-
box4.position.set( - 2.017, 0.018, 6.124 );
72-
box4.rotation.set( 0, 0.333, 0 );
73-
box4.scale.set( 2.002, 4.566, 2.064 );
74-
this.add( box4 );
75-
76-
const box5 = new Mesh( geometry, boxMaterial );
77-
box5.position.set( 2.291, - 0.756, - 2.621 );
78-
box5.rotation.set( 0, - 0.286, 0 );
79-
box5.scale.set( 1.546, 1.552, 1.496 );
80-
this.add( box5 );
81-
82-
const box6 = new Mesh( geometry, boxMaterial );
83-
box6.position.set( - 2.193, - 0.369, - 5.547 );
84-
box6.rotation.set( 0, 0.516, 0 );
85-
box6.scale.set( 3.875, 3.487, 2.986 );
86-
this.add( box6 );
54+
const boxes = new InstancedMesh( geometry, boxMaterial, 6 );
55+
const transform = new Object3D();
56+
57+
// box1
58+
transform.position.set( - 10.906, 2.009, 1.846 );
59+
transform.rotation.set( 0, - 0.195, 0 );
60+
transform.scale.set( 2.328, 7.905, 4.651 );
61+
transform.updateMatrix();
62+
boxes.setMatrixAt( 0, transform.matrix );
63+
64+
// box2
65+
transform.position.set( - 5.607, - 0.754, - 0.758 );
66+
transform.rotation.set( 0, 0.994, 0 );
67+
transform.scale.set( 1.970, 1.534, 3.955 );
68+
transform.updateMatrix();
69+
boxes.setMatrixAt( 1, transform.matrix );
70+
71+
// box3
72+
transform.position.set( 6.167, 0.857, 7.803 );
73+
transform.rotation.set( 0, 0.561, 0 );
74+
transform.scale.set( 3.927, 6.285, 3.687 );
75+
transform.updateMatrix();
76+
boxes.setMatrixAt( 2, transform.matrix );
77+
78+
// box4
79+
transform.position.set( - 2.017, 0.018, 6.124 );
80+
transform.rotation.set( 0, 0.333, 0 );
81+
transform.scale.set( 2.002, 4.566, 2.064 );
82+
transform.updateMatrix();
83+
boxes.setMatrixAt( 3, transform.matrix );
84+
85+
// box5
86+
transform.position.set( 2.291, - 0.756, - 2.621 );
87+
transform.rotation.set( 0, - 0.286, 0 );
88+
transform.scale.set( 1.546, 1.552, 1.496 );
89+
transform.updateMatrix();
90+
boxes.setMatrixAt( 4, transform.matrix );
91+
92+
// box6
93+
transform.position.set( - 2.193, - 0.369, - 5.547 );
94+
transform.rotation.set( 0, 0.516, 0 );
95+
transform.scale.set( 3.875, 3.487, 2.986 );
96+
transform.updateMatrix();
97+
boxes.setMatrixAt( 5, transform.matrix );
98+
99+
this.add( boxes );
87100

88101

89102
// -x right

0 commit comments

Comments
 (0)