Create multiple instances of Object3D in THREE.js with various positions and rotations

Can I draw Object3D multiple times with different locations/rotations without cloning it? I want to avoid duplicating the object and instead just reference its geometries and materials. The Object3D in question is a Collada model (dae.scene) in my code.

var obj = new THREE.Object3D();
//...

var objs = [];
for(var i=0; i<10; i++) {
    objs.push( ? );
}

objs[j].position.set(x, y, z);
//...

Your help is much appreciated,

Answer №1

One way to achieve this is by creating several Object3D instances and attaching the Collada object you want to display multiple times as a child object to each one. By specifying position, rotation, and scale for each Object3D object, you can render your Collada object at different locations. Although your Collada object only exists in one instance, it can be rendered multiple times due to the Object3D objects.

Answer №2

If you try to add the same model to your scene without first cloning it, you will encounter issues. The materials and geometries of a collada model may be located at various levels within the model hierarchy, but you can navigate through the hierarchy to locate them. Cloning the model is the recommended approach. It's worth noting that as of now, Three.js does not support the concept of an instance of a model.

To learn more about how to properly clone a model in Three.js while loading it only once, check out this resource: Three.js - load JSON model once and add it multiple times.

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

Using Express.js and Angular for user authentication and session management

In my current project, I am utilizing expressjs and angularjs to create an app. The setup involves expressjs serving a single .html file that houses an angular single-page-application. All routing is handled by angularjs, while expressjs provides web servi ...

Is there a way to automatically adjust the size of an input field after dynamic spans have been

I am looking to replicate the tagging functionality found on StackOverflow when posting a new question. In this case, spans are dynamically added using an input field located next to them. Here is an example: <div> <div id="multiple-span"&g ...

How do I go about showing every character on a separate line using a for loop?

var input = prompt("What is Lance attempting to convey?"); //user enters any text for (var i = 0; i <= input.length; i++) { var output = input.charAt(i); if (output == "e" || output == "o" || output == "a" || output == "u") { outp ...

Tips for effectively redirecting traffic to another website

Is there a way to redirect someone from a page URL like example.com/2458/233 to example2.com/2458/233? The first URL contains only a file that redirects to the other domain. Can anybody provide instructions on how to achieve this process? To clarify furt ...

What are the steps to implement the jQuery slide menu effect on a website?

When visiting the website , you may notice a symbol positioned in the top left corner of the site. By clicking on this symbol, a sleek div will slide out. How can this type of animation be achieved through javascript or jquery? ...

How does the Angular2-all.umd.js compare to the angular2.js file?

Currently, Angular 2 is in its 13th beta phase. I came across https://code.angularjs.org/2.0.0-beta.13/ and noticed that there are two different versions of Angular2 available: angular2-all.umd.js angular2.js What distinguishes these two versions from ...

What is the best starting dataset to use from a large pool of data points when creating a stock line chart in High

I am working on creating a line stock highchart similar to the example shown here: https://www.highcharts.com/demo/stock/lazy-loading In the provided example, the initial load fetches data from https://demo-live-data.highcharts.com/aapl-historical.json, s ...

jQuery live function is not functioning as anticipated

I am facing issues with ajax requests and simple <input type="submit"/>. I have a practice of loading views within other views, in a modular way, using jQuery's .load(url) function to move from one view to another. The problem arises when I loa ...

Is there a way to assign a vertex shader to a geometry in threeJS without altering the material?

Currently, I am experimenting with modifying geometries using my vertex shader. The shader applies specific linear transforms to each vertex of the geometry, resulting in a change in shape. However, I am facing difficulty in enabling phong lighting and tex ...

How can I store items in a JavaScript array so that they are accessible on a different page?

I'm running into an issue with my PHP website. Each item has a "request a quote" button that, when clicked, is supposed to add the item name to an array using JavaScript. This array should then be added to the "message" field on the contact.php form. ...

Display the MediaStream on a WebGLRenderer

It may sound a bit unusual, but how can you display a video stream var videoStream = new MediaStream(stream.getVideoTracks()); using var renderer = new THREE.WebGLRenderer({antialias: true, alpha: true}); renderer.setSize(640, 480); ...

This code encountered an Uncaught SyntaxError due to an invalid or unexpected token

Hey there, I've been struggling with an Uncaught SyntaxError: Invalid or unexpected token issue whenever I try to click on the edit or delete button. Can someone please help me figure out what's wrong with this code? I've spent hours looking ...

Is there a way to transfer a JSON map object from Flask and then utilize it as a JavaScript object?

python server code from flask import Flask, render_template, request import os import sys import json data_raw = [('0', '1', '0', '0'), ('0', '0', '1', '0'), ('1', ...

Tips for utilizing rowspan and colspan in BootstrapTable

I am creating a table using bootrapTable and would like to know how I can use rowspan or colspan to achieve a table layout similar to the one shown in this image: Click here for image description $table.bootstrapTable({ columns: [{ ...

What is the best way to ensure the checkbox functions correctly in this specific situation?

I am utilizing PHP, Smarty, and jQuery in the development of my website. Currently, I am working on implementing checkboxes within a Smarty template. Below is a snippet of my Smarty code related to checkboxes: <table cellpadding="5" cellspacing="0" bor ...

Obtaining the value of a specific dynamic `<td>` element using jQuery

My page layout resembles this design (I am unable to post an image due to insufficient points, so I have it hosted elsewhere) My goal is for jQuery to identify the specific email when a user clicks on the delete button. For instance, if a user clicks on & ...

Obtain the native element of a React child component passed through props, along with its dimensions including height and width

Is there a way in React to access the native HTML element or retrieve the boundaries of an element passed as a child in props? Consider the following component: class SomeComp extends Component { componentDidMount() { this.props.children.forEa ...

Having trouble with utilizing react-select and its menuIsOpen attribute?

Currently, I'm navigating a complex component that requires the use of an options list. As react-select is already implemented throughout my application, it seems logical to utilize it in this scenario as well. My goal is to integrate react-select inl ...

Creating a promise in an AngularJS factory function to perform an operation

When working within an Angular factory, I am tasked with creating a function that must return a promise. Once the promise is returned, additional functionality will be added. SPApp.factory('processing', ['$http', '$rootScope&a ...

Error encountered while connecting to SQL Server from node.js causing the express server to crash due to a ConnectionError

Encountering an issue with node.js tedious error ConnectionError: Failed to connect to sqlserverip:1433 causing unexpected crashes in my express server. Seeking suggestions on how to prevent such crashes. <a href="/cdn-cgi/l/email-protection" class="__ ...