如何在从@theatre/core获取JSON文件后,使用react three fiber动画相机?

huangapple go评论69阅读模式
英文:

How to animate a camera after getting a JSON file from @theatre/core with react three fiber?

问题

在从 main.jsx 中移除了 studio 后,相机停在第一帧。唯一的方式是使用滚动才能移动相机,但我想要在首次访问网站时开始动画并停止。

以下是 App.jsx 的内容:

import { Canvas, useFrame } from '@react-three/fiber';
import './App.css';
import { Test } from './components/test';
import { getProject, val } from '@theatre/core';
import { SheetProvider, PerspectiveCamera, useCurrentSheet } from '@theatre/r3f';
import flyThroughState from './assets/CamAni.json';

function App() {
  const sheet = getProject('Fly Through', { state: flyThroughState }).sheet("Scene");

  return (
    <>
      <Canvas gl={{ preserveDrawingBuffer: true }}>
        <SheetProvider sheet={sheet}>
          <Scene />
        </SheetProvider>
      </Canvas>
    </>
  );
}

export default App;

如何使用我从 Fly Through 获取的 JSON 文件使相机进行动画?

英文:

After removing the studio from main.jsx the camera stops at the first frame.
The only way i got it to move is using scroll but i want the animation to start when first getting in the website and stopping.
here's App.jsx:

    import { Canvas, useFrame  } from &#39;@react-three/fiber&#39;;
import &#39;./App.css&#39;;
import { Test } from &#39;./components/test&#39;;
import { getProject, val } from &#39;@theatre/core&#39;;
import { SheetProvider , PerspectiveCamera, useCurrentSheet} from &#39;@theatre/r3f&#39;;
import flyThroughState from &#39;./assets/CamAni.json&#39;;
function App() {
  const sheet = getProject(&#39;Fly Through&#39;,{state: flyThroughState}).sheet(&quot;Scene&quot;)
  return (
    &lt;&gt;
    &lt;Canvas  gl={{ preserveDrawingBuffer: true }}&gt;
         &lt;SheetProvider sheet={sheet}&gt;
          &lt;Scene /&gt;
        &lt;/SheetProvider&gt;
    &lt;/Canvas&gt;
    &lt;/&gt;
  )
}
export default App

how can i get the camera to animate with the json file i got from Fly Through ?

答案1

得分: 0

如果有人在将来需要这个这里是我修复的代码

~~~
    function App() {
  const sheet = getProject('飞越',{state: flyThroughState}).sheet('场景')
    useEffect(() => {
      sheet.project.ready.then(() => sheet.sequence.play({ iterationCount:1, range: [0, 3] }))
    }, [])
  
  return (<>
    <Canvas  gl={{ preserveDrawingBuffer: true }}>

         <SheetProvider sheet={sheet}>
          <Scene />
        </SheetProvider>
    </Canvas>
    </>
  )
}

export default App
~~~
英文:

If anyone need this in the futur, here's the code I fixed it.

    function App() {
  const sheet = getProject(&#39;Fly Through&#39;,{state: flyThroughState}).sheet(&quot;Scene&quot;)
    useEffect(() =&gt; {
      sheet.project.ready.then(() =&gt; sheet.sequence.play({ iterationCount:1, range: [0, 3] }))
    }, [])
  
  return (&lt;&gt;
    &lt;Canvas  gl={{ preserveDrawingBuffer: true }}&gt;

         &lt;SheetProvider sheet={sheet}&gt;
          &lt;Scene /&gt;
        &lt;/SheetProvider&gt;
    &lt;/Canvas&gt;
    &lt;/&gt;
  )
}

export default App

huangapple
  • 本文由 发表于 2023年7月24日 16:59:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76752867.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定