I receive this error when trying to import any .glb file. I have tried searching for a solution, but there is only one other forum post mentioning this and I can’t say it helps me.
(The .obj file in the code loads just fine)
Some general forum posts I have come across trying to find a solution have mentioned the file being loaded as the wrong type. Here is my network tab:
Here are 2 files I tried:
IIqYD6NmbMBg_MHphQqssaKlpeaN9rpF.glb (1.2 MB)
bluesword.glb (14.7 KB)
Here is my code:
<head>
</head>
<body style="">
<canvas id="avatarCanvas"></canvas>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="/include/three.min.js"></script>
<script src="/include/OBJLoader.js"></script>
<script src="https://unpkg.com/three@0.85.0/examples/js/loaders/GLTFLoader.js"></script>
<script>
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById('avatarCanvas'), preserveDrawingBuffer: true, alpha: true, antialias: true});
renderer.setSize( 500, 500 );
renderer.setClearColor( 0x000000, 0 );
var scene = new THREE.Scene();
//scene.background = new THREE.Color( 0x121212 );
var camera = new THREE.PerspectiveCamera( 60, 500/500, 0.1, 1000 );
const alight = new THREE.AmbientLight( 0x919191 ); // soft white light
scene.add( alight );
const plight = new THREE.PointLight( 0xf2f2f2, 1, 200 );
plight.position.set( 50, 50, 50 );
scene.add( plight );
var objLoader = new THREE.OBJLoader();
objLoader.setPath('');
// ADD HEAD
objLoader.load(
"/assets/head.obj",
function (geometry) {
geometry.traverse(function (child) {
if (child instanceof THREE.Mesh) {
child.material.color.setHex(0xeaeaea);
}
});
geometry.position.y = 1.5;
geometry.rotation.y = 3.14159;
scene.add(geometry);
});
function loadGLB(modelPath) {
const glbLoader = new THREE.GLTFLoader();
glbLoader.load(modelPath, (gltf) => {
const model = gltf.scene;
model.position.set(0, 0, 0);
model.scale.set(1, 1, 1);
model.rotation.set(0, 0, 0);
scene.add(model);
});
}
loadGLB('/my/test.glb');
var dun = 0;
THREE.DefaultLoadingManager.onProgress = function ( url, itemsLoaded, itemsTotal ) {
render();
dun += 1;
};
camera.position.x = -2.5; camera.position.y = 2; camera.position.z = 6;
camera.lookAt(new THREE.Vector3(0,-0.3,0));
camera.zoom = 1.1;
camera.updateProjectionMatrix();
function render() {
renderer.render(scene, camera);
};