"Displaying a Variety of STL Files Simultaneously with ThreeJS on a Website

Hello, I am currently working on displaying multiple STL files using threeJS in a web page. I have successfully displayed one file, but I am stuck on how to render more than one STL file on the same page. Below is my existing code:

var container, camera, scene, renderer;

init();
animate();

// Code continues...
<div id="pratik"></div>

I am looking for guidance on how to include another STL file named 'mk6.stl' in addition to the current file. If anyone has experience with this and can provide assistance, it would be greatly appreciated. I tried using SketchFan, but it did not meet my requirements. Thank you.

Answer №1

If you've already managed to load a single STL file and integrate it into your scene, the process for loading multiple files is quite simple. You can just reuse your STLLoader instance as shown below:

var loader = new THREE.STLLoader();
loader.load( 'FIRSTFILE.stl', function ( geometry ) {
    var material = new THREE.MeshPhongMaterial( { color: 0xff5533 } );
    var mesh = new THREE.Mesh( geometry, material );
    scene.add( mesh );
} );

loader.load( 'SECONDFILE.stl', function ( geometry ) {
    var material = new THREE.MeshPhongMaterial( { color: 0xff5533 } );
    var mesh = new THREE.Mesh( geometry, material );
    scene.add( mesh );
} );

Alternatively, if you have an array of URLs containing the paths to your STL files, you can utilize a loop to iterate through them and use the loaders load() method.

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

Ways to maintain group settings for a Telerik MVC Grid connected to Ajax

Currently, I am seeking guidance on how to persist grouping settings on an Ajax bound Telerik ASP .NET MVC grid. My goal is to have the grid display revert back to its previous settings when a user navigates away to a detail screen and then returns to the ...

Failed to input data into the database

I created a modal window with a form that should submit the field data to the database without closing the modal window. It should then display a message saying "You have been RSVP'd" before fading out the modal window. There are 2 issues: 1) After ...

Tips for comparing JSON object structures: contrasting an array of objects like [{},{},{}] with a single object like {k:v, k2:v2

I have a PHP application where I receive two different JSON responses from two different tools. However, I want to utilize the same JavaScript code to handle both responses. My goal is to compare the following data structures: data = [ {'k1': ...

What is the best way to create a slideshow using an IFrame?

Currently seeking a solution for an iframe slideshow that can smoothly transition between multiple HTML iframes. I have a total of 5 iframes that need to rotate automatically and continuously. Any suggestions on how to build a lively and dynamic iframe sl ...

Setting up a Babel configuration for a full-stack MERN application

After giving up on learning Rails, I shifted my focus to diving into Node using the MERN stack. Despite completing courses by Stephen Grider and Andrew Mead on Udemy, as well as all the Code School JS courses, I feel like I'm not making much progress. ...

Inquiries about ngshow and the scope concept

I have a question about using AngularJS. I have multiple sections and only want to display one at a time using <section ng-show="section6_us"> </section> and <section ng-show="section7_us"> </section>. My scope has many variables. ...

Encountering a "DOM Exception 11: InvalidStateError" when attempting to use websocket.send

I encountered the following error message: DOM Invalidate exception 11 This error is coming from the code snippet below, but I'm having trouble identifying the root cause. /*The coding style may appear pseudo-stylish with potential syntax errors*/ ...

What is the best way to merge values in an array based on their keys?

Here is a sample of the data I have: data = [ [ {"name":"cpumhz","data":[[1433856538,0],[1433856598,0]]}, {"name":"mem","data":[[1433856538,13660],[1433856598,13660]]} ], [ {"name":"cpumhz","data":[[1433856538,0],[1433856598,0]]}, {" ...

Is it possible to access a function on the main page from a plugin?

In my plugin, I need to call a function that is located on the main page, not within the plugin's .js file. EDIT I am currently working with jQuery to parse a very large XML file and generate a substantial list (resulting in a 1.1 MB HTML file when ...

Why is my HTTP request callback not being executed?

I've been trying to send an HTTP POST request to a 3rd-party API using a promise method. Oddly enough, the callback function never seems to run, even though when I test the code on its own, the API call is successful. Node.js and the concept of an e ...

Using input masking to restrict user input to only numbers and English alphabet characters

My input field is masked as "999999999" and functions correctly with an English keyboard. However, I am able to enter Japanese/Chinese characters into it, which breaks the masking. Is there a way to limit input to English keyboard numerics only? <inpu ...

Order a portion of a JSON array according to another part of the same array

Having a json array that needs sorting in JavaScript. The EventName field should match the respective Age fields like 01-10 Days and 10-20 Days. [ {Age: "01-10 Days", EventName: "Invoice AP Review", Value: 1, ActiveInvoices: []} ,{Age: "01-10 Days", Even ...

Is it possible to retrieve correctly formatted JSON data from this API?

I need help retrieving data from the API located at . When I access the API directly, it returns an array wrapped in <pre></pre> tags, rather than in JSON format. I would like to use an AJAX call to retrieve this data instead of using PHP. Is t ...

How can I ensure that an item stays in place within a vertically sortable list using Dndkit? (I am also considering alternative drag-and-drop libraries)

Let's say for instance that 5 was marked as frozen. If 4 was then moved below 6, the change in arrangement would be as follows: before: https://i.sstatic.net/iVZFtAmj.png after: https://i.sstatic.net/tCq09Qgy.png My current approach involves us ...

Building a connection between a PostgreSQL database and implementing it with Node.js and React.js

After creating a node.js file with database connectivity, the next step is to integrate it into a webpage built with react.js. The util.js file is used to handle API calls: require("isomorphic-fetch"); function addName(time) { return fetch(&ap ...

Allow clicking through the iframe, while still able to interact with its contents

I am facing a challenge of making an iframe click-through, while ensuring that the body of the iframe remains clickable. I have attempted to achieve this using the following code: iframe.style.width = '100%' iframe.style.height = '100%&apos ...

Using a TCP server to transfer and store files with node.js

I am managing multiple devices that are continuously sending messages to a TCP Server built in node. The primary purpose of this TCP server is to route certain messages to redis for further processing by another application. I have created a basic server ...

Errors are being encountered when retrieving Shadow Shader Chunks

As I work on combining a basic toon shaded ShaderMaterial with threejs' built-in shadow system, I encountered some errors. It seems that when I set the Mesh's recieveShadow property to true, I run into issues. The errors I am facing are: Vertex ...

Is it possible to update the content page without having to refresh the master page?

Our website features a Master page with main menu options and corresponding sub menus. When a user clicks on a main menu item, the relevant sub menus should be displayed. After clicking on a sub menu, the content page should update without having to refr ...

Adding a context menu to a Leaflet map

Could someone provide guidance on how to add a custom context menu to a Leaflet map in Vue 3? I am currently utilizing [email protected], @vue-leaflet/[email protected], and experimenting with [email protected]. Here is a snippet of my code: ...