Skip to content

Commit

Permalink
SkinnedMesh: Use correct bounding volume for raycasting. (#25791)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Apr 8, 2023
1 parent 5ce153a commit 988d96e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/objects/Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ class Mesh extends Object3D {

}

if ( this.isSkinnedMesh ) {

this.applyBoneTransform( index, target );

}

return target;

}
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions src/objects/SkinnedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 988d96e

Please sign in to comment.