很抱歉,如果这似乎是一个显而易见的答案,但我正在尝试创建一个类似于this的动画。我正在尝试创建一个与react-three-fiber类似的,但我不能使用文档中显示的那些,因为它们操作样式转换属性,这在three.js中是不可能的。我试图通过position属性和属性来操作它,但是它带来了一个错误,如here所示,我真的不知道从哪里开始修复这个错误。下面是我的代码:
const props = useSpring({
to: async next => {
await next({ position: [100, 100, 100] });
await next({ position: [50, 50, 50] });
},
from: { position: [100, 100, 100] },
config: { duration: 3500 },
reset: true
});
return (
<Canvas>
<a.group {...props}>
<Box position={[-1.2, 0, 0]} />
<Box position={[1.2, 0, 0]} />
</a.group>
</Canvas>
)我已经成功地使用了react-spring的悬停和缩放功能,但在使用位置时就不起作用了。
发布于 2020-04-30 16:43:34
我认为像这样的事情最好用三角学来做。
const ref = useRef()
useFrame(() => {
ref.current.position.y = Math.sin(state.clock.getElapsedTime()) * 10
})
return <group ref={ref}> ...Math.sin将产生一个介于-1到1之间的值,并在这两者之间平滑地交替。乘以你的因子(距离),你就得到了它。这里有一个像这样推拉相机的例子:https://codesandbox.io/s/r3f-lod-e9vpx
否则它是react-spring/three,而不是react-spring:https://codesandbox.io/s/clever-bartik-tkql8
https://stackoverflow.com/questions/61507235
复制相似问题