three.js dev template - module
HTML
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three/build/three.webgpu.js",
"three/webgpu": "https://unpkg.com/three/build/three.webgpu.js",
"three/tsl": "https://unpkg.com/three/build/three.tsl.js",
"three/addons/": "https://unpkg.com/three/examples/jsm/"
}
}
</script>
CSS
body {
margin: 0px;
}
JavaScript
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
let mesh, mesh2, mesh3, renderer, scene, camera, controls;
init();
function init() {
// renderer
renderer = new THREE.WebGPURenderer();
renderer.shadowMap.enabled = true
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );
// scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x000000 );
// camera
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 20000 );
camera.position.set( -304.3201624856659, 565.680936087031, 828.7361472558915);
// controls
controls = new OrbitControls( camera, renderer.domElement );
// light
const light = new THREE.PointLight( 0xffffff, 1 );
light.position.set( 227.0233737813206, 28.82779785987021, 0 );
light.castShadow = true
light.shadow.mapSize.width = 1024
light.shadow.mapSize.height = 1024
light.shadow.camera.near = 1
light.shadow.camera.far = 20000
light.intensity = 1147440
light.castShadow = true
scene.add( light );
const lightHelper = new THREE.PointLightHelper(light, 10)
scene.add(lightHelper)
const shadowCamHelper = new THREE.CameraHelper(light.shadow.camera)
scene.add(shadowCamHelper)
// for (const shadowCam of light.)
console.log(light.shadow)
// axes
scene.add( new THREE.AxesHelper( 20 ) );
// geometry
const geometry = new THREE.SphereGeometry( 100, 12, 8 );
const geometry2 = new THREE.PlaneGeometry( 1000, 1000 );
const geometry3 = new THREE.BoxGeometry( 100, 100, 100);
// material
const material = new THREE.MeshPhongMaterial( {
color: 0x00ffff,
} );
// mesh
...