I’m making a 3D animated movie using 3js and have a problem loading the 3D models using GLTFLoader. I know the code but whenever I run the code, an error message in the console is shown which says syntax error. Your gltf file is being read as your HTML file .
Here’s the detailed error:
" Unexpected token ‘<’, “<!DOCTYPE "... is not valid JSON
at JSON.parse ()
at GLTFLoader.parse (GLTFLoader.js:340:17)
at Object.onLoad (GLTFLoader.js:245:11)
at three.module.js:44568:38”
I tried a bunch of different solutions but nothing seems to work. Kindly help me in solving this issue. Here’s my code :
import * as THREE from ‘three’;
import {OrbitControls} from
‘three/examples/jsm/controls/OrbitControls’;
import { GLTFLoader } from ‘three/examples/jsm/loaders/GLTFLoader.js’;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
renderer.setClearColor(0xA3A3A3);
const orbit = new OrbitControls(camera, renderer.domElement);
camera.position.set(10, 10, 10);
orbit.update();
// Lighting
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(0, 1, 1).normalize();
scene.add(light);
// Load GLTF Model
const assetLoader = new GLTFLoader();
const m_url = ‘C:/Users/shrey/OneDrive/Desktop/threejsprojects/assets/ground.glTF’;
assetLoader.load(m_url,
function(glTF) {
const model = glTF.scene;
scene. add(model);
},
undefined,
function (error) {
console.error(error);
}
);
renderer.render(scene, camera);