@guilhermebkel/scenec 0.2.0 → 0.2.2
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.
- package/README.md +23 -12
- package/dist/Adapters/FontAdapter.js +5 -1
- package/dist/Commands/BestCommand.d.ts +11 -0
- package/dist/Commands/BestCommand.js +73 -0
- package/dist/Commands/RenderCommand.d.ts +2 -0
- package/dist/Commands/RenderCommand.js +7 -0
- package/dist/Modules/BestModule.d.ts +41 -0
- package/dist/Modules/BestModule.js +159 -0
- package/dist/Modules/CompilationModule.d.ts +5 -0
- package/dist/Modules/CompilationModule.js +92 -19
- package/dist/Modules/CritiqueModule.d.ts +3 -0
- package/dist/Modules/CritiqueModule.js +60 -5
- package/dist/Protocols/AssetProtocol.d.ts +6 -1
- package/dist/Protocols/AssetProtocol.js +17 -1
- package/dist/Protocols/CommandProtocol.d.ts +2 -0
- package/dist/Protocols/CompilationProtocol.d.ts +27 -1
- package/dist/Protocols/CritiqueProtocol.d.ts +17 -1
- package/dist/Protocols/CritiqueProtocol.js +11 -1
- package/dist/Protocols/KitProtocol.d.ts +8 -2
- package/dist/Protocols/KitProtocol.js +8 -2
- package/dist/Protocols/PersonProtocol.d.ts +4 -0
- package/dist/Protocols/PersonProtocol.js +2 -0
- package/dist/Protocols/SceneProtocol.d.ts +204 -5
- package/dist/Protocols/SceneProtocol.js +60 -7
- package/dist/Resources/Assets/BaseAsset.d.ts +1 -0
- package/dist/Resources/Assets/BaseAsset.js +1 -0
- package/dist/Resources/Assets/BigPlantAsset.js +8 -1
- package/dist/Resources/Assets/BlackboardAsset.d.ts +11 -0
- package/dist/Resources/Assets/BlackboardAsset.js +20 -0
- package/dist/Resources/Assets/BushAsset.js +1 -1
- package/dist/Resources/Assets/ChairAsset.d.ts +5 -0
- package/dist/Resources/Assets/ChairAsset.js +23 -0
- package/dist/Resources/Assets/ChatBubbleAsset.d.ts +11 -0
- package/dist/Resources/Assets/ChatBubbleAsset.js +18 -0
- package/dist/Resources/Assets/CloudAsset.js +3 -1
- package/dist/Resources/Assets/ConfettiAsset.d.ts +10 -0
- package/dist/Resources/Assets/ConfettiAsset.js +18 -0
- package/dist/Resources/Assets/CursorAsset.d.ts +11 -0
- package/dist/Resources/Assets/CursorAsset.js +17 -0
- package/dist/Resources/Assets/DeskAsset.js +7 -2
- package/dist/Resources/Assets/FirstAidKitAsset.d.ts +10 -0
- package/dist/Resources/Assets/FirstAidKitAsset.js +19 -0
- package/dist/Resources/Assets/GlobeAsset.d.ts +10 -0
- package/dist/Resources/Assets/GlobeAsset.js +18 -0
- package/dist/Resources/Assets/HouseAsset.js +22 -6
- package/dist/Resources/Assets/LaptopAsset.js +5 -1
- package/dist/Resources/Assets/PlantAsset.js +1 -1
- package/dist/Resources/Assets/PodiumAsset.d.ts +11 -0
- package/dist/Resources/Assets/PodiumAsset.js +20 -0
- package/dist/Resources/Assets/RefrigeratorAsset.d.ts +11 -0
- package/dist/Resources/Assets/RefrigeratorAsset.js +21 -0
- package/dist/Resources/Assets/SinkAsset.d.ts +11 -0
- package/dist/Resources/Assets/SinkAsset.js +21 -0
- package/dist/Resources/Assets/SofaAsset.d.ts +5 -0
- package/dist/Resources/Assets/SofaAsset.js +30 -2
- package/dist/Resources/Assets/StarsAsset.d.ts +6 -0
- package/dist/Resources/Assets/StarsAsset.js +37 -24
- package/dist/Resources/Assets/StethoscopeAsset.d.ts +10 -0
- package/dist/Resources/Assets/StethoscopeAsset.js +18 -0
- package/dist/Resources/Assets/StoveAsset.d.ts +11 -0
- package/dist/Resources/Assets/StoveAsset.js +20 -0
- package/dist/Resources/Assets/ToggleAsset.d.ts +11 -0
- package/dist/Resources/Assets/ToggleAsset.js +21 -0
- package/dist/Resources/Assets/TreeAsset.d.ts +5 -0
- package/dist/Resources/Assets/TreeAsset.js +32 -7
- package/dist/Resources/Assets/WaterCoolerAsset.d.ts +11 -0
- package/dist/Resources/Assets/WaterCoolerAsset.js +20 -0
- package/dist/Resources/Assets/WhiteboardAsset.d.ts +10 -0
- package/dist/Resources/Assets/WhiteboardAsset.js +18 -0
- package/dist/Resources/Kits/BaseKit.d.ts +2 -1
- package/dist/Resources/Kits/BaseKit.js +1 -0
- package/dist/Resources/Kits/ClayKit.d.ts +9 -0
- package/dist/Resources/Kits/ClayKit.js +11 -0
- package/dist/Resources/Kits/DuotoneKit.d.ts +16 -0
- package/dist/Resources/Kits/DuotoneKit.js +18 -0
- package/dist/Resources/Kits/IsometricKit.d.ts +8 -0
- package/dist/Resources/Kits/IsometricKit.js +10 -0
- package/dist/Resources/Kits/OutlineKit.d.ts +3 -0
- package/dist/Resources/Kits/OutlineKit.js +1 -1
- package/dist/Resources/Kits/PaperKit.d.ts +2 -0
- package/dist/Resources/Kits/PaperKit.js +1 -0
- package/dist/Resources/Kits/PosterKit.d.ts +14 -0
- package/dist/Resources/Kits/PosterKit.js +16 -0
- package/dist/Resources/Kits/SketchKit.d.ts +2 -1
- package/dist/Resources/Kits/SketchKit.js +1 -0
- package/dist/Services/AssetService.js +29 -1
- package/dist/Services/BackgroundService.d.ts +10 -2
- package/dist/Services/BackgroundService.js +52 -11
- package/dist/Services/CatalogService.d.ts +1 -0
- package/dist/Services/CatalogService.js +8 -3
- package/dist/Services/ColorCritiqueService.d.ts +42 -0
- package/dist/Services/ColorCritiqueService.js +232 -0
- package/dist/Services/ContextService.js +9 -5
- package/dist/Services/DescriptionService.d.ts +2 -1
- package/dist/Services/DescriptionService.js +8 -2
- package/dist/Services/DetailService.d.ts +7 -0
- package/dist/Services/DetailService.js +18 -0
- package/dist/Services/FocusCritiqueService.d.ts +23 -0
- package/dist/Services/FocusCritiqueService.js +166 -0
- package/dist/Services/FramingService.d.ts +31 -0
- package/dist/Services/FramingService.js +108 -0
- package/dist/Services/GazeService.js +3 -1
- package/dist/Services/GroundDetailService.d.ts +50 -0
- package/dist/Services/GroundDetailService.js +115 -0
- package/dist/Services/KitService.d.ts +11 -2
- package/dist/Services/KitService.js +45 -10
- package/dist/Services/LightingService.d.ts +15 -0
- package/dist/Services/LightingService.js +124 -6
- package/dist/Services/PaletteService.d.ts +108 -0
- package/dist/Services/PaletteService.js +282 -0
- package/dist/Services/PieceService.d.ts +4 -0
- package/dist/Services/PieceService.js +28 -7
- package/dist/Services/PlacementService.js +7 -1
- package/dist/Services/PlaneBackgroundService.d.ts +4 -0
- package/dist/Services/PlaneBackgroundService.js +42 -3
- package/dist/Services/PlaneProjectionService.d.ts +4 -0
- package/dist/Services/PlaneProjectionService.js +33 -4
- package/dist/Services/RasterService.js +20 -3
- package/dist/Services/RidgeService.d.ts +31 -0
- package/dist/Services/RidgeService.js +85 -0
- package/dist/Services/ScaleCritiqueService.d.ts +11 -0
- package/dist/Services/ScaleCritiqueService.js +57 -0
- package/dist/Services/SkyDetailService.d.ts +39 -0
- package/dist/Services/SkyDetailService.js +95 -0
- package/dist/Services/{ContactCritiqueService.d.ts → TangentCritiqueService.d.ts} +10 -6
- package/dist/Services/TangentCritiqueService.js +136 -0
- package/dist/Services/TextService.d.ts +43 -3
- package/dist/Services/TextService.js +288 -32
- package/dist/Services/ThumbnailCritiqueService.d.ts +30 -0
- package/dist/Services/ThumbnailCritiqueService.js +130 -0
- package/dist/Utils/ColorUtil.d.ts +14 -0
- package/dist/Utils/ColorUtil.js +68 -5
- package/dist/Utils/DetailUtil.d.ts +7 -0
- package/dist/Utils/DetailUtil.js +15 -0
- package/dist/Utils/FontMetricsUtil.d.ts +7 -0
- package/dist/Utils/FontMetricsUtil.js +694 -0
- package/dist/Utils/OklabUtil.d.ts +18 -0
- package/dist/Utils/OklabUtil.js +89 -0
- package/dist/Utils/PersonArmUtil.d.ts +13 -1
- package/dist/Utils/PersonArmUtil.js +53 -5
- package/dist/Utils/PersonHeadUtil.js +3 -1
- package/dist/Utils/PersonOutfitUtil.d.ts +16 -0
- package/dist/Utils/PersonOutfitUtil.js +89 -13
- package/dist/Utils/PersonUtil.d.ts +2 -0
- package/dist/Utils/PersonUtil.js +14 -4
- package/dist/Utils/SanitizeUtil.js +1 -0
- package/dist/Utils/ShapeUtil.d.ts +9 -0
- package/dist/Utils/ShapeUtil.js +26 -0
- package/dist/Utils/TypesettingUtil.d.ts +17 -0
- package/dist/Utils/TypesettingUtil.js +92 -0
- package/dist/cli.js +32 -3
- package/dist/render.d.ts +3 -1
- package/dist/render.js +5 -0
- package/fonts/DMSerifDisplay-Regular.ttf +0 -0
- package/fonts/OFL.txt +2 -0
- package/fonts/PatrickHand-Regular.ttf +0 -0
- package/package.json +1 -1
- package/skills/draw-scene/SKILL.md +2 -1
- package/skills/draw-scene/recipes/carousel.yaml +1 -1
- package/skills/draw-scene/recipes/conference-keynote.yaml +43 -0
- package/skills/draw-scene/recipes/product-feature.yaml +41 -0
- package/skills/draw-scene/recipes/product-illustration.yaml +2 -1
- package/skills/draw-scene/references/catalog.md +19 -1
- package/skills/draw-scene/references/dsl.md +24 -6
- package/dist/Services/ContactCritiqueService.js +0 -101
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Placement } from "../Protocols/CompilationProtocol.js";
|
|
2
|
+
import type { GroundDetail } from "../Protocols/SceneProtocol.js";
|
|
3
|
+
import type { Theme } from "../Protocols/ThemeProtocol.js";
|
|
4
|
+
export interface GroundDetailOptions {
|
|
5
|
+
detail?: GroundDetail;
|
|
6
|
+
seed: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
horizonY: number;
|
|
10
|
+
theme: Theme;
|
|
11
|
+
placements?: readonly Placement[];
|
|
12
|
+
isPathBlocked?: (x: number, y: number) => boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class GroundDetailService {
|
|
15
|
+
private static readonly LOW_COUNT;
|
|
16
|
+
private static readonly HIGH_COUNT;
|
|
17
|
+
private static readonly BLOB_COUNT;
|
|
18
|
+
private static readonly SEED_STEP;
|
|
19
|
+
private static readonly BLOB_SEED_STEP;
|
|
20
|
+
private static readonly DETAIL_TO_COUNT;
|
|
21
|
+
private static readonly FAR_SHADE;
|
|
22
|
+
private static readonly NEAR_SHADE;
|
|
23
|
+
private static readonly BLOB_SHADE_POS;
|
|
24
|
+
private static readonly BLOB_SHADE_NEG;
|
|
25
|
+
private static readonly BLOB_OPACITY;
|
|
26
|
+
private static readonly FOOT_PADDING_X;
|
|
27
|
+
private static readonly FOOT_PADDING_Y;
|
|
28
|
+
private static readonly CYCLE_PEBBLE;
|
|
29
|
+
private static readonly BLOB_X_MIN;
|
|
30
|
+
private static readonly BLOB_X_SPAN;
|
|
31
|
+
private static readonly BLOB_Y_MIN;
|
|
32
|
+
private static readonly BLOB_Y_SPAN;
|
|
33
|
+
private static readonly BLOB_RX_MIN;
|
|
34
|
+
private static readonly BLOB_RX_SPAN;
|
|
35
|
+
private static readonly BLOB_RY_MIN;
|
|
36
|
+
private static readonly BLOB_RY_SPAN;
|
|
37
|
+
private static readonly TUFT_SHADE;
|
|
38
|
+
private static readonly TUFT_X_MIN;
|
|
39
|
+
private static readonly TUFT_X_SPAN;
|
|
40
|
+
private static readonly TUFT_EXPONENT;
|
|
41
|
+
private static readonly TUFT_RATIO_SCALE;
|
|
42
|
+
private static readonly TUFT_RATIO_MIN;
|
|
43
|
+
private static readonly TUFT_SCALE_BASE;
|
|
44
|
+
private static readonly TUFT_SCALE_SPAN;
|
|
45
|
+
static groundGradientDef(theme: Theme): string;
|
|
46
|
+
static draw(options: GroundDetailOptions): string;
|
|
47
|
+
private static drawBlobs;
|
|
48
|
+
private static drawTufts;
|
|
49
|
+
private static isNearFeet;
|
|
50
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ColorUtil } from "../Utils/ColorUtil.js";
|
|
2
|
+
import { SeedUtil } from "../Utils/SeedUtil.js";
|
|
3
|
+
class GroundDetailService {
|
|
4
|
+
static LOW_COUNT = 14;
|
|
5
|
+
static HIGH_COUNT = 32;
|
|
6
|
+
static BLOB_COUNT = 3;
|
|
7
|
+
static SEED_STEP = 53;
|
|
8
|
+
static BLOB_SEED_STEP = 97;
|
|
9
|
+
static DETAIL_TO_COUNT = {
|
|
10
|
+
none: 0,
|
|
11
|
+
low: GroundDetailService.LOW_COUNT,
|
|
12
|
+
high: GroundDetailService.HIGH_COUNT
|
|
13
|
+
};
|
|
14
|
+
static FAR_SHADE = 0.14;
|
|
15
|
+
static NEAR_SHADE = -0.06;
|
|
16
|
+
static BLOB_SHADE_POS = 0.04;
|
|
17
|
+
static BLOB_SHADE_NEG = -0.04;
|
|
18
|
+
static BLOB_OPACITY = 0.35;
|
|
19
|
+
static FOOT_PADDING_X = 12;
|
|
20
|
+
static FOOT_PADDING_Y = 14;
|
|
21
|
+
static CYCLE_PEBBLE = 4;
|
|
22
|
+
static BLOB_X_MIN = 0.15;
|
|
23
|
+
static BLOB_X_SPAN = 0.7;
|
|
24
|
+
static BLOB_Y_MIN = 0.2;
|
|
25
|
+
static BLOB_Y_SPAN = 0.6;
|
|
26
|
+
static BLOB_RX_MIN = 0.08;
|
|
27
|
+
static BLOB_RX_SPAN = 0.08;
|
|
28
|
+
static BLOB_RY_MIN = 0.08;
|
|
29
|
+
static BLOB_RY_SPAN = 0.08;
|
|
30
|
+
static TUFT_SHADE = -0.15;
|
|
31
|
+
static TUFT_X_MIN = 0.04;
|
|
32
|
+
static TUFT_X_SPAN = 0.92;
|
|
33
|
+
static TUFT_EXPONENT = 0.65;
|
|
34
|
+
static TUFT_RATIO_SCALE = 0.88;
|
|
35
|
+
static TUFT_RATIO_MIN = 0.1;
|
|
36
|
+
static TUFT_SCALE_BASE = 0.35;
|
|
37
|
+
static TUFT_SCALE_SPAN = 0.65;
|
|
38
|
+
static groundGradientDef(theme) {
|
|
39
|
+
const farColor = ColorUtil.sh(theme.ground, GroundDetailService.FAR_SHADE);
|
|
40
|
+
const nearColor = ColorUtil.sh(theme.ground, GroundDetailService.NEAR_SHADE);
|
|
41
|
+
return `<linearGradient id="ground" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="${farColor}"/><stop offset="1" stop-color="${nearColor}"/></linearGradient>`;
|
|
42
|
+
}
|
|
43
|
+
static draw(options) {
|
|
44
|
+
const { detail = "low", seed, width, height, horizonY, theme, placements = [], isPathBlocked } = options;
|
|
45
|
+
const count = GroundDetailService.DETAIL_TO_COUNT[detail];
|
|
46
|
+
if (count <= 0) {
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
const blobs = GroundDetailService.drawBlobs({ seed, width, height, horizonY, theme });
|
|
50
|
+
const tufts = GroundDetailService.drawTufts({
|
|
51
|
+
count,
|
|
52
|
+
seed,
|
|
53
|
+
width,
|
|
54
|
+
height,
|
|
55
|
+
horizonY,
|
|
56
|
+
theme,
|
|
57
|
+
placements,
|
|
58
|
+
isPathBlocked
|
|
59
|
+
});
|
|
60
|
+
return blobs + tufts;
|
|
61
|
+
}
|
|
62
|
+
static drawBlobs(parts) {
|
|
63
|
+
const { seed, width, height, horizonY, theme } = parts;
|
|
64
|
+
const groundHeight = height - horizonY;
|
|
65
|
+
let svg = "";
|
|
66
|
+
for (let index = 0; index < GroundDetailService.BLOB_COUNT; index++) {
|
|
67
|
+
const random = SeedUtil.sequence(seed + index * GroundDetailService.BLOB_SEED_STEP);
|
|
68
|
+
const posX = (GroundDetailService.BLOB_X_MIN + random() * GroundDetailService.BLOB_X_SPAN) * width;
|
|
69
|
+
const blobYRatio = GroundDetailService.BLOB_Y_MIN + random() * GroundDetailService.BLOB_Y_SPAN;
|
|
70
|
+
const posY = horizonY + blobYRatio * groundHeight;
|
|
71
|
+
const radiusX = width * (GroundDetailService.BLOB_RX_MIN + random() * GroundDetailService.BLOB_RX_SPAN);
|
|
72
|
+
const radiusY = groundHeight * (GroundDetailService.BLOB_RY_MIN + random() * GroundDetailService.BLOB_RY_SPAN);
|
|
73
|
+
const shadeAmount = index % 2 === 0 ? GroundDetailService.BLOB_SHADE_POS : GroundDetailService.BLOB_SHADE_NEG;
|
|
74
|
+
const fill = ColorUtil.sh(theme.ground, shadeAmount);
|
|
75
|
+
svg += `<ellipse cx="${posX.toFixed(1)}" cy="${posY.toFixed(1)}" rx="${radiusX.toFixed(1)}" ry="${radiusY.toFixed(1)}" fill="${fill}" opacity="${GroundDetailService.BLOB_OPACITY}"/>`;
|
|
76
|
+
}
|
|
77
|
+
return svg;
|
|
78
|
+
}
|
|
79
|
+
static drawTufts(parts) {
|
|
80
|
+
const { count, seed, width, height, horizonY, theme, placements, isPathBlocked } = parts;
|
|
81
|
+
const groundHeight = height - horizonY;
|
|
82
|
+
const tuftColor = ColorUtil.sh(theme.groundDark || theme.ground, GroundDetailService.TUFT_SHADE);
|
|
83
|
+
let svg = "";
|
|
84
|
+
for (let index = 0; index < count; index++) {
|
|
85
|
+
const random = SeedUtil.sequence(seed + index * GroundDetailService.SEED_STEP);
|
|
86
|
+
const posX = (GroundDetailService.TUFT_X_MIN + random() * GroundDetailService.TUFT_X_SPAN) * width;
|
|
87
|
+
const ratio = random() ** GroundDetailService.TUFT_EXPONENT * GroundDetailService.TUFT_RATIO_SCALE + GroundDetailService.TUFT_RATIO_MIN;
|
|
88
|
+
const posY = horizonY + ratio * groundHeight;
|
|
89
|
+
if (GroundDetailService.isNearFeet(posX, posY, placements) || isPathBlocked?.(posX, posY)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const scale = GroundDetailService.TUFT_SCALE_BASE + GroundDetailService.TUFT_SCALE_SPAN * ratio;
|
|
93
|
+
const isPebble = index % GroundDetailService.CYCLE_PEBBLE === 0;
|
|
94
|
+
const shape = isPebble ? `<ellipse cx="0" cy="0" rx="3.5" ry="2" fill="${tuftColor}" opacity="0.6"/>` : `<path d="M -5 0 Q -4 -9 -7 -14 M 0 0 Q 0 -11 1 -16 M 5 0 Q 4 -9 7 -13" stroke="${tuftColor}" stroke-width="1.3" fill="none" stroke-linecap="round"/>`;
|
|
95
|
+
svg += `<g transform="translate(${posX.toFixed(1)} ${posY.toFixed(1)}) scale(${scale.toFixed(2)})">${shape}</g>`;
|
|
96
|
+
}
|
|
97
|
+
return svg;
|
|
98
|
+
}
|
|
99
|
+
static isNearFeet(posX, posY, placements) {
|
|
100
|
+
return placements.some((placement) => {
|
|
101
|
+
const isGrounded = !placement.isBackdrop && placement.kind !== "sky";
|
|
102
|
+
if (!isGrounded) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const left = placement.boxLeft - GroundDetailService.FOOT_PADDING_X;
|
|
106
|
+
const right = placement.boxRight + GroundDetailService.FOOT_PADDING_X;
|
|
107
|
+
const top = placement.y - GroundDetailService.FOOT_PADDING_Y;
|
|
108
|
+
const bottom = placement.y + GroundDetailService.FOOT_PADDING_Y;
|
|
109
|
+
return posX >= left && posX <= right && posY >= top && posY <= bottom;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
GroundDetailService
|
|
115
|
+
};
|
|
@@ -2,20 +2,29 @@ import type { KitId, KitSceneName, KitTextureName } from "../Protocols/KitProtoc
|
|
|
2
2
|
import { BaseKit } from "../Resources/Kits/BaseKit.js";
|
|
3
3
|
import type { CompilationContext } from "../Protocols/CompilationProtocol.js";
|
|
4
4
|
import type { CompileResult } from "../Protocols/ResultProtocol.js";
|
|
5
|
+
export interface OutlineFilterOptions {
|
|
6
|
+
shadeX?: number;
|
|
7
|
+
shadeY?: number;
|
|
8
|
+
wobble?: number;
|
|
9
|
+
}
|
|
5
10
|
export declare class KitService {
|
|
6
11
|
static readonly KIT_ID_TO_KIT: Record<KitId, BaseKit>;
|
|
7
12
|
private static readonly WHOLE_KIT_HEIGHT;
|
|
8
13
|
private static readonly LIGHT_MODE_TO_IS_HATCHED;
|
|
9
14
|
private static readonly DIGITS;
|
|
15
|
+
private static readonly WOBBLE_FREQUENCY;
|
|
16
|
+
private static readonly WOBBLE_SEED;
|
|
17
|
+
private static readonly SMALL_SHAPE;
|
|
10
18
|
private static readonly DROP_BLUR;
|
|
11
19
|
private static readonly DROP_OFFSET_X;
|
|
12
20
|
private static readonly DROP_OFFSET_Y;
|
|
13
21
|
private static readonly SCENE_TO_FILTER;
|
|
14
22
|
private static readonly TEXTURE_TO_FILTER;
|
|
15
23
|
private static fixed;
|
|
16
|
-
static outlineFilter(id: string, radius: number, ink: string): string;
|
|
24
|
+
static outlineFilter(id: string, radius: number, ink: string, options?: OutlineFilterOptions): string;
|
|
17
25
|
static dropFilter(id: string, scale: number): string;
|
|
18
|
-
static innerStroke(art: string, width: number, ink: string): string;
|
|
26
|
+
static innerStroke(art: string, width: number, ink: string, detailRatio?: number): string;
|
|
27
|
+
private static isSmallShape;
|
|
19
28
|
static hatchDefs(ink: string): string;
|
|
20
29
|
static sceneFilter(kind: KitSceneName): string;
|
|
21
30
|
static texture(kind: KitTextureName | undefined, width: number, height: number): string;
|
|
@@ -4,23 +4,46 @@ import { HatchKit } from "../Resources/Kits/HatchKit.js";
|
|
|
4
4
|
import { RisoKit } from "../Resources/Kits/RisoKit.js";
|
|
5
5
|
import { PaperKit } from "../Resources/Kits/PaperKit.js";
|
|
6
6
|
import { SketchKit } from "../Resources/Kits/SketchKit.js";
|
|
7
|
+
import { ClayKit } from "../Resources/Kits/ClayKit.js";
|
|
8
|
+
import { DuotoneKit } from "../Resources/Kits/DuotoneKit.js";
|
|
9
|
+
import { PosterKit } from "../Resources/Kits/PosterKit.js";
|
|
10
|
+
import { IsometricKit } from "../Resources/Kits/IsometricKit.js";
|
|
7
11
|
import { RegistryUtil } from "../Utils/RegistryUtil.js";
|
|
8
12
|
import { IdUtil } from "../Utils/IdUtil.js";
|
|
9
13
|
import { SvgUtil } from "../Utils/SvgUtil.js";
|
|
10
14
|
class KitService {
|
|
11
|
-
static KIT_ID_TO_KIT = RegistryUtil.indexById(
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
static KIT_ID_TO_KIT = RegistryUtil.indexById([
|
|
16
|
+
new FlatKit(),
|
|
17
|
+
new OutlineKit(),
|
|
18
|
+
new HatchKit(),
|
|
19
|
+
new RisoKit(),
|
|
20
|
+
new PaperKit(),
|
|
21
|
+
new SketchKit(),
|
|
22
|
+
new ClayKit(),
|
|
23
|
+
new DuotoneKit(),
|
|
24
|
+
new PosterKit(),
|
|
25
|
+
new IsometricKit()
|
|
26
|
+
]);
|
|
14
27
|
static WHOLE_KIT_HEIGHT = 900;
|
|
15
28
|
static LIGHT_MODE_TO_IS_HATCHED = { none: false, hatch: true };
|
|
16
29
|
static DIGITS = 3;
|
|
30
|
+
static WOBBLE_FREQUENCY = 0.035;
|
|
31
|
+
static WOBBLE_SEED = 9;
|
|
32
|
+
static SMALL_SHAPE = 5;
|
|
17
33
|
static DROP_BLUR = 2.2;
|
|
18
34
|
static DROP_OFFSET_X = 2.5;
|
|
19
35
|
static DROP_OFFSET_Y = 4;
|
|
20
36
|
static SCENE_TO_FILTER = {
|
|
21
|
-
// Why: posterize to flat ink,
|
|
22
|
-
riso: `<filter id="kitScene" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB"><feComponentTransfer in="SourceGraphic" result="post"><feFuncR type="discrete" tableValues="0.1 0.35 0.6 0.85 1"/><feFuncG type="discrete" tableValues="0.1 0.35 0.6 0.85 1"/><feFuncB type="discrete" tableValues="0.12 0.38 0.62 0.86 1"/></feComponentTransfer><feOffset in="post" dx="2.2" dy="1.4" result="off"/><feColorMatrix in="off" type="matrix" values="0 0 0 0 1 0 0 0 0 0.
|
|
23
|
-
|
|
37
|
+
// Why: posterize to flat ink, misregister accent ink on darkest plate, mask speckle by ink amount and simulate halftone.
|
|
38
|
+
riso: `<filter id="kitScene" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB"><feComponentTransfer in="SourceGraphic" result="post"><feFuncR type="discrete" tableValues="0.1 0.35 0.6 0.85 1"/><feFuncG type="discrete" tableValues="0.1 0.35 0.6 0.85 1"/><feFuncB type="discrete" tableValues="0.12 0.38 0.62 0.86 1"/></feComponentTransfer><feOffset in="post" dx="2.2" dy="1.4" result="off"/><feColorMatrix in="off" type="matrix" values="0 0 0 0 1 0 0 0 0 0.28 0 0 0 0 0.69 -1.8 -1.8 -1.8 0 0.85" result="tint"/><feBlend in="post" in2="tint" mode="multiply" result="reg"/><feColorMatrix in="post" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.3 -0.59 -0.11 0 0.94" result="ink"/><feTurbulence type="fractalNoise" baseFrequency="0.75" numOctaves="1" seed="7" result="grain"/><feComposite in="grain" in2="ink" operator="arithmetic" k1="0" k2="0.6" k3="1.2" k4="-0.5" result="dotSum"/><feComponentTransfer in="dotSum" result="dots"><feFuncA type="linear" slope="3.0" intercept="-0.6"/></feComponentTransfer><feColorMatrix in="dots" type="matrix" values="0 0 0 0 0.1 0 0 0 0 0.12 0 0 0 0 0.25 0 0 0 0.35 0" result="spk"/><feComposite in="spk" in2="ink" operator="in" result="spk2"/><feBlend in="reg" in2="spk2" mode="multiply" result="final"/></filter>`,
|
|
39
|
+
// Why: pencil edge lines, saturated watercolor wash with grayscale turbulence (colored noise reads as speckle), darker edge band pooling and offset color wash.
|
|
40
|
+
sketch: `<filter id="kitScene" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB"><feColorMatrix in="SourceGraphic" type="matrix" values="0.3 0.59 0.11 0 0 0.3 0.59 0.11 0 0 0.3 0.59 0.11 0 0 0 0 0 1 0" result="g"/><feConvolveMatrix in="g" order="3" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" preserveAlpha="true" result="e1"/><feConvolveMatrix in="g" order="3" kernelMatrix="1 1 1 1 -8 1 1 1 1" preserveAlpha="true" result="e2"/><feComposite in="e1" in2="e2" operator="arithmetic" k2="1" k3="1" result="e"/><feColorMatrix in="e" type="matrix" values="0 0 0 0 0.22 0 0 0 0 0.22 0 0 0 0 0.26 2.2 2.2 2.2 0 0" result="lines"/><feMorphology in="lines" operator="dilate" radius="0.6" result="lines2"/><feColorMatrix in="SourceGraphic" type="saturate" values="0.8" result="sat"/><feComponentTransfer in="sat" result="washBase"><feFuncR type="linear" slope="0.75" intercept="0.22"/><feFuncG type="linear" slope="0.75" intercept="0.22"/><feFuncB type="linear" slope="0.75" intercept="0.20"/></feComponentTransfer><feTurbulence type="fractalNoise" baseFrequency="0.018" numOctaves="2" seed="4" result="washNoiseColor"/><feColorMatrix in="washNoiseColor" type="matrix" values="0.3 0.59 0.11 0 0 0.3 0.59 0.11 0 0 0.3 0.59 0.11 0 0 0 0 0 0 1" result="washNoise"/><feBlend in="washBase" in2="washNoise" mode="soft-light" result="washUneven"/><feMorphology in="SourceAlpha" operator="erode" radius="1.4" result="eroded"/><feComposite in="SourceAlpha" in2="eroded" operator="out" result="edgeBand"/><feColorMatrix in="edgeBand" type="matrix" values="0 0 0 -0.32 1 0 0 0 -0.32 1 0 0 0 -0.32 1 0 0 0 0 1" result="edgeDarken"/><feBlend in="washUneven" in2="edgeDarken" mode="multiply" result="washWithEdges"/><feComposite in="washWithEdges" in2="SourceGraphic" operator="in" result="washClipped"/><feOffset in="washClipped" dx="1.6" dy="1.2" result="washOffset"/><feMerge><feMergeNode in="washOffset"/><feMergeNode in="lines2"/></feMerge></filter>`,
|
|
41
|
+
// Why: soft 3D bevel and rim lighting with diffuse contact shading.
|
|
42
|
+
clay: `<filter id="kitScene" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB"><feGaussianBlur in="SourceAlpha" stdDeviation="3.0" result="b1"/><feOffset in="b1" dx="-2.5" dy="-3.0" result="hiOffset"/><feOffset in="b1" dx="2.5" dy="3.0" result="shOffset"/><feComposite in="hiOffset" in2="shOffset" operator="arithmetic" k2="1.2" k3="-0.9" result="rimRaw"/><feColorMatrix in="rimRaw" type="matrix" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.2 -0.1" result="rim"/><feComposite in="shOffset" in2="hiOffset" operator="arithmetic" k2="0.8" k3="-0.6" result="shRaw"/><feColorMatrix in="shRaw" type="matrix" values="0 0 0 0 0.15 0 0 0 0 0.15 0 0 0 0 0.2 0 0 0 0.7 0" result="sh"/><feBlend in="SourceGraphic" in2="sh" mode="multiply" result="shaded"/><feBlend in="shaded" in2="rim" mode="screen" result="lit"/><feComposite in="lit" in2="SourceGraphic" operator="in" result="final"/></filter>`,
|
|
43
|
+
// Why: luminance mapped across two inks (navy and paper) with fine halftone texture.
|
|
44
|
+
duotone: `<filter id="kitScene" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB"><feColorMatrix in="SourceGraphic" type="matrix" values="0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0" result="lum"/><feComponentTransfer in="lum" result="map"><feFuncR type="table" tableValues="0.114 0.22 0.55 0.82 0.957"/><feFuncG type="table" tableValues="0.176 0.32 0.62 0.85 0.922"/><feFuncB type="table" tableValues="0.314 0.45 0.71 0.86 0.851"/></feComponentTransfer><feTurbulence type="fractalNoise" baseFrequency="0.75" numOctaves="1" seed="11" result="nz"/><feColorMatrix in="nz" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.18 0" result="ht"/><feBlend in="map" in2="ht" mode="multiply" result="final"/></filter>`,
|
|
45
|
+
// Why: 4-5 color posterization, sun-faded grade and coarse shadow halftone.
|
|
46
|
+
poster: `<filter id="kitScene" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB"><feComponentTransfer in="SourceGraphic" result="post"><feFuncR type="discrete" tableValues="0.12 0.35 0.58 0.82 1.0"/><feFuncG type="discrete" tableValues="0.12 0.35 0.58 0.82 1.0"/><feFuncB type="discrete" tableValues="0.14 0.36 0.59 0.83 1.0"/></feComponentTransfer><feColorMatrix in="post" type="matrix" values="1.04 0 0 0 0.03 0 0.98 0 0 0.02 0 0 0.88 0 -0.01 0 0 0 1 0" result="faded"/><feColorMatrix in="post" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.5 -1.5 -1.5 0 0.8" result="shMask"/><feTurbulence type="fractalNoise" baseFrequency="0.4" numOctaves="1" seed="17" result="coarseNz"/><feComposite in="coarseNz" in2="shMask" operator="in" result="coarseDots"/><feColorMatrix in="coarseDots" type="matrix" values="0 0 0 0 0.17 0 0 0 0 0.13 0 0 0 0 0.10 0 0 0 0.35 0" result="shDots"/><feBlend in="faded" in2="shDots" mode="multiply" result="final"/></filter>`
|
|
24
47
|
};
|
|
25
48
|
static TEXTURE_TO_FILTER = {
|
|
26
49
|
paper: {
|
|
@@ -35,8 +58,12 @@ class KitService {
|
|
|
35
58
|
static fixed(value) {
|
|
36
59
|
return value.toFixed(KitService.DIGITS);
|
|
37
60
|
}
|
|
38
|
-
static outlineFilter(id, radius, ink) {
|
|
39
|
-
|
|
61
|
+
static outlineFilter(id, radius, ink, options = {}) {
|
|
62
|
+
const { shadeX = 0, shadeY = 0, wobble = 0 } = options;
|
|
63
|
+
const isWeighted = shadeX !== 0 || shadeY !== 0;
|
|
64
|
+
const weighted = isWeighted ? `<feOffset in="d" dx="${KitService.fixed(shadeX)}" dy="${KitService.fixed(shadeY)}" result="d2"/><feMerge result="dm"><feMergeNode in="d"/><feMergeNode in="d2"/></feMerge>` : `<feOffset in="d" dx="0" dy="0" result="dm"/>`;
|
|
65
|
+
const wobbled = wobble > 0 ? `<feTurbulence type="fractalNoise" baseFrequency="${KitService.WOBBLE_FREQUENCY}" numOctaves="2" seed="${KitService.WOBBLE_SEED}" result="n"/><feDisplacementMap in="dm" in2="n" scale="${KitService.fixed(wobble)}" xChannelSelector="R" yChannelSelector="G" result="dw"/>` : `<feOffset in="dm" dx="0" dy="0" result="dw"/>`;
|
|
66
|
+
return `<filter id="${id}" x="-15%" y="-15%" width="130%" height="130%"><feMorphology in="SourceAlpha" operator="dilate" radius="${KitService.fixed(radius)}" result="d"/>` + weighted + wobbled + `<feFlood flood-color="${ink}"/><feComposite in2="dw" operator="in" result="o"/><feMerge><feMergeNode in="o"/><feMergeNode in="SourceGraphic"/></feMerge></filter>`;
|
|
40
67
|
}
|
|
41
68
|
static dropFilter(id, scale) {
|
|
42
69
|
const blur = KitService.fixed(KitService.DROP_BLUR / scale);
|
|
@@ -44,14 +71,22 @@ class KitService {
|
|
|
44
71
|
const offsetY = KitService.fixed(KitService.DROP_OFFSET_Y / scale);
|
|
45
72
|
return `<filter id="${id}" x="-20%" y="-20%" width="140%" height="150%"><feGaussianBlur in="SourceAlpha" stdDeviation="${blur}"/><feOffset dx="${offsetX}" dy="${offsetY}" result="b"/><feFlood flood-color="#2B1D10" flood-opacity="0.42"/><feComposite in2="b" operator="in" result="sh"/><feMerge><feMergeNode in="sh"/><feMergeNode in="SourceGraphic"/></feMerge></filter>`;
|
|
46
73
|
}
|
|
47
|
-
static innerStroke(art, width, ink) {
|
|
74
|
+
static innerStroke(art, width, ink, detailRatio = 1) {
|
|
48
75
|
const shapes = art.replace(/<(rect|path|circle|ellipse|polygon)\b([^>]*?)\/>/g, (match, tag, attrs) => {
|
|
49
76
|
const hasStroke = /\bstroke=/.test(attrs);
|
|
50
77
|
const isUnpainted = /\bopacity=|fill-opacity=|fill="none"|fill="url\(/.test(attrs);
|
|
51
|
-
|
|
78
|
+
if (isUnpainted && !hasStroke) {
|
|
79
|
+
return `<${tag}${attrs} stroke="none"/>`;
|
|
80
|
+
}
|
|
81
|
+
const isDetail = !hasStroke && KitService.isSmallShape(attrs);
|
|
82
|
+
return isDetail ? `<${tag}${attrs} stroke-width="${KitService.fixed(width * detailRatio)}"/>` : match;
|
|
52
83
|
});
|
|
53
84
|
return `<g stroke="${ink}" stroke-width="${KitService.fixed(width)}" stroke-linejoin="round">${shapes}</g>`;
|
|
54
85
|
}
|
|
86
|
+
static isSmallShape(attrs) {
|
|
87
|
+
const sizes = [...attrs.matchAll(/\b(?:r|rx|ry)="([\d.]+)"/g)].map((match) => Number(match[1]) * 2).concat([...attrs.matchAll(/\b(?:width|height)="([\d.]+)"/g)].map((match) => Number(match[1])));
|
|
88
|
+
return sizes.length > 0 && Math.min(...sizes) <= KitService.SMALL_SHAPE;
|
|
89
|
+
}
|
|
55
90
|
static hatchDefs(ink) {
|
|
56
91
|
return `<pattern id="hatchP" width="7" height="7" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect x="0" y="0" width="1.5" height="7" fill="${ink}" fill-opacity="0.5"/></pattern><pattern id="hatchC" width="6" height="6" patternUnits="userSpaceOnUse" patternTransform="rotate(-35)"><rect x="0" y="0" width="1.4" height="6" fill="${ink}" fill-opacity="0.42"/><rect x="0" y="0" width="6" height="1.2" fill="${ink}" fill-opacity="0.22"/></pattern>`;
|
|
57
92
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { Background, Camera, CompilationContext, LightState, Placement } from "../Protocols/CompilationProtocol.js";
|
|
2
|
+
import type { TimeName } from "../Protocols/SceneProtocol.js";
|
|
2
3
|
export declare class LightingService {
|
|
3
4
|
private static readonly DIRECTION_TO_FRACTION;
|
|
4
5
|
private static readonly MODE_TO_TRAITS;
|
|
6
|
+
private static readonly TIME_TO_LIGHT_COLOR;
|
|
7
|
+
private static readonly TIME_TO_GRADE;
|
|
8
|
+
private static readonly PANE_BOXES;
|
|
9
|
+
private static readonly SHAFT_WIDTH_RATIO;
|
|
10
|
+
private static readonly FLOOR_PATCH_START;
|
|
11
|
+
private static readonly FLOOR_PATCH_SPAN;
|
|
12
|
+
private static readonly FLOOR_LEFT_FAR;
|
|
13
|
+
private static readonly FLOOR_LEFT_NEAR;
|
|
14
|
+
private static readonly FLOOR_PANE_OPACITY;
|
|
5
15
|
private static readonly INDOOR_LIGHT;
|
|
6
16
|
private static readonly OPEN_LIGHT;
|
|
7
17
|
private static readonly SETTING_TO_LIGHT;
|
|
@@ -14,6 +24,8 @@ export declare class LightingService {
|
|
|
14
24
|
private static readonly DAY_LIGHT;
|
|
15
25
|
private static readonly SOURCE_ASSETS;
|
|
16
26
|
static resolve(context: CompilationContext, list: Placement[], background: Background): LightState | null;
|
|
27
|
+
private static resolveShaft;
|
|
28
|
+
static timeGradeFilter(time: TimeName): string;
|
|
17
29
|
private static settingLightOf;
|
|
18
30
|
private static directionOf;
|
|
19
31
|
private static sourceOf;
|
|
@@ -21,4 +33,7 @@ export declare class LightingService {
|
|
|
21
33
|
static applyToBackground(svg: string, light: LightState, context: CompilationContext, camera: Camera): string;
|
|
22
34
|
private static vignetteDef;
|
|
23
35
|
private static defs;
|
|
36
|
+
private static sunGlowDef;
|
|
37
|
+
private static shaftGradDef;
|
|
38
|
+
private static indoorShaftSvg;
|
|
24
39
|
}
|
|
@@ -12,19 +12,51 @@ class LightingService {
|
|
|
12
12
|
none: { isOff: true, isHatch: false },
|
|
13
13
|
hatch: { isOff: false, isHatch: true }
|
|
14
14
|
};
|
|
15
|
+
static TIME_TO_LIGHT_COLOR = {
|
|
16
|
+
golden: "#FFAE42",
|
|
17
|
+
noon: "#FFFFF0",
|
|
18
|
+
overcast: "#D8DFE8",
|
|
19
|
+
dusk: "#E8A0BF",
|
|
20
|
+
night: "#9BB8ED"
|
|
21
|
+
};
|
|
22
|
+
static TIME_TO_GRADE = {
|
|
23
|
+
golden: `<filter id="timeGrade" color-interpolation-filters="sRGB"><feColorMatrix type="matrix" values="1.08 0 0 0 0.04 0 1.02 0 0 0.02 0 0 0.88 0 -0.02 0 0 0 1 0"/></filter>`,
|
|
24
|
+
noon: `<filter id="timeGrade" color-interpolation-filters="sRGB"><feComponentTransfer><feFuncR type="linear" slope="1.05" intercept="-0.025"/><feFuncG type="linear" slope="1.05" intercept="-0.025"/><feFuncB type="linear" slope="1.05" intercept="-0.025"/></feComponentTransfer></filter>`,
|
|
25
|
+
overcast: `<filter id="timeGrade" color-interpolation-filters="sRGB"><feColorMatrix type="saturate" values="0.75"/><feComponentTransfer><feFuncR type="linear" slope="0.95" intercept="0.04"/><feFuncG type="linear" slope="0.95" intercept="0.04"/><feFuncB type="linear" slope="0.98" intercept="0.05"/></feComponentTransfer></filter>`,
|
|
26
|
+
dusk: `<filter id="timeGrade" color-interpolation-filters="sRGB"><feColorMatrix type="matrix" values="1.05 0 0 0 0.05 0 0.92 0 0 0.01 0 0 1.08 0 0.06 0 0 0 1 0"/></filter>`,
|
|
27
|
+
night: `<filter id="timeGrade" color-interpolation-filters="sRGB"><feColorMatrix type="matrix" values="0.65 0 0 0 0.01 0 0.72 0 0 0.02 0 0 0.92 0 0.08 0 0 0 1 0"/></filter>`
|
|
28
|
+
};
|
|
29
|
+
static PANE_BOXES = [
|
|
30
|
+
[0.08, 0.08, 0.46, 0.46],
|
|
31
|
+
[0.54, 0.08, 0.92, 0.46],
|
|
32
|
+
[0.08, 0.54, 0.46, 0.92],
|
|
33
|
+
[0.54, 0.54, 0.92, 0.92]
|
|
34
|
+
];
|
|
35
|
+
static SHAFT_WIDTH_RATIO = 0.4;
|
|
36
|
+
static FLOOR_PATCH_START = 0.15;
|
|
37
|
+
static FLOOR_PATCH_SPAN = 0.7;
|
|
38
|
+
static FLOOR_LEFT_FAR = 2.2;
|
|
39
|
+
static FLOOR_LEFT_NEAR = 0.4;
|
|
40
|
+
static FLOOR_PANE_OPACITY = 0.2;
|
|
15
41
|
static INDOOR_LIGHT = {
|
|
16
42
|
surface: "wall",
|
|
17
43
|
blur: 6e-3,
|
|
18
44
|
glowY: 0.25,
|
|
19
45
|
extraSourceAsset: "window",
|
|
20
|
-
glowLayers: (defs, { width, height, horizonY }) =>
|
|
46
|
+
glowLayers: (defs, { width, height, horizonY, light }) => {
|
|
47
|
+
const shaftLayer = light.shaft ? LightingService.indoorShaftSvg(light.shaft, light, { width, height, horizonY }) : "";
|
|
48
|
+
return `${defs}<rect width="${width}" height="${horizonY}" fill="url(#glow)" style="mix-blend-mode: screen;"/><rect width="${width}" height="${height}" fill="url(#falloff)" style="mix-blend-mode: multiply;"/>` + shaftLayer;
|
|
49
|
+
}
|
|
21
50
|
};
|
|
22
51
|
static OPEN_LIGHT = {
|
|
23
52
|
surface: "skyTop",
|
|
24
53
|
blur: 3e-3,
|
|
25
54
|
glowY: 0.15,
|
|
26
55
|
extraSourceAsset: null,
|
|
27
|
-
glowLayers: (defs, { width, height }) =>
|
|
56
|
+
glowLayers: (defs, { width, height, light }) => {
|
|
57
|
+
const sunLayer = light.celestialGlow ? `<rect width="${width}" height="${height}" fill="url(#sunGlow)" style="mix-blend-mode: screen;"/>` : "";
|
|
58
|
+
return `${defs}<rect width="${width}" height="${height * 0.75}" fill="url(#glow)" style="mix-blend-mode: screen;"/>${sunLayer}`;
|
|
59
|
+
}
|
|
28
60
|
};
|
|
29
61
|
static SETTING_TO_LIGHT = {
|
|
30
62
|
indoor: LightingService.INDOOR_LIGHT
|
|
@@ -49,17 +81,51 @@ class LightingService {
|
|
|
49
81
|
const settingLight = LightingService.settingLightOf(setting);
|
|
50
82
|
const { extraSourceAsset } = settingLight;
|
|
51
83
|
const source = LightingService.sourceOf(requested.from, { list, width, extraSourceAsset });
|
|
84
|
+
const isNight = canvas.time === "night" || ColorUtil.luminance(theme[settingLight.surface]) < LightingService.NIGHT_LUMINANCE;
|
|
52
85
|
const [red, green, blue] = background.shadowRgba;
|
|
86
|
+
const celestial = list.find((placement) => IdUtil.isOneOf(LightingService.SOURCE_ASSETS, placement.asset));
|
|
87
|
+
const celestialGlow = celestial ? { cx: celestial.x / width, cy: celestial.y / context.height } : null;
|
|
88
|
+
const shaft = LightingService.resolveShaft(setting, list, requested, width);
|
|
53
89
|
return {
|
|
54
90
|
source,
|
|
55
91
|
strength: requested.strength ?? kitLight.strength ?? LightingService.DEFAULT_STRENGTH,
|
|
56
92
|
direction: LightingService.directionOf(source),
|
|
57
|
-
isNight
|
|
93
|
+
isNight,
|
|
58
94
|
shadowColor: `rgb(${red},${green},${blue})`,
|
|
59
95
|
shadowRgb: [red, green, blue],
|
|
60
|
-
isHatch: modeTraits?.isHatch === true
|
|
96
|
+
isHatch: modeTraits?.isHatch === true,
|
|
97
|
+
time: canvas.time,
|
|
98
|
+
shaft,
|
|
99
|
+
celestialGlow
|
|
61
100
|
};
|
|
62
101
|
}
|
|
102
|
+
static resolveShaft(setting, list, requested, width) {
|
|
103
|
+
if (setting !== "indoor" || requested.shafts === false) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const windowPlacement = list.find((placement) => placement.asset === "window");
|
|
107
|
+
if (!windowPlacement) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const winX = windowPlacement.x;
|
|
111
|
+
const winY = windowPlacement.y;
|
|
112
|
+
const winW = windowPlacement.width * windowPlacement.scale;
|
|
113
|
+
const winH = windowPlacement.height * windowPlacement.scale;
|
|
114
|
+
const isRight = winX > width * 0.5;
|
|
115
|
+
const floorLeft = isRight ? winX - winW * LightingService.FLOOR_LEFT_FAR : winX + winW * LightingService.FLOOR_LEFT_NEAR;
|
|
116
|
+
const floorRight = isRight ? winX - winW * LightingService.FLOOR_LEFT_NEAR : winX + winW * LightingService.FLOOR_LEFT_FAR;
|
|
117
|
+
return {
|
|
118
|
+
windowX: winX,
|
|
119
|
+
windowY: winY,
|
|
120
|
+
windowWidth: winW,
|
|
121
|
+
windowHeight: winH,
|
|
122
|
+
floorLeft,
|
|
123
|
+
floorRight
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
static timeGradeFilter(time) {
|
|
127
|
+
return LightingService.TIME_TO_GRADE[time];
|
|
128
|
+
}
|
|
63
129
|
static settingLightOf(setting) {
|
|
64
130
|
return IdUtil.lookup(LightingService.SETTING_TO_LIGHT, setting) ?? LightingService.OPEN_LIGHT;
|
|
65
131
|
}
|
|
@@ -83,6 +149,12 @@ class LightingService {
|
|
|
83
149
|
return sourcePlacement ? sourcePlacement.x / scene.width : LightingService.DEFAULT_SOURCE;
|
|
84
150
|
}
|
|
85
151
|
static lightColorOf(light) {
|
|
152
|
+
if (light.time != null) {
|
|
153
|
+
const timeColor = IdUtil.lookup(LightingService.TIME_TO_LIGHT_COLOR, light.time);
|
|
154
|
+
if (timeColor != null) {
|
|
155
|
+
return timeColor;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
86
158
|
return light.isNight ? LightingService.NIGHT_LIGHT : LightingService.DAY_LIGHT;
|
|
87
159
|
}
|
|
88
160
|
static applyToBackground(svg, light, context, camera) {
|
|
@@ -94,7 +166,7 @@ class LightingService {
|
|
|
94
166
|
return defs;
|
|
95
167
|
}
|
|
96
168
|
const horizonY = height * lines.horizon;
|
|
97
|
-
return LightingService.settingLightOf(setting).glowLayers(defs, { width, height, horizonY });
|
|
169
|
+
return LightingService.settingLightOf(setting).glowLayers(defs, { width, height, horizonY, light });
|
|
98
170
|
}
|
|
99
171
|
static vignetteDef(light) {
|
|
100
172
|
const { shadowColor, strength } = light;
|
|
@@ -111,7 +183,53 @@ class LightingService {
|
|
|
111
183
|
const rgb = shadowRgb.map((channel) => (channel / 255).toFixed(3));
|
|
112
184
|
const fade = (factor) => (factor * strength).toFixed(3);
|
|
113
185
|
const falloffOpacity = direction ? fade(0.13) : 0;
|
|
114
|
-
return `<linearGradient id="
|
|
186
|
+
return `<linearGradient id="lgLight" x1="${direction ? fromX : 0.5}" y1="0" x2="${direction ? toX : 0.5}" y2="${direction ? 0.35 : 1}"><stop offset="0" stop-color="${lightColor}" stop-opacity="${fade(0.26)}"/><stop offset="0.42" stop-color="${lightColor}" stop-opacity="0"/></linearGradient><linearGradient id="lgShade" x1="${direction ? fromX : 0.5}" y1="0" x2="${direction ? toX : 0.5}" y2="${direction ? 0.35 : 1}"><stop offset="0.6" stop-color="${shadowColor}" stop-opacity="0"/><stop offset="1" stop-color="${shadowColor}" stop-opacity="${fade(0.5)}"/></linearGradient><linearGradient id="lgAO" x1="0" y1="0" x2="0" y2="1"><stop offset="0.72" stop-color="${shadowColor}" stop-opacity="0"/><stop offset="1" stop-color="${shadowColor}" stop-opacity="${fade(0.32)}"/></linearGradient><filter id="toWhite" color-interpolation-filters="sRGB"><feColorMatrix values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/></filter><filter id="castF" x="-30%" y="-30%" width="160%" height="160%" color-interpolation-filters="sRGB"><feColorMatrix values="0 0 0 0 ${rgb[0]} 0 0 0 0 ${rgb[1]} 0 0 0 0 ${rgb[2]} 0 0 0 1 0"/><feGaussianBlur stdDeviation="${blur}"/></filter><clipPath id="groundClip"><rect y="${(horizonY * camera.zoom + camera.translateY).toFixed(1)}" width="${width}" height="${height}"/></clipPath><radialGradient id="glow" cx="${source}" cy="${settingLight.glowY}" r="0.75"><stop offset="0" stop-color="${lightColor}" stop-opacity="${fade(0.55)}"/><stop offset="1" stop-color="${lightColor}" stop-opacity="0"/></radialGradient><linearGradient id="falloff" x1="${fromX}" y1="0" x2="${toX}" y2="0"><stop offset="0.35" stop-color="${shadowColor}" stop-opacity="0"/><stop offset="1" stop-color="${shadowColor}" stop-opacity="${falloffOpacity}"/></linearGradient>` + LightingService.sunGlowDef(light, lightColor, fade) + LightingService.shaftGradDef(light, lightColor, fade, { width, height });
|
|
187
|
+
}
|
|
188
|
+
static sunGlowDef(light, lightColor, fade) {
|
|
189
|
+
if (!light.celestialGlow) {
|
|
190
|
+
return "";
|
|
191
|
+
}
|
|
192
|
+
return `<radialGradient id="sunGlow" cx="${light.celestialGlow.cx.toFixed(3)}" cy="${light.celestialGlow.cy.toFixed(3)}" r="0.32"><stop offset="0" stop-color="${lightColor}" stop-opacity="${fade(0.38)}"/><stop offset="0.45" stop-color="${lightColor}" stop-opacity="${fade(0.14)}"/><stop offset="1" stop-color="${lightColor}" stop-opacity="0"/></radialGradient>`;
|
|
193
|
+
}
|
|
194
|
+
static shaftGradDef(light, lightColor, fade, bounds) {
|
|
195
|
+
if (!light.shaft) {
|
|
196
|
+
return "";
|
|
197
|
+
}
|
|
198
|
+
const { width, height } = bounds;
|
|
199
|
+
const shaftX = (light.shaft.windowX / width).toFixed(3);
|
|
200
|
+
const shaftY = (light.shaft.windowY / height).toFixed(3);
|
|
201
|
+
const targetX = ((light.shaft.floorLeft + light.shaft.floorRight) / 2 / width).toFixed(3);
|
|
202
|
+
return `<linearGradient id="shaftGrad" x1="${shaftX}" y1="${shaftY}" x2="${targetX}" y2="1"><stop offset="0" stop-color="${lightColor}" stop-opacity="${fade(0.22)}"/><stop offset="0.75" stop-color="${lightColor}" stop-opacity="${fade(0.06)}"/><stop offset="1" stop-color="${lightColor}" stop-opacity="0"/></linearGradient>`;
|
|
203
|
+
}
|
|
204
|
+
static indoorShaftSvg(shaft, light, bounds) {
|
|
205
|
+
const { height, horizonY } = bounds;
|
|
206
|
+
const halfWidth = shaft.windowWidth * LightingService.SHAFT_WIDTH_RATIO;
|
|
207
|
+
const winLeft = shaft.windowX - halfWidth;
|
|
208
|
+
const winRight = shaft.windowX + halfWidth;
|
|
209
|
+
const winBottom = shaft.windowY;
|
|
210
|
+
const shaftPoints = `${winLeft.toFixed(1)},${winBottom.toFixed(1)} ${winRight.toFixed(1)},${winBottom.toFixed(1)} ${shaft.floorRight.toFixed(1)},${height.toFixed(1)} ${shaft.floorLeft.toFixed(1)},${height.toFixed(1)}`;
|
|
211
|
+
const shaftPolygon = `<polygon points="${shaftPoints}" fill="url(#shaftGrad)" style="mix-blend-mode: screen;"/>`;
|
|
212
|
+
const lightColor = LightingService.lightColorOf(light);
|
|
213
|
+
const paneOpacity = (LightingService.FLOOR_PANE_OPACITY * light.strength).toFixed(3);
|
|
214
|
+
const floorHeight = height - horizonY;
|
|
215
|
+
let panesSvg = "";
|
|
216
|
+
LightingService.PANE_BOXES.forEach(([u0, v0, u1, v1]) => {
|
|
217
|
+
const mapPoint = (coordU, coordV) => {
|
|
218
|
+
const spanRatio = LightingService.FLOOR_PATCH_START + coordV * LightingService.FLOOR_PATCH_SPAN;
|
|
219
|
+
const paneY = horizonY + spanRatio * floorHeight;
|
|
220
|
+
const progress = (paneY - horizonY) / floorHeight;
|
|
221
|
+
const leftAtY = winLeft + (shaft.floorLeft - winLeft) * progress;
|
|
222
|
+
const rightAtY = winRight + (shaft.floorRight - winRight) * progress;
|
|
223
|
+
const paneX = leftAtY + coordU * (rightAtY - leftAtY);
|
|
224
|
+
return `${paneX.toFixed(1)},${paneY.toFixed(1)}`;
|
|
225
|
+
};
|
|
226
|
+
const p1 = mapPoint(u0, v0);
|
|
227
|
+
const p2 = mapPoint(u1, v0);
|
|
228
|
+
const p3 = mapPoint(u1, v1);
|
|
229
|
+
const p4 = mapPoint(u0, v1);
|
|
230
|
+
panesSvg += `<polygon points="${p1} ${p2} ${p3} ${p4}" fill="${lightColor}" opacity="${paneOpacity}" style="mix-blend-mode: screen;"/>`;
|
|
231
|
+
});
|
|
232
|
+
return shaftPolygon + panesSvg;
|
|
115
233
|
}
|
|
116
234
|
}
|
|
117
235
|
export {
|