@idosgames/gfx 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ import Phaser from 'phaser';
2
+ import { c as Mood, e as TierSettings } from '../moods-CROfsmd7.js';
3
+
4
+ /** Past this the screen is not sharper to the eye, only slower to fill. */
5
+ declare const MAX_DENSITY = 2;
6
+ /** The screen's density, capped. Baked art uses it once; the canvas may drop below it (see the controller). */
7
+ declare function screenDensity(): number;
8
+ /** The density the scene's canvas is drawn at right now (the Scale Manager's zoom is its inverse). */
9
+ declare function canvasDensity(scene: Phaser.Scene): number;
10
+ /**
11
+ * Tells Phaser a texture was drawn `k` times bigger than it should show: an image of it keeps the
12
+ * size it would have at `k = 1` (its `width`, `displayWidth`, `setDisplaySize`, hit area), only with
13
+ * `k` times the pixels. Phaser draws a texture divided by its source's `resolution` (that is how its
14
+ * own Text is sharp) but sizes a game object by the frame's `realWidth`, so both are set.
15
+ *
16
+ * ⚠ Only for textures shown by images and sprites. A particle emitter sizes its particles by the
17
+ * frame's PIXELS and ignores the resolution: a marked texture there comes out `k` times bigger.
18
+ * A TileSprite neither: it maps by pixels too (`Backdrop` scales its tiles itself).
19
+ */
20
+ declare function markDensity(texture: Phaser.Textures.Texture, k: number): void;
21
+
22
+ declare const FX: {
23
+ readonly dot: "gfx:dot";
24
+ readonly spark: "gfx:spark";
25
+ readonly puff: "gfx:puff";
26
+ readonly chip: "gfx:chip";
27
+ readonly ring: "gfx:ring";
28
+ readonly star: "gfx:star";
29
+ /** A wide soft light: the halo behind a thing that shines. */
30
+ readonly glow: "gfx:glow";
31
+ /** A soft dark ellipse: the shadow under an actor. */
32
+ readonly shadow: "gfx:shadow";
33
+ /** Dark corners of the frame. */
34
+ readonly vignette: "gfx:vignette";
35
+ };
36
+ type FxTexture = (typeof FX)[keyof typeof FX];
37
+ /** Side of an effect picture, pixels. */
38
+ declare const FX_SIZE = 64;
39
+ /** Makes the effect pictures a scene's game does not have yet. Cheap to call again. */
40
+ declare function ensureFxTextures(scene: Phaser.Scene): void;
41
+
42
+ interface Burst2D {
43
+ x: number;
44
+ y: number;
45
+ /** 0xRRGGBB. */
46
+ color: number;
47
+ /** How many (default 12). */
48
+ n?: number;
49
+ /** How far they fly, in the scene's units (default 60). */
50
+ size?: number;
51
+ }
52
+ declare class Particles2D {
53
+ private readonly scene;
54
+ private readonly depth;
55
+ private readonly emitters;
56
+ private readonly shot;
57
+ /** Share of a burst's particles really emitted (the tier's). */
58
+ amount: number;
59
+ constructor(scene: Phaser.Scene, depth?: number, amount?: number);
60
+ private emitter;
61
+ private many;
62
+ private fire;
63
+ /** Bright pieces flying out of a point and falling: a hit, a pickup, a thing breaking. */
64
+ burst(o: Burst2D): void;
65
+ /** Paper pieces of many colours thrown up and fluttering down: a win. */
66
+ confetti(o: {
67
+ x: number;
68
+ y: number;
69
+ colors: readonly number[];
70
+ n?: number;
71
+ size?: number;
72
+ }): void;
73
+ /** Glints twinkling around a point: a thing worth taking, a reward. */
74
+ sparkle(o: Burst2D): void;
75
+ /** A low cloud kicked up from the ground: a landing, a skid, running feet. */
76
+ dust(o: Burst2D): void;
77
+ /** A ring spreading from a point: a shock wave, a thing being placed. */
78
+ ring(o: Burst2D): void;
79
+ destroy(): void;
80
+ }
81
+
82
+ interface FrameGrade {
83
+ /** The frame's size changed, in the scene's own units, and where its centre is. */
84
+ resize(width: number, height: number, centerX?: number, centerY?: number): void;
85
+ /** Drops the camera's colour pass (a slow device gives it up); the vignette stays. */
86
+ setFilter(on: boolean): void;
87
+ /**
88
+ * Feed it every frame's time in seconds and a slow device gives the colour pass up by itself, only
89
+ * when that is proven to help (AdaptiveQuality: A, B, A). A game that steps quality down itself does
90
+ * not call this.
91
+ */
92
+ frame(dt: number): void;
93
+ destroy(): void;
94
+ }
95
+ /**
96
+ * The mood's saturation and contrast as ONE colour pass on the scene's main camera (mid and high tiers)
97
+ * and its vignette as a picture over the frame (every tier). `depth` must be above the game's field.
98
+ */
99
+ declare function createFrameGrade(scene: Phaser.Scene, mood: Mood, tier: TierSettings, depth?: number): FrameGrade;
100
+ /** A soft light of a colour behind a thing that shines (a coin, a gem, a shot). `size` is its width. */
101
+ declare function glowSprite(scene: Phaser.Scene, x: number, y: number, size: number, color: number, alpha?: number): Phaser.GameObjects.Image;
102
+ /** A soft dark ellipse on the ground under an actor: `width` across, a third of it deep. */
103
+ declare function shadowSprite(scene: Phaser.Scene, x: number, y: number, width: number, alpha?: number): Phaser.GameObjects.Image;
104
+ interface Backdrop {
105
+ /** The frame's size changed, in the scene's own units, and where its centre is. */
106
+ resize(width: number, height: number, centerX?: number, centerY?: number): void;
107
+ destroy(): void;
108
+ }
109
+ /**
110
+ * The back of a frame out of ONE colour ("#rrggbb"): lighter and warmer at the top, deeper and cooler at
111
+ * the bottom, a soft light coming from above. A flat fill is what makes a puzzle's field look like a
112
+ * settings screen; this is one picture drawn first, on every tier. `depth` must be under the game's field.
113
+ */
114
+ declare function createBackdrop(scene: Phaser.Scene, color: string, depth?: number): Backdrop;
115
+
116
+ export { type Backdrop, type Burst2D, FX, FX_SIZE, type FrameGrade, type FxTexture, MAX_DENSITY, Particles2D, canvasDensity, createBackdrop, createFrameGrade, ensureFxTextures, glowSprite, markDensity, screenDensity, shadowSprite };
@@ -0,0 +1 @@
1
+ import {d}from'../chunk-CJTRRUEK.js';import {h as h$1,g}from'../chunk-PYGRABBR.js';import M from'phaser';var v=2;function z(){let r=typeof devicePixelRatio=="number"&&devicePixelRatio>0?devicePixelRatio:1;return Math.min(2,Math.max(1,r))}function P(r){let e=r.scale.zoom;return e>0?1/e:1}function D(r,e){if(e===1)return;let t=r.source[0];t&&(t.resolution=e);for(let n of r.getFrameNames(true)){let i=r.get(n);i.data.sourceSize.w=i.cutWidth/e,i.data.sourceSize.h=i.cutHeight/e;}}var o={dot:"gfx:dot",spark:"gfx:spark",puff:"gfx:puff",chip:"gfx:chip",ring:"gfx:ring",star:"gfx:star",glow:"gfx:glow",shadow:"gfx:shadow",vignette:"gfx:vignette"},f=64,p=(r,e="255,255,255",t=1)=>(n,i)=>{let a=i/2,s=n.createRadialGradient(a,a,0,a,a,a*t);for(let[l,d]of r)s.addColorStop(l,`rgba(${e},${d})`);n.fillStyle=s,n.fillRect(0,0,i,i);},F={[o.dot]:[f,p([[0,1],[.25,.85],[.6,.22],[1,0]])],[o.spark]:[f,(r,e)=>{let t=e/2;p([[0,1],[.5,.25],[1,0]],"255,255,255",.55)(r,e),r.fillStyle="rgba(255,255,255,0.95)";for(let n of [0,Math.PI/2])r.save(),r.translate(t,t),r.rotate(n),r.beginPath(),r.moveTo(-t*.96,0),r.quadraticCurveTo(0,-t*.1,t*.96,0),r.quadraticCurveTo(0,t*.1,-t*.96,0),r.fill(),r.restore();}],[o.puff]:[f,p([[0,.7],[.55,.42],[1,0]])],[o.chip]:[f,(r,e)=>{let t=e/2;r.fillStyle="#ffffff",r.beginPath(),r.roundRect(t*.3,t*.55,t*1.4,t*.9,t*.14),r.fill();}],[o.ring]:[f,(r,e)=>{let t=e/2;r.strokeStyle="#ffffff",r.lineWidth=t*.16,r.beginPath(),r.arc(t,t,t*.8,0,Math.PI*2),r.stroke();}],[o.star]:[f,(r,e)=>{let t=e/2;r.fillStyle="#ffffff",r.beginPath();for(let n=0;n<10;n++){let i=n%2===0?t*.92:t*.4,a=-Math.PI/2+n*Math.PI/5;r.lineTo(t+Math.cos(a)*i,t+Math.sin(a)*i);}r.closePath(),r.fill();}],[o.glow]:[128,p([[0,.9],[.3,.45],[.65,.12],[1,0]])],[o.shadow]:[f,p([[0,.8],[.35,.6],[.7,.22],[1,0]],"29,42,107")],[o.vignette]:[256,p([[0,0],[.55,0],[.82,.32],[1,.85]],"6,8,24",1.42)]};function m(r){for(let e of Object.values(o)){if(r.textures.exists(e))continue;let[t,n]=F[e],i=r.textures.createCanvas(e,t,t);i&&(n(i.context,t),i.refresh());}}var h=class{constructor(e,t=66,n=1){this.scene=e;this.depth=t;this.amount=n,m(e);}scene;depth;emitters=new Map;shot={tint:16777215,speedMin:0,speedMax:0,size:1,sizeEnd:0,life:400,lifeSpread:0,angleMin:0,angleMax:360};amount;emitter(e,t,n){let i=`${e}|${t?1:0}|${n}`,a=this.emitters.get(i);if(a)return a;let s=this.shot,l=(d,c)=>d+Math.random()*(c-d);return a=this.scene.add.particles(0,0,e,{emitting:false,lifespan:{onEmit:()=>s.life+Math.random()*s.lifeSpread},speed:{onEmit:()=>l(s.speedMin,s.speedMax)},angle:{onEmit:()=>l(s.angleMin,s.angleMax)},scale:{onEmit:()=>s.size/f,onUpdate:(d,c,u)=>(s.size+(s.sizeEnd-s.size)*u)/f},alpha:{onEmit:()=>1,onUpdate:(d,c,u)=>u<.65?1:1-(u-.65)/.35},rotate:{onEmit:()=>Math.random()*360},tint:{onEmit:()=>s.tint},gravityY:n,blendMode:t?M.BlendModes.ADD:M.BlendModes.NORMAL}),a.setDepth(this.depth),this.emitters.set(i,a),a}many(e){return Math.max(1,Math.round(e*this.amount))}fire(e,t,n,i,a,s,l){Object.assign(this.shot,{angleMin:0,angleMax:360,lifeSpread:0},l),this.emitter(e,t,n).explode(s,i,a);}burst(e){let t=this.many(e.n??12),n=e.size??60,i={speedMin:n*1.6,speedMax:n*4.2};this.fire(o.dot,false,n*9,e.x,e.y,Math.ceil(t*.65),{...i,tint:e.color,size:n*.26,sizeEnd:n*.06,life:380,lifeSpread:260}),this.fire(o.spark,true,n*5,e.x,e.y,Math.ceil(t*.35),{...i,tint:e.color,size:n*.5,sizeEnd:0,life:320,lifeSpread:220}),this.fire(o.dot,true,0,e.x,e.y,1,{tint:e.color,speedMin:0,speedMax:0,size:n*.9,sizeEnd:n*2.4,life:200});}confetti(e){let t=this.many(e.n??36),n=e.size??120,i=Math.max(1,Math.round(t/Math.max(1,e.colors.length)));for(let a of e.colors)this.fire(o.chip,false,n*5,e.x,e.y,i,{tint:a,speedMin:n*1.5,speedMax:n*4.5,angleMin:200,angleMax:340,size:n*.2,sizeEnd:n*.16,life:1100,lifeSpread:700});}sparkle(e){let t=e.size??40;this.fire(o.spark,true,-t*.6,e.x,e.y,this.many(e.n??5),{tint:e.color,speedMin:t*.3,speedMax:t*1.2,size:t*.55,sizeEnd:0,life:420,lifeSpread:320});}dust(e){let t=e.size??40;this.fire(o.puff,false,-t*.4,e.x,e.y,this.many(e.n??4),{tint:e.color,speedMin:t*.4,speedMax:t*1.3,angleMin:180,angleMax:360,size:t*.5,sizeEnd:t*1.3,life:380,lifeSpread:240});}ring(e){let t=e.size??60;this.fire(o.ring,true,0,e.x,e.y,1,{tint:e.color,speedMin:0,speedMax:0,size:t*.35,sizeEnd:t*1.5,life:380});}destroy(){for(let e of this.emitters.values())e.destroy();this.emitters.clear();}};function E(r,e,t,n=9e3){m(r);let i=e.vignette>0?r.add.image(0,0,o.vignette).setDepth(n).setAlpha(Math.min(1,e.vignette*1.5)).setScrollFactor(0):null,a=r.cameras.main,s=null,l=c=>{if(c===!!s)return;let u=a.filters?.external;u&&(c?(s=u.addColorMatrix(),s.colorMatrix.saturate(e.saturation-1),s.colorMatrix.contrast(e.contrast-1,true)):s&&(u.remove(s),s=null));},d$1=null;return t.post&&(e.saturation!==1||e.contrast!==1)&&(l(true),d$1=new d([{name:"post",apply:()=>l(false),revert:()=>l(true)}])),{resize(c,u,S=c/2,g=u/2){i?.setPosition(S,g).setDisplaySize(c,u);},setFilter:l,frame(c){d$1?.frame(c);},destroy(){l(false),i?.destroy();}}}function T(r,e,t,n,i,a=.6){return m(r),r.add.image(e,t,o.glow).setDisplaySize(n,n).setTint(i).setAlpha(a).setBlendMode(M.BlendModes.ADD)}function k(r,e,t,n,i=.32){return m(r),r.add.image(e,t,o.shadow).setDisplaySize(n,n*.3).setAlpha(i)}function B(r,e,t=-1e5){let n=`gfx:backdrop:${e}`;if(!r.textures.exists(n)){let l=r.textures.createCanvas(n,64,256);if(l){let d=l.context,c=d.createLinearGradient(0,0,0,256);c.addColorStop(0,h$1(e,.3)),c.addColorStop(.45,e),c.addColorStop(1,g(e,.32)),d.fillStyle=c,d.fillRect(0,0,64,256);let u=d.createRadialGradient(64/2,0,0,64/2,0,256*.7);u.addColorStop(0,"rgba(255,255,255,0.2)"),u.addColorStop(1,"rgba(255,255,255,0)"),d.fillStyle=u,d.fillRect(0,0,64,256),l.refresh();}}let i=r.textures.exists(n)?r.add.image(0,0,n).setDepth(t).setScrollFactor(0):null;return {resize(a,s,l=a/2,d=s/2){i?.setPosition(l,d).setDisplaySize(a,s);},destroy(){i?.destroy();}}}export{o as FX,f as FX_SIZE,v as MAX_DENSITY,h as Particles2D,P as canvasDensity,B as createBackdrop,E as createFrameGrade,m as ensureFxTextures,T as glowSprite,D as markDensity,z as screenDensity,k as shadowSprite};
@@ -0,0 +1,140 @@
1
+ 'use strict';var u=require('three');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var u__namespace=/*#__PURE__*/_interopNamespace(u);function N(a,e,t,r=e.maxDensity){let i=typeof devicePixelRatio=="number"&&devicePixelRatio>0?devicePixelRatio:1,o=Math.max(1,Math.min(i,e.maxDensity,r));return a.setPixelRatio(o),a.outputColorSpace=u__namespace.SRGBColorSpace,a.toneMapping=u__namespace.NeutralToneMapping,a.toneMappingExposure=t.exposure,O(a,e),{density:o}}function j(a){let e=a.extensions;return e.has("EXT_color_buffer_float")||e.has("EXT_color_buffer_half_float")}function O(a,e){a.shadowMap.enabled=e.shadows!=="none",a.shadowMap.type=e.shadows!=="none"&&j(a)?u__namespace.VSMShadowMap:u__namespace.PCFShadowMap;}function U(a,e,t,r,i=t.shadowMap){e.castShadow=t.shadows!=="none",e.shadow.intensity=r,!(i<=0)&&(e.shadow.mapSize.set(i,i),a.shadowMap.type===u__namespace.VSMShadowMap?(e.shadow.radius=Math.max(3,Math.round(i/256)),e.shadow.blurSamples=8,e.shadow.bias=-8e-4,e.shadow.normalBias=.02):(e.shadow.radius=3,e.shadow.bias=-4e-4,e.shadow.normalBias=.03));}function V(a,e,t,r){let i=new u__namespace.HemisphereLight(e.ambientSky,e.ambientGround,e.ambientPower),o=new u__namespace.DirectionalLight(e.sun,e.sunPower),n=new u__namespace.Vector3(-0.5,1,-0.6).normalize();U(r,o,t,e.shadow),a.add(i,o,o.target);let s=0;return {hemi:i,sun:o,sunDir:n,setMood(l){i.color.set(l.ambientSky),i.groundColor.set(l.ambientGround),i.intensity=l.ambientPower,o.color.set(l.sun),o.intensity=l.sunPower,o.shadow.intensity=l.shadow;},aim(l,d){if(o.target.position.copy(l),o.position.copy(l).addScaledVector(n,d*1.2),d===s)return;s=d;let c=o.shadow.camera;c.left=c.bottom=-d/2,c.right=c.top=d/2,c.near=.5,c.far=d*3,c.updateProjectionMatrix();},setShadows(l){o.castShadow=l;},dispose(){a.remove(i,o,o.target),o.shadow.map?.dispose(),i.dispose(),o.dispose();}}}var W=`
2
+ varying vec3 vDir;
3
+ void main() {
4
+ vDir = position;
5
+ vec4 p = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
6
+ // on the far plane: everything of the world is drawn over it
7
+ gl_Position = p.xyww;
8
+ }
9
+ `,$=`
10
+ uniform vec3 uTop;
11
+ uniform vec3 uHorizon;
12
+ uniform vec3 uBottom;
13
+ uniform vec3 uSun;
14
+ uniform vec3 uSunDir;
15
+ uniform vec3 uCloud;
16
+ uniform float uClouds;
17
+ uniform float uStars;
18
+ uniform float uTime;
19
+ varying vec3 vDir;
20
+
21
+ #ifdef SKY_DETAIL
22
+ float hash(vec2 p) {
23
+ p = fract(p * vec2(123.34, 456.21));
24
+ p += dot(p, p + 45.32);
25
+ return fract(p.x * p.y);
26
+ }
27
+ float noise(vec2 p) {
28
+ vec2 i = floor(p);
29
+ vec2 f = fract(p);
30
+ vec2 u = f * f * (3.0 - 2.0 * f);
31
+ return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),
32
+ mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
33
+ }
34
+ #endif
35
+
36
+ void main() {
37
+ vec3 d = normalize(vDir);
38
+ float up = d.y;
39
+ // the horizon is a soft band: the zenith above it, the haze below
40
+ vec3 col = mix(uHorizon, uTop, pow(clamp(up, 0.0, 1.0), 0.55));
41
+ col = mix(col, uBottom, smoothstep(0.0, -0.35, up));
42
+
43
+ float s = max(dot(d, uSunDir), 0.0);
44
+ // a wide warm halo and a tight glow at the sun itself
45
+ col += uSun * (pow(s, 8.0) * 0.22 + pow(s, 96.0) * 0.9);
46
+
47
+ #ifdef SKY_DETAIL
48
+ if (uClouds > 0.0 && up > 0.02) {
49
+ vec2 p = d.xz / (up + 0.18) * 1.6 + vec2(uTime * 0.012, uTime * 0.004);
50
+ float n = noise(p) * 0.62 + noise(p * 2.3 + 7.1) * 0.38;
51
+ float c = smoothstep(1.0 - uClouds * 0.62, 1.0 - uClouds * 0.62 + 0.26, n);
52
+ // clouds thin out towards the horizon, lit by the sun's side
53
+ c *= smoothstep(0.02, 0.22, up);
54
+ col = mix(col, uCloud + uSun * pow(s, 6.0) * 0.25, c * 0.9);
55
+ }
56
+ if (uStars > 0.0 && up > 0.0) {
57
+ vec2 g = d.xz / (up + 0.4) * 46.0;
58
+ float h = hash(floor(g));
59
+ float tw = 0.6 + 0.4 * sin(uTime * 2.0 + h * 40.0);
60
+ float star = step(0.985, h) * smoothstep(0.5, 0.0, length(fract(g) - 0.5));
61
+ col += vec3(star * tw * uStars) * smoothstep(0.0, 0.3, up);
62
+ }
63
+ #endif
64
+
65
+ gl_FragColor = vec4(col, 1.0);
66
+ #include <tonemapping_fragment>
67
+ #include <colorspace_fragment>
68
+ }
69
+ `;function K(a,e){let t={uTop:{value:new u__namespace.Color},uHorizon:{value:new u__namespace.Color},uBottom:{value:new u__namespace.Color},uSun:{value:new u__namespace.Color},uSunDir:{value:new u__namespace.Vector3(-0.5,1,-0.6).normalize()},uCloud:{value:new u__namespace.Color},uClouds:{value:0},uStars:{value:0},uTime:{value:0}},r=new u__namespace.ShaderMaterial({uniforms:t,vertexShader:W,fragmentShader:$,defines:e?{SKY_DETAIL:1}:{},side:u__namespace.BackSide,depthWrite:false,depthTest:false,fog:false}),i=new u__namespace.SphereGeometry(1,24,12),o=new u__namespace.Mesh(i,r);o.frustumCulled=false,o.renderOrder=-1e3,o.matrixAutoUpdate=false;let n=s=>{t.uTop.value.set(s.skyTop),t.uHorizon.value.set(s.skyHorizon),t.uBottom.value.set(s.skyBottom),t.uSun.value.set(s.sun),t.uCloud.value.set(s.cloudColor),t.uClouds.value=s.clouds,t.uStars.value=s.stars;};return n(a),{object:o,setMood:n,setSun(s){t.uSunDir.value.copy(s).normalize();},update(s,l){t.uTime.value=l,o.matrix.makeTranslation(s.position.x,s.position.y,s.position.z),o.matrixWorldNeedsUpdate=true;},dispose(){i.dispose(),r.dispose();}}}var x=a=>Math.min(1,Math.max(0,a));function z(a){let e=/^#[0-9a-fA-F]{6}/.test(a)?a.slice(1,7):"ffffff";return [Number.parseInt(e.slice(0,2),16),Number.parseInt(e.slice(2,4),16),Number.parseInt(e.slice(4,6),16)]}var P=(a,e,t)=>`#${[a,e,t].map(r=>Math.round(Math.min(255,Math.max(0,r))).toString(16).padStart(2,"0")).join("")}`;function q(a){let[e,t,r]=z(a),i=e/255,o=t/255,n=r/255,s=Math.max(i,o,n),l=Math.min(i,o,n),d=(s+l)/2,c=s-l;if(c<1e-6)return [0,0,d];let E=c/(1-Math.abs(2*d-1)),v;return s===i?v=(o-n)/c%6:s===o?v=(n-i)/c+2:v=(i-o)/c+4,[(v*60+360)%360,x(E),d]}function C(a,e,t){let r=(a%360+360)%360,i=(1-Math.abs(2*t-1))*x(e),o=i*(1-Math.abs(r/60%2-1)),n=t-i/2,[s,l,d]=r<60?[i,o,0]:r<120?[o,i,0]:r<180?[0,i,o]:r<240?[0,o,i]:r<300?[o,0,i]:[i,0,o];return P((s+n)*255,(l+n)*255,(d+n)*255)}var _=.1;var Y=228;function X(a,e,t){let r=(e-a+540)%360-180;return a+Math.sign(r)*Math.min(Math.abs(r),t)}function A(a,e){let t=x(e);if(t===0)return P(...z(a));let[r,i,o]=q(a);if(o>.93||o<.08)return P(...z(a));if(i<_){let d=1-Math.abs(o-.5)/.43;return C(Y,.2*t*x(d*1.6),o)}let n=o>.52?o-(o-.52)*.7*t:o,s=x((i-_)/.25),l=x(i+(1-i)*.5*t*s);return r>62&&r<128?C(X(r,118,16*t),Math.min(l,Math.max(i,.58)),n):C(r,l,n)}var J={matte:{spec:0,gloss:8,rim:.15,emissive:0},plastic:{spec:.28,gloss:28,rim:1,emissive:0},glossy:{spec:.7,gloss:80,rim:1.15,emissive:0},glow:{spec:.2,gloss:28,rim:.6,emissive:.85}};function Q(a,e,t){a.onBeforeCompile=r=>{r.uniforms.uToyRim=e.uToyRim,r.uniforms.uToyRimPower=e.uToyRimPower,r.uniforms.uToySpec={value:t.spec},r.uniforms.uToyGloss={value:t.gloss},r.uniforms.uToyRimK={value:t.rim},r.fragmentShader=r.fragmentShader.replace("#include <common>",`#include <common>
70
+ uniform vec3 uToyRim;
71
+ uniform float uToyRimPower;
72
+ uniform float uToySpec;
73
+ uniform float uToyGloss;
74
+ uniform float uToyRimK;`).replace("#include <opaque_fragment>",`{
75
+ vec3 toyV = normalize(vViewPosition);
76
+ vec3 toyN = normalize(normal);
77
+ float toyF = 1.0 - saturate(dot(toyN, toyV));
78
+ // the sky lights from above: the rim is strongest on edges that face up
79
+ vec3 toyUp = normalize((viewMatrix * vec4(0.0, 1.0, 0.0, 0.0)).xyz);
80
+ float toySky = 0.35 + 0.65 * saturate(dot(toyN, toyUp) * 0.5 + 0.5);
81
+ outgoingLight += uToyRim * (toyF * toyF * toyF) * uToyRimPower * uToyRimK * toySky * diffuseColor.rgb;
82
+ #if NUM_DIR_LIGHTS > 0
83
+ vec3 toyH = normalize(directionalLights[0].direction + toyV);
84
+ // no highlight where the sun does not reach (a shadow, a back face)
85
+ float toyLit = saturate(dot(reflectedLight.directDiffuse, vec3(0.6)) * 4.0);
86
+ outgoingLight += directionalLights[0].color * pow(saturate(dot(toyN, toyH)), uToyGloss) * uToySpec * toyLit * 0.32;
87
+ #endif
88
+ }
89
+ #include <opaque_fragment>`);},a.customProgramCacheKey=()=>"idos-toy-1";}var L=class{cache=new Map;shared;vibrance;constructor(e){this.vibrance=e.vibrance,this.shared={uToyRim:{value:new u__namespace.Color(e.rim)},uToyRimPower:{value:e.rimPower}};}setMood(e){if(this.shared.uToyRim.value.set(e.rim),this.shared.uToyRimPower.value=e.rimPower,e.vibrance!==this.vibrance){this.vibrance=e.vibrance;for(let[t,r]of this.cache)r.color.set(A(t.slice(0,t.indexOf("|")),this.vibrance)),r.emissiveIntensity>0&&r.emissive.getHex()!==0&&r.emissive.copy(r.color);}}get(e,t={}){let r=t.finish??"plastic",i=t.alpha??1,o=`${e}|${r}|${i}|${t.flat?1:0}`,n=this.cache.get(o);return n||(n=this.make(e,t),this.cache.set(o,n)),n}make(e,t={}){let r=J[t.finish??"plastic"],i=t.alpha??1,o=new u__namespace.Color(t.map?e:A(e,this.vibrance)),n=new u__namespace.MeshLambertMaterial({color:o,transparent:i<1,opacity:i,depthWrite:i>=1,flatShading:!!t.flat,...t.map?{map:t.map}:{},...t.side===void 0?{}:{side:t.side},...t.alphaTest?{alphaTest:t.alphaTest}:{}});return r.emissive>0&&(n.emissive=o.clone(),n.emissiveIntensity=r.emissive),Q(n,this.shared,r),n}dispose(){for(let e of this.cache.values())e.dispose();this.cache.clear();}};var H=["dot","spark","puff","chip","ring","star"],g=64,b=null;function Z(){if(b)return b.users+=1,b.texture;let a=document.createElement("canvas");a.width=g*H.length,a.height=g;let e=a.getContext("2d"),t=g/2,r=(n,s)=>{e.save(),e.translate(n*g,0),e.beginPath(),e.rect(0,0,g,g),e.clip(),s(),e.restore();},i=(n,s=t)=>{let l=e.createRadialGradient(t,t,0,t,t,s);for(let[d,c]of n)l.addColorStop(d,`rgba(255,255,255,${c})`);e.fillStyle=l,e.fillRect(0,0,g,g);};r(0,()=>i([[0,1],[.25,.85],[.6,.22],[1,0]])),r(1,()=>{i([[0,1],[.5,.25],[1,0]],t*.55),e.fillStyle="rgba(255,255,255,0.95)";for(let n of [0,Math.PI/2])e.save(),e.translate(t,t),e.rotate(n),e.beginPath(),e.moveTo(-t*.96,0),e.quadraticCurveTo(0,-t*.1,t*.96,0),e.quadraticCurveTo(0,t*.1,-t*.96,0),e.fill(),e.restore();}),r(2,()=>i([[0,.7],[.55,.42],[1,0]])),r(3,()=>{e.fillStyle="#ffffff",e.beginPath(),e.roundRect(t*.3,t*.55,t*1.4,t*.9,t*.14),e.fill();}),r(4,()=>{e.strokeStyle="#ffffff",e.lineWidth=t*.16,e.beginPath(),e.arc(t,t,t*.8,0,Math.PI*2),e.stroke();}),r(5,()=>{e.fillStyle="#ffffff",e.beginPath();for(let n=0;n<10;n++){let s=n%2===0?t*.92:t*.4,l=-Math.PI/2+n*Math.PI/5;e.lineTo(t+Math.cos(l)*s,t+Math.sin(l)*s);}e.closePath(),e.fill();});let o=new u__namespace.CanvasTexture(a);return o.colorSpace=u__namespace.SRGBColorSpace,o.generateMipmaps=false,o.minFilter=u__namespace.LinearFilter,b={texture:o,users:1},o}function ee(){b&&(b.users-=1,!(b.users>0)&&(b.texture.dispose(),b=null));}var te=`
90
+ attribute vec3 iPos;
91
+ attribute vec4 iLook; // size, turn, sprite cell, additive (0 / 1)
92
+ attribute vec4 iColor; // rgb, alpha
93
+ uniform float uCells;
94
+ varying vec2 vUv;
95
+ varying vec4 vColor;
96
+ varying float vAdd;
97
+ void main() {
98
+ float cs = cos(iLook.y);
99
+ float sn = sin(iLook.y);
100
+ vec2 corner = position.xy * iLook.x;
101
+ corner = vec2(corner.x * cs - corner.y * sn, corner.x * sn + corner.y * cs);
102
+ vec4 mv = modelViewMatrix * vec4(iPos, 1.0);
103
+ mv.xy += corner;
104
+ gl_Position = projectionMatrix * mv;
105
+ vUv = vec2((uv.x + iLook.z) / uCells, uv.y);
106
+ vColor = iColor;
107
+ vAdd = iLook.w;
108
+ }
109
+ `,oe=`
110
+ uniform sampler2D uMap;
111
+ varying vec2 vUv;
112
+ varying vec4 vColor;
113
+ varying float vAdd;
114
+ void main() {
115
+ float a = texture2D(uMap, vUv).a * vColor.a;
116
+ if (a < 0.004) discard;
117
+ // premultiplied: an additive sprite adds its light and covers nothing
118
+ gl_FragColor = vec4(vColor.rgb * a, a * (1.0 - vAdd));
119
+ #include <tonemapping_fragment>
120
+ #include <colorspace_fragment>
121
+ }
122
+ `,M=class{object;capacity;geometry;material;pos;look;color;constructor(e,t=900){this.capacity=e;let r=new u__namespace.PlaneGeometry(1,1),i=new u__namespace.InstancedBufferGeometry;i.index=r.index,i.setAttribute("position",r.getAttribute("position")),i.setAttribute("uv",r.getAttribute("uv")),this.pos=new u__namespace.InstancedBufferAttribute(new Float32Array(e*3),3),this.look=new u__namespace.InstancedBufferAttribute(new Float32Array(e*4),4),this.color=new u__namespace.InstancedBufferAttribute(new Float32Array(e*4),4);for(let o of [this.pos,this.look,this.color])o.setUsage(u__namespace.DynamicDrawUsage);i.setAttribute("iPos",this.pos),i.setAttribute("iLook",this.look),i.setAttribute("iColor",this.color),i.instanceCount=0,this.geometry=i,this.material=new u__namespace.ShaderMaterial({uniforms:{uMap:{value:Z()},uCells:{value:H.length}},vertexShader:te,fragmentShader:oe,transparent:true,depthWrite:false,blending:u__namespace.CustomBlending,blendSrc:u__namespace.OneFactor,blendDst:u__namespace.OneMinusSrcAlphaFactor,blendSrcAlpha:u__namespace.OneFactor,blendDstAlpha:u__namespace.OneMinusSrcAlphaFactor,fog:false}),this.object=new u__namespace.Mesh(i,this.material),this.object.frustumCulled=false,this.object.renderOrder=t;}put(e,t,r,i,o,n,s,l,d,c,E,v){let h=this.pos.array,f=this.look.array,S=this.color.array;h[e*3]=t,h[e*3+1]=r,h[e*3+2]=i,f[e*4]=o,f[e*4+1]=n,f[e*4+2]=s,f[e*4+3]=l?1:0,S[e*4]=d,S[e*4+1]=c,S[e*4+2]=E,S[e*4+3]=v;}commit(e){this.geometry.instanceCount=e,this.object.visible=e>0,e!==0&&(this.pos.needsUpdate=true,this.look.needsUpdate=true,this.color.needsUpdate=true);}dispose(){this.geometry.dispose(),this.material.dispose(),ee();}},k=a=>H.indexOf(a);var R=16,I=class{object;sprites;data;flags;side;count=0;colors=new Map;amount;constructor(e=512,t=1){this.sprites=new M(e),this.object=this.sprites.object,this.data=new Float32Array(e*R),this.flags=new Uint8Array(e),this.side=new Float32Array(e*3),this.amount=t,this.sprites.commit(0);}get alive(){return this.count}color(e){let t=this.colors.get(e);return t||(t=new u__namespace.Color(e),this.colors.set(e,t)),t}spawn(e){if(this.count>=this.sprites.capacity)return;let t=this.count++,r=this.data,i=t*R,o=this.color(e.color);r[i]=e.x,r[i+1]=e.y,r[i+2]=e.z,r[i+3]=e.vx??0,r[i+4]=e.vy??0,r[i+5]=e.vz??0,r[i+6]=0,r[i+7]=e.life,r[i+8]=e.size,r[i+9]=e.sizeEnd??0,r[i+10]=Math.random()*Math.PI*2,r[i+11]=e.spin??0,r[i+12]=o.r,r[i+13]=o.g,r[i+14]=o.b,r[i+15]=e.alpha??1,this.side[t*3]=e.gravity??0,this.side[t*3+1]=e.drag??0,this.side[t*3+2]=e.floor??Number.NEGATIVE_INFINITY,this.flags[t]=k(e.sprite??"dot")|(e.additive?16:0);}many(e){return Math.max(1,Math.round(e*this.amount))}burst(e){let t=this.many(e.n??14),r=e.size??1.2;for(let i=0;i<t;i++){let o=Math.random()*Math.PI*2,n=r*(1.4+Math.random()*2.2),s=i%3===0;this.spawn({x:e.x,y:e.y,z:e.z,vx:Math.cos(o)*n,vy:r*(2+Math.random()*3.2),vz:Math.sin(o)*n,life:.45+Math.random()*.35,size:r*(s?.34:.2)*(.7+Math.random()*.6),color:e.color,sprite:s?"spark":"dot",additive:s,gravity:16,drag:1.2,spin:s?0:4});}this.spawn({x:e.x,y:e.y,z:e.z,life:.22,size:r*.7,sizeEnd:r*2.2,color:e.color,sprite:"dot",additive:true,alpha:.7});}confetti(e){let t=this.many(e.n??40),r=e.size??2;for(let i=0;i<t;i++){let o=Math.random()*Math.PI*2,n=r*(.6+Math.random()*1.6);this.spawn({x:e.x,y:e.y,z:e.z,vx:Math.cos(o)*n,vy:r*(3+Math.random()*3),vz:Math.sin(o)*n,life:1.3+Math.random()*.9,size:r*(.08+Math.random()*.06),sizeEnd:r*.07,color:e.colors[i%e.colors.length]??"#ffffff",sprite:"chip",gravity:r*3.5,drag:1.6,spin:(Math.random()-.5)*16});}}sparkle(e){let t=this.many(e.n??6),r=e.size??.6;for(let i=0;i<t;i++)this.spawn({x:e.x+(Math.random()-.5)*r,y:e.y+(Math.random()-.2)*r,z:e.z+(Math.random()-.5)*r,vy:.3+Math.random()*.5,life:.5+Math.random()*.4,size:r*(.35+Math.random()*.35),color:e.color,sprite:"spark",additive:true});}dust(e){let t=this.many(e.n??5),r=e.size??.6;for(let i=0;i<t;i++){let o=Math.random()*Math.PI*2;this.spawn({x:e.x,y:e.y+.05,z:e.z,vx:Math.cos(o)*r*1.6,vy:.4+Math.random()*.6,vz:Math.sin(o)*r*1.6,life:.45+Math.random()*.3,size:r*.5,sizeEnd:r*1.3,color:e.color,sprite:"puff",drag:3,alpha:.55});}}ring(e){let t=e.size??1.5;this.spawn({x:e.x,y:e.y,z:e.z,life:.4,size:t*.4,sizeEnd:t*1.9,color:e.color,sprite:"ring",additive:true});}update(e){if(this.count===0){this.sprites.commit(0);return}let t=this.data,r=this.side,i=0;for(;i<this.count;){let o=i*R,n=t[o+6]+e,s=t[o+7];if(n>=s){let f=--this.count;f!==i&&(t.copyWithin(o,f*R,f*R+R),r.copyWithin(i*3,f*3,f*3+3),this.flags[i]=this.flags[f]);continue}t[o+6]=n;let l=Math.max(0,1-r[i*3+1]*e);t[o+3]=t[o+3]*l,t[o+4]=(t[o+4]-r[i*3]*e)*l,t[o+5]=t[o+5]*l,t[o]=t[o]+t[o+3]*e,t[o+1]=t[o+1]+t[o+4]*e,t[o+2]=t[o+2]+t[o+5]*e;let d=r[i*3+2];t[o+1]<d&&(t[o+1]=d,t[o+4]=-t[o+4]*.35),t[o+10]=t[o+10]+t[o+11]*e;let c=n/s,E=t[o+8]+(t[o+9]-t[o+8])*c,v=c<.65?1:1-(c-.65)/.35,h=this.flags[i];this.sprites.put(i,t[o],t[o+1],t[o+2],E,t[o+10],h&15,(h&16)!==0,t[o+12],t[o+13],t[o+14],t[o+15]*v),i++;}this.sprites.commit(this.count);}clear(){this.count=0,this.sprites.commit(0);}dispose(){this.sprites.dispose();}},F=class{object;sprites;n=0;colors=new Map;constructor(e=256){this.sprites=new M(e,850),this.object=this.sprites.object,this.sprites.commit(0);}begin(){this.n=0;}add(e,t,r,i,o,n=.5){if(this.n>=this.sprites.capacity)return;let s=this.colors.get(o);s||(s=new u__namespace.Color(o),this.colors.set(o,s)),this.sprites.put(this.n++,e,t,r,i,0,0,true,s.r,s.g,s.b,n);}end(){this.sprites.commit(this.n);}dispose(){this.sprites.dispose();}};var D=class{object;texture;m=new u__namespace.Matrix4;n=0;constructor(e=256,t=.28){let r=document.createElement("canvas");r.width=r.height=64;let i=r.getContext("2d"),o=i.createRadialGradient(32,32,0,32,32,32);o.addColorStop(0,"rgba(0,0,0,1)"),o.addColorStop(.35,"rgba(0,0,0,0.75)"),o.addColorStop(.7,"rgba(0,0,0,0.25)"),o.addColorStop(1,"rgba(0,0,0,0)"),i.fillStyle=o,i.fillRect(0,0,64,64),this.texture=new u__namespace.CanvasTexture(r);let n=new u__namespace.MeshBasicMaterial({map:this.texture,color:"#1d2a6b",transparent:true,opacity:t,depthWrite:false,toneMapped:false,polygonOffset:true,polygonOffsetFactor:-2,polygonOffsetUnits:-2}),s=new u__namespace.PlaneGeometry(1,1).rotateX(-Math.PI/2);this.object=new u__namespace.InstancedMesh(s,n,e),this.object.frustumCulled=false,this.object.count=0,this.object.renderOrder=10;}begin(){this.n=0;}add(e,t,r,i,o=i){this.n>=this.object.instanceMatrix.count||(this.m.makeScale(i,1,o).setPosition(e,t+.02,r),this.object.setMatrixAt(this.n++,this.m));}end(){this.object.count=this.n,this.object.visible=this.n>0,this.n>0&&(this.object.instanceMatrix.needsUpdate=true);}dispose(){this.object.geometry.dispose(),this.object.material.dispose(),this.texture.dispose(),this.object.dispose();}};var G=64;function re(){return new u__namespace.ShaderMaterial({name:"SanitizeMaterial",uniforms:{inputBuffer:new u__namespace.Uniform(null)},vertexShader:`
123
+ varying vec2 vUv;
124
+ void main() {
125
+ vUv = position.xy * 0.5 + 0.5;
126
+ gl_Position = vec4(position.xy, 1.0, 1.0);
127
+ }
128
+ `,fragmentShader:`
129
+ uniform sampler2D inputBuffer;
130
+ varying vec2 vUv;
131
+ // NaN: nothing; +infinity (an overflowed highlight): as bright as kept; \u2212infinity: nothing
132
+ float finite(float v) {
133
+ return isnan(v) ? 0.0 : isinf(v) ? (v > 0.0 ? ${G.toFixed(1)} : 0.0) : v;
134
+ }
135
+ void main() {
136
+ vec4 c = texture2D(inputBuffer, vUv);
137
+ c = vec4(finite(c.r), finite(c.g), finite(c.b), finite(c.a));
138
+ gl_FragColor = vec4(clamp(c.rgb, 0.0, ${G.toFixed(1)}), clamp(c.a, 0.0, 1.0));
139
+ }
140
+ `,depthTest:false,depthWrite:false,toneMapped:false})}async function ie(a,e,t,r,i){if(!i.post)return null;try{let o=await import('postprocessing'),n=i.tier==="high",s=new o.EffectComposer(a,{frameBufferType:n?u__namespace.HalfFloatType:u__namespace.UnsignedByteType,multisampling:Math.min(i.msaa,a.capabilities.maxSamples??0)});s.addPass(new o.RenderPass(e,t)),n&&s.addPass(new o.ShaderPass(re(),"inputBuffer"));let l=new o.BloomEffect({mipmapBlur:!0,luminanceThreshold:r.bloomThreshold,luminanceSmoothing:.18,intensity:r.bloom,radius:.72,levels:n?6:4}),d=new o.ToneMappingEffect({mode:o.ToneMappingMode.NEUTRAL}),c=new o.HueSaturationEffect({saturation:r.saturation-1}),E=new o.BrightnessContrastEffect({contrast:r.contrast-1}),v=new o.VignetteEffect({offset:.32,darkness:r.vignette});return s.addPass(new o.EffectPass(t,l,d,c,E,v)),{render(h){s.render(h);},setSize(h,f){s.setSize(h,f,!1);},setMood(h){l.intensity=h.bloom,l.luminanceMaterial.threshold=h.bloomThreshold,c.saturation=h.saturation-1,E.contrast=h.contrast-1,v.darkness=h.vignette;},dispose(){s.dispose();}}}catch{return null}}exports.Billboards=M;exports.BlobShadows=D;exports.Halos=F;exports.Particles=I;exports.SPRITES=H;exports.ToyLook=L;exports.createLightRig=V;exports.createPostChain=ie;exports.createSky=K;exports.setupRenderer=N;exports.setupShadowMap=O;exports.setupSunShadow=U;exports.softShadowsSupported=j;exports.spriteIndex=k;
@@ -0,0 +1,228 @@
1
+ import * as THREE from 'three';
2
+ import { c as Mood, e as TierSettings } from '../moods-CROfsmd7.cjs';
3
+
4
+ interface RendererSetup {
5
+ /** Canvas pixels per CSS pixel the renderer was set to. */
6
+ readonly density: number;
7
+ }
8
+ /**
9
+ * Colour space, tone mapping, canvas density and the shadow map for a tier and a mood.
10
+ * `maxDensity` lowers the tier's cap (a game that knows it is heavy).
11
+ */
12
+ declare function setupRenderer(renderer: THREE.WebGLRenderer, tier: TierSettings, mood: Mood, maxDensity?: number): RendererSetup;
13
+ /**
14
+ * Can the GPU draw the soft shadow: a variance map is drawn into a half-float target. Nearly every
15
+ * phone with WebGL2 can; one that cannot gets PCF, a tighter edge but the same lightness.
16
+ */
17
+ declare function softShadowsSupported(renderer: THREE.WebGLRenderer): boolean;
18
+ /**
19
+ * The shadow map of the standard: soft and light, like a casual game's. The edge is a blurred variance
20
+ * map (VSM), not PCF: PCF in three takes five samples, so a wide edge of it is grainy, and a narrow one
21
+ * is the hard dark shadow that makes a toy scene look like a render. With VSM every receiver also
22
+ * casts: a see-through thing must not receive (see the views).
23
+ */
24
+ declare function setupShadowMap(renderer: THREE.WebGLRenderer, tier: TierSettings): void;
25
+ /**
26
+ * The sun's shadow for a tier: the map's size, the soft edge and how dark it is (`strength`, the mood's
27
+ * `shadow`). `mapSize` overrides the tier's map. The edge is about the same width in metres on every
28
+ * tier: a finer map blurs over more of its pixels.
29
+ */
30
+ declare function setupSunShadow(renderer: THREE.WebGLRenderer, sun: THREE.DirectionalLight, tier: TierSettings, strength: number, mapSize?: number): void;
31
+ interface LightRig {
32
+ readonly hemi: THREE.HemisphereLight;
33
+ readonly sun: THREE.DirectionalLight;
34
+ /** Where the sun shines FROM (unit vector, world space). */
35
+ readonly sunDir: THREE.Vector3;
36
+ setMood(mood: Mood): void;
37
+ /** The shadow box: `size` metres around `target` (call when the camera's target moves). */
38
+ aim(target: THREE.Vector3, size: number): void;
39
+ /** The shadow map on or off (a slow device gives it up). */
40
+ setShadows(on: boolean): void;
41
+ dispose(): void;
42
+ }
43
+ /** The sun and the sky's light. Added to `scene`; the sun casts the shadow by the tier. */
44
+ declare function createLightRig(scene: THREE.Scene, mood: Mood, tier: TierSettings, renderer: THREE.WebGLRenderer): LightRig;
45
+
46
+ interface Sky {
47
+ readonly object: THREE.Mesh;
48
+ setMood(mood: Mood): void;
49
+ /** Where the sun shines FROM (unit vector, world space). */
50
+ setSun(dir: THREE.Vector3): void;
51
+ /** Once a frame: the dome follows the camera, the clouds drift. */
52
+ update(camera: THREE.Camera, time: number): void;
53
+ dispose(): void;
54
+ }
55
+ declare function createSky(mood: Mood, detail: boolean): Sky;
56
+
57
+ type ToyFinish = "matte" | "plastic" | "glossy" | "glow";
58
+ interface ToyOptions {
59
+ readonly finish?: ToyFinish;
60
+ readonly alpha?: number;
61
+ readonly flat?: boolean;
62
+ /** The colour comes from a map or instance colours as well (the paint stays white). */
63
+ readonly map?: THREE.Texture | null;
64
+ readonly side?: THREE.Side;
65
+ readonly alphaTest?: number;
66
+ }
67
+ /**
68
+ * The toy materials of one scene: cached by colour, finish and alpha, all sharing the mood's rim light.
69
+ * `get` returns a shared material: do not change it, ask for another one.
70
+ */
71
+ declare class ToyLook {
72
+ private readonly cache;
73
+ private readonly shared;
74
+ private vibrance;
75
+ constructor(mood: Mood);
76
+ setMood(mood: Mood): void;
77
+ /** A cached material of a colour (#hex). */
78
+ get(hex: string, options?: ToyOptions): THREE.MeshLambertMaterial;
79
+ /** A material of its own (not cached): the caller owns and disposes it. */
80
+ make(hex: string, options?: ToyOptions): THREE.MeshLambertMaterial;
81
+ dispose(): void;
82
+ }
83
+
84
+ /** Cells of the atlas, left to right. */
85
+ declare const SPRITES: readonly ["dot", "spark", "puff", "chip", "ring", "star"];
86
+ type SpriteName = (typeof SPRITES)[number];
87
+ /**
88
+ * A fixed pool of sprites. Fill slots with `put`, say how many are live with `commit`: the mesh draws
89
+ * the first `count` of them in one call.
90
+ */
91
+ declare class Billboards {
92
+ readonly object: THREE.Mesh;
93
+ readonly capacity: number;
94
+ private readonly geometry;
95
+ private readonly material;
96
+ private readonly pos;
97
+ private readonly look;
98
+ private readonly color;
99
+ constructor(capacity: number, renderOrder?: number);
100
+ /** Writes slot `i`. `color` is linear RGB (a THREE.Color's r, g, b). */
101
+ put(i: number, x: number, y: number, z: number, size: number, turn: number, sprite: number, additive: boolean, r: number, g: number, b: number, alpha: number): void;
102
+ /** The first `count` slots are drawn; the buffers are uploaded only when something is live. */
103
+ commit(count: number): void;
104
+ dispose(): void;
105
+ }
106
+ declare const spriteIndex: (name: SpriteName) => number;
107
+
108
+ interface ParticleSpawn {
109
+ x: number;
110
+ y: number;
111
+ z: number;
112
+ vx?: number;
113
+ vy?: number;
114
+ vz?: number;
115
+ /** Seconds it lives. */
116
+ life: number;
117
+ /** Size in metres at birth and at death (default: shrinks to nothing). */
118
+ size: number;
119
+ sizeEnd?: number;
120
+ color: string;
121
+ sprite?: SpriteName;
122
+ /** Adds its light instead of covering (a spark, a glint). */
123
+ additive?: boolean;
124
+ /** Metres per second² down (default 0). */
125
+ gravity?: number;
126
+ /** Share of speed lost per second (0 = none). */
127
+ drag?: number;
128
+ /** Radians per second. */
129
+ spin?: number;
130
+ alpha?: number;
131
+ /** The floor it bounces off a little (none by default). */
132
+ floor?: number;
133
+ }
134
+ interface BurstOptions {
135
+ x: number;
136
+ y: number;
137
+ z: number;
138
+ color: string;
139
+ /** How many (default 14). */
140
+ n?: number;
141
+ /** How far they fly, metres (default 1.2). */
142
+ size?: number;
143
+ }
144
+ declare class Particles {
145
+ readonly object: THREE.Mesh;
146
+ private readonly sprites;
147
+ private readonly data;
148
+ private readonly flags;
149
+ /** Gravity, drag and the floor of every slot. */
150
+ private readonly side;
151
+ private count;
152
+ private readonly colors;
153
+ /** Share of a burst's particles really emitted (the tier's). */
154
+ amount: number;
155
+ constructor(capacity?: number, amount?: number);
156
+ get alive(): number;
157
+ private color;
158
+ spawn(p: ParticleSpawn): void;
159
+ private many;
160
+ /** Bright pieces flying out of a point and falling: a hit, a pickup, a thing breaking. */
161
+ burst(o: BurstOptions): void;
162
+ /** Paper pieces of many colours thrown up and fluttering down: a win. */
163
+ confetti(o: {
164
+ x: number;
165
+ y: number;
166
+ z: number;
167
+ colors: readonly string[];
168
+ n?: number;
169
+ size?: number;
170
+ }): void;
171
+ /** Glints twinkling around a point: a thing worth taking, a reward. */
172
+ sparkle(o: BurstOptions): void;
173
+ /** A low cloud kicked up from the ground: a landing, a skid, running feet. */
174
+ dust(o: BurstOptions): void;
175
+ /** A ring spreading over the ground: a shock wave, a landing, a thing being placed. */
176
+ ring(o: BurstOptions): void;
177
+ /** Once a frame. */
178
+ update(dt: number): void;
179
+ clear(): void;
180
+ dispose(): void;
181
+ }
182
+ /**
183
+ * Glow halos: a soft light around every thing that shines (a coin, a gem, a lamp), placed anew every
184
+ * frame (`begin`, `add`…, `end`). One draw call for all of them. It is the glow of the low tier, and
185
+ * under the post chain's bloom it makes the shining things bloom harder.
186
+ */
187
+ declare class Halos {
188
+ readonly object: THREE.Mesh;
189
+ private readonly sprites;
190
+ private n;
191
+ private readonly colors;
192
+ constructor(capacity?: number);
193
+ begin(): void;
194
+ /** A soft light of a colour around a point (`size` metres across). */
195
+ add(x: number, y: number, z: number, size: number, hex: string, alpha?: number): void;
196
+ end(): void;
197
+ dispose(): void;
198
+ }
199
+
200
+ declare class BlobShadows {
201
+ readonly object: THREE.InstancedMesh;
202
+ private readonly texture;
203
+ private readonly m;
204
+ private n;
205
+ constructor(capacity?: number, opacity?: number);
206
+ begin(): void;
207
+ /** A spot `w` × `d` metres at (x, y, z); `y` is the ground under the thing. */
208
+ add(x: number, y: number, z: number, w: number, d?: number): void;
209
+ end(): void;
210
+ dispose(): void;
211
+ }
212
+
213
+ interface PostChain {
214
+ /** Draws the scene through the chain to the screen. */
215
+ render(dt: number): void;
216
+ setSize(width: number, height: number): void;
217
+ setMood(mood: Mood): void;
218
+ dispose(): void;
219
+ }
220
+ /**
221
+ * Builds the chain for a scene and a camera. Resolves to null when it cannot be built; the caller then
222
+ * keeps drawing with `renderer.render`. The renderer's own tone mapping is left as it is: three applies
223
+ * it only to a frame drawn straight to the screen, so the chain maps the tones itself (after the glow),
224
+ * and a caller that stops using the chain (a slow device) gets its tone mapping back with no switch.
225
+ */
226
+ declare function createPostChain(renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera, mood: Mood, tier: TierSettings): Promise<PostChain | null>;
227
+
228
+ export { Billboards, BlobShadows, type BurstOptions, Halos, type LightRig, type ParticleSpawn, Particles, type PostChain, type RendererSetup, SPRITES, type Sky, type SpriteName, type ToyFinish, ToyLook, type ToyOptions, createLightRig, createPostChain, createSky, setupRenderer, setupShadowMap, setupSunShadow, softShadowsSupported, spriteIndex };