Tips for resolving the "THREE.Object3D.add: object not an instance of THREE.Object3D." error when using OBJLoader

In an attempt to enhance my VR scene, I am following a tutorial on adding controllers using OBJ models. I wanted to use custom OBJ models in place of the default line pointers but encountered a loading issue where they either took too long to load or didn't load at all.

 ...
 var gun = new OBJLoader();
 gun.load('models/CA-87.obj');

 this.controllers = [];
  ...
 for (let i = 0; i < 2; ++i) {
 const controller = renderer.vr.getController(i);
 //controller.addEventListener('select', selectListener);
 //controller.addEventListener('selectstart', selectListener);
 //controller.addEventListener('selectend', endListener); 
 scene.add(controller);

 controller.add(gun);

 this.controllers.push({controller, gun});
                  }
 ...

I encountered the following errors: "THREE.Object3D.add: object not an instance of THREE.Object3D. > Object { manager: {…}, materials: null }". The expectation was to see these custom models integrate into the scene and respond to the movements of the vive controllers being used, but unfortunately, they did not appear as intended.

Answer №1

weapon is a tool for loading objects, not the object itself. According to the documentation, OBJLoader provides an Object3D in a callback function. So...

let objLoader = new OBJLoader();
objLoader.load('models/CA-87.obj', weapon => {
  // ...
  inventory.add(weapon);
  // ...
});

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

Accessing local JSON data through JavaScript

I am looking to access a JSON file locally using JavaScript. The file is named "posts.json" and contains the following information: { "post0": "<empty>", //1 "post1": "<empty>", //2 "post ...

Is web analytics done via client-side (JavaScript) or server-side logging on websites?

As I embark on creating a web application to track web statistics for my clients, I've run into a dilemma. With the rise of ajax usage, I'm unsure whether it's best to log a user visit using JavaScript or serverside. Additionally, I'm u ...

Steps to create a "drop down" feature similar to the one seen in Gmail

I am currently working on creating a dropdown panel similar to the one found on the top bar of Gmail. When users click on the Setting icon, their name, or the Share link, a panel drops down. Is there a jQuery plugin available that can help me quickly imp ...

The axios-retry feature fails to handle responses with a status code in the 4XX range

Currently, I am utilizing axios to make API calls. In the event of a failure or when the response status is not equal to 200, it is imperative that I retry the API call. By default, axios's retry mechanism is designed to handle status codes in the 5XX ...

What is the reason why createServer() is often not recognized as a function?

After installing express globally and npm on my express app, I am encountering issues with both intellisence and the app itself (I am using visual studio code on mac OS Yosemite). Below is a snippet of the code: /// <reference path="typings/node/node. ...

Following conventional methods often results in oversized containers and monolithic code

I've heard that it's recommended to use classes for containers and functions for components. Containers handle state, while components are simple functions that receive and send props to and from the containers. The issue I'm encountering i ...

Retrieve an array from the updated scope

I need help with my code. How can I retrieve the names from an array and display them in my input box? Also, how do I get all the changed names back into the array? Thanks in advance! - Marco app.js var g[]; var names = ['John', 'Steve&apo ...

Discovering the file names of JavaScript files within a context path and dynamically loading them

I am currently working on a Struts application where I need to dynamically load a JSP file with its corresponding JavaScript file upon menu selection. Although the functionality is working smoothly, I am facing an issue in loading the JavaScript file along ...

The issue of execution order in JavaScript Recursion with promises

In the process of developing a method for creating markup to be used in a web app's off-canvas navigation. One of the challenges I am facing is making an asynchronous callback to another service that provides children nodes for the parent menu node (r ...

Connect my Vue.js model data to the object that will be used for submission

I need help figuring out how to bind data from my input field into my Vue.js model. I've tried putting the UnitName inside the model but it's not working. Can someone provide some guidance on how to achieve this? new Vue({ el: "#app", da ...

Learn how to effortlessly transfer a massive 1GB file using node and express

Encountering an issue when attempting to upload a large file to a node js instance using express, resulting in failure for files of significant size. The error message received is as follows: Error: Request aborted at IncomingMessage.<anonymous> (/s ...

Using React Native - Issue occurs when tapping a row within a ListView: Property `_pressRow` cannot be read as it is null

Currently, I am working on a small ReactNative + Redux application that utilizes a ListView. While referencing the code example from the documentation available at here, I have implemented a setup similar to the provided sample. However, I am encountering ...

What benefits does registering a Vue component locally provide?

According to the Vue documentation, global registration may not always be the best option. The documentation states: Global registration is not always ideal. When using a build system like Webpack, globally registering all components can result in unnece ...

Struggling with setting up dynamic URL parameters in react-router

I'm working on generating dynamic URLs to display different content based on the URL parameters. When I include: <Route path="/example/:id" component={Example} /> and then visit /example/99 in my browser, I see an error message in th ...

Error message in Vuex4: Unable to access 'state' property because it is undefined

Having trouble with Vue3 and Vuex4, I keep encountering this error: Uncaught TypeError: Cannot read properties of undefined (reading 'state') at ReactiveEffect.eval [as fn] (App.vue?3dfd:36) at ReactiveEffect.run (reactivity.esm-bundler.j ...

The author's voice kicks in with a warning message whenever he makes a mistake with a command

Hello everyone, I hope you are having a great day! Today, I am looking for a code that will kick someone named "A" from the voice channel if they do not follow a command correctly. Let me explain my requirements through the code snippet below: const discor ...

Angular JS presents an exciting feature called Multiple Filters, which allows

I have a data representation application that displays information in table format with columns id, name, price, quantity The data is presented using ng-repeat. You can view it on this Plunker <body ng-controller="myController"> <h1>Data< ...

Display title upon hovering over image linked to mysql with php

Is there a way to display the image title when hovering over images connected to MySQL using PHP? Below is the code I have been using: <div class="galleryko"> <?php $data = mysql_query("SELECT * FROM tbl_gallery_featured")?> <div clas ...

Utilize jQuery to extract all values from the second cell of a table and store them in an array

I have a task that involves pushing numbers from text boxes into an array. These text boxes are located in the second cell of each table row, while the third cell contains a date picker. Currently, the code snippet provided retrieves all values from both ...

Determine the available time slots for reserving a resource

I am developing an application that displays the weekly availability (Monday-Sunday) of a bookable resource. Next to this calendar view, users can select: A) Length of desired booking slot (15 min/30 min/60 min) B) Time zone The time slots are based ...