Unable to access GLB model after building it in Three.js

Using GLTFLoader, I successfully imported a model that works flawlessly with npm run dev. However, when I attempt to build it using npx vite build, the model file seems inaccessible. The file is located at /public/models/miku_pde.glb.

When running npm run dev: https://i.sstatic.net/30bwz.png

After building: https://i.sstatic.net/IqIuF.png

This snippet of code showcases how I imported the model:

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

let model;
const loader = new GLTFLoader();
const modelPath = "/models/miku_pde.glb";

loader.load(modelPath, (gltf) => {
  model = gltf.scene;
  model.position.y = -15;
  scene.add(model);
});

I was anticipating the model to display properly. I double-checked the path for accuracy, but unfortunately, it continues to fail after the build process.

Answer №1

Ensure to move the GLB file to src/models/models/ directory and avoid using the public folder to stay stress-free

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import modelPath from  "@/assets/models/miku_pde.glb?url";
let model;
const loader = new GLTFLoader();
loader.load(modelPath, (gltf) => {
  model = gltf.scene;
  model.position.y = -15;
  scene.add(model);
});

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

Button press triggers the fadeIn function successfully, but the keypress event does not have the same effect

I'm currently facing an issue with two div elements on my webpage. I want only one of them to be visible at a time, depending on which key is pressed. If the 1 key is pressed, I want 'div1' to fadeIn (if it's not already visible) and fo ...

Instructions on how to include a conditional click attribute to a hyperlink

Is there a way to make an anchor tag trigger a function only if a specific variable is set? In this scenario, the variable name is assigned the value of "Shnick", so when the link is clicked it should activate the func() method. However, clicking the link ...

Are There Data Racing Issues in JavaScript?

Imagine executing the following code snippet. let score = 0; for (let i = 0; i < some_length; i++) { asyncFunction(i, function() { score++; }); // incrementing callback function } The code above may potentially lead to a data race issue where two ...

Display only the spans that contain text or are not empty

I need a solution to hide only those spans that are empty. <div class="img-wrapper"> <div class="showcase-caption" style="display: block; "> <span id="MainContent_ImageCaption_0">This one has caption</span> </div> ...

HTML fields that are serialized as deeply nested JSON objects

Currently, I am working on a Java REST web service that handles POST data from a basic HTML form. My goal is to ensure that the client code sends the correct JSON to the web service in order for the server code to populate my objects accurately. The data ...

Issue with AJAX MVC HTML: jQuery value is not blocking API call

Upon clicking a button, I am triggering a web API call using AJAX. My form is utilizing JqueryVal for form validations based on my viewmodel data annotations. The issue I am facing is that when I click the "Listo" button in my form, it executes the API ca ...

What is the best way to retrieve data from multi-dimensional JSON structures?

Looking to extract specific values from my JSON file. console.log( objects.assignments.header.report_type ); I need to display HOMEWORK Javascript $.ajax({ url: "/BIM/rest/report/assignment", type: "POST", dataTyp ...

Troubleshooting: Resolving the issue of LABjs not being recognized as a function when used with jQuery scripts

I am currently working on optimizing the load time of my website by implementing LABjs. However, I have encountered an issue with 'Undefined not a function' in relation to jQuery.cookie('mycookie') within my own jQuery script. I would ...

Transforming the elements within an array of objects into individual key-value pairs and then adding them to a fresh array

Hello, I am diving into the world of Typescript/Javascript and encountering some challenges when it comes to manipulating arrays of data. Please bear with me as I navigate through my learning curve. Imagine having an array of objects structured like this: ...

Implementing AJAX requests in jQuery DataTable with ASP.NET MVC

For some time now, I have been using the jQuery DataTables 1.10.13 plugin. Recently, I encountered an issue related to the ajax data source for my HTML table. This is how I initialized jQuery DataTable inside Files.cshtml <script language="javascript" ...

Tokens for Access and Renewal

In my mobile app, I am utilizing the Caspio REST API for user authentication. After successful authentication, I received an access token which I added to my AJAX call with 'Authorization' as Bearer [access token]. I am aware that I can refresh ...

The connection between React-redux @connect is malfunctioning, whereas using connect() functions smoothly

Is there an issue with using the @connect() syntax instead of export default connect()? It seems that when I stick to the traditional syntax class PhonePage extends Component { ... } export default connect(state => ({ testedByPhone: state.pho ...

Tips for modifying the border of an entire column in react-table

My goal is to adjust the style according to the screenshot below. This is what I expect: However, this is what I currently have: As you can see, the border bottom of the last column is not applied as expected. I have tried using the props provided by r ...

Is it possible to nest a filter within another filter in AngularJS?

After creating a filter to convert my date to time, I decided to name it the official filter "date" of AngularJS. project.date_created_at and project.mel have different formats, so I needed to create a custom filter for project.date_created_at. HTML : ...

My servlet is not providing any response to Java

Here is the code on my JSP page: <button data-ng-click="login()">Fetch data from server</button> In the mainController.js file: $scope.login = function() { var xmlHttpReq = new XMLHttpRequest(); xmlHttpReq.open('POST', ...

Filter the ng-repeat list dynamically by triggering ng-click event

I am currently developing an application on that requires users to be able to filter a list of credit cards by clicking on filters located on the interface, such as filtering for only Amex cards or cards with no fees. Although I have successfully bound t ...

Loading jQuery leads to the entire body of the webpage becoming white

As I transition from a welcoming page to a new content page using jQuery's fadeOut/fadeIn and load functions, I encounter an issue where the background, which is black on both pages, suddenly changes to white upon loading the second page. This isn&ap ...

How to pass event data when clicking on a div using React

I'm curious about how the onClick event flows in React when clicking on a div. In my application, there's a ParentComponent that renders a ChildComponent which generates a div for each item in the props.options array. I have a couple of questio ...

Complete a promise using the then() method and return the result

I'm working with a JavaScript code snippet that looks like this: function justTesting() { promise.then(function(output) { return output + 1; }); } var test = justTesting(); Every time I check the value of the test variable, it's always ...

Utilizing inter-process communication in Electron to establish a global variable from the renderer process

renderer.js ipcRenderer.sendSync('setGlobal', 'globalVarName').varInner.varInner2 = 'result'; main.js global.globalVarName = { varInner: { varInner2: '' }, iWontChange: ' ...