Utilizing components of GLTF to create an InstancedMesh

I have been working on replicating a specific piece of code found in the three.js repository related to instanced rendering.

While following this example, I came across a part that is confusing to me.

Why do we need to copy THREE.InstancedBufferGeometry by using THREE.BufferGeomtry.prototype?

loader.load( './models/gltf/Flower/Flower.glb', function ( gltf ) {

            const _stemMesh = gltf.scene.getObjectByName( 'Stem' );
            const _blossomMesh = gltf.scene.getObjectByName( 'Blossom' );

            stemGeometry = new THREE.InstancedBufferGeometry();
            blossomGeometry = new THREE.InstancedBufferGeometry();

            THREE.BufferGeometry.prototype.copy.call( stemGeometry, _stemMesh.geometry );
            THREE.BufferGeometry.prototype.copy.call( blossomGeometry, _blossomMesh.geometry );

It seems like it may be a JavaScript concept, but I am still unclear on why it has to be done this way.

Is there a reason why I can't simply use InstancedBufferGeometry.copy() directly?

Thank you,

Answer №1

What is the reason for copying THREE.InstancedBufferGeometry by THREE.BufferGeometry.prototype?

InstancedBufferGeometry inherits from BufferGeometry and has a modified copy() method. If you were to directly use InstancedBufferGeometry.copy(), it would attempt to copy an InstancedBufferGeometry specific property called instanceCount from a BufferGeometry. This would cause the property of the subclass to become undefined.

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

Creating three functions with the same name, one with a callback, another with a promise, and the third with async/await, can

I am looking to create a versatile function that can be used in 3 different ways to handle npm dependencies Using Promises Using callbacks Using async/await For Instance 1) Using async/await var mongoose = require('mongoose'); async fu ...

Tips for creating CSS styles for a selected input field

I seem to be stuck in a situation where my screen looks similar to the screenshot provided. There are four input elements that I would like to have bordered just like in the image, complete with a circled tick mark. I've managed to create these four i ...

Arranging date and time in jQuery based on AM/PM notation

I have written some JavaScript code to sort dates in ascending order (from newest to oldest). I have successfully sorted the dates, but I am having trouble sorting the time with AM or PM using a 12-hour format. I can do it in a 24-hour format, but not in ...

Tips for making a horizontal grid layout with three items in each row

I have a scenario where I need to render a group of Player components using map() loop, and I want them to be displayed horizontally side by side using a Grid component from material-ui. Currently, the components are rendering in a vertical layout: https ...

Steps for verifying the presence of an element in Selenium using JavaScript

I'm facing an issue with a Jest and Selenium test. I'm trying to verify if an element is removed from the DOM after being clicked. Here's what I've attempted: test('User removes button after clicking on it', async (done) =& ...

Is there a way to delegate properties in Angular 2+ similar to React?

When working with React, I have found it convenient to pass props down dynamically using the spread operator: function SomeComponent(props) { const {takeOutProp, ...restOfProps} = props; return <div {...restOfProps}/>; } Now, I am curious how I ...

When I decide to incorporate both BootstrapVue and Vuetify CSS frameworks into a single project

Can I incorporate two CSS frameworks into my current Nuxt.js project? Does anyone have any insight on why it might be beneficial to use two different CSS frameworks in a Vue.js project? Please provide some guidance on this matter. I am looking to optimize ...

Mastering the Art of Nodemailer

Can anyone advise on how to utilize nodemailer with dynamic email and password retrieved from a database? export const mailTransporter = nodemailer.createTransport({ service: 'gmail', auth: { user: email_user, pass: email_pass, }, } ...

Issue with Translate3d functionality in fullpage.js not functioning as expected

Currently, I am in the process of constructing a website using fullpage.js with WordPress. Everything is functioning well except for one issue - when attempting to disable the plugin by using destroy() or changing setAutoScrolling to false, the translate3d ...

What is the reasoning behind placing CDN links at the bottom of the index file?

What is the reason for placing CDN links for AngularJS file at the end of the index page? I initially placed it at the top of the file and it worked fine. Is there a significant difference between these two placements? ...

Verify if the form has been refreshed in React JS

In my React application, I have a form inside a modal pop-up. When the user closes the pop-up, I want to check for any changes made in the form fields. If there are changes, I will display a confirmation modal; if not, I will simply close the pop-up. <F ...

Using the React JS useState hook to toggle the state of a JSON object containing an array when a checkbox is clicked

When I submit my state as a stringified variable from a form to a POST request via a lamda server, it gets parsed and sent to sendgrid for templating. To loop over specific parts (multiple checkboxes) in JSON format, each with the same key but different va ...

Troubleshooting issue with Ajax.Actionlink not canceling request using jQuery's onBegin

In the "onBegin" ajax option of an ajax.actionlink, I have a function that is called. function cancelAction() { $.ajax({ data: { p: "test", z: "value" }, url: '@Url.Action("DoSomething", "TestCtlr")', type: "GET", ...

Press and hold feature using CSS or JavaScript

When working with a jQuery draggable element, my objective is to change the cursor to a move cursor when clicking and holding the header. I have attempted using CSS active and focus properties, but so far no changes are taking place. ...

I am sometimes experiencing issues with activating ajax code using Bootstrap 3 modal

I'm stumped trying to find a solution for this issue. Currently, I am utilizing the bootstrap modal to retrieve ajax content from a specified URL. To prevent content overlap, I am using $.removeData() when reloading the content. The problem arises w ...

Tips for checking the type radio button input with Angular.js

I want to implement validation for a radio button field using Angular.js. Below is the code snippet I am working with: <form name="myForm" enctype="multipart/form-data" novalidate> <div> <input type="radio" ng-model="new" value="true" ng- ...

Running compiler-produced assembler code within the program

Recently, I came across an interesting presentation discussing inline ASM generation in Javascript optimization. The presentation can be found at the following link: . In another paper located here: https://sites.google.com/site/juliangamble/Home/Compiler ...

Creating a dynamic loader with JavaScript and PHP: A step-by-step guide

Currently focused on PHP development, my task involves retrieving data from a database using multiple queries. The database may contain anywhere from 10 records to 10,000 records. I am looking for a way to incorporate a progress bar that displays the com ...

What are the solutions for resolving the error "npm run build failed to compile React JS?"

Having trouble creating an optimized production build... Compilation failed. Module not found: Error: Unable to locate './App' in '/Users/qadeer/Desktop/Khazan/guardman/src' Did you mean 'App.js'? BREAKING CHANGE: The request ...

Operate on Nested JSON Arrays

I have the following JSON array: var salesData = [ { "products": "Cars", "solddate" : "2022-01-01", "noofitems" : " ...