Last active
August 29, 2015 14:17
-
-
Save t-kashima/f0434e64c047cefd8313 to your computer and use it in GitHub Desktop.
Three.jsで林檎(STL)をくるくる
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 lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Threejs / Apple</title> | |
<style>body { background-color: black; margin: 0px; padding: 0px; } canvas { width: 100%; height: 100% }</style> | |
</head> | |
<body> | |
<script src="three.min.js"></script> | |
<script src="OrbitControls.js"></script> | |
<script src="STLLoader.js"></script> | |
<script> | |
var scene = new THREE.Scene(); | |
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); | |
camera.position.z = 30; | |
var renderer = new THREE.WebGLRenderer(); | |
renderer.setSize( window.innerWidth, window.innerHeight ); | |
document.body.appendChild( renderer.domElement ); | |
var controls = new THREE.OrbitControls(camera, renderer.domElement); | |
var loader = new THREE.STLLoader(); | |
loader.load('Apple.stl', function(geometry) { | |
var material = new THREE.MeshLambertMaterial({ambient: 0xff5533, color: 0xff5533}); | |
var mesh = new THREE.Mesh(geometry, material); | |
scene.add(mesh); | |
scene.add(new THREE.AmbientLight(0x777777)); | |
function render() { | |
requestAnimationFrame(render); | |
mesh.rotation.x += 0.01; | |
mesh.rotation.y += 0.01; | |
controls.update(); | |
renderer.render(scene, camera); | |
} | |
render(); | |
}); | |
function onWindowResize() { | |
camera.aspect = window.innerWidth / window.innerHeight; | |
camera.updateProjectionMatrix(); | |
renderer.setSize( window.innerWidth, window.innerHeight ); | |
} | |
window.addEventListener('resize', onWindowResize, false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment