Hello! I have recently started to learn three.js and I have ran into some roadblocks right at the start…
I have followed the getting started instructions and was able to start a local server with basic shapes/lines.
But now I want to start using GLTFLoader, but I have been tackling this issue for the past few hours and I have sadly no results.
I am trying to get this pirate ship to show up, but it will not load.
ship_light.bin (494.9 KB)
ship_light.gltf (30.7 KB)
I was using the webgl GLTFLoader on github as a reference, and other things I found on stack overflow that may have helped (like moving the camera in case it was inside the gLTF object).
But honestly, I am just looking for guidance and better practices for facing this issue… It shouldn’t be this difficult lol.
<html>
<head>
<title>My first three.js app</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%
}
</style>
</head>
<body>
<script src="examples/js/loaders/GLTFLoader.js"></script>
<script src="examples/js/controls/OrbitControls.js"></script>
<script src="examples/js/WebGL.js"></script>
<script src="build/three.js"></script>
<script src="build/three.min.js"></script>
<script>
if (WEBGL.isWebGLAvailable() === false) {
document.body.appendChild(WEBGL.getWebGLErrorMessage());
}
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(100, 100, 100);
camera.lookAt(new THREE.Vector3(0, 0, 0));
var renderer = new THREE.WebGLRenderer({
alpha: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.gammaOutput = true;
document.body.appendChild(renderer.domElement);
var light = new THREE.HemisphereLight(0xbbbbff, 0x444422);
light.position.set(0, 1, 0);
scene.add(light);
var loader = new THREE.GLTFLoader();
loader.load('light_ship.gltf', function (gltf) {
var ship = gltf.scene;
scene.add(ship);
});
var animate = function () {
requestAnimationFrame(animate);
renderer.render(scene, camera);
};
animate();
</script>
</body>
</html>