Cannot add OrbitControl from drei to this starter.
See original GitHub issueI try to add the OrbitControl from Drei to this project. With next-transpile-modules setup, the same code works well if I create the next.js project then import react-three-fiber, drei, etc. but I cannot make it work with this template.
Here is how I edit the _canvas.jsx file. I’m I missing something?
https://codesandbox.io/s/bold-monad-dqfr3?file=/src/components/layout/_canvas.jsx:0-1402
import { Canvas, useFrame } from '@react-three/fiber'
import { Preload } from '@react-three/drei'
import { A11yUserPreferences } from '@react-three/a11y'
import useStore from '@/helpers/store'
import { OrbitControls } from '@react-three/drei'
import React, { useRef, useState } from 'react'
function Box(props) {
// This reference will give us direct access to the THREE.Mesh object
const mesh = useRef()
// Set up state for the hovered and active state
const [hovered, setHover] = useState(false)
const [active, setActive] = useState(false)
// Subscribe this component to the render-loop, rotate the mesh every frame
useFrame((state, delta) => (mesh.current.rotation.x += 0.01))
// Return the view, these are regular Threejs elements expressed in JSX
return (
<mesh
{...props}
ref={mesh}
scale={active ? 1.5 : 1}
onClick={(event) => setActive(!active)}
onPointerOver={(event) => setHover(true)}
onPointerOut={(event) => setHover(false)}
>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
</mesh>
)
}
const LCanvas = ({ children }) => {
return (
<Canvas>
<ambientLight />
<pointLight position={[10, 10, 10]} />
<Box position={[-1.2, 0, 0]} />
<Box position={[1.2, 0, 0]} />
<OrbitControls />
</Canvas>
)
}
export default LCanvas
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
javascript - Three.js - OrbitControls doesn't work - Stack Overflow
In your HTML the order matters when adding OrbitControls as it needs certain things from Three.js. It should be <script src="../build/three.min.js"></script> ...
Read more >Add Controls in ThreeJs | OrbitControls in ThreeJs - YouTube
Controlling objects in ThreeJs is a pretty important topic so by doing that we can create a pretty good interactive 3D view, ...
Read more >OrbitControls – three.js docs
Orbit controls allow the camera to orbit around a target. To use this, as with all files in the /examples directory, you will...
Read more >Adding OrbitControls to React Three Fiber - Code Workshop
Three.JS has an import we can use called OrbitControls that adds a lot of free camera movement functionality. It is very configurable and...
Read more >@react-three/drei - npm
Some drei controls already take it into account, like CameraShake, Gizmo and TransformControls. Drei currently exports OrbitControls , MapControls , ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The sandbox was broken earlier… i.e. did not run (it is working now)
So if you inspect the elements you will see the dom element you referenced here:
is covering the canvas. so if you remove
h-screenit should workIf anyone encounters this error you should look at the changes for /layout/canvas.jsx in the commit: https://github.com/pmndrs/react-three-next/commit/3aa88a174035e0f3b1a69783d56d4f470745e251 This has the correct way to pass the dom events to the orbit controls.