gkjohnson / three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.
https://gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
MIT License
2.4k stars 248 forks source link

Uncaught TypeError: tmpInverseMatrix.copy(...).invert is not a function #430

Closed CarloPoletto closed 2 years ago

CarloPoletto commented 2 years ago

Describe the bug

I am trying to use three-mesh-bvh to quickly calculate the raycast in a mesh. However, when I run the intersectObjects function it throws the exception tmpInverseMatrix.copy(...).invert is not a function

Code

import * as Three from "three";
import { computeBoundsTree, disposeBoundsTree, acceleratedRaycast } from 'three-mesh-bvh';

Three.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree;
Three.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree;
Three.Mesh.prototype.raycast = acceleratedRaycast;

let mesh = new Three.Mesh();
mesh.geometry = new Three.BufferGeometry();
...
mesh.geometry.computeBoundsTree();

let raycaster = new Three.Raycaster();
raycaster.firstHitOnly = true;
raycaster.intersectObjects( [ mesh ] );

Platform:

Screenshots

Cattura

gkjohnson commented 2 years ago

Hello! You are using an older version of three.js that doesn't support Matrix4.invert which was introduced in v0.123.0. You'll have to upgrade or shim the function yourself in order to use this package.