Error message in three.min.js version 2: The Object3D cannot be added because it is not an instance of THREE.Object3

Encountering an issue with the error message "three.min.js:2 THREE.Object3D.add: object not an instance of THREE.Object3D" when attempting to run a 3D object.

const loader = new THREE.OBJLoader();

loader.load("./model/Room.obj", function (object) {
  scene.add(object.scene);
  console.log(object);
  renderer.render(scene, camera);
});

Answer №1

Instead of using the traditional method:

scene.add(object.scene);

try this approach when working with OBJLoader:

scene.add(object);

The OBJLoader always provides an instance of THREE.Group which does not have a scene property.

It's important to note that each loader in three.js may return results in slightly different formats. This means that the code within the onLoad() callback should be tailored to the specific loader being used.

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

JavaScript Scrolling Functionality Not Functioning as Expected

I have implemented a scroll function on my website $('#lisr').scroll( function() { if($(this).scrollTop() + $(this).innerHeight()>= $(this)[0].scrollHeight) { //Perform some action here } } However, I am encountering an ...

Is the value of the index in the input constantly fluctuating in Vue?

I have a method that generates an array of objects in the following way: onCalculate_a(code) { let data = this.forms.calculate_a.map((p,i) => { return { product_code: code, price: p } }); this.su ...

Having trouble retrieving JSON array in PHP

I'm facing a challenge accessing data from PHP that's coming from JSON in JavaScript. I utilize local storage to store some temporary information: var tbRomaneio = localStorage.getItem("tbRomaneio");// Retrieves stored data tbRomaneio = JSON.pa ...

Issue with unrecognized expression in JQuery when processing Ajax response

Recently, I implemented a JQuery Ajax Form on my website. $('#modal-body-sign-in').on('submit', '#sign-in', function(e) { e.preventDefault(); var data = $(this).serialize(); var url = $(this).attr(&apo ...

Custom JavaScript code in Bootstrap Navbar Toggler results in closing the menu when a dropdown is clicked

As a newcomer to JavaScript, I am currently learning the language while working on a website. I have customized a template that I found online but am struggling with the JS code that I'm not very familiar with. Here's my issue: When using the na ...

Prevent child div from resizing along with parent div during a resize event by utilizing the .resizable()

Check out this example here I am able to resize the div using jQuery, but I don't want the #spacer to have a fixed width at first because the content of the could vary in size. Even if I remove: width:100px; and try setting it to a percentage or ...

Generate a custom website using React to display multiple copies of a single item dynamically

As a newcomer to React and web development, I've been pondering the possibility of creating dynamic webpages. Let's say I have a .json file containing information about various soccer leagues, structured like this: "api": { "results": 1376, ...

The ajax function does not provide a response

Can you help me figure out why this JavaScript function keeps returning 'undefined'? I really need it to return either true or false. I've included my code below: function Ajax() { var XML; if(window.XMLHttpRequest) XML=new ...

Guide on updating the default screen background color for all pages in React JS (Next JS) with the help of tailwind CSS

How can I change the default screen background color for all pages within my web application? Here are the technologies I've used: React JS Next JS Tailwind CSS I would like to set the screen background color of all pages to a light grey shade, as ...

Use jQuery to smoothly navigate to a designated pixel position by scrolling down the page

Is it possible to use jQuery to scroll down a page to a specific pixel? I am currently working on a website with a fixed navigation bar that scrolls to an anchor point when a button is clicked, utilizing the jQuery smooth scroll plugin. The issue I am fa ...

Obtain date and currency formatting preferences

How can I retrieve the user's preferences for date and currency formats using JavaScript? ...

Navigating to and Revealing a Division by Clicking

Check out this code snippet: <a onclick="$('a[href=\'#tab-customtab\']').trigger('click');">Enquire Now</a> <div id="tab-customtab"></div> This piece of code triggers the opening of the #ta ...

The issue of JavaScript Memory Leakage when utilizing FileReader and Promise

-Modify I have raised a bug report to address this issue I am attempting to upload a directory to my server containing large files, including CT scan images. While the process is functioning correctly, I am encountering memory problems. document.getElem ...

What sets Node.js, Npm, and node packages apart from each other?

After delving into the world of NodeJS, I found myself installing a variety of packages for different tutorials and projects. Eventually, my setup looked something like this: louis@louis:~$ node -v v5.10.0 louis@louis:~$ nodejs -v v6.2.1 louis@louis:~$ np ...

The extent of locally declared variables within a Vue component

Within this code snippet: <template> <div> <p v-for="prop in receivedPropsLocal" :key="prop.id" > {{prop}} </p> </div> </template> <script> export default ...

JavaScript: Update missing values in an array by assigning the average of its neighboring values

Consider the following array: [5,2,null,5,9,4] To replace the null value with the average of the previous and next values (2 and 5), you can do the following: [5,2,3.5,5,9,4] If there are consecutive null values in an array: [5,2,null,null,9,4] You c ...

Tips for automatically reloading a URL at specific times using Javascript

I am having trouble getting a URL to work when invoked by a cron job. My plan is to achieve the same outcome using Javascript: how can I refresh the page at a specific time each day (8:00 PM)? ...

Guide to implementing a variable delay or sleep function in JQuery within a for loop

I've noticed that many people have asked similar questions, but none of the solutions provided seem to work in my specific case. My goal is to incorporate a delay within a for loop with varying time lengths. These time lengths are retrieved from an a ...

How to Determine the Size of a JSON Response Using JQuery?

When using a JQuery getJSON call, how can I determine the length of the JSON data that is returned? function refreshRoomList() { $.getJSON('API/list_rooms', function (rooms) { if (rooms.length > 0) { ...

Comparing the use of `slice(-1)` versus `slice(0, -1)` with a

There is an array that we will refer to as collection. If the array has only one element, for example [5], then collection.slice(-1) will return [5]. But strangely enough, if you try collection.slice(0,-1), it will give you an empty array: []. Have you ...