joeb joeb - 3 months ago 17
Javascript Question

Three js sample scene not working

Sorry for the total noob question but Im just starting in three.js. This will probably be a simple answer for the pros. Im trying to start with the most basic scene and build my knowledge from there. So i started with the example scene straight from the docs. All i get when i run it, both locally, and on my server is just a white screen, no canvas or scene. The examples i downloaded work both locally and on my server so im not quite sure why this doesn't work. Here's my code.

<!DOCTYPE html>
<html>
<head>
<title>My first Three.js app</title>
<style>canvas { width: 100%; height: 100% }</style>
</head>
<body>
<canvas></canvas>
<script src="threejs/three.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 1, 10000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.BoxGeometry(700, 700, 700, 10, 10, 10);
var material = new THREE.MeshBasicMaterial({color: 0xfffff, wireframe: true});
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 1000;
function render() {
requestAnimationFrame(render);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
};
render();
</script>
</body>
</html>


Thanks in advance for any help.

Joe

Answer

Check your three.js file location. This src worked for me , my html file is in the home folder (three.js-master)

<script src="build/three.js"></script>