Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
load a 3D model with GLTFLoader (ThreeJS) in Reactjs without using React Fiber

I want to load a 3D model with GLTFLoader but it gives me a syntax error

and I tried these ways

  • const loader = new THREE.GLTFLoader();
  • const loader = new GLTFLoader(); after importing it

but all of the above didn't work with me

How can I solve this without using React Fiber?

enter image description here

import { useEffect } from "react";
import * as THREE from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
import Stats from "three/examples/jsm/libs/stats.module";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";

export default function Main() {
  useEffect(() => {
    /**
     * scene
     */
    const scene = new THREE.Scene();

    /**
     * textures
     */
    const textureLoader = new THREE.TextureLoader();
    const matcapTexture = textureLoader.load("./static/textures/matcaps/1.png");

    /**
     * objects
     */

    // torus
    const torusGeometry = new THREE.TorusBufferGeometry(0.2, 0.1, 15, 45);
    // const torusMaterial = new THREE.MeshMatcapMaterial({ map: matcapTexture });
    const torusMaterial = new THREE.MeshNormalMaterial();
    const torus = new THREE.Mesh(torusGeometry, torusMaterial);
    torus.position.set(0, 0.3, 0);
    scene.add(torus);

    // 3D model
    const loader = new GLTFLoader();

    loader.load("./model_1/scene.gltf", (gltf) => {
      scene.add(gltf.scene);
    });

    /**
     * camera
     */
    const camera = new THREE.PerspectiveCamera(
      75,
      window.innerWidth / window.innerHeight,
      0.01,
      10000
    );
    camera.position.set(0, 0, 4);
    scene.add(camera);

 /**
 * renderer
 */
const canvas = document.querySelector("#canvasElement");
const renderer = new THREE.WebGLRenderer({
  canvas,
  antialias: true,
});
renderer.setSize(window.innerWidth, 400);
renderer.setClearColor("white");
  }, []);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I figured out that I should have put the model's files in the public folder

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!