-
-
Save brett-miller/60cb9862fb0283c2f1126fd35166accf to your computer and use it in GitHub Desktop.
[STL]test to upload STL file on gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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