File tree 3 files changed +27
-28
lines changed
3 files changed +27
-28
lines changed Original file line number Diff line number Diff line change 11
11
< h1 > [name]</ h1 >
12
12
13
13
< p class ="desc ">
14
- Represents a box in 2D space.
14
+ Represents an axis-aligned bounding box (AABB) in 2D space.
15
15
</ p >
16
16
17
17
Original file line number Diff line number Diff line change 11
11
< h1 > [name]</ h1 >
12
12
13
13
< p class ="desc ">
14
- Represents a box or cube in 3D space. The main purpose of this is to represent
15
- the world-axis-aligned bounding boxes for objects.
14
+ Represents an axis-aligned bounding box (AABB) in 3D space.
16
15
</ p >
17
16
18
-
17
+
19
18
< h2 > Example</ h2 >
20
19
21
20
< code >
22
- // Creating the object whose bounding box we want to compute
23
- var sphereObject = new THREE.Mesh(
24
- new THREE.SphereGeometry(),
25
- new THREE.MeshBasicMaterial( 0xff0000 )
21
+ var box = new THREE.Box3();
22
+
23
+ var mesh = new THREE.Mesh(
24
+ new THREE.SphereBufferGeometry(),
25
+ new THREE.MeshBasicMaterial()
26
26
);
27
- // Creating the actual bounding box with Box3
28
- sphereObject.geometry.computeBoundingBox();
29
- var box = sphereObject.geometry.boundingBox.clone();
27
+
28
+ // ensure the bounding box is computed for its geometry
29
+ // this should be done only once (assuming static geometries)
30
+ mesh.geometry.computeBoundingBox();
30
31
31
32
// ...
32
-
33
- // In the animation loop, to keep the bounding box updated after move/rotate/scale operations
34
- sphereObject.updateMatrixWorld( true );
35
- box.copy( sphereObject.geometry.boundingBox ).applyMatrix4( sphereObject.matrixWorld );
36
- </ code >
37
33
34
+ // in the animation loop, compute the current bounding box with the world matrix
35
+ box.copy( mesh.geometry.boundingBox ).applyMatrix4( mesh.matrixWorld );
36
+ </ code >
38
37
39
-
40
38
< h2 > Constructor</ h2 >
41
39
42
40
Original file line number Diff line number Diff line change @@ -17,20 +17,21 @@ <h1>[name]</h1>
17
17
< h2 > 示例</ h2 >
18
18
19
19
< code >
20
- // Creating the object whose bounding box we want to compute
21
- var sphereObject = new THREE.Mesh(
22
- new THREE.SphereGeometry(),
23
- new THREE.MeshBasicMaterial( 0xff0000 )
20
+ var box = new THREE.Box3();
21
+
22
+ var mesh = new THREE.Mesh(
23
+ new THREE.SphereBufferGeometry(),
24
+ new THREE.MeshBasicMaterial()
24
25
);
25
- // Creating the actual bounding box with Box3
26
- sphereObject.geometry.computeBoundingBox();
27
- var box = sphereObject.geometry.boundingBox.clone();
26
+
27
+ // ensure the bounding box is computed for its geometry
28
+ // this should be done only once (assuming static geometries)
29
+ mesh.geometry.computeBoundingBox();
28
30
29
31
// ...
30
-
31
- // In the animation loop, to keep the bounding box updated after move/rotate/scale operations
32
- sphereObject.updateMatrixWorld( true );
33
- box.copy( sphereObject.geometry.boundingBox ).applyMatrix4( sphereObject.matrixWorld );
32
+
33
+ // in the animation loop, compute the current bounding box with the world matrix
34
+ box.copy( mesh.geometry.boundingBox ).applyMatrix4( mesh.matrixWorld );
34
35
</ code >
35
36
36
37
< h2 > 构造器(Constructor)</ h2 >
You can’t perform that action at this time.
0 commit comments