rayzee 11.2.1 → 11.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -34
- package/dist/ArchiveImporter-Cgyx5AF7.js +7860 -0
- package/dist/BidirectionalIntegrator-BKF-cwH2.js +954 -0
- package/dist/{BufferLayout-D_IBo2ci.js → BufferLayout-xPRH9jYD.js} +41 -5
- package/dist/{NeuralRetouch-Cr-otSW8.js → NeuralRetouch-C3Q2XqbF.js} +4 -3
- package/dist/{NeuralSuperRes-B7E3_M0t.js → NeuralSuperRes-DV5TtURP.js} +11 -5
- package/dist/{PathTracer-D6nbknj5.js → PathTracer-D3MvEaZK.js} +4384 -4618
- package/dist/{PhysicalSky-Dq5VSiCQ.js → PhysicalSky-CY4jiz6a.js} +2 -2
- package/dist/{RayzeeRenderer-DbjqO6v-.js → RayzeeRenderer-D23m6NqG.js} +486 -391
- package/dist/SolarLimb-bZE6y63S.js +762 -0
- package/dist/{ToneMapGPU-BOjpul7A.js → ToneMapGPU-CTDBvmmS.js} +31 -22
- package/dist/addons/archives.es.js +1 -1
- package/dist/addons/bidirectional.es.js +1 -1
- package/dist/addons/physical-sky.es.js +1 -1
- package/dist/rayzee-core.es.js +7 -7
- package/dist/rayzee.es.js +1327 -838
- package/dist/rayzee.umd.js +146 -134
- package/dist/sceneCachePolicy-AKOEu2lf.js +1602 -0
- package/package.json +1 -1
- package/src/EngineDefaults.js +2 -2
- package/src/Passes/AIUpscaler.js +2 -0
- package/src/PathTracerApp.js +126 -19
- package/src/Pipeline/CompletionTracker.js +7 -3
- package/src/Processor/ArchiveImporter.js +173 -94
- package/src/Processor/ArchiveReader.js +20 -23
- package/src/Processor/AssetLoader.js +48 -1
- package/src/Processor/BVHRefitter.js +109 -13
- package/src/Processor/BufferLayout.js +115 -0
- package/src/Processor/ChunkedRecords.js +3 -2
- package/src/Processor/EmissiveTriangleBuilder.js +6 -6
- package/src/Processor/GeometryExtractor.js +189 -79
- package/src/Processor/HostMemory.js +39 -9
- package/src/Processor/InstanceTable.js +714 -42
- package/src/Processor/PBRT/PBRTCurves.js +224 -6
- package/src/Processor/PBRT/PBRTMaterials.js +3 -0
- package/src/Processor/PBRT/PBRTSceneBuilder.js +82 -25
- package/src/Processor/PackedRayBuffer.js +5 -2
- package/src/Processor/SceneProcessor.js +747 -141
- package/src/Processor/TLASBuilder.js +32 -17
- package/src/Processor/ToneMapCPU.js +16 -4
- package/src/Processor/ToneMapGPU.js +30 -14
- package/src/Processor/USD/USDLayer.js +1149 -0
- package/src/Processor/USD/USDScene.js +1655 -0
- package/src/Processor/USD/USDStage.js +682 -0
- package/src/Processor/USD/USDText.js +674 -0
- package/src/Processor/USD/index.js +138 -0
- package/src/Processor/Workers/BVHRefitWorker.js +3 -3
- package/src/RayzeeRenderer.js +221 -33
- package/src/RenderSettings.js +4 -2
- package/src/Stages/AutoExposure.js +484 -494
- package/src/Stages/Compositor.js +27 -6
- package/src/Stages/LocalExposure.js +546 -0
- package/src/Stages/NormalDepth.js +7 -12
- package/src/Stages/PathTracer.js +18 -21
- package/src/Stages/PathTracerStage.js +282 -103
- package/src/Storage/GeometrySpill.js +46 -14
- package/src/Storage/SceneGraphCodec.js +17 -3
- package/src/Storage/SpillStore.js +9 -0
- package/src/TSL/BVHTraversal.js +183 -7
- package/src/TSL/Common.js +57 -13
- package/src/TSL/ShadeKernel.js +3 -2
- package/src/TSL/TextureSampling.js +11 -8
- package/src/TSL/patches.js +84 -0
- package/src/index.js +1 -0
- package/src/integrators/BidirectionalIntegrator.js +20 -2
- package/src/managers/DenoisingManager.js +15 -19
- package/src/managers/InteractionManager.js +19 -6
- package/src/managers/MaterialDataManager.js +22 -5
- package/src/managers/UniformManager.js +3 -0
- package/src/managers/VideoRenderManager.js +30 -4
- package/src/neural/NeuralRetouch.js +1 -0
- package/src/neural/NeuralSuperRes.js +6 -1
- package/dist/ArchiveImporter-D_x863yu.js +0 -5198
- package/dist/BidirectionalIntegrator-DmkxxEOR.js +0 -946
- package/dist/SolarLimb-CPaeZVwz.js +0 -721
- package/dist/sceneCachePolicy-C4-4qwt6.js +0 -485
|
@@ -0,0 +1,1602 @@
|
|
|
1
|
+
import { t as e } from "./EngineEvents-Ci8dVWCP.js";
|
|
2
|
+
import { a as t, i as n, r } from "./Logger-dDDGj9Av.js";
|
|
3
|
+
import { f as i, v as a, y as o } from "./BufferLayout-xPRH9jYD.js";
|
|
4
|
+
import { n as s } from "./EngineIssues-CIZnXHsF.js";
|
|
5
|
+
import { n as c, r as l } from "./shared-BGBcSxBQ.js";
|
|
6
|
+
import { n as u } from "./AssetConfig-DSEntE65.js";
|
|
7
|
+
import { BackSide as d, BufferAttribute as f, Color as p, DoubleSide as m, FrontSide as h, Matrix3 as g, Matrix4 as _, RGBAFormat as v, Vector2 as y, Vector3 as b } from "three";
|
|
8
|
+
//#region src/Processor/utils.js
|
|
9
|
+
var x = null;
|
|
10
|
+
function S(e) {
|
|
11
|
+
x = e;
|
|
12
|
+
}
|
|
13
|
+
var C = () => x?.({ type: e.LOADING_RESET }), w = (t) => {
|
|
14
|
+
x?.({
|
|
15
|
+
type: e.LOADING_UPDATE,
|
|
16
|
+
...t
|
|
17
|
+
});
|
|
18
|
+
}, T = (t) => {
|
|
19
|
+
x?.({
|
|
20
|
+
type: e.STATS_UPDATE,
|
|
21
|
+
...t
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
function ee(e) {
|
|
25
|
+
return e.frameCount || 0;
|
|
26
|
+
}
|
|
27
|
+
function te(e) {
|
|
28
|
+
if (Array.isArray(e)) e.forEach((e) => {
|
|
29
|
+
e.userData && e.userData.isFallback || (ne(e), e.dispose());
|
|
30
|
+
});
|
|
31
|
+
else {
|
|
32
|
+
if (e.userData && e.userData.isFallback) return;
|
|
33
|
+
ne(e), e.dispose();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function ne(e) {
|
|
37
|
+
e && [
|
|
38
|
+
"alphaMap",
|
|
39
|
+
"aoMap",
|
|
40
|
+
"bumpMap",
|
|
41
|
+
"clearcoatMap",
|
|
42
|
+
"clearcoatNormalMap",
|
|
43
|
+
"clearcoatRoughnessMap",
|
|
44
|
+
"displacementMap",
|
|
45
|
+
"emissiveMap",
|
|
46
|
+
"envMap",
|
|
47
|
+
"gradientMap",
|
|
48
|
+
"lightMap",
|
|
49
|
+
"map",
|
|
50
|
+
"metalnessMap",
|
|
51
|
+
"normalMap",
|
|
52
|
+
"roughnessMap",
|
|
53
|
+
"specularMap",
|
|
54
|
+
"sheenColorMap",
|
|
55
|
+
"sheenRoughnessMap",
|
|
56
|
+
"specularIntensityMap",
|
|
57
|
+
"specularColorMap",
|
|
58
|
+
"thicknessMap",
|
|
59
|
+
"transmissionMap",
|
|
60
|
+
"diffuseTransmissionMap",
|
|
61
|
+
"diffuseTransmissionColorMap"
|
|
62
|
+
].forEach((t) => {
|
|
63
|
+
e[t] && (e[t].dispose(), e[t] = null);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function re({ material: e, geometry: t, children: n }) {
|
|
67
|
+
if (e && te(e), t && t.dispose(), n.length > 0) for (let e of n) re(e);
|
|
68
|
+
}
|
|
69
|
+
function ie(e) {
|
|
70
|
+
if (!e) return;
|
|
71
|
+
e._canvasTarget && e._onCanvasTargetResize && e._canvasTarget.removeEventListener("resize", e._onCanvasTargetResize);
|
|
72
|
+
let t = e.dispose();
|
|
73
|
+
return e._canvasTarget = null, t;
|
|
74
|
+
}
|
|
75
|
+
function ae(e, t = []) {
|
|
76
|
+
if (e && !(t.includes(e.name) || e.isScene)) {
|
|
77
|
+
if (e.isMaterial) {
|
|
78
|
+
te(e);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
for (; e.children.length > 0;) for (let t of e.children) ae(t);
|
|
82
|
+
re(e), e.removeFromParent(), e.clear();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function oe(e) {
|
|
86
|
+
e?.traverse((e) => {
|
|
87
|
+
e.geometry?.userData?.__rayzeeOwned && e.geometry.dispose();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function se(e, t) {
|
|
91
|
+
return t;
|
|
92
|
+
}
|
|
93
|
+
function ce(e, t = !1) {
|
|
94
|
+
return t ? 1 : 1 / (e + 1);
|
|
95
|
+
}
|
|
96
|
+
function le() {
|
|
97
|
+
let e = 0, t = 0, n = 0, r = 0;
|
|
98
|
+
return {
|
|
99
|
+
start() {
|
|
100
|
+
e = performance.now();
|
|
101
|
+
},
|
|
102
|
+
end() {
|
|
103
|
+
t = performance.now();
|
|
104
|
+
let i = t - e;
|
|
105
|
+
return r += i, n++, i;
|
|
106
|
+
},
|
|
107
|
+
getAverageFrameTime() {
|
|
108
|
+
return n > 0 ? r / n : 0;
|
|
109
|
+
},
|
|
110
|
+
getFPS() {
|
|
111
|
+
let e = this.getAverageFrameTime();
|
|
112
|
+
return e > 0 ? 1e3 / e : 0;
|
|
113
|
+
},
|
|
114
|
+
reset() {
|
|
115
|
+
n = 0, r = 0;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/EngineDefaults.js
|
|
121
|
+
var E = de({
|
|
122
|
+
maxBounces: 3,
|
|
123
|
+
transmissiveBounces: 5,
|
|
124
|
+
maxSubsurfaceSteps: 8,
|
|
125
|
+
maxTransparentBounces: 32,
|
|
126
|
+
integrator: "path",
|
|
127
|
+
shadowRays: "two",
|
|
128
|
+
samplingTechnique: 2,
|
|
129
|
+
enableEmissiveTriangleSampling: !1,
|
|
130
|
+
emissiveBoost: 1,
|
|
131
|
+
enableAlphaShadows: !1,
|
|
132
|
+
fireflyThreshold: 3,
|
|
133
|
+
shadowTerminatorOffset: .1,
|
|
134
|
+
globalIlluminationIntensity: 1,
|
|
135
|
+
wavefrontSortMaterials: !0,
|
|
136
|
+
maxSamples: 60,
|
|
137
|
+
renderLimitMode: "frames",
|
|
138
|
+
renderTimeLimit: 30,
|
|
139
|
+
renderMode: 0,
|
|
140
|
+
useAdaptiveSampling: !0,
|
|
141
|
+
noiseThreshold: .1,
|
|
142
|
+
adaptiveMinSamples: 8,
|
|
143
|
+
adaptiveStopFraction: .9,
|
|
144
|
+
usePixelFreeze: !0,
|
|
145
|
+
pixelFreezeThreshold: .02,
|
|
146
|
+
pixelFreezeStability: 8,
|
|
147
|
+
convergenceOverlay: !1,
|
|
148
|
+
interactionModeEnabled: !0,
|
|
149
|
+
exposure: 1,
|
|
150
|
+
saturation: 1,
|
|
151
|
+
transparentBackground: !1,
|
|
152
|
+
backgroundColor: "#000000",
|
|
153
|
+
enableEnvironment: !0,
|
|
154
|
+
environmentIntensity: 1,
|
|
155
|
+
environmentRotation: 0,
|
|
156
|
+
showBackground: !0,
|
|
157
|
+
backgroundIntensity: 1,
|
|
158
|
+
backgroundBlurriness: 0,
|
|
159
|
+
backgroundBlurSamples: 8,
|
|
160
|
+
groundProjectionEnabled: !1,
|
|
161
|
+
groundProjectionRadius: 100,
|
|
162
|
+
groundProjectionHeight: 15,
|
|
163
|
+
groundProjectionLevel: 0,
|
|
164
|
+
enableGroundCatcher: !1,
|
|
165
|
+
groundCatcherHeight: 0,
|
|
166
|
+
cameraProjection: "perspective",
|
|
167
|
+
panoramaLonRange: [-180, 180],
|
|
168
|
+
panoramaLatRange: [-90, 90],
|
|
169
|
+
panoramaLevelHorizon: !0,
|
|
170
|
+
enableDOF: !1,
|
|
171
|
+
dofMode: "look",
|
|
172
|
+
dofBlur: .05,
|
|
173
|
+
focusDistance: .8,
|
|
174
|
+
aperture: 5.6,
|
|
175
|
+
focalLength: 50,
|
|
176
|
+
apertureScale: 1,
|
|
177
|
+
anamorphicRatio: 1,
|
|
178
|
+
unitsPerMetre: 1,
|
|
179
|
+
maxTextureSize: 4096,
|
|
180
|
+
areaLightIntensityScale: .1,
|
|
181
|
+
visMode: 0,
|
|
182
|
+
debugVisScale: 100
|
|
183
|
+
}), ue = Object.freeze({
|
|
184
|
+
perspective: 0,
|
|
185
|
+
equirectangular: 1,
|
|
186
|
+
orthographic: 2
|
|
187
|
+
}), D = de({
|
|
188
|
+
color: [
|
|
189
|
+
1,
|
|
190
|
+
1,
|
|
191
|
+
1
|
|
192
|
+
],
|
|
193
|
+
emissive: [
|
|
194
|
+
0,
|
|
195
|
+
0,
|
|
196
|
+
0
|
|
197
|
+
],
|
|
198
|
+
emissiveIntensity: 1,
|
|
199
|
+
roughness: 1,
|
|
200
|
+
metalness: 0,
|
|
201
|
+
ior: 1.5,
|
|
202
|
+
opacity: 1,
|
|
203
|
+
transmission: 0,
|
|
204
|
+
thickness: 0,
|
|
205
|
+
attenuationColor: [
|
|
206
|
+
1,
|
|
207
|
+
1,
|
|
208
|
+
1
|
|
209
|
+
],
|
|
210
|
+
attenuationDistance: Infinity,
|
|
211
|
+
dispersion: 0,
|
|
212
|
+
sheen: 0,
|
|
213
|
+
sheenRoughness: 1,
|
|
214
|
+
sheenColor: [
|
|
215
|
+
0,
|
|
216
|
+
0,
|
|
217
|
+
0
|
|
218
|
+
],
|
|
219
|
+
specularIntensity: 1,
|
|
220
|
+
specularColor: [
|
|
221
|
+
1,
|
|
222
|
+
1,
|
|
223
|
+
1
|
|
224
|
+
],
|
|
225
|
+
clearcoat: 0,
|
|
226
|
+
clearcoatRoughness: 0,
|
|
227
|
+
iridescence: 0,
|
|
228
|
+
iridescenceIOR: 1.3,
|
|
229
|
+
iridescenceThicknessRange: [100, 400],
|
|
230
|
+
normalScale: [1, 1],
|
|
231
|
+
bumpScale: 1,
|
|
232
|
+
displacementScale: 1,
|
|
233
|
+
transparent: 0,
|
|
234
|
+
alphaTest: 0,
|
|
235
|
+
alphaMode: 0,
|
|
236
|
+
side: 0,
|
|
237
|
+
depthWrite: 1,
|
|
238
|
+
subsurface: 0,
|
|
239
|
+
subsurfaceColor: [
|
|
240
|
+
1,
|
|
241
|
+
1,
|
|
242
|
+
1
|
|
243
|
+
],
|
|
244
|
+
subsurfaceRadius: [
|
|
245
|
+
1,
|
|
246
|
+
.2,
|
|
247
|
+
.1
|
|
248
|
+
],
|
|
249
|
+
subsurfaceRadiusScale: 1,
|
|
250
|
+
subsurfaceAnisotropy: 0,
|
|
251
|
+
anisotropy: 0,
|
|
252
|
+
anisotropyRotation: 0,
|
|
253
|
+
diffuseTransmission: 0,
|
|
254
|
+
diffuseTransmissionColor: [
|
|
255
|
+
1,
|
|
256
|
+
1,
|
|
257
|
+
1
|
|
258
|
+
]
|
|
259
|
+
});
|
|
260
|
+
function de(e) {
|
|
261
|
+
for (let t of Object.values(e)) typeof t == "object" && Object.freeze(t);
|
|
262
|
+
return Object.freeze(e);
|
|
263
|
+
}
|
|
264
|
+
var fe = {
|
|
265
|
+
maxSamples: 30,
|
|
266
|
+
bounces: 20,
|
|
267
|
+
transmissiveBounces: 24,
|
|
268
|
+
maxSubsurfaceSteps: 64,
|
|
269
|
+
renderMode: 1,
|
|
270
|
+
enableAlphaShadows: !0,
|
|
271
|
+
enableOIDN: !0,
|
|
272
|
+
oidnQuality: "high",
|
|
273
|
+
interactionModeEnabled: !1,
|
|
274
|
+
useAdaptiveSampling: !0,
|
|
275
|
+
noiseThreshold: .02,
|
|
276
|
+
adaptiveStopFraction: .94,
|
|
277
|
+
usePixelFreeze: !0
|
|
278
|
+
}, pe = {
|
|
279
|
+
maxSamples: E.maxSamples,
|
|
280
|
+
bounces: E.maxBounces,
|
|
281
|
+
renderMode: E.renderMode,
|
|
282
|
+
enableAlphaShadows: E.enableAlphaShadows,
|
|
283
|
+
transmissiveBounces: 12,
|
|
284
|
+
maxSubsurfaceSteps: E.maxSubsurfaceSteps,
|
|
285
|
+
enableOIDN: !0,
|
|
286
|
+
oidnQuality: "fast",
|
|
287
|
+
interactionModeEnabled: !0,
|
|
288
|
+
useAdaptiveSampling: !0,
|
|
289
|
+
noiseThreshold: .1,
|
|
290
|
+
usePixelFreeze: !0
|
|
291
|
+
};
|
|
292
|
+
function me(e) {
|
|
293
|
+
return {
|
|
294
|
+
maxSamples: e.maxSamples,
|
|
295
|
+
maxBounces: e.bounces,
|
|
296
|
+
transmissiveBounces: e.transmissiveBounces,
|
|
297
|
+
maxSubsurfaceSteps: e.maxSubsurfaceSteps,
|
|
298
|
+
enableAlphaShadows: e.enableAlphaShadows ?? !1,
|
|
299
|
+
useAdaptiveSampling: e.useAdaptiveSampling ?? !1,
|
|
300
|
+
noiseThreshold: e.noiseThreshold ?? E.noiseThreshold,
|
|
301
|
+
adaptiveStopFraction: e.adaptiveStopFraction ?? E.adaptiveStopFraction,
|
|
302
|
+
adaptiveMinSamples: e.adaptiveMinSamples ?? E.adaptiveMinSamples,
|
|
303
|
+
usePixelFreeze: e.usePixelFreeze ?? !1,
|
|
304
|
+
pixelFreezeThreshold: e.pixelFreezeThreshold ?? E.pixelFreezeThreshold,
|
|
305
|
+
pixelFreezeStability: e.pixelFreezeStability ?? E.pixelFreezeStability,
|
|
306
|
+
interactionModeEnabled: e.interactionModeEnabled ?? E.interactionModeEnabled
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/Processor/TextureBuckets.js
|
|
311
|
+
var O = {
|
|
312
|
+
VEC4_PER_BVH_NODE: 4,
|
|
313
|
+
FLOATS_PER_VEC4: 4,
|
|
314
|
+
MIN_TEXTURE_WIDTH: 4,
|
|
315
|
+
MAX_CONCURRENT_WORKERS: Math.min(typeof navigator < "u" && navigator.hardwareConcurrency || 4, 6),
|
|
316
|
+
BUFFER_POOL_SIZE: 20,
|
|
317
|
+
CANVAS_POOL_SIZE: 12,
|
|
318
|
+
CACHE_SIZE_LIMIT: 50,
|
|
319
|
+
MAX_TEXTURE_SIZE: 8192,
|
|
320
|
+
DEFAULT_MAX_TEXTURE_SIZE: 4096,
|
|
321
|
+
MAX_TEXTURES_LIMIT: 4 * 256,
|
|
322
|
+
MATERIAL_BUCKET_COUNT: 4,
|
|
323
|
+
BUCKET_LAYER_STRIDE: 256
|
|
324
|
+
}, he = 64;
|
|
325
|
+
function k(e, t) {
|
|
326
|
+
let n = Math.ceil(Math.max(1, e) / he) * he;
|
|
327
|
+
return Math.min(t, Math.max(O.MIN_TEXTURE_WIDTH, n));
|
|
328
|
+
}
|
|
329
|
+
function A(e) {
|
|
330
|
+
let t = 0, n = 0, r = 0;
|
|
331
|
+
for (let i of e) t = Math.max(t, i.width), n = Math.max(n, i.height), r += i.count;
|
|
332
|
+
return {
|
|
333
|
+
units: e,
|
|
334
|
+
width: t,
|
|
335
|
+
height: n,
|
|
336
|
+
count: r
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function j(e, t) {
|
|
340
|
+
return k(e.width, t) * e.height * e.count * 4;
|
|
341
|
+
}
|
|
342
|
+
function M(e, t) {
|
|
343
|
+
return e.reduce((e, n) => e + j(n, t), 0);
|
|
344
|
+
}
|
|
345
|
+
function ge(e, t, n) {
|
|
346
|
+
let r = e.slice();
|
|
347
|
+
for (; r.length > t;) {
|
|
348
|
+
let e = null;
|
|
349
|
+
for (let t = 0; t < r.length; t++) for (let i = t + 1; i < r.length; i++) {
|
|
350
|
+
let a = A(r[t].units.concat(r[i].units)), o = j(a, n) - j(r[t], n) - j(r[i], n);
|
|
351
|
+
(!e || o < e.delta) && (e = {
|
|
352
|
+
i: t,
|
|
353
|
+
j: i,
|
|
354
|
+
delta: o,
|
|
355
|
+
fused: a
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
r = r.filter((t, n) => n !== e.i && n !== e.j).concat([e.fused]);
|
|
359
|
+
}
|
|
360
|
+
return r;
|
|
361
|
+
}
|
|
362
|
+
function _e(e, t, n) {
|
|
363
|
+
let r = [];
|
|
364
|
+
for (let e = t - 1; e >= 0; e--) r.push(Math.max(O.MIN_TEXTURE_WIDTH, Math.round(n / 2 ** e)));
|
|
365
|
+
let i = r.map(() => []);
|
|
366
|
+
for (let t of e) {
|
|
367
|
+
let e = 2 ** Math.ceil(Math.log2(Math.max(t.width, t.height))), n = r.findIndex((t) => e <= t);
|
|
368
|
+
n < 0 && (n = r.length - 1), i[n].push(t);
|
|
369
|
+
}
|
|
370
|
+
return i.filter((e) => e.length).map(A);
|
|
371
|
+
}
|
|
372
|
+
function ve(e, t) {
|
|
373
|
+
let n = e;
|
|
374
|
+
for (let e = 0; e < 8; e++) {
|
|
375
|
+
let e = !1;
|
|
376
|
+
for (let r of n.flatMap((e) => e.units)) {
|
|
377
|
+
let i = n.findIndex((e) => e.units.includes(r));
|
|
378
|
+
if (!(i < 0)) for (let a = 0; a < n.length; a++) {
|
|
379
|
+
if (a === i) continue;
|
|
380
|
+
let o = [];
|
|
381
|
+
for (let e = 0; e < n.length; e++) if (e === i) {
|
|
382
|
+
let t = n[e].units.filter((e) => e !== r);
|
|
383
|
+
t.length && o.push(A(t));
|
|
384
|
+
} else e === a ? o.push(A(n[e].units.concat([r]))) : o.push(n[e]);
|
|
385
|
+
if (M(o, t) < M(n, t)) {
|
|
386
|
+
n = o, e = !0;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (!e) break;
|
|
392
|
+
}
|
|
393
|
+
return n;
|
|
394
|
+
}
|
|
395
|
+
function ye(e, t, n = O.MATERIAL_BUCKET_COUNT) {
|
|
396
|
+
let r = /* @__PURE__ */ new Map();
|
|
397
|
+
for (let { width: n, height: i } of e) {
|
|
398
|
+
let e = Math.min(t, Math.max(1, n || 1)), a = Math.min(t, Math.max(1, i || 1)), o = `${e}x${a}`, s = r.get(o);
|
|
399
|
+
s ? s.count++ : r.set(o, {
|
|
400
|
+
width: e,
|
|
401
|
+
height: a,
|
|
402
|
+
count: 1
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
let i = [...r.values()], a = i.map((e) => A([e]));
|
|
406
|
+
if (a.length > n) {
|
|
407
|
+
let e = _e(i, n, t), r = ge(a, n, t);
|
|
408
|
+
a = M(e, t) < M(r, t) ? e : r, a = ve(a, t);
|
|
409
|
+
}
|
|
410
|
+
return a.map((e) => ({
|
|
411
|
+
width: k(e.width, t),
|
|
412
|
+
height: e.height
|
|
413
|
+
})).sort((e, t) => e.width * e.height - t.width * t.height);
|
|
414
|
+
}
|
|
415
|
+
function be(e, t, n) {
|
|
416
|
+
let r = Math.max(1, e || 1), i = Math.max(1, t || 1);
|
|
417
|
+
for (let e = 0; e < n.length; e++) if (n[e].width >= r && n[e].height >= i) return e;
|
|
418
|
+
return Math.max(0, n.length - 1);
|
|
419
|
+
}
|
|
420
|
+
function xe(e, t) {
|
|
421
|
+
return e * O.BUCKET_LAYER_STRIDE + t;
|
|
422
|
+
}
|
|
423
|
+
//#endregion
|
|
424
|
+
//#region src/Processor/ChunkedRecords.js
|
|
425
|
+
var N = 64 * 1024 * 1024, P = typeof SharedArrayBuffer < "u", F = null;
|
|
426
|
+
function Se(e) {
|
|
427
|
+
F = e;
|
|
428
|
+
}
|
|
429
|
+
function I(e, t, n) {
|
|
430
|
+
let r = n ? new e(new SharedArrayBuffer(t * e.BYTES_PER_ELEMENT)) : new e(t);
|
|
431
|
+
return F && r.byteLength > 0 && F(r.byteLength, n), r;
|
|
432
|
+
}
|
|
433
|
+
var L = class e {
|
|
434
|
+
constructor(e, t, n, r = N, i = !1) {
|
|
435
|
+
let a = t * n.BYTES_PER_ELEMENT, o = Math.max(1, Math.floor(r / a));
|
|
436
|
+
this.recordCount = e, this.lanesPerRecord = t, this.LaneType = n, this.recordsPerChunk = e <= o ? Math.max(e, 1) : o, this.shared = i, this.chunks = [];
|
|
437
|
+
let s = e;
|
|
438
|
+
for (; s > 0;) {
|
|
439
|
+
let e = Math.min(s, this.recordsPerChunk);
|
|
440
|
+
this.chunks.push(I(n, e * t, i)), s -= e;
|
|
441
|
+
}
|
|
442
|
+
this.chunks.length === 0 && this.chunks.push(I(n, 0, i));
|
|
443
|
+
}
|
|
444
|
+
static adopt(t, n, r, i) {
|
|
445
|
+
let a = Object.create(e.prototype);
|
|
446
|
+
return a.recordCount = n, a.lanesPerRecord = r, a.LaneType = t[0]?.constructor ?? null, a.recordsPerChunk = i, a.chunks = t, a.shared = typeof SharedArrayBuffer < "u" && t[0]?.buffer instanceof SharedArrayBuffer, a;
|
|
447
|
+
}
|
|
448
|
+
static lazy(t, n, r, i = N, a = !1) {
|
|
449
|
+
let o = Math.max(1, Math.floor(i / (n * r.BYTES_PER_ELEMENT))), s = Object.create(e.prototype);
|
|
450
|
+
return s.recordCount = t, s.lanesPerRecord = n, s.LaneType = r, s.recordsPerChunk = t <= o ? Math.max(t, 1) : o, s.shared = a, s.chunks = Array(Math.max(1, Math.ceil(t / s.recordsPerChunk))), s._views = [], s;
|
|
451
|
+
}
|
|
452
|
+
_materialize(e) {
|
|
453
|
+
if (this._owner) return this._owner._materialize(e), this.chunks[e];
|
|
454
|
+
let t = e * this.recordsPerChunk, n = Math.min(this.recordsPerChunk, this.recordCount - t) * this.lanesPerRecord, r = this.chunks[e] = I(this.LaneType, n, this.shared);
|
|
455
|
+
for (let t of this._liveViews()) t.chunks[e] = new t.LaneType(r.buffer, r.byteOffset, r.byteLength / t.LaneType.BYTES_PER_ELEMENT);
|
|
456
|
+
return r;
|
|
457
|
+
}
|
|
458
|
+
materializeAll() {
|
|
459
|
+
for (let e = 0; e < this.chunks.length; e++) !this.chunks[e] && !this._spilled?.has(e) && this._materialize(e);
|
|
460
|
+
return this;
|
|
461
|
+
}
|
|
462
|
+
get chunkCount() {
|
|
463
|
+
return this.chunks.length;
|
|
464
|
+
}
|
|
465
|
+
get single() {
|
|
466
|
+
return this.chunks.length === 1 ? this.chunks[0] : null;
|
|
467
|
+
}
|
|
468
|
+
get byteLength() {
|
|
469
|
+
let e = 0;
|
|
470
|
+
for (let t of this.chunks) t && (e += t.byteLength);
|
|
471
|
+
return e;
|
|
472
|
+
}
|
|
473
|
+
chunkFor(e) {
|
|
474
|
+
let t = e / this.recordsPerChunk | 0, n = this.chunks[t];
|
|
475
|
+
if (n) return n;
|
|
476
|
+
if (this._spilled?.has(t)) throw Error(`ChunkedRecords: chunk ${t} is on disk — await ensureResident() before touching record ${e}`);
|
|
477
|
+
return this._materialize(t);
|
|
478
|
+
}
|
|
479
|
+
async spill(e, { keep: t = () => !1 } = {}) {
|
|
480
|
+
if (this._owner) throw Error("ChunkedRecords: spill the storage, not a view of it");
|
|
481
|
+
this._store = e, this._spilled ??= /* @__PURE__ */ new Set();
|
|
482
|
+
let n = 0;
|
|
483
|
+
for (let r = 0; r < this.chunks.length; r++) {
|
|
484
|
+
let i = this.chunks[r];
|
|
485
|
+
if (!(!i || t(r))) {
|
|
486
|
+
await e.write(r, i), this.chunks[r] = null;
|
|
487
|
+
for (let e of this._liveViews()) e.chunks[r] = null;
|
|
488
|
+
this._spilled.add(r), n += i.byteLength;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return n;
|
|
492
|
+
}
|
|
493
|
+
async spillChunk(e, t) {
|
|
494
|
+
let n = this.chunks[e];
|
|
495
|
+
if (!n) return 0;
|
|
496
|
+
this._store = t, this._spilled ??= /* @__PURE__ */ new Set(), await t.write(e, n), this.chunks[e] = null;
|
|
497
|
+
for (let t of this._liveViews()) t.chunks[e] = null;
|
|
498
|
+
return this._spilled.add(e), n.byteLength;
|
|
499
|
+
}
|
|
500
|
+
async ensureResident(e = 0, t = this.recordCount) {
|
|
501
|
+
if (!this._spilled?.size || t <= 0) return;
|
|
502
|
+
let n = e / this.recordsPerChunk | 0, r = (e + t - 1) / this.recordsPerChunk | 0;
|
|
503
|
+
for (let e = n; e <= r; e++) {
|
|
504
|
+
if (!this._spilled.has(e)) continue;
|
|
505
|
+
let t = Math.min(this.recordsPerChunk, this.recordCount - e * this.recordsPerChunk) * this.lanesPerRecord, n = I(this.LaneType, t, this.shared), r = new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
|
|
506
|
+
this._store.readInto ? await this._store.readInto(e, r) : r.set(new Uint8Array(await this._store.read(e, r.byteLength))), this.chunks[e] = n;
|
|
507
|
+
for (let t of this._liveViews()) t.chunks[e] = new t.LaneType(n.buffer, n.byteOffset, n.byteLength / t.LaneType.BYTES_PER_ELEMENT);
|
|
508
|
+
this._spilled.delete(e);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
_liveViews() {
|
|
512
|
+
return this._weakViews &&= this._weakViews.filter((e) => e.deref()), [...this._views ?? [], ...(this._weakViews ?? []).map((e) => e.deref())];
|
|
513
|
+
}
|
|
514
|
+
isResident(e = 0, t = this.recordCount) {
|
|
515
|
+
if (!this._spilled?.size || t <= 0) return !0;
|
|
516
|
+
let n = e / this.recordsPerChunk | 0, r = (e + t - 1) / this.recordsPerChunk | 0;
|
|
517
|
+
for (let e = n; e <= r; e++) if (this._spilled.has(e)) return !1;
|
|
518
|
+
return !0;
|
|
519
|
+
}
|
|
520
|
+
get spilledChunks() {
|
|
521
|
+
return this._spilled?.size ?? 0;
|
|
522
|
+
}
|
|
523
|
+
baseOf(e) {
|
|
524
|
+
return e % this.recordsPerChunk * this.lanesPerRecord;
|
|
525
|
+
}
|
|
526
|
+
isContiguous(e, t) {
|
|
527
|
+
return t <= 0 ? !0 : (e / this.recordsPerChunk | 0) == ((e + t - 1) / this.recordsPerChunk | 0);
|
|
528
|
+
}
|
|
529
|
+
slice(e, t) {
|
|
530
|
+
let n = this.baseOf(e), r = t * this.lanesPerRecord;
|
|
531
|
+
if (this.isContiguous(e, t)) return this.chunkFor(e).subarray(n, n + r);
|
|
532
|
+
let i = new this.LaneType(r);
|
|
533
|
+
return this.readRecords(e, t, i), i;
|
|
534
|
+
}
|
|
535
|
+
readRecords(e, t, n) {
|
|
536
|
+
let r = 0;
|
|
537
|
+
for (; r < t;) {
|
|
538
|
+
let i = e + r, a = this.chunkFor(i), o = this.baseOf(i), s = this.recordsPerChunk - i % this.recordsPerChunk, c = Math.min(s, t - r);
|
|
539
|
+
n.set(a.subarray(o, o + c * this.lanesPerRecord), r * this.lanesPerRecord), r += c;
|
|
540
|
+
}
|
|
541
|
+
return n;
|
|
542
|
+
}
|
|
543
|
+
setRecords(e, t) {
|
|
544
|
+
let n = t.length / this.lanesPerRecord, r = 0;
|
|
545
|
+
for (; r < n;) {
|
|
546
|
+
let i = e + r, a = this.chunkFor(i), o = this.baseOf(i), s = this.recordsPerChunk - i % this.recordsPerChunk, c = Math.min(s, n - r);
|
|
547
|
+
a.set(t.subarray(r * this.lanesPerRecord, (r + c) * this.lanesPerRecord), o), r += c;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
copyOf(e, t) {
|
|
551
|
+
return this.readRecords(e, t, new this.LaneType(t * this.lanesPerRecord));
|
|
552
|
+
}
|
|
553
|
+
trimTo(t) {
|
|
554
|
+
let n = Math.max(1, Math.ceil(t / this.recordsPerChunk)), r = this.chunks.slice(0, n), i = (t - (n - 1) * this.recordsPerChunk) * this.lanesPerRecord, a = r[n - 1];
|
|
555
|
+
return a.length > i && (r[n - 1] = a.subarray(0, Math.max(0, i))), e.adopt(r, t, this.lanesPerRecord, this.recordsPerChunk);
|
|
556
|
+
}
|
|
557
|
+
grow(e) {
|
|
558
|
+
if (e <= this.recordCount) return;
|
|
559
|
+
let t = this.chunks.length - 1, n = (e, t) => Math.min(this.recordsPerChunk, t - e * this.recordsPerChunk) * this.lanesPerRecord, r = this.chunks[t];
|
|
560
|
+
this.recordCount = e;
|
|
561
|
+
for (let t of this._liveViews()) t.recordCount = e;
|
|
562
|
+
if (this.chunks.length * this.recordsPerChunk < e) {
|
|
563
|
+
this.chunks.length = Math.ceil(e / this.recordsPerChunk);
|
|
564
|
+
for (let e of this._liveViews()) e.chunks.length = this.chunks.length;
|
|
565
|
+
}
|
|
566
|
+
if (r && r.length < n(t, e)) {
|
|
567
|
+
let i = I(this.LaneType, n(t, e), this.shared);
|
|
568
|
+
i.set(r), this.chunks[t] = i;
|
|
569
|
+
for (let e of this._liveViews()) e.chunks[t] = new e.LaneType(i.buffer, i.byteOffset, i.byteLength / e.LaneType.BYTES_PER_ELEMENT);
|
|
570
|
+
} else if (!r && this._spilled?.has(t)) throw Error(`ChunkedRecords: cannot grow past chunk ${t}, which is on disk`);
|
|
571
|
+
}
|
|
572
|
+
release(e, t) {
|
|
573
|
+
let n = this.recordsPerChunk, r = Math.ceil(e / n), i = Math.floor((e + t) / n), a = 0;
|
|
574
|
+
for (let e = r; e < i; e++) {
|
|
575
|
+
let t = this.chunks[e];
|
|
576
|
+
if (t) {
|
|
577
|
+
a += t.byteLength, this.chunks[e] = void 0;
|
|
578
|
+
for (let t of this._liveViews()) t.chunks[e] = void 0;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return a;
|
|
582
|
+
}
|
|
583
|
+
trimInPlace(e) {
|
|
584
|
+
let t = Math.max(1, Math.ceil(e / this.recordsPerChunk)), n = Math.max(0, (e - (t - 1) * this.recordsPerChunk) * this.lanesPerRecord), r = [this, ...this._liveViews()];
|
|
585
|
+
for (let i of r) {
|
|
586
|
+
i.chunks.length = t;
|
|
587
|
+
let r = i.chunks[t - 1];
|
|
588
|
+
r && r.length > n && (i.chunks[t - 1] = r.subarray(0, n)), i.recordCount = e;
|
|
589
|
+
}
|
|
590
|
+
if (this._spilled) for (let e of this._spilled) e >= t && this._spilled.delete(e);
|
|
591
|
+
return this;
|
|
592
|
+
}
|
|
593
|
+
viewAs(t) {
|
|
594
|
+
let n = (e) => new t(e.buffer, e.byteOffset, e.byteLength / t.BYTES_PER_ELEMENT), r = e.adopt(this.chunks.map((e) => e ? n(e) : void 0), this.recordCount, this.lanesPerRecord, this.recordsPerChunk);
|
|
595
|
+
return r.LaneType = t, r._owner = this, this._views ? this._views.push(r) : (this._weakViews ??= []).push(new WeakRef(r)), r._spilled = this._spilled ??= /* @__PURE__ */ new Set(), r;
|
|
596
|
+
}
|
|
597
|
+
}, Ce = 32 * 1024 * 1024, R = "chunks.bin", we = class e {
|
|
598
|
+
static async create(t, n, r, { label: i = "", expectedBytes: a = 0 } = {}) {
|
|
599
|
+
let o = t?.area(l.SPILL), s = await o?.create(n, {
|
|
600
|
+
label: i,
|
|
601
|
+
expectedBytes: a,
|
|
602
|
+
growable: [R]
|
|
603
|
+
});
|
|
604
|
+
return s ? new e(o, n, r, s) : null;
|
|
605
|
+
}
|
|
606
|
+
constructor(e, t, n, r) {
|
|
607
|
+
this._area = e, this._key = t, this._chunkBytes = n, this._writer = r, this._entry = null, this._file = null;
|
|
608
|
+
}
|
|
609
|
+
write(e, t) {
|
|
610
|
+
return this.writeAt(e * this._chunkBytes, t);
|
|
611
|
+
}
|
|
612
|
+
async writeAt(e, t) {
|
|
613
|
+
if (!this._writer && (this._entry?.release(), this._entry = this._file = null, this._writer = await this._area.edit(this._key), !this._writer)) throw Error("spill: its storage entry is gone");
|
|
614
|
+
let n = new Uint8Array(t.buffer, t.byteOffset, t.byteLength), r = 0;
|
|
615
|
+
do
|
|
616
|
+
await this._writer.write(R, n.subarray(r, Math.min(n.length, r + Ce)), { at: e + r }), r += Ce;
|
|
617
|
+
while (r < n.length);
|
|
618
|
+
}
|
|
619
|
+
async flush() {
|
|
620
|
+
if (this._writer &&= (await this._writer.commit(), null), !this._entry && (this._entry = await this._area.open(this._key, { wait: !0 }), this._file = await this._entry?.file(R), !this._file)) throw Error("spill: its storage entry is gone");
|
|
621
|
+
}
|
|
622
|
+
read(e, t) {
|
|
623
|
+
return this.readAt(e * this._chunkBytes, t);
|
|
624
|
+
}
|
|
625
|
+
async readAt(e, t) {
|
|
626
|
+
return await this.flush(), await this._file.slice(e, e + t).arrayBuffer();
|
|
627
|
+
}
|
|
628
|
+
async readInto(e, t) {
|
|
629
|
+
let n = await this.read(e, t.byteLength);
|
|
630
|
+
t.set(new Uint8Array(n)), n.transfer?.(0);
|
|
631
|
+
}
|
|
632
|
+
async dispose() {
|
|
633
|
+
this._writer && await this._writer.abort(), this._writer = null, this._entry?.release(), this._entry = this._file = null, await this._area.remove(this._key);
|
|
634
|
+
}
|
|
635
|
+
}, z = 32 * 1024 * 1024, Te = z / 4, Ee = 64 * 1024 * 1024, De = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new WeakSet();
|
|
636
|
+
function V(e) {
|
|
637
|
+
B.delete(e), e.transfer?.(0);
|
|
638
|
+
}
|
|
639
|
+
function Oe(e) {
|
|
640
|
+
let t = De.get(e);
|
|
641
|
+
return t || De.set(e, t = new e(0)), t;
|
|
642
|
+
}
|
|
643
|
+
var ke = class e {
|
|
644
|
+
static async create(t, n, r = 0) {
|
|
645
|
+
let i = await we.create(t, n, 0, {
|
|
646
|
+
label: "Scene geometry (while building)",
|
|
647
|
+
expectedBytes: r
|
|
648
|
+
});
|
|
649
|
+
return i ? new e(i) : null;
|
|
650
|
+
}
|
|
651
|
+
static canTake(e) {
|
|
652
|
+
if (Object.keys(e.morphAttributes ?? {}).length) return !1;
|
|
653
|
+
for (let t in e.attributes) if (!e.attributes[t].isBufferAttribute) return !1;
|
|
654
|
+
return !e.index || e.index.isBufferAttribute === !0;
|
|
655
|
+
}
|
|
656
|
+
constructor(e) {
|
|
657
|
+
this._store = e, this._records = [], this._geometries = [], this._end = 0, this._pack = null, this._packAt = 0, this._packUsed = 0, this._packRecords = [], this._chain = Promise.resolve(), this._queued = 0, this.bytes = 0, this.error = null;
|
|
658
|
+
}
|
|
659
|
+
get queuedBytes() {
|
|
660
|
+
return this._queued;
|
|
661
|
+
}
|
|
662
|
+
add(e) {
|
|
663
|
+
e.boundingBox || e.computeBoundingBox(), e.boundingSphere || e.computeBoundingSphere();
|
|
664
|
+
let t = Object.values(e.attributes);
|
|
665
|
+
e.index && t.push(e.index), this.addAttributes(t), this._geometries.push({
|
|
666
|
+
geometry: e,
|
|
667
|
+
box: e.boundingBox.clone(),
|
|
668
|
+
sphere: e.boundingSphere.clone()
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
addAttributes(e) {
|
|
672
|
+
let t = /* @__PURE__ */ new Map();
|
|
673
|
+
for (let n of e) {
|
|
674
|
+
let e = n.array;
|
|
675
|
+
if (!e?.byteLength) continue;
|
|
676
|
+
let r = t.get(e);
|
|
677
|
+
r || t.set(e, r = this._write(e)), r.attributes.push(n), n.array = Oe(e.constructor);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
_write(e) {
|
|
681
|
+
let t = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), n = {
|
|
682
|
+
at: 0,
|
|
683
|
+
byteLength: t.byteLength,
|
|
684
|
+
Type: e.constructor,
|
|
685
|
+
attributes: [],
|
|
686
|
+
array: null,
|
|
687
|
+
pack: null,
|
|
688
|
+
offset: 0
|
|
689
|
+
};
|
|
690
|
+
return this._records.push(n), this.bytes += t.byteLength, t.byteLength >= Te ? (n.at = this._end, n.array = e, this._end += t.byteLength, this._queue(n.at, t, [n]), n) : (this._pack && this._packUsed + t.byteLength > z && this._flushPack(), this._pack || (this._pack = new Uint8Array(z), this._packAt = this._end, this._packUsed = 0, this._end += z), this._pack.set(t, this._packUsed), n.at = this._packAt + this._packUsed, n.pack = this._pack, n.offset = this._packUsed, this._packUsed += n.byteLength, this._packRecords.push(n), B.has(e.buffer) && V(e.buffer), n);
|
|
691
|
+
}
|
|
692
|
+
_flushPack() {
|
|
693
|
+
this._pack && (this._queue(this._packAt, this._pack.subarray(0, this._packUsed), this._packRecords, !0), this._pack = null, this._packRecords = []);
|
|
694
|
+
}
|
|
695
|
+
_queue(e, t, n, r = !1) {
|
|
696
|
+
let i = t.byteLength;
|
|
697
|
+
this._queued += i, this._chain = this._chain.then(async () => {
|
|
698
|
+
if (!this.error) {
|
|
699
|
+
await this._store.writeAt(e, t);
|
|
700
|
+
for (let e of n) {
|
|
701
|
+
let t = e.array?.buffer;
|
|
702
|
+
e.array = e.pack = null, B.has(t) && V(t);
|
|
703
|
+
}
|
|
704
|
+
r && t.buffer.transfer?.(0);
|
|
705
|
+
}
|
|
706
|
+
}).catch((e) => void (this.error ??= e)).finally(() => void (this._queued -= i));
|
|
707
|
+
}
|
|
708
|
+
written() {
|
|
709
|
+
return this._flushPack(), this._chain;
|
|
710
|
+
}
|
|
711
|
+
async restore() {
|
|
712
|
+
await this.written();
|
|
713
|
+
let e = this._records.sort((e, t) => e.at - t.at);
|
|
714
|
+
e.some((e) => !e.array && !e.pack) && await this._store.flush();
|
|
715
|
+
let t = null, n = 0;
|
|
716
|
+
for (let r of e) {
|
|
717
|
+
let e;
|
|
718
|
+
if (r.array ? e = r.array : r.pack ? e = new r.Type(r.pack.slice(r.offset, r.offset + r.byteLength).buffer) : r.byteLength > Ee ? e = new r.Type(await this._store.readAt(r.at, r.byteLength)) : ((!t || r.at + r.byteLength > n + t.byteLength) && (t && V(t), n = r.at, t = await this._store.readAt(r.at, Ee)), e = new r.Type(t.slice(r.at - n, r.at - n + r.byteLength))), e.byteLength !== r.byteLength) throw Error("geometry spill: an array came back short");
|
|
719
|
+
e !== r.array && B.add(e.buffer);
|
|
720
|
+
for (let t of r.attributes) t.array = e;
|
|
721
|
+
}
|
|
722
|
+
t && V(t);
|
|
723
|
+
for (let { geometry: e, box: t, sphere: n } of this._geometries) e.boundingBox = t, e.boundingSphere = n;
|
|
724
|
+
this._records = [], this._geometries = [], this.bytes = 0;
|
|
725
|
+
}
|
|
726
|
+
async dispose() {
|
|
727
|
+
await this._chain, this._records = [], this._geometries = [], this._pack = null, this._packRecords = [], await this._store.dispose();
|
|
728
|
+
}
|
|
729
|
+
}, Ae = r("geometry"), H = O.MAX_TEXTURES_LIMIT, je = new Set([
|
|
730
|
+
"color",
|
|
731
|
+
"emissive",
|
|
732
|
+
"attenuationColor",
|
|
733
|
+
"sheenColor",
|
|
734
|
+
"specularColor",
|
|
735
|
+
"subsurfaceColor",
|
|
736
|
+
"diffuseTransmissionColor"
|
|
737
|
+
]), U = Object.freeze({
|
|
738
|
+
MATERIAL: "material",
|
|
739
|
+
MAPPED: "mapped",
|
|
740
|
+
DEFAULT: "default",
|
|
741
|
+
HOST: "host"
|
|
742
|
+
}), Me = [
|
|
743
|
+
1,
|
|
744
|
+
0,
|
|
745
|
+
0,
|
|
746
|
+
0,
|
|
747
|
+
0,
|
|
748
|
+
1,
|
|
749
|
+
0,
|
|
750
|
+
0,
|
|
751
|
+
0,
|
|
752
|
+
0,
|
|
753
|
+
1,
|
|
754
|
+
0,
|
|
755
|
+
0,
|
|
756
|
+
0,
|
|
757
|
+
0,
|
|
758
|
+
1
|
|
759
|
+
];
|
|
760
|
+
function Ne(e) {
|
|
761
|
+
for (let t = 0; t < 16; t++) if (e[t] !== Me[t]) return !1;
|
|
762
|
+
return !0;
|
|
763
|
+
}
|
|
764
|
+
function W(e) {
|
|
765
|
+
return {
|
|
766
|
+
map: e.map,
|
|
767
|
+
normalMap: e.normalMap,
|
|
768
|
+
bumpMap: e.bumpMap,
|
|
769
|
+
roughnessMap: e.roughnessMap,
|
|
770
|
+
metalnessMap: e.metalnessMap,
|
|
771
|
+
emissiveMap: e.emissiveMap ?? (e.isMeshBasicMaterial ? e.map : void 0),
|
|
772
|
+
displacementMap: e.displacementMap,
|
|
773
|
+
anisotropyMap: e.anisotropyMap,
|
|
774
|
+
clearcoatMap: e.clearcoatMap,
|
|
775
|
+
clearcoatRoughnessMap: e.clearcoatRoughnessMap,
|
|
776
|
+
transmissionMap: e.transmissionMap,
|
|
777
|
+
sheenColorMap: e.sheenColorMap,
|
|
778
|
+
sheenRoughnessMap: e.sheenRoughnessMap,
|
|
779
|
+
specularIntensityMap: e.specularIntensityMap,
|
|
780
|
+
specularColorMap: e.specularColorMap,
|
|
781
|
+
diffuseTransmissionMap: e.diffuseTransmissionMap,
|
|
782
|
+
diffuseTransmissionColorMap: e.diffuseTransmissionColorMap,
|
|
783
|
+
iridescenceMap: e.iridescenceMap,
|
|
784
|
+
iridescenceThicknessMap: e.iridescenceThicknessMap
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
function Pe(e) {
|
|
788
|
+
if (e.userData?.gltfExtensions?.KHR_materials_unlit?.alphaMode) {
|
|
789
|
+
let t = e.userData.gltfExtensions.KHR_materials_unlit.alphaMode;
|
|
790
|
+
return t === "BLEND" ? 2 : +(t === "MASK");
|
|
791
|
+
}
|
|
792
|
+
return e.alphaTest > 0 ? 1 : e.transparent && e.opacity < 1 || e.map && e.map.format === v && e.transparent ? 2 : 0;
|
|
793
|
+
}
|
|
794
|
+
function Fe(e) {
|
|
795
|
+
let t = 0, n = /* @__PURE__ */ new Set(), r = (e) => {
|
|
796
|
+
let i = e.isMesh && e.material ? e.geometry : null;
|
|
797
|
+
if (i && !n.has(i.uuid)) {
|
|
798
|
+
n.add(i.uuid);
|
|
799
|
+
for (let e in i.attributes) t += i.attributes[e].array?.byteLength ?? 0;
|
|
800
|
+
t += i.index?.array?.byteLength ?? 0;
|
|
801
|
+
}
|
|
802
|
+
if (e.children) for (let t of e.children) r(t);
|
|
803
|
+
};
|
|
804
|
+
return r(e), t;
|
|
805
|
+
}
|
|
806
|
+
function Ie(e) {
|
|
807
|
+
let t = 0, n = /* @__PURE__ */ new Set();
|
|
808
|
+
return e.traverse?.((e) => {
|
|
809
|
+
let r = e.isInstancedMesh ? e.instanceMatrix?.array : null;
|
|
810
|
+
r && !n.has(r) && (n.add(r), t += r.byteLength);
|
|
811
|
+
}), t;
|
|
812
|
+
}
|
|
813
|
+
function G(e, t) {
|
|
814
|
+
let n = e.x, r = e.y, i = e.z;
|
|
815
|
+
e.x = t[0] * n + t[4] * r + t[8] * i + t[12], e.y = t[1] * n + t[5] * r + t[9] * i + t[13], e.z = t[2] * n + t[6] * r + t[10] * i + t[14];
|
|
816
|
+
}
|
|
817
|
+
function K(e, t) {
|
|
818
|
+
let n = e.x, r = e.y, i = e.z;
|
|
819
|
+
e.x = t[0] * n + t[3] * r + t[6] * i, e.y = t[1] * n + t[4] * r + t[7] * i, e.z = t[2] * n + t[5] * r + t[8] * i;
|
|
820
|
+
}
|
|
821
|
+
var q = 1 << 21;
|
|
822
|
+
function J(e) {
|
|
823
|
+
return !!(e.isSkinnedMesh || Object.keys(e.geometry?.morphAttributes ?? {}).length);
|
|
824
|
+
}
|
|
825
|
+
function Le(e) {
|
|
826
|
+
return e[0] * (e[5] * e[10] - e[9] * e[6]) - e[4] * (e[1] * e[10] - e[9] * e[2]) + e[8] * (e[1] * e[6] - e[5] * e[2]);
|
|
827
|
+
}
|
|
828
|
+
function Re(e) {
|
|
829
|
+
let t = !1, n = /* @__PURE__ */ new Set();
|
|
830
|
+
return e.traverse((e) => {
|
|
831
|
+
if (!(t || !e.isMesh || !e.material)) {
|
|
832
|
+
for (let r of Array.isArray(e.material) ? e.material : [e.material]) if (!n.has(r)) {
|
|
833
|
+
n.add(r);
|
|
834
|
+
for (let e in r) r[e]?.isTexture && (t = !0);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}), t;
|
|
838
|
+
}
|
|
839
|
+
function ze(e, t) {
|
|
840
|
+
let n = e.getAttribute(t);
|
|
841
|
+
if (!n || n.normalized || !(n.array instanceof Float32Array) || e.morphAttributes?.[t]?.length) return;
|
|
842
|
+
let r = n.array;
|
|
843
|
+
for (let e = 0; e < r.length; e++) {
|
|
844
|
+
let t = r[e];
|
|
845
|
+
if (!(t >= -1.0001 && t <= 1.0001)) return;
|
|
846
|
+
}
|
|
847
|
+
let i = new Int16Array(r.length);
|
|
848
|
+
for (let e = 0; e < r.length; e++) i[e] = Math.round(Math.max(-1, Math.min(1, r[e])) * 32767);
|
|
849
|
+
e.setAttribute(t, new f(i, n.itemSize, !0));
|
|
850
|
+
}
|
|
851
|
+
var Be = class {
|
|
852
|
+
constructor({ issues: e = null } = {}) {
|
|
853
|
+
this._issues = e, this._droppedTextures = 0, this._vectorPool = {
|
|
854
|
+
vec3: Array(9).fill().map(() => new b()),
|
|
855
|
+
vec2: [
|
|
856
|
+
,
|
|
857
|
+
,
|
|
858
|
+
,
|
|
859
|
+
,
|
|
860
|
+
,
|
|
861
|
+
,
|
|
862
|
+
].fill().map(() => new y())
|
|
863
|
+
}, this._geometryRanges = /* @__PURE__ */ new Map(), this.expandedTriangleCount = 0, this._allocatePlacements(0), this._matrixPool = {
|
|
864
|
+
mat3: new g(),
|
|
865
|
+
mat4: new _()
|
|
866
|
+
}, this.resetArrays(), this.triangleCount = 0, this.currentTriangleIndex = 0;
|
|
867
|
+
}
|
|
868
|
+
_getVec3(e = 0) {
|
|
869
|
+
return this._vectorPool.vec3[e % this._vectorPool.vec3.length];
|
|
870
|
+
}
|
|
871
|
+
_getVec2(e = 0) {
|
|
872
|
+
return this._vectorPool.vec2[e % this._vectorPool.vec2.length];
|
|
873
|
+
}
|
|
874
|
+
extract(e) {
|
|
875
|
+
this.resetArrays();
|
|
876
|
+
let t = this._countTriangles(e);
|
|
877
|
+
return this._triangleCapacity = Math.max(1024, t), this._allocateTriangles(this._triangleCapacity), this.currentTriangleIndex = 0, this._allocatePlacements(this._countPlacements(e)), this._geometryUses = this._countGeometryUses(e), this.bakeInverse = /* @__PURE__ */ new Map(), this.traverseObject(e), this._compressAttributes(e), this.logStats(), this.getExtractedData();
|
|
878
|
+
}
|
|
879
|
+
async extractStreaming(e, { onStore: t, onRange: n, pause: r, yieldEvery: i = 1 << 20, releaseGeometry: a = null }) {
|
|
880
|
+
this.resetArrays(), this._triangleCapacity = Math.max(1, this._countStoredTriangles(e)), this._allocateTriangles(this._triangleCapacity, !0), t?.(this.triangles), this.currentTriangleIndex = 0, this._allocatePlacements(this._countPlacements(e)), this._geometryUses = this._countGeometryUses(e), this.bakeInverse = /* @__PURE__ */ new Map(), this._onRange = n, this._releaseAfterRead = a ? this._geometryReleaser(e, a) : null;
|
|
881
|
+
try {
|
|
882
|
+
let t = [e], n = 0;
|
|
883
|
+
for (; t.length;) {
|
|
884
|
+
let e = t.pop();
|
|
885
|
+
if (this._visit(e), e.children) for (let n = e.children.length - 1; n >= 0; n--) t.push(e.children[n]);
|
|
886
|
+
this.currentTriangleIndex - n >= i && (n = this.currentTriangleIndex, await r(this.currentTriangleIndex));
|
|
887
|
+
}
|
|
888
|
+
} finally {
|
|
889
|
+
this._onRange = null, this._releaseAfterRead = null;
|
|
890
|
+
}
|
|
891
|
+
return this._compressAttributes(e), this.triangles.trimInPlace(this.currentTriangleIndex), this._streamedStore = !0, this.logStats(), this.getExtractedData();
|
|
892
|
+
}
|
|
893
|
+
_countStoredTriangles(e) {
|
|
894
|
+
let t = /* @__PURE__ */ new Set(), n = 0, r = (e) => {
|
|
895
|
+
if (e.isMesh && e.geometry && e.material) {
|
|
896
|
+
let r = e.geometry, i = Math.ceil((r.index ? r.index.count : r.attributes.position?.count ?? 0) / 3), a = Array.isArray(e.material) ? e.material[0] : e.material, o = a?.emissive, s = a?.emissiveIntensity > 0 && !!o && (o.r > 0 || o.g > 0 || o.b > 0), c = e.isInstancedMesh ? e.count ?? 0 : 1;
|
|
897
|
+
if (s && e.isInstancedMesh && !J(e) && i * c <= q) n += i * c;
|
|
898
|
+
else if (s || J(e)) n += i;
|
|
899
|
+
else {
|
|
900
|
+
let e = `${r.uuid}|${a?.uuid}`;
|
|
901
|
+
t.has(e) || (t.add(e), n += i);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
if (e.children) for (let t of e.children) r(t);
|
|
905
|
+
};
|
|
906
|
+
return r(e), n;
|
|
907
|
+
}
|
|
908
|
+
_geometryReleaser(e, t) {
|
|
909
|
+
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = (e, t) => {
|
|
910
|
+
t ||= !!e.userData?.__rayzeeExternal;
|
|
911
|
+
let o = e.isMesh && e.material ? e.geometry : null;
|
|
912
|
+
if (o) {
|
|
913
|
+
if (!n.has(o)) {
|
|
914
|
+
ke.canTake(o) || i.add(o);
|
|
915
|
+
for (let e of [...Object.values(o.attributes), o.index]) {
|
|
916
|
+
let t = e?.array;
|
|
917
|
+
if (!t) continue;
|
|
918
|
+
let n = r.get(t);
|
|
919
|
+
n && n !== o ? i.add(o).add(n) : r.set(t, o);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
n.set(o, (n.get(o) ?? 0) + 1), (t || J(e)) && i.add(o);
|
|
923
|
+
}
|
|
924
|
+
if (e.children) for (let n of e.children) a(n, t);
|
|
925
|
+
};
|
|
926
|
+
return a(e, !1), (e) => {
|
|
927
|
+
let r = e.material ? e.geometry : null;
|
|
928
|
+
if (!r || !n.has(r)) return;
|
|
929
|
+
let a = n.get(r) - 1;
|
|
930
|
+
if (a > 0) return void n.set(r, a);
|
|
931
|
+
n.delete(r), !i.has(r) && (this._compressGeometry(r), t(r));
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
surveyScene(e) {
|
|
935
|
+
let t = 0, n = (e) => {
|
|
936
|
+
if (e.isMesh && e.geometry && e.material && t++, e.children) for (let t of e.children) n(t);
|
|
937
|
+
};
|
|
938
|
+
return n(e), {
|
|
939
|
+
triangles: this._countTriangles(e),
|
|
940
|
+
placements: this._countPlacements(e),
|
|
941
|
+
meshes: t,
|
|
942
|
+
geometryBytes: Fe(e),
|
|
943
|
+
instanceBytes: Ie(e)
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
_countGeometryUses(e) {
|
|
947
|
+
let t = /* @__PURE__ */ new Map();
|
|
948
|
+
return e.traverse((e) => {
|
|
949
|
+
if (!e.isMesh || !e.geometry || !e.material) return;
|
|
950
|
+
let n = `${e.geometry.uuid}|${e.material.uuid}`;
|
|
951
|
+
t.set(n, (t.get(n) ?? 0) + 1);
|
|
952
|
+
}), t;
|
|
953
|
+
}
|
|
954
|
+
_countPlacements(e) {
|
|
955
|
+
let t = 0;
|
|
956
|
+
if (e.isMesh && e.geometry && e.material && (t += e.isInstancedMesh && e.instanceMatrix ? e.count ?? e.instanceMatrix.array.length / 16 : 1), e.children) for (let n of e.children) t += this._countPlacements(n);
|
|
957
|
+
return t;
|
|
958
|
+
}
|
|
959
|
+
_allocatePlacements(e) {
|
|
960
|
+
this.instanceCount = 0, this.instanceCapacity = e, this.instanceSource = new Int32Array(e), this._runs = {
|
|
961
|
+
first: [],
|
|
962
|
+
arrays: [],
|
|
963
|
+
arrayOf: [],
|
|
964
|
+
base: [],
|
|
965
|
+
owned: []
|
|
966
|
+
}, this._runArrayIndex = /* @__PURE__ */ new Map(), this._singles = null, this._singlesUsed = 0, this._singlesRun = null, this._compressed = /* @__PURE__ */ new Set(), this._matrixLists = /* @__PURE__ */ new Map();
|
|
967
|
+
}
|
|
968
|
+
_beginRun(e, t, n) {
|
|
969
|
+
let r = this._runs, i = this._runArrayIndex.get(e);
|
|
970
|
+
i === void 0 && this._runArrayIndex.set(e, i = r.arrays.push(e) - 1), r.first.push(this.instanceCount), r.arrayOf.push(i), r.base.push(t), r.owned.push(n);
|
|
971
|
+
}
|
|
972
|
+
_singleRow() {
|
|
973
|
+
let e = this._runs;
|
|
974
|
+
if (this._singles || (this._singles = new Float32Array(1024 * 16), this._singlesIndex = e.arrays.push(this._singles) - 1), this._singlesUsed + 16 > this._singles.length) {
|
|
975
|
+
let t = new Float32Array(this._singles.length * 2);
|
|
976
|
+
t.set(this._singles), this._singles = e.arrays[this._singlesIndex] = t;
|
|
977
|
+
}
|
|
978
|
+
this._singlesRun !== e.first.length - 1 && (e.first.push(this.instanceCount), e.arrayOf.push(this._singlesIndex), e.base.push(this._singlesUsed), e.owned.push(1), this._singlesRun = e.first.length - 1);
|
|
979
|
+
let t = this._singlesUsed;
|
|
980
|
+
return this._singlesUsed += 16, t;
|
|
981
|
+
}
|
|
982
|
+
_matrixRuns() {
|
|
983
|
+
let e = this._runs;
|
|
984
|
+
return {
|
|
985
|
+
first: [...e.first, this.instanceCount],
|
|
986
|
+
arrays: e.arrays,
|
|
987
|
+
arrayOf: e.arrayOf,
|
|
988
|
+
base: e.base,
|
|
989
|
+
owned: e.owned
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
_compressAttributes(e) {
|
|
993
|
+
let t = (e, n) => {
|
|
994
|
+
if (!e.userData?.__rayzeeExternal) {
|
|
995
|
+
n(e);
|
|
996
|
+
for (let r of e.children) t(r, n);
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
t(e, (e) => {
|
|
1000
|
+
e.isMesh && e.geometry && this._compressGeometry(e.geometry);
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
_compressGeometry(e) {
|
|
1004
|
+
if (!this._compressed.has(e.uuid)) {
|
|
1005
|
+
this._compressed.add(e.uuid);
|
|
1006
|
+
for (let t of [
|
|
1007
|
+
"normal",
|
|
1008
|
+
"tangent",
|
|
1009
|
+
"color"
|
|
1010
|
+
]) ze(e, t);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
_countTriangles(e) {
|
|
1014
|
+
let t = 0;
|
|
1015
|
+
if (e.isMesh && e.geometry && e.material) {
|
|
1016
|
+
let n = e.geometry.index, r = e.geometry.attributes.position;
|
|
1017
|
+
n ? t += Math.ceil(n.count / 3) : r && (t += Math.ceil(r.count / 3));
|
|
1018
|
+
}
|
|
1019
|
+
if (e.children) for (let n of e.children) t += this._countTriangles(n);
|
|
1020
|
+
return t;
|
|
1021
|
+
}
|
|
1022
|
+
_ensureCapacity(e) {
|
|
1023
|
+
if (e <= this._triangleCapacity) return;
|
|
1024
|
+
if (this._onRange) {
|
|
1025
|
+
this.triangles.grow(e), this._triangleCapacity = e;
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
let t = this.triangles, n = this.currentTriangleIndex;
|
|
1029
|
+
this._allocateTriangles(e);
|
|
1030
|
+
for (let e = 0; e < n; e++) this.triangles.chunkFor(e).set(t.chunkFor(e).subarray(t.baseOf(e), t.baseOf(e) + t.lanesPerRecord), this.triangles.baseOf(e));
|
|
1031
|
+
this._triangleCapacity = e;
|
|
1032
|
+
}
|
|
1033
|
+
_allocateTriangles(e, t = !1) {
|
|
1034
|
+
this.triangles = (t ? L.lazy : (...e) => new L(...e))(e, i.FLOATS_PER_TRIANGLE, Uint32Array, void 0, P), this.triangleFloatChunks = this.triangles.viewAs(Float32Array), this.triangleData = this.triangles.single, this.triangleFloats = this.triangleFloatChunks.single;
|
|
1035
|
+
}
|
|
1036
|
+
traverseObject(e) {
|
|
1037
|
+
if (this._visit(e), e.children) for (let t of e.children) this.traverseObject(t);
|
|
1038
|
+
}
|
|
1039
|
+
_visit(e) {
|
|
1040
|
+
e.isMesh ? (this.processMesh(e), this._releaseAfterRead?.(e)) : e.isDirectionalLight ? this.directionalLights.push(e) : e.isCamera && this.cameras.push(e);
|
|
1041
|
+
}
|
|
1042
|
+
processMesh(e) {
|
|
1043
|
+
if (!e.geometry || !e.material) {
|
|
1044
|
+
console.warn("Skipping mesh with missing geometry or material:", e);
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
let t = this.processMaterial(e.material);
|
|
1048
|
+
e.userData.materialIndex = t;
|
|
1049
|
+
let n = this.meshes.length;
|
|
1050
|
+
this.meshes.push(e), e.userData.meshIndex = n;
|
|
1051
|
+
let r = `${e.geometry.uuid}|${t}`, i = J(e), a = !this._emissiveMaterial(t) && !i, o = a ? this._geometryRanges.get(r) : null;
|
|
1052
|
+
if (o) {
|
|
1053
|
+
let t = {
|
|
1054
|
+
start: o.start,
|
|
1055
|
+
count: o.count,
|
|
1056
|
+
expandedStart: this.expandedTriangleCount,
|
|
1057
|
+
sharedFrom: o.meshIndex
|
|
1058
|
+
};
|
|
1059
|
+
this.expandedTriangleCount += o.count, this.meshTriangleRanges.push(t), this._recordPlacements(e, n, !1, !1, o.count > 0);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
let s = this.currentTriangleIndex, c = e.isInstancedMesh && !i && this._emissiveMaterial(t) && this._canExpand(e), l = c || !e.isInstancedMesh && !i && (this._geometryUses.get(`${e.geometry.uuid}|${e.material?.uuid}`) === 1 || this._emissiveMaterial(t));
|
|
1063
|
+
this.extractGeometry(e, t, n, l, c);
|
|
1064
|
+
let u = {
|
|
1065
|
+
start: s,
|
|
1066
|
+
count: this.currentTriangleIndex - s,
|
|
1067
|
+
expandedStart: this.expandedTriangleCount
|
|
1068
|
+
};
|
|
1069
|
+
this.expandedTriangleCount += u.count, this.meshTriangleRanges.push(u), u.count > 0 && !l && a && this._geometryRanges.set(r, {
|
|
1070
|
+
...u,
|
|
1071
|
+
meshIndex: n
|
|
1072
|
+
}), this._recordPlacements(e, n, l, c, u.count > 0 && a), u.count > 0 && this._onRange?.(n, u);
|
|
1073
|
+
}
|
|
1074
|
+
_recordPlacements(e, t, n = !1, r = !1, i = !1) {
|
|
1075
|
+
let a = e.matrixWorld.elements, o = this.instanceSource;
|
|
1076
|
+
if (!e.isInstancedMesh || !e.instanceMatrix || r) {
|
|
1077
|
+
let r = this._singleRow(), i = this._singles, s = this._nextPlacement();
|
|
1078
|
+
if (o[s] = t, n) {
|
|
1079
|
+
for (let e = 0; e < 16; e++) i[r + e] = +(e % 5 == 0);
|
|
1080
|
+
this.bakeInverse.set(t, Float32Array.from(this._matrixPool.mat4.copy(e.matrixWorld).invert().elements));
|
|
1081
|
+
} else for (let e = 0; e < 16; e++) i[r + e] = a[e];
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
let s = e.instanceMatrix.array, c = e.count ?? s.length / 16;
|
|
1085
|
+
if (i && c > 0) {
|
|
1086
|
+
let n = this._matrixLists.get(e.instanceMatrix);
|
|
1087
|
+
n || this._matrixLists.set(e.instanceMatrix, n = []), n.push({
|
|
1088
|
+
meshIndex: t,
|
|
1089
|
+
start: this.instanceCount,
|
|
1090
|
+
count: c,
|
|
1091
|
+
world: Float32Array.from(a)
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
if (c <= 0) return;
|
|
1095
|
+
let l = Ne(a) && s.length >= c * 16, u = l ? s : new Float32Array(c * 16);
|
|
1096
|
+
this._beginRun(l ? e.instanceMatrix : u, 0, +!l);
|
|
1097
|
+
for (let e = 0; e < c; e++) {
|
|
1098
|
+
let n = e * 16, r = this._nextPlacement(), i = e * 16;
|
|
1099
|
+
if (o[r] = t, !l) for (let e = 0; e < 4; e++) for (let t = 0; t < 4; t++) u[i + e * 4 + t] = a[t] * s[n + e * 4] + a[4 + t] * s[n + e * 4 + 1] + a[8 + t] * s[n + e * 4 + 2] + a[12 + t] * s[n + e * 4 + 3];
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
_instanceGroups() {
|
|
1103
|
+
let e = [];
|
|
1104
|
+
for (let t of this._matrixLists.values()) {
|
|
1105
|
+
let n = [];
|
|
1106
|
+
for (let e of t) {
|
|
1107
|
+
let t = n.find((t) => t.count === e.count && t.world.every((t, n) => t === e.world[n]));
|
|
1108
|
+
t ? (t.members.push(e.meshIndex), t.starts.push(e.start)) : n.push({
|
|
1109
|
+
world: e.world,
|
|
1110
|
+
count: e.count,
|
|
1111
|
+
members: [e.meshIndex],
|
|
1112
|
+
starts: [e.start]
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
for (let t of n) t.members.length >= 2 && e.push({
|
|
1116
|
+
members: t.members,
|
|
1117
|
+
starts: t.starts,
|
|
1118
|
+
count: t.count
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
return this._matrixLists.clear(), e;
|
|
1122
|
+
}
|
|
1123
|
+
_nextPlacement() {
|
|
1124
|
+
if (this.instanceCount >= this.instanceCapacity) {
|
|
1125
|
+
let e = Math.max(16, this.instanceCapacity * 2), t = new Int32Array(e);
|
|
1126
|
+
t.set(this.instanceSource), this.instanceSource = t, this.instanceCapacity = e;
|
|
1127
|
+
}
|
|
1128
|
+
return this.instanceCount++;
|
|
1129
|
+
}
|
|
1130
|
+
_canExpand(e) {
|
|
1131
|
+
let t = e.geometry, n = (t.index ? t.index.count : t.attributes.position.count) / 3, r = e.count ?? (e.instanceMatrix?.array.length ?? 0) / 16;
|
|
1132
|
+
return n * r <= q ? !0 : (this._issues?.record(s.EMISSIVE_INSTANCES_COLLAPSED, `"${e.name || "instanced mesh"}" would need ${Math.round(n * r).toLocaleString()} triangles to light every instance; lighting the first one only`, {
|
|
1133
|
+
instances: r,
|
|
1134
|
+
trianglesPerInstance: n,
|
|
1135
|
+
limit: q
|
|
1136
|
+
}), !1);
|
|
1137
|
+
}
|
|
1138
|
+
_emissiveMaterial(e) {
|
|
1139
|
+
let t = this.materials[e];
|
|
1140
|
+
if (!t || !(t.emissiveIntensity > 0)) return !1;
|
|
1141
|
+
let n = t.emissive;
|
|
1142
|
+
return !!n && (n.r > 0 || n.g > 0 || n.b > 0);
|
|
1143
|
+
}
|
|
1144
|
+
processMaterial(e) {
|
|
1145
|
+
let n = this._materialUuidMap.get(e.uuid) ?? -1;
|
|
1146
|
+
if (n === -1) {
|
|
1147
|
+
e.depthWrite === !1 && (e.depthWrite = !0, t(Ae, "depthWrite", "material had depthWrite disabled — enabled for rastered rendering"));
|
|
1148
|
+
let r = this.createMaterialObject(e);
|
|
1149
|
+
this.materials.push(r), n = this.materials.length - 1, this._materialUuidMap.set(e.uuid, n);
|
|
1150
|
+
}
|
|
1151
|
+
return n;
|
|
1152
|
+
}
|
|
1153
|
+
getMaterialType(e) {
|
|
1154
|
+
return e.isMeshPhysicalMaterial ? "physical" : e.isMeshStandardMaterial ? "standard" : e.isMeshPhongMaterial ? "phong" : e.isMeshLambertMaterial ? "lambert" : e.isMeshBasicMaterial ? "basic" : e.isMeshToonMaterial ? "toon" : "unknown";
|
|
1155
|
+
}
|
|
1156
|
+
getPhysicalDefaults() {
|
|
1157
|
+
let e = {};
|
|
1158
|
+
for (let [t, n] of Object.entries(D)) e[t] = je.has(t) ? new p().fromArray(n) : Array.isArray(n) ? [...n] : n;
|
|
1159
|
+
return e.normalScale = {
|
|
1160
|
+
x: D.normalScale[0],
|
|
1161
|
+
y: D.normalScale[1]
|
|
1162
|
+
}, e;
|
|
1163
|
+
}
|
|
1164
|
+
mapLegacyMaterialToPhysical(e, t) {
|
|
1165
|
+
let n = {};
|
|
1166
|
+
switch (t) {
|
|
1167
|
+
case "basic":
|
|
1168
|
+
n.emissive = e.color.clone(), n.emissiveIntensity = 1, n.color = new p(0), n.roughness = 1, n.metalness = 0, n.specularIntensity = 0;
|
|
1169
|
+
break;
|
|
1170
|
+
case "lambert":
|
|
1171
|
+
n.roughness = 1, n.metalness = 0, n.specularIntensity = 0;
|
|
1172
|
+
break;
|
|
1173
|
+
case "phong":
|
|
1174
|
+
{
|
|
1175
|
+
let t = e.shininess || 30;
|
|
1176
|
+
n.roughness = Math.sqrt(2 / (t + 2)), n.metalness = 0;
|
|
1177
|
+
}
|
|
1178
|
+
if (e.specular) {
|
|
1179
|
+
let t = e.specular, r = t.r * .299 + t.g * .587 + t.b * .114, i = Math.max(t.r, t.g, t.b);
|
|
1180
|
+
n.specularIntensity = Math.min(r * 2, 1), n.specularColor = i > 0 ? t.clone().multiplyScalar(1 / i) : new p(1, 1, 1);
|
|
1181
|
+
}
|
|
1182
|
+
break;
|
|
1183
|
+
case "toon":
|
|
1184
|
+
n.roughness = .9, n.metalness = 0;
|
|
1185
|
+
break;
|
|
1186
|
+
case "standard":
|
|
1187
|
+
case "physical": break;
|
|
1188
|
+
}
|
|
1189
|
+
return n;
|
|
1190
|
+
}
|
|
1191
|
+
createMaterialObject(e) {
|
|
1192
|
+
let t = this.getPhysicalDefaults(), n = this.getMaterialType(e), r = this.mapLegacyMaterialToPhysical(e, n), i = W(e), a = {}, o = (n) => r[n] === void 0 ? e[n] !== void 0 && e[n] !== null ? (a[n] = U.MATERIAL, e[n]) : (a[n] = U.DEFAULT, t[n]) : (a[n] = U.MAPPED, r[n]);
|
|
1193
|
+
for (let e of [
|
|
1194
|
+
"transparent",
|
|
1195
|
+
"alphaMode",
|
|
1196
|
+
"side",
|
|
1197
|
+
"depthWrite"
|
|
1198
|
+
]) a[e] = U.MATERIAL;
|
|
1199
|
+
return {
|
|
1200
|
+
uuid: e.uuid,
|
|
1201
|
+
color: o("color"),
|
|
1202
|
+
emissive: o("emissive"),
|
|
1203
|
+
emissiveIntensity: o("emissiveIntensity"),
|
|
1204
|
+
roughness: Math.max(.02, o("roughness")),
|
|
1205
|
+
metalness: o("metalness"),
|
|
1206
|
+
ior: o("ior"),
|
|
1207
|
+
opacity: o("opacity"),
|
|
1208
|
+
transmission: o("transmission"),
|
|
1209
|
+
thickness: o("thickness"),
|
|
1210
|
+
attenuationColor: o("attenuationColor"),
|
|
1211
|
+
attenuationDistance: o("attenuationDistance"),
|
|
1212
|
+
dispersion: o("dispersion"),
|
|
1213
|
+
sheen: o("sheen"),
|
|
1214
|
+
sheenRoughness: o("sheenRoughness"),
|
|
1215
|
+
sheenColor: o("sheenColor"),
|
|
1216
|
+
clearcoat: o("clearcoat"),
|
|
1217
|
+
clearcoatRoughness: o("clearcoatRoughness"),
|
|
1218
|
+
iridescence: o("iridescence"),
|
|
1219
|
+
iridescenceIOR: o("iridescenceIOR"),
|
|
1220
|
+
iridescenceThicknessRange: o("iridescenceThicknessRange"),
|
|
1221
|
+
subsurface: o("subsurface"),
|
|
1222
|
+
subsurfaceColor: o("subsurfaceColor"),
|
|
1223
|
+
subsurfaceRadius: o("subsurfaceRadius"),
|
|
1224
|
+
subsurfaceRadiusScale: o("subsurfaceRadiusScale"),
|
|
1225
|
+
subsurfaceAnisotropy: o("subsurfaceAnisotropy"),
|
|
1226
|
+
anisotropy: o("anisotropy"),
|
|
1227
|
+
anisotropyRotation: o("anisotropyRotation"),
|
|
1228
|
+
specularIntensity: o("specularIntensity"),
|
|
1229
|
+
specularColor: o("specularColor"),
|
|
1230
|
+
diffuseTransmission: o("diffuseTransmission"),
|
|
1231
|
+
diffuseTransmissionColor: o("diffuseTransmissionColor"),
|
|
1232
|
+
normalScale: o("normalScale"),
|
|
1233
|
+
bumpScale: o("bumpScale"),
|
|
1234
|
+
displacementScale: o("displacementScale"),
|
|
1235
|
+
transparent: +!!e.transparent,
|
|
1236
|
+
alphaTest: o("alphaTest"),
|
|
1237
|
+
alphaMode: Pe(e),
|
|
1238
|
+
side: this.getMaterialSide(e),
|
|
1239
|
+
depthWrite: e.depthWrite ?? !0 ? 1 : 0,
|
|
1240
|
+
map: this.processTexture(i.map, this.maps),
|
|
1241
|
+
normalMap: this.processTexture(i.normalMap, this.normalMaps),
|
|
1242
|
+
bumpMap: this.processTexture(i.bumpMap, this.bumpMaps),
|
|
1243
|
+
roughnessMap: this.processTexture(i.roughnessMap, this.roughnessMaps),
|
|
1244
|
+
metalnessMap: this.processTexture(i.metalnessMap, this.metalnessMaps),
|
|
1245
|
+
emissiveMap: this.processTexture(i.emissiveMap, this.emissiveMaps),
|
|
1246
|
+
displacementMap: this.processTexture(i.displacementMap, this.displacementMaps),
|
|
1247
|
+
anisotropyMap: this.processTexture(i.anisotropyMap, this.anisotropyMaps),
|
|
1248
|
+
clearcoatMap: this.processTexture(i.clearcoatMap, this.clearcoatMaps),
|
|
1249
|
+
clearcoatRoughnessMap: this.processTexture(i.clearcoatRoughnessMap, this.clearcoatRoughnessMaps),
|
|
1250
|
+
transmissionMap: this.processTexture(i.transmissionMap, this.transmissionMaps),
|
|
1251
|
+
thicknessMap: this.processTexture(e.thicknessMap, []),
|
|
1252
|
+
sheenColorMap: this.processTexture(i.sheenColorMap, this.sheenColorMaps),
|
|
1253
|
+
sheenRoughnessMap: this.processTexture(i.sheenRoughnessMap, this.sheenRoughnessMaps),
|
|
1254
|
+
specularIntensityMap: this.processTexture(i.specularIntensityMap, this.specularIntensityMaps),
|
|
1255
|
+
specularColorMap: this.processTexture(i.specularColorMap, this.specularColorMaps),
|
|
1256
|
+
diffuseTransmissionMap: this.processTexture(i.diffuseTransmissionMap, this.diffuseTransmissionMaps),
|
|
1257
|
+
diffuseTransmissionColorMap: this.processTexture(i.diffuseTransmissionColorMap, this.diffuseTransmissionColorMaps),
|
|
1258
|
+
iridescenceMap: this.processTexture(i.iridescenceMap, this.iridescenceMaps),
|
|
1259
|
+
iridescenceThicknessMap: this.processTexture(i.iridescenceThicknessMap, this.iridescenceThicknessMaps),
|
|
1260
|
+
mapMatrix: this.getTextureMatrix(i.map),
|
|
1261
|
+
normalMapMatrices: this.getTextureMatrix(i.normalMap),
|
|
1262
|
+
bumpMapMatrices: this.getTextureMatrix(i.bumpMap),
|
|
1263
|
+
roughnessMapMatrices: this.getTextureMatrix(i.roughnessMap),
|
|
1264
|
+
metalnessMapMatrices: this.getTextureMatrix(i.metalnessMap),
|
|
1265
|
+
emissiveMapMatrices: this.getTextureMatrix(i.emissiveMap),
|
|
1266
|
+
displacementMapMatrices: this.getTextureMatrix(i.displacementMap),
|
|
1267
|
+
sources: a,
|
|
1268
|
+
originalType: n
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
getTextureMatrix(e) {
|
|
1272
|
+
return e ? (e.matrixAutoUpdate && e.updateMatrix(), e.matrix.elements) : new g().elements;
|
|
1273
|
+
}
|
|
1274
|
+
getMaterialSide(e) {
|
|
1275
|
+
if (e.transmission > 0) return 2;
|
|
1276
|
+
switch (e.side) {
|
|
1277
|
+
case h: return 0;
|
|
1278
|
+
case d: return 1;
|
|
1279
|
+
case m: return 2;
|
|
1280
|
+
default: return 0;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
processTexture(e, t) {
|
|
1284
|
+
if (!e) return -1;
|
|
1285
|
+
let n = this._textureIndexCache.get(t);
|
|
1286
|
+
n || (n = /* @__PURE__ */ new Map(), this._textureIndexCache.set(t, n));
|
|
1287
|
+
let r = e.source.uuid, i = n.get(r);
|
|
1288
|
+
if (i !== void 0) return i;
|
|
1289
|
+
if (t.length < H) {
|
|
1290
|
+
t.push(e);
|
|
1291
|
+
let i = t.length - 1;
|
|
1292
|
+
return n.set(r, i), i;
|
|
1293
|
+
}
|
|
1294
|
+
return this._droppedTextures++, this._droppedTextures === 1 && this._issues?.record(s.TEXTURE_LIMIT_EXCEEDED, `scene needs more than ${H} distinct textures for one map type; the rest render untextured`, {
|
|
1295
|
+
limit: H,
|
|
1296
|
+
firstDropped: e.name || e.source?.uuid
|
|
1297
|
+
}), -1;
|
|
1298
|
+
}
|
|
1299
|
+
extractGeometry(e, t, n, r = !1, i = !1) {
|
|
1300
|
+
e.updateMatrix(), e.updateMatrixWorld();
|
|
1301
|
+
let a = e.geometry;
|
|
1302
|
+
a.attributes.normal || a.computeVertexNormals();
|
|
1303
|
+
let o = a.attributes.position, s = a.attributes.normal, c = a.attributes.uv, l = a.index ? a.index.array : null, u = l ? l.length / 3 : o.count / 3;
|
|
1304
|
+
if (i) {
|
|
1305
|
+
let r = e.count ?? e.instanceMatrix.array.length / 16, i = this._matrixPool.mat4, a = new _();
|
|
1306
|
+
for (let d = 0; d < r; d++) {
|
|
1307
|
+
i.fromArray(e.instanceMatrix.array, d * 16), a.multiplyMatrices(e.matrixWorld, i);
|
|
1308
|
+
let r = new g().getNormalMatrix(a);
|
|
1309
|
+
this.extractTrianglesInBatch(o, s, c, l, u, t, n, a, r, Le(a.elements) < 0);
|
|
1310
|
+
}
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
let d = r ? this._matrixPool.mat4.copy(e.matrixWorld) : null, f = r ? this._matrixPool.mat3.getNormalMatrix(e.matrixWorld) : null, p = r && Le(d.elements) < 0;
|
|
1314
|
+
this.extractTrianglesInBatch(o, s, c, l, u, t, n, d, f, p);
|
|
1315
|
+
}
|
|
1316
|
+
extractTrianglesInBatch(e, t, n, r, i, a, o, s = null, c = null, l = !1) {
|
|
1317
|
+
for (; this.materialTriangleCounts.length <= a;) this.materialTriangleCounts.push(0);
|
|
1318
|
+
this.materialTriangleCounts[a] += i;
|
|
1319
|
+
let u = this._getVec3(0), d = this._getVec3(1), f = this._getVec3(2), p = this._getVec3(3), m = this._getVec3(4), h = this._getVec3(5), g = this._getVec2(0), _ = this._getVec2(1), v = this._getVec2(2);
|
|
1320
|
+
this._ensureCapacity(this.currentTriangleIndex + i);
|
|
1321
|
+
let y = s?.elements, b = c?.elements;
|
|
1322
|
+
for (let c = 0; c < i; c++) {
|
|
1323
|
+
let i = c * 3, x = r ? r[i + 0] : i + 0, S = l ? 2 : 1, C = l ? 1 : 2, w = r ? r[i + S] : i + S, T = r ? r[i + C] : i + C;
|
|
1324
|
+
this.getVertex(e, x, u), this.getVertex(e, w, d), this.getVertex(e, T, f), this.getVertex(t, x, p), this.getVertex(t, w, m), this.getVertex(t, T, h), n ? (this.getVertex(n, x, g), this.getVertex(n, w, _), this.getVertex(n, T, v)) : (g.set(0, 0), _.set(0, 0), v.set(0, 0)), s && (G(u, y), G(d, y), G(f, y), K(p, b), K(m, b), K(h, b)), p.normalize(), m.normalize(), h.normalize(), this.packTriangleDataTextureFormat(this.currentTriangleIndex, u, d, f, p, m, h, g, _, v, a, o), this.currentTriangleIndex++;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
packTriangleDataTextureFormat(e, t, n, r, s, c, l, u, d, f, p, m) {
|
|
1328
|
+
let h = i, g = this.triangles.baseOf(e), _ = this.triangleFloatChunks.chunkFor(e), v = this.triangles.chunkFor(e);
|
|
1329
|
+
_[g + h.POSITION_A_OFFSET + 0] = t.x, _[g + h.POSITION_A_OFFSET + 1] = t.y, _[g + h.POSITION_A_OFFSET + 2] = t.z, v[g + h.NORMAL_A_PACKED_OFFSET] = a(s.x, s.y, s.z), _[g + h.POSITION_B_OFFSET + 0] = n.x, _[g + h.POSITION_B_OFFSET + 1] = n.y, _[g + h.POSITION_B_OFFSET + 2] = n.z, v[g + h.NORMAL_B_PACKED_OFFSET] = a(c.x, c.y, c.z), _[g + h.POSITION_C_OFFSET + 0] = r.x, _[g + h.POSITION_C_OFFSET + 1] = r.y, _[g + h.POSITION_C_OFFSET + 2] = r.z, v[g + h.NORMAL_C_PACKED_OFFSET] = a(l.x, l.y, l.z), _[g + h.UV_AB_OFFSET + 0] = u.x, _[g + h.UV_AB_OFFSET + 1] = u.y, _[g + h.UV_AB_OFFSET + 2] = d.x, _[g + h.UV_AB_OFFSET + 3] = d.y, _[g + h.UV_C_OFFSET + 0] = f.x, _[g + h.UV_C_OFFSET + 1] = f.y, v[g + h.MATERIAL_FLAGS_OFFSET] = o(p, this.materials[p]), v[g + h.MESH_INDEX_OFFSET] = m;
|
|
1330
|
+
}
|
|
1331
|
+
releaseTriangles() {
|
|
1332
|
+
this.triangles = null, this.triangleData = null, this.triangleFloatChunks = null, this.triangleFloats = null;
|
|
1333
|
+
}
|
|
1334
|
+
getTriangleData() {
|
|
1335
|
+
return this.triangles ? this._streamedStore ? this.triangles : this.triangles.trimTo(this.currentTriangleIndex) : null;
|
|
1336
|
+
}
|
|
1337
|
+
getTriangleCount() {
|
|
1338
|
+
return this.currentTriangleIndex;
|
|
1339
|
+
}
|
|
1340
|
+
getVertex(e, t, n) {
|
|
1341
|
+
return e.itemSize === 2 ? (n.x = e.getX(t), n.y = e.getY(t)) : e.itemSize >= 3 && (n.x = e.getX(t), n.y = e.getY(t), n.z = e.getZ(t)), n;
|
|
1342
|
+
}
|
|
1343
|
+
logStats() {
|
|
1344
|
+
let e = this.currentTriangleIndex * i.FLOATS_PER_TRIANGLE * 4;
|
|
1345
|
+
Ae.debug(n.list([
|
|
1346
|
+
`${n.count(this.currentTriangleIndex, "tri")} (${n.mb(e)})`,
|
|
1347
|
+
n.count(this.materials.length, "material"),
|
|
1348
|
+
n.count(this.maps.length, "map")
|
|
1349
|
+
]));
|
|
1350
|
+
}
|
|
1351
|
+
extractMaterialsOnly(e) {
|
|
1352
|
+
return this.resetArrays(), this._traverseMaterialsOnly(e), this.getExtractedData();
|
|
1353
|
+
}
|
|
1354
|
+
_traverseMaterialsOnly(e) {
|
|
1355
|
+
if (e.isMesh && e.geometry && e.material) {
|
|
1356
|
+
let t = this.processMaterial(e.material);
|
|
1357
|
+
e.userData.materialIndex = t;
|
|
1358
|
+
let n = this.meshes.length;
|
|
1359
|
+
this.meshes.push(e), e.userData.meshIndex = n;
|
|
1360
|
+
} else e.isDirectionalLight ? this.directionalLights.push(e) : e.isCamera && this.cameras.push(e);
|
|
1361
|
+
if (e.children) for (let t of e.children) this._traverseMaterialsOnly(t);
|
|
1362
|
+
}
|
|
1363
|
+
resetArrays() {
|
|
1364
|
+
this._droppedTextures = 0, this.triangles = null, this._streamedStore = !1, this.triangleData = null, this.triangleFloatChunks = null, this.triangleFloats = null, this.triangleCount = 0, this.currentTriangleIndex = 0, this.materials = [], this.materialTriangleCounts = [], this.meshes = [], this.meshTriangleRanges = [], this._geometryRanges = /* @__PURE__ */ new Map(), this.expandedTriangleCount = 0, this._allocatePlacements(0), this.maps = [], this.normalMaps = [], this.bumpMaps = [], this.metalnessMaps = [], this.emissiveMaps = [], this.roughnessMaps = [], this.displacementMaps = [], this.anisotropyMaps = [], this.transmissionMaps = [], this.clearcoatMaps = [], this.clearcoatRoughnessMaps = [], this.sheenColorMaps = [], this.sheenRoughnessMaps = [], this.iridescenceMaps = [], this.iridescenceThicknessMaps = [], this.specularIntensityMaps = [], this.specularColorMaps = [], this.diffuseTransmissionMaps = [], this.diffuseTransmissionColorMaps = [], this.directionalLights = [], this.cameras = [], this._materialUuidMap = /* @__PURE__ */ new Map(), this._textureIndexCache = /* @__PURE__ */ new WeakMap();
|
|
1365
|
+
}
|
|
1366
|
+
getExtractedData() {
|
|
1367
|
+
return {
|
|
1368
|
+
triangleData: this.getTriangleData(),
|
|
1369
|
+
triangleCount: this.getTriangleCount(),
|
|
1370
|
+
materials: this.materials,
|
|
1371
|
+
materialTriangleCounts: this.materialTriangleCounts,
|
|
1372
|
+
meshes: this.meshes,
|
|
1373
|
+
meshTriangleRanges: this.meshTriangleRanges,
|
|
1374
|
+
expandedTriangleCount: this.expandedTriangleCount,
|
|
1375
|
+
instanceSource: this.instanceSource.subarray(0, this.instanceCount),
|
|
1376
|
+
matrixRuns: this._matrixRuns(),
|
|
1377
|
+
instanceCount: this.instanceCount,
|
|
1378
|
+
instanceGroups: this._instanceGroups(),
|
|
1379
|
+
bakeInverse: this.bakeInverse,
|
|
1380
|
+
maps: this.maps,
|
|
1381
|
+
normalMaps: this.normalMaps,
|
|
1382
|
+
bumpMaps: this.bumpMaps,
|
|
1383
|
+
metalnessMaps: this.metalnessMaps,
|
|
1384
|
+
emissiveMaps: this.emissiveMaps,
|
|
1385
|
+
roughnessMaps: this.roughnessMaps,
|
|
1386
|
+
displacementMaps: this.displacementMaps,
|
|
1387
|
+
anisotropyMaps: this.anisotropyMaps,
|
|
1388
|
+
transmissionMaps: this.transmissionMaps,
|
|
1389
|
+
clearcoatMaps: this.clearcoatMaps,
|
|
1390
|
+
clearcoatRoughnessMaps: this.clearcoatRoughnessMaps,
|
|
1391
|
+
sheenColorMaps: this.sheenColorMaps,
|
|
1392
|
+
sheenRoughnessMaps: this.sheenRoughnessMaps,
|
|
1393
|
+
iridescenceMaps: this.iridescenceMaps,
|
|
1394
|
+
iridescenceThicknessMaps: this.iridescenceThicknessMaps,
|
|
1395
|
+
specularIntensityMaps: this.specularIntensityMaps,
|
|
1396
|
+
specularColorMaps: this.specularColorMaps,
|
|
1397
|
+
diffuseTransmissionMaps: this.diffuseTransmissionMaps,
|
|
1398
|
+
diffuseTransmissionColorMaps: this.diffuseTransmissionColorMaps,
|
|
1399
|
+
directionalLights: this.directionalLights,
|
|
1400
|
+
cameras: this.cameras
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
}, Y = {
|
|
1404
|
+
Worker: null,
|
|
1405
|
+
decodeImage: null
|
|
1406
|
+
};
|
|
1407
|
+
function Ve(e) {
|
|
1408
|
+
e && Object.assign(Y, e);
|
|
1409
|
+
}
|
|
1410
|
+
function He() {
|
|
1411
|
+
return Y;
|
|
1412
|
+
}
|
|
1413
|
+
function Ue() {
|
|
1414
|
+
return typeof navigator < "u" && navigator.hardwareConcurrency || 4;
|
|
1415
|
+
}
|
|
1416
|
+
function We() {
|
|
1417
|
+
return !!Y.decodeImage || typeof self < "u" && (typeof createImageBitmap < "u" || typeof document < "u");
|
|
1418
|
+
}
|
|
1419
|
+
function Ge() {
|
|
1420
|
+
return !!Y.Worker || typeof Worker < "u";
|
|
1421
|
+
}
|
|
1422
|
+
var X = 0;
|
|
1423
|
+
async function Ke(e) {
|
|
1424
|
+
if (!Y.Worker || X === 0 && globalThis.Worker !== void 0) return e();
|
|
1425
|
+
X++ === 0 && (globalThis.Worker = Y.Worker);
|
|
1426
|
+
try {
|
|
1427
|
+
return await e();
|
|
1428
|
+
} finally {
|
|
1429
|
+
--X === 0 && globalThis.Worker === Y.Worker && delete globalThis.Worker;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
function qe(e, t) {
|
|
1433
|
+
let n = Y.Worker;
|
|
1434
|
+
if (!n) return new e(t);
|
|
1435
|
+
let r = Object.prototype.hasOwnProperty.call(globalThis, "Worker"), i = globalThis.Worker;
|
|
1436
|
+
globalThis.Worker = n;
|
|
1437
|
+
try {
|
|
1438
|
+
return new e(t);
|
|
1439
|
+
} finally {
|
|
1440
|
+
r ? globalThis.Worker = i : delete globalThis.Worker;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
//#endregion
|
|
1444
|
+
//#region src/Storage/CDFCache.js
|
|
1445
|
+
var Je = 5;
|
|
1446
|
+
function Ye(e, t) {
|
|
1447
|
+
e && t && (e.userData.__rayzeeSource = t);
|
|
1448
|
+
}
|
|
1449
|
+
function Xe(e) {
|
|
1450
|
+
let t = e?.userData?.__rayzeeSource;
|
|
1451
|
+
if (!t) return null;
|
|
1452
|
+
let { width: n = 0, height: r = 0 } = e.image ?? {};
|
|
1453
|
+
return `cdf:${Je}:${t}|${n}x${r}|${e.userData.__rayzeeColorSpace ?? "native"}`;
|
|
1454
|
+
}
|
|
1455
|
+
var Ze = () => c(u().cacheNamespace)?.area(l.CDF) ?? null, Z = [
|
|
1456
|
+
"exactConditional",
|
|
1457
|
+
"exactMarginal",
|
|
1458
|
+
"exactRowGuide",
|
|
1459
|
+
"exactMarginalGuide"
|
|
1460
|
+
], Q = Z.map((e) => `${e}.f32`);
|
|
1461
|
+
async function Qe(e) {
|
|
1462
|
+
let t = Xe(e), n = t ? await Ze()?.open(t) : null;
|
|
1463
|
+
if (!n) return null;
|
|
1464
|
+
try {
|
|
1465
|
+
let e = await Promise.all(Q.map((e) => n.file(e)));
|
|
1466
|
+
if (e.some((e) => !e)) return null;
|
|
1467
|
+
let t = await Promise.all(e.map(async (e) => new Float32Array(await e.arrayBuffer()))), { totalSum: r, width: i, height: a, exactWidth: o, exactHeight: s, radianceIntegral: c } = n.extra;
|
|
1468
|
+
return {
|
|
1469
|
+
...Object.fromEntries(Z.map((e, n) => [e, t[n]])),
|
|
1470
|
+
totalSum: r,
|
|
1471
|
+
width: i,
|
|
1472
|
+
height: a,
|
|
1473
|
+
exactWidth: o,
|
|
1474
|
+
exactHeight: s,
|
|
1475
|
+
radianceIntegral: c
|
|
1476
|
+
};
|
|
1477
|
+
} finally {
|
|
1478
|
+
n.release();
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
async function $e(e, t) {
|
|
1482
|
+
let { totalSum: n, width: r, height: i, exactWidth: a, exactHeight: o, radianceIntegral: s } = t, c = Z.map((e) => t[e]), l = Xe(e), u = l ? Ze() : null;
|
|
1483
|
+
if (!u || c.some((e) => !e)) return !1;
|
|
1484
|
+
let d = await u.create(l, {
|
|
1485
|
+
label: e.name || "environment",
|
|
1486
|
+
expectedBytes: c.reduce((e, t) => e + t.byteLength, 0)
|
|
1487
|
+
});
|
|
1488
|
+
if (!d) return !1;
|
|
1489
|
+
try {
|
|
1490
|
+
for (let e = 0; e < Q.length; e++) await d.write(Q[e], c[e]);
|
|
1491
|
+
return await d.commit({
|
|
1492
|
+
totalSum: n,
|
|
1493
|
+
width: r,
|
|
1494
|
+
height: i,
|
|
1495
|
+
exactWidth: a,
|
|
1496
|
+
exactHeight: o,
|
|
1497
|
+
radianceIntegral: s
|
|
1498
|
+
}), !0;
|
|
1499
|
+
} catch {
|
|
1500
|
+
return await d.abort(), !1;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
//#endregion
|
|
1504
|
+
//#region src/Processor/HostMemory.js
|
|
1505
|
+
var et = i.FLOATS_PER_TRIANGLE * 4, tt = 64, nt = .9, rt = 28, it = 45, at = 4, ot = 1536 * 1024 * 1024, st = 7040 * 1024 * 1024, ct = 9216 * 1024 * 1024, lt = 12e7, ut = 6e7, dt = 8192;
|
|
1506
|
+
function ft(e) {
|
|
1507
|
+
if (e > 0) return {
|
|
1508
|
+
gb: e,
|
|
1509
|
+
assumed: !1
|
|
1510
|
+
};
|
|
1511
|
+
let t = typeof navigator < "u" ? navigator.deviceMemory : void 0;
|
|
1512
|
+
return t > 0 ? {
|
|
1513
|
+
gb: t,
|
|
1514
|
+
assumed: !1
|
|
1515
|
+
} : {
|
|
1516
|
+
gb: 4,
|
|
1517
|
+
assumed: !0
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
var pt = 1.15, mt = 12 * 1024 * 1024 * 1024;
|
|
1521
|
+
function ht({ triangles: e, placements: t, geometryBytes: n = 0, instanceBytes: r = 0 }) {
|
|
1522
|
+
let i = {
|
|
1523
|
+
triangles: e * et,
|
|
1524
|
+
bvh: Math.ceil(e * nt) * tt,
|
|
1525
|
+
geometry: n,
|
|
1526
|
+
instances: r,
|
|
1527
|
+
placements: t * rt,
|
|
1528
|
+
orderMaps: e * at
|
|
1529
|
+
};
|
|
1530
|
+
return i.total = i.triangles + i.bvh + i.geometry + i.instances + i.placements + i.orderMaps, i;
|
|
1531
|
+
}
|
|
1532
|
+
function gt(e, t, n) {
|
|
1533
|
+
let r = e.geometry + e.instances + t * 4 + n, i = e.instances + e.placements + t * it + e.orderMaps;
|
|
1534
|
+
return Math.max(r, i);
|
|
1535
|
+
}
|
|
1536
|
+
function _t(e, { chunkBytes: t = N, shared: n = !1, allocate: r = null } = {}) {
|
|
1537
|
+
let i = Math.min(e, mt), a = r ?? (n ? (e) => new SharedArrayBuffer(e) : (e) => new ArrayBuffer(e)), o = [], s = 0;
|
|
1538
|
+
try {
|
|
1539
|
+
for (; s < i;) {
|
|
1540
|
+
let e = Math.min(t, i - s);
|
|
1541
|
+
o.push(a(e)), s += e;
|
|
1542
|
+
}
|
|
1543
|
+
} catch {}
|
|
1544
|
+
for (let e = o.length - 1; e >= 0; e--) o[e] = null;
|
|
1545
|
+
return o.length = 0, {
|
|
1546
|
+
placed: s,
|
|
1547
|
+
want: i,
|
|
1548
|
+
exhausted: s < i,
|
|
1549
|
+
capped: e > i
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
var vt = class {
|
|
1553
|
+
constructor() {
|
|
1554
|
+
this.reset();
|
|
1555
|
+
}
|
|
1556
|
+
reset() {
|
|
1557
|
+
this.phase = "idle", this.events = [], this.samples = [], this.allocatedBytes = 0, this.peakLiveBytes = 0, this.byPhase = Object.create(null);
|
|
1558
|
+
}
|
|
1559
|
+
mark(e) {
|
|
1560
|
+
return this.phase = e, this.byPhase[e] ??= {
|
|
1561
|
+
allocated: 0,
|
|
1562
|
+
chunks: 0
|
|
1563
|
+
}, this;
|
|
1564
|
+
}
|
|
1565
|
+
alloc(e, t = "chunk") {
|
|
1566
|
+
if (!(e > 0)) return;
|
|
1567
|
+
let n = this.byPhase[this.phase] ??= {
|
|
1568
|
+
allocated: 0,
|
|
1569
|
+
chunks: 0
|
|
1570
|
+
};
|
|
1571
|
+
n.allocated += e, n.chunks++, this.allocatedBytes += e, this.events.push({
|
|
1572
|
+
phase: this.phase,
|
|
1573
|
+
bytes: e,
|
|
1574
|
+
what: t,
|
|
1575
|
+
at: performance.now()
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
sample(e, t) {
|
|
1579
|
+
let n = 0;
|
|
1580
|
+
for (let e in t) n += t[e] || 0;
|
|
1581
|
+
return n > this.peakLiveBytes && (this.peakLiveBytes = n), this.samples.push({
|
|
1582
|
+
label: e,
|
|
1583
|
+
phase: this.phase,
|
|
1584
|
+
total: n,
|
|
1585
|
+
parts: t,
|
|
1586
|
+
at: performance.now()
|
|
1587
|
+
}), n;
|
|
1588
|
+
}
|
|
1589
|
+
get report() {
|
|
1590
|
+
return {
|
|
1591
|
+
allocatedBytes: this.allocatedBytes,
|
|
1592
|
+
peakLiveBytes: this.peakLiveBytes,
|
|
1593
|
+
byPhase: { ...this.byPhase },
|
|
1594
|
+
samples: this.samples.slice()
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
}, yt = "11.4.0", $ = 1e4, bt = 15e5;
|
|
1598
|
+
function xt(e, t, n = $) {
|
|
1599
|
+
return e >= n && t / bt < e / 3;
|
|
1600
|
+
}
|
|
1601
|
+
//#endregion
|
|
1602
|
+
export { ae as $, ze as A, k as B, We as C, U as D, Be as E, L as F, E as G, xe as H, N as I, fe as J, pe as K, P as L, Re as M, ke as N, Pe as O, we as P, oe as Q, Se as R, Ue as S, Ke as T, ye as U, be as V, ue as W, ce as X, me as Y, le as Z, $e as _, vt as a, w as at, qe as b, st as c, lt as d, ie as et, ft as f, Qe as g, gt as h, ct as i, se as it, W as j, Fe as k, dt as l, _t as m, xt as n, C as nt, ot as o, T as ot, ht as p, D as q, yt as r, S as rt, pt as s, $ as t, ee as tt, ut as u, Ye as v, Ge as w, He as x, Ve as y, O as z };
|