Skip to content

Commit

Permalink
fix: use new instance shape
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Jan 2, 2025
1 parent 681f2f9 commit 5d07ec9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/core/MotionPathControls.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three'
import * as React from 'react'
import { ThreeElements, useFrame, useThree } from '@react-three/fiber'
import { ThreeElements, useFrame, useThree, Instance } from '@react-three/fiber'
import { easing, misc } from 'maath'

export type MotionPathProps = Omit<ThreeElements['group'], 'ref'> & {
Expand Down Expand Up @@ -113,7 +113,12 @@ export const MotionPathControls = /* @__PURE__ */ React.forwardRef<THREE.Group,

React.useLayoutEffect(() => {
path.curves = []
const _curves = curves.length > 0 ? curves : (ref.current as any)?.__r3f.objects
const _curves =
curves.length > 0
? curves
: (ref.current as THREE.Group & { __r3f: Instance<THREE.Group> }).__r3f!.children.map(
(instance) => instance.object
)
for (var i = 0; i < _curves.length; i++) path.add(_curves[i])

//Smoothen curve
Expand Down
11 changes: 7 additions & 4 deletions src/core/MultiMaterial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
* Original idea by https://x.com/verekia
*/

import { ThreeElements } from '@react-three/fiber'
import { ThreeElements, Instance } from '@react-three/fiber'
import * as React from 'react'
import * as THREE from 'three'

export type MultiMaterialProps = Omit<ThreeElements['group'], 'ref'>

export function MultiMaterial(props: MultiMaterialProps) {
const group = React.useRef(null!)
const group = React.useRef<THREE.Group>(null!)
React.useLayoutEffect(() => {
const parent = (group.current as any)?.parent
const parent = group.current.parent as THREE.Mesh<THREE.BufferGeometry, THREE.Material[]> | undefined
const geometry = parent?.geometry
if (geometry) {
const oldMaterial = parent.material
parent.material = (group.current as any).__r3f.objects
parent.material = (group.current as THREE.Group & { __r3f: Instance<THREE.Group> }).__r3f.children.map(
(instance) => instance.object
) as THREE.Material[]
const oldGroups = [...geometry.groups]
geometry.clearGroups()
parent.material.forEach((material, index) => {
Expand Down

0 comments on commit 5d07ec9

Please sign in to comment.