@drawcall/lod 0.1.2 → 0.3.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.
Files changed (358) hide show
  1. package/README.md +13 -70
  2. package/dist/at.d.ts +2 -0
  3. package/dist/at.js +8 -0
  4. package/dist/at.js.map +1 -0
  5. package/dist/bake.d.ts +22 -0
  6. package/dist/bake.js +88 -0
  7. package/dist/bake.js.map +1 -0
  8. package/dist/baked/codec.d.ts +5 -5
  9. package/dist/baked/codec.js +58 -158
  10. package/dist/baked/codec.js.map +1 -1
  11. package/dist/baked/coverage.d.ts +6 -3
  12. package/dist/baked/coverage.js +6 -3
  13. package/dist/baked/coverage.js.map +1 -1
  14. package/dist/baked/fields.d.ts +9 -0
  15. package/dist/baked/fields.js +22 -0
  16. package/dist/baked/fields.js.map +1 -0
  17. package/dist/baked/index.d.ts +16 -6
  18. package/dist/baked/index.js +23 -21
  19. package/dist/baked/index.js.map +1 -1
  20. package/dist/baked/interior/faces.d.ts +4 -3
  21. package/dist/baked/interior/faces.js +13 -10
  22. package/dist/baked/interior/faces.js.map +1 -1
  23. package/dist/baked/interior/material.d.ts +7 -10
  24. package/dist/baked/interior/material.js +29 -36
  25. package/dist/baked/interior/material.js.map +1 -1
  26. package/dist/baked/interior/rooms.js +1 -1
  27. package/dist/baked/interior/rooms.js.map +1 -1
  28. package/dist/baked/low.d.ts +2 -2
  29. package/dist/baked/low.js +9 -8
  30. package/dist/baked/low.js.map +1 -1
  31. package/dist/baked/raster.js +6 -6
  32. package/dist/baked/raster.js.map +1 -1
  33. package/dist/baked/textures.d.ts +17 -0
  34. package/dist/baked/textures.js +95 -0
  35. package/dist/baked/textures.js.map +1 -0
  36. package/dist/baked/transfer.js +19 -18
  37. package/dist/baked/transfer.js.map +1 -1
  38. package/dist/baked/unwrap.js +4 -3
  39. package/dist/baked/unwrap.js.map +1 -1
  40. package/dist/baked/xatlas.js.map +1 -1
  41. package/dist/codec/container.d.ts +8 -0
  42. package/dist/codec/container.js +63 -0
  43. package/dist/codec/container.js.map +1 -0
  44. package/dist/codec/mesh.d.ts +8 -0
  45. package/dist/codec/mesh.js +220 -0
  46. package/dist/codec/mesh.js.map +1 -0
  47. package/dist/dispose.d.ts +11 -4
  48. package/dist/dispose.js +39 -12
  49. package/dist/dispose.js.map +1 -1
  50. package/dist/gpu.d.ts +39 -0
  51. package/dist/gpu.js +41 -0
  52. package/dist/gpu.js.map +1 -0
  53. package/dist/impostor/bake/atlas.d.ts +4 -4
  54. package/dist/impostor/bake/atlas.js +12 -12
  55. package/dist/impostor/bake/atlas.js.map +1 -1
  56. package/dist/impostor/bake/fit.d.ts +8 -0
  57. package/dist/impostor/bake/fit.js +28 -0
  58. package/dist/impostor/bake/fit.js.map +1 -0
  59. package/dist/impostor/bake/index.d.ts +23 -14
  60. package/dist/impostor/bake/index.js +42 -134
  61. package/dist/impostor/bake/index.js.map +1 -1
  62. package/dist/impostor/bake/materials.d.ts +3 -3
  63. package/dist/impostor/bake/materials.js +60 -12
  64. package/dist/impostor/bake/materials.js.map +1 -1
  65. package/dist/impostor/bake/sheet.d.ts +8 -0
  66. package/dist/impostor/bake/sheet.js +90 -0
  67. package/dist/impostor/bake/sheet.js.map +1 -0
  68. package/dist/impostor/bake/source.d.ts +2 -2
  69. package/dist/impostor/bake/source.js +8 -19
  70. package/dist/impostor/bake/source.js.map +1 -1
  71. package/dist/impostor/codec.d.ts +5 -11
  72. package/dist/impostor/codec.js +37 -121
  73. package/dist/impostor/codec.js.map +1 -1
  74. package/dist/impostor/impostor.d.ts +31 -7
  75. package/dist/impostor/impostor.js +21 -6
  76. package/dist/impostor/impostor.js.map +1 -1
  77. package/dist/impostor/ktx2/encode.d.ts +26 -0
  78. package/dist/impostor/ktx2/encode.js +117 -0
  79. package/dist/impostor/ktx2/encode.js.map +1 -0
  80. package/dist/impostor/ktx2/transcode.d.ts +3 -0
  81. package/dist/impostor/ktx2/transcode.js +99 -0
  82. package/dist/impostor/ktx2/transcode.js.map +1 -0
  83. package/dist/impostor/ktx2/uastc.d.ts +7 -0
  84. package/dist/impostor/ktx2/uastc.js +64 -0
  85. package/dist/impostor/ktx2/uastc.js.map +1 -0
  86. package/dist/impostor/ktx2/wasm/encoder.d.ts +4 -0
  87. package/dist/impostor/ktx2/wasm/encoder.js +10 -0
  88. package/dist/impostor/ktx2/wasm/encoder.js.map +1 -0
  89. package/dist/impostor/ktx2/wasm/transcoder.d.ts +3 -0
  90. package/dist/impostor/ktx2/wasm/transcoder.js +9 -0
  91. package/dist/impostor/ktx2/wasm/transcoder.js.map +1 -0
  92. package/dist/impostor/ktx2/worker.d.ts +1 -0
  93. package/dist/impostor/ktx2/worker.js +12 -0
  94. package/dist/impostor/ktx2/worker.js.map +1 -0
  95. package/dist/impostor/mesh/card.d.ts +3 -3
  96. package/dist/impostor/mesh/card.js +11 -8
  97. package/dist/impostor/mesh/card.js.map +1 -1
  98. package/dist/impostor/mesh/index.d.ts +10 -7
  99. package/dist/impostor/mesh/index.js +15 -18
  100. package/dist/impostor/mesh/index.js.map +1 -1
  101. package/dist/impostor/mesh/material.d.ts +24 -13
  102. package/dist/impostor/mesh/material.js +67 -51
  103. package/dist/impostor/mesh/material.js.map +1 -1
  104. package/dist/impostor/mesh/surface.d.ts +20 -16
  105. package/dist/impostor/mesh/surface.js +81 -58
  106. package/dist/impostor/mesh/surface.js.map +1 -1
  107. package/dist/impostor/mesh/textures.d.ts +3 -3
  108. package/dist/impostor/mesh/textures.js +24 -34
  109. package/dist/impostor/mesh/textures.js.map +1 -1
  110. package/dist/impostor/octahedral.d.ts +1 -8
  111. package/dist/impostor/octahedral.js +3 -18
  112. package/dist/impostor/octahedral.js.map +1 -1
  113. package/dist/index.d.ts +16 -10
  114. package/dist/index.js +14 -8
  115. package/dist/index.js.map +1 -1
  116. package/dist/instanced/camera.d.ts +46 -0
  117. package/dist/instanced/camera.js +70 -0
  118. package/dist/instanced/camera.js.map +1 -0
  119. package/dist/instanced/chunk.d.ts +97 -0
  120. package/dist/instanced/chunk.js +156 -0
  121. package/dist/instanced/chunk.js.map +1 -0
  122. package/dist/instanced/chunks.d.ts +60 -0
  123. package/dist/instanced/chunks.js +208 -0
  124. package/dist/instanced/chunks.js.map +1 -0
  125. package/dist/instanced/cull.d.ts +28 -0
  126. package/dist/instanced/cull.js +22 -0
  127. package/dist/instanced/cull.js.map +1 -0
  128. package/dist/instanced/index.d.ts +96 -92
  129. package/dist/instanced/index.js +229 -512
  130. package/dist/instanced/index.js.map +1 -1
  131. package/dist/instanced/key.d.ts +19 -0
  132. package/dist/instanced/key.js +45 -0
  133. package/dist/instanced/key.js.map +1 -0
  134. package/dist/instanced/levels.d.ts +60 -0
  135. package/dist/instanced/levels.js +130 -0
  136. package/dist/instanced/levels.js.map +1 -0
  137. package/dist/instanced/lists.d.ts +70 -0
  138. package/dist/instanced/lists.js +133 -0
  139. package/dist/instanced/lists.js.map +1 -0
  140. package/dist/instanced/measure.d.ts +28 -0
  141. package/dist/instanced/measure.js +203 -0
  142. package/dist/instanced/measure.js.map +1 -0
  143. package/dist/instanced/meshes.d.ts +46 -14
  144. package/dist/instanced/meshes.js +137 -22
  145. package/dist/instanced/meshes.js.map +1 -1
  146. package/dist/instanced/mirror.d.ts +20 -0
  147. package/dist/instanced/mirror.js +37 -0
  148. package/dist/instanced/mirror.js.map +1 -0
  149. package/dist/instanced/pages/buffers.d.ts +37 -0
  150. package/dist/instanced/pages/buffers.js +15 -0
  151. package/dist/instanced/pages/buffers.js.map +1 -0
  152. package/dist/instanced/pages/chunk.d.ts +51 -0
  153. package/dist/instanced/pages/chunk.js +81 -0
  154. package/dist/instanced/pages/chunk.js.map +1 -0
  155. package/dist/instanced/pages/index.d.ts +74 -0
  156. package/dist/instanced/pages/index.js +269 -0
  157. package/dist/instanced/pages/index.js.map +1 -0
  158. package/dist/instanced/pages/passes.d.ts +21 -0
  159. package/dist/instanced/pages/passes.js +52 -0
  160. package/dist/instanced/pages/passes.js.map +1 -0
  161. package/dist/instanced/pages/slots.d.ts +11 -0
  162. package/dist/instanced/pages/slots.js +90 -0
  163. package/dist/instanced/pages/slots.js.map +1 -0
  164. package/dist/instanced/pages/workgroup.d.ts +14 -0
  165. package/dist/instanced/pages/workgroup.js +38 -0
  166. package/dist/instanced/pages/workgroup.js.map +1 -0
  167. package/dist/instanced/raycast.d.ts +15 -0
  168. package/dist/instanced/raycast.js +46 -0
  169. package/dist/instanced/raycast.js.map +1 -0
  170. package/dist/instanced/rows.d.ts +108 -0
  171. package/dist/instanced/rows.js +209 -0
  172. package/dist/instanced/rows.js.map +1 -0
  173. package/dist/instanced/shape.d.ts +25 -0
  174. package/dist/instanced/shape.js +51 -0
  175. package/dist/instanced/shape.js.map +1 -0
  176. package/dist/instanced/sort.d.ts +63 -0
  177. package/dist/instanced/sort.js +162 -0
  178. package/dist/instanced/sort.js.map +1 -0
  179. package/dist/instanced/update.d.ts +30 -0
  180. package/dist/instanced/update.js +207 -0
  181. package/dist/instanced/update.js.map +1 -0
  182. package/dist/levels/bounds.d.ts +21 -0
  183. package/dist/levels/bounds.js +42 -0
  184. package/dist/levels/bounds.js.map +1 -0
  185. package/dist/levels/cameras.d.ts +48 -0
  186. package/dist/levels/cameras.js +122 -0
  187. package/dist/levels/cameras.js.map +1 -0
  188. package/dist/levels/compile/contexts.d.ts +30 -0
  189. package/dist/levels/compile/contexts.js +18 -0
  190. package/dist/levels/compile/contexts.js.map +1 -0
  191. package/dist/levels/compile/index.d.ts +39 -0
  192. package/dist/levels/compile/index.js +185 -0
  193. package/dist/levels/compile/index.js.map +1 -0
  194. package/dist/levels/compile/pipelines.d.ts +26 -0
  195. package/dist/levels/compile/pipelines.js +177 -0
  196. package/dist/levels/compile/pipelines.js.map +1 -0
  197. package/dist/levels/compiles.d.ts +29 -0
  198. package/dist/levels/compiles.js +50 -0
  199. package/dist/levels/compiles.js.map +1 -0
  200. package/dist/levels/draw.d.ts +102 -0
  201. package/dist/levels/draw.js +401 -0
  202. package/dist/levels/draw.js.map +1 -0
  203. package/dist/levels/fade.d.ts +69 -0
  204. package/dist/levels/fade.js +150 -0
  205. package/dist/levels/fade.js.map +1 -0
  206. package/dist/levels/index.d.ts +99 -0
  207. package/dist/levels/index.js +155 -0
  208. package/dist/levels/index.js.map +1 -0
  209. package/dist/levels/item.d.ts +38 -0
  210. package/dist/levels/item.js +97 -0
  211. package/dist/levels/item.js.map +1 -0
  212. package/dist/levels/load.d.ts +31 -0
  213. package/dist/levels/load.js +142 -0
  214. package/dist/levels/load.js.map +1 -0
  215. package/dist/levels/manager.d.ts +159 -0
  216. package/dist/levels/manager.js +339 -0
  217. package/dist/levels/manager.js.map +1 -0
  218. package/dist/{material.js → levels/material.js} +13 -7
  219. package/dist/levels/material.js.map +1 -0
  220. package/dist/levels/renderer.d.ts +29 -0
  221. package/dist/levels/renderer.js +41 -0
  222. package/dist/levels/renderer.js.map +1 -0
  223. package/dist/levels/requests.d.ts +49 -0
  224. package/dist/levels/requests.js +95 -0
  225. package/dist/levels/requests.js.map +1 -0
  226. package/dist/levels/screen.d.ts +14 -0
  227. package/dist/levels/screen.js +21 -0
  228. package/dist/levels/screen.js.map +1 -0
  229. package/dist/levels/wait.d.ts +27 -0
  230. package/dist/levels/wait.js +61 -0
  231. package/dist/levels/wait.js.map +1 -0
  232. package/dist/loader/build.d.ts +10 -0
  233. package/dist/loader/build.js +28 -0
  234. package/dist/loader/build.js.map +1 -0
  235. package/dist/loader/cache.d.ts +12 -15
  236. package/dist/loader/cache.js +64 -33
  237. package/dist/loader/cache.js.map +1 -1
  238. package/dist/loader/context.d.ts +46 -0
  239. package/dist/loader/context.js +91 -0
  240. package/dist/loader/context.js.map +1 -0
  241. package/dist/loader/dependencies.d.ts +32 -0
  242. package/dist/loader/dependencies.js +113 -0
  243. package/dist/loader/dependencies.js.map +1 -0
  244. package/dist/loader/index.d.ts +62 -0
  245. package/dist/loader/index.js +284 -0
  246. package/dist/loader/index.js.map +1 -0
  247. package/dist/loader/level.d.ts +41 -0
  248. package/dist/loader/level.js +140 -0
  249. package/dist/loader/level.js.map +1 -0
  250. package/dist/loader/request.d.ts +87 -0
  251. package/dist/loader/request.js +59 -0
  252. package/dist/loader/request.js.map +1 -0
  253. package/dist/loader/url.d.ts +16 -0
  254. package/dist/loader/url.js +35 -0
  255. package/dist/loader/url.js.map +1 -0
  256. package/dist/lod.d.ts +79 -49
  257. package/dist/lod.js +209 -153
  258. package/dist/lod.js.map +1 -1
  259. package/dist/meshopt.d.ts +6 -0
  260. package/dist/meshopt.js +19 -0
  261. package/dist/meshopt.js.map +1 -0
  262. package/dist/simplify/cards.d.ts +14 -0
  263. package/dist/simplify/cards.js +128 -0
  264. package/dist/simplify/cards.js.map +1 -0
  265. package/dist/{simplify.d.ts → simplify/index.d.ts} +7 -4
  266. package/dist/{simplify.js → simplify/index.js} +42 -22
  267. package/dist/simplify/index.js.map +1 -0
  268. package/dist/{bounds.d.ts → source/detail.d.ts} +4 -13
  269. package/dist/{bounds.js → source/detail.js} +62 -32
  270. package/dist/source/detail.js.map +1 -0
  271. package/dist/source/{error.d.ts → deviation.d.ts} +3 -3
  272. package/dist/source/{error.js → deviation.js} +12 -12
  273. package/dist/source/deviation.js.map +1 -0
  274. package/dist/source/{shading.d.ts → evaluator.d.ts} +10 -10
  275. package/dist/source/{shading.js → evaluator.js} +5 -5
  276. package/dist/source/evaluator.js.map +1 -0
  277. package/dist/source/{trace.d.ts → raycaster.d.ts} +6 -6
  278. package/dist/source/{trace.js → raycaster.js} +8 -8
  279. package/dist/source/raycaster.js.map +1 -0
  280. package/dist/source/{texels.d.ts → sampler.d.ts} +1 -1
  281. package/dist/source/{texels.js → sampler.js} +3 -3
  282. package/dist/source/sampler.js.map +1 -0
  283. package/dist/source/source.d.ts +2 -2
  284. package/dist/source/source.js +2 -2
  285. package/dist/source/source.js.map +1 -1
  286. package/dist/source/surface.js +1 -1
  287. package/dist/source/surface.js.map +1 -1
  288. package/dist/task.d.ts +6 -0
  289. package/dist/{pause.js → task.js} +5 -5
  290. package/dist/task.js.map +1 -0
  291. package/dist/three.d.ts +20 -19
  292. package/dist/three.js +29 -35
  293. package/dist/three.js.map +1 -1
  294. package/dist/tsl.d.ts +10 -14
  295. package/dist/tsl.js +12 -47
  296. package/dist/tsl.js.map +1 -1
  297. package/dist/typegpu.d.ts +37 -0
  298. package/dist/typegpu.js +37 -0
  299. package/dist/typegpu.js.map +1 -0
  300. package/dist/wind/bounds.js +2 -2
  301. package/dist/wind/bounds.js.map +1 -1
  302. package/dist/wind/hooks.d.ts +7 -4
  303. package/dist/wind/hooks.js +5 -2
  304. package/dist/wind/hooks.js.map +1 -1
  305. package/dist/wind/index.d.ts +4 -4
  306. package/dist/wind/index.js +43 -40
  307. package/dist/wind/index.js.map +1 -1
  308. package/dist/wind/sway.d.ts +4 -1
  309. package/dist/wind/sway.js +4 -1
  310. package/dist/wind/sway.js.map +1 -1
  311. package/package.json +24 -8
  312. package/skills/lod/SKILL.md +147 -108
  313. package/dist/bounds.js.map +0 -1
  314. package/dist/fade.d.ts +0 -44
  315. package/dist/fade.js +0 -78
  316. package/dist/fade.js.map +0 -1
  317. package/dist/impostor/cache.d.ts +0 -15
  318. package/dist/impostor/cache.js +0 -44
  319. package/dist/impostor/cache.js.map +0 -1
  320. package/dist/instanced/args.d.ts +0 -20
  321. package/dist/instanced/args.js +0 -77
  322. package/dist/instanced/args.js.map +0 -1
  323. package/dist/instanced/bounds.d.ts +0 -50
  324. package/dist/instanced/bounds.js +0 -271
  325. package/dist/instanced/bounds.js.map +0 -1
  326. package/dist/instanced/dirty.d.ts +0 -12
  327. package/dist/instanced/dirty.js +0 -61
  328. package/dist/instanced/dirty.js.map +0 -1
  329. package/dist/instanced/select.d.ts +0 -84
  330. package/dist/instanced/select.js +0 -264
  331. package/dist/instanced/select.js.map +0 -1
  332. package/dist/lazy.d.ts +0 -64
  333. package/dist/lazy.js +0 -187
  334. package/dist/lazy.js.map +0 -1
  335. package/dist/levels.d.ts +0 -72
  336. package/dist/levels.js +0 -146
  337. package/dist/levels.js.map +0 -1
  338. package/dist/loader/dispose.d.ts +0 -3
  339. package/dist/loader/dispose.js +0 -25
  340. package/dist/loader/dispose.js.map +0 -1
  341. package/dist/loader.d.ts +0 -99
  342. package/dist/loader.js +0 -234
  343. package/dist/loader.js.map +0 -1
  344. package/dist/material.js.map +0 -1
  345. package/dist/pause.d.ts +0 -6
  346. package/dist/pause.js.map +0 -1
  347. package/dist/renderer.d.ts +0 -21
  348. package/dist/renderer.js +0 -83
  349. package/dist/renderer.js.map +0 -1
  350. package/dist/simplify.js.map +0 -1
  351. package/dist/source/error.js.map +0 -1
  352. package/dist/source/shading.js.map +0 -1
  353. package/dist/source/texels.js.map +0 -1
  354. package/dist/source/trace.js.map +0 -1
  355. package/dist/view.d.ts +0 -30
  356. package/dist/view.js +0 -75
  357. package/dist/view.js.map +0 -1
  358. /package/dist/{material.d.ts → levels/material.d.ts} +0 -0
@@ -0,0 +1,59 @@
1
+ import { ladderEntry } from "./cache.js";
2
+ import { loaderPathURL, sourceRelativeURL } from "./url.js";
3
+ // What a LodLoader is asked for, normalised, and the cache entries the levels it derives are saved under.
4
+ /**
5
+ * Whether this runs in a production server-side build (`import.meta.env.PROD` and `SSR`), which precomputes assets
6
+ * into the deployed cache: every level is built and saved, and a level that cannot be saved fails the build.
7
+ */
8
+ export const warmup = import.meta.env?.PROD === true && import.meta.env?.SSR === true;
9
+ const DEFAULT_LEVELS = [{ type: "impostor" }];
10
+ /** `request` with its URLs resolved against `path`, and every asset URL it builds from named as a dependency. */
11
+ export function normalize(request, path) {
12
+ const input = typeof request === "string" ? { url: request } : request;
13
+ const url = loaderPathURL(input.url, path);
14
+ const levels = structuredClone(input.levels ?? DEFAULT_LEVELS);
15
+ const urls = { source: url };
16
+ levels.forEach((level, position) => {
17
+ if (level.type !== "baked")
18
+ return;
19
+ for (const name of ["low", "interior"]) {
20
+ const value = level[name];
21
+ if (value !== undefined)
22
+ urls[auxiliary(position + 1, name)] = sourceRelativeURL(value, url);
23
+ }
24
+ });
25
+ return { ...input, url, levels, urls };
26
+ }
27
+ /** The request of ladder level `index`, which must be a derived level. */
28
+ export function derived(levels, index) {
29
+ const level = levels[index - 1];
30
+ if (!level || level.type === "empty")
31
+ throw new Error(`LodLoader: level ${index} is not derived`);
32
+ return level;
33
+ }
34
+ /** The dependency name of the low or interior asset of the baked level at ladder index `level`. */
35
+ export const auxiliary = (level, name) => `auxiliary:${level}:${name}`;
36
+ /** Derived level `index`'s cache entry, keyed by the inputs it is built from; undefined when the ladder is not cacheable. */
37
+ export function levelEntry(ladder, index, dependencies, options) {
38
+ // Keyed by role rather than ladder position, so adding or removing another level leaves this one's entry.
39
+ const roles = { source: "source", low: auxiliary(index, "low"), interior: auxiliary(index, "interior") };
40
+ return entry(ladder, derived(ladder.levels, index), roles, dependencies, options);
41
+ }
42
+ /** The cache entry of the source's shape, which describes the ladder before any level is built. */
43
+ export function shapeEntry(ladder, dependencies, options) {
44
+ return entry(ladder, "shape", { source: "source" }, dependencies, options);
45
+ }
46
+ function entry({ modules }, of, roles, dependencies, options) {
47
+ if (!modules)
48
+ return undefined;
49
+ const pick = (values) => Object.fromEntries(Object.entries(roles).flatMap(([role, name]) => {
50
+ const value = values[name];
51
+ return value === undefined ? [] : [[role, value]];
52
+ }));
53
+ return ladderEntry(pick(dependencies.inputs), of, pick(modules), options);
54
+ }
55
+ /** `entry` and the bytes it holds, read: undefined when it holds none. */
56
+ export async function cached(entry) {
57
+ return { entry, bytes: await entry?.load() };
58
+ }
59
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/loader/request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAwB,MAAM,YAAY,CAAC;AAG/D,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE5D,0GAA0G;AAE1G;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM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CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAU,CAAC,CAAC;IAC7D,CAAC,CAAC,CACH,CAAC;IACJ,OAAO,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAA6B;IACxD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** Resolve a relative asset path without changing absolute URLs or root-relative paths. */
2
+ export declare function loaderPathURL(url: string, base: string): string;
3
+ export declare const urlPath: (url: string) => string;
4
+ export declare const urlQuery: (url: string) => string;
5
+ export declare function assetPath(url: string): {
6
+ path: string;
7
+ extension: string;
8
+ };
9
+ export declare function sourceRelativeURL(value: string, source: string): string;
10
+ /**
11
+ * A same-origin path, as localURL leaves it, or a `file:` URL, as a `vite build` warmup sees public files: vitecache
12
+ * can resolve only these to project files.
13
+ */
14
+ export declare const isLocal: (url: string) => boolean;
15
+ /** Same-origin dependencies as paths, portable between development and deployment. */
16
+ export declare function localURL(url: string): string;
@@ -0,0 +1,35 @@
1
+ import { LoaderUtils } from "three/webgpu";
2
+ const absolute = /^[a-z][a-z\d+.-]*:/i;
3
+ /** An origin no URL has, to parse paths with when there is no document to resolve them against. */
4
+ const placeholderOrigin = "https://lod.invalid";
5
+ /** Resolve a relative asset path without changing absolute URLs or root-relative paths. */
6
+ export function loaderPathURL(url, base) {
7
+ return absolute.test(url) || url.startsWith("/") ? url : LoaderUtils.resolveURL(url, base);
8
+ }
9
+ export const urlPath = (url) => url.replace(/[?#].*$/s, "");
10
+ export const urlQuery = (url) => new URL(url, placeholderOrigin).search;
11
+ export function assetPath(url) {
12
+ const path = urlPath(url);
13
+ const extension = /\.(glb|gltf|glts)$/i.exec(path)?.[1]?.toLowerCase();
14
+ if (!extension)
15
+ throw new Error(`LodLoader: cannot load "${url}": expected a .glb, .gltf or .glts file`);
16
+ return { path, extension };
17
+ }
18
+ export function sourceRelativeURL(value, source) {
19
+ const base = new URL(source, typeof document === "undefined" ? placeholderOrigin : document.baseURI);
20
+ const url = new URL(value, base);
21
+ return url.origin === base.origin && !absolute.test(source) ? url.pathname + url.search + url.hash : url.href;
22
+ }
23
+ /**
24
+ * A same-origin path, as localURL leaves it, or a `file:` URL, as a `vite build` warmup sees public files: vitecache
25
+ * can resolve only these to project files.
26
+ */
27
+ export const isLocal = (url) => (url.startsWith("/") && !url.startsWith("//")) || url.startsWith("file:");
28
+ /** Same-origin dependencies as paths, portable between development and deployment. */
29
+ export function localURL(url) {
30
+ if (typeof location === "undefined" || !/^https?:/i.test(url))
31
+ return url;
32
+ const parsed = new URL(url);
33
+ return parsed.origin === location.origin ? parsed.pathname + parsed.search + parsed.hash : url;
34
+ }
35
+ //# sourceMappingURL=url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/loader/url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AACvC,mGAAmG;AACnG,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEhD,2FAA2F;AAC3F,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,IAAY;IACrD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,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,CAAC,GAAW,EAAW,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAE3H,sFAAsF;AACtF,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAC1E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AACjG,CAAC"}
package/dist/lod.d.ts CHANGED
@@ -1,78 +1,108 @@
1
- import { Object3D, type Camera, type Intersection, type Raycaster } from "three/webgpu";
2
- import { type LevelsEventMap } from "./lazy.js";
3
- import { type LodLevel } from "./levels.js";
4
- import { WIND_BOUNDS } from "./wind/hooks.js";
1
+ import { Object3D, type Camera, type Intersection, type LoadingManager, type Raycaster } from "three/webgpu";
2
+ import type { LodGpu } from "./gpu.js";
3
+ import { type LodLevel, type ThresholdedLevel } from "./levels/index.js";
4
+ import { type LodEventMap } from "./levels/manager.js";
5
+ import { WIND } from "./wind/hooks.js";
6
+ export interface LodOptions {
7
+ /**
8
+ * Gets an item while levels a camera needs load, compile or fade in, ended once they are complete. Without one, a
9
+ * Lod nested in another's level reports to that one's, any other to three's `DefaultLoadingManager`. Wait for a
10
+ * quiet frame, one in which no item started or ended, rendering (or compiling) the Scene that holds the Lod a frame
11
+ * apart meanwhile, to capture what a camera sees complete. A Lod its renderer rendered around for a frame without
12
+ * updating it ends its item, and its next update starts it again. Renders of other scenes in a separate task can end
13
+ * the item early, and the next update reopens it; a renderer that only compiles leaves a hidden Lod's item held.
14
+ */
15
+ manager?: LoadingManager;
16
+ }
5
17
  /**
6
- * Levels of detail of one object, switched by its height on screen. Level 0 is the
7
- * source; each further level is used while the object is at most its `maxPixels` tall
8
- * (see `LodLevel.maxPixels` for the defaults). Near a switch both neighbours draw and
9
- * split the pixels with a dither, so nothing pops; elsewhere exactly one level is visible
10
- * and the others are hidden. Shadows follow the camera's choice and fade with it; nothing
11
- * of the object is drawn into a directional light's shadow map whose texels are wider
12
- * than the whole object: it could cover a texel only by chance.
18
+ * One object's levels, switched by on-screen height with dithered fades. three's renderer calls `update` with each
19
+ * camera before it draws, shadow maps' included; each camera measures at the height it draws at, measured in each
20
+ * render (outside one, the canvas's). Orthographic cameras switch without fading. Shadows follow what the camera draws
21
+ * and omit casters smaller than a shadow texel; levels cast into three's shadow maps, not into a light whose shadow
22
+ * map a custom shadow node replaces. Nothing draws until the coarsest level that draws something has loaded, which
23
+ * loads first; a deferred level loads when a camera first needs it, once that one has loaded, and meanwhile the
24
+ * nearest loaded coarser level draws in its place.
13
25
  *
14
- * three's renderer calls `update(camera)` while it lists the scene (as for its own LOD),
15
- * before shadow maps render; the calls its shadow passes make are ignored. The height
16
- * uses the viewport the camera last drew one of the levels' meshes in, in CSS pixels
17
- * (1080 before that), so several views each get their own. An orthographic camera has
18
- * no distance to dither by: levels switch by on-screen size there too, but at once.
26
+ * Arriving levels' texture uploads are paced to about one uncompressed 2048² RGBA texture's bytes per frame. Levels
27
+ * are cloned into the Lod. A nested Lod switches and fades its own levels. Lines, points and sprites draw without
28
+ * fading. Raycasts hit the source only. A Lod draws with its LodGpu's renderer only.
19
29
  *
20
- * Levels are children of the Lod in its space, any Object3D: meshes, an ImpostorMesh, a
21
- * group, another Lod. Each mesh draws with a faded copy of its material, which every Lod
22
- * drawing that material shares. Lines, points and sprites are drawn but neither fade nor
23
- * tell the Lod the viewport height. A nested Lod hands over to its neighbours at once.
24
- * Raycasts hit the source only.
25
- *
26
- * Levels are read when the Lod is built: meshes added to a level later, or moved within
27
- * it, are neither faded nor measured right. Build a new Lod instead.
30
+ * Build a new Lod after adding or moving meshes within a level: geometry is measured and hooked at construction or
31
+ * arrival. Skinned meshes and ShaderMaterials are refused; use static meshes with node materials or supported built-in
32
+ * materials.
28
33
  */
29
- export declare class Lod extends Object3D<LevelsEventMap> {
34
+ export declare class Lod extends Object3D<LodEventMap> {
35
+ private readonly gpu;
30
36
  /** Multiplies every measured height: below 1, cheaper levels take over sooner. */
31
37
  static quality: number;
32
38
  /** Tint every level by its index, to see which level draws where. */
33
39
  static debug: boolean;
34
- /**
35
- * Share of a level's range its fade spans: from `maxPixels × (1 - fade)` up to its
36
- * `maxPixels`, the finer level draws too.
37
- */
40
+ /** Share of a level's range its fade spans: from `maxPixels × (1 - fade)` up to its `maxPixels`, the finer level draws too. */
38
41
  static readonly fade = 0.1;
39
42
  readonly isLOD = true;
40
43
  /** Let the renderer call `update` with its camera every frame. */
41
44
  autoUpdate: boolean;
42
- /** Draw only this level, without fades. */
45
+ /** Draw only this level, without fades, once the coarsest level that draws something has loaded. */
43
46
  forceLevel: number | null;
44
- readonly levels: readonly LodLevel[];
45
- private readonly entries;
46
- /** Per level, how its meshes draw. */
47
- private readonly draws;
48
- /** Bounding sphere of the source (see the constructor) in the Lod's own space. */
47
+ /** The levels, each `object` this Lod's own copy once there is one. Set `maxPixels` to move a switch. */
48
+ readonly levels: ThresholdedLevel[];
49
+ /** The levels as they were given, which a copy is made from. */
50
+ private inputs;
51
+ /** Per level, where its meshes' fade comes from. */
52
+ private readonly fades;
53
+ /** Per level, whether its object is a Lod, which fades its own levels. */
54
+ private readonly nested;
55
+ /**
56
+ * Per loaded level, what in it may cast (see `shadowCasters`): found when it is built or joins, read every shadow
57
+ * map.
58
+ */
59
+ private readonly casters;
60
+ /** The levels as levelsToDraw reads them. */
61
+ private encoded;
62
+ /** Bounding sphere of the source (see `measureLevels`) in the Lod's own space. */
49
63
  private sphere;
50
64
  private casterRadius;
65
+ private loads;
51
66
  private disposed;
52
- private readonly installed;
53
- private fallback;
54
67
  /**
55
- * `levels[0]` is the source. Empty only as the target of `copy`. A source that draws
56
- * nothing (an empty Object3D, for detail another system draws) is measured by the
57
- * first level that draws something.
68
+ * `levels[0]` is the source. Empty only as the target of `copy`. A source that draws nothing (an empty Object3D, for
69
+ * detail another system draws) is measured by the first level that draws something. `gpu` is what it shares with
70
+ * every Lod drawing with its renderer.
58
71
  */
59
- constructor(levels?: Object3D[]);
72
+ constructor(levels: readonly LodLevel[], gpu: LodGpu, options?: LodOptions);
60
73
  private build;
61
- /** Fade the meshes under `node` by `draw` and learn the viewport height from them; an inner Lod fades its own. */
74
+ /** Fade the meshes under `node` by `fade`; an inner Lod fades its own. */
62
75
  private hook;
63
- [WIND_BOUNDS](padding: number): void;
64
- /** Pick and fade levels for `camera`; three's renderer calls this itself while `autoUpdate`. */
76
+ /** A copy of `loaded`, level `index`'s object, parented hidden for world matrices and wind until it joins. */
77
+ private prepare;
78
+ get pending(): boolean;
79
+ get error(): Error | undefined;
80
+ /** Where the item of levels a camera misses goes (see `LodOptions.manager`). */
81
+ get manager(): LoadingManager;
82
+ set manager(manager: LoadingManager | undefined);
83
+ /** Switch and fade the levels for `camera`, and load those it needs. What fails is reported (see `error`): three is rendering. */
65
84
  update(camera: Camera): void;
85
+ /** Show the levels for `camera`, a shadow map's when `shadow`. */
86
+ private show;
87
+ /** The source's height on `camera`'s screen, and the levels as levelsToDraw reads them there. */
88
+ private measure;
89
+ /**
90
+ * The index of the level that draws most of the Lod's pixels for `camera` from where it is, with the levels loaded
91
+ * now and no arrival under way (see `drawnLevel`); null while no level it could draw is loaded.
92
+ */
93
+ getLevel(camera: Camera): number | null;
94
+ [WIND](padding: number): void;
66
95
  raycast(raycaster: Raycaster, intersects: Intersection[]): boolean;
67
96
  /**
68
- * Copies `source`'s levels into this empty Lod (it throws otherwise). The copies share
69
- * geometry, materials and textures with `source`, as three's clone does; the Lod
70
- * settings and each level's `maxPixels` come along.
97
+ * Copies `source`'s levels into this empty Lod (it throws otherwise). The copies share geometry, materials and
98
+ * textures with `source`, as three's clone does; the settings, LoadingManager, wind and each level's `maxPixels`
99
+ * come along.
71
100
  */
72
101
  copy(source: Lod): this;
102
+ clone(): this;
73
103
  /**
74
- * Frees every level, the source included: geometries, materials and their textures.
75
- * Clones share them, so dispose a Lod only once no clone draws any more.
104
+ * Release what the Lod made of its levels, once nothing it prepares or compiles still uses them. Objects you give or
105
+ * load are yours to dispose; LodLoader's are freed when the last Lod holding them is disposed (see `LodLevel.hold`).
76
106
  */
77
107
  dispose(): void;
78
108
  }