Troubleshooting pathing issues with Three.js and the useGLTF hook

Currently, I am working on a basic project using next.js and trying to explore three.js. However, I have encountered a simple yet challenging issue that I can't seem to solve.

In the screenshot attached, you can see my project structure. Within Sculpture.jsx, I am attempting to utilize the useGLTF hook, which requires me to specify the path to the GLTF file.

I'm unsure if there is an issue with the path I have provided or if the problem lies elsewhere. You can view the screenshot here.

import React from "react";
  import {
    Suspense,
    useEffect,
    useState,
  } from "react";
  import { Canvas } from "@react-three/fiber";
  import {
    OrbitControls,
    Preload,
    useGLTF,
  } from "@react-three/drei";
  import CanvasLoader from "../CanvasLoader";

  const Sculpture = () => {
    const model = useGLTF("./sculpture/scene.gltf");

    return <div>Sculpture</div>;
  };

  export default Sculpture;

You can also take a look at another screenshot by following this link here.

Answer №1

It appears there may be a mistake in the path you provided. The issue seems to stem from the absence of a folder named Textures. Despite encountering a similar error myself, I managed to resolve it by taking the following steps: I placed my gltf model in the specified path: "src/assets/models/3Dmodel.gltf". and imported it as follows:

import SculptureScene from "../assets/models/3Dmodel.gltf";

const Sculpture = () => {
  const model = useGLTF(SculptureScene);

  return <div>Sculpture</div>;
};

This approach proved effective for me. However, if you wish to include a 3D model in the public directory, simply utilize this code snippet:

const Sculpture = () => {
  const model = useGLTF("/sculpture/scene.gltf");

  return <div>Sculpture</div>;
};

Just ensure that the path is accurate.

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

Integrate properties into a React component using an object as the representation

Can props be added to a component represented by an object? I am looking to add these props just once, within the map function, if possible. children: [ { id: '1', isActive: false, label: 'Home', component: & ...

How can I add content to the body of a modal in Bootstrap 3?

My application has a button that, when clicked, is supposed to trigger a modal popup containing some data. I want the data in the modal to come from another application via a PHP file accessed through a URL. How can this be achieved? <?php echo '& ...

Encountering a RangeError in FusionCharts with VueJS, I faced the issue of exceeding the maximum call stack size while trying to

After inserting a clip array into xAxis, I encountered a RangeError. Has anyone else experienced this issue? I have set up a repository to demonstrate the bug: https://github.com/Ic3m4n34/fusioncharts-bug (App.vue) Does anyone have suggestions on how to ...

Create a basic login form using cookies in Flask and incorporate it into a webpage

I apologize for asking a common question, but I have gone through numerous articles. I have a list of usernames that I would like to store in a cookie and then utilize them across various HTML pages. Essentially, I want the username to be displayed on the ...

Switching the active className in React and Next.js based on selection status

My goal is to dynamically change the className of each Card component when clicked on. When one Card is selected, the others should revert back to their default className. This is my UserBookingData component: const UserBookingData = ({ bookings }: any) = ...

What is the process for incorporating an array of models?

let userData = await db.user.findOne({ attributes: attributes, include: ['charges', 'availability', 'practice',// 'services', 'education',// 'user_role', ...

Managing user access and permissions using JavaScript on the front end

I find myself in a situation where I am working on developing a single page application: The majority of the operations rely on ajax requests. Depending on the user's login status (admin, regular user, visitor), different components need to be displ ...

Error: Unable to access the 'stateUpdate' property (a function) because it is undefined when passing data from a parent component to a child component

I seem to be encountering a problem with passing a function from the parent to child component in react js. Even after attempting to pass the value to the component as props, I keep getting a type error mentioned in the question. It's puzzling why th ...

Error encountered: Unexpected token found in JSX while attempting to integrate the react-simple-typewriter component

Exploring the realm of creating a portfolio website through practice and experimenting with various animations. I've been diving into this particular document, https://www.npmjs.com/package/react-simple-typewriter, and conducting online research to g ...

The Docker container is successfully running based on the Dockerfile, however, when trying to access it from the docker-compose container

I seem to be encountering an issue with my docker-compose configuration file as I attempt to run a Next.js app using Docker and enable hot reload functionality. While running the Next.js app directly from its Dockerfile works fine, the hot reload feature ...

Filtering JSON data by date range in React JS

I have a dataset with JSON data containing ISO dates, and my goal is to filter out entries based on the "date_created" field falling within a specific date range. The time component should be ignored in this comparison, and the original JSON data should re ...

Converting text to JSON using JSONP with jQuery's AJAX functionality

Potential Duplicate Question 1 Possible Duplicate Inquiry 2 I have been searching for a definitive explanation on JSONP across various questions but haven't been able to find one yet. For instance, I am attempting to make a cross domain request us ...

Problem with delaying in Jquery's .each method

I'm currently working on a JavaScript project and encountering some issues. Below is my HTML code: <div class="views-row"></div> <div class="views-row"></div> <div class="views-row"></div> <div class="views-row ...

Disallow standard click behavior if a specific class is present elsewhere on the webpage

My CSS code triggers a dropdown menu to open when the .dashboard-actions class is clicked. When the user clicks, the class of the 2nd div in the tree changes to "dropdown open", indicating that the dropdown menu is visible. Clicking off the menu removes th ...

Using Angular to create unique filter elements

<select ng-model="model" id="filter"> <option value="" id="dropdownDefault">Title</option> <option ng-repeat="select in selects" value="{{select.title}}" id="dropdown">{{select.title}}</option> </select> <sel ...

Calculating the number of rows using JQuery

After browsing similar questions on Stack Overflow, I have not found a solution that fits my specific case. I have multiple tables on a page that share the same template without unique IDs. I am trying to determine if the rows are empty when certain data i ...

having difficulty grasping the variable's scope within this code

Here we have a code snippet where the variable vid is initialized inside a function. The question arises on how this variable can be used outside the function, specifically in the context of vid.play(). How does the program know that vid was created usin ...

Locate the customers' IP addresses through an application built with ExpressJS

A few days back, I created a nodejs script for capturing user agents. While my script was functional, I faced difficulties in logging the REMOTE_ADDRESS of the client. app.js: var express = require('express'), http = require('http'), a ...

Using event.target.value in find() caused the function to return undefined, but it worked as expected when storing the value in

I am facing a peculiar issue. I am working with a select component that passes a value called "classID" up to a useState. There is an array mapped over the select component which is sent from a NodeJS API and looks like this: [{classID: 371, teacherID: 1, ...

Retrieving PHP variable within a JavaScript file

I have a PHP script running on my server that tracks the number of files in a specific directory. I want to retrieve this file count ($fileCount) in my JavaScript code. numberOfImages.php: <?php $dir = "/my/directory/"; $fi = new FilesystemIterator($d ...