Deleting items based on identification

When attempting to remove my 3DObject created with three.js using the Id, it doesn't work. However, when using the Name, it works perfectly. Is there a mistake in my approach?

    scene.remove(scene.getObjectByName("objectname")); //successfully removes by Name
    scene.remove(scene.getObjectById(objectID)); //unsuccessful attempt at removal by Id

Answer №1

scene.remove() is specifically designed to work with objects that are direct children of the scene. If you encounter an issue, consider using this alternative snippet of code:

var object = scene.getObjectById( objectID )
var parent = object.parent;
parent.remove( object );

This workaround was tested on three.js R109

Answer №2

I've hit a roadblock in my progress. I have identified the issue, but finding a solution has proven elusive.

Currently, the Raycast is not returning the correct object.id. While intersects[0].object.id shows 72, logging the id of my created object reveals it to be 21. Furthermore, the scene.object.name is set to BotSkinned through code (object.name = "BotSkinned"), yet the Raycast reports intersects[0].object.name as "Bot_Skinned_0". I am searching for a way to properly link my Raycastobject to my coded object, particularly since I need to create multiple objects with the same name and must utilize the ID for this purpose.

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

Revamping the purpose of a function found within an HTML <script> tag

index.html: <script id="change"> function methods(){ return 1; } </script> js.js: ... button.addEventListener("click", ()=>{ document.querySelector("#change").innerHTML = ` function ...

The serverless functions in Next.Js only seem to work after being pinged

I am dealing with an endpoint in my project that receives messages from a WhatsApp webhook. This endpoint then makes an asynchronous call to another endpoint and responds with a 200 status back to the WhatsApp webhook. While this process works smoothly an ...

Seeking assistance in setting up localization for a web application with JavaScript and JSON integration

I'm currently working on setting up a web application that needs to be able to use client-side JavaScript for localization, especially since it will need to function offline. In order to achieve this, I have created a function and a JSON array within ...

How can you modify the styling of a single child element within a grandparent container and then revert it back to its original state

My goal is for #homeContainer to occupy the entire width of the page, but a higher-level element is restricting its width and margin. Below you can see the DOM structure. By removing margin: 0 auto, I am able to achieve full width. How can I specifically ...

How can I convert a Node.js Express response from JSON to an HTML page?

I have a small application that sends various error messages to the client in JSON format if something goes wrong. Is it possible to display these messages on an HTML page somehow? For instance, let's say I have a simple login form with fields for u ...

Having an issue with the Show/Hide Javascript toggle on the same page. Multiple hidden texts are appearing simultaneously. Seeking a solution without the use of JQuery

This code is functioning efficiently. I am looking for a way to display and conceal various texts using different expand/hide links within multiple tables on the same page. I prefer to achieve this without using JQuery, just like in this straightforward sc ...

Angular directive ng-if on a certain path

Is it possible to display a specific div based on the route being viewed? I have a universal header and footer, but I want to hide something in the header when on the / route. <body> <header> <section ng-if=""></section&g ...

HTML code that has been "commented out" means

Within my _Layout.cshtml file, the following lines are present: <!--[if IE 7]> <link rel="stylesheet" type="text/css" media="all" href="/Content/css/ie7.css" /> <![endif]--> <!--[if IE 6]> <link rel="stylesheet" type="te ...

Developing a personalized Object3D class

Having a background in AS3/Away3D, I am new to THREE.js and I am trying to create a custom object class that extends THREE.Object3D for my scene. CustomObject will contain behavioral properties and methods, with each instance having its own data object det ...

Can fog be applied from a fixed location within a three.js scene without being tied to the camera's position?

Is it feasible to render fog in such a way that an avatar on a terrain remains clear while the surrounding area gradually fades into the mist, especially when the camera is positioned overhead at a distance? ...

The transparency attribute in BufferGeometry allows for the manipulation

When working with BufferGeometry, one can easily utilize the material setting {vertexColors: THREE.FaceColors} to assign various colors to faces. However, the challenge arises when trying to establish transparency. Is there a method available to apply tra ...

reCAPTCHA v3 - Alert: There are no existing reCAPTCHA clients available

After coming across a similar issue on Stack Overflow (link to the question here), I attempted to implement reCAPTCHA on my website to combat spam emails received through the form. Despite following Google's instructions, I encountered an error that p ...

In what way does this closure cause componentDidUpdate to mimic the behavior of useEffect?

Recently, I came across an insightful article by Dan Abramov titled: A Complete Guide to useEffect. In the section that discusses how Each Render Has Its Own… Everything, two examples were provided. The first example demonstrates the usage of useEffect a ...

How can I completely alter the content of aaData in jquery.dataTables?

Looking to completely change the content of a datatable purely from a javascript perspective, without relying on Ajax calls. I've attempted using the following script: oTable.fnClearTable(); oTable.fnAddData(R); oTable.fnAdjustColumnSizin ...

Ways to extract data from form inputs with the help of jQuery

My HTML form allows users to enter data and upon submission, I need to use jQuery to capture the entered values. <form class="my-form needs-validation" method="POST"> <input type="text" id="firstName" name="First Name"> <input type="tex ...

Error: Attempting to access the 'getCroppedCanvas' property of an undefined value in VueJs

I've been exploring the vue-cropperjs library, but every time I execute the code, I encounter error messages: Uncaught TypeError: Cannot read property 'getCroppedCanvas' of undefined Uncaught TypeError: Cannot read property 'replace&ap ...

The correct method for including a CSS file in a Vue.js application

How can external CSS files be properly added in a Vue.js Application? I have come across multiple methods for adding CSS files in a Vue.js Application. One suggestion is to use the following code: <link rel="stylesheet" type="text/css" href="/static/b ...

"Enhance Your Browse experience: Chrome Extension that automatically appends content to pages

I'm currently developing a Chrome extension that detects when a URL on a specific domain changes, and if the URL matches a certain pattern, it will add new HTML content to the webpage. Here is an excerpt from my manifest.json file: { "name": "Ap ...

Creating a component context in React JS

Can someone help me understand how to create a React component context? I have managed to get it working, but I struggle because of my lack of understanding of React. I will share my code. My goal is to create a set of 4 page components that appear withi ...

I am currently facing an issue with my Next JS app where the search results page is not showing up when a user enters a query

I am currently working on a search application using Next.js. Within my app directory, I have 3 main files - layout.js, page.js, and searchResults.js Here is the code in layout.js: export const metadata = { title: 'xyz Search', description: ...