GLTF file: Error 404 - File could not be located

Working on loading a GLTF file and encountering a specific error: https://i.sstatic.net/EbovJ.png

Curious as to why the file cannot be located and opened. Is it necessary to establish a local server for this process? After reviewing other examples online, I came across this one which incorporates a DRACOLoader. I'm unsure of its purpose and whether it needs to be implemented in order for the file to load.

The following is the code I am currently using:

<html>

    <head>
        <meta charset="utf-8">
        <title>Initial Website Attempt</title>


        <style>
            body { margin: 0;
                background: linear-gradient(to bottom, #33ccff 0%, #ffffff 20%);}
            canvas { display: block; }
        </style>

    </head>

    <body>

      <!-- <script type = "module" src="build/myScript.js"></script>-->
       <script type = "module">
        import * as THREE from '../build/three.module.js';

          import { GLTFLoader } from '../build/GLTFLoader.js';

            let scene, camera, renderer, hlight;


            function init () {
                //scene
                scene = new THREE.Scene();

                //camera
                camera = new THREE.PerspectiveCamera(40, window.innerWidth/ window.innerHeight, 1, 5000);

                //light
                hlight = new THREE.AmbientLight (0x404040, 100);
                scene.add(hlight);


                //render                
                renderer = new THREE.WebGLRenderer({antialias:true});
                renderer.setPixelRatio( window.devicePixelRatio );
                renderer.setClearColor( 0x000000, 0 );
                renderer.setSize(window.innerWidth, window.innerHeight);

                document.body.appendChild(renderer.domElement);

                //3d
                let loader = new GLTFLoader();
                loader.load('assets/londonmap.gltf', function(gltf){
                    scene.add(gltf.scene);

                })


            }


            function onWindowResize () {

                camera.aspect = window.innerWidth / window.innerHeight;
                camera.updateProjectionMatrix();
                renderer.setSize(window.innerWidth, window.innerHeight);
                }

                window.addEventListener('resize', onWindowResize, false);

            function animate () {

                requestAnimationFrame(animate);

                render();

            }

            function render() {

                renderer.render( scene, camera );

            }

            init ();
            animate();


       </script>
    </body>
</html>

Answer №1

DracoLoader is essential only if the glTF file was compressed using the Draco compression algorithm.

Receiving a HTTP 404 error indicates that the specified file (in this case assets/londonmap.gltf) could not be loaded from the given path. Therefore, it is important to ensure that the file actually exists in the correct directory.

It is highly recommended to utilize a local web server while working with these files to avoid any potential security issues within the browser. The project provides a helpful guide on this topic: How to run things locally.

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

Transitioning from a multipage application to Piral: A comprehensive guide

Our organization operates several ASP.NET Core applications that are traditional multipage applications. As we develop a new portal using Piral, we want to incorporate elements from our existing applications while also introducing new modules. How can we ...

Add-on or code snippet for Node.js that allows for optional regex groups

Strings in Sequence line 1 = [A B C] line 2 = [A C] line 3 = [B C] Regular Expression /\[?(?<groupA>[A])?(?:[ ]*)?(?<groupB>[B])?(?:[ ]*)?(?<groupC>[C])\]/gm Is there a way to achieve the desired output using a plugin or spe ...

The React date picker is experiencing a delay when opened with a click

A peculiar problem has arisen with react-datepicker. I have successfully integrated my datepicker with Redux Form, and the code is as follows: <DatePicker customInput={<CustomDateInputNew {...props} />} onChange={date => { props.input. ...

Using JavaScript to dynamically change the IDs of multiple select elements during runtime

I am facing an issue when trying to assign different IDs to multiple select elements at runtime. The number of select elements may vary, but I need each one to have a unique ID. Can anyone assist me in locating the select elements at runtime and assignin ...

Calculating the total of an array's values using JavaScript

Receiving information from an API and looking to aggregate the values it contains. Consider the following code snippet: function totalPesos(){ $http.get('/api/valueForTest') .then(function(data){ $scope.resumePesos = data.data.Re ...

Why was the express.js boilerplate code created?

As a newcomer to Node and Express, I am curious about the purpose of the boilerplate directories that are automatically generated when setting up an express project. I have searched online for explanations on the significance of these files without much l ...

Determine the Total of Various Input Numbers Using JQuery

There are 3 input fields where users can enter numbers, and I want to calculate the sum of these numbers every time a user updates one of them. HTML <input class="my-input" type="number" name="" value="0" min="0"> <input class="my-input" type="n ...

When my webpage is opened in Firefox, I notice that it automatically scrolls down upon loading

I recently embarked on the task of building a website from scratch but ran into an unusual bug in Firefox. The issue causes the page to scroll down to the first div, completely bypassing its margin. I want to clarify that I am not seeking a solution spe ...

The height of the div element is automatically adjusted to zero

I am dealing with a simple layout where I have a main div that floats to the left. Within this main div, I nest other divs using the clear both style. Below is a simplified version of my setup: <div id="wrapper" class="floatLeft"> <div id="ma ...

Utilizing JavaScript to retrieve data from a JSON-parsed SOAP envelope

Welcome to the exciting world of development! This is my first post, so please bear with me if I ask a seemingly silly question. Currently, I am utilizing Xml2js for sending a SOAP request and then converting the response into JSON format. However, I&apos ...

The type 'SVGPathSeg' cannot be assigned to type 'EnterElement' because the property 'ownerDocument' is not present in type 'SVGPathSeg'

I'm attempting to replicate this example using the d3-ng2-service service on Angular 5. Component: OnInit code: let d3 = this.d3; let d3ParentElement: Selection<HTMLElement, any, null, undefined>; let d3Svg: Selection<SVGSVGElement, any, n ...

The art of efficiently handling and outputting an array of files using node

In a folder filled with markdown files like so: myDir |- fileA.md |- fileB.md |- fileC.md |- fileD.md I want to extract just the filenames without the file extension and store them in an array. This is my attempt: var mdFiles = fs.readdir('myDir&a ...

Switching over to styled components from plain CSS using a ternary operator

Currently, I am in the process of converting my project from using regular CSS to styled components (https://styled-components.com/). So far, I have successfully converted all my other components except for one that I'm having trouble with. I've ...

Is AngularJS the right choice for creating components?

Currently, I am developing a PHP web application with approximately 200 unique views. Most of these views simply display tables or forms. However, there are about 10 pages where users could benefit from dynamic/async components to prevent constant page re ...

JavaScript alert box

I'm fairly new to the world of web development, with knowledge in CSS & HTML and currently learning TypeScript. I'm attempting to create a message icon that opens and closes a notifications bar. Here's where I'm at so far: document.getE ...

HTML View of JSON Object Hierarchy

Hello, I have been trying various methods but am struggling to figure out how to display the following JSON object as a tree HTML view with ul li items using JavaScript. Can anyone help me with this? [ { "CategoriesModelId": 7, "Name": "Parent ...

Exploring the translateZ values in Three.js [tutorial]

I've been searching high and low for the answer to my problem, but I can't seem to find a solution anywhere. I'm attempting to determine the position values that would result from an object translating Z by -100, without actually performing ...

Changing the content of a PHP div with an Ajax callback inside another Ajax callback?

In the index.php file, there is a script that triggers an ajax call when a header element is clicked. This call sends a $selection variable to ajax.php, which then replaces #div1 with the received HTML data. <script> $(document).ready(function(){ ...

What could be causing the lack of data for the current user?

I have been attempting to fetch the current user session and display the data in the view, but nothing is appearing. I even checked the database and confirmed an active session with all the necessary information. I attempted logging the user out and starti ...

Tips for incorporating a dynamic basePath into your NextJS project

For my new app, I am trying to include the groupID in the URL before the actual path, such as 'https://web-site.com/1/tasks'. The NextJs docs mention a basePath that is set at build time and cannot be modified. With numerous routes in my current ...