three.js dev template - module
HTML
<script type="importmap">
{
"imports": {
"three": "https://raw.githack.com/Mugen87/three.js/3d68d51e80413fe7f933622ca2c9f9b6bb1030ae/build/three.webgpu.js",
"three/webgpu": "https://raw.githack.com/Mugen87/three.js/3d68d51e80413fe7f933622ca2c9f9b6bb1030ae/build/three.webgpu.js",
"three/tsl": "https://raw.githack.com/Mugen87/three.js/3d68d51e80413fe7f933622ca2c9f9b6bb1030ae/build/three.tsl.js",
"three/addons/": "https://raw.githack.com/Mugen87/three.js/3d68d51e80413fe7f933622ca2c9f9b6bb1030ae/examples/jsm/"
}
}
</script>
CSS
body {
margin: 0px;
}
JavaScript
import * as THREE from 'three/webgpu';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import Stats from 'three/addons/libs/stats.module.js';
let camera, scene, renderer;
let controls;
let stats;
let group;
init();
function initMesh() {
group = new THREE.Group();
const geometry = new THREE.BoxGeometry()
for ( let i = 0; i < 100; i ++ ) {
for ( let j = 0; j < 100; j ++ ) {
const material = new THREE.MeshBasicNodeMaterial( {
color: new THREE.Color( Math.random() * 0xffffff ),
side: THREE.DoubleSide,
} );
const child = new THREE.Mesh( geometry, material );
child.position.x = 50 - i;
child.position.z = 50 - j;
child.frustumCulled = false;
group.add( child );
}
}
scene.add( group );
}
function init() {
// camera
const aspect = window.innerWidth / window.innerHeight;
camera = new THREE.PerspectiveCamera( 70, aspect, 1, 1000 );
camera.position.set( 0, 75, 75 );
// renderer
renderer = new THREE.WebGPURenderer( { forceWebGL: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
// scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xc1c1c1 );
const light = new THREE.DirectionalLight( 0xffffff, 3.4 );
scene.add( light );
document.body.appendChild( renderer.domElement );
initMesh();
controls = new OrbitControls( camera, renderer.domElement );
stats = new Stats();
document.body.appendChild( stats.domElement );
// listeners
window.addEventListener( 'resize', onWindowResize );
function onWindowResize() {
const width = window.innerWidth;
const height =...