123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - performance [nodes]</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link type="text/css" rel="stylesheet" href="main.css">
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank">three.js</a><span class="white"> - NodeMaterial Performance</span><br />
- <br>
- <b>Node Material System</b>
- <br>
- <div>
- Standard<b>Node</b>Material |
- <span id="node" class="white">None</span>
- </div>
- <div>
- MeshStandard<b>Node</b>Material |
- <span id="nodeBased" class="white">None</span>
- </div>
- <br>
- <b>Current Material System</b>
- <br>
- <div>
- MeshStandardMaterial |
- <span id="default" class="white">None</span>
- </div>
- <br>
- <a id="bench" href="javascript:void(0);">Click to benchmark</a>
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import Stats from './jsm/libs/stats.module.js';
- import {
- StandardNodeMaterial,
- MeshStandardNodeMaterial
- } from './jsm/nodes/Nodes.js';
- var container, stats;
- var camera, scene, renderer;
- var geometry;
- var meshes = [];
- var mouseX = 0, mouseY = 0;
- var windowHalfX = window.innerWidth / 2;
- var windowHalfY = window.innerHeight / 2;
- document.addEventListener( 'mousemove', onDocumentMouseMove, false );
- init();
- animate();
- function createScene( MaterialClass, count ) {
- count = count !== undefined ? count : 70;
- var i = 0;
- for ( i = 0; i < meshes.length; i ++ ) {
- meshes[ i ].material.dispose();
- scene.remove( meshes[ i ] );
- }
- meshes = [];
- for ( i = 0; i < count; i ++ ) {
- var material = new MaterialClass(),
- color = 0xFFFFFF * Math.random();
- if ( material.color.isNode ) material.color.value.setHex( color );
- else material.color.setHex( color );
- // prevent share code
- material.defines.UUID = material.uuid;
- var mesh = new THREE.Mesh( geometry, material );
- mesh.position.x = Math.random() * 1000 - 500;
- mesh.position.y = Math.random() * 1000 - 500;
- mesh.position.z = Math.random() * 1000 - 500;
- mesh.rotation.x = Math.random() * 2 * Math.PI;
- mesh.rotation.y = Math.random() * 2 * Math.PI;
- mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
- mesh.matrixAutoUpdate = false;
- mesh.updateMatrix();
- scene.add( mesh );
- meshes.push( mesh );
- }
- }
- function benchmark() {
- var time, benchmarkTime;
- // Stabilizes CPU
- createScene( THREE.MeshStandardMaterial, 10 );
- render();
- // Standard *Node* Material
- time = performance.now();
- createScene( StandardNodeMaterial );
- render();
- benchmarkTime = ( performance.now() - time ) / 1000;
- document.getElementById( 'node' ).textContent = benchmarkTime.toFixed( 3 ) + " seconds";
- // Mesh Standard *Node* Material
- time = performance.now();
- createScene( MeshStandardNodeMaterial );
- render();
- benchmarkTime = ( performance.now() - time ) / 1000;
- document.getElementById( 'nodeBased' ).textContent = benchmarkTime.toFixed( 3 ) + " seconds";
- // Mesh Standard Material
- time = performance.now();
- createScene( THREE.MeshStandardMaterial );
- render();
- benchmarkTime = ( performance.now() - time ) / 1000;
- document.getElementById( 'default' ).textContent = benchmarkTime.toFixed( 3 ) + " seconds";
- }
- document.getElementById( 'bench' ).addEventListener( 'click', function () {
- if ( geometry ) {
- benchmark();
- }
- } );
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
- camera.position.z = 3200;
- scene = new THREE.Scene();
- scene.add( new THREE.PointLight( 0xFFFFFF ) );
- //scene.background = new THREE.Color( 0xffffff );
- var loader = new THREE.BufferGeometryLoader();
- loader.load( 'models/json/suzanne_buffergeometry.json', function ( geo ) {
- geo.computeVertexNormals();
- geometry = geo;
- } );
- renderer = new THREE.WebGLRenderer();
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- //renderer.sortObjects = false;
- container.appendChild( renderer.domElement );
- stats = new Stats();
- container.appendChild( stats.dom );
- //
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- windowHalfX = window.innerWidth / 2;
- windowHalfY = window.innerHeight / 2;
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function onDocumentMouseMove( event ) {
- mouseX = ( event.clientX - windowHalfX ) * 10;
- mouseY = ( event.clientY - windowHalfY ) * 10;
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- function render() {
- camera.position.x += ( mouseX - camera.position.x ) * .05;
- camera.position.y += ( - mouseY - camera.position.y ) * .05;
- camera.lookAt( scene.position );
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|