Docker
- Update three in static file
This commit is contained in:
@ -0,0 +1,143 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>three.js webgpu - sprites</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 - sprites
|
||||
</div>
|
||||
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"three": "../build/three.webgpu.js",
|
||||
"three/tsl": "../build/three.webgpu.js",
|
||||
"three/addons/": "./jsm/"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
|
||||
import * as THREE from '/static/three/build/three.module.js';
|
||||
import { texture, uv, userData, rangeFog, color } from 'three/tsl';
|
||||
|
||||
let camera, scene, renderer;
|
||||
|
||||
let map;
|
||||
|
||||
let group;
|
||||
|
||||
let imageWidth = 1, imageHeight = 1;
|
||||
|
||||
init();
|
||||
|
||||
function init() {
|
||||
|
||||
const width = window.innerWidth;
|
||||
const height = window.innerHeight;
|
||||
|
||||
camera = new THREE.PerspectiveCamera( 60, width / height, 1, 2100 );
|
||||
camera.position.z = 1500;
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scene.fogNode = rangeFog( color( 0x0000ff ), 1500, 2100 );
|
||||
|
||||
// create sprites
|
||||
|
||||
const amount = 200;
|
||||
const radius = 500;
|
||||
|
||||
const textureLoader = new THREE.TextureLoader();
|
||||
|
||||
map = textureLoader.load( 'textures/sprite1.png', ( map ) => {
|
||||
|
||||
imageWidth = map.image.width;
|
||||
imageHeight = map.image.height;
|
||||
|
||||
} );
|
||||
|
||||
group = new THREE.Group();
|
||||
|
||||
const textureNode = texture( map );
|
||||
|
||||
const material = new THREE.SpriteNodeMaterial();
|
||||
material.colorNode = textureNode.mul( uv() ).mul( 2 ).saturate();
|
||||
material.opacityNode = textureNode.a;
|
||||
material.rotationNode = userData( 'rotation', 'float' ); // get value of: sprite.userData.rotation
|
||||
material.transparent = true;
|
||||
|
||||
for ( let a = 0; a < amount; a ++ ) {
|
||||
|
||||
const x = Math.random() - 0.5;
|
||||
const y = Math.random() - 0.5;
|
||||
const z = Math.random() - 0.5;
|
||||
|
||||
const sprite = new THREE.Sprite( material );
|
||||
|
||||
sprite.position.set( x, y, z );
|
||||
sprite.position.normalize();
|
||||
sprite.position.multiplyScalar( radius );
|
||||
|
||||
// individual rotation per sprite
|
||||
sprite.userData.rotation = 0;
|
||||
|
||||
group.add( sprite );
|
||||
|
||||
}
|
||||
|
||||
scene.add( group );
|
||||
|
||||
//
|
||||
|
||||
renderer = new THREE.WebGPURenderer( { antialias: true } );
|
||||
renderer.setPixelRatio( window.devicePixelRatio );
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
renderer.setAnimationLoop( render );
|
||||
document.body.appendChild( renderer.domElement );
|
||||
|
||||
window.addEventListener( 'resize', onWindowResize );
|
||||
|
||||
}
|
||||
|
||||
function onWindowResize() {
|
||||
|
||||
const width = window.innerWidth;
|
||||
const height = window.innerHeight;
|
||||
|
||||
camera.aspect = width / height;
|
||||
camera.updateProjectionMatrix();
|
||||
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
const time = Date.now() / 1000;
|
||||
|
||||
for ( let i = 0, l = group.children.length; i < l; i ++ ) {
|
||||
|
||||
const sprite = group.children[ i ];
|
||||
const scale = Math.sin( time + sprite.position.x * 0.01 ) * 0.3 + 1.0;
|
||||
|
||||
sprite.userData.rotation += 0.1 * ( i / l );
|
||||
sprite.scale.set( scale * imageWidth, scale * imageHeight, 1.0 );
|
||||
|
||||
}
|
||||
|
||||
group.rotation.x = time * 0.5;
|
||||
group.rotation.y = time * 0.75;
|
||||
group.rotation.z = time * 1.0;
|
||||
|
||||
renderer.render( scene, camera );
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user