Skip to content

Commit

Permalink
fix(MeshRefractionMaterial): work across unique meshes (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed May 20, 2023
1 parent 529939b commit 833d3cb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/MeshRefractionMaterial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as THREE from 'three'
import * as React from 'react'
import { useLayoutEffect, useMemo, useRef } from 'react'
import { extend, ReactThreeFiber, useThree, useFrame } from '@react-three/fiber'
import { MeshBVH, SAH } from 'three-mesh-bvh'
import { MeshBVHUniformStruct, MeshBVH, SAH } from 'three-mesh-bvh'
import { MeshRefractionMaterial as MeshRefractionMaterial_ } from '../materials/MeshRefractionMaterial'

declare global {
Expand Down Expand Up @@ -69,8 +69,9 @@ export function MeshRefractionMaterial({
const geometry = (material.current as any)?.__r3f?.parent?.geometry
// Update the BVH
if (geometry) {
;(material.current as any).bvh = new MeshBVHUniformStruct()
;(material.current as any).bvh.updateFrom(
new MeshBVH(geometry.toNonIndexed(), { lazyGeneration: false, strategy: SAH })
new MeshBVH(geometry.clone().toNonIndexed(), { lazyGeneration: false, strategy: SAH })
)
}
}, [])
Expand Down

1 comment on commit 833d3cb

@vercel
Copy link

@vercel vercel bot commented on 833d3cb May 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.