I've been having some trouble uploading a gLTF file using three.js. Despite fixing some errors, I'm still greeted with a black screen. One solution was adding this to my chrome target directory:
‘path to your chrome installation\chrome.exe --allow-file-access-from-files’
This fixed the issue momentarily, but I continue to receive the following error when checking the console: https://i.sstatic.net/9AD76.png
Could someone provide assistance? All I want to do is display the 'DamagedHelmet.gltf' file on the screen with three.js.
The error occasionally resurfaces, and here's how it appears: https://i.sstatic.net/FivB7.png The code:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Three.js Crash Course</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/GLTFLoader.js"></script>
<script>
// To display anything we need three things: scene, camera, renderer.
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75/*POV*/, window.innerWidth / window.innerHeight/*aspect ratio so it takes on the size of the screen*/, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();//API for rendering/processing 2D and 3D to browsers
renderer.setSize(window.innerWidth, innerHeight); // Size you want it to render which is size of screen/area
document.body.appendChild(renderer.domElement); // Add the renderer to the HTML document/canvas
controls = new THREE.OrbitControls(camera, renderer.domElement);
//-------create shape you need geometry, material/apperance and cube
var loader = new THREE.GLTFLoader();
loader.load(
// Resource URL
'models/gltf/duck/gLTF/duck.gltf',
// Called when the resource is loaded
function ( gltf ) {
scene.add( gltf.scene );
camera.position.z = 5;
gltf.animations; // Array<THREE.AnimationClip>
gltf.scene; // THREE.Scene
gltf.scenes; // Array<THREE.Scene>
gltf.cameras; // Array<THREE.Camera>
gltf.asset; // Object
},
// Called when loading is in progresses
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// Called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
var animate = function() {
requestAnimationFrame(animate);
// cube.rotation.x += 0.01;
// cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>