Although the green cube is successfully loaded and animated, none of OrbitControls function works.
I’m using three inside vue.
I could successfully use Orbitcontrols a while ago. I did change some code of OrbitControls with patch package but I uninstalled everything about patch package and three. And reinstall three again.
Now I can’t use a simple Orbitcontrols T_T
THREE Js version - ^0.128.0
Vue Js - v^2.5.17
Node v14.17.0
Npm v6.14.13
import * as THREE from 'three';
import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader';
import {OrbitControls,MapControls} from 'three/examples/jsm/controls/OrbitControls';
let scene, camera, obj, renderer, cube, container, controls,clock=new THREE.Clock();
export default {
name: "",
props: [],
data() {
return {}
},
methods: {
_Init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1,
1000 );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
cube = new THREE.Mesh( geometry, material );
scene.add( cube );
controls = new OrbitControls(camera, renderer.domElement);
camera.position.z=3;
camera.position.y=5.0;
camera.position.x=0;
controls.update();
this.animate();
animate() {
requestAnimationFrame( this.animate );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render( scene, camera );
controls.update();
}
},
mounted() {
this._Init();
},
}
I don’t know what’s wrong inside my project. I have deleted node-modules and package-lock json inside my project and reinstall three but it didn’t work.
Edit : As far as I could think , I updated npm to ^7 yesterday and i got some errors with vulnerabilities . So I deleted npm folder inside user/bin and .npm folder inside home/user/ and reinstalled node and npm. I also ran “npm cache clean --force”. That’s all I did.
This worked for me as well, can I ask why I need to add this though out of curiosity? I get conceptually that when the “change” event fires we re-render the scene and camera. So in our case when we move around, the scene rerenders. Shouldnt OrbitControls do this out of the box though?