The function getObjectById is not functioning properly and is throwing an error: TypeError - scene.getObjectById is

Just starting out as a new programmer in the world of Javascript and three.js, I encountered an error where getObjectById is not working properly. The specific TypeError message reads: "scene.getObjectById is not a function."

My goal was to access an object within the three.js scene using its id, which I had saved in an array at location tre[m][1].

The issue seems to occur not only with calling by id but also by name.

function crvtre(){

//  alert("I enter crvtre");
      for(var m=0; m<max; m++){
          for(var n=m+1; n<max; n++){
          // we should add in (tre[m][0] != tre[n][0]) to draw between trees only and inside one tree
              if(tre[m][5]==0 && tre[n][5]==0 && (tre[m][0] != tre[n][0])){

                  var object = scene.getObjectById(tre[m][1],true);
                  console.log(object.userData[1])
               }
           }
      }
      //animate();
}

Although this may seem like a trivial issue, I have been struggling to pinpoint the exact reason behind it. Any ideas or suggestions would be greatly appreciated!

Answer №1

The reason you're receiving that error is because getObjectById is not a function of THREE.Scene

If you need to retrieve an object within a scene and already know its location, simply access it like this:

var obj = tree[n][0];

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

When React first fetches data and users move to chat with each other, the state value does not update

Recently, I started learning about React and Node.js as I dive into building a chat application. When a user is clicked for one-on-one chat, I retrieve records from the database using backend Node.js and also incorporate socket.io. In my Chat.js file: imp ...

slow loading background slideshow in css

Creating a simple slideshow for the background using CSS has been successful, but I am facing an issue with making all backgrounds utilize background-size: cover. I want the images to fit properly on the screen. Another problem is that the pictures take a ...

Facing issues with building Angular 7 and Ionic 4 - getting error message "TypeError: Cannot read properties of undefined (reading 'kind')"

I need assistance with a problem I am encountering while building my Angular 7 & Ionic 4 application... When I run the ng build --prod command, I encounter the following error: ERROR in ./node_modules/ionic4-auto-complete/fesm5/ionic4-auto-complete.js ...

Deactivating the Grid and its offspring in React.js MUI

Is it possible to Disable the Grid (MUI Component) and its Children in React js? Additionally, how can we Disable any Container and its items in React js, regardless of the type of children they have? For example: <Grid item disabled // ...

Parent passing down React state, but child component fails to update it

When a setState function is passed down from a parent component, I aim to update the state of the parent setter if the enter key is pressed. However, despite setting the state, nothing seems to happen and I am left with an empty array. Below is the snippe ...

Tips for manipulating bits 52-32 within Javascript code, without utilizing string methods

Here is my functional prototype code that is currently operational: function int2str(int, bits) { const str = int.toString(2); var ret = ''; for (var i = 0; i < (bits - str.length); ++i) { ret += '0'; } re ...

const queryString = 'search=' + searchId; - using jQuery

I have recently started learning about jQuery and I am currently studying a piece of code in order to implement a similar concept in my coursework. $(function(){ $(".search").keyup(function() { var searchid = $(this).val(); var dataStr ...

Create a CSV file through an MVC Web API HttpResponse and retrieve it using AngularJS for downloading

I am attempting to create a CSV file from my web API and retrieve that file using angularjs. Below is an example of my API controller: [HttpPost] public HttpResponseMessage GenerateCSV(FieldParameters fieldParams) { var output = new byte[ ...

Retrieving the current day integer from a fullcalendar rendering in JavaScript and utilizing it as an array key

I am currently working on rendering a full calendar and I would like each cell to be displayed in a different color based on an array that contains color values for each day of the month. The array is retrieved in JSON format. Here is an example JSON arra ...

Unable to prolong TypeScript document

As I develop a drag and drop interface, upon dropping a file, the native File is retrieved. To enhance this interface with additional information, I decided to explore various approaches. In my initial attempt, I utilized: interface AcceptedFile extends ...

How to Disable Envmap in Three.js

Incorporating an environment map into my scene has been a successful endeavor. The lines of code involved are: sceneTarget.environment = envMap; and sceneTarget.background = envMap; Now, I am seeking guidance on how to disable the environment altogether. ...

Developing several sliders and ensuring they operate independently of each other

I am currently in the process of developing multiple sliders for a website that I am building. As I reach the halfway point, I have encountered a problem that has stumped me. With several sliders involved, I have successfully obtained the length or count ...

Transform the dynamic JSON format into a key-value pair structure with nested children nodes

Looking to convert a dynamic JSON structure into a tree node: { "video": { "width": 1920, "height": 1080, "video_codec": "H264", "CBR": "4337025", "frame_rate& ...

"Exploring the best method to utilize a for loop for updating an array of objects in

I'm looking to update a nested mongo document using a for loop with my node.js code below: //loop starts var update = { "rate":mainRate, "classifierCategories."+e+".rate":temiz[i].slice(0,2) }; classifier.update({"classifierS ...

Include a function call within a ternary operator in JSX code

I am looking to call a function within a ternary operator condition. Here is what my code looks like: {snapshot.Bid[0].Price !== 'undefined' ? `(${initialOrderInfo.snapshot.Bid[0].Price}` {renderCurrencySymb ...

What is the best way to navigate through the underlying MatDialog while the MatSelect is active?

When attempting to customize the scroll behavior of a MatSelect in a regular page, I discovered that using the MAT_SELECT_SCROLL_STRATEGY injection token with the NoopScrollStrategy allows for scrolling the underlying page while keeping the MatSelect stati ...

What methods can Ajax utilize to make asynchronous requests and receive synchronous responses?

While using jQuery ajax to send a request to a web service, I came across an interesting bug: var AjaxResult; login = function () { AjaxResult = ""; $.ajax({ type: "POST", url: KnutBase.getServiceUrl() + "ServiceInterface/HmsPlanne ...

Unable to export Interface in Typescript - the specific module does not offer an export named Settings

I am encountering an issue while trying to export/import an interface in Typescript. The error message I receive is causing confusion as I'm unsure of where I went wrong. Uncaught SyntaxError: The requested module '/src/types/settings.ts' ...

A guide to categorizing and tallying JSON data based on multiple keys within the past 30 days using JavaScript/jQuery

I am facing an issue while trying to display a chart and extract specific data from an array. My goal is to generate a chart based on three columns in a JSON array: Source, Campaign, and Date. The process involves grouping the data, counting it, and then ...

What is the way to include an additional filter in an AngularJS search filter?

I currently have a functioning search filter in place that utilizes a search input element: <input placeholder="Search" type="text" ng-model="search.$"/> Moreover, I have: <tr ng-repeat="person in people | filter:search:strict"> <td> ...