oda-engine 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.
- package/README.md +151 -2
- package/bin/nowhere.mjs +352 -0
- package/lib/account.mjs +57 -0
- package/lib/agentModules.mjs +57 -0
- package/lib/devServer.mjs +351 -0
- package/lib/headless.mjs +231 -0
- package/lib/headlessPreview.mjs +212 -0
- package/lib/keys.mjs +517 -0
- package/lib/make.mjs +855 -0
- package/lib/mcp.mjs +537 -0
- package/lib/open.mjs +22 -0
- package/lib/preview.mjs +87 -0
- package/lib/previewRpc.mjs +134 -0
- package/lib/project.mjs +359 -0
- package/lib/publishFlow.mjs +131 -0
- package/lib/resources.mjs +50 -0
- package/lib/rules.mjs +60 -0
- package/lib/scaffold.mjs +42 -0
- package/lib/setup.mjs +59 -0
- package/lib/tools.mjs +668 -0
- package/package.json +51 -4
- package/template/game.config.json +9 -0
- package/template/scene.json +4 -0
- package/template/src/main.ts +11 -0
- package/vendor/DOCS.md +447 -0
- package/vendor/agent/appRun.mjs +520 -0
- package/vendor/agent/assets/brief.mjs +242 -0
- package/vendor/agent/assets/collider.mjs +531 -0
- package/vendor/agent/assets/environments/index.mjs +12 -0
- package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
- package/vendor/agent/assets/fetch.mjs +168 -0
- package/vendor/agent/assets/footprint.mjs +13 -0
- package/vendor/agent/assets/gltf.mjs +547 -0
- package/vendor/agent/assets/hdr.mjs +269 -0
- package/vendor/agent/assets/imageOps.mjs +171 -0
- package/vendor/agent/assets/images/codex.mjs +307 -0
- package/vendor/agent/assets/images/fal.mjs +75 -0
- package/vendor/agent/assets/images/gemini.mjs +84 -0
- package/vendor/agent/assets/images/index.mjs +25 -0
- package/vendor/agent/assets/images/openai.mjs +75 -0
- package/vendor/agent/assets/images/stability.mjs +71 -0
- package/vendor/agent/assets/images/views.mjs +31 -0
- package/vendor/agent/assets/import.mjs +1352 -0
- package/vendor/agent/assets/inspect.mjs +465 -0
- package/vendor/agent/assets/jobs.mjs +196 -0
- package/vendor/agent/assets/ktx2.mjs +290 -0
- package/vendor/agent/assets/ledger.mjs +466 -0
- package/vendor/agent/assets/net.mjs +254 -0
- package/vendor/agent/assets/prices.json +39 -0
- package/vendor/agent/assets/providers/fal.mjs +115 -0
- package/vendor/agent/assets/providers/index.mjs +22 -0
- package/vendor/agent/assets/providers/meshy.mjs +119 -0
- package/vendor/agent/assets/providers/tripo.mjs +188 -0
- package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
- package/vendor/agent/assets/sources/index.mjs +23 -0
- package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
- package/vendor/agent/assets/sources/polypizza.mjs +121 -0
- package/vendor/agent/assets/splat.mjs +631 -0
- package/vendor/agent/assets/targets.mjs +122 -0
- package/vendor/agent/assets/tile.mjs +261 -0
- package/vendor/agent/assets/unzip.mjs +180 -0
- package/vendor/agent/blender/cleanup.py +360 -0
- package/vendor/agent/blender/convert.py +167 -0
- package/vendor/agent/blender/find.mjs +192 -0
- package/vendor/agent/blender/nw_export.py +104 -0
- package/vendor/agent/blender/nw_rubric.py +426 -0
- package/vendor/agent/blender/run.mjs +193 -0
- package/vendor/agent/blender/runner.py +252 -0
- package/vendor/agent/blender/sheet.py +743 -0
- package/vendor/agent/depth.mjs +134 -0
- package/vendor/agent/director/board.mjs +451 -0
- package/vendor/agent/director/contracts.mjs +663 -0
- package/vendor/agent/director/director.mjs +2365 -0
- package/vendor/agent/director/estimate.mjs +200 -0
- package/vendor/agent/director/gate.mjs +802 -0
- package/vendor/agent/director/limits.json +16 -0
- package/vendor/agent/director/methods.mjs +457 -0
- package/vendor/agent/director/policy.json +33 -0
- package/vendor/agent/director/prompts.mjs +244 -0
- package/vendor/agent/director/reading.mjs +341 -0
- package/vendor/agent/director/router.mjs +184 -0
- package/vendor/agent/director/seams.mjs +243 -0
- package/vendor/agent/director/session.mjs +643 -0
- package/vendor/agent/director/store.mjs +119 -0
- package/vendor/agent/director/taskGate.mjs +110 -0
- package/vendor/agent/director/teamLedger.mjs +118 -0
- package/vendor/agent/director/triage.mjs +63 -0
- package/vendor/agent/downloads.cjs +363 -0
- package/vendor/agent/flow.mjs +78 -0
- package/vendor/agent/guard.mjs +613 -0
- package/vendor/agent/host.mjs +1736 -0
- package/vendor/agent/language.mjs +58 -0
- package/vendor/agent/ledger.mjs +360 -0
- package/vendor/agent/locale.cjs +186 -0
- package/vendor/agent/loop/capacity.mjs +74 -0
- package/vendor/agent/loop/compose.mjs +127 -0
- package/vendor/agent/loop/gate.mjs +205 -0
- package/vendor/agent/loop/judge.mjs +189 -0
- package/vendor/agent/loop/levels.mjs +273 -0
- package/vendor/agent/loop/state.mjs +358 -0
- package/vendor/agent/notes.cjs +278 -0
- package/vendor/agent/pace.mjs +258 -0
- package/vendor/agent/panels.mjs +431 -0
- package/vendor/agent/prompt.mjs +342 -0
- package/vendor/agent/reference/board.mjs +410 -0
- package/vendor/agent/reference/compose.mjs +364 -0
- package/vendor/agent/reference/decode.mjs +56 -0
- package/vendor/agent/reference/facts.mjs +1874 -0
- package/vendor/agent/reference/png.mjs +107 -0
- package/vendor/agent/reference/records.mjs +63 -0
- package/vendor/agent/reference/web.mjs +252 -0
- package/vendor/agent/roles/artist.mjs +69 -0
- package/vendor/agent/roles/builder.mjs +79 -0
- package/vendor/agent/roles/checks.mjs +223 -0
- package/vendor/agent/roles/common.mjs +188 -0
- package/vendor/agent/roles/critic.mjs +171 -0
- package/vendor/agent/roles/index.mjs +39 -0
- package/vendor/agent/roles/modeller.mjs +142 -0
- package/vendor/agent/roles/qa.mjs +58 -0
- package/vendor/agent/roles/rubrics.mjs +79 -0
- package/vendor/agent/roles/sound.mjs +69 -0
- package/vendor/agent/rounds.cjs +333 -0
- package/vendor/agent/shared.mjs +284 -0
- package/vendor/agent/stopGate.mjs +574 -0
- package/vendor/agent/subagents.mjs +129 -0
- package/vendor/agent/tools/assets.mjs +499 -0
- package/vendor/agent/tools/blender.mjs +754 -0
- package/vendor/agent/tools/cards.mjs +479 -0
- package/vendor/agent/tools/choices.mjs +479 -0
- package/vendor/agent/tools/compose.mjs +74 -0
- package/vendor/agent/tools/environment.mjs +488 -0
- package/vendor/agent/tools/eyes.mjs +733 -0
- package/vendor/agent/tools/generate.mjs +338 -0
- package/vendor/agent/tools/guide.mjs +46 -0
- package/vendor/agent/tools/harness.mjs +193 -0
- package/vendor/agent/tools/image.mjs +643 -0
- package/vendor/agent/tools/index.mjs +162 -0
- package/vendor/agent/tools/look.mjs +578 -0
- package/vendor/agent/tools/loop.mjs +858 -0
- package/vendor/agent/tools/others.mjs +123 -0
- package/vendor/agent/tools/pictures.mjs +535 -0
- package/vendor/agent/tools/reference.mjs +366 -0
- package/vendor/agent/transcripts.mjs +118 -0
- package/vendor/agent-loop.mjs +602 -0
- package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
- package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
- package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
- package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
- package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
- package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
- package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
- package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
- package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
- package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
- package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
- package/vendor/auth.cjs +570 -0
- package/vendor/build.cjs +953 -0
- package/vendor/catalog.json +455 -0
- package/vendor/connectors.cjs +688 -0
- package/vendor/eyes.mjs +733 -0
- package/vendor/gameExports.json +1390 -0
- package/vendor/git.cjs +222 -0
- package/vendor/models.json +57 -0
- package/vendor/publish.cjs +1018 -0
- package/vendor/refBoard.cjs +301 -0
- package/vendor/schema/dist/assets.d.ts +335 -0
- package/vendor/schema/dist/assets.js +439 -0
- package/vendor/schema/dist/brief.d.ts +357 -0
- package/vendor/schema/dist/brief.js +302 -0
- package/vendor/schema/dist/common.d.ts +9 -0
- package/vendor/schema/dist/common.js +13 -0
- package/vendor/schema/dist/config.d.ts +406 -0
- package/vendor/schema/dist/config.js +355 -0
- package/vendor/schema/dist/contract.d.ts +599 -0
- package/vendor/schema/dist/contract.js +1146 -0
- package/vendor/schema/dist/index.d.ts +14 -0
- package/vendor/schema/dist/index.js +21 -0
- package/vendor/schema/dist/look.d.ts +463 -0
- package/vendor/schema/dist/look.js +681 -0
- package/vendor/schema/dist/lookStats.d.ts +230 -0
- package/vendor/schema/dist/lookStats.js +768 -0
- package/vendor/schema/dist/pilot.d.ts +32 -0
- package/vendor/schema/dist/pilot.js +44 -0
- package/vendor/schema/dist/publish.d.ts +214 -0
- package/vendor/schema/dist/publish.js +291 -0
- package/vendor/schema/dist/scene.d.ts +75 -0
- package/vendor/schema/dist/scene.js +120 -0
- package/vendor/schema/dist/skyLight.d.ts +141 -0
- package/vendor/schema/dist/skyLight.js +436 -0
- package/vendor/schema/dist/style.d.ts +131 -0
- package/vendor/schema/dist/style.js +155 -0
- package/vendor/schema/package.json +1 -0
- package/vendor/selectionPrompt.mjs +51 -0
- package/vendor/useTools.mjs +195 -0
- package/vendor/userMessage.mjs +26 -0
- package/web-dist/assets/GaussianSplatUtils-CptQkDVX.js +1 -0
- package/web-dist/assets/KTX2Loader-C53LJqss.js +2 -0
- package/web-dist/assets/SPZLoader-BQ3tjaTv.js +1 -0
- package/web-dist/assets/gaussianSplat-_9tcWegB.js +1 -0
- package/web-dist/assets/index-Baka-ZO7.js +693 -0
- package/web-dist/assets/index-CcjyyQco.css +1 -0
- package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
- package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
- package/web-dist/index.html +34 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Hex } from './common.js';
|
|
3
|
+
import { LookStyle, NO_STYLE, resolveLook } from './look.js';
|
|
4
|
+
// The space's style: how it is drawn, written before any target picture is
|
|
5
|
+
// made and read by everything that judges the look. style.json at the
|
|
6
|
+
// project's root is the record.
|
|
7
|
+
//
|
|
8
|
+
// It comes from this space's request only. When the creator attaches
|
|
9
|
+
// pictures or names a style (an artist, a game, a film, a movement), it is
|
|
10
|
+
// those, analysed for how they are drawn rather than what they show. When
|
|
11
|
+
// they give neither, the agent researches artists and styles that suit the
|
|
12
|
+
// request, proposes directions that differ from each other and from the
|
|
13
|
+
// creator's other spaces, and the creator's pick (or, with no answer, the
|
|
14
|
+
// agent's own) is written here. There is no list of styles to start from:
|
|
15
|
+
// a photograph is one style among the rest and never the default.
|
|
16
|
+
//
|
|
17
|
+
// What it says in words steers the target pictures (image_generate kind
|
|
18
|
+
// target), the modelling and the judge; `look` is the techniques the engine
|
|
19
|
+
// draws it with (the look's style block), which look_apply copies into
|
|
20
|
+
// game.config.json.
|
|
21
|
+
export const STYLE_FILE = 'style.json';
|
|
22
|
+
export const STYLE_SCHEMA = 'nowhere/style@1';
|
|
23
|
+
const ProjectFile = z
|
|
24
|
+
.string()
|
|
25
|
+
.min(1)
|
|
26
|
+
.max(300)
|
|
27
|
+
.refine((p) => !p.startsWith('/') && !p.includes('\\') && !p.split('/').includes('..') && !/^[A-Za-z]:/.test(p), 'must be a path inside the project');
|
|
28
|
+
/** One work the style is read from: a picture the creator attached, an
|
|
29
|
+
* artist, a game, a film, a print, a movement. */
|
|
30
|
+
export const StyleSource = z
|
|
31
|
+
.object({
|
|
32
|
+
/** Who or what it is: "Moebius, Arzach (1975)", "the creator's sketch". */
|
|
33
|
+
what: z.string().min(1).max(200),
|
|
34
|
+
url: z.string().url().optional(),
|
|
35
|
+
/** A picture of it in the project (.nowhere/refs/... or refs/...). */
|
|
36
|
+
path: ProjectFile.optional(),
|
|
37
|
+
/** What this space takes from it, as a way of drawing. */
|
|
38
|
+
takes: z.string().min(1).max(300),
|
|
39
|
+
})
|
|
40
|
+
.strict();
|
|
41
|
+
/** A direction that was proposed, kept so the choice can be read back. */
|
|
42
|
+
export const StyleDirection = z
|
|
43
|
+
.object({
|
|
44
|
+
name: z.string().min(1).max(80),
|
|
45
|
+
medium: z.string().min(1).max(200),
|
|
46
|
+
/** Why it suits the request, and what makes it unlike the others. */
|
|
47
|
+
why: z.string().min(1).max(400),
|
|
48
|
+
/** Its sample picture in the project, when one was made. */
|
|
49
|
+
picture: ProjectFile.optional(),
|
|
50
|
+
})
|
|
51
|
+
.strict();
|
|
52
|
+
export const SpaceStyle = z
|
|
53
|
+
.object({
|
|
54
|
+
schema: z.literal(STYLE_SCHEMA),
|
|
55
|
+
/** What the space is drawn as, in the words a person would use: "a
|
|
56
|
+
* pen-and-ink storybook on cream paper", "a 1997 console game, low
|
|
57
|
+
* poly with blurry textures", "a photograph". */
|
|
58
|
+
medium: z.string().min(1).max(200),
|
|
59
|
+
/** attached: read from the creator's pictures. named: the creator named
|
|
60
|
+
* it. chosen: the creator picked one of the proposed directions.
|
|
61
|
+
* researched: proposed, no pick came, and the agent chose. */
|
|
62
|
+
from: z.enum(['attached', 'named', 'chosen', 'researched']),
|
|
63
|
+
sources: z.array(StyleSource).min(1).max(12),
|
|
64
|
+
/** Form: the shape language, the proportions, how much detail and where. */
|
|
65
|
+
shape: z
|
|
66
|
+
.object({
|
|
67
|
+
language: z.string().min(1).max(300),
|
|
68
|
+
proportions: z.string().min(1).max(300),
|
|
69
|
+
detail: z.enum(['sparse', 'moderate', 'dense']),
|
|
70
|
+
})
|
|
71
|
+
.strict(),
|
|
72
|
+
/** Lines: none, outlines round forms, ink that draws inside them too, a
|
|
73
|
+
* loose sketch, or edges made by the paint itself. */
|
|
74
|
+
line: z
|
|
75
|
+
.object({
|
|
76
|
+
kind: z.enum(['none', 'outline', 'ink', 'sketch', 'painted']),
|
|
77
|
+
weight: z.string().max(160).optional(),
|
|
78
|
+
color: Hex.optional(),
|
|
79
|
+
})
|
|
80
|
+
.strict(),
|
|
81
|
+
/** How light turns to shade: as light does, soft and simplified, in
|
|
82
|
+
* flat steps, all flat, by strokes, by dots, or in paint. */
|
|
83
|
+
shading: z
|
|
84
|
+
.object({
|
|
85
|
+
kind: z.enum(['physical', 'soft', 'bands', 'flat', 'hatched', 'dotted', 'painterly']),
|
|
86
|
+
steps: z.number().int().min(2).max(8).optional(),
|
|
87
|
+
shadowColor: Hex.optional(),
|
|
88
|
+
})
|
|
89
|
+
.strict(),
|
|
90
|
+
/** The surface treatment: grain, brush, paper, clean flat colour, pixels. */
|
|
91
|
+
surface: z.string().min(1).max(300),
|
|
92
|
+
palette: z
|
|
93
|
+
.object({
|
|
94
|
+
colors: z.array(Hex).min(2).max(16),
|
|
95
|
+
/** How it is used: "saturated primaries on cream, black only in lines". */
|
|
96
|
+
rule: z.string().min(1).max(300),
|
|
97
|
+
})
|
|
98
|
+
.strict(),
|
|
99
|
+
/** Concrete rules for whoever models, textures and lights the space,
|
|
100
|
+
* each one checkable in a picture. */
|
|
101
|
+
rules: z.array(z.string().min(1).max(240)).min(3).max(16),
|
|
102
|
+
/** The engine's drawing techniques for it (the look's style block), or
|
|
103
|
+
* null for a style the light and materials draw alone (a photograph). */
|
|
104
|
+
look: LookStyle.nullable(),
|
|
105
|
+
/** How the creator's other spaces look, which this one must not. */
|
|
106
|
+
avoid: z.array(z.string().min(1).max(200)).max(12).optional(),
|
|
107
|
+
/** The directions proposed before the choice, when there was one. */
|
|
108
|
+
directions: z.array(StyleDirection).max(4).optional(),
|
|
109
|
+
})
|
|
110
|
+
.strict();
|
|
111
|
+
const finding = (path, message) => ({
|
|
112
|
+
path: `${STYLE_FILE}${path ? ':' + path : ''}`,
|
|
113
|
+
code: 'style',
|
|
114
|
+
message,
|
|
115
|
+
hint: 'Call nw_schema with kind "style" to see the exact shape.',
|
|
116
|
+
});
|
|
117
|
+
/** Validates a raw style.json value: the schema, then what it alone cannot say. */
|
|
118
|
+
export function validateStyle(raw) {
|
|
119
|
+
const parsed = SpaceStyle.safeParse(raw);
|
|
120
|
+
if (!parsed.success)
|
|
121
|
+
return { ok: false, findings: parsed.error.issues.map((i) => finding(i.path.join('.'), i.message)) };
|
|
122
|
+
const style = parsed.data;
|
|
123
|
+
const findings = [];
|
|
124
|
+
if (style.from === 'chosen' && !(style.directions && style.directions.length >= 2)) {
|
|
125
|
+
findings.push(finding('directions', 'a style the creator chose names the directions it was chosen from (two or more)'));
|
|
126
|
+
}
|
|
127
|
+
if (style.shading.kind === 'bands' && style.look && !style.look.bands) {
|
|
128
|
+
findings.push(finding('look.bands', 'the shading is in bands, and the look draws none: give look.bands its count'));
|
|
129
|
+
}
|
|
130
|
+
if ((style.line.kind === 'outline' || style.line.kind === 'ink') && style.look && !style.look.outline) {
|
|
131
|
+
findings.push(finding('look.outline', `the line is ${style.line.kind}, and the look draws no outline: give look.outline its width and colour`));
|
|
132
|
+
}
|
|
133
|
+
return findings.length ? { ok: false, findings } : { ok: true, style, findings: [] };
|
|
134
|
+
}
|
|
135
|
+
const TECHNIQUES = ['outline', 'bands', 'hatch', 'halftone', 'paint', 'paper', 'pixel'];
|
|
136
|
+
/**
|
|
137
|
+
* Where game.config.json's look draws otherwise than style.json says, as
|
|
138
|
+
* sentences for nw_status and the stop gate: a technique the style names
|
|
139
|
+
* and the look does not draw, and one the look draws that the style does
|
|
140
|
+
* not name. Empty when they agree, or when there is no style.
|
|
141
|
+
*/
|
|
142
|
+
export function styleAdvice(style, config) {
|
|
143
|
+
if (!style)
|
|
144
|
+
return [];
|
|
145
|
+
const wanted = style.look ? resolveLook({ look: { style: style.look } }).style : NO_STYLE;
|
|
146
|
+
const drawn = resolveLook(config).style;
|
|
147
|
+
const out = [];
|
|
148
|
+
const missing = TECHNIQUES.filter((t) => wanted[t] !== null && drawn[t] === null);
|
|
149
|
+
const extra = TECHNIQUES.filter((t) => wanted[t] === null && drawn[t] !== null);
|
|
150
|
+
if (missing.length)
|
|
151
|
+
out.push(`style.json draws with ${missing.join(', ')}, which game.config.json's look.style does not: copy them over with look_apply.`);
|
|
152
|
+
if (extra.length)
|
|
153
|
+
out.push(`game.config.json's look.style draws with ${extra.join(', ')}, which style.json does not name: take them off, or add them to style.json's look if the style has them.`);
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// What the creator had selected when they hit send, written for the agent.
|
|
2
|
+
//
|
|
3
|
+
// Modelled on a file reference in a coding tool: the point is not to describe
|
|
4
|
+
// the object in prose, it is to hand over the id and the paths so the agent can
|
|
5
|
+
// open the right files and act. Kept in its own module so the wording is
|
|
6
|
+
// testable without starting an agent.
|
|
7
|
+
|
|
8
|
+
const trio = (v) =>
|
|
9
|
+
Array.isArray(v) && v.length === 3 && v.every((n) => typeof n === 'number' && Number.isFinite(n))
|
|
10
|
+
? v.map((n) => Number(n.toFixed(4))).join(', ')
|
|
11
|
+
: null
|
|
12
|
+
|
|
13
|
+
/** Returns a block to prepend to the user's message, or '' when nothing is
|
|
14
|
+
* selected or the selection is not something we can describe honestly. */
|
|
15
|
+
export function describeSelection(a) {
|
|
16
|
+
if (!a || typeof a.id !== 'string' || typeof a.asset !== 'string') return ''
|
|
17
|
+
const position = trio(a.position)
|
|
18
|
+
const rotation = trio(a.rotation)
|
|
19
|
+
const scale = trio(a.scale)
|
|
20
|
+
if (!position || !rotation || !scale) return ''
|
|
21
|
+
|
|
22
|
+
// Older callers send neither; the block still describes the rest.
|
|
23
|
+
const kind =
|
|
24
|
+
typeof a.kind === 'string' && a.kind
|
|
25
|
+
? `\n kind ${a.kind} (what the game's rules see: world.placed("${a.kind}"), onTouch("${a.kind}"))`
|
|
26
|
+
: ''
|
|
27
|
+
const solid =
|
|
28
|
+
typeof a.solid === 'boolean'
|
|
29
|
+
? `\n solid ${a.solid ? 'yes (blocks the player)' : 'no (the player walks through it)'}`
|
|
30
|
+
: ''
|
|
31
|
+
|
|
32
|
+
return `<selected-object>
|
|
33
|
+
The creator has this object selected in the viewport right now. It is something
|
|
34
|
+
they placed by hand, recorded in scene.json, not something the game code makes.
|
|
35
|
+
|
|
36
|
+
id ${a.id}${kind}${solid}
|
|
37
|
+
model ${a.asset}
|
|
38
|
+
position ${position}
|
|
39
|
+
rotation ${rotation} (radians, XYZ)
|
|
40
|
+
scale ${scale}
|
|
41
|
+
|
|
42
|
+
Both paths are relative to your working directory. Edit scene.json to move,
|
|
43
|
+
rotate, scale, duplicate or delete it, or to change its kind or solid flag; the
|
|
44
|
+
studio reloads as you save. Game code already sees it through ctx.placed and
|
|
45
|
+
world.placed(kind), so do not add it again with world.add. The model file itself
|
|
46
|
+
is binary; read it only if you have a reason to.
|
|
47
|
+
</selected-object>
|
|
48
|
+
|
|
49
|
+
`
|
|
50
|
+
}
|
|
51
|
+
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// The agent's hands outside the studio: its own browser (agentBrowser.cjs)
|
|
2
|
+
// and the creator's computer (agentComputer.cjs). Defined once here for both
|
|
3
|
+
// loops: agent-host.mjs makes them SDK tools for Claude, agent-loop.mjs hands
|
|
4
|
+
// their JSON Schema to every other vendor. Each runs in the main process over
|
|
5
|
+
// the agent rpc and replies { ok, text, images?, error? }.
|
|
6
|
+
|
|
7
|
+
import { z } from 'zod'
|
|
8
|
+
|
|
9
|
+
const tab = z.number().int().optional().describe('Which tab (from browser_tabs); the one in front if left out.')
|
|
10
|
+
const coordinate = z.array(z.number()).length(2).describe('[x, y] in pixels of your last screenshot.')
|
|
11
|
+
const reason = z
|
|
12
|
+
.string()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe('On your first use: one short sentence for the creator, in the screen language (the studio context names it) like every word on a card, saying what you will do on their computer and why. They read it on the consent card before they allow it.')
|
|
15
|
+
|
|
16
|
+
const BROWSER_ACTIONS = [
|
|
17
|
+
'screenshot',
|
|
18
|
+
'left_click',
|
|
19
|
+
'right_click',
|
|
20
|
+
'middle_click',
|
|
21
|
+
'double_click',
|
|
22
|
+
'triple_click',
|
|
23
|
+
'hover',
|
|
24
|
+
'left_click_drag',
|
|
25
|
+
'type',
|
|
26
|
+
'key',
|
|
27
|
+
'hold_key',
|
|
28
|
+
'scroll',
|
|
29
|
+
'scroll_to',
|
|
30
|
+
'wait',
|
|
31
|
+
'zoom',
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
const COMPUTER_ACTIONS = [
|
|
35
|
+
'screenshot',
|
|
36
|
+
'left_click',
|
|
37
|
+
'right_click',
|
|
38
|
+
'middle_click',
|
|
39
|
+
'double_click',
|
|
40
|
+
'triple_click',
|
|
41
|
+
'mouse_move',
|
|
42
|
+
'left_click_drag',
|
|
43
|
+
'left_mouse_down',
|
|
44
|
+
'left_mouse_up',
|
|
45
|
+
'scroll',
|
|
46
|
+
'type',
|
|
47
|
+
'key',
|
|
48
|
+
'hold_key',
|
|
49
|
+
'wait',
|
|
50
|
+
'zoom',
|
|
51
|
+
'cursor_position',
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
export const USE_TOOLS = [
|
|
55
|
+
{
|
|
56
|
+
name: 'browser_navigate',
|
|
57
|
+
rpc: ['browser', 'navigate'],
|
|
58
|
+
description:
|
|
59
|
+
'Opens a page in your own browser: a real Chromium window beside the studio that the creator can watch, with its own profile (none of the creator\'s sign-ins, unless they sign in there for you). url is an address, or "back", "forward" or "reload"; new_tab opens it in another tab. Returns the title and address. Then use browser_find or browser_read_page for refs, or a browser screenshot to see it.',
|
|
60
|
+
shape: {
|
|
61
|
+
url: z.string().describe('An http(s) address (https:// is added when left out), or "back", "forward", "reload".'),
|
|
62
|
+
new_tab: z.boolean().optional().describe('Open it in a new tab instead of the one in front.'),
|
|
63
|
+
tab,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'browser_read_page',
|
|
68
|
+
rpc: ['browser', 'read-page'],
|
|
69
|
+
description:
|
|
70
|
+
'The page in your browser as its accessibility tree, as Chromium computes it: each element\'s role, name, value and state, with a ref (ref_123) to act on with the browser tool. filter "interactive" (the default) lists only what can be clicked or typed into; "all" gives the whole structure with its text. ref_id narrows it to one element and what is inside it. Canvas and WebGL content (a 3D scene) is not in the tree: take a screenshot for that.',
|
|
71
|
+
shape: {
|
|
72
|
+
filter: z.enum(['interactive', 'all']).optional().describe('"interactive" (default) or "all".'),
|
|
73
|
+
ref_id: z.string().optional().describe('Only this element\'s part of the tree.'),
|
|
74
|
+
max_chars: z.number().int().optional().describe('Cut the answer at this length (default 40000).'),
|
|
75
|
+
tab,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'browser_find',
|
|
80
|
+
rpc: ['browser', 'find'],
|
|
81
|
+
description:
|
|
82
|
+
'Finds elements on the page in your browser whose role, name, value or text contains every word of query, with their refs. Quicker than reading the whole page when you know what you are after, e.g. "sign in button" or "search".',
|
|
83
|
+
shape: { query: z.string().describe('Words to look for.'), tab },
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'browser',
|
|
87
|
+
rpc: ['browser', 'act'],
|
|
88
|
+
description: [
|
|
89
|
+
'Acts on the page in your browser like a person with a mouse and keyboard.',
|
|
90
|
+
'Aim with ref (from browser_read_page or browser_find) when you can: the element is scrolled into view and clicked at its centre. coordinate [x, y] is in pixels of your last screenshot, for things the tree cannot name (a canvas, a 3D scene).',
|
|
91
|
+
'Actions: screenshot (see the viewport); left_click, right_click, middle_click, double_click, triple_click, hover; left_click_drag (from start_ref or start_coordinate to ref or coordinate); type (text, into ref when given, else wherever the focus is); key (text: one chord or several separated by spaces, e.g. "Enter", "cmd+a Delete", "shift+Tab"); hold_key (text held for duration seconds, e.g. "w" to walk forward in a 3D scene); scroll (scroll_direction up/down/left/right, scroll_amount steps, at ref or coordinate or the middle); scroll_to (ref); wait (duration seconds); zoom (region [x1, y1, x2, y2] of the last screenshot, at full resolution).',
|
|
92
|
+
'modifiers ("shift", "cmd+shift") are held during a click. After anything that may change the page, check what happened (browser_find, browser_read_page or a screenshot) before the next step.',
|
|
93
|
+
].join(' '),
|
|
94
|
+
shape: {
|
|
95
|
+
action: z.enum(BROWSER_ACTIONS),
|
|
96
|
+
ref: z.string().optional().describe('The element to act on, e.g. "ref_42".'),
|
|
97
|
+
coordinate: coordinate.optional(),
|
|
98
|
+
start_ref: z.string().optional().describe('Where a drag starts, as a ref.'),
|
|
99
|
+
start_coordinate: coordinate.optional().describe('Where a drag starts, [x, y] in the last screenshot.'),
|
|
100
|
+
text: z.string().optional().describe('What to type, or the keys to press or hold.'),
|
|
101
|
+
modifiers: z.string().optional().describe('Keys held during a click, e.g. "shift" or "cmd+shift".'),
|
|
102
|
+
scroll_direction: z.enum(['up', 'down', 'left', 'right']).optional(),
|
|
103
|
+
scroll_amount: z.number().int().optional().describe('Steps to scroll (default 3).'),
|
|
104
|
+
duration: z.number().optional().describe('Seconds, for wait and hold_key (at most 10).'),
|
|
105
|
+
region: z.array(z.number()).length(4).optional().describe('[x1, y1, x2, y2] of the last screenshot, for zoom.'),
|
|
106
|
+
tab,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'browser_form_input',
|
|
111
|
+
rpc: ['browser', 'form-input'],
|
|
112
|
+
description:
|
|
113
|
+
'Sets a form field by ref in one go: a select\'s option (by its value or visible text), a checkbox or radio button ("true" or "false"), a text field, a text area, or an editable element. Best for selects and checkboxes; for search boxes and fields that react to each keystroke, type into them with the browser tool instead.',
|
|
114
|
+
shape: { ref: z.string(), value: z.string().describe('The option, "true"/"false", or the text.'), tab },
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'browser_get_text',
|
|
118
|
+
rpc: ['browser', 'get-text'],
|
|
119
|
+
description: 'The readable text of the page in your browser (its article or main part when it has one), for reading docs, references and articles.',
|
|
120
|
+
shape: { max_chars: z.number().int().optional().describe('Cut at this length (default 30000).'), tab },
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'browser_tabs',
|
|
124
|
+
rpc: ['browser', 'tabs'],
|
|
125
|
+
description:
|
|
126
|
+
'The tabs in your browser: "list" them, open a "new" one (with url), bring one forward with "select", or "close" one (tab). The other browser tools act on the tab in front unless given tab.',
|
|
127
|
+
shape: { action: z.enum(['list', 'new', 'select', 'close']), tab, url: z.string().optional() },
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'browser_javascript',
|
|
131
|
+
rpc: ['browser', 'javascript'],
|
|
132
|
+
description:
|
|
133
|
+
'Runs JavaScript in the page in your browser and returns the value of its last expression as JSON (a promise is awaited, 20 s at most). For reading state a page or its 3D app keeps, or checking what the page tree cannot show. It runs with the page\'s own rights; never use it to get past a sign-in, a paywall or a CAPTCHA.',
|
|
134
|
+
shape: { code: z.string(), tab },
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'browser_console',
|
|
138
|
+
rpc: ['browser', 'console'],
|
|
139
|
+
description:
|
|
140
|
+
'The console of the page in your browser: logs, warnings, errors and uncaught exceptions, oldest first. only_errors, pattern (a regular expression) and limit narrow it; clear empties it after reading. Read it after opening the published planet to catch what it throws.',
|
|
141
|
+
shape: {
|
|
142
|
+
only_errors: z.boolean().optional(),
|
|
143
|
+
pattern: z.string().optional(),
|
|
144
|
+
limit: z.number().int().optional().describe('How many of the newest (default 50).'),
|
|
145
|
+
clear: z.boolean().optional(),
|
|
146
|
+
tab,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: 'computer',
|
|
151
|
+
rpc: ['computer'],
|
|
152
|
+
description: [
|
|
153
|
+
'Uses the creator\'s own computer: sees the screen and drives the real mouse and keyboard, for work in desktop apps that no connector reaches (Blender, an image editor, a system dialog).',
|
|
154
|
+
'The creator is asked once, so give reason on your first call; while you are in control a bar on their screen says so and lets them stop you.',
|
|
155
|
+
'Start with action "screenshot". Every action that changes something replies with a fresh screenshot: look at it before your next step. coordinate [x, y] is in pixels of the last screenshot.',
|
|
156
|
+
'Actions: screenshot; left_click, right_click, middle_click, double_click, triple_click (at coordinate, or where the pointer is); mouse_move; left_click_drag (start_coordinate to coordinate); left_mouse_down, left_mouse_up; scroll (scroll_direction up/down/left/right, scroll_amount notches, at coordinate); type (text); key (text: a chord like "cmd+s", "Return", "ctrl+shift+z", or several separated by spaces); hold_key (text, duration seconds); wait (duration seconds); zoom (region [x1, y1, x2, y2] at full resolution, to read small text); cursor_position.',
|
|
157
|
+
'modifiers ("shift", "alt", "cmd") are held during a click, drag or scroll. display chooses the screen (1, 2, ...) when there are several.',
|
|
158
|
+
'Bring the app you need to the front first (computer_apps). Prefer keyboard shortcuts to hunting for small buttons, and aim for the middle of what you click.',
|
|
159
|
+
].join(' '),
|
|
160
|
+
shape: {
|
|
161
|
+
action: z.enum(COMPUTER_ACTIONS),
|
|
162
|
+
coordinate: coordinate.optional(),
|
|
163
|
+
start_coordinate: coordinate.optional().describe('Where a drag starts.'),
|
|
164
|
+
text: z.string().optional().describe('What to type, or the keys to press or hold.'),
|
|
165
|
+
modifiers: z.string().optional().describe('Keys held during a click, drag or scroll, e.g. "shift" or "cmd+alt".'),
|
|
166
|
+
scroll_direction: z.enum(['up', 'down', 'left', 'right']).optional(),
|
|
167
|
+
scroll_amount: z.number().int().optional().describe('Wheel notches (default 3).'),
|
|
168
|
+
duration: z.number().optional().describe('Seconds, for wait and hold_key (at most 10).'),
|
|
169
|
+
region: z.array(z.number()).length(4).optional().describe('[x1, y1, x2, y2] of the last screenshot, for zoom.'),
|
|
170
|
+
display: z.number().int().optional().describe('Which screen to use, from 1, when there are several.'),
|
|
171
|
+
reason,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: 'computer_apps',
|
|
176
|
+
rpc: ['computer-apps'],
|
|
177
|
+
description:
|
|
178
|
+
'The apps open on the creator\'s computer: "list" them, or "open" one by name (e.g. "Blender"), which brings it to the front or starts it, and replies with a screenshot. Asked of the creator first, like computer.',
|
|
179
|
+
shape: { action: z.enum(['list', 'open']), name: z.string().optional(), reason },
|
|
180
|
+
},
|
|
181
|
+
]
|
|
182
|
+
|
|
183
|
+
/** The rpc call for a tool's input: [method, params]. */
|
|
184
|
+
export function rpcFor(useTool, args) {
|
|
185
|
+
const [method, sub] = useTool.rpc
|
|
186
|
+
return sub ? [method, { tool: sub, params: args ?? {} }] : [method, args ?? {}]
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** A plain JSON Schema for a tool's input, for the vendors agent-loop.mjs talks to. */
|
|
190
|
+
export function jsonSchemaOf(useTool) {
|
|
191
|
+
const schema = z.toJSONSchema(z.object(useTool.shape))
|
|
192
|
+
delete schema.$schema
|
|
193
|
+
delete schema.additionalProperties
|
|
194
|
+
return schema
|
|
195
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// The creator's message as the Agent SDK takes it: one user message whose
|
|
2
|
+
// content is the text and any pictures, in a stream of messages. The SDK
|
|
3
|
+
// keeps the session open until the run ends (it has a permission callback
|
|
4
|
+
// and in-process tools to answer) before closing it. Always the stream, with
|
|
5
|
+
// or without pictures: Query.applyFlagSettings (the effort raised mid-run
|
|
6
|
+
// after a cost approval, agent/host.mjs) works only in streaming input mode.
|
|
7
|
+
// Its own module so scripts/agent-sdk-image-check.mjs runs the same code.
|
|
8
|
+
|
|
9
|
+
/** @param {string} text @param {{ mime: string, data: string }[] | undefined} images */
|
|
10
|
+
export function promptFor(text, images) {
|
|
11
|
+
const pictures = Array.isArray(images) ? images : []
|
|
12
|
+
async function* one() {
|
|
13
|
+
yield {
|
|
14
|
+
type: 'user',
|
|
15
|
+
message: {
|
|
16
|
+
role: 'user',
|
|
17
|
+
content: [
|
|
18
|
+
{ type: 'text', text },
|
|
19
|
+
...pictures.map((i) => ({ type: 'image', source: { type: 'base64', media_type: i.mime, data: i.data } })),
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
parent_tool_use_id: null,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return one()
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{aD as E,a6 as d,a7 as b,an as H,aE as A,af as u}from"./index-Baka-ZO7.js";const y=.2820947917738781,B=[0,9,15,21],p=[0,3,4,6],c=new H,m=new H,h=new b,w=new E,f=new d,g=new d;function D(t,r,n,e,i,l,a,s,S){w.set(l,a,s,S).normalize(),f.set(n,e,i),h.compose(g,w,f),c.setFromMatrix4(h),m.copy(c).transpose(),c.multiply(m);const o=c.elements;t[r]=o[0],t[r+1]=o[3],t[r+2]=o[6],t[r+3]=o[4],t[r+4]=o[7],t[r+5]=o[8]}function G(t,r){const n=new Uint32Array(t*p[r]);return n.fill(2155905152),{packed:n,bytes:new Uint8ClampedArray(n.buffer)}}function _(t,r,n){const e=p[n];if(!(t instanceof Uint32Array))throw new Error(`THREE.createGaussianSplatGeometry: sphericalHarmonics${n} must use packed uint32 words.`);if(t.length!==r*e)throw new Error(`THREE.createGaussianSplatGeometry: Invalid sphericalHarmonics${n} packed length.`);return new u(t,e)}function $(t){if(t===void 0||t.isBufferGeometry!==!0)return 0;let r=0;for(let e=1;e<=3;e++){const i=t.getAttribute(`sphericalHarmonics${e}`);if(i===void 0)break;if(i.itemSize!==p[e])throw new Error(`THREE.getSphericalHarmonicsDegree: Invalid sphericalHarmonics${e} itemSize.`);if(!(i.array instanceof Uint32Array))throw new Error(`THREE.getSphericalHarmonicsDegree: sphericalHarmonics${e} must use packed uint32 words.`);r=e}for(let e=r+1;e<=3;e++)if(t.getAttribute(`sphericalHarmonics${e}`)!==void 0)throw new Error("THREE.getSphericalHarmonicsDegree: Spherical harmonics attributes must be contiguous.");const n=t.getAttribute("position");if(n!==void 0){for(let e=1;e<=r;e++)if(t.getAttribute(`sphericalHarmonics${e}`).count!==n.count)throw new Error("THREE.getSphericalHarmonicsDegree: Spherical harmonics attribute counts must match position.")}return r}function T(t,r,n,e={}){const i=new A;i.setAttribute("position",new u(t,3)),i.setAttribute("covariance",new u(r,6)),i.setAttribute("color",new u(n,4,!0));const l=t.length/3;for(let a=1;a<=3;a++){const s=e[`sh${a}`]||e[`sphericalHarmonics${a}`];s!==void 0&&i.setAttribute(`sphericalHarmonics${a}`,_(s,l,a))}return $(i),i.computeBoundingBox(),i.computeBoundingSphere(),i}export{B as S,G as a,p as b,T as c,y as d,$ as g,D as w};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{C as ut,S as ye,L as mt,F as $,a as Tt,b as gt,c as Ce,d as Z,e as we,f as yt,N as de,R as fe,g as ie,h as oe,i as Ct,j as wt,k as Ft,l as St,m as ae,n as he,o as le,p as ee,q as Q,r as Et,s as xt,t as Ut,u as Rt,v as Fe,w as Se,x as pe,y as X,z as K,A as G,U as c,H as L,B as Ee,D as xe,E as Ue,G as z,I as Bt,J as At,K as Pt,M as ue,O as bt,P as kt,Q as Gt}from"./index-Baka-ZO7.js";import{Q as Lt}from"./zstddec.module-CfFeQW7d.js";class Dt{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0,this.workerCreator=null}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e<this.pool;e++)if(!(this.workerStatus&1<<e))return e;return-1}_onMessage(e,t){const s=this.workersResolve[e];if(s&&s(t),this.queue.length){const{resolve:r,msg:i,transfer:o}=this.queue.shift();this.workersResolve[e]=r,this.workers[e].postMessage(i,o)}else this.workerStatus^=1<<e}setWorkerCreator(e){this.workerCreator=e}setWorkerLimit(e){this.pool=e}postMessage(e,t){return new Promise(s=>{const r=this._getIdleWorker();r!==-1?(this._initWorker(r),this.workerStatus|=1<<r,this.workersResolve[r]=s,this.workers[r].postMessage(e,t)):this.queue.push({resolve:s,msg:e,transfer:t})})}dispose(){this.workers.forEach(e=>e.terminate()),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}const vt=0,me=2,Ht=1,Te=2,Ot=0,Mt=1,It=10,Nt=0,Re=9,Be=15,Ae=16,Pe=22,be=37,ke=43,Ge=76,Le=83,ce=91,De=97,ve=100,He=103,Oe=109,Me=122,Ie=123,Ne=131,Ve=132,We=133,Xe=134,Ke=137,ze=138,je=139,qe=140,Ye=141,Je=142,Qe=145,Ze=146,$e=148,et=152,tt=153,rt=154,st=155,nt=156,it=157,ot=158,at=165,lt=166,pt=1000054e3,ct=1000054001,_t=1000054004,dt=1000054005,_e=1000066e3,ft=1000066004;class W{constructor(e,t,s,r){this._dataView=void 0,this._littleEndian=void 0,this._offset=void 0,this._dataView=new DataView(e.buffer,e.byteOffset+t,s),this._littleEndian=r,this._offset=0}_nextUint8(){const e=this._dataView.getUint8(this._offset);return this._offset+=1,e}_nextUint16(){const e=this._dataView.getUint16(this._offset,this._littleEndian);return this._offset+=2,e}_nextUint32(){const e=this._dataView.getUint32(this._offset,this._littleEndian);return this._offset+=4,e}_nextUint64(){const e=this._dataView.getUint32(this._offset,this._littleEndian)+4294967296*this._dataView.getUint32(this._offset+4,this._littleEndian);return this._offset+=8,e}_nextInt32(){const e=this._dataView.getInt32(this._offset,this._littleEndian);return this._offset+=4,e}_nextUint8Array(e){const t=new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+this._offset,e);return this._offset+=e,t}_skip(e){return this._offset+=e,this}_scan(e,t=0){const s=this._offset;let r=0;for(;this._dataView.getUint8(this._offset)!==t&&r<e;)r++,this._offset++;return r<e&&this._offset++,new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+s,r)}}const S=[171,75,84,88,32,50,48,187,13,10,26,10];function ge(n){return new TextDecoder().decode(n)}function Vt(n){const e=new Uint8Array(n.buffer,n.byteOffset,S.length);if(e[0]!==S[0]||e[1]!==S[1]||e[2]!==S[2]||e[3]!==S[3]||e[4]!==S[4]||e[5]!==S[5]||e[6]!==S[6]||e[7]!==S[7]||e[8]!==S[8]||e[9]!==S[9]||e[10]!==S[10]||e[11]!==S[11])throw new Error("Missing KTX 2.0 identifier.");const t={vkFormat:0,typeSize:1,pixelWidth:0,pixelHeight:0,pixelDepth:0,layerCount:0,faceCount:1,levelCount:0,supercompressionScheme:0,levels:[],dataFormatDescriptor:[{vendorId:0,descriptorType:0,versionNumber:2,colorModel:0,colorPrimaries:1,transferFunction:2,flags:0,texelBlockDimension:[0,0,0,0],bytesPlane:[0,0,0,0,0,0,0,0],samples:[]}],keyValue:{},globalData:null},s=17*Uint32Array.BYTES_PER_ELEMENT,r=new W(n,S.length,s,!0);t.vkFormat=r._nextUint32(),t.typeSize=r._nextUint32(),t.pixelWidth=r._nextUint32(),t.pixelHeight=r._nextUint32(),t.pixelDepth=r._nextUint32(),t.layerCount=r._nextUint32(),t.faceCount=r._nextUint32(),t.levelCount=r._nextUint32(),t.supercompressionScheme=r._nextUint32();const i=r._nextUint32(),o=r._nextUint32(),m=r._nextUint32(),E=r._nextUint32(),C=r._nextUint64(),x=r._nextUint64(),_=3*Math.max(t.levelCount,1)*8,w=new W(n,S.length+s,_,!0);for(let d=0,u=Math.max(t.levelCount,1);d<u;d++)t.levels.push({levelData:new Uint8Array(n.buffer,n.byteOffset+w._nextUint64(),w._nextUint64()),uncompressedByteLength:w._nextUint64()});const l=new W(n,i,o,!0);l._skip(4);const p=l._nextUint16(),a=l._nextUint16(),g=l._nextUint16(),F=l._nextUint16(),f={vendorId:p,descriptorType:a,versionNumber:g,colorModel:l._nextUint8(),colorPrimaries:l._nextUint8(),transferFunction:l._nextUint8(),flags:l._nextUint8(),texelBlockDimension:[l._nextUint8(),l._nextUint8(),l._nextUint8(),l._nextUint8()],bytesPlane:[l._nextUint8(),l._nextUint8(),l._nextUint8(),l._nextUint8(),l._nextUint8(),l._nextUint8(),l._nextUint8(),l._nextUint8()],samples:[]},y=(F/4-6)/4;for(let d=0;d<y;d++){const u={bitOffset:l._nextUint16(),bitLength:l._nextUint8(),channelType:l._nextUint8(),samplePosition:[l._nextUint8(),l._nextUint8(),l._nextUint8(),l._nextUint8()],sampleLower:Number.NEGATIVE_INFINITY,sampleUpper:Number.POSITIVE_INFINITY};64&u.channelType?(u.sampleLower=l._nextInt32(),u.sampleUpper=l._nextInt32()):(u.sampleLower=l._nextUint32(),u.sampleUpper=l._nextUint32()),f.samples[d]=u}t.dataFormatDescriptor.length=0,t.dataFormatDescriptor.push(f);const T=new W(n,m,E,!0);for(;T._offset<E;){const d=T._nextUint32(),u=T._scan(d),U=ge(u);if(t.keyValue[U]=T._nextUint8Array(d-u.byteLength-1),U.match(/^ktx/i)){const J=ge(t.keyValue[U]);t.keyValue[U]=J.substring(0,J.lastIndexOf("\0"))}T._skip(d%4?4-d%4:0)}if(x<=0)return t;const h=new W(n,C,x,!0),b=h._nextUint16(),B=h._nextUint16(),j=h._nextUint32(),D=h._nextUint32(),v=h._nextUint32(),H=h._nextUint32(),O=[];for(let d=0,u=Math.max(t.levelCount,1);d<u;d++)O.push({imageFlags:h._nextUint32(),rgbSliceByteOffset:h._nextUint32(),rgbSliceByteLength:h._nextUint32(),alphaSliceByteOffset:h._nextUint32(),alphaSliceByteLength:h._nextUint32()});const M=C+h._offset,A=M+j,I=A+D,P=I+v,q=new Uint8Array(n.buffer,n.byteOffset+M,j),N=new Uint8Array(n.buffer,n.byteOffset+A,D),V=new Uint8Array(n.buffer,n.byteOffset+I,v),Y=new Uint8Array(n.buffer,n.byteOffset+P,H);return t.globalData={endpointCount:b,selectorCount:B,imageDescs:O,endpointsData:q,selectorsData:N,tablesData:V,extendedData:Y},t}const Wt="display-p3",Xt="display-p3-linear";({...ut.spaces[ye]});const Kt="",zt="",te=new WeakMap;let re=0,se;class R extends mt{constructor(e){super(e),this.transcoderPath="",this.transcoderBinary=null,this.transcoderPending=null,this.workerPool=new Dt,this.workerSourceURL="",this.workerConfig=null,typeof MSC_TRANSCODER<"u"&&console.warn('THREE.KTX2Loader: Please update to latest "basis_transcoder". "msc_basis_transcoder" is no longer supported in three.js r125+.')}setTranscoderPath(e){return this.transcoderPath=e,this}setWorkerLimit(e){return this.workerPool.setWorkerLimit(e),this}async detectSupportAsync(e){return console.warn('KTX2Loader: "detectSupportAsync()" has been deprecated. Use "detectSupport()" and "await renderer.init();" when creating the renderer.'),await e.init(),this.detectSupport(e)}detectSupport(e){return e.isWebGPURenderer===!0?this.workerConfig={astcSupported:e.hasFeature("texture-compression-astc"),astcHDRSupported:!1,etc1Supported:e.hasFeature("texture-compression-etc1"),etc2Supported:e.hasFeature("texture-compression-etc2"),dxtSupported:e.hasFeature("texture-compression-s3tc"),bptcSupported:e.hasFeature("texture-compression-bc"),pvrtcSupported:e.hasFeature("texture-compression-pvrtc")}:(this.workerConfig={astcSupported:e.extensions.has("WEBGL_compressed_texture_astc"),astcHDRSupported:e.extensions.has("WEBGL_compressed_texture_astc")&&e.extensions.get("WEBGL_compressed_texture_astc").getSupportedProfiles().includes("hdr"),etc1Supported:e.extensions.has("WEBGL_compressed_texture_etc1"),etc2Supported:e.extensions.has("WEBGL_compressed_texture_etc"),dxtSupported:e.extensions.has("WEBGL_compressed_texture_s3tc"),bptcSupported:e.extensions.has("EXT_texture_compression_bptc"),pvrtcSupported:e.extensions.has("WEBGL_compressed_texture_pvrtc")||e.extensions.has("WEBKIT_WEBGL_compressed_texture_pvrtc")},typeof navigator<"u"&&typeof navigator.platform<"u"&&typeof navigator.userAgent<"u"&&navigator.platform.indexOf("Linux")>=0&&navigator.userAgent.indexOf("Android")<0&&this.workerConfig.astcSupported&&this.workerConfig.etc2Supported&&this.workerConfig.bptcSupported&&this.workerConfig.dxtSupported&&(this.workerConfig.astcSupported=!1,this.workerConfig.etc1Supported=!1,this.workerConfig.etc2Supported=!1)),this}init(){if(!this.transcoderPending){const e=new $(this.manager);e.setWithCredentials(this.withCredentials);const t=new $(this.manager);t.setWithCredentials(this.withCredentials),t.setResponseType("arraybuffer");let s,r;this.transcoderPath===""?(s=e.loadAsync(zt),r=t.loadAsync(Kt)):(e.setPath(this.transcoderPath),s=e.loadAsync("basis_transcoder.js"),t.setPath(this.transcoderPath),r=t.loadAsync("basis_transcoder.wasm")),this.transcoderPending=Promise.all([s,r]).then(([i,o])=>{const m=R.BasisWorker.toString(),E=["/* constants */","let _EngineFormat = "+JSON.stringify(R.EngineFormat),"let _EngineType = "+JSON.stringify(R.EngineType),"let _TranscoderFormat = "+JSON.stringify(R.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(R.BasisFormat),"/* basis_transcoder.js */",i,"/* worker */",m.substring(m.indexOf("{")+1,m.lastIndexOf("}"))].join(`
|
|
2
|
+
`);this.workerSourceURL=URL.createObjectURL(new Blob([E])),this.transcoderBinary=o,this.workerPool.setWorkerCreator(()=>{const C=new Worker(this.workerSourceURL),x=this.transcoderBinary.slice(0);return C.postMessage({type:"init",config:this.workerConfig,transcoderBinary:x},[x]),C})}),re>0&&console.warn("THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues. Use a single KTX2Loader instance, or call .dispose() on old instances."),re++}return this.transcoderPending}load(e,t,s,r){if(this.workerConfig===null)throw new Error("THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.");const i=new $(this.manager);i.setPath(this.path),i.setCrossOrigin(this.crossOrigin),i.setWithCredentials(this.withCredentials),i.setRequestHeader(this.requestHeader),i.setResponseType("arraybuffer"),i.load(e,o=>{this.parse(o,t,r)},s,r)}parse(e,t,s){if(this.workerConfig===null)throw new Error("THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.");if(te.has(e))return te.get(e).promise.then(t).catch(s);this._createTexture(e).then(r=>t?t(r):null).catch(s)}_createTextureFrom(e,t){const{type:s,error:r,data:{faces:i,width:o,height:m,format:E,type:C,dfdFlags:x}}=e;if(s==="error")return Promise.reject(r);let _;if(t.faceCount===6)_=new Tt(i,E,C);else{const w=i[0].mipmaps;_=t.layerCount>1?new gt(w,o,m,t.layerCount,E,C):new Ce(w,o,m,E,C)}return _.minFilter=i[0].mipmaps.length===1?Z:we,_.magFilter=Z,_.generateMipmaps=!1,_.needsUpdate=!0,_.colorSpace=ht(t),_.premultiplyAlpha=!!(x&Ht),_}async _createTexture(e,t={}){const s=Vt(new Uint8Array(e)),r=s.vkFormat===_e&&s.dataFormatDescriptor[0].colorModel===167;if(!(s.vkFormat===Nt||r&&!this.workerConfig.astcHDRSupported))return Yt(s);const o=t,m=this.init().then(()=>this.workerPool.postMessage({type:"transcode",buffer:e,taskConfig:o},[e])).then(E=>this._createTextureFrom(E.data,s));return te.set(e,{promise:m}),m}dispose(){this.workerPool.dispose(),this.workerSourceURL&&URL.revokeObjectURL(this.workerSourceURL),re--}}R.BasisFormat={ETC1S:0,UASTC:1,UASTC_HDR:2};R.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16,BC6H:22,RGB_HALF:24,RGBA_HALF:25};R.EngineFormat={RGBAFormat:G,RGBA_ASTC_4x4_Format:Q,RGB_BPTC_UNSIGNED_Format:Gt,RGBA_BPTC_Format:oe,RGBA_ETC2_EAC_Format:Se,RGBA_PVRTC_4BPPV1_Format:ie,RGBA_S3TC_DXT5_Format:ae,RGB_ETC1_Format:kt,RGB_ETC2_Format:Fe,RGB_PVRTC_4BPPV1_Format:bt,RGBA_S3TC_DXT1_Format:le};R.EngineType={UnsignedByteType:c,HalfFloatType:L,FloatType:z};R.BasisWorker=function(){let n,e,t;const s=_EngineFormat,r=_EngineType,i=_TranscoderFormat,o=_BasisFormat;self.addEventListener("message",function(p){const a=p.data;switch(a.type){case"init":n=a.config,m(a.transcoderBinary);break;case"transcode":e.then(()=>{try{const{faces:g,buffers:F,width:f,height:y,hasAlpha:T,format:h,type:b,dfdFlags:B}=E(a.buffer);self.postMessage({type:"transcode",id:a.id,data:{faces:g,width:f,height:y,hasAlpha:T,format:h,type:b,dfdFlags:B}},F)}catch(g){console.error(g),self.postMessage({type:"error",id:a.id,error:g.message})}});break}});function m(p){e=new Promise(a=>{t={wasmBinary:p,onRuntimeInitialized:a},BASIS(t)}).then(()=>{t.initializeBasis(),t.KTX2File===void 0&&console.warn("THREE.KTX2Loader: Please update Basis Universal transcoder.")})}function E(p){const a=new t.KTX2File(new Uint8Array(p));function g(){a.close(),a.delete()}if(!a.isValid())throw g(),new Error("THREE.KTX2Loader: Invalid or unsupported .ktx2 file");let F;if(a.isUASTC())F=o.UASTC;else if(a.isETC1S())F=o.ETC1S;else if(a.isHDR())F=o.UASTC_HDR;else throw new Error("THREE.KTX2Loader: Unknown Basis encoding");const f=a.getWidth(),y=a.getHeight(),T=a.getLayers()||1,h=a.getLevels(),b=a.getFaces(),B=a.getHasAlpha(),j=a.getDFDFlags(),{transcoderFormat:D,engineFormat:v,engineType:H}=_(F,f,y,B);if(!f||!y||!h)throw g(),new Error("THREE.KTX2Loader: Invalid texture");if(!a.startTranscoding())throw g(),new Error("THREE.KTX2Loader: .startTranscoding failed");const O=[],M=[];for(let A=0;A<b;A++){const I=[];for(let P=0;P<h;P++){const q=[];let N,V;for(let d=0;d<T;d++){const u=a.getImageLevelInfo(P,d,A);A===0&&P===0&&d===0&&(u.origWidth%4!==0||u.origHeight%4!==0)&&console.warn("THREE.KTX2Loader: ETC1S and UASTC textures should use multiple-of-four dimensions."),h>1?(N=u.origWidth,V=u.origHeight):(N=u.width,V=u.height);let U=new Uint8Array(a.getImageTranscodedSizeInBytes(P,d,0,D));const J=a.transcodeImage(U,P,d,A,D,0,-1,-1);if(H===r.HalfFloatType&&(U=new Uint16Array(U.buffer,U.byteOffset,U.byteLength/Uint16Array.BYTES_PER_ELEMENT)),!J)throw g(),new Error("THREE.KTX2Loader: .transcodeImage failed.");q.push(U)}const Y=l(q);I.push({data:Y,width:N,height:V}),M.push(Y.buffer)}O.push({mipmaps:I,width:f,height:y,format:v,type:H})}return g(),{faces:O,buffers:M,width:f,height:y,hasAlpha:B,dfdFlags:j,format:v,type:H}}const C=[{if:"astcSupported",basisFormat:[o.UASTC],transcoderFormat:[i.ASTC_4x4,i.ASTC_4x4],engineFormat:[s.RGBA_ASTC_4x4_Format,s.RGBA_ASTC_4x4_Format],engineType:[r.UnsignedByteType],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[o.ETC1S,o.UASTC],transcoderFormat:[i.BC7_M5,i.BC7_M5],engineFormat:[s.RGBA_BPTC_Format,s.RGBA_BPTC_Format],engineType:[r.UnsignedByteType],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[o.ETC1S,o.UASTC],transcoderFormat:[i.BC1,i.BC3],engineFormat:[s.RGBA_S3TC_DXT1_Format,s.RGBA_S3TC_DXT5_Format],engineType:[r.UnsignedByteType],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[o.ETC1S,o.UASTC],transcoderFormat:[i.ETC1,i.ETC2],engineFormat:[s.RGB_ETC2_Format,s.RGBA_ETC2_EAC_Format],engineType:[r.UnsignedByteType],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[o.ETC1S,o.UASTC],transcoderFormat:[i.ETC1],engineFormat:[s.RGB_ETC1_Format],engineType:[r.UnsignedByteType],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[o.ETC1S,o.UASTC],transcoderFormat:[i.PVRTC1_4_RGB,i.PVRTC1_4_RGBA],engineFormat:[s.RGB_PVRTC_4BPPV1_Format,s.RGBA_PVRTC_4BPPV1_Format],engineType:[r.UnsignedByteType],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0},{if:"bptcSupported",basisFormat:[o.UASTC_HDR],transcoderFormat:[i.BC6H],engineFormat:[s.RGB_BPTC_UNSIGNED_Format],engineType:[r.HalfFloatType],priorityHDR:1,needsPowerOfTwo:!1},{basisFormat:[o.ETC1S,o.UASTC],transcoderFormat:[i.RGBA32,i.RGBA32],engineFormat:[s.RGBAFormat,s.RGBAFormat],engineType:[r.UnsignedByteType,r.UnsignedByteType],priorityETC1S:100,priorityUASTC:100,needsPowerOfTwo:!1},{basisFormat:[o.UASTC_HDR],transcoderFormat:[i.RGBA_HALF],engineFormat:[s.RGBAFormat],engineType:[r.HalfFloatType],priorityHDR:100,needsPowerOfTwo:!1}],x={[o.ETC1S]:C.filter(p=>p.basisFormat.includes(o.ETC1S)).sort((p,a)=>p.priorityETC1S-a.priorityETC1S),[o.UASTC]:C.filter(p=>p.basisFormat.includes(o.UASTC)).sort((p,a)=>p.priorityUASTC-a.priorityUASTC),[o.UASTC_HDR]:C.filter(p=>p.basisFormat.includes(o.UASTC_HDR)).sort((p,a)=>p.priorityHDR-a.priorityHDR)};function _(p,a,g,F){const f=x[p];for(let y=0;y<f.length;y++){const T=f[y];if(T.if&&!n[T.if]||!T.basisFormat.includes(p)||F&&T.transcoderFormat.length<2||T.needsPowerOfTwo&&!(w(a)&&w(g)))continue;const h=T.transcoderFormat[F?1:0],b=T.engineFormat[F?1:0],B=T.engineType[0];return{transcoderFormat:h,engineFormat:b,engineType:B}}throw new Error("THREE.KTX2Loader: Failed to identify transcoding target.")}function w(p){return p<=2?!0:(p&p-1)===0&&p!==0}function l(p){if(p.length===1)return p[0];let a=0;for(let f=0;f<p.length;f++){const y=p[f];a+=y.byteLength}const g=new Uint8Array(a);let F=0;for(let f=0;f<p.length;f++){const y=p[f];g.set(y,F),F+=y.byteLength}return g}};const jt=new Set([G,pe,K,X]),qt=new Set([ce]),ne={[Oe]:G,[He]:K,[ve]:X,[De]:G,[Le]:K,[Ge]:X,[ce]:G,[ke]:G,[be]:G,[Pe]:K,[Ae]:K,[Be]:X,[Re]:X,[Ie]:pe,[Me]:pe,[et]:Se,[$e]:Fe,[tt]:Rt,[rt]:Ut,[st]:xt,[nt]:Et,[_e]:Q,[ot]:Q,[it]:Q,[ft]:ee,[lt]:ee,[at]:ee,[Xe]:le,[We]:le,[Ve]:he,[Ne]:he,[ze]:ae,[Ke]:ae,[qe]:St,[je]:Ft,[Je]:wt,[Ye]:Ct,[Ze]:oe,[Qe]:oe,[dt]:ie,[ct]:ie,[_t]:fe,[pt]:fe},k={[Oe]:z,[He]:z,[ve]:z,[De]:L,[Le]:L,[Ge]:L,[ce]:Ue,[ke]:c,[be]:c,[Pe]:c,[Ae]:c,[Be]:c,[Re]:c,[Ie]:xe,[Me]:Ee,[et]:c,[$e]:c,[tt]:c,[rt]:c,[st]:c,[nt]:c,[_e]:L,[ot]:c,[it]:c,[ft]:L,[lt]:c,[at]:c,[Xe]:c,[We]:c,[Ve]:c,[Ne]:c,[ze]:c,[Ke]:c,[qe]:c,[je]:c,[Je]:c,[Ye]:c,[Ze]:c,[Qe]:c,[dt]:c,[ct]:c,[_t]:c,[pt]:c};async function Yt(n){const{vkFormat:e}=n;if(ne[e]===void 0)throw new Error("THREE.KTX2Loader: Unsupported vkFormat: "+e);k[e]===void 0&&console.warn('THREE.KTX2Loader: Missing ".type" for vkFormat: '+e);let t;n.supercompressionScheme===me&&(se||(se=new Promise(async o=>{const m=new Lt;await m.init(),o(m)})),t=await se);const s=[];for(let o=0;o<n.levels.length;o++){const m=Math.max(1,n.pixelWidth>>o),E=Math.max(1,n.pixelHeight>>o),C=n.pixelDepth?Math.max(1,n.pixelDepth>>o):0,x=n.levels[o];let _;if(n.supercompressionScheme===vt)_=x.levelData;else if(n.supercompressionScheme===me)_=t.decode(x.levelData,x.uncompressedByteLength);else throw new Error("THREE.KTX2Loader: Unsupported supercompressionScheme.");let w;k[e]===z?w=new Float32Array(_.buffer,_.byteOffset,_.byteLength/Float32Array.BYTES_PER_ELEMENT):k[e]===L||k[e]===Ue?w=new Uint16Array(_.buffer,_.byteOffset,_.byteLength/Uint16Array.BYTES_PER_ELEMENT):k[e]===xe||k[e]===Ee?w=new Uint32Array(_.buffer,_.byteOffset,_.byteLength/Uint32Array.BYTES_PER_ELEMENT):w=_,s.push({data:w,width:m,height:E,depth:C})}const r=n.levelCount===0||s.length>1;let i;if(jt.has(ne[e]))i=n.pixelDepth===0?new Bt(s[0].data,n.pixelWidth,n.pixelHeight):new At(s[0].data,n.pixelWidth,n.pixelHeight,n.pixelDepth),i.minFilter=r?Pt:ue,i.magFilter=ue,i.generateMipmaps=n.levelCount===0,i.normalized=qt.has(e);else{if(n.pixelDepth>0)throw new Error("THREE.KTX2Loader: Unsupported pixelDepth.");i=new Ce(s,n.pixelWidth,n.pixelHeight),i.minFilter=r?we:Z,i.magFilter=Z}return i.mipmaps=s,i.type=k[e],i.format=ne[e],i.colorSpace=ht(n),i.needsUpdate=!0,Promise.resolve(i)}function ht(n){const e=n.dataFormatDescriptor[0];return e.colorPrimaries===Mt?e.transferFunction===Te?ye:yt:e.colorPrimaries===It?e.transferFunction===Te?Wt:Xt:e.colorPrimaries===Ot?de:(console.warn(`THREE.KTX2Loader: Unsupported color primaries, "${e.colorPrimaries}"`),de)}export{R as KTX2Loader};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{L as C,F as b,T as v,V as R}from"./index-Baka-ZO7.js";import{Q as M}from"./zstddec.module-CfFeQW7d.js";import{w as F,c as B,a as I,S as q,b as N,d as G}from"./GaussianSplatUtils-CptQkDVX.js";const D=1347635022,T=16,V=G/.15,k=128,Q=2,x=3,Z=[0,3,8,15,24];let _;const g=new Float32Array(256),H=new Uint8ClampedArray(256);for(let n=0;n<256;n++)g[n]=Math.exp(n/16-10),H[n]=((n/255-.5)*V+.5)*255;const A=new Float64Array(1024);for(let n=0;n<1024;n++){const e=Math.SQRT1_2*((n&511)/511);A[n]=(n&512)!==0?-e:e}const $=[0,0,0,0];class ne extends C{constructor(e){super(e)}load(e,o,r,t){const s=this,a=new b(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(f){s.parse(f,o,function(i){t?t(i):console.error(i),s.manager.itemError(e)})},r,t)}parse(e,o,r){try{if(e.byteLength>=8){const a=new DataView(e),f=a.getUint32(0,!0),i=a.getUint32(4,!0);if(f===D){if(i!==4)throw new Error(`THREE.SPZLoader: SPZ version ${i} is not supported.`);const c=X().then(S=>this.parseRawSPZV4(new Uint8Array(e),S));return o!==void 0&&c.then(o).catch(r),c}}const t=v(new Uint8Array(e)),s=this.parseRawSPZ(t);return o!==void 0&&o(s),s}catch(t){if(r!==void 0){r(t);return}throw t}}parseRawSPZ(e){if(e.byteLength<T)throw new Error("THREE.SPZLoader: Invalid SPZ header.");const o=new DataView(e.buffer,e.byteOffset,e.byteLength),r=o.getUint32(0,!0),t=o.getUint32(4,!0),s=o.getUint32(8,!0),a=o.getUint8(12),f=o.getUint8(13),i=o.getUint8(14);if(r!==D)throw new Error("THREE.SPZLoader: Invalid SPZ magic.");if(t<1||t>3)throw new Error(`THREE.SPZLoader: SPZ version ${t} is not supported.`);if(a>=Z.length)throw new Error(`THREE.SPZLoader: Unsupported SPZ spherical harmonics degree ${a}.`);const c=Math.min(a,x),S=s*3*(t===1?2:3),u=s*(t===3?4:3),p=s*Z[a]*3,w=(i&k)!==0?s*6:0,m=T+S+s+s*3+s*3+u+p+w;if(e.byteLength!==m)throw new Error("THREE.SPZLoader: Invalid SPZ byte length.");let d=T;const E=e.subarray(d,d+S);d+=S;const l=e.subarray(d,d+s);d+=s;const O=e.subarray(d,d+s*3);d+=s*3;const h=e.subarray(d,d+s*3);d+=s*3;const P=e.subarray(d,d+u);d+=u;const U=e.subarray(d,d+p);return z({positions:E,alphas:l,colors:O,scales:h,rotations:P,sphericalHarmonics:U,count:s,version:t,fractionalBits:f,shDegree:c,storedShDegree:a})}parseRawSPZV4(e,o){const r=new DataView(e.buffer,e.byteOffset,e.byteLength),t=r.getUint32(8,!0),s=r.getUint8(12),a=Math.min(s,x),f=r.getUint8(13),i=r.getUint8(14),c=r.getUint8(15),S=r.getUint32(16,!0);(i&Q)!==0&&console.warn("THREE.SPZLoader: SPZ vendor extensions are not supported and will be skipped.");const u=t*3*3,p=t*4,w=t*Z[s]*3,m=[u,t,t*3,t*3,p,w],d=[];let E=S+c*16;for(let h=0;h<c;h++){const P=S+h*16,U=Number(r.getBigUint64(P,!0));d.push({compressedOffset:E,compressedSize:U}),E+=U}const l=[];let O=0;for(let h=0;h<m.length;h++){const P=m[h];if(P===0){l.push(new Uint8Array);continue}const U=d[O++],L=e.subarray(U.compressedOffset,U.compressedOffset+U.compressedSize);l.push(o.decode(L,P))}return z({positions:l[0],alphas:l[1],colors:l[2],scales:l[3],rotations:l[4],sphericalHarmonics:l[5],count:t,version:4,fractionalBits:f,shDegree:a,storedShDegree:s})}}function X(){if(_===void 0){const n=new M;_=n.init().then(()=>n).catch(e=>{throw _=void 0,e})}return _}function z({positions:n,alphas:e,colors:o,scales:r,rotations:t,sphericalHarmonics:s,count:a,version:f,fractionalBits:i,shDegree:c,storedShDegree:S}){const u=new Float32Array(a*3),p=new Float32Array(a*6),w=new Uint8ClampedArray(a*4),m={};Y(n,u,0,a,f,i);const d=f>=3?t.byteOffset%4===0?new Uint32Array(t.buffer,t.byteOffset,a):new Uint32Array(t.buffer.slice(t.byteOffset,t.byteOffset+a*4)):null,E=$;for(let l=0;l<a;l++){const O=l*3,h=l*4,P=g[r[O]],U=g[r[O+1]],L=g[r[O+2]];f>=3?J(d[l],E):j(t,O,E),F(p,l*6,P,U,L,E[0],E[1],E[2],E[3]),w[h]=H[o[O]],w[h+1]=H[o[O+1]],w[h+2]=H[o[O+2]],w[h+3]=e[l]}return W(s,0,a,c,m,S),B(u,p,w,m)}function W(n,e,o,r,t,s=r){if(r===0)return;const a=[];for(let i=1;i<=r;i++){const c=I(o,i);t[`sh${i}`]=c.packed,a.push({bytes:c.bytes,components:q[i],stride:N[i]*4})}const f=Z[s]*3;for(let i=0;i<o;i++){let S=e+i*f;for(let u=0;u<a.length;u++){const p=a[u],w=i*p.stride;for(let m=0;m<p.components;m++)p.bytes[w+m]=n[S++]}}}function Y(n,e,o,r,t,s){if(t===1){for(let f=0;f<r;f++){const i=f*3,c=o+i*2;e[i]=R.fromHalfFloat(n[c]|n[c+1]<<8),e[i+1]=R.fromHalfFloat(n[c+2]|n[c+3]<<8),e[i+2]=R.fromHalfFloat(n[c+4]|n[c+5]<<8)}return}const a=1/(1<<s);for(let f=0;f<r;f++){const i=f*3,c=o+f*9;e[i]=y(n,c)*a,e[i+1]=y(n,c+3)*a,e[i+2]=y(n,c+6)*a}}function y(n,e){return(n[e]<<8|n[e+1]<<16|n[e+2]<<24)>>8}function j(n,e,o){const r=n[e]/127.5-1,t=n[e+1]/127.5-1,s=n[e+2]/127.5-1;o[0]=r,o[1]=t,o[2]=s,o[3]=Math.sqrt(Math.max(0,1-r*r-t*t-s*s))}function J(n,e){const o=n>>>30,r=A[n&1023],t=A[n>>>10&1023],s=A[n>>>20&1023];switch(o){case 0:e[1]=s,e[2]=t,e[3]=r;break;case 1:e[0]=s,e[2]=t,e[3]=r;break;case 2:e[0]=s,e[1]=t,e[3]=r;break;default:e[0]=s,e[1]=t,e[2]=r;break}e[o]=Math.sqrt(Math.max(0,1-(r*r+t*t+s*s)))}export{ne as SPZLoader};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{W as H,X as V,Y as O,Z as lt,_ as M,$ as P,a0 as Nt,a1 as le,a2 as ue,a3 as me,a4 as de,a5 as ut,a6 as B,a7 as E,a8 as Zt,a9 as N,aa as L,ab as he,ac as jt,ad as pe,ae as ge,af as xe,ag as w,ah as mt,ai as y,aj as dt,ak as be,al as fe,am as _e,an as ye,ao as Ae,ap as Ve,aq as ht,ar as Se,as as Mt,at as Q,au as pt,av as qt,aw as Wt,ax as tt,ay as zt,az as et,aA as ve,aB as we,aC as Be}from"./index-Baka-ZO7.js";import{g as Ce,b as He,S as gt}from"./GaussianSplatUtils-CptQkDVX.js";class Re{constructor(t,{binCount:e=4096,workgroupSize:n=256}={}){this.count=t,this.binCount=e,this.workgroupSize=n;const s=new Uint32Array(t);for(let l=0;l<t;l++)s[l]=l;this.orderAttribute=new H(s,1,Uint32Array);const a=new H(new Uint32Array(t),1,Uint32Array),r=new H(new Uint32Array(e),1,Uint32Array),c=new H(new Uint32Array(e),1,Uint32Array);this.orderRead=V(this.orderAttribute,"uint",t).toReadOnly(),this.orderWrite=V(this.orderAttribute,"uint",t),this.binRead=V(a,"uint",t).toReadOnly(),this.binWrite=V(a,"uint",t),this.histogramAtomic=V(r,"uint",e).toAtomic(),this.offsetAtomic=V(c,"uint",e).toAtomic(),this._webGLBuffersEnabled=!1,this._cpuBins=new Uint32Array(t),this._cpuCounts=new Uint32Array(e),this._cpuOffsets=new Uint32Array(e),this._resetNode=null,this._histogramNode=null,this._prefixNode=null,this._scatterNode=null}setBinNode(t){const{binCount:e,workgroupSize:n,count:s}=this;this._resetNode=O(()=>{lt(this.histogramAtomic.element(M),P(0)),lt(this.offsetAtomic.element(M),P(0))})().compute(e,[n]).setName("CountingSortReset"),this._histogramNode=O(()=>{const a=t().toVar("bin");this.binWrite.element(M).assign(a),Nt(this.histogramAtomic.element(a),P(1))})().compute(s,[n]).setName("CountingSortHistogram"),this._prefixNode=O(()=>{const a=P(0).toVar("sum");le({start:0,end:e,type:"uint",name:"bin",condition:"<"},({bin:r})=>{const c=ue(this.histogramAtomic.element(r)).toVar("count");lt(this.offsetAtomic.element(r),a),a.addAssign(c)})})().compute(1).setName("CountingSortPrefix"),this._scatterNode=O(()=>{const a=this.binRead.element(M).toVar("bin"),r=Nt(this.offsetAtomic.element(a),P(1)).toVar("targetIndex");this.orderWrite.element(r).assign(M)})().compute(s,[n]).setName("CountingSortScatter")}compute(t){t.compute(this._resetNode),t.compute(this._histogramNode),t.compute(this._prefixNode),t.compute(this._scatterNode)}computeCPU(t){const{count:e,binCount:n}=this,s=this.orderAttribute.array,a=this._cpuBins,r=this._cpuCounts,c=this._cpuOffsets;r.fill(0);for(let i=0;i<e;i++){const u=t(i);a[i]=u,r[u]++}let l=0;for(let i=0;i<n;i++)c[i]=l,l+=r[i];for(let i=0;i<e;i++)s[c[a[i]]++]=i;this.orderAttribute.needsUpdate=!0,this.orderAttribute.pbo!==void 0&&(this.orderAttribute.pbo.needsUpdate=!0)}enableWebGLBuffers(){this._webGLBuffersEnabled!==!0&&(this.orderAttribute.setUsage(me),this.orderRead.setPBO(!0),this._webGLBuffersEnabled=!0)}}const T=4096,Ft=256,Ne=.9995,Dt=.3,F=2,Me=1e-4,We=.2,Pt=1024,ze=1.4,It=new B,Ot=new B,ot=new B,xt=new B,Ut=new Zt,Tt=new E,Lt=new E,Et=new E,I=new pe,bt=new jt,q=new ye,nt=new B,ft=new B,kt=new B,st=new B;class Fe extends de{constructor(t,{autoSort:e=!0}={}){const n=t.getAttribute("position"),s=t.getAttribute("covariance"),a=t.getAttribute("color"),r=Ce(t),c=n.count;t.boundingBox===null&&t.computeBoundingBox(),t.boundingSphere===null&&t.computeBoundingSphere();const l=Pe(c),i=Ie(c,n.array,s.array,a.array,{degree:r,sh1:r>=1?t.getAttribute("sphericalHarmonics1").array:void 0,sh2:r>=2?t.getAttribute("sphericalHarmonics2").array:void 0,sh3:r>=3?t.getAttribute("sphericalHarmonics3").array:void 0}),u=ut(new B),m=Ee(i,u),_=new Re(c,{binCount:T,workgroupSize:Ft}),p=ke(i,_,u),f=Ge(p.vertexNode,p.fragmentNode);f.receivedShadowPositionNode=p.shadowPositionNode,super(l,f),this.isGaussianSplat=!0,this.type="GaussianSplat",this.splatGeometry=t,this.boundingBox=null,this.boundingSphere=null,this.autoSort=e,this._buffers=i,this._sort=_,this._sortMatrix=ut(new E),this._sortDepthRange=ut(new Zt(0,1)),this._sortInitialized=!1,this._lastSortDirection=new B,this._localCameraPosition=u,this._sphericalHarmonicsComputeNode=m,this._sphericalHarmonicsInitialized=!1,this._lastSphericalHarmonicsCameraMatrix=new E,this._lastSphericalHarmonicsWorldMatrix=new E,this._sphericalHarmonicsVertexNode=p.sphericalHarmonicsVertexNode,this._precomputedSphericalHarmonicsVertexNode=p.vertexNode,this._positionAttribute=n;const h=i.centerRead,A=this._sortMatrix,d=this._sortDepthRange;_.setBinNode(()=>{const g=h.element(M).xyz.toVar("center"),x=A.mul(N(g,1)).xyz.toVar("viewCenter").z.negate().toVar("depth"),S=L(d.y.sub(d.x),1e-4).toVar("range"),C=x.sub(d.x).div(S).clamp(0,1).toVar("normalized"),v=P(C.mul(T-1)).toVar("depthBin");return P(T-1).sub(v)}),this.onBeforeRender=(g,b,x)=>{const S=g.backend&&g.backend.isWebGLBackend===!0?this._sphericalHarmonicsVertexNode:this._precomputedSphericalHarmonicsVertexNode;S!==null&&f.vertexNode!==S&&(f.vertexNode=S,f.needsUpdate=!0),this.updateSphericalHarmonics(g,x),this.autoSort===!0&&this.updateSort(g,x)}}updateSphericalHarmonics(t,e){if(this._sphericalHarmonicsComputeNode===null)return!1;const n=t.backend&&t.backend.isWebGLBackend===!0;return this._sphericalHarmonicsInitialized===!0&&e.matrixWorld.equals(this._lastSphericalHarmonicsCameraMatrix)&&this.matrixWorld.equals(this._lastSphericalHarmonicsWorldMatrix)&&(n===!0||this._buffers.sphericalHarmonicsContributionRead!==void 0)||(n===!0&&Gt(this._buffers),Tt.copy(this.matrixWorld).invert(),this._localCameraPosition.value.setFromMatrixPosition(e.matrixWorld).applyMatrix4(Tt),this._lastSphericalHarmonicsCameraMatrix.copy(e.matrixWorld),this._lastSphericalHarmonicsWorldMatrix.copy(this.matrixWorld),this._sphericalHarmonicsInitialized=!0,n===!0)?!1:(Oe(this._buffers),t.compute(this._sphericalHarmonicsComputeNode),!0)}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new he),this.boundingBox.makeEmpty();const t=this.splatGeometry.getAttribute("position"),e=this.splatGeometry.getAttribute("covariance"),n=t.count;for(let s=0;s<n;s++){const a=t.getX(s),r=t.getY(s),c=t.getZ(s),l=e.getComponent(s,0),i=e.getComponent(s,3),u=e.getComponent(s,5),m=F*Math.sqrt(Math.max(l,i,u));this.boundingBox.expandByPoint(st.set(a-m,r-m,c-m)),this.boundingBox.expandByPoint(st.set(a+m,r+m,c+m))}}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new jt),this.computeBoundingBox(),this.boundingBox.getBoundingSphere(this.boundingSphere);const t=this.splatGeometry.getAttribute("position"),e=this.splatGeometry.getAttribute("covariance"),n=t.count,s=this.boundingSphere.center;let a=0;for(let r=0;r<n;r++){const c=t.getX(r),l=t.getY(r),i=t.getZ(r),u=e.getComponent(r,0),m=e.getComponent(r,3),_=e.getComponent(r,5),p=F*Math.sqrt(Math.max(u,m,_));a=Math.max(a,s.distanceTo(st.set(c,l,i))+p)}this.boundingSphere.radius=a}raycast(t,e){const n=this.matrixWorld;if(this.boundingSphere===null&&this.computeBoundingSphere(),bt.copy(this.boundingSphere),bt.applyMatrix4(n),t.ray.intersectsSphere(bt)===!1||(Et.copy(n).invert(),I.copy(t.ray).applyMatrix4(Et),this.boundingBox!==null&&I.intersectsBox(this.boundingBox)===!1))return;const s=this.splatGeometry.getAttribute("position"),a=this.splatGeometry.getAttribute("covariance"),r=this.splatGeometry.getAttribute("color"),c=s.count;for(let l=0;l<c;l++)De(s,a,r,l,n,t,e,this)}updateSort(t,e){this.updateWorldMatrix(!0,!1);const n=this._needsSort(e);return this._sortInitialized===!1||n===!0?(this._updateSortUniforms(e),t.backend&&t.backend.isWebGLBackend===!0?(Gt(this._buffers),this._sort.enableWebGLBuffers(),this._sortCPU()):this._sort.compute(t),this._sortInitialized=!0,this._lastSortDirection.copy(xt),!0):!1}_needsSort(t){Lt.multiplyMatrices(t.matrixWorldInverse,this.matrixWorld);const e=Lt.elements;return xt.set(e[2],e[6],e[10]).normalize(),xt.dot(this._lastSortDirection)<Ne}_updateSortUniforms(t){this._sortMatrix.value.multiplyMatrices(t.matrixWorldInverse,this.matrixWorld),this.boundingSphere===null&&this.computeBoundingSphere(),It.copy(this.boundingSphere.center).applyMatrix4(this.matrixWorld),Ot.copy(It).applyMatrix4(t.matrixWorldInverse),ot.setFromMatrixScale(this.matrixWorld);const e=this.boundingSphere.radius*Math.max(ot.x,ot.y,ot.z),n=-Ot.z,s=Math.max(t.near,n-e),a=Math.max(s+1e-4,n+e);Ut.set(s,a),this._sortDepthRange.value.copy(Ut)}_sortCPU(){const t=this._positionAttribute.array,e=this._sortMatrix.value.elements,n=this._sortDepthRange.value.x,s=Math.max(this._sortDepthRange.value.y-n,1e-4),a=(T-1)/s;this._sort.computeCPU(r=>{const c=r*3,l=-(e[2]*t[c]+e[6]*t[c+1]+e[10]*t[c+2]+e[14]),i=Math.min(T-1,Math.max(0,Math.floor((l-n)*a)));return T-1-i})}}function De(o,t,e,n,s,a,r,c){if(e.getW(n)<We)return;const l=t.getComponent(n,0),i=t.getComponent(n,3),u=t.getComponent(n,5),m=Math.max(l,i,u);if(m<=0)return;const _=st.fromBufferAttribute(o,n),p=F*Math.sqrt(m);if(I.distanceSqToPoint(_)>p*p)return;const f=t.getComponent(n,1),h=t.getComponent(n,2),A=t.getComponent(n,4),d=m*Me;if(q.set(l+d,f,h,f,i+d,A,h,A,u+d),q.determinant()<=0)return;q.invert(),ft.copy(I.direction).applyMatrix3(q);const b=I.direction.dot(ft);if(b<=0)return;nt.copy(I.origin).sub(_),kt.copy(nt).applyMatrix3(q);const x=2*nt.dot(ft),S=nt.dot(kt)-F*F,C=x*x-4*b*S;if(C<0)return;const v=Math.sqrt(C);let R=(-x-v)/(2*b);if(R<0&&(R=(-x+v)/(2*b)),R<0)return;const W=new B;I.at(R,W).applyMatrix4(s);const z=a.ray.origin.distanceTo(W);z<a.near||z>a.far||r.push({distance:z,point:W,index:n,face:null,faceIndex:null,barycoord:null,object:c})}function Pe(o){const t=new ge;return t.setAttribute("position",new xe(new Float32Array([-2,-2,0,2,-2,0,2,2,0,-2,2,0]),3)),t.setIndex([0,1,2,0,2,3]),t.instanceCount=o,t}function Ie(o,t,e,n,s){const a=new Float32Array(o*4),r=new Float32Array(o*4),c=new Float32Array(o*4),l=new Uint32Array(o),i=s.degree;for(let h=0;h<o;h++){const A=h*3,d=h*4,g=h*6;a[d]=t[A],a[d+1]=t[A+1],a[d+2]=t[A+2],r[d]=e[g],r[d+1]=e[g+1],r[d+2]=e[g+2],r[d+3]=e[g+3],c[d]=e[g+4],c[d+1]=e[g+5],l[h]=(n[d]|n[d+1]<<8|n[d+2]<<16|n[d+3]<<24)>>>0}const u=new H(a,4),m=new H(r,4),_=new H(c,4),p=new H(l,1),f={count:o,sphericalHarmonicsDegree:i,webGLBuffersEnabled:!1,centerRead:V(u,"vec4",o).toReadOnly(),covarianceARead:V(m,"vec4",o).toReadOnly(),covarianceBRead:V(_,"vec4",o).toReadOnly(),colorRead:V(p,"uint",o).toReadOnly()};for(let h=1;h<=i;h++){const A=He[h],d=new H(s[`sh${h}`],1);f[`sphericalHarmonics${h}Attribute`]=d,f[`sphericalHarmonics${h}Read`]=V(d,"uint",o*A).toReadOnly(),f[`sphericalHarmonics${h}Words`]=A}return f}function Oe(o){if(o.sphericalHarmonicsContributionRead!==void 0)return;const t=new H(new Float32Array(o.count*4),4);o.sphericalHarmonicsContributionRead=V(t,"vec4",o.count).toReadOnly(),o.sphericalHarmonicsContributionWrite=V(t,"vec4",o.count)}function Gt(o){if(o.webGLBuffersEnabled!==!0){o.centerRead.setPBO(!0),o.covarianceARead.setPBO(!0),o.covarianceBRead.setPBO(!0),o.colorRead.setPBO(!0);for(let t=1;t<=o.sphericalHarmonicsDegree;t++)o[`sphericalHarmonics${t}Read`].setPBO(!0);o.webGLBuffersEnabled=!0}}function Ue(o,t,e,n){const s=[];let a=n;for(let r=0;r<e&&a>0;r++){const c=o.element(t.mul(e).add(r)).toVar(),l=Math.min(4,a);for(let i=0;i<l;i++){const u=c.shiftRight(i*8).bitAnd(255);s.push(qt(u).sub(128).div(128))}a-=l}return s}function Te(o,t){const e=[],n=o.length/3;for(let s=0;s<n;s++){const a=s*3;e.push(w(o[a],o[a+1],o[a+2]).toVar(`${t}${s}`))}return e}function Le(o,t){let e=o[0].mul(t[0]);for(let n=1;n<o.length;n++)e=e.add(o[n].mul(t[n]));return e}function _t(o,t,e,n,s,a){const r=Ue(o,t,e,n),c=Te(r,s);return Le(c,a)}function Yt(o,t,e,n,s){const a=Ae(t.sub(e)).toVar("sphericalHarmonicsViewDirection"),r=a.x,c=a.y,l=a.z;if(o.addAssign(_t(s.sphericalHarmonics1Read,n,s.sphericalHarmonics1Words,gt[1],"sh1_",[c.mul(-.4886025),l.mul(.4886025),r.mul(-.4886025)])),s.sphericalHarmonicsDegree>=2){const i=r.mul(r).toVar("shXX"),u=c.mul(c).toVar("shYY"),m=l.mul(l).toVar("shZZ");if(o.addAssign(_t(s.sphericalHarmonics2Read,n,s.sphericalHarmonics2Words,gt[2],"sh2_",[r.mul(c).mul(1.0925484),c.mul(l).mul(-1.0925484),m.mul(2).sub(i).sub(u).mul(.3153915),r.mul(l).mul(-1.0925484),i.sub(u).mul(.5462742)])),s.sphericalHarmonicsDegree>=3){const _=r.mul(c).toVar("shXY");o.addAssign(_t(s.sphericalHarmonics3Read,n,s.sphericalHarmonics3Words,gt[3],"sh3_",[c.mul(i.mul(3).sub(u)).mul(-.5900436),_.mul(l).mul(2.8906114),c.mul(m.mul(4).sub(i).sub(u)).mul(-.4570458),l.mul(m.mul(2).sub(i.mul(3)).sub(u.mul(3))).mul(.3731763),r.mul(m.mul(4).sub(i).sub(u)).mul(-.4570458),l.mul(i.sub(u)).mul(1.4453057),r.mul(i.sub(u.mul(3))).mul(-.5900436)]))}}}function Ee(o,t){return o.sphericalHarmonicsDegree===0?null:O(()=>{const e=M,n=o.centerRead.element(e).xyz.toVar("center"),s=w(0).toVar("sphericalHarmonicsContribution");Yt(s,n,t,e,o),o.sphericalHarmonicsContributionWrite.element(e).assign(N(s,0))})().compute(o.count,[Ft]).setName("GaussianSplatSphericalHarmonics")}function ke(o,t,e){const n=mt("vec2","vSplatUv"),s=mt("vec4","vSplatColor"),a=mt("vec3","vSplatWorldPosition"),r=u=>O(()=>{const m=t.orderRead.element(M).toVar("splatIndex"),_=o.centerRead.element(m).xyz.toVar("center"),p=o.covarianceARead.element(m).toVar("covA"),f=o.covarianceBRead.element(m).toVar("covB"),h=Ve(o.colorRead.element(m)).toVar("splatColor"),A=h.rgb.toVar("splatRgb");o.sphericalHarmonicsDegree>0&&(u===!0?A.addAssign(o.sphericalHarmonicsContributionRead.element(m).rgb):Yt(A,_,e,m,o)),n.assign(ht.xy),a.assign(Se.mul(N(_,1)).xyz);const d=Mt.mul(N(_,1)).toVar("viewCenter4"),g=d.xyz.toVar("viewCenter"),b=Q.mul(d).toVar("centerClip"),x=Mt,S=w(x[0].x,x[1].x,x[2].x).toVar("r0"),C=w(x[0].y,x[1].y,x[2].y).toVar("r1"),v=w(x[0].z,x[1].z,x[2].z).toVar("r2"),R=w(p.x,p.y,p.z).toVar("cov0"),W=w(p.y,p.w,f.x).toVar("cov1"),z=w(p.z,f.x,f.y).toVar("cov2"),rt=w(y(S,R),y(S,W),y(S,z)).toVar("vc0"),yt=w(y(C,R),y(C,W),y(C,z)).toVar("vc1"),Xt=w(y(v,R),y(v,W),y(v,z)).toVar("vc2"),$t=y(rt,S).toVar("c00"),Kt=y(rt,C).toVar("c01"),At=y(rt,v).toVar("c02"),Jt=y(yt,C).toVar("c11"),Vt=y(yt,v).toVar("c12"),at=y(Xt,v).toVar("c22"),Qt=pt(g.z,-.01).toVar("z"),Y=qt(1).div(Qt).toVar("invZ"),St=Y.mul(Y).toVar("invZ2"),U=Wt.zw.mul(.5).mul(tt(Q[0].x,Q[1].y)).toVar("focal"),it=Q[3].w.toVar("orthographic"),vt=it.oneMinus().toVar("perspective"),k=zt(U.x.negate().mul(Y),U.x,it).toVar("j00"),G=zt(U.y.negate().mul(Y),U.y,it).toVar("j11"),Z=U.x.mul(g.x).mul(St).mul(vt).toVar("j02"),j=U.y.mul(g.y).mul(St).mul(vt).toVar("j12"),wt=k.mul(k).mul($t).add(k.mul(Z).mul(At).mul(2)).add(Z.mul(Z).mul(at)).toVar("cov2dABase"),D=k.mul(G).mul(Kt).add(k.mul(j).mul(At)).add(Z.mul(G).mul(Vt)).add(Z.mul(j).mul(at)).toVar("cov2dB"),Bt=G.mul(G).mul(Jt).add(G.mul(j).mul(Vt).mul(2)).add(j.mul(j).mul(at)).toVar("cov2dCBase"),X=wt.add(Dt).toVar("cov2dA"),$=Bt.add(Dt).toVar("cov2dC"),te=wt.mul(Bt).sub(D.mul(D)).toVar("detBase"),ee=X.mul($).sub(D.mul(D)).toVar("det"),oe=et(L(te.div(L(ee,1e-6)),0)).toVar("alphaScale");s.assign(N(A.clamp(0,1),h.a.mul(oe)));const Ct=X.add($).mul(.5).toVar("halfTrace"),ct=et(L(X.sub($).mul(.5).pow2().add(D.mul(D)),1e-7)).toVar("radius"),ne=L(Ct.add(ct),1e-7).toVar("lambda1"),se=L(Ct.sub(ct),1e-7).toVar("lambda2"),K=tt(1,0).toVar("axis1");dt(ct.greaterThan(1e-5),()=>{const Rt=ve(D.mul(2),X.sub($)).mul(.5).toVar("angle");K.assign(tt(we(Rt),Be(Rt)))});const re=tt(K.y.negate(),K.x).toVar("axis2"),ae=pt(et(ne),Pt).toVar("scale1"),ie=pt(et(se),Pt).toVar("scale2"),ce=K.mul(ht.x).mul(ae).add(re.mul(ht.y).mul(ie)).toVar("offsetPixels").mul(2).div(Wt.zw).toVar("offsetNdc"),Ht=b.add(N(ce.mul(b.w),0,0)).toVar("clip"),J=b.w.mul(ze).toVar("clipLimit");return dt(g.z.greaterThanEqual(-.01).or(b.z.lessThan(b.w.negate())).or(b.z.greaterThan(b.w)).or(b.x.lessThan(J.negate())).or(b.x.greaterThan(J)).or(b.y.lessThan(J.negate())).or(b.y.greaterThan(J)),()=>{Ht.assign(N(2,2,2,1))}),Ht})(),c=r(!0),l=o.sphericalHarmonicsDegree>0?r(!1):null,i=O(()=>{const u=y(n,n).toVar("r2");return dt(u.greaterThan(4),()=>{be()}),N(s.rgb,fe(u.mul(-.5)).mul(s.a))})();return{vertexNode:c,sphericalHarmonicsVertexNode:l,fragmentNode:i,shadowPositionNode:a}}function Ge(o,t){const e=new _e;return e.vertexNode=o,e.colorNode=t,e.transparent=!0,e.depthWrite=!1,e.depthTest=!0,e.forceSinglePass=!0,e.fog=!1,e}export{Fe as GaussianSplat};
|