123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js - webgl memory test I</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">
- <style>
- body {
- background-color: #fff;
- color: #000;
- }
- a {
- color: #08f;
- }
- </style>
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - memory test I
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- var container;
- var camera, scene, renderer;
- init();
- animate();
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
- camera.position.z = 200;
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0xffffff );
- renderer = new THREE.WebGLRenderer();
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- container.appendChild( renderer.domElement );
- }
- function createImage() {
- var canvas = document.createElement( 'canvas' );
- canvas.width = 256;
- canvas.height = 256;
- var context = canvas.getContext( '2d' );
- context.fillStyle = 'rgb(' + Math.floor( Math.random() * 256 ) + ',' + Math.floor( Math.random() * 256 ) + ',' + Math.floor( Math.random() * 256 ) + ')';
- context.fillRect( 0, 0, 256, 256 );
- return canvas;
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- }
- function render() {
- var geometry = new THREE.SphereBufferGeometry( 50, Math.random() * 64, Math.random() * 32 );
- var texture = new THREE.CanvasTexture( createImage() );
- var material = new THREE.MeshBasicMaterial( { map: texture, wireframe: true } );
- var mesh = new THREE.Mesh( geometry, material );
- scene.add( mesh );
- renderer.render( scene, camera );
- scene.remove( mesh );
- // clean up
- geometry.dispose();
- material.dispose();
- texture.dispose();
- }
- </script>
- </body>
- </html>
|