Corrected errors and added stats in rendering of prototype

This commit is contained in:
Thomas FORGIONE 2015-04-13 09:35:49 +02:00
parent 7bcd8e7e23
commit b5d2822d00
4 changed files with 19 additions and 2 deletions

View File

@ -1 +0,0 @@
Deny from all

6
js/three/stats.min.js vendored Normal file
View File

@ -0,0 +1,6 @@
// stats.js - http://github.com/mrdoob/stats.js
var Stats=function(){var l=Date.now(),m=l,g=0,n=Infinity,o=0,h=0,p=Infinity,q=0,r=0,s=0,f=document.createElement("div");f.id="stats";f.addEventListener("mousedown",function(b){b.preventDefault();t(++s%2)},!1);f.style.cssText="width:80px;opacity:0.9;cursor:pointer";var a=document.createElement("div");a.id="fps";a.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#002";f.appendChild(a);var i=document.createElement("div");i.id="fpsText";i.style.cssText="color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";
i.innerHTML="FPS";a.appendChild(i);var c=document.createElement("div");c.id="fpsGraph";c.style.cssText="position:relative;width:74px;height:30px;background-color:#0ff";for(a.appendChild(c);74>c.children.length;){var j=document.createElement("span");j.style.cssText="width:1px;height:30px;float:left;background-color:#113";c.appendChild(j)}var d=document.createElement("div");d.id="ms";d.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#020;display:none";f.appendChild(d);var k=document.createElement("div");
k.id="msText";k.style.cssText="color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";k.innerHTML="MS";d.appendChild(k);var e=document.createElement("div");e.id="msGraph";e.style.cssText="position:relative;width:74px;height:30px;background-color:#0f0";for(d.appendChild(e);74>e.children.length;)j=document.createElement("span"),j.style.cssText="width:1px;height:30px;float:left;background-color:#131",e.appendChild(j);var t=function(b){s=b;switch(s){case 0:a.style.display=
"block";d.style.display="none";break;case 1:a.style.display="none",d.style.display="block"}};return{REVISION:12,domElement:f,setMode:t,begin:function(){l=Date.now()},end:function(){var b=Date.now();g=b-l;n=Math.min(n,g);o=Math.max(o,g);k.textContent=g+" MS ("+n+"-"+o+")";var a=Math.min(30,30-30*(g/200));e.appendChild(e.firstChild).style.height=a+"px";r++;b>m+1E3&&(h=Math.round(1E3*r/(b-m)),p=Math.min(p,h),q=Math.max(q,h),i.textContent=h+" FPS ("+p+"-"+q+")",a=Math.min(30,30-30*(h/100)),c.appendChild(c.firstChild).style.height=
a+"px",m=b,r=0);return b},update:function(){l=this.end()}}};"object"===typeof module&&(module.exports=Stats);

13
prototype/js/main.js vendored
View File

@ -6,6 +6,7 @@ var objects = [];
var cameras = new CameraContainer(); var cameras = new CameraContainer();
var spheres = new Array(mesh_number); var spheres = new Array(mesh_number);
var visible = 0; var visible = 0;
var stats;
var loader; var loader;
@ -23,12 +24,20 @@ function init() {
renderer.setSize(container_size.width, container_size.height); renderer.setSize(container_size.width, container_size.height);
renderer.shadowMapEnabled = true; renderer.shadowMapEnabled = true;
// renderer.setClearColor(0x000000); // renderer.setClearColor(0x000000);
document.getElementById('container').appendChild(renderer.domElement);
// on initialise la scène // on initialise la scène
scene = new THREE.Scene(); scene = new THREE.Scene();
raycaster = new THREE.Raycaster(); raycaster = new THREE.Raycaster();
// Create stats counter
stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = 'absolute';
stats.domElement.style.cssFloat = "top-left";
container.appendChild( stats.domElement );
container.appendChild(renderer.domElement);
// init light // init light
var directional_light = new THREE.DirectionalLight(0x999999); var directional_light = new THREE.DirectionalLight(0x999999);
directional_light.position.set(1, 0.5, 1).normalize(); directional_light.position.set(1, 0.5, 1).normalize();
@ -157,10 +166,12 @@ function animate() {
// on appelle la fonction animate() récursivement à chaque frame // on appelle la fonction animate() récursivement à chaque frame
requestAnimationFrame(animate); requestAnimationFrame(animate);
stats.begin();
cameras.update(); cameras.update();
cameras.look(); cameras.look();
renderer.render(scene, cameras.mainCamera()); renderer.render(scene, cameras.mainCamera());
stats.end();
} }
function onWindowResize() { function onWindowResize() {

View File

@ -12,4 +12,5 @@
<script src="/js/BufferGeometryToGeometry.js"></script> <script src="/js/BufferGeometryToGeometry.js"></script>
<script src="/js/PointerCamera.js"></script> <script src="/js/PointerCamera.js"></script>
<script src="/js/CameraContainer.js"></script> <script src="/js/CameraContainer.js"></script>
<script src="/js/three/stats.min.js"></script>
# #