Troubleshooting the 404 Not Found Issue with THREE.JS GLTFLoader

I'm currently working on incorporating a 3D model into my webpage using Three.js and I've encountered a 404 Error while trying to fetch the model with GLTFLoader. It's puzzling because I am certain that the path to the model is correct. Here is the error message displayed in the console:

Error: fetch for "http://127.0.0.1:5500/modele/voiture/scene.gltf" responded with 404: Not Found

Within my JavaScript code, I have implemented a loadModel() function which I then included in my init() function. This is how the loadModel() function looks like:

function loadModel() {
    // ------------ 3D Image Loader -------------- //
    const loader = new THREE.GLTFLoader();

    //loader.setCrossOrigin('./');
    
    loader.load('modele/voiture/scene.gltf', function(gltf){ 
        var voiture = gltf.scene;
        voiture.scale.setScalar(5);
        scene.add(gltf.scene);
        voiture = gltf.scene.children[0];
        rendu.render(scene, camera);
    });
}

I would greatly appreciate any advice or feedback on my code. Thank you so much in advance!

Answer №1

Make sure to add a "/" before the url path.

function loadModel() {
    // ------------ 3D image loader -------------- //
    const loader = new THREE.GLTFLoader();

    //loader.setCrossOrigin('./');
    
    loader.load('/model/car/scene.gltf', function(gltf){ 
        var car = gltf.scene;
        car.scale.setScalar(5);
        scene.add(gltf.scene);
        car = gltf.scene.children[0];
        rendu.render(scene, camera);
    });
}

Alternatively, you can use the full link:

function loadModel() {
    // ------------ 3D image loader -------------- //
    const loader = new THREE.GLTFLoader();

    //loader.setCrossOrigin('./');

    loader.load("http://127.0.0.1:5500/model/car/scene.gltf", function(gltf){ 
        var car = gltf.scene;
        car.scale.setScalar(5);
        scene.add(gltf.scene);
        car = gltf.scene.children[0];
        rendu.render(scene, camera);
    });
}

If that doesn't work, try running

curl "http://127.0.0.1:5500/model/car/scene.gltf"
in your terminal. If nothing is returned, there may be an issue with the server or the url.

Answer №2

After facing a similar issue, I successfully resolved it by relocating the glb file to the public folder within my React Project.

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

The functionality of the date picker is hindered when a dropdown with multiple selections is activated, and conversely, the multi-selection feature of

I am working on an application where I need to implement a drop-down with multi-selection functionality, as well as a date picker for text boxes. For the drop-down with multi-selection feature, I referred to the code in the following link: . Additionally, ...

Mastering the Art of jQuery Function Chaining for Beginners

I want to change the name and ID of an element when a radio button is clicked. To avoid duplication of the selector, I tried setting it up this way: $( "#selectOther" ).click(function() { $( "[field=primaryInput]" ).attr('id', "modifiedId", ...

"Unable to append new <li> elements to a sortable list in jQuery UI once all existing <li>

My current setup involves a sortable functionality structured as follows: <ul id="sortable2" class="connectedSortable"> <li class="ui-state-default">First <a title='delete' class="itemDelete text-right"><i class="fa fa- ...

Jquery onchange event fails to fire

$('#selectclassid').trigger("change"); $('#selectclassid').on('change', function() { }); When trying to manually trigger the onchange event, it does not seem to be firing as expected. Although this format is commonly seen ...

Sharing a React UI Library featuring custom styled components

As a newcomer to a company, I am a junior developer looking for some guidance. Although I have some experience with React, I am struggling with a current issue. The problem I am facing is that when I import a library from npm, my React project fails to r ...

Informing the parent window of the child window's activities in order to adjust the timer for the user timeout feature

Within my Jquery function, I have implemented a feature that darkens the screen after a period of user inactivity. This triggers a pop-up window giving the user the option to stay logged in by clicking a button. If there is no response within the set time ...

Tips for designing a hyperlink insertion modal while preserving text selection

I am working on a React website that utilizes Slate-React () for creating a rich text input field. Currently, Slate uses the browser's prompt() function to add hyperlinks to selected text. However, I need to customize the styling of the prompt modal a ...

Uncovering the hidden treasures of checkbox values using jQuery

I've encountered an issue with a form containing checkboxes. Some values are meant to be true by default, so I've hidden them using the following method: <input type=checkbox name="<%= _key %>" checked="checked" style="display:none" /& ...

Updating dynamic content in IBM Worklight V6.1 with jQuery Mobile v1.4.3 requires waiting for the DOM to load

I need to dynamically update the content of a div within my HTML page structure. <!DOCTYPE HTML> <html> ... <body> <div data-role="page"> <div data-role="header"> //Image </div> <!-- Th ...

The 'in' operator cannot be utilized to search for '_id' within

I am attempting to retrieve an existing user document using mongoose with express, but I am encountering the following error: /webroot/api.domain.com/production/node_modules/mongoose/lib/document.js:162 if (obj && '_id' in obj) con ...

Exploring the integration of JSONP with the unmatched features of Google

I am attempting to utilize the Google maps directions API by using jquery $.ajax. After checking my developer tools, it seems that the XHR request has been completed. However, I believe there may be an issue with the way jquery Ajax handles JSON.parse. Y ...

Guide for scrolling to the top of a span located outside an iframe while working within the iframe

I have a website that is embedded within an iframe on another site. Unfortunately, the hosting site has set the iframe to a fixed height inside a span with a scroll bar (for unknown reasons). Is there a way for me to change the scrolling behavior of the ...

What is the best way to utilize unique slash commands in Slack threads?

After setting up a custom slash command /news in Slack, it appears to work fine. However, I'm struggling to figure out how to trigger slash commands within threads. Whenever I try to use the command, I receive this error message: /news is not support ...

Using AJAX to send an array of values to a PHP script in order to process and

I have very little experience with javascript/jquery: My ajax call returns entries displayed in an html table format like this: Stuff | Other stuff | delete stuff ------|----------------|------------------------- value1| from database | delete this ...

Arranging the items in a specific sequence - Angular

I am dealing with an object of objects and I need to display these objects and their values in a specific order (not alphabetically). How can I accomplish this using angular? Below is a sample of my object: var filters = { language : { someProperty : ...

Trouble with Highchart.js when passing an array

Currently experimenting with highchart.js. Here is the code snippet: $.ajax({ type: "POST", url: "api/getListWeight", dataType: "json", data : {idBoxeur : idBoxeur} }).done(function( dataWeightList ) { ...

Enhance the color scheme of your collapsed or expanded Bootstrap NAV for mobile devices

Currently working on customizing the navbar using Bootstrap. I've been able to style it perfectly for both desktop and mobile devices in its initial state. The issue arises when attempting to style the navbar in its expanded and collapsed states on m ...

The Holy Alliance of Laravel and Vue

I am facing issues with user authentication using Laravel Sanctum. I have set up everything properly, with Vite and Vue 3 as the frontend. The problem arises when I attempt to login with Laravel's default auth - it works fine. However, when I make a r ...

Encountering a JavaScript/TypeScript issue that reads "Unable to access property 'Items' as it is undefined"

I encountered an issue with Javascript where I'm receiving an error message stating "Cannot read property 'Items' of undefined". The this keyword is consistently showing as undefined in the Base class. How can this problem be resolved? Coul ...

Error when trying to assign values to an undefined property in an array

While working on a problem in Leetcode, I encountered an issue with an empty array. I attempted to push some numbers into it and received an error message that I am unsure of the reason for. Below is my code snippet: // r and c values are pre-defined numbe ...