123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <html lang="en">
- <head>
- <title>WebGPU Sandbox</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" rel="noopener">three.js</a> WebGPU - sandbox<br/>(Chrome Canary with flag: --enable-unsafe-webgpu)
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js';
- import WebGPU from './jsm/renderers/webgpu/WebGPU.js';
- let camera, scene, renderer;
- let mesh;
- init().then( animate ).catch( onInitError );
- async function init() {
- if ( WebGPU.isAvailable() === false ) {
- document.body.appendChild( WebGPU.getErrorMessage() );
- throw 'No WebGPU support';
- }
- camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );
- camera.position.z = 4;
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0x222222 );
- // textured mesh
- const loader = new THREE.TextureLoader();
- const texture = loader.load( './textures/uv_grid_opengl.jpg' );
- const geometryMesh = new THREE.BoxBufferGeometry();
- const materialMesh = new THREE.MeshBasicMaterial( { map: texture } );
- mesh = new THREE.Mesh( geometryMesh, materialMesh );
- mesh.position.set( - 1, 0.5, 0 );
- scene.add( mesh );
- // points
- const geometryPoints = new THREE.BufferGeometry().setFromPoints( [ new THREE.Vector3( 0, - 1, 0 ), new THREE.Vector3( 1, - 1, 0 ) ] );
- const materialPoints = new THREE.PointsMaterial();
- const points = new THREE.Points( geometryPoints, materialPoints );
- scene.add( points );
- // lines
- const geometryLine = new THREE.BufferGeometry().setFromPoints( [
- new THREE.Vector3( 1, 0, 0 ),
- new THREE.Vector3( 2, 0, 0 ),
- new THREE.Vector3( 2, 1, 0 ),
- new THREE.Vector3( 1, 1, 0 )
- ] );
- const materialLine = new THREE.LineBasicMaterial();
- const line = new THREE.Line( geometryLine, materialLine );
- scene.add( line );
- renderer = new WebGPURenderer();
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
- window.addEventListener( 'resize', onWindowResize, false );
- return renderer.init();
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function animate() {
- requestAnimationFrame( animate );
- mesh.rotation.x += 0.01;
- mesh.rotation.y += 0.02;
- renderer.render( scene, camera );
- }
- function onInitError( error ) {
- console.error( error );
- }
- </script>
- </body>
- </html>
|