feat: add OrbitControls

This commit is contained in:
divyap 2026-03-18 11:55:16 +05:30
parent 5b1849d98a
commit c714dfa763

View File

@ -1,4 +1,5 @@
import * as THREE from 'three' import * as THREE from 'three'
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
const scene = new THREE.Scene() const scene = new THREE.Scene()
scene.background = new THREE.Color(0xf0f0f0) scene.background = new THREE.Color(0xf0f0f0)
@ -10,6 +11,8 @@ const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight) renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement) document.body.appendChild(renderer.domElement)
const controls = new OrbitControls(camera, renderer.domElement)
const ambientLight = new THREE.AmbientLight(0xffffff, Math.PI / 2) const ambientLight = new THREE.AmbientLight(0xffffff, Math.PI / 2)
scene.add(ambientLight) scene.add(ambientLight)
@ -39,6 +42,7 @@ function animate() {
cube2.rotation.x += 0.01 cube2.rotation.x += 0.01
cube2.rotation.y += 0.01 cube2.rotation.y += 0.01
controls.update()
renderer.render(scene, camera) renderer.render(scene, camera)
} }