Browse Source

SkinnedMesh: Use correct bounding volume for raycasting. (#25791)

Michael Herzog 2 years ago
parent
commit
988d96e727
2 changed files with 34 additions and 6 deletions
  1. 9 6
      src/objects/Mesh.js
  2. 25 0
      src/objects/SkinnedMesh.js

+ 9 - 6
src/objects/Mesh.js

@@ -143,12 +143,6 @@ class Mesh extends Object3D {
 
 		}
 
-		if ( this.isSkinnedMesh ) {
-
-			this.applyBoneTransform( index, target );
-
-		}
-
 		return target;
 
 	}
@@ -191,8 +185,17 @@ class Mesh extends Object3D {
 
 		}
 
+		this._computeIntersections( raycaster, intersects );
+
+	}
+
+	_computeIntersections( raycaster, intersects ) {
+
 		let intersection;
 
+		const geometry = this.geometry;
+		const material = this.material;
+
 		const index = geometry.index;
 		const position = geometry.attributes.position;
 		const uv = geometry.attributes.uv;

+ 25 - 0
src/objects/SkinnedMesh.js

@@ -14,6 +14,8 @@ const _vector3 = /*@__PURE__*/ new Vector3();
 const _matrix4 = /*@__PURE__*/ new Matrix4();
 const _vertex = /*@__PURE__*/ new Vector3();
 
+const _sphere = /*@__PURE__*/ new Sphere();
+
 class SkinnedMesh extends Mesh {
 
 	constructor( geometry, material ) {
@@ -95,6 +97,29 @@ class SkinnedMesh extends Mesh {
 
 	}
 
+	raycast( raycaster, intersects ) {
+
+		if ( this.boundingSphere === null ) this.computeBoundingSphere();
+
+		_sphere.copy( this.boundingSphere );
+		_sphere.applyMatrix4( this.matrixWorld );
+
+		if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
+
+		this._computeIntersections( raycaster, intersects );
+
+	}
+
+	getVertexPosition( index, target ) {
+
+		super.getVertexPosition( index, target );
+
+		this.applyBoneTransform( index, target );
+
+		return target;
+
+	}
+
 	bind( skeleton, bindMatrix ) {
 
 		this.skeleton = skeleton;