@threenative/core 0.3.3 → 0.3.5
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/capabilities.json +2019 -59
- package/dist/{assets-CYKk2WTu.d.ts → assets-CqvE429w.d.ts} +45 -3
- package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
- package/dist/{canvas-layer-C1SnMoJ-.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
- package/dist/{game-D_6r-k4Y.d.ts → game-Bj8G1wmD.d.ts} +242 -17
- package/dist/hot.d.ts +5 -5
- package/dist/index.d.ts +1131 -105
- package/dist/index.js +15201 -4782
- package/dist/model-lod-BDAUYgsS.d.ts +197 -0
- package/dist/playtest.d.ts +6 -4
- package/dist/playtest.js +84 -11
- package/dist/react-css.d.ts +62 -0
- package/dist/react-css.js +591 -0
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-Cy4qeBOA.d.ts → renderer-9yEo9hPa.d.ts} +676 -21
- package/dist/terrain-jobs-worker.d.ts +2 -0
- package/dist/terrain-jobs-worker.js +130 -0
- package/dist/ui-layer.d.ts +5 -3
- package/dist/ui-layer.js +59 -8
- package/dist/world.d.ts +1596 -17
- package/dist/world.js +17035 -521
- package/gpl/fixtures/make_world_fixture.py +184 -0
- package/gpl/recipes/_common.py +11 -0
- package/gpl/recipes/decimate.py +11 -5
- package/gpl/recipes/export_world.py +699 -0
- package/mcp/blender-server.mjs +61 -4
- package/mcp/blender.mjs +3 -4
- package/mcp/engine-server.mjs +55 -21
- package/mcp/servers.mjs +4 -4
- package/package.json +15 -9
- package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
- package/patches/three@0.185.1.patch +8246 -389
- package/scripts/apply-three-patch.mjs +123 -41
- package/src/animation-blend.ts +264 -0
- package/src/animation-composition.ts +362 -0
- package/src/animation-layers.ts +260 -0
- package/src/animation-root-motion.ts +283 -0
- package/src/animation.ts +896 -0
- package/src/assets.ts +1303 -0
- package/src/atmosphere/index.ts +335 -0
- package/src/atmosphere/luts.ts +298 -0
- package/src/atmosphere/params.ts +323 -0
- package/src/audio.ts +912 -0
- package/src/billboard.ts +124 -0
- package/src/bone-lengths.ts +157 -0
- package/src/camera-shake.ts +116 -0
- package/src/canvas-layer.ts +47 -0
- package/src/clip-audit.ts +401 -0
- package/src/clustered-batch.ts +492 -0
- package/src/clustered-mesh.ts +638 -0
- package/src/compute-driven.ts +176 -0
- package/src/compute-timing.ts +318 -0
- package/src/config.ts +593 -0
- package/src/debug.ts +82 -0
- package/src/engine-render-hook.ts +25 -0
- package/src/entities.ts +79 -0
- package/src/entity-snapshot.ts +53 -0
- package/src/flight.ts +683 -0
- package/src/fluid-field.ts +748 -0
- package/src/fluid-particles.ts +1253 -0
- package/src/frame-budget.ts +1368 -0
- package/src/game.ts +2390 -0
- package/src/geometry-capture.ts +1098 -0
- package/src/gpu-class.ts +160 -0
- package/src/gpu-frame-observation.ts +424 -0
- package/src/gpu-readback.ts +143 -0
- package/src/gpu-scene-bvh.ts +464 -0
- package/src/grounding.ts +100 -0
- package/src/hot.ts +161 -0
- package/src/import-meta.d.ts +13 -0
- package/src/index.ts +1536 -0
- package/src/input.ts +690 -0
- package/src/instanced-batch-lod.ts +283 -0
- package/src/instanced-batch.ts +274 -0
- package/src/interpolation.ts +129 -0
- package/src/launch-diagnostics.ts +161 -0
- package/src/loop.ts +564 -0
- package/src/matrix-world.ts +245 -0
- package/src/merge-parts.ts +812 -0
- package/src/model-lod.ts +1315 -0
- package/src/net-protocol.ts +333 -0
- package/src/net-session.ts +477 -0
- package/src/net.ts +80 -0
- package/src/ocean/fft.ts +72 -0
- package/src/ocean/spectral.ts +728 -0
- package/src/particle-significance.ts +102 -0
- package/src/particles.ts +648 -0
- package/src/path-follow.ts +175 -0
- package/src/picking.ts +250 -0
- package/src/pipeline-census.ts +1566 -0
- package/src/platform.ts +210 -0
- package/src/playtest.ts +839 -0
- package/src/pointer-events.ts +411 -0
- package/src/pose-measure.ts +435 -0
- package/src/profiling/FrameCounters.ts +231 -0
- package/src/profiling/Spans.ts +548 -0
- package/src/profiling/opacity-convention.ts +21 -0
- package/src/profiling/render-list-validate.ts +175 -0
- package/src/profiling/render-trap-audit.ts +84 -0
- package/src/profiling/scene-warning.ts +190 -0
- package/src/profiling/span-probes.ts +191 -0
- package/src/profiling/unlit-foliage-warning.ts +149 -0
- package/src/projection-apply.ts +1529 -0
- package/src/projection-marker.ts +142 -0
- package/src/projection-plan.ts +1258 -0
- package/src/projection-skinned.ts +419 -0
- package/src/projection-stability.ts +409 -0
- package/src/projection-uniform.ts +328 -0
- package/src/random.ts +41 -0
- package/src/react-css.ts +604 -0
- package/src/react-glyphs.ts +114 -0
- package/src/react-host.ts +576 -0
- package/src/react-layout.ts +265 -0
- package/src/react.ts +60 -0
- package/src/render/alpha-antialiasing.ts +159 -0
- package/src/render/batched-velocity.ts +126 -0
- package/src/render/chain.ts +1021 -0
- package/src/render/daylight.ts +189 -0
- package/src/render/depth-pyramid.ts +596 -0
- package/src/render/foliage-alpha.ts +166 -0
- package/src/render/material-key.ts +60 -0
- package/src/render/mesh-pool.ts +144 -0
- package/src/render/probe-volume.ts +1668 -0
- package/src/render/resolution-subrect.ts +253 -0
- package/src/render/velocity.ts +442 -0
- package/src/render/virtual-shadow-pages.ts +827 -0
- package/src/render/virtual-shadow-partial.ts +174 -0
- package/src/render/virtual-shadow.ts +3330 -0
- package/src/render/world-impostor-surface.ts +722 -0
- package/src/render/world-impostor.ts +558 -0
- package/src/render-camera-cull.ts +441 -0
- package/src/render-pass-budget.ts +501 -0
- package/src/renderProjection.ts +758 -0
- package/src/renderer-config.ts +127 -0
- package/src/renderer.ts +1847 -0
- package/src/replay-protocol.ts +85 -0
- package/src/replay.ts +205 -0
- package/src/resolution-scaler.ts +819 -0
- package/src/rig-preparation.ts +271 -0
- package/src/ripple-field.ts +432 -0
- package/src/scale.ts +109 -0
- package/src/scene.ts +239 -0
- package/src/schedule.ts +155 -0
- package/src/skeletal-mesh.ts +61 -0
- package/src/skeleton.ts +100 -0
- package/src/snow-field.ts +744 -0
- package/src/softbody-topology.ts +269 -0
- package/src/softbody.ts +516 -0
- package/src/sprite-animator.ts +222 -0
- package/src/startup-readiness.ts +386 -0
- package/src/state.ts +66 -0
- package/src/static-transform.ts +274 -0
- package/src/storage-buffer.ts +253 -0
- package/src/streaming.ts +308 -0
- package/src/target-fps.ts +92 -0
- package/src/terrain-jobs-worker.ts +17 -0
- package/src/terrain-jobs.ts +353 -0
- package/src/textures.ts +39 -0
- package/src/tracers.ts +237 -0
- package/src/ui-bridge.ts +368 -0
- package/src/ui-hit-regions.ts +380 -0
- package/src/ui-layer.ts +83 -0
- package/src/ui-state.ts +220 -0
- package/src/version.ts +2 -0
- package/src/viewport.ts +253 -0
- package/src/warmup.ts +1357 -0
- package/src/water-surface.ts +384 -0
- package/src/wave-field.ts +524 -0
- package/src/world-capabilities.ts +131 -0
- package/src/world-cell-proxy.ts +392 -0
- package/src/world-cells.ts +10564 -0
- package/src/world-gpu-scene.ts +3354 -0
- package/src/world-heightmap.ts +82 -0
- package/src/world-package.ts +469 -0
- package/src/world-passes.ts +582 -0
- package/src/world-region.ts +17 -0
- package/src/world-terrain-splat.ts +564 -0
- package/src/world-tiles.ts +3826 -0
- package/src/world-topology.ts +370 -0
- package/src/world-validate.ts +48 -0
- package/src/world.ts +805 -0
- package/dist/gpu-readback-CMklJs6r.d.ts +0 -112
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgXToneMapping,
|
|
3
|
+
type Color,
|
|
4
|
+
DirectionalLight,
|
|
5
|
+
FogExp2,
|
|
6
|
+
Group,
|
|
7
|
+
HemisphereLight,
|
|
8
|
+
type Object3D,
|
|
9
|
+
type Scene,
|
|
10
|
+
type ToneMapping,
|
|
11
|
+
type Vector3,
|
|
12
|
+
} from "three";
|
|
13
|
+
import { SkyMesh } from "three/addons/objects/SkyMesh.js";
|
|
14
|
+
import type { IComputeDriven } from "../compute-driven.js";
|
|
15
|
+
import type { IRendererLike } from "../renderer.js";
|
|
16
|
+
import { VirtualShadowNode } from "./virtual-shadow.js";
|
|
17
|
+
|
|
18
|
+
/** Every value is the game's: this rig wires them and chooses none. */
|
|
19
|
+
export interface IDaylightOptions {
|
|
20
|
+
/** The eye the sky, the sun's shadow windows and the haze centre on; usually the camera. */
|
|
21
|
+
readonly follow: Object3D;
|
|
22
|
+
/** Unit vector from the ground towards the sun. */
|
|
23
|
+
readonly sunDirection: Vector3;
|
|
24
|
+
readonly sunColor: Color;
|
|
25
|
+
/** Irradiance in three's physical units; the same number a Blender sun strength carries. */
|
|
26
|
+
readonly sunIntensity: number;
|
|
27
|
+
/** Half-widths of the shadow windows in world units, finest first, strictly increasing. */
|
|
28
|
+
readonly shadowExtents: readonly number[];
|
|
29
|
+
/** Texels per shadow level edge; a level's texel is `2 * extent / shadowMapSize`. Default: the sun's `shadow.mapSize.width` (512). */
|
|
30
|
+
readonly shadowMapSize?: number;
|
|
31
|
+
/**
|
|
32
|
+
* How far a window may trail the camera before it re-renders, as a fraction of its own extent:
|
|
33
|
+
* one value for every level, or one per level finest first, the last entry standing in for the
|
|
34
|
+
* rest. One for all of them spends the hysteresis the fine level can least afford on the coarse
|
|
35
|
+
* one, which is the level a walking camera re-renders least. Default 0.125.
|
|
36
|
+
*/
|
|
37
|
+
readonly refreshStep?: number | readonly number[];
|
|
38
|
+
/** Preetham sky parameters, as three's `SkyMesh` takes them. */
|
|
39
|
+
readonly sky: {
|
|
40
|
+
readonly turbidity: number;
|
|
41
|
+
readonly rayleigh: number;
|
|
42
|
+
readonly mieCoefficient: number;
|
|
43
|
+
readonly mieDirectionalG: number;
|
|
44
|
+
};
|
|
45
|
+
/** Sky fill from above and bounce from below, as a hemisphere light. */
|
|
46
|
+
readonly fill: { readonly sky: Color; readonly ground: Color; readonly intensity: number };
|
|
47
|
+
/** Exponential-squared haze in the sky's horizon colour, so distance fades into the sky. */
|
|
48
|
+
readonly haze: { readonly color: Color; readonly density: number };
|
|
49
|
+
/** Linear exposure multiplier for the tone curve (2^EV). */
|
|
50
|
+
readonly exposure: number;
|
|
51
|
+
/** The tone curve, a look the game picks; AgX when it names none. */
|
|
52
|
+
readonly toneMapping?: ToneMapping;
|
|
53
|
+
/**
|
|
54
|
+
* Edge of the sky box in world units. It must sit inside the camera's far plane with its corners
|
|
55
|
+
* included (a box, so half-diagonal ≈ 0.87 × this).
|
|
56
|
+
*/
|
|
57
|
+
readonly skySize: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* An outdoor daylight rig: a physical sky that stays on the eye, one sun whose open-world shadow
|
|
62
|
+
* windows follow the eye (`VirtualShadowNode`), a hemisphere fill, sky-coloured distance haze and
|
|
63
|
+
* the AgX tone curve at the game's exposure. It is plumbing, not a look: every colour, angle,
|
|
64
|
+
* intensity and density is a required option, and the rig adds nothing a game did not ask for.
|
|
65
|
+
*
|
|
66
|
+
* Add it with `ctx.add(daylight)`: `attachRenderer` sets tone mapping, exposure and the shadow map
|
|
67
|
+
* once, and `process` (render cadence) keeps the sky box, the sun and its target on the eye every
|
|
68
|
+
* frame, so a 2 km map never walks out of its own sky or shadow.
|
|
69
|
+
*
|
|
70
|
+
* @situation daytime sky, sun and shadows for a large outdoor map
|
|
71
|
+
* @situation distant terrain should fade into the sky instead of a coloured wall
|
|
72
|
+
* @situation match a Blender look-dev scene's sun, sky and exposure in the game
|
|
73
|
+
* @constraint every value is required; there is no default sun, sky, haze or exposure
|
|
74
|
+
* @constraint `skySize` must keep the sky box's corners inside the camera's far plane
|
|
75
|
+
* @constraint shadowExtents follow `VirtualShadowNode`: half-widths, finest first, strictly increasing
|
|
76
|
+
* @override sky uniforms stay live on `daylight.sky`; the light and fill are `daylight.sun` and `daylight.fill`
|
|
77
|
+
* @example
|
|
78
|
+
* const daylight = new Daylight({ follow: ctx.camera, sunDirection, sunColor, sunIntensity: 4, shadowExtents: [24, 96, 320], sky: { turbidity: 3, rayleigh: 1.4, mieCoefficient: 0.004, mieDirectionalG: 0.8 }, fill: { sky, ground, intensity: 1.1 }, haze: { color: horizon, density: 0.0011 }, exposure: 2 ** -0.6, skySize: 1600 });
|
|
79
|
+
* ctx.add(daylight);
|
|
80
|
+
*/
|
|
81
|
+
export class Daylight extends Group implements IComputeDriven {
|
|
82
|
+
readonly warmupNodes: readonly unknown[] = [];
|
|
83
|
+
readonly processCadence = "render" as const;
|
|
84
|
+
readonly sky: SkyMesh;
|
|
85
|
+
readonly sun: DirectionalLight;
|
|
86
|
+
readonly fill: HemisphereLight;
|
|
87
|
+
readonly #follow: Object3D;
|
|
88
|
+
readonly #sunDirection: Vector3;
|
|
89
|
+
readonly #haze: FogExp2;
|
|
90
|
+
readonly #exposure: number;
|
|
91
|
+
readonly #toneMapping: ToneMapping;
|
|
92
|
+
#released = false;
|
|
93
|
+
|
|
94
|
+
constructor(options: IDaylightOptions) {
|
|
95
|
+
super();
|
|
96
|
+
this.name = "daylight";
|
|
97
|
+
if (!(options.exposure > 0)) throw new Error("Daylight exposure must be positive.");
|
|
98
|
+
if (!(options.skySize > 0)) throw new Error("Daylight skySize must be positive.");
|
|
99
|
+
this.#follow = options.follow;
|
|
100
|
+
this.#sunDirection = options.sunDirection.clone().normalize();
|
|
101
|
+
this.#exposure = options.exposure;
|
|
102
|
+
this.#toneMapping = options.toneMapping ?? AgXToneMapping;
|
|
103
|
+
|
|
104
|
+
this.sky = new SkyMesh();
|
|
105
|
+
this.sky.name = "daylight-sky";
|
|
106
|
+
this.sky.scale.setScalar(options.skySize);
|
|
107
|
+
this.sky.frustumCulled = false;
|
|
108
|
+
this.sky.turbidity.value = options.sky.turbidity;
|
|
109
|
+
this.sky.rayleigh.value = options.sky.rayleigh;
|
|
110
|
+
this.sky.mieCoefficient.value = options.sky.mieCoefficient;
|
|
111
|
+
this.sky.mieDirectionalG.value = options.sky.mieDirectionalG;
|
|
112
|
+
// The haze is for the world in front of the sky, not for the sky: the dome is half a sky size
|
|
113
|
+
// from the eye, fully fogged at any useful density, and a fogged dome is a flat grey sky.
|
|
114
|
+
this.sky.material.fog = false;
|
|
115
|
+
this.sky.sunPosition.value.copy(this.#sunDirection);
|
|
116
|
+
// Where the frame budget counts this mesh's main-pass draw (`RenderPassBudget`). One draw, on
|
|
117
|
+
// the main camera's own layer, and no world system owns it — so without the origin it is a line
|
|
118
|
+
// in the `other` bucket that reads as a prop rather than as the sky.
|
|
119
|
+
this.sky.userData.tnDrawSource = "sky";
|
|
120
|
+
this.add(this.sky);
|
|
121
|
+
|
|
122
|
+
this.fill = new HemisphereLight(options.fill.sky, options.fill.ground, options.fill.intensity);
|
|
123
|
+
this.add(this.fill);
|
|
124
|
+
|
|
125
|
+
this.sun = new DirectionalLight(options.sunColor, options.sunIntensity);
|
|
126
|
+
this.sun.name = "daylight-sun";
|
|
127
|
+
this.sun.castShadow = true;
|
|
128
|
+
this.sun.shadow.shadowNode = new VirtualShadowNode(this.sun, {
|
|
129
|
+
clipExtents: [...options.shadowExtents],
|
|
130
|
+
// A game that wants the fine level on a different cadence than the coarse two says so here,
|
|
131
|
+
// per level, instead of taking one step for all of them.
|
|
132
|
+
...(options.refreshStep === undefined ? {} : { refreshStep: options.refreshStep }),
|
|
133
|
+
...(options.shadowMapSize === undefined ? {} : { mapSize: options.shadowMapSize }),
|
|
134
|
+
});
|
|
135
|
+
this.add(this.sun);
|
|
136
|
+
this.add(this.sun.target);
|
|
137
|
+
|
|
138
|
+
this.#haze = new FogExp2(options.haze.color, options.haze.density);
|
|
139
|
+
this.#place();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
get released(): boolean {
|
|
143
|
+
return this.#released;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The haze this rig owns; `attachRenderer` puts it on the scene the rig was added to. */
|
|
147
|
+
get haze(): FogExp2 {
|
|
148
|
+
return this.#haze;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
attachRenderer(renderer: IRendererLike): void {
|
|
152
|
+
const raw = renderer.raw as {
|
|
153
|
+
toneMapping?: number;
|
|
154
|
+
toneMappingExposure?: number;
|
|
155
|
+
shadowMap?: { enabled: boolean };
|
|
156
|
+
};
|
|
157
|
+
raw.toneMapping = this.#toneMapping;
|
|
158
|
+
raw.toneMappingExposure = this.#exposure;
|
|
159
|
+
if (raw.shadowMap !== undefined) raw.shadowMap.enabled = true;
|
|
160
|
+
const scene = this.#scene();
|
|
161
|
+
if (scene !== undefined) {
|
|
162
|
+
scene.fog = this.#haze;
|
|
163
|
+
scene.background = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
process(): void {
|
|
168
|
+
this.#place();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
detach(): void {
|
|
172
|
+
const scene = this.#scene();
|
|
173
|
+
if (scene !== undefined && scene.fog === this.#haze) scene.fog = null;
|
|
174
|
+
this.#released = true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Sky box, sun and target on the eye; the sun sits along its direction, outside the windows. */
|
|
178
|
+
#place(): void {
|
|
179
|
+
const eye = this.#follow.getWorldPosition(this.sky.position);
|
|
180
|
+
this.sun.target.position.copy(eye);
|
|
181
|
+
this.sun.position.copy(eye).addScaledVector(this.#sunDirection, 400);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
#scene(): Scene | undefined {
|
|
185
|
+
let node: Object3D | null = this.parent;
|
|
186
|
+
while (node !== null && !(node as Scene).isScene) node = node.parent;
|
|
187
|
+
return (node as Scene | null) ?? undefined;
|
|
188
|
+
}
|
|
189
|
+
}
|