Search code examples
javascriptreactjsthree.jsreact-three-fiber

How to rotate entire canvas in react js with react-three-fiber?


I followed this codrops tutorial on how to make a scrollable site using react-three-fiber.

I changed it up quite a bit and centered all the items as well as removed the RGB split effect. Now I would like to rotate the entire scrollarea/canvas in order to achieve a diagonal scroll effect similar to this page. Is it possible to just rotate the scrollArea as a whole or do I have to rotate every component individually using mesh.rotate.z =... and so on?

Full example Code

Code that brings everything together:

function App() {
 const scrollArea = useRef()
 const onScroll = e => (state.top.current = e.target.scrollTop)
 useEffect(() => void onScroll({ target: scrollArea.current }), [])
 return (
 <>
  <Canvas className="canvas" concurrent pixelRatio={1} orthographic camera={{ zoom: 
    state.zoom, position: [0, 0, 500] }}>
    <Suspense fallback={<Dom center className="loading" children="Loading..." />}>
      <Content />
      <Startup />
    </Suspense>
  </Canvas>
  <div className="scrollArea" ref={scrollArea} onScroll={onScroll}>
    {new Array(state.sections).fill().map((_, index) => (
      <div key={index} id={"0" + index} style={{ height: `${(state.pages / 
      state.sections) * 47}vh` }} />//site length
    ))}
    </div>
    <div className="frame">
    <div className="frame__links">
      <a className="frame__link" href="http://tympanus.net/Tutorials/PhysicsMenu/">
        Work
      </a>
      <a className="frame__link" href="https://tympanus.net/codrops/?p=45441">
        About
      </a>
    </div>
  </div>

</>
)}

Solution

  • I solved it by putting my content inside a group which I then rotated like such:

    <group rotation-z={0.025} rotation-y={0.0} rotation-x={0.05}>