Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
bvh ignores instance mesh (#7711)
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField authored Mar 8, 2023
1 parent e63c967 commit a8178f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/engine/src/scene/components/ModelComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ function ModelReactor({ root }: EntityReactorProps) {
if (model.generateBVH) {
const bvhDone = [] as Promise<void>[]
scene.traverse((obj: Mesh) => {
if (obj.geometry?.boundsTree) return
bvhDone.push(generateMeshBVH(obj))
})
// trigger group state invalidation when bvh is done
Expand Down
13 changes: 10 additions & 3 deletions packages/engine/src/scene/functions/bvhWorkerPool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mesh } from 'three'
import { InstancedMesh, Mesh } from 'three'

import { GenerateMeshBVHWorker } from '../../common/classes/GenerateMeshBVHWorker'

Expand All @@ -7,8 +7,15 @@ const poolSize = 1
const bvhWorkers: GenerateMeshBVHWorker[] = []
const meshQueue: Mesh[] = []

export function generateMeshBVH(mesh: Mesh) {
if (!mesh.isMesh || !mesh.geometry || !mesh.geometry.attributes.position) return Promise.resolve()
export function generateMeshBVH(mesh: Mesh | InstancedMesh) {
if (
!mesh.isMesh ||
(mesh as InstancedMesh).isInstancedMesh ||
!mesh.geometry ||
!mesh.geometry.attributes.position ||
mesh.geometry.boundsTree
)
return Promise.resolve()
if (!bvhWorkers.length) {
for (let i = 0; i < poolSize; i++) {
bvhWorkers.push(new GenerateMeshBVHWorker())
Expand Down

0 comments on commit a8178f2

Please sign in to comment.