用法一:canvas
var stats = new Stats(); stats.setMode(0); stats.domElement.style.position = 'absolute'; stats.domElement.style.left = '0px'; stats.domElement.style.top = '0px'; document.body.appendChild(stats.domElement); setInterval(function () { stats.begin(); stats.end(); }, 1000 / 60)
用法二(紅字部分):app
var renderer; var stats = new Stats(); function initThree() { stats.setMode(0); stats.domElement.style.position = 'absolute'; stats.domElement.style.left = '0px'; stats.domElement.style.top = '0px'; document.body.appendChild(stats.domElement); renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setClearColor(0xffffff, 1.0); } ......此處代碼省略......
function animation3D() {
cylinder.position.x -= 0.5;
renderer.render(scene, camera);
requestAnimationFrame(animation3D);
stats.update();
}
requestAnimationFrame(animation3D);