Last active
October 30, 2024 14:10
-
-
Save ektogamat/1f93fc5056abf56ac6b342fb50c5836c to your computer and use it in GitHub Desktop.
Mesh transition Material Free version - Smooths the color transition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by Anderson Mancini @2024 | |
// Check documentation on how to use it at https://codesandbox.io/p/sandbox/meshtransitionmaterialfree-l7pzn7 | |
import React, { useRef, useMemo } from 'react' | |
import { useFrame, useThree } from '@react-three/fiber' | |
import { easing } from 'maath' | |
export default function TransitionMaterialFree(props) { | |
const materialRef = useRef() | |
useFrame((_, delta) => | |
easing.dampC( | |
materialRef.current.color, | |
props.transitionColor, | |
props.transitionTime ? props.transitionTime : 0.25, | |
delta | |
) | |
) | |
return <meshPhysicalMaterial ref={materialRef} {...props} /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍