@@ -4,8 +4,8 @@ import type { Body, Quaternion as CQuaternion, Vec3, World } from 'cannon-es'
44import CannonDebugger from 'cannon-es-debugger'
55import type { FC } from 'react'
66import { useMemo , useRef , useState } from 'react'
7- import type { Color } from 'three'
8- import { Quaternion , Scene , Vector3 } from 'three'
7+ import { Color , InstancedMesh } from 'three'
8+ import { Quaternion , Scene , Vector3 , Matrix4 } from 'three'
99
1010import type { DebugApi } from './debug-context'
1111import { debugContext } from './debug-context'
@@ -22,6 +22,7 @@ export type DebugProviderProps = {
2222const q = new Quaternion ( )
2323const s = new Vector3 ( 1 , 1 , 1 )
2424const v = new Vector3 ( )
25+ const m = new Matrix4 ( )
2526
2627export const DebugProvider : FC < DebugProviderProps > = ( {
2728 children,
@@ -36,9 +37,18 @@ export const DebugProvider: FC<DebugProviderProps> = ({
3637
3738 useFrame ( ( ) => {
3839 for ( const uuid in bodyMap ) {
39- refs [ uuid ] . matrix . decompose ( v , q , s )
40- bodyMap [ uuid ] . position . copy ( v as unknown as Vec3 )
41- bodyMap [ uuid ] . quaternion . copy ( q as unknown as CQuaternion )
40+ let ref = refs [ uuid ]
41+ if ( ref instanceof InstancedMesh ) {
42+ const index = parseInt ( uuid . split ( '/' ) [ 1 ] )
43+ ref . getMatrixAt ( index , m )
44+ m . decompose ( v , q , s )
45+ bodyMap [ uuid ] . position . copy ( v as unknown as Vec3 )
46+ bodyMap [ uuid ] . quaternion . copy ( q as unknown as CQuaternion )
47+ } else {
48+ ref . matrix . decompose ( v , q , s )
49+ bodyMap [ uuid ] . position . copy ( v as unknown as Vec3 )
50+ bodyMap [ uuid ] . quaternion . copy ( q as unknown as CQuaternion )
51+ }
4252 }
4353
4454 cannonDebuggerRef . current . update ( )
0 commit comments