@neta-art/cohub-cli 10.18.0 → 10.19.0
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/dist/board-export.d.ts +8 -2
- package/dist/board-export.js +75 -42
- package/dist/board-gpu/page.js +339 -133
- package/dist/board-gpu/protocol.d.ts +1 -0
- package/dist/board-kernel.d.ts +1 -1
- package/dist/board-kernel.js +1113 -188
- package/dist/board-media-export.d.ts +16 -0
- package/dist/board-media-export.js +147 -0
- package/dist/board-media.d.ts +2 -1
- package/dist/board-media.js +23 -0
- package/dist/commands/boards/authoring.js +45 -3
- package/dist/commands/space-displays.d.ts +1 -1
- package/dist/commands/space-displays.js +70 -18
- package/dist/output.d.ts +1 -0
- package/dist/output.js +3 -0
- package/dist/safe-remote-image.d.ts +4 -0
- package/dist/safe-remote-image.js +8 -0
- package/package.json +2 -2
package/dist/board-gpu/page.js
CHANGED
|
@@ -5944,6 +5944,7 @@ const itemEnvelope$1 = {
|
|
|
5944
5944
|
y: .5
|
|
5945
5945
|
}).describe("Rotation and scale origin as fractions of the size."),
|
|
5946
5946
|
opacity: ratio$1.default(1),
|
|
5947
|
+
visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
|
|
5947
5948
|
style: BoardStyleSchema$1.default({}),
|
|
5948
5949
|
locked: boolean().optional(),
|
|
5949
5950
|
metadata: record(string(), unknown()).optional()
|
|
@@ -6093,7 +6094,8 @@ const mediaProps$1 = {
|
|
|
6093
6094
|
};
|
|
6094
6095
|
const timedFileProps$1 = {
|
|
6095
6096
|
...mediaProps$1,
|
|
6096
|
-
time: nonNegative$1.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline.")
|
|
6097
|
+
time: nonNegative$1.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline. It sounds while its time moves forward."),
|
|
6098
|
+
volume: ratio$1.optional().describe("Loudness from 0 to 1; defaults to 1. Animate it to fade.")
|
|
6097
6099
|
};
|
|
6098
6100
|
const BoardCropSchema$1 = object({
|
|
6099
6101
|
x: ratio$1,
|
|
@@ -8636,7 +8638,7 @@ function parameterKind(track) {
|
|
|
8636
8638
|
if (values.every((value) => BoardColorSchema$1.safeParse(value).success)) return "color";
|
|
8637
8639
|
return "discrete";
|
|
8638
8640
|
}
|
|
8639
|
-
function
|
|
8641
|
+
function compileBoardTrack(animationId, id, track, targetType) {
|
|
8640
8642
|
const resolved = resolveBoardProperty(targetType, track.property);
|
|
8641
8643
|
if (!resolved.ok) return null;
|
|
8642
8644
|
const kind = targetType === "script" ? parameterKind(track) : resolved.spec.kind;
|
|
@@ -8694,7 +8696,7 @@ function compileAnimation(animationId, animation, document) {
|
|
|
8694
8696
|
for (const [id, track] of Object.entries(tracks).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
8695
8697
|
const targetType = track.target === "camera" ? BOARD_CAMERA_TARGET$1 : document.animations[track.target] ? "animation" : document.board.scripts?.[track.target] ? "script" : document.items[track.target]?.type;
|
|
8696
8698
|
if (!targetType) continue;
|
|
8697
|
-
const entry =
|
|
8699
|
+
const entry = compileBoardTrack(animationId, id, track, targetType);
|
|
8698
8700
|
if (!entry) continue;
|
|
8699
8701
|
(targetType === "animation" ? children : compiled).push(entry);
|
|
8700
8702
|
}
|
|
@@ -9077,16 +9079,18 @@ function buildBoardScene(document, previous) {
|
|
|
9077
9079
|
return result;
|
|
9078
9080
|
},
|
|
9079
9081
|
binders: (id) => binders.get(id) ?? [],
|
|
9080
|
-
opacity: (id) => cumulativeOpacity((key) => items[key], id)
|
|
9082
|
+
opacity: (id) => cumulativeOpacity((key) => items[key], id),
|
|
9083
|
+
shown: (id) => cumulativeOpacity((key) => items[key], id, true) > 0
|
|
9081
9084
|
};
|
|
9082
9085
|
}
|
|
9083
|
-
function cumulativeOpacity(lookup, id) {
|
|
9086
|
+
function cumulativeOpacity(lookup, id, presence = false) {
|
|
9084
9087
|
let value = 1;
|
|
9085
9088
|
let cursor = id;
|
|
9086
9089
|
for (let depth = 0; cursor && depth < 64; depth += 1) {
|
|
9087
9090
|
const item = lookup(cursor);
|
|
9088
9091
|
if (!item) break;
|
|
9089
|
-
|
|
9092
|
+
if (item.visible === false) return 0;
|
|
9093
|
+
if (!presence) value *= item.opacity;
|
|
9090
9094
|
cursor = item.parent;
|
|
9091
9095
|
}
|
|
9092
9096
|
return value;
|
|
@@ -56048,10 +56052,12 @@ init_Matrix();
|
|
|
56048
56052
|
init_Rectangle();
|
|
56049
56053
|
init_GlProgram();
|
|
56050
56054
|
init_Geometry();
|
|
56055
|
+
init_RenderTarget();
|
|
56051
56056
|
init_Shader();
|
|
56052
56057
|
init_UniformGroup();
|
|
56053
56058
|
init_RenderTexture();
|
|
56054
56059
|
init_ImageSource();
|
|
56060
|
+
init_TextureSource();
|
|
56055
56061
|
init_Texture();
|
|
56056
56062
|
init_TexturePool();
|
|
56057
56063
|
init_textureFrom();
|
|
@@ -62075,6 +62081,9 @@ function colorSteps(filter) {
|
|
|
62075
62081
|
}
|
|
62076
62082
|
var BoardColorFilter = class extends ColorMatrixFilter {
|
|
62077
62083
|
css = "";
|
|
62084
|
+
constructor() {
|
|
62085
|
+
super({ resolution: "inherit" });
|
|
62086
|
+
}
|
|
62078
62087
|
set(filter) {
|
|
62079
62088
|
const steps = colorSteps(filter);
|
|
62080
62089
|
this.css = steps.map(({ step, value }) => step.css(value)).join(" ");
|
|
@@ -62152,21 +62161,47 @@ function shaderPasses() {
|
|
|
62152
62161
|
};
|
|
62153
62162
|
return passes;
|
|
62154
62163
|
}
|
|
62155
|
-
|
|
62156
|
-
|
|
62164
|
+
const TEXELS_PER_DEVIATION = 4;
|
|
62165
|
+
const MAX_HALVINGS = 5;
|
|
62166
|
+
function gaussian(filters, input, output, deviation, clear, first) {
|
|
62167
|
+
const { horizontal, vertical, copy } = shaderPasses();
|
|
62168
|
+
const resolution = input.source.resolution;
|
|
62169
|
+
const halvings = Math.max(0, Math.min(MAX_HALVINGS, Math.floor(Math.log2(deviation * resolution / TEXELS_PER_DEVIATION))));
|
|
62170
|
+
const borrowed = [];
|
|
62171
|
+
const borrow = (scale) => {
|
|
62172
|
+
const texture = TexturePool.getOptimalTexture(input.frame.width, input.frame.height, resolution * scale, false);
|
|
62173
|
+
borrowed.push(texture);
|
|
62174
|
+
return texture;
|
|
62175
|
+
};
|
|
62176
|
+
let source = input;
|
|
62177
|
+
let scale = 1;
|
|
62178
|
+
for (let step = 0; step < Math.max(halvings, first ? 1 : 0); step++) {
|
|
62179
|
+
if (step < halvings) scale /= 2;
|
|
62180
|
+
const next = borrow(scale);
|
|
62181
|
+
filters.applyFilter(step === 0 && first ? first : copy, source, next, true);
|
|
62182
|
+
source = next;
|
|
62183
|
+
}
|
|
62157
62184
|
horizontal.resources.blurUniforms.uniforms.uStep = [deviation / 4, 0];
|
|
62158
62185
|
vertical.resources.blurUniforms.uniforms.uStep = [0, deviation / 4];
|
|
62159
|
-
const between =
|
|
62160
|
-
filters.applyFilter(horizontal,
|
|
62161
|
-
filters.applyFilter(vertical, between, output, clear);
|
|
62162
|
-
|
|
62186
|
+
const between = borrow(scale);
|
|
62187
|
+
filters.applyFilter(horizontal, source, between, true);
|
|
62188
|
+
if (scale === 1) filters.applyFilter(vertical, between, output, clear);
|
|
62189
|
+
else {
|
|
62190
|
+
const blurred = borrow(scale);
|
|
62191
|
+
filters.applyFilter(vertical, between, blurred, true);
|
|
62192
|
+
filters.applyFilter(copy, blurred, output, clear);
|
|
62193
|
+
}
|
|
62194
|
+
for (const texture of borrowed) TexturePool.returnTexture(texture);
|
|
62163
62195
|
}
|
|
62164
62196
|
var BoardBlurFilter = class extends Filter {
|
|
62165
62197
|
css = "";
|
|
62166
62198
|
radius = 0;
|
|
62167
62199
|
deviation = 0;
|
|
62168
62200
|
constructor() {
|
|
62169
|
-
super({
|
|
62201
|
+
super({
|
|
62202
|
+
glProgram: program("board-copy", COPY_FRAGMENT),
|
|
62203
|
+
resolution: "inherit"
|
|
62204
|
+
});
|
|
62170
62205
|
}
|
|
62171
62206
|
set(radius, zoom) {
|
|
62172
62207
|
this.radius = radius;
|
|
@@ -62193,6 +62228,7 @@ var BoardShadowFilter = class extends Filter {
|
|
|
62193
62228
|
deviation = 0;
|
|
62194
62229
|
constructor() {
|
|
62195
62230
|
super({
|
|
62231
|
+
resolution: "inherit",
|
|
62196
62232
|
glProgram: program("board-shadow", SHADOW_FRAGMENT),
|
|
62197
62233
|
resources: { shadowUniforms: {
|
|
62198
62234
|
uOffset: {
|
|
@@ -62225,12 +62261,9 @@ var BoardShadowFilter = class extends Filter {
|
|
|
62225
62261
|
}
|
|
62226
62262
|
apply(filters, input, output, clearMode) {
|
|
62227
62263
|
const { copy } = shaderPasses();
|
|
62228
|
-
|
|
62229
|
-
filters.applyFilter(this, input,
|
|
62230
|
-
if (this.deviation > 0) gaussian(filters, shadow, output, this.deviation, clearMode);
|
|
62231
|
-
else filters.applyFilter(copy, shadow, output, clearMode);
|
|
62264
|
+
if (this.deviation > 0) gaussian(filters, input, output, this.deviation, clearMode, this);
|
|
62265
|
+
else filters.applyFilter(this, input, output, clearMode);
|
|
62232
62266
|
filters.applyFilter(copy, input, output, false);
|
|
62233
|
-
TexturePool.returnTexture(shadow);
|
|
62234
62267
|
}
|
|
62235
62268
|
getCanvasFilterString() {
|
|
62236
62269
|
return this.css;
|
|
@@ -62717,6 +62750,32 @@ function roundRectPoints(width, height, radius) {
|
|
|
62717
62750
|
worldPoint(width - r, 0)
|
|
62718
62751
|
];
|
|
62719
62752
|
}
|
|
62753
|
+
function shapeOutlinePoints(geometry, width, height, radius) {
|
|
62754
|
+
const p = (x, y) => worldPoint(x, y);
|
|
62755
|
+
switch (geometry) {
|
|
62756
|
+
case "ellipse": {
|
|
62757
|
+
const segments = 64;
|
|
62758
|
+
return Array.from({ length: 65 }, (_, index) => {
|
|
62759
|
+
const angle = -Math.PI / 2 + index / segments * Math.PI * 2;
|
|
62760
|
+
return p(width / 2 + Math.cos(angle) * width / 2, height / 2 + Math.sin(angle) * height / 2);
|
|
62761
|
+
});
|
|
62762
|
+
}
|
|
62763
|
+
case "diamond": return [
|
|
62764
|
+
p(width / 2, 0),
|
|
62765
|
+
p(width, height / 2),
|
|
62766
|
+
p(width / 2, height),
|
|
62767
|
+
p(0, height / 2),
|
|
62768
|
+
p(width / 2, 0)
|
|
62769
|
+
];
|
|
62770
|
+
case "triangle": return [
|
|
62771
|
+
p(width / 2, 0),
|
|
62772
|
+
p(width, height),
|
|
62773
|
+
p(0, height),
|
|
62774
|
+
p(width / 2, 0)
|
|
62775
|
+
];
|
|
62776
|
+
default: return roundRectPoints(width, height, radius);
|
|
62777
|
+
}
|
|
62778
|
+
}
|
|
62720
62779
|
const SHADOW_LAYERS = 5;
|
|
62721
62780
|
function traceCardOutline(graphics, rect, style, grow = 0) {
|
|
62722
62781
|
const x = rect.x - grow;
|
|
@@ -63261,7 +63320,8 @@ const modelCardRenderer = {
|
|
|
63261
63320
|
const BOARD_PLAY_MEDIA = "play-media";
|
|
63262
63321
|
function mediaPlayBadgeVisible(item, zoom, options) {
|
|
63263
63322
|
if (!options.materialized) return false;
|
|
63264
|
-
if (item.type === "video"
|
|
63323
|
+
if (item.type === "video") return item.props.time === void 0;
|
|
63324
|
+
if (item.type === "audio") return true;
|
|
63265
63325
|
if (isBoardModelItem(item)) return boardCardDetailed(zoom);
|
|
63266
63326
|
if (item.type !== "task" || !boardCardDetailed(zoom)) return false;
|
|
63267
63327
|
const artifact = featuredTaskArtifact(item.props.snapshot.artifacts);
|
|
@@ -64291,7 +64351,6 @@ const frameCardRenderer = {
|
|
|
64291
64351
|
};
|
|
64292
64352
|
//#endregion
|
|
64293
64353
|
//#region ../sdk/src/board/render/renderers/shape-card-renderer.ts
|
|
64294
|
-
const DEFAULT_ROUNDED_RADIUS = 8;
|
|
64295
64354
|
const partsByContainer$7 = /* @__PURE__ */ new WeakMap();
|
|
64296
64355
|
const pathCache = /* @__PURE__ */ new Map();
|
|
64297
64356
|
function parsedPath(d) {
|
|
@@ -64330,7 +64389,7 @@ function traceShapeOutline(graphics, props, width, height, radius) {
|
|
|
64330
64389
|
graphics.moveTo(width / 2, 0).lineTo(width, height).lineTo(0, height).closePath();
|
|
64331
64390
|
return;
|
|
64332
64391
|
case "rounded":
|
|
64333
|
-
graphics.roundRect(0, 0, width, height, radius ??
|
|
64392
|
+
graphics.roundRect(0, 0, width, height, radius ?? 8);
|
|
64334
64393
|
return;
|
|
64335
64394
|
case "path": {
|
|
64336
64395
|
const parsed = props.path ? parsedPath(props.path) : null;
|
|
@@ -64347,32 +64406,6 @@ function traceShapeOutline(graphics, props, width, height, radius) {
|
|
|
64347
64406
|
else graphics.rect(0, 0, width, height);
|
|
64348
64407
|
}
|
|
64349
64408
|
}
|
|
64350
|
-
function outlinePoints(geometry, width, height, radius) {
|
|
64351
|
-
const p = (x, y) => worldPoint(x, y);
|
|
64352
|
-
switch (geometry) {
|
|
64353
|
-
case "ellipse": {
|
|
64354
|
-
const segments = 64;
|
|
64355
|
-
return Array.from({ length: 65 }, (_, index) => {
|
|
64356
|
-
const angle = -Math.PI / 2 + index / segments * Math.PI * 2;
|
|
64357
|
-
return p(width / 2 + Math.cos(angle) * width / 2, height / 2 + Math.sin(angle) * height / 2);
|
|
64358
|
-
});
|
|
64359
|
-
}
|
|
64360
|
-
case "diamond": return [
|
|
64361
|
-
p(width / 2, 0),
|
|
64362
|
-
p(width, height / 2),
|
|
64363
|
-
p(width / 2, height),
|
|
64364
|
-
p(0, height / 2),
|
|
64365
|
-
p(width / 2, 0)
|
|
64366
|
-
];
|
|
64367
|
-
case "triangle": return [
|
|
64368
|
-
p(width / 2, 0),
|
|
64369
|
-
p(width, height),
|
|
64370
|
-
p(0, height),
|
|
64371
|
-
p(width / 2, 0)
|
|
64372
|
-
];
|
|
64373
|
-
default: return roundRectPoints(width, height, radius);
|
|
64374
|
-
}
|
|
64375
|
-
}
|
|
64376
64409
|
function sync$7(container, item, context) {
|
|
64377
64410
|
const parts = partsByContainer$7.get(container);
|
|
64378
64411
|
if (!parts) return;
|
|
@@ -64412,8 +64445,8 @@ function sync$7(container, item, context) {
|
|
|
64412
64445
|
const partial = style.trim !== void 0 && style.trim < 1;
|
|
64413
64446
|
if (strokeWidth > 0 && (!partial || style.trim)) {
|
|
64414
64447
|
if ((pattern || partial) && props.geometry !== "path") {
|
|
64415
|
-
const radius = style.radius ?? (props.geometry === "rounded" ?
|
|
64416
|
-
tracePolyline(parts.shape, trimPolyline(
|
|
64448
|
+
const radius = style.radius ?? (props.geometry === "rounded" ? 8 : 0);
|
|
64449
|
+
tracePolyline(parts.shape, trimPolyline(shapeOutlinePoints(props.geometry, width, height, radius), style.trim), pattern);
|
|
64417
64450
|
} else traceShapeOutline(parts.shape, props, width, height, style.radius);
|
|
64418
64451
|
parts.shape.stroke({
|
|
64419
64452
|
color: stroke,
|
|
@@ -65977,8 +66010,9 @@ function sync(container, item, context) {
|
|
|
65977
66010
|
text: duration ? `${title} · ${duration}` : title,
|
|
65978
66011
|
width
|
|
65979
66012
|
}, context);
|
|
66013
|
+
const live = context.mediaTexture?.(item.id) ?? null;
|
|
65980
66014
|
const key = context.assetKey(item);
|
|
65981
|
-
const texture = key ? context.getTexture(key) : null;
|
|
66015
|
+
const texture = live ?? (key ? context.getTexture(key) : null);
|
|
65982
66016
|
const elevation = cardElevation(context, item.id);
|
|
65983
66017
|
const sig = [
|
|
65984
66018
|
key ?? "",
|
|
@@ -65987,6 +66021,7 @@ function sync(container, item, context) {
|
|
|
65987
66021
|
height,
|
|
65988
66022
|
elevation,
|
|
65989
66023
|
boardCardDetailed(context.zoom),
|
|
66024
|
+
item.props.time === void 0,
|
|
65990
66025
|
context.themeKey
|
|
65991
66026
|
].join("|");
|
|
65992
66027
|
if (sig === parts.sig) return;
|
|
@@ -66026,7 +66061,7 @@ function sync(container, item, context) {
|
|
|
66026
66061
|
} : context.style);
|
|
66027
66062
|
}
|
|
66028
66063
|
parts.chrome.clear();
|
|
66029
|
-
if (boardCardDetailed(context.zoom)) drawMediaPlayKey(parts.chrome, screen.x + screen.width / 2, screen.y + screen.height / 2, Math.min(18, Math.min(screen.width, screen.height) * .16), context);
|
|
66064
|
+
if (boardCardDetailed(context.zoom) && item.props.time === void 0) drawMediaPlayKey(parts.chrome, screen.x + screen.width / 2, screen.y + screen.height / 2, Math.min(18, Math.min(screen.width, screen.height) * .16), context);
|
|
66030
66065
|
}
|
|
66031
66066
|
function drawFilmRails(graphics, width, height, rail, hole) {
|
|
66032
66067
|
const size = Math.min(FILM_HOLE, rail * .45);
|
|
@@ -66429,6 +66464,7 @@ const itemEnvelope = {
|
|
|
66429
66464
|
y: .5
|
|
66430
66465
|
}).describe("Rotation and scale origin as fractions of the size."),
|
|
66431
66466
|
opacity: ratio.default(1),
|
|
66467
|
+
visible: boolean().optional().describe("false hides the item and its children; key it on a timeline to show the item only for a span."),
|
|
66432
66468
|
style: BoardStyleSchema.default({}),
|
|
66433
66469
|
locked: boolean().optional(),
|
|
66434
66470
|
metadata: record(string(), unknown()).optional()
|
|
@@ -66578,7 +66614,8 @@ const mediaProps = {
|
|
|
66578
66614
|
};
|
|
66579
66615
|
const timedFileProps = {
|
|
66580
66616
|
...mediaProps,
|
|
66581
|
-
time: nonNegative.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline.")
|
|
66617
|
+
time: nonNegative.optional().describe("Playback position in milliseconds; animate props.time to play it on a timeline. It sounds while its time moves forward."),
|
|
66618
|
+
volume: ratio.optional().describe("Loudness from 0 to 1; defaults to 1. Animate it to fade.")
|
|
66582
66619
|
};
|
|
66583
66620
|
const BoardCropSchema = object({
|
|
66584
66621
|
x: ratio,
|
|
@@ -68352,6 +68389,12 @@ float luminance(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
|
|
|
68352
68389
|
//#endregion
|
|
68353
68390
|
//#region ../sdk/src/board/render/shader/program.ts
|
|
68354
68391
|
const BOARD_SHADER_ITERATIONS = 65536;
|
|
68392
|
+
const BOARD_SPRITE_PLACEMENTS = [
|
|
68393
|
+
"uCohubSpriteGeometry",
|
|
68394
|
+
"uCohubSpriteColor",
|
|
68395
|
+
"uCohubSpriteData",
|
|
68396
|
+
"uCohubSpriteRotation"
|
|
68397
|
+
];
|
|
68355
68398
|
const FORBIDDEN = [
|
|
68356
68399
|
[/#\s*(version|extension|pragma|line)\b/, "#version, #extension, #pragma and #line are set by Cohub"],
|
|
68357
68400
|
[/\b(uniform|attribute|varying|layout)\b/, "declare uniforms in shader.uniforms; inputs and outputs belong to Cohub"],
|
|
@@ -68442,7 +68485,8 @@ function declarations(input, stage) {
|
|
|
68442
68485
|
"precision highp float;",
|
|
68443
68486
|
"precision highp int;",
|
|
68444
68487
|
"precision highp sampler2D;",
|
|
68445
|
-
stage === "vertex" ? "#define COHUB_VERTEX 1" : "#define COHUB_FRAGMENT 1"
|
|
68488
|
+
stage === "vertex" ? "#define COHUB_VERTEX 1" : "#define COHUB_FRAGMENT 1",
|
|
68489
|
+
`#define COHUB_SPRITE_COLUMNS 256`
|
|
68446
68490
|
];
|
|
68447
68491
|
if (stage === "vertex") lines.push("#define dFdx(x) ((x) * 0.0)", "#define dFdy(x) ((x) * 0.0)", "#define fwidth(x) ((x) * 0.0)", "#define discard return vec4(0.0)");
|
|
68448
68492
|
lines.push("struct Board { float time; float delta; int frame; vec2 size; vec4 view; vec2 resolution; float zoom; float seed; float quality; float dark; };", "uniform Board board;");
|
|
@@ -68465,6 +68509,22 @@ vec4 cohubClip(vec2 local) {
|
|
|
68465
68509
|
return vec4((m * vec3(local, 1.0)).xy, 0.0, 1.0);
|
|
68466
68510
|
}`;
|
|
68467
68511
|
const VARYINGS = "vec2 vCohubUv; vec2 vCohubLocal; vec4 vCohubColor; vec4 vCohubData;";
|
|
68512
|
+
function spriteVertex(out) {
|
|
68513
|
+
return `in vec2 aPosition;
|
|
68514
|
+
${CLIP}
|
|
68515
|
+
${out}
|
|
68516
|
+
void cohubEmit(vec2 position, vec2 size, float rotation, vec4 color, vec4 data) {
|
|
68517
|
+
vec2 corner = (aPosition - 0.5) * size;
|
|
68518
|
+
float c = cos(rotation);
|
|
68519
|
+
float r = sin(rotation);
|
|
68520
|
+
vec2 local = position + vec2(corner.x * c - corner.y * r, corner.x * r + corner.y * c);
|
|
68521
|
+
gl_Position = cohubClip(local);
|
|
68522
|
+
vCohubUv = aPosition;
|
|
68523
|
+
vCohubLocal = local;
|
|
68524
|
+
vCohubColor = color;
|
|
68525
|
+
vCohubData = data;
|
|
68526
|
+
}`;
|
|
68527
|
+
}
|
|
68468
68528
|
function vertexMain(kind) {
|
|
68469
68529
|
const out = VARYINGS.split(" ").reduce((text, part, index) => text + (index % 2 ? `${part} ` : `out ${part} `), "");
|
|
68470
68530
|
if (kind === "filter") return `in vec2 aPosition;
|
|
@@ -68481,22 +68541,20 @@ void main() {
|
|
|
68481
68541
|
vCohubColor = vec4(1.0);
|
|
68482
68542
|
vCohubData = vec4(0.0);
|
|
68483
68543
|
}`;
|
|
68484
|
-
if (kind === "
|
|
68485
|
-
${
|
|
68486
|
-
|
|
68544
|
+
if (kind === "placed") return `${spriteVertex(out)}
|
|
68545
|
+
${BOARD_SPRITE_PLACEMENTS.map((name) => `uniform sampler2D ${name};`).join("\n")}
|
|
68546
|
+
void main() {
|
|
68547
|
+
ivec2 at = ivec2(gl_InstanceID % COHUB_SPRITE_COLUMNS, gl_InstanceID / COHUB_SPRITE_COLUMNS);
|
|
68548
|
+
vec4 placed = texelFetch(uCohubSpriteGeometry, at, 0);
|
|
68549
|
+
if (placed.z <= 0.0 || placed.w <= 0.0) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }
|
|
68550
|
+
cohubEmit(placed.xy, placed.zw, texelFetch(uCohubSpriteRotation, at, 0).x, texelFetch(uCohubSpriteColor, at, 0), texelFetch(uCohubSpriteData, at, 0));
|
|
68551
|
+
}`;
|
|
68552
|
+
if (kind === "sprites") return `${spriteVertex(out)}
|
|
68487
68553
|
void main() {
|
|
68488
68554
|
cohubIterations = 0;
|
|
68489
68555
|
Sprite s = sprite(gl_InstanceID);
|
|
68490
68556
|
if (!s.visible || s.size.x <= 0.0 || s.size.y <= 0.0) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); return; }
|
|
68491
|
-
|
|
68492
|
-
float c = cos(s.rotation);
|
|
68493
|
-
float r = sin(s.rotation);
|
|
68494
|
-
vec2 local = s.position + vec2(corner.x * c - corner.y * r, corner.x * r + corner.y * c);
|
|
68495
|
-
gl_Position = cohubClip(local);
|
|
68496
|
-
vCohubUv = aPosition;
|
|
68497
|
-
vCohubLocal = local;
|
|
68498
|
-
vCohubColor = s.color;
|
|
68499
|
-
vCohubData = s.data;
|
|
68557
|
+
cohubEmit(s.position, s.size, s.rotation, s.color, s.data);
|
|
68500
68558
|
}`;
|
|
68501
68559
|
return `in vec2 aPosition;
|
|
68502
68560
|
uniform vec4 uCohubGeometry;
|
|
@@ -68512,7 +68570,25 @@ void main() {
|
|
|
68512
68570
|
}`;
|
|
68513
68571
|
}
|
|
68514
68572
|
function fragmentMain(kind) {
|
|
68515
|
-
|
|
68573
|
+
const inputs = VARYINGS.split(" ").reduce((text, part, index) => text + (index % 2 ? `${part} ` : `in ${part} `), "");
|
|
68574
|
+
if (kind === "place") return `uniform int uCohubSpriteCount;
|
|
68575
|
+
layout(location = 0) out vec4 cohubGeometry;
|
|
68576
|
+
layout(location = 1) out vec4 cohubColor;
|
|
68577
|
+
layout(location = 2) out vec4 cohubData;
|
|
68578
|
+
layout(location = 3) out vec4 cohubRotation;
|
|
68579
|
+
void main() {
|
|
68580
|
+
cohubIterations = 0;
|
|
68581
|
+
ivec2 at = ivec2(gl_FragCoord.xy);
|
|
68582
|
+
int id = at.y * COHUB_SPRITE_COLUMNS + at.x;
|
|
68583
|
+
if (id >= uCohubSpriteCount) { cohubGeometry = vec4(0.0); return; }
|
|
68584
|
+
Sprite s = sprite(id);
|
|
68585
|
+
bool shown = s.visible && s.size.x > 0.0 && s.size.y > 0.0;
|
|
68586
|
+
cohubGeometry = shown ? vec4(s.position, s.size) : vec4(0.0);
|
|
68587
|
+
cohubColor = s.color;
|
|
68588
|
+
cohubData = s.data;
|
|
68589
|
+
cohubRotation = vec4(s.rotation, 0.0, 0.0, 0.0);
|
|
68590
|
+
}`;
|
|
68591
|
+
return `${inputs}
|
|
68516
68592
|
${kind === "filter" ? "in vec2 vTextureCoord;" : "uniform vec4 uColor;"}
|
|
68517
68593
|
out vec4 finalColor;
|
|
68518
68594
|
void main() {
|
|
@@ -68528,16 +68604,18 @@ function lineCount(text) {
|
|
|
68528
68604
|
function buildBoardShaderProgram(input) {
|
|
68529
68605
|
const { code, includes } = prepareBoardShaderSource(input.glsl);
|
|
68530
68606
|
const library = includes.map((name) => BOARD_SHADER_LIBRARY[name]).join("\n");
|
|
68531
|
-
const
|
|
68532
|
-
const head = `${declarations(input,
|
|
68533
|
-
const main = name === "vertex" ? vertexMain(input.kind) : fragmentMain(input.kind);
|
|
68607
|
+
const author = (role, main) => {
|
|
68608
|
+
const head = `${declarations(input, role)}\n${library}`;
|
|
68534
68609
|
return {
|
|
68535
68610
|
source: `${head}\n${code}\n${main}\n`,
|
|
68536
68611
|
firstLine: lineCount(head) + 1
|
|
68537
68612
|
};
|
|
68538
68613
|
};
|
|
68539
|
-
const vertex =
|
|
68540
|
-
|
|
68614
|
+
const vertex = input.kind === "sprites" ? author("vertex", vertexMain(input.kind)) : {
|
|
68615
|
+
source: `${declarations(input, "vertex")}\n${vertexMain(input.kind)}\n`,
|
|
68616
|
+
firstLine: 1
|
|
68617
|
+
};
|
|
68618
|
+
const fragment = author(input.kind === "place" ? "vertex" : "fragment", fragmentMain(input.kind));
|
|
68541
68619
|
return {
|
|
68542
68620
|
vertex: vertex.source,
|
|
68543
68621
|
fragment: fragment.source,
|
|
@@ -68685,6 +68763,51 @@ function check(renderer, program, label) {
|
|
|
68685
68763
|
}
|
|
68686
68764
|
if (error) throw new Error(error);
|
|
68687
68765
|
}
|
|
68766
|
+
const placing = /* @__PURE__ */ new WeakMap();
|
|
68767
|
+
function canPlaceSprites(renderer) {
|
|
68768
|
+
let supported = placing.get(renderer);
|
|
68769
|
+
if (supported === void 0) {
|
|
68770
|
+
const gl = renderer.type === RendererType.WEBGL ? renderer.gl : null;
|
|
68771
|
+
supported = Boolean(gl?.getExtension("EXT_color_buffer_float") && gl.getParameter(gl.MAX_DRAW_BUFFERS) >= BOARD_SPRITE_PLACEMENTS.length);
|
|
68772
|
+
placing.set(renderer, supported);
|
|
68773
|
+
}
|
|
68774
|
+
return supported;
|
|
68775
|
+
}
|
|
68776
|
+
function createPlacement(mesh, uniforms, sprites) {
|
|
68777
|
+
mesh.mesh.blendMode = "none";
|
|
68778
|
+
const height = Math.ceil(sprites / 256);
|
|
68779
|
+
const textures = BOARD_SPRITE_PLACEMENTS.map(() => new TextureSource({
|
|
68780
|
+
width: 256,
|
|
68781
|
+
height,
|
|
68782
|
+
resolution: 1,
|
|
68783
|
+
format: "rgba32float",
|
|
68784
|
+
scaleMode: "nearest",
|
|
68785
|
+
autoGenerateMipmaps: false
|
|
68786
|
+
}));
|
|
68787
|
+
return {
|
|
68788
|
+
mesh,
|
|
68789
|
+
uniforms,
|
|
68790
|
+
target: new RenderTarget({
|
|
68791
|
+
colorTextures: textures,
|
|
68792
|
+
width: 256,
|
|
68793
|
+
height,
|
|
68794
|
+
resolution: 1
|
|
68795
|
+
}),
|
|
68796
|
+
textures
|
|
68797
|
+
};
|
|
68798
|
+
}
|
|
68799
|
+
function destroyPlacement(renderer, placement) {
|
|
68800
|
+
const system = renderer.renderTarget;
|
|
68801
|
+
const gpu = system._gpuRenderTargetHash?.[placement.target.uid];
|
|
68802
|
+
if (gpu && system._gpuRenderTargetHash) {
|
|
68803
|
+
system._gpuRenderTargetHash[placement.target.uid] = null;
|
|
68804
|
+
system.adaptor?.destroyGpuRenderTarget(gpu);
|
|
68805
|
+
}
|
|
68806
|
+
system._renderSurfaceToRenderTargetHash?.delete(placement.target);
|
|
68807
|
+
placement.target.destroy();
|
|
68808
|
+
for (const texture of placement.textures) texture.destroy();
|
|
68809
|
+
destroyBoardShaderMesh(placement.mesh);
|
|
68810
|
+
}
|
|
68688
68811
|
function boardUniforms(parameters, uniforms) {
|
|
68689
68812
|
const vec = (size) => new Float32Array(size);
|
|
68690
68813
|
const fields = {
|
|
@@ -68732,6 +68855,10 @@ function boardUniforms(parameters, uniforms) {
|
|
|
68732
68855
|
value: vec(4),
|
|
68733
68856
|
type: "vec4<f32>"
|
|
68734
68857
|
},
|
|
68858
|
+
uCohubSpriteCount: {
|
|
68859
|
+
value: 0,
|
|
68860
|
+
type: "i32"
|
|
68861
|
+
},
|
|
68735
68862
|
uCohubRegion: {
|
|
68736
68863
|
value: vec(4),
|
|
68737
68864
|
type: "vec4<f32>"
|
|
@@ -68843,6 +68970,8 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68843
68970
|
const meshes = [];
|
|
68844
68971
|
const filters = [];
|
|
68845
68972
|
const container = layer === "filter" ? null : new Container({ label: `board-shader-${label}` });
|
|
68973
|
+
const place = canPlaceSprites(renderer);
|
|
68974
|
+
let placementsStale = true;
|
|
68846
68975
|
shader.passes.forEach((pass, index) => {
|
|
68847
68976
|
const name = `${label} pass ${index + 1}`;
|
|
68848
68977
|
if (layer === "filter") {
|
|
@@ -68858,21 +68987,36 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68858
68987
|
cohubUniforms: group,
|
|
68859
68988
|
...textures
|
|
68860
68989
|
},
|
|
68861
|
-
padding: 0
|
|
68990
|
+
padding: 0,
|
|
68991
|
+
resolution: "inherit"
|
|
68862
68992
|
});
|
|
68863
68993
|
filters.push(filter);
|
|
68864
68994
|
return;
|
|
68865
68995
|
}
|
|
68866
68996
|
const sprites = pass.sprites ?? 0;
|
|
68867
|
-
|
|
68997
|
+
let placement = null;
|
|
68998
|
+
if (sprites && place) {
|
|
68999
|
+
const own = boardUniforms(parameters, uniforms);
|
|
69000
|
+
placement = createPlacement(boardShaderMesh("board-shader-place", program("place", pass.glsl, name), {
|
|
69001
|
+
cohubUniforms: own,
|
|
69002
|
+
...textures
|
|
69003
|
+
}), own, sprites);
|
|
69004
|
+
}
|
|
69005
|
+
const kind = !sprites ? "box" : placement ? "placed" : "sprites";
|
|
69006
|
+
const resources = {
|
|
68868
69007
|
cohubUniforms: group,
|
|
68869
69008
|
...textures
|
|
68870
|
-
}
|
|
69009
|
+
};
|
|
69010
|
+
placement?.textures.forEach((texture, slot) => {
|
|
69011
|
+
resources[BOARD_SPRITE_PLACEMENTS[slot]] = texture;
|
|
69012
|
+
});
|
|
69013
|
+
const drawn = boardShaderMesh("board-shader", program(kind, pass.glsl, name), resources, boardQuadGeometry(Math.max(1, sprites)));
|
|
68871
69014
|
drawn.mesh.blendMode = pass.blend ?? "normal";
|
|
68872
69015
|
container?.addChild(drawn.mesh);
|
|
68873
69016
|
meshes.push({
|
|
68874
69017
|
...drawn,
|
|
68875
|
-
sprites
|
|
69018
|
+
sprites,
|
|
69019
|
+
placement
|
|
68876
69020
|
});
|
|
68877
69021
|
});
|
|
68878
69022
|
let state = null;
|
|
@@ -68954,6 +69098,53 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68954
69098
|
}
|
|
68955
69099
|
target.update();
|
|
68956
69100
|
}
|
|
69101
|
+
function advance(target, state, frame, catchUp) {
|
|
69102
|
+
const wanted = Math.floor(frame.time / STEP_MS);
|
|
69103
|
+
if (wanted < state.steps || state.steps < 0) {
|
|
69104
|
+
for (const texture of [state.read, state.write]) target.render({
|
|
69105
|
+
container: blank,
|
|
69106
|
+
target: texture,
|
|
69107
|
+
clear: true,
|
|
69108
|
+
clearColor: [
|
|
69109
|
+
0,
|
|
69110
|
+
0,
|
|
69111
|
+
0,
|
|
69112
|
+
0
|
|
69113
|
+
]
|
|
69114
|
+
});
|
|
69115
|
+
state.steps = Math.max(0, wanted - MAX_REPLAY);
|
|
69116
|
+
}
|
|
69117
|
+
if (!catchUp && wanted - state.steps > MAX_LAG) state.steps = wanted - STEPS_PER_FRAME;
|
|
69118
|
+
const limit = catchUp ? Number.POSITIVE_INFINITY : STEPS_PER_FRAME;
|
|
69119
|
+
let ran = 0;
|
|
69120
|
+
while (state.steps < wanted && ran < limit) {
|
|
69121
|
+
fill(state.uniforms, frame, {
|
|
69122
|
+
x: 0,
|
|
69123
|
+
y: 0,
|
|
69124
|
+
width: state.write.width,
|
|
69125
|
+
height: state.write.height
|
|
69126
|
+
}, state.steps);
|
|
69127
|
+
state.simulate.shader.resources.uCohubState = state.read.source;
|
|
69128
|
+
target.render({
|
|
69129
|
+
container: state.simulate.mesh,
|
|
69130
|
+
target: state.write,
|
|
69131
|
+
clear: true
|
|
69132
|
+
});
|
|
69133
|
+
[state.read, state.write] = [state.write, state.read];
|
|
69134
|
+
state.steps++;
|
|
69135
|
+
ran++;
|
|
69136
|
+
}
|
|
69137
|
+
const source = state.read.source;
|
|
69138
|
+
for (const { shader, placement } of meshes) {
|
|
69139
|
+
shader.resources.uCohubState = source;
|
|
69140
|
+
if (placement) placement.mesh.shader.resources.uCohubState = source;
|
|
69141
|
+
}
|
|
69142
|
+
for (const filter of filters) filter.resources.uCohubState = source;
|
|
69143
|
+
return {
|
|
69144
|
+
ran,
|
|
69145
|
+
behind: state.steps < wanted
|
|
69146
|
+
};
|
|
69147
|
+
}
|
|
68957
69148
|
return {
|
|
68958
69149
|
layer,
|
|
68959
69150
|
container,
|
|
@@ -68961,21 +69152,35 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68961
69152
|
surfaces,
|
|
68962
69153
|
animated: hasState,
|
|
68963
69154
|
update(frame) {
|
|
68964
|
-
fill(group, frame, frame.region);
|
|
68965
|
-
time = frame.time;
|
|
68966
|
-
last = frame;
|
|
68967
69155
|
if (frame.quality !== quality) {
|
|
68968
69156
|
quality = frame.quality;
|
|
68969
69157
|
for (const { geometry, sprites } of meshes) if (sprites) geometry.instanceCount = Math.max(1, Math.round(sprites * quality));
|
|
68970
69158
|
}
|
|
69159
|
+
fill(group, frame, frame.region);
|
|
69160
|
+
for (const { geometry, placement } of meshes) {
|
|
69161
|
+
if (!placement) continue;
|
|
69162
|
+
placement.uniforms.uniforms.uCohubSpriteCount = geometry.instanceCount;
|
|
69163
|
+
fill(placement.uniforms, frame, {
|
|
69164
|
+
x: 0,
|
|
69165
|
+
y: 0,
|
|
69166
|
+
width: 256,
|
|
69167
|
+
height: Math.ceil(geometry.instanceCount / 256)
|
|
69168
|
+
});
|
|
69169
|
+
}
|
|
69170
|
+
time = frame.time;
|
|
69171
|
+
last = frame;
|
|
69172
|
+
placementsStale = true;
|
|
68971
69173
|
},
|
|
68972
69174
|
prepare(target, options) {
|
|
68973
|
-
if (!
|
|
68974
|
-
const
|
|
68975
|
-
|
|
68976
|
-
|
|
68977
|
-
|
|
68978
|
-
|
|
69175
|
+
if (!last) return false;
|
|
69176
|
+
const stepped = state ? advance(target, state, last, options?.catchUp === true) : {
|
|
69177
|
+
ran: 0,
|
|
69178
|
+
behind: false
|
|
69179
|
+
};
|
|
69180
|
+
if (placementsStale || stepped.ran) {
|
|
69181
|
+
for (const { placement } of meshes) if (placement) target.render({
|
|
69182
|
+
container: placement.mesh.mesh,
|
|
69183
|
+
target: placement.target,
|
|
68979
69184
|
clear: true,
|
|
68980
69185
|
clearColor: [
|
|
68981
69186
|
0,
|
|
@@ -68984,38 +69189,17 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
68984
69189
|
0
|
|
68985
69190
|
]
|
|
68986
69191
|
});
|
|
68987
|
-
|
|
69192
|
+
placementsStale = false;
|
|
68988
69193
|
}
|
|
68989
|
-
|
|
68990
|
-
const limit = options?.catchUp ? Number.POSITIVE_INFINITY : STEPS_PER_FRAME;
|
|
68991
|
-
let ran = 0;
|
|
68992
|
-
while (state.steps < wanted && ran < limit) {
|
|
68993
|
-
fill(state.uniforms, last, {
|
|
68994
|
-
x: 0,
|
|
68995
|
-
y: 0,
|
|
68996
|
-
width: state.write.width,
|
|
68997
|
-
height: state.write.height
|
|
68998
|
-
}, state.steps);
|
|
68999
|
-
state.simulate.shader.resources.uCohubState = state.read.source;
|
|
69000
|
-
target.render({
|
|
69001
|
-
container: state.simulate.mesh,
|
|
69002
|
-
target: state.write,
|
|
69003
|
-
clear: true
|
|
69004
|
-
});
|
|
69005
|
-
[state.read, state.write] = [state.write, state.read];
|
|
69006
|
-
state.steps++;
|
|
69007
|
-
ran++;
|
|
69008
|
-
}
|
|
69009
|
-
const source = state.read.source;
|
|
69010
|
-
for (const { shader } of meshes) shader.resources.uCohubState = source;
|
|
69011
|
-
for (const filter of filters) filter.resources.uCohubState = source;
|
|
69012
|
-
return state.steps < wanted;
|
|
69194
|
+
return stepped.behind;
|
|
69013
69195
|
},
|
|
69014
69196
|
setSurfaces(texture, region) {
|
|
69015
|
-
|
|
69016
|
-
|
|
69017
|
-
|
|
69018
|
-
|
|
69197
|
+
const shaders = [...meshes.flatMap(({ shader, placement }) => placement ? [shader, placement.mesh.shader] : [shader]), ...filters];
|
|
69198
|
+
if (state) shaders.push(state.simulate.shader);
|
|
69199
|
+
for (const target of shaders) target.resources.uCohubSurfaces = texture.source;
|
|
69200
|
+
const groups = [group, ...meshes.flatMap(({ placement }) => placement ? [placement.uniforms] : [])];
|
|
69201
|
+
if (state) groups.push(state.uniforms);
|
|
69202
|
+
for (const target of groups) {
|
|
69019
69203
|
setUniform(target, "uCohubSurfaceRegion", [
|
|
69020
69204
|
region.x,
|
|
69021
69205
|
region.y,
|
|
@@ -69024,9 +69208,13 @@ function createBoardShaderLayer(renderer, shader, parameters, label) {
|
|
|
69024
69208
|
]);
|
|
69025
69209
|
target.update();
|
|
69026
69210
|
}
|
|
69211
|
+
placementsStale = true;
|
|
69027
69212
|
},
|
|
69028
69213
|
destroy() {
|
|
69029
|
-
for (const drawn of meshes)
|
|
69214
|
+
for (const drawn of meshes) {
|
|
69215
|
+
destroyBoardShaderMesh(drawn);
|
|
69216
|
+
if (drawn.placement) destroyPlacement(renderer, drawn.placement);
|
|
69217
|
+
}
|
|
69030
69218
|
container?.destroy();
|
|
69031
69219
|
for (const filter of filters) filter.destroy();
|
|
69032
69220
|
blank.destroy();
|
|
@@ -69260,35 +69448,49 @@ const SKIPPED = /* @__PURE__ */ new Set([
|
|
|
69260
69448
|
"frame",
|
|
69261
69449
|
"arrow",
|
|
69262
69450
|
"draw",
|
|
69263
|
-
"effect"
|
|
69451
|
+
"effect",
|
|
69452
|
+
"text"
|
|
69264
69453
|
]);
|
|
69454
|
+
const LIGHT_BLENDS = /* @__PURE__ */ new Set(["screen", "add"]);
|
|
69265
69455
|
const SURFACE_EDGE = 512;
|
|
69456
|
+
const SURFACE_MARGIN = .25;
|
|
69457
|
+
const SURFACE_COARSEN = 1.5;
|
|
69458
|
+
function surfaceOutline(item) {
|
|
69459
|
+
const { width, height } = item.frame;
|
|
69460
|
+
const radius = item.style?.radius;
|
|
69461
|
+
if (item.type === "shape") {
|
|
69462
|
+
const { geometry } = item.props;
|
|
69463
|
+
return shapeOutlinePoints(geometry, width, height, radius ?? (geometry === "rounded" ? 8 : 0));
|
|
69464
|
+
}
|
|
69465
|
+
return roundRectPoints(width, height, radius ?? 0);
|
|
69466
|
+
}
|
|
69266
69467
|
function boardSurfaceOutlines(scene, owner, world, worldToLocal, candidates) {
|
|
69267
69468
|
const prefix = scriptTemporaryPrefix(owner);
|
|
69268
69469
|
const outlines = [];
|
|
69269
69470
|
const items = candidates ? [...candidates].map((id) => scene.get(id)).filter((item) => Boolean(item)) : scene.items;
|
|
69270
69471
|
for (const item of items) {
|
|
69271
|
-
if (item.id === owner || SKIPPED.has(item.type) || item.id.startsWith(prefix) || scene.opacity(item.id) <= 0) continue;
|
|
69472
|
+
if (item.id === owner || SKIPPED.has(item.type) || LIGHT_BLENDS.has(item.style?.blend ?? "") || item.id.startsWith(prefix) || scene.opacity(item.id) <= 0) continue;
|
|
69272
69473
|
if (!rectsIntersect(itemBounds(item.frame), world)) continue;
|
|
69273
|
-
const
|
|
69474
|
+
const { width, height } = item.frame;
|
|
69274
69475
|
const points = [];
|
|
69275
|
-
|
|
69276
|
-
const
|
|
69277
|
-
return [.5 + Math.cos(angle) / 2, .5 + Math.sin(angle) / 2];
|
|
69278
|
-
}) : [
|
|
69279
|
-
[0, 0],
|
|
69280
|
-
[1, 0],
|
|
69281
|
-
[1, 1],
|
|
69282
|
-
[0, 1]
|
|
69283
|
-
];
|
|
69284
|
-
for (const [u, v] of corners) {
|
|
69285
|
-
const local = applyMatrix$1(worldToLocal, framePoint(item.frame, u, v));
|
|
69476
|
+
for (const point of surfaceOutline(item)) {
|
|
69477
|
+
const local = applyMatrix$1(worldToLocal, framePoint(item.frame, width ? point.x / width : 0, height ? point.y / height : 0));
|
|
69286
69478
|
points.push(local.x, local.y);
|
|
69287
69479
|
}
|
|
69288
69480
|
outlines.push(points);
|
|
69289
69481
|
}
|
|
69290
69482
|
return outlines;
|
|
69291
69483
|
}
|
|
69484
|
+
function boardSurfaceRegion(previous, region, margin) {
|
|
69485
|
+
if (!margin) return region;
|
|
69486
|
+
if (previous && previous.x <= region.x && previous.y <= region.y && previous.x + previous.width >= region.x + region.width && previous.y + previous.height >= region.y + region.height && previous.width <= region.width * (1 + 2 * margin) * SURFACE_COARSEN) return previous;
|
|
69487
|
+
return {
|
|
69488
|
+
x: region.x - region.width * margin,
|
|
69489
|
+
y: region.y - region.height * margin,
|
|
69490
|
+
width: region.width * (1 + 2 * margin),
|
|
69491
|
+
height: region.height * (1 + 2 * margin)
|
|
69492
|
+
};
|
|
69493
|
+
}
|
|
69292
69494
|
function parameterValues(parameters, params, color) {
|
|
69293
69495
|
const values = {};
|
|
69294
69496
|
for (const [name, spec] of Object.entries(parameters ?? {})) {
|
|
@@ -69378,7 +69580,9 @@ function createBoardShaderLayers() {
|
|
|
69378
69580
|
uniforms: output.uniforms
|
|
69379
69581
|
});
|
|
69380
69582
|
if (entry.layer.surfaces) {
|
|
69381
|
-
const {
|
|
69583
|
+
const { localToWorld } = placement;
|
|
69584
|
+
const margin = owner.root ? SURFACE_MARGIN : 0;
|
|
69585
|
+
const region = boardSurfaceRegion(entry.surfaces?.region ?? null, placement.region, margin);
|
|
69382
69586
|
const corners = [
|
|
69383
69587
|
applyMatrix$1(localToWorld, region),
|
|
69384
69588
|
applyMatrix$1(localToWorld, {
|
|
@@ -69402,7 +69606,7 @@ function createBoardShaderLayers() {
|
|
|
69402
69606
|
width: Math.max(...xs) - Math.min(...xs),
|
|
69403
69607
|
height: Math.max(...ys) - Math.min(...ys)
|
|
69404
69608
|
};
|
|
69405
|
-
const edge = Math.max(64, Math.round(SURFACE_EDGE * host.quality));
|
|
69609
|
+
const edge = Math.max(64, Math.round(SURFACE_EDGE * (1 + 2 * margin) * host.quality));
|
|
69406
69610
|
const key = `${[
|
|
69407
69611
|
region.x,
|
|
69408
69612
|
region.y,
|
|
@@ -70046,9 +70250,9 @@ async function fetchTexture(query) {
|
|
|
70046
70250
|
const bitmap = await createImageBitmap(await response.blob(), { premultiplyAlpha: "premultiply" });
|
|
70047
70251
|
return new Texture({ source: new ImageSource({ resource: bitmap }) });
|
|
70048
70252
|
}
|
|
70049
|
-
async function loadTextures(items, scale, maxBytes) {
|
|
70253
|
+
async function loadTextures(items, scale, maxBytes, overrides) {
|
|
70050
70254
|
const exportKey = (item) => {
|
|
70051
|
-
const key = boardAssetKey(item);
|
|
70255
|
+
const key = overrides[item.id] ?? boardAssetKey(item);
|
|
70052
70256
|
return key && boardAssetKeySource(key)?.media !== "model" ? key : null;
|
|
70053
70257
|
};
|
|
70054
70258
|
const selection = selectBoardExportAssets([...items], exportKey, {
|
|
@@ -70151,13 +70355,15 @@ globalThis.cohubBoardGpu = {
|
|
|
70151
70355
|
const prepared = prepareBoardExport(document, options);
|
|
70152
70356
|
if (!prepared) throw new Error("Nothing to export: the region contains no items.");
|
|
70153
70357
|
const visible = prepared.plan.items.filter((item) => prepared.scene.opacity(item.id) > 0);
|
|
70154
|
-
const
|
|
70358
|
+
const overrides = frame.assetKeys ?? {};
|
|
70359
|
+
const loaded = frame.withImages ? await loadTextures(visible, prepared.plan.scale, frame.imageMemory, overrides) : /* @__PURE__ */ new Map();
|
|
70155
70360
|
if (frame.withImages && frame.background === "paper" && document.board.background.image && background === void 0) background = await fetchTexture("background=1").catch(() => null);
|
|
70156
70361
|
const result = renderBoardExport(renderer, document, {
|
|
70157
70362
|
...options,
|
|
70158
70363
|
...theme,
|
|
70159
70364
|
background: frame.background,
|
|
70160
70365
|
textures: loaded,
|
|
70366
|
+
assetKey: (item) => overrides[item.id] ?? boardAssetKey(item),
|
|
70161
70367
|
backgroundTexture: frame.background === "paper" ? background ?? void 0 : void 0,
|
|
70162
70368
|
shaderLayers: session.layers
|
|
70163
70369
|
});
|