threex
Version:
Game Extensions for three.js http://www.threejsgames.com/extensions/
108 lines (96 loc) • 4.08 kB
HTML
<!DOCTYPE html>
<script src='../../../vendor/three.js/build/three.min.js'></script>
<script src='../threex.minecraft.js'></script>
<!-- include animation -->
<script src='../threex.animation.js'></script>
<script src='../threex.animations.js'></script>
<script src='../threex.minecraftcharheadanim.js'></script>
<script src='../threex.minecraftcharbodyanim.js'></script>
<!-- ================= -->
<body style='margin: 0px; background-color: #bbbbbb; overflow: hidden;'>
<div>
<strong>Body Animations</strong>
<button onclick='switchBodyValue(this.innerText);'>stand</button>
<button onclick='switchBodyValue(this.innerText);'>fall</button>
<button onclick='switchBodyValue(this.innerText);'>strafe</button>
<button onclick='switchBodyValue(this.innerText);'>jump</button>
<button onclick='switchBodyValue(this.innerText);'>walk</button>
<button onclick='switchBodyValue(this.innerText);'>run</button>
<button onclick='switchBodyValue(this.innerText);'>wave</button>
<button onclick='switchBodyValue(this.innerText);'>hiwave</button>
<button onclick='switchBodyValue(this.innerText);'>circularPunch</button>
<button onclick='switchBodyValue(this.innerText);'>rightPunch</button>
</div>
<div>
<strong>Head Animations</strong>
<button onclick='switchHeadValue(this.innerText);'>still</button>
<button onclick='switchHeadValue(this.innerText);'>yes</button>
<button onclick='switchHeadValue(this.innerText);'>no</button>
</div>
<script>
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var updateFcts = [];
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 100 );
camera.position.y = 0.3;
camera.position.z = 2;
//////////////////////////////////////////////////////////////////////////////////
// load Character //
//////////////////////////////////////////////////////////////////////////////////
var character = new THREEx.MinecraftChar()
scene.add(character.root)
var headAnims = new THREEx.MinecraftCharHeadAnimations(character);
updateFcts.push(function(delta, now){
headAnims.update(delta, now)
})
headAnims.start('yes');
var switchHeadValue = function(value){
headAnims.start(value)
}
// init bodyAnims
var bodyAnims = new THREEx.MinecraftCharBodyAnimations(character);
updateFcts.push(function(delta, now){
bodyAnims.update(delta, now)
})
bodyAnims.start('walk');
var switchBodyValue = function(value){
bodyAnims.start(value)
}
//////////////////////////////////////////////////////////////////////////////////
// Camera Controls //
//////////////////////////////////////////////////////////////////////////////////
var mouse = {x : 0, y : 0}
document.addEventListener('mousemove', function(event){
mouse.x = (event.clientX / window.innerWidth ) - 0.5
mouse.y = (event.clientY / window.innerHeight) - 0.5
}, false)
updateFcts.push(function(delta, now){
// camera.position.x += (mouse.x*5 - camera.position.x) * (delta*3)
// camera.position.y += (mouse.y*5 - camera.position.y) * (delta*3)
// camera.lookAt( scene.position )
})
//////////////////////////////////////////////////////////////////////////////////
// render the scene //
//////////////////////////////////////////////////////////////////////////////////
updateFcts.push(function(){
renderer.render( scene, camera );
})
//////////////////////////////////////////////////////////////////////////////////
// loop runner //
//////////////////////////////////////////////////////////////////////////////////
var lastTimeMsec= null
requestAnimationFrame(function animate(nowMsec){
// keep looping
requestAnimationFrame( animate );
// measure time
lastTimeMsec = lastTimeMsec || nowMsec-1000/60
var deltaMsec = Math.min(200, nowMsec - lastTimeMsec)
lastTimeMsec = nowMsec
// call each update function
updateFcts.forEach(function(updateFn){
updateFn(deltaMsec/1000, nowMsec/1000)
})
})
</script></body>