Error message with ThreeJS ObjectLoader: "unable to interpret the 'fog' property as it is not defined"

Currently, my setup involves using ThreeJS to import a scene as shown in the code snippet below:

$(document).ready(function(){
    var scene = new THREE.ObjectLoader().load("scene.js");
    var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
    var renderer = new THREE.WebGLRenderer();
    var fly = new THREE.OrbitControls(camera);
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );

   var gui = new dat.GUI();
gui.add(controls, 'rotationSpeed',0,100);
    camera.position.z = 5;
    camera.position.z = 32;
    function render() {
        requestAnimationFrame( render );
        renderer.render( scene, camera );
    }
    render();
});
    var controls = new function() {
            this.rotationSpeed = 0.02;
            this.bouncingSpeed = 0.03;
    };

Here is the link to the scene I am using (Exported from ThreeJS editor):
However, when attempting to load the scene, an error message repeatedly appears stating "cannot read property 'fog' of undefined" and "undefined is not a function". What could be causing this issue? How can it be resolved?

Answer №1

load() operates asynchronously, meaning it does not return a value directly but instead passes the result to a callback function. You can try implementing it like this:

var loader = new ObjectLoader();
loader.load('scene.js', function(object) {
    scene.add(object); // Add the loaded object into your scene here
});

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

Breaking up a string using regex with various conditions

(Javascript old version of Node.js) Update: I need to clarify my request. I have a variety of instances like these var name1; CONST name2 Let nam; leT nam VAr n1 ; What I want as output is name1 name2 nam nam n1 Therefore, I am ex ...

What is the process for retrieving document field values for an item in Umbraco 7 backoffice?

I have developed a unique Umbraco 7 dashboard where I aim to retrieve specific field details from instances of a particular document type in my Umbraco CMS. After successfully obtaining a list of all documents of the specified type using entityResource.ge ...

Definitions for TypeScript related to the restivus.d.ts file

If you're looking for the TypeScript definition I mentioned, you can find it here. I've been working with a Meteor package called restivus. When using it, you simply instantiate the constructor like this: var Api = new Restivus({ useDefaultA ...

How can I create a JSON string that exactly matches the data source needed for a pie chart? Any tips

received JSON string: "{Date:'15/05/2015',y:'6'}, {Date:'01/08/2015',y:'6'}, {Date:'02/08/2015',y:'6'}, {Date:'08/08/2015',y:'72'}, {Date:'09/08/2015',y:&apo ...

Organize routes into distinct modules in Angular 6

Currently grappling with routing in my Angular 6 application. Wondering if the structure I have in mind is feasible. Here's what it looks like: The App module contains the main routing with a parent route defining the layout: const routes: Routes = ...

What is the best way to transfer variables in my specific scenario?

As I consider the optimal approach for managing my controllers, I find myself faced with a challenge of passing data between them. In my setup, I have multiple controllers that require sharing data throughout. For the first controller: app.controller(&a ...

The Vanilla JS script in Next.js fails to execute upon deployment

Currently developing a simple static site with Next.js. The lone vanilla JS script in use is for managing a mobile menu - enabling toggling and adding a specific class to disable scrolling on the body: if (process.browser) { document.addEventListener(&ap ...

Blending Angular5 and AngularJS in Polymer

We are considering launching two new projects - one using Angular 5 and the other utilizing Polymer. The second project is intended to serve as a component library for reuse in not only the Angular 5 project but also in other AngularJS projects. After res ...

Is it possible to configure route localization in Next.js and next-i18next to function as an URL alias?

Currently, I am utilizing NextJs version 10.0.5 in conjunction with next-i18next version 8.1.0 to localize my application. With the introduction of subpath routing for internationalized routing in NextJs 10, I encountered a situation where I needed to modi ...

Getting information from a JSON file with several variables: A guide for using node.js, express, and jQuery

In order to minimize the number of Ajax calls, I am attempting to send three variables in a single Ajax response. However, I am facing difficulties when trying to process the data on the client side. Let me elaborate on my issue and if sending multiple var ...

What is the best way to make three divs that can be adjusted in size?

Desired Layout: | A | | B | | C | ^ ^ Adjustment Behavior: | A | | B | | C | Current Issue: | A | C | I attempted to enhance the functionality by modifying the provided JavaScript cod ...

Tips for creating emissiveMap lighting exclusively in dimly lit spaces using three.js

Using three.js, I am able to render the earth with textures and add an emissive texture for city lights. However, I am facing a problem where even the light areas of the earth emit city lights. For example: https://i.sstatic.net/hZ1Cr.png Is there a way ...

Enhanced functionality for Thingworx using ThreeJS

I'm currently facing an issue while developing a 3 JS extension for Thingworx, specifically with the renderHtml function when working with a 3 JS canvas (Check out the code). //runtime.ts file renderHtml(): string { let htmlString = '<div ...

JavaScript: Creating keys for objects dynamically

const vehicles = [ { 'id': 'truck', 'defaultCategory': 'vehicle' } ] const result = [] Object.keys(vehicles).map((vehicle) => { result.push({ foo: vehicles[vehicle].defaultCategory }) }) c ...

Printing feature not functioning properly on Internet Explorer version 11

Currently, I am facing an issue with printing a document using a blob URL and iFrame. Everything works perfectly in Chrome, but unfortunately, it's not functioning properly in IE browser. I need guidance on how to successfully print a blob URL that i ...

Using the after ship.com API with CORS in JavaScript using Ajax

Hi everyone, this is my first time posting here. I'm having trouble sending data via the POST method. When I checked the console, I saw the following error message: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote ...

Is it possible to retrieve data from a particular index within an array using Mongoose

For instance, if the following is my documents: { "field": [ "hello", "random wording", { "otherId": 3232, "otherId2": 32332 } ], } Would it be possible to create a query that matches both i ...

Benefits of using props destructuring in React - beyond just being a syntactic shortcut

This idea might not be exclusive to React, but I've struggled to discover a compelling reason beyond concise and easier-to-read code. ...

No location matched any routes

I'm currently working on a notes application, and I've encountered an error when trying to edit the notes. The error message says "No routes matched location id ...". Any idea what could be causing this issue? The approach I'm taking is to ...

Tips for organizing HTML logic in a separate document

I am faced with the task of displaying a list in HTML based on specific conditions: <!-- Display list if there are more than 5 results --> <div list.numberOfResults > 10"> <b>Name: </b>{{list.name}} <b>ID ...