Skip to content

Instantly share code, notes, and snippets.

@fictorial
Created July 2, 2015 14:24
Show Gist options
  • Save fictorial/e7c8addf8bfa4614ee97 to your computer and use it in GitHub Desktop.
Save fictorial/e7c8addf8bfa4614ee97 to your computer and use it in GitHub Desktop.
Clara.io issue w.r.t. THREE.js import and spotlights
var scene, camera, renderer;
$(function () {
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMapEnabled = true;
document.body.appendChild(renderer.domElement);
function aspect_ratio() {
return window.innerWidth / window.innerHeight;
}
camera = new THREE.PerspectiveCamera(60, aspect_ratio(), 0.1, 100);
camera.aspect = aspect_ratio();
var loader = new THREE.ObjectLoader();
loader.load("/static/darts-room.json", function on_load(obj) {
console.log('loaded scene', obj);
scene = obj;
camera.lookAt(scene.position);
camera.position.z = 3;
camera.position.y = -0.5;
var axes = new THREE.AxisHelper(0.25);
var spotlight = scene.getObjectByName("SpotLight");
spotlight.add(axes);
update();
}, function on_progress(xhr) {
if (xhr.lengthComputable) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log(Math.round(percentComplete, 2) + '% downloaded');
}
}, function on_error(xhr) {
console.error('load failed', xhr);
});
function update() {
requestAnimationFrame(update);
renderer.render(scene, camera);
}
window.addEventListener('resize', function () {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = aspect_ratio();
camera.updateProjectionMatrix();
}, false);
});
<!doctype html>
<html>
<head>
<title>Darts</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r71/three.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment