1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <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';
- let camera, scene, renderer;
- let mesh;
- init().then( animate );
- async function init() {
- 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( 0xffffff );
- // 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 );
- }
- </script>
- </body>
- </html>
|