1
1
import { Mesh } from './Mesh.js' ;
2
+ import { Box3 } from '../math/Box3.js' ;
2
3
import { Matrix4 } from '../math/Matrix4.js' ;
4
+ import { Sphere } from '../math/Sphere.js' ;
3
5
import { Vector3 } from '../math/Vector3.js' ;
4
6
import { Vector4 } from '../math/Vector4.js' ;
5
7
@@ -10,6 +12,7 @@ const _skinWeight = /*@__PURE__*/ new Vector4();
10
12
11
13
const _vector3 = /*@__PURE__ */ new Vector3 ( ) ;
12
14
const _matrix4 = /*@__PURE__ */ new Matrix4 ( ) ;
15
+ const _vertex = /*@__PURE__ */ new Vector3 ( ) ;
13
16
14
17
class SkinnedMesh extends Mesh {
15
18
@@ -25,6 +28,57 @@ class SkinnedMesh extends Mesh {
25
28
this . bindMatrix = new Matrix4 ( ) ;
26
29
this . bindMatrixInverse = new Matrix4 ( ) ;
27
30
31
+ this . boundingBox = null ;
32
+ this . boundingSphere = null ;
33
+
34
+ }
35
+
36
+ computeBoundingBox ( ) {
37
+
38
+ const geometry = this . geometry ;
39
+
40
+ if ( this . boundingBox === null ) {
41
+
42
+ this . boundingBox = new Box3 ( ) ;
43
+
44
+ }
45
+
46
+ this . boundingBox . makeEmpty ( ) ;
47
+
48
+ const positionAttribute = geometry . getAttribute ( 'position' ) ;
49
+
50
+ for ( let i = 0 ; i < positionAttribute . count ; i ++ ) {
51
+
52
+ _vertex . fromBufferAttribute ( positionAttribute , i ) ;
53
+ this . applyBoneTransform ( i , _vertex ) ;
54
+ this . boundingBox . expandByPoint ( _vertex ) ;
55
+
56
+ }
57
+
58
+ }
59
+
60
+ computeBoundingSphere ( ) {
61
+
62
+ const geometry = this . geometry ;
63
+
64
+ if ( this . boundingSphere === null ) {
65
+
66
+ this . boundingSphere = new Sphere ( ) ;
67
+
68
+ }
69
+
70
+ this . boundingSphere . makeEmpty ( ) ;
71
+
72
+ const positionAttribute = geometry . getAttribute ( 'position' ) ;
73
+
74
+ for ( let i = 0 ; i < positionAttribute . count ; i ++ ) {
75
+
76
+ _vertex . fromBufferAttribute ( positionAttribute , i ) ;
77
+ this . applyBoneTransform ( i , _vertex ) ;
78
+ this . boundingSphere . expandByPoint ( _vertex ) ;
79
+
80
+ }
81
+
28
82
}
29
83
30
84
copy ( source , recursive ) {
0 commit comments