The THREE.STLLoader function cannot be initialized as it is not a constructor

Struggling to load an STL model on three.js, constantly receiving the error message "THREE.STLLoader is not a constructor" in the console.

This is the code I'm using:


var loader = new THREE.STLLoader();
loader.load( '3dbenchy-1.stl', function ( geometry ) {
scene.add( new THREE.Mesh( geometry ) );
});

Answer №1

When working within a three.js build, you'll find an examples folder that contains two subfolders named "js" and "jsm". It's recommended to use the "jsm" folder for ES6 modules rather than mixing traditional JavaScript classes with modules.

Answer №2

STLLoader is not included in the library core. In order to use it, you must include the relevant file separately, as shown in the example below:

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

Editing an XML file on the browser and saving it in its original location on the local file system

Seeking assistance with editing an XML file directly from the browser on a local file system and saving it back to its original location. I have conducted extensive research using Google, but have not been able to find a suitable solution. Any help or gu ...

What are the methods for altering the material of a glTF model using THREE.js?

I've created a model using Blender and baked all the lighting and textures. However, when I import it into THREE.js in .glb format, it automatically uses the standard material. While this may work in certain cases, my concern is that I want to retain ...

Looking to extract data from various checkbox options and save it as an array variable

For a coding boot camp assignment, I'm working on a modal that includes options for the days of the week. My approach involves using Jquery .each and CSS :checked to retrieve the values assigned to each input. However, every time I attempt to log the ...

spinning shapes in three.js

Having a small issue with my object and lighting. Whenever I rotate my object, the light also moves with it. I want the light to stay static. Could this be happening because I added the scene to the renderer? I'm not sure how to add my object to the r ...

Conceal the Form Upon Submission

I'm currently working on a project where I want to hide my form after the submit button is pressed using Jquery. Firstly, I have included the Jquery library in my code. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jque ...

Improve performance by rendering table rows without using binding techniques

My current project involves using Angular 1.4, where I have encountered performance challenges with ng-repeat while rendering a large number of rows, such as for tables. I am curious if there is an efficient way to use ng-repeat or explore different iterat ...

axios.get consistently delivers a Promise of type <Pending>

I have been searching for a solution to my issue, but so far none of the suggestions have worked for me. Below is the code that I am struggling with: const Element = () => { async function getEndData() { const data = (await getEnd()) ...

Creating a visual representation of the information stored in my JSON data file using a Quasar table

As a VueJS student, I'm struggling to display the distances from my JSON file in a table. What is the best way to retrieve and show all the distance data for "5" and "10" by both walking and driving? Should I use this code: this.concurrentsRows = JSO ...

While handling a post request in Node.js, an error is thrown: TypeError - Unable to destructure the 'firstName' property from 'req.body' because it is undefined. Interestingly, the same destructuring works perfectly fine for another

After researching similar questions without finding a solution to my specific issue, I am reaching out for help. The app I'm working on allows users to post memories or cards. While creating a new card with a POST request poses no problem, attempting ...

Utilizing accurate server URLs (Codeigniter) for local JavaScript execution

Help Needed: Issue with Correct Path Names in Local JavaScript with CodeIgniter Backend I am facing difficulties in using the correct path names in local JavaScript while working with a backend in CodeIgniter. -user_data -application -system -assets In ...

The universal CSS variables of Material UI

Creating reusable CSS variables for components can greatly simplify styling. In regular CSS, you would declare them like this: :root { --box-shadow: 0 2px 5px -1px rgba(0, 0, 0, 0.3); } This variable can then be utilized as shown below: .my-class { ...

The error message "data.map is not a function" is thrown in the getStatic

I am currently working on a blog project using Strapi in conjunction with Next.js My goal is to create dynamic pages by utilizing [id].js within the pages/posts/[id].js structure However, I've encountered an issue while attempting to map through the ...

Tips for Ensuring a JavaScript Contact Form Submits Successfully

Snippet of HTML Code for Contact Form: Contact Me <label for="Name">Name:</label> <input type="text" name="name" id="Name" accesskey="N" tabindex="1"> ...

Alter the font color upon clicking the menu using jQuery

When I click on the menu and sub-menu items, I want to change their colors along with their parent. You can see an example of how I want it to work here. However, currently, when I click on a sub-menu item, the color of the parent menu item gets removed. ...

Why does trying to package a Windows app on OSX prompt a request for Wine installation?

For several months, I have been successfully utilizing Electron on macOS (10.11.6) to create and package both OSX and Windows applications. My current setup includes electron v1.7.3 and "electron-packager" "^8.5.2", all of which have not been updated in a ...

Are alterations in hues within three.js program an unusual quirk of three.js?

I'm trying to change the color of a cube in three.js to a random color. I've looked at various resources, like Changing color of cube in three.js, but for some reason, my code doesn't update the cube's color despite the console output s ...

Transmitting Several Pictures at Once Through WhatsApp-WebJS

I have encountered a challenge while attempting to send multiple images in a single WhatsApp message using the WhatsApp-WebJS library. Despite receiving a "success" confirmation without any errors, the images and message fail to appear on WhatsAp ...

What is the best way to create a fixed navigation bar that only stays fixed on particular sections of my website?

In my digital portfolio, I have divided it into "4 sections," each represented by a separate scrollable web page. These sections are also known as parts, starting from #part1 up to 4. For section 1 (#part1), I prefer not to display the navigation bar. How ...

What is the best way to implement ES2023 functionalities in TypeScript?

I'm facing an issue while trying to utilize the ES2023 toReversed() method in TypeScript within my Next.js project. When building, I encounter the following error: Type error: Property 'toReversed' does not exist on type 'Job[]'. ...

Experiencing difficulties accessing the API route through Express

Every time I attempt to access /api/file, I am receiving a status code of 404. Here is the relevant code snippet: app.js : ... app.use("/api", require("./routes/users")); app.use("/api", require("./routes/file")); ...