Commit 18828d1c authored by Chunchi Che's avatar Chunchi Che

use spring in hands ui

parent ab9e3118
...@@ -12,7 +12,8 @@ import { ...@@ -12,7 +12,8 @@ import {
import { store } from "../../store"; import { store } from "../../store";
import { useHover } from "react-babylonjs"; import { useHover } from "react-babylonjs";
import { useClick } from "./hook"; import { useClick } from "./hook";
import { useState, useRef } from "react"; import { useState, useRef, useEffect } from "react";
import { useSpring, animated } from "./spring";
const groundShape = CONFIG.GroundShape(); const groundShape = CONFIG.GroundShape();
const left = -(groundShape.width / 2); const left = -(groundShape.width / 2);
...@@ -38,11 +39,33 @@ const Hands = () => { ...@@ -38,11 +39,33 @@ const Hands = () => {
const CHand = (props: { state: Hand; idx: number; gap: number }) => { const CHand = (props: { state: Hand; idx: number; gap: number }) => {
const handShape = CONFIG.HandShape(); const handShape = CONFIG.HandShape();
const position = new BABYLON.Vector3(
left + props.gap * props.idx, const [spring, api] = useSpring(
handShape.height / 2, () => ({
-(groundShape.height / 2) - 1 from: {
position: new BABYLON.Vector3(
left + props.gap * props.idx,
handShape.height / 2,
-(groundShape.height / 2) - 1
),
},
config: {
clamp: true,
},
}),
[props.idx, props.gap]
); );
useEffect(() => {
api({
position: new BABYLON.Vector3(
left + props.gap * props.idx,
handShape.height / 2,
-(groundShape.height / 2) - 1
),
});
}, [props.idx, props.gap]);
const rotation = CONFIG.HandRotation(); const rotation = CONFIG.HandRotation();
const hoverScale = CONFIG.HandHoverScaling(); const hoverScale = CONFIG.HandHoverScaling();
...@@ -82,14 +105,15 @@ const CHand = (props: { state: Hand; idx: number; gap: number }) => { ...@@ -82,14 +105,15 @@ const CHand = (props: { state: Hand; idx: number; gap: number }) => {
[state] [state]
); );
return ( return (
<> // @ts-ignore
<plane <animated.transformNode name="">
<animated.plane
name={`hand-${idx}`} name={`hand-${idx}`}
ref={planeRef} ref={planeRef}
width={handShape.width} width={handShape.width}
height={handShape.height} height={handShape.height}
scaling={hovered ? hoverScale : defaultScale} scaling={hovered ? hoverScale : defaultScale}
position={position} position={spring.position}
rotation={rotation} rotation={rotation}
> >
<standardMaterial <standardMaterial
...@@ -100,8 +124,8 @@ const CHand = (props: { state: Hand; idx: number; gap: number }) => { ...@@ -100,8 +124,8 @@ const CHand = (props: { state: Hand; idx: number; gap: number }) => {
) )
} }
/> />
</plane> </animated.plane>
</> </animated.transformNode>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment