three.js 性能插件stats简单用法
编程语言
2018-05-09 21:39:30
阅读次数: 2
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Three框架</title>
- <script type="text/javascript" script src="three.js"></script>
- <script type="text/javascript" script src="stats.min.js"></script>
-
- <style type="text/css">
- div#canvas-frame {
- border: none;
- cursor: pointer;
- width: 100%;
- height: 600px;
- background-color: #EEEEEE;
- }
- </style>
-
- <script>
- var renderer;
- var stats;
- function initThree() {
- width = document.getElementById('canvas-frame').clientWidth;
- height = document.getElementById('canvas-frame').clientHeight;
- renderer = new THREE.WebGLRenderer({ antialias : true });
- renderer.setSize(width, height);
- document.getElementById('canvas-frame').appendChild(renderer.domElement);
- renderer.setClearColorHex(0xFFFFFF, 1.0);
-
-
- stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.left = '0px';
- stats.domElement.style.top = '0px';
- document.getElementById('canvas-frame').appendChild(stats.domElement);
- }
-
- var camera;
- function initCamera() {
- camera = new THREE.PerspectiveCamera(45, width / height, 1, 10000);
- camera.position.x = 0;
- camera.position.y = 0;
- camera.position.z = 600;
- camera.up.x = 0;
- camera.up.y = 0;
- camera.up.z = 0;
- camera.lookAt({
- x : 0,
- y : 0,
- z : 0
- });
- }
-
- var scene;
- function initScene() {
- scene = new THREE.Scene();
- }
-
- var light;
- function initLight() {
- light = new THREE.PointLight(0x00FF00);
- light.position.set(0, 0,300);
- scene.add(light);
- }
-
- var cube;
- var mesh;
- function initObject() {
-
- var geometry = new THREE.CylinderGeometry( 10,15,40);
- var material = new THREE.MeshLambertMaterial( { color:0xFFFFFF} );
- mesh = new THREE.Mesh( geometry,material);
- mesh.position.x = 100;
- mesh.position.y = 100;
- mesh.position.z = 100;
- scene.add(mesh);
-
- }
-
- function threeStart() {
- initThree();
- initCamera();
- initScene();
- initLight();
- initObject();
- animation();
- }
-
- function animation()
- {
- mesh.position.z+=1;
- renderer.render(scene, camera);
- requestAnimationFrame(animation);
- stats.update();
- }
- </script>
- </head>
-
- <body onload="threeStart();">
- <div id="canvas-frame"></div>
- </body>
- </html>
- <!DOCTYPE html>
- <html lang="en">
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Three框架</title>
- <script type="text/javascript" script src="three.js"></script>
- <script type="text/javascript" script src="stats.min.js"></script>
-
- <style type="text/css">
- div#canvas-frame {
- border: none;
- cursor: pointer;
- width: 100%;
- height: 600px;
- background-color: #EEEEEE;
- }
- </style>
- </head>
-
- <body>
- <script type = "text/javascript">
- var renderer;
- var stats;
- function initThree() {
- renderer = new THREE.WebGLRenderer({ antialias : true });
- renderer.setSize(1000, 800);
- document.body.appendChild (renderer.domElement );
- renderer.setClearColorHex(0xFFFFFF, 1.0);
-
-
- stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.left = '0px';
- stats.domElement.style.top = '0px';
- document.body.appendChild( stats.domElement );
- }
-
- var camera;
- function initCamera() {
- camera = new THREE.PerspectiveCamera(45, 1000 / 800, 1, 10000);
- camera.position.x = 0;
- camera.position.y = 0;
- camera.position.z = 600;
- camera.up.x = 0;
- camera.up.y = 0;
- camera.up.z = 0;
- camera.lookAt({
- x : 0,
- y : 0,
- z : 0
- });
- }
-
- var scene;
- function initScene() {
- scene = new THREE.Scene();
- }
-
- var light;
- function initLight() {
- light = new THREE.PointLight(0x00FF00);
- light.position.set(0, 0,300);
- scene.add(light);
- }
-
- var cube;
- var mesh;
- function initObject() {
-
- var geometry = new THREE.CylinderGeometry( 10,15,40);
- var material = new THREE.MeshLambertMaterial( { color:0xFFFFFF} );
- mesh = new THREE.Mesh( geometry,material);
- mesh.position.x = 100;
- mesh.position.y = 100;
- mesh.position.z = 100;
- scene.add(mesh);
-
- }
-
- function animation()
- {
- mesh.position.z+=1;
- renderer.render(scene, camera);
- requestAnimationFrame(animation);
- stats.update();
- }
-
- !function threeStart() {
- initThree();
- initCamera();
- initScene();
- initLight();
- initObject();
- animation();
- }();
- </script>
- </body>
- </html>
转载自xiangjinqi.iteye.com/blog/2377516