Error message: Orbit controls have encountered an issue - Uncaught TypeError: Cannot access property 'ROTATE' when it is undefined

Yesterday, the code was functioning properly until it suddenly started displaying an error in the orbit control JS file on line 82. The error message reads as follows:

Uncaught TypeError: Cannot read property 'ROTATE' of undefined at new THREE.OrbitControls (OrbitControls.js:82)

This issue is causing a complete breakdown of the 3D scene. By commenting out the code for controls, the 3D scene is operational again. Can someone assist me with resolving this problem?

// Establish a Parent container for the 3D scene
var container = document.getElementById("threedscene");

///////////////////////////////////////////////
/// Set Up The SCENE/Camera  ///////////////////

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth/window.innerHeight, 0.1, 1000 );

var renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
camera.position.set(0, 0, 20);


// Orbit Controls
var controls = new THREE.OrbitControls( camera, renderer.domElement )
controls.minDistance = 4.11;
controls.maxDistance = 20;
controls.enableZoom = false;

///////////////////////////////////////////////////////////////////////
/// Configure The Lights  /////////////////////////

var light = new THREE.AmbientLight( 0x888888 )
scene.add( light )
var light = new THREE.DirectionalLight( 0xfdfcf0, 1 )
light.position.set(10,10,10)
scene.add( light )

///////////////////////////
/// Create the Objects  ////////////////////

// Earth
var earthGeometry = new THREE.SphereGeometry(4, 50,50 );
var earthMaterial = new THREE.MeshPhongMaterial({
    map: new THREE.ImageUtils.loadTexture("https://thefederal.com/embed/earth-moon/images/land_ocean_ice_cloud_2048.jpg"),
    color: 0xaaaaaa,
    specular: 0x333333,
    shininess: 25
});
var earth = new THREE.Mesh(earthGeometry, earthMaterial);
scene.add(earth);
earth.rotation.y = 3.6;
earth.rotation.x = 0.3;

var markerGeometry = new THREE.SphereGeometry(0.10, 50,50 );
var markerMaterial = new THREE.MeshPhongMaterial({
    // map: new THREE.ImageUtils.loadTexture("images/land_ocean_ice_cloud_2048.jpg"),
    // map: new THREE.ImageUtils.loadTexture("images/marker_3.jpg"),
    color: 0xA40000,
    specular: 0x333333,
    shininess: 25
});
var marker = new THREE.Mesh(markerGeometry, markerMaterial);
scene.add(marker);
marker.position.set(1,-0.2,3.8)

elementgroup = new THREE.Object3D();//create an empty container
elementgroup.add( earth );//add a mesh with geometry to it
elementgroup.add( marker );//add a mesh with geometry to it
scene.add( elementgroup );//when done, add the group to the scene

var spriteMap = new THREE.TextureLoader().load( "https://thefederal.com/embed/earth-moon/images/sprite.png" );
var spriteMaterial = new THREE.SpriteMaterial( { map: spriteMap, color: 0xffffff } );
var sprite = new THREE.Sprite( spriteMaterial );

scene.add( sprite );

var spriteMap2 = new THREE.TextureLoader().load( "https://thefederal.com/embed/earth-moon/images/sprite2.png" );
var spriteMaterial2 = new THREE.SpriteMaterial( { map: spriteMap2, color: 0xffffff } );
var sprite2 = new THREE.Sprite( spriteMaterial2 );
sprite2.position.x = 8;
sprite2.scale.set(8, 8, 8)

scene.add( sprite );
scene.add( sprite2 );


//Clouds
var cloudGeometry = new THREE.SphereGeometry(4.1,  50, 50);
var cloudMaterial = new THREE.MeshPhongMaterial({
    map: new THREE.ImageUtils.loadTexture("https://thefederal.com/embed/earth-moon/images/clouds_2.jpg"),
    transparent: true,
    opacity: 0.1
});
var clouds = new THREE.Mesh(cloudGeometry, cloudMaterial);
scene.add(clouds);

////////////////////////////////////
/// Render the object with animation loop  /////////////////////////
var render = function (actions) {

    renderer.render(scene, camera);

    angle += dAngle;
    moon.position.x = r * Math.cos(angle);
    moon.position.z = r * Math.sin(angle);


    requestAnimationFrame( render );
};

render();


var domEvents = new THREEx.DomEvents(camera, renderer.domElement);

domEvents.addEventListener(marker, 'mouseover', function(event){
    marker.scale.set(1.5, 1.5, 1.5);
})

domEvents.addEventListener(marker, 'mouseout', function(event){
    marker.scale.set(1, 1, 1);
})

Answer №1

Based on information from a forum post, it seems that the issue at hand is due to a version mismatch. By including in your code, you should be able to resolve this problem. The discrepancy arises from updates made to three.js - the original file - and the orbit controls example, which may have resulted in your current version of three.js being outdated. I hope this explanation clears things up for you!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Jest - Test snapshot failure occurred following the inclusion of "</React.Fragment>"

I encountered an error message while running Jest. As I am not very familiar with using Jest, I would appreciate any insights on why this test is failing. Results: Jest test result: - Snapshot + Received - <span - className="icon icon-dismiss size-2 ...

What is the correct method to conceal the error message using JavaScript with document.getElementById("failedUpdateMessage").style.visibility = "hidden"

Once I had applied the code to conceal the element identified by the id "failedUpdateMessage", I now want to reveal that hidden element on a certain webpage using html. How can I achieve this using java script? I attempted to change "hidden" to "show" bu ...

Passing event handlers to Client Components within NextJS 13 and using the <button onClick={}> element is not supported

Oops! It looks like you can't pass event handlers to Client Component props. If you want your component to be interactive, consider converting some of it to a Client Component. const reqHelp = () => { Swal.fire({ title: '1', ...

` `Spinning graphics and written content``

I am looking to create a dynamic element on my website where an image and corresponding text block rotate every few seconds. An example of what I am envisioning can be seen on this website: While I know how to implement a javascript for rotating images, I ...

JavaScript Spinlocks Explained

What is the best way to implement a spinlock in JavaScript? I am attempting to load multiple images and I need to wait until all of them have finished loading before proceeding. My current approach involves using a spinlock like this: for(...) image[i ...

Difficulty encountered while integrating chart.js with Django using npm

Encountering an issue while using Chart.js in my Django project - when utilizing the NPM package, it fails to work. However, switching to the CDN resolves the problem seamlessly. Chart.js version 3.9.1 Below is a snippet from my project's index.html ...

I am looking to modify the JSON format of the API response

Received this response from the API and need to convert the JSON format below: Original: "data": [ [ { "isFile": "true", "fileType": "image", "filesize": 100793, ...

AngularJS Web-app: Display error page if JavaScript is disabled in the browser

If a user has disabled JavaScript in their browser, I want to display an error message indicating that my AngularJS WebApp cannot be viewed. My initial approach is to display this error message by default and replace it with my Angular start page once Jav ...

Adjust the z-index of the div to control the overflow scrollbar

I am facing an issue with a div that has a horizontal scrollbar and an image (or another div) positioned over the entire page using absolute positioning. The problem is I wish to scroll the div that is beside the image. For anchor links (a), I have set the ...

What is the mechanism behind making a Promise appear synchronous when using a Proxy in JavaScript?

const handler: ProxyHandler<any> = { get: (target: Promise<any>, prop: string, receiver: any) => { return target.then((o) => { return o[prop].apply(o); }); }, }; return new Proxy(obj, handler) ...

Calculate the quantity of rows within a specific div container

Looking at the image provided, there are multiple divs inside a main div. I am trying to figure out how many rows the main div contains. For instance, in this particular scenario, there are 5 rows. It is important to mention that the inner div is floated ...

Tips for updating routerlink in navigation bar in Angular 4

I'm encountering an issue with routing to the wrong routelink. How can I prevent this from happening? My apologies for my lack of experience. The error message displayed in the Chrome console is: ERROR Error: Uncaught (in promise): Error: Cannot mat ...

Is there a way to showcase a block of Python code using a combination of HTML, CSS, and Javascript to enhance its

On my website, I want to display code blocks similar to how StackOverflow does it. The code block should be properly colored, formatted, and spaced out for better readability. All the code blocks on my site will be in python. def func(A): result = 0 ...

Even with the openBrowser({ignoreCertificateErrors: true}) function in Taiko, I still encountered difficulties accessing the unsafe website

I encountered a browser popup authentication on the website below, so I attempted to use the code provided. openBrowser({ignoreCertificateErrors: true}); goto('https://feature:bb#Yrp$!xNP6@e.clinique.na.us.rac-166-dec22-elb3.ncsastage.usva1.featur ...

Creating variables dynamically and incorporating them into anchor tags: A comprehensive guide

In my HTML page, I have a feature where users can add multiple buttons with anchors that require passing variables. Currently, I am manually adding the variables like this: Code Snippet: <!DOCTYPE html> <html lang="en"> <head> ...

Fade in images smoothly

Currently, I am in the process of creating a visually appealing image "slider" for a landing page on one of my websites. The slider that I have already created is fully functional and successful, but I am looking to take it up a notch... My goal is to inc ...

Executing code asynchronously and handling callbacks using Process.nextTick and Promise

When I execute the following code: process.nextTick(() => console.log(8)) Promise.resolve("hi").then(t => console.log(t)) console.log(7); The output displayed is 7 8 hi This behavior is as expected because process.n ...

"Enhance your audio experience across all browsers with the revolutionary

I am looking for a way to play an mp3 file endlessly when the user opens my website. I need a lightweight crossbrowser solution that works in all browsers, including IE. Any suggestions? ...

What is the best method to extract the country_code from JSON data using jQuery or JavaScript?

{ "status": "success", "description": "Data successfully received.", "data": { "geo": { "host": "2405:204:3213:5500:b012:b9d5:e4db:47b6", "ip": "2405:204:3213:5500:b012:b9d5:e4db:47b6", "rdns": "2405:204:3213:5500:b012:b9d5:e4db ...

What is the best strategy for managing various contexts in React?

Just diving into React - I've been experimenting with using multiple contexts in my App component. Following the instructions laid out in the official guide on working with multiple contexts. Let me share my current code: App.js import React from " ...