Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SkinnedMesh: Use correct bounding volume for raycasting. #25791

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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