Skip to content

Instantly share code, notes, and snippets.

@bellbind
Last active April 17, 2017 17:49
Show Gist options
  • Save bellbind/9b780159b04bd1cc5758 to your computer and use it in GitHub Desktop.
Save bellbind/9b780159b04bd1cc5758 to your computer and use it in GitHub Desktop.
[STL]test to upload STL file on gist
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!doctype html>
<html>
<head>
<script src="http://threejs.org/build/three.min.js"></script>
<script src="http://threejs.org/examples/js/loaders/STLLoader.js"></script>
<script>
window.addEventListener("load", function () {
var camera = new THREE.PerspectiveCamera(
30, window.innerWidth/ window.innerHeight, 1, 1500);
camera.position.set(300, 450, 300);
var cameraTarget = new THREE.Vector3(0, 0, 0);
var scene = new THREE.Scene();
var light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(0, 300, 300);
scene.add(light);
scene.add(new THREE.AmbientLight(0x555555));
var renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var loader = new THREE.STLLoader();
loader.addEventListener("load", function (event) {
console.log("loaded");
var material = new THREE.MeshPhongMaterial({
ambient: 0xff0000, color: 0xff0000,
specular: 0x333333, shininess: 64});
var mesh = new THREE.Mesh(event.content, material);
//mesh.scale.set(0.01, 0.01, 0.01);
mesh.rotation.set(-Math.PI / 2, 0, 0);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
});
loader.load("test.stl");
(function animate() {
requestAnimationFrame(animate);
var timer = Date.now() * 0.001;
camera.position.x = Math.cos(timer) * 300;
camera.position.z = Math.sin(timer) * 300;
camera.lookAt(cameraTarget);
renderer.render(scene, camera);
})();
}, false);
</script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment