tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

41 lignes · 1230 octetsBrut · Historique
1<script lang="ts">
2 import { T } from '@threlte/core';
3 import * as THREE from 'three';
4
5 /** The system's star at the origin: the light planets are shaded from, made visible. */
6 let { radius = 6 }: { radius?: number } = $props();
7
8 const glow = new THREE.SpriteMaterial({
9 map: makeGlowTexture(),
10 color: '#ffd9a0',
11 transparent: true,
12 blending: THREE.AdditiveBlending,
13 depthWrite: false
14 });
15
16 function makeGlowTexture(): THREE.Texture {
17 const size = 128;
18 const canvas = document.createElement('canvas');
19 canvas.width = canvas.height = size;
20 const ctx = canvas.getContext('2d')!;
21 const g = ctx.createRadialGradient(size / 2, size / 2, 0, size / 2, size / 2, size / 2);
22 g.addColorStop(0, 'rgba(255,255,255,1)');
23 g.addColorStop(0.25, 'rgba(255,220,160,0.6)');
24 g.addColorStop(1, 'rgba(255,180,90,0)');
25 ctx.fillStyle = g;
26 ctx.fillRect(0, 0, size, size);
27 return new THREE.CanvasTexture(canvas);
28 }
29
30 $effect(() => () => {
31 glow.map?.dispose();
32 glow.dispose();
33 });
34</script>
35
36<T.PointLight intensity={2} distance={0} decay={0} color="#fff7ed" />
37<T.Mesh>
38 <T.SphereGeometry args={[radius, 32, 32]} />
39 <T.MeshBasicMaterial color="#fff1d6" />
40</T.Mesh>
41<T.Sprite material={glow} scale={radius * 7} />