I use orbit controls once in my javascript code, with no imports at the top of my javascript file:
OrbitControls(camera, renderer.domElement)
This leads to a console log error, OrbitControls is undefined. I have tried a whole bunch of differing configurations to get this to work, but no success, does anyone have any ideas on how to resolve?
I found these topics, none of which seem to resolve my issue:
(This seems to imply that I do not have to do any thing if I download three from a CDN, but this did not work).
even if you somehow make that work, threejs will soon delete /js and then you’ll scramble. especially as a beginner, you’re wasting your your time on script tags. the old ones are from a bygone era and very few things support them any longer, we’re using modules now. the esm script tags are not finished and will cause you never ending trouble. not to mention that CDNs can be unreliable.
webdev functions through node, npm and bundling. you are ready to go in seconds:
install node
type “npm create vite”, name your project, select “vanilla”
cd into your project
run “npm install three”
run “npm run dev”
and that is it, open the url it gives you in the browser, open your editor, edit a file and save, it will be reflected in the browser. when you want to publish run “npm run build” and copy the dist folder onto your server, it will already be compressed and tree shaken (using only the parts you actually need).
if you want to use three:
import * as THREE from 'three'
import { OrbitControls } form 'three/examples/jsm/controls/OrbitControls'