Using Three.js with Webpack 5 and FBXLoader inline integration

I am currently working with Webpack 5 and attempting to provide a direct file path to my FBXLoader using the latest Webpack asset modules:

const loader = new FBXLoader()
loader.load('../assets/models/myModel.fbx', (object) => { ... }) // encountering error 404, file not found

Despite managing to import and load the file successfully, I am facing a persistent issue where the file consistently shows up as a 404 error. This occurs when I pass the path in line with what is mentioned above.

In my Webpack 5 configuration, I have implemented the following rule:

// Fbx - resolves import only for myFile from '../assets/models/myModel.fbx'
{
  test: /\.fbx/,
  type: 'asset/resource',
},

Answer №1

To ensure that webpack includes your model, make sure to use an import statement in your JavaScript file pointing to it.

This is how my JavaScript code ended up looking like after including the model, and it loaded perfectly fine.

import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader'
import Stats from 'three/examples/jsm/libs/stats.module'
import ringModel from './models/ring.fbx';  // Added this line

export default function displayRing() {
    const scene = new THREE.Scene();
    scene.add(new THREE.AxesHelper(5));

/* Additional setup code */

    const fbxLoader = new FBXLoader()
    fbxLoader.load(
        ringModel, // Using the model here
        (object) => {
            object.scale.set(.1, .1, .1)
            scene.add(object)
        },
        (xhr) => { console.log((xhr.loaded / xhr.total) * 100 + '% loaded') },
        (error) => { console.log(error) }
    );

/* Render function, etc */
}

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

Inconsistencies in Height Among JQuery Elements

I am encountering an issue with my datatable.js, where I am attempting to limit its height based on a specific row number, such as 4.5 rows. However, I am facing a problem with the row height (tr height). For example, when using the following method with m ...

Alternate the color over time using CSS

Is there a way to dynamically change the color of a div from black to white every two seconds, and then from white to black, continuously toggling as long as the div is visible? Essentially, I want the div to only be displayed when a user clicks and drag ...

Changing the color of a div through animation

Similar Question: jQuery animate backgroundColor I am looking to make a div shine or switch colors to signal to someone that they have gotten a message. What is the best way to animate the background color of a div for this purpose? ...

Bringing in Zip Folders

Currently, I am encountering an issue with the OBJ format files being too heavy to download. I am considering uploading the OBJ files in a Zip folder for a more streamlined process, allowing the viewer to unzip the files and call the function OBJLoader. ...

Locating the save directory with fileSystem API

I've been working on saving a file using the fileSystem API. It appears that the code below is functional. However, I am unable to locate where the saved file is stored. If it's on MacOS, shouldn't it be in this directory? /Users/USERNAM ...

Can the color of text be adjusted (to either white or black) based on the background color (in any color and format)?

To achieve a text color that contrasts well with any background, I need to make sure it's either black or white. The background in my app can vary in color and format, so finding the perfect solution has been challenging. Using mix-blend-mode doesn&a ...

How can I determine if a specific button has been clicked in a child window from a different domain?

Is there a method to detect when a specific button is clicked in a cross-domain child window that cannot be modified? Or determine if a POST request is sent to a particular URL from the child window? Below is an example of the HTML code for the button tha ...

Proportional fluid image grid with responsive design

After implementing various media queries, I've managed to create an image grid using Bootstrap 4+ that looks great on specific devices and layouts. Here's the reference code: .cmd-three-img-container { position: relative; margi ...

ReactJS is facing a fatal error: CALL_AND_RETRY_LAST Allocation has failed due to JavaScript heap running out of memory

I'm currently experiencing an issue on a ReactJS project (a smaller project, not a large complex one) that is manually configured with Webpack and Babel. After some time (2-3 hours), this error appears and if I restart the server, it goes back to norm ...

Tips for rearranging the order of x-editable events?

I'm currently developing a web application using angularJs and xeditables. Within this application, I have multiple xeditable text elements following each other, with validation triggering upon pressing enter or clicking outside the text field: &l ...

What steps can be taken to resolve the dependency problem with npm installation?

Attempting to incorporate npm install react-material-ui-carousel --save into my react project has presented a challenge. Upon installation, I encountered a dependency tree issue. Even after deleting the lock and npm modules files, followed by running npm ...

Is there a way to interact with specific locations on an image by clicking in JavaScript?

https://i.stack.imgur.com/gTiMi.png This image shows a keypad with coordinates for each number. I am able to identify the coordinates, but I am struggling to click on a specific coordinate within the image using JavaScript. Can someone assist me in achiev ...

I'm looking to combine multiple RSS feeds into a single feed, then transform the combined feed into JSON data using JavaScript. How can I achieve this?

I have been experimenting with merging multiple RSS feeds into one and converting it to JSON format. For combining the feeds, I utilized the following package: rss-combiner Below is the code snippet that successfully combines the RSS feeds: var RSSCombin ...

The three.js live server is displaying a blank white screen instead of the expected black background

As I attempt to set up my three.js following tutorials on Youtube, using Visual Studio Code, I encounter a perplexing issue. Despite copying the script precisely as demonstrated in the tutorials, every time I check the live server, instead of seeing a blac ...

Using an image instead of a checkbox when it is selected (Angular 4/Ionic 3)

Is there a way to swap out the checkbox for an image? I want this image to change dynamically based on whether the checkbox is checked or not. Unfortunately, adding a class doesn't seem to do the trick as it modifies all icons in the same column. The ...

Guide to Efficiently downloading a PDF file using Vue and Laravel

THE SCENARIO: Client Side: Vue. Server Side: Laravel. Within the web application, I need to enable users to download specific PDF files: I require Laravel to retrieve the file and send it back as a response to an API GET request. Then, in my Vue web ap ...

When employing TypeScript, an error pops up stating "cannot find name 'ObjectConstructor'" when attempting to use Object.assign

I am rephrasing my query as I realized it was unclear earlier. I have an API that is sending me data in the following format: {"photos":[{"id":1,"title":"photo_1_title"}]} In my code, I have a variable called photos and a function named getPhotos() For ...

How to insert text into a text input using onKeyPress in react.js

I am looking to simulate a typing effect where the phrase 'Surveillance Capitalism' is inputted letter by letter into a text input field as a user types. However, I encounter an issue when trying to add each individual letter into the input; I re ...

Is it possible to utilize AngularJS' ng-view and routing alongside jade?

Currently, I am diving into the world of the MEAN stack. I noticed that Express utilizes jade by default, but I decided to experiment with it even though I can easily use html instead. When attempting to route with Angular, like so: ... body div(ng-view ...

How to modify and remove a card element in semantic UI with react coding

I have recently created some cards and now I want to enhance the user experience by allowing them to edit the card data and delete the card altogether if they choose to do so. For the deletion functionality, here is an example of deleting a card using jQu ...