UNPKG

threex

Version:

Game Extensions for three.js http://www.threejsgames.com/extensions/

57 lines (50 loc) 1.78 kB
<!DOCTYPE html> <script src="../../../vendor/three.js/build/three.min.js"></script> <body style='margin: 0px; background-color: #bbbbbb; overflow: hidden;'><script> var renderer = new THREE.WebGLRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement ); var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000 ); camera.position.z = 3; var geometry = new THREE.CubeGeometry( 1, 1, 1); var material = new THREE.MeshNormalMaterial(); var mesh = new THREE.Mesh( geometry, material ); scene.add( mesh ); /** * * here the function are hooked in a array of function * * function are push/removed in the array with normal array function * * simple as it is very vendor.js * * ## how to handle priority * * possible handling of priority with function wrapper to store the priority ? * * with a special sort function * * simpler is to have multiple array per section * * updateFcts * * renderUpdateFcts * * postRenderUpdateFcts * * i like this one. it is super simple * * */ var updateFcts = []; updateFcts.push(function(delta, now){ mesh.rotation.x += 1 * delta; mesh.rotation.y += 0.01; }) 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>