@aura3d/rendering 1.4.0 → 1.4.2

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 (308) hide show
  1. package/package.json +38 -4
  2. package/AGENTS.md +0 -46
  3. package/src/ArchitecturalLightingFixtures.ts +0 -241
  4. package/src/ArchitecturalMaterialCatalog.ts +0 -130
  5. package/src/ArchitecturalMeasurementFixtures.ts +0 -155
  6. package/src/BRDFLut.ts +0 -47
  7. package/src/CameraFraming.ts +0 -200
  8. package/src/CanonicalSceneFixtures.ts +0 -95
  9. package/src/CascadedShadowMaps.ts +0 -449
  10. package/src/ColorManagement.ts +0 -127
  11. package/src/CullingFixtures.ts +0 -280
  12. package/src/DecalGeometry.ts +0 -26
  13. package/src/DepthPass.ts +0 -110
  14. package/src/EnvironmentBackgroundPass.ts +0 -194
  15. package/src/EnvironmentBackgroundResources.ts +0 -309
  16. package/src/EnvironmentLighting.ts +0 -96
  17. package/src/EnvironmentMapResources.ts +0 -1026
  18. package/src/EnvironmentPipeline.ts +0 -69
  19. package/src/EnvironmentPlatform.ts +0 -1306
  20. package/src/EnvironmentPreset.ts +0 -155
  21. package/src/Exposure.ts +0 -66
  22. package/src/ExternalParityRenderPreset.ts +0 -725
  23. package/src/ForwardPass.ts +0 -1668
  24. package/src/FrameVisualMetrics.ts +0 -301
  25. package/src/Geometry.ts +0 -461
  26. package/src/GeometryPrimitives.ts +0 -2
  27. package/src/HDRRenderPipeline.ts +0 -94
  28. package/src/IBL.ts +0 -86
  29. package/src/IndexBuffer.ts +0 -57
  30. package/src/InstancedPBRMaterial.ts +0 -186
  31. package/src/InstancedUnlitMaterial.ts +0 -60
  32. package/src/Instancing.ts +0 -19
  33. package/src/LightCollector.ts +0 -82
  34. package/src/LightUniforms.ts +0 -47
  35. package/src/LightingDebug.ts +0 -80
  36. package/src/LightingDefaults.ts +0 -79
  37. package/src/LightingRig.ts +0 -301
  38. package/src/LineGeometry.ts +0 -2
  39. package/src/Material.ts +0 -209
  40. package/src/MaterialBinding.ts +0 -131
  41. package/src/MaterialInstance.ts +0 -59
  42. package/src/MaterialPresets.ts +0 -272
  43. package/src/MorphTarget.ts +0 -124
  44. package/src/MorphTargetPlan.ts +0 -178
  45. package/src/MorphUnlitMaterial.ts +0 -60
  46. package/src/NormalMappedPBRMaterial.ts +0 -188
  47. package/src/OceanFixtures.ts +0 -318
  48. package/src/PBRLightingDefaults.ts +0 -12
  49. package/src/PBRMaterial.ts +0 -442
  50. package/src/PMREM.ts +0 -53
  51. package/src/PbrReference.ts +0 -681
  52. package/src/PostProcessPass.ts +0 -2507
  53. package/src/ProceduralTextureFixtures.ts +0 -393
  54. package/src/ProductTurntableFixtures.ts +0 -815
  55. package/src/Raycaster.ts +0 -21
  56. package/src/ReflectionProbe.ts +0 -13
  57. package/src/ReflectionSurfaces.ts +0 -219
  58. package/src/RenderBackend.ts +0 -43
  59. package/src/RenderDebugViews.ts +0 -138
  60. package/src/RenderDevice.ts +0 -836
  61. package/src/RenderGraph.ts +0 -194
  62. package/src/RenderPass.ts +0 -27
  63. package/src/RenderPipeline.ts +0 -101
  64. package/src/RenderQueue.ts +0 -12
  65. package/src/RenderState.ts +0 -12
  66. package/src/Renderer.ts +0 -2631
  67. package/src/RendererDebugOverlay.ts +0 -80
  68. package/src/RendererFeatureGates.ts +0 -150
  69. package/src/RendererPostprocessPlan.ts +0 -279
  70. package/src/RendererTiming.ts +0 -251
  71. package/src/RendererVisualPipelineReport.ts +0 -836
  72. package/src/ResourceLifecycle.ts +0 -21
  73. package/src/Sampler.ts +0 -37
  74. package/src/SceneOptimization.ts +0 -518
  75. package/src/ShaderChunks.ts +0 -393
  76. package/src/ShaderLibrary.ts +0 -2766
  77. package/src/ShaderModule.ts +0 -36
  78. package/src/ShaderPreprocessor.ts +0 -260
  79. package/src/ShaderReflection.ts +0 -201
  80. package/src/ShadowMap.ts +0 -237
  81. package/src/ShadowPass.ts +0 -198
  82. package/src/ShadowProjection.ts +0 -115
  83. package/src/SkinnedLitMaterial.ts +0 -397
  84. package/src/SkinnedUnlitMaterial.ts +0 -63
  85. package/src/SkinningBounds.ts +0 -131
  86. package/src/SpaceEnvironmentFixtures.ts +0 -200
  87. package/src/SpriteGeometry.ts +0 -21
  88. package/src/StereoCameraRig.ts +0 -127
  89. package/src/StereoEffects.ts +0 -274
  90. package/src/TerrainFixtures.ts +0 -180
  91. package/src/Texture.ts +0 -307
  92. package/src/TextureBinding.ts +0 -91
  93. package/src/TexturedPBRMaterial.ts +0 -1112
  94. package/src/TexturedUnlitMaterial.ts +0 -67
  95. package/src/ToneMapping.ts +0 -105
  96. package/src/UniformBinder.ts +0 -16
  97. package/src/UniformLayout.ts +0 -129
  98. package/src/UnlitMaterial.ts +0 -75
  99. package/src/VegetationFixtures.ts +0 -314
  100. package/src/VertexBuffer.ts +0 -120
  101. package/src/VertexFormat.ts +0 -171
  102. package/src/VoxelWorldFixtures.ts +0 -280
  103. package/src/WeatherFixtures.ts +0 -223
  104. package/src/WebGL2Device.ts +0 -2280
  105. package/src/WebGL2StateCache.ts +0 -330
  106. package/src/WebGPUDevice.ts +0 -2877
  107. package/src/WebGPURenderToTextureProof.ts +0 -139
  108. package/src/advanced-runtime/AdvancedRenderer.ts +0 -73
  109. package/src/advanced-runtime/index.ts +0 -9
  110. package/src/animation/AnimationMaterialStyle.ts +0 -32
  111. package/src/animation/AnimationRenderPreset.ts +0 -45
  112. package/src/animation/AnimationToonMaterial.ts +0 -387
  113. package/src/animation/AnimationVisualQuality.ts +0 -71
  114. package/src/animation/applyAnimationRenderPreset.ts +0 -180
  115. package/src/animation/index.ts +0 -5
  116. package/src/cinematic/BloomPass.ts +0 -26
  117. package/src/cinematic/CinematicDepthComposition.ts +0 -30
  118. package/src/cinematic/CinematicEvidence.ts +0 -123
  119. package/src/cinematic/CinematicLightingRig.ts +0 -144
  120. package/src/cinematic/CinematicMaterialPresets.ts +0 -130
  121. package/src/cinematic/CinematicPostProcess.ts +0 -83
  122. package/src/cinematic/DepthHazePass.ts +0 -30
  123. package/src/cinematic/EmissivePracticalLightSystem.ts +0 -45
  124. package/src/cinematic/FilmGrainPass.ts +0 -24
  125. package/src/cinematic/FogVolumeSystem.ts +0 -30
  126. package/src/cinematic/GlowCardSystem.ts +0 -44
  127. package/src/cinematic/RainParticleSystem.ts +0 -151
  128. package/src/cinematic/VignettePass.ts +0 -25
  129. package/src/cinematic/WetReflectionApproximation.ts +0 -27
  130. package/src/cinematic/index.ts +0 -14
  131. package/src/effects/CollisionModule.ts +0 -64
  132. package/src/effects/ColorModule.ts +0 -60
  133. package/src/effects/ForceModule.ts +0 -25
  134. package/src/effects/GPUParticleBackend.ts +0 -569
  135. package/src/effects/Particle.ts +0 -108
  136. package/src/effects/ParticleDiagnostics.ts +0 -224
  137. package/src/effects/ParticleEffectPresets.ts +0 -147
  138. package/src/effects/ParticleEmitter.ts +0 -326
  139. package/src/effects/ParticleModule.ts +0 -26
  140. package/src/effects/ParticleRenderPass.ts +0 -117
  141. package/src/effects/ParticleRenderer.ts +0 -132
  142. package/src/effects/ParticleSystem.ts +0 -333
  143. package/src/effects/SizeModule.ts +0 -56
  144. package/src/effects/TrailModule.ts +0 -72
  145. package/src/effects/VelocityModule.ts +0 -75
  146. package/src/effects/index.ts +0 -15
  147. package/src/index.ts +0 -925
  148. package/src/materials/AlphaSorting.ts +0 -30
  149. package/src/materials/MaterialExtensions.ts +0 -42
  150. package/src/materials/PhysicalMaterial.ts +0 -133
  151. package/src/materials/TransmissionPass.ts +0 -51
  152. package/src/performance/BVH.ts +0 -18
  153. package/src/performance/Batcher.ts +0 -2
  154. package/src/performance/FrustumCuller.ts +0 -9
  155. package/src/performance/LOD.ts +0 -20
  156. package/src/performance/Octree.ts +0 -10
  157. package/src/performance/RenderItemSorting.ts +0 -170
  158. package/src/performance/RendererStats.ts +0 -43
  159. package/src/performance/ResourceBudget.ts +0 -44
  160. package/src/postprocess/BloomPass.ts +0 -28
  161. package/src/postprocess/CinematicDiagnostics.ts +0 -642
  162. package/src/postprocess/ColorGradingPass.ts +0 -24
  163. package/src/postprocess/DepthOfFieldPass.ts +0 -12
  164. package/src/postprocess/EffectComposer.ts +0 -349
  165. package/src/postprocess/SSAOPass.ts +0 -20
  166. package/src/postprocess/index.ts +0 -34
  167. package/src/production-runtime/AnimationControlsPipeline.ts +0 -77
  168. package/src/production-runtime/PBRHDRPipeline.ts +0 -381
  169. package/src/production-runtime/ProductionEffectsPipeline.ts +0 -85
  170. package/src/production-runtime/ProductionRendererTypes.ts +0 -136
  171. package/src/production-runtime/ProductionRuntimeRenderer.ts +0 -172
  172. package/src/production-runtime/ProductionWebGL2Renderer.ts +0 -313
  173. package/src/production-runtime/ProductionWebGPURenderer.ts +0 -396
  174. package/src/production-runtime/TransmissionBackdropCapture.ts +0 -130
  175. package/src/production-runtime/animation/MorphTargetRenderer.ts +0 -2
  176. package/src/production-runtime/animation/SkinningRenderer.ts +0 -2
  177. package/src/production-runtime/backends/RendererBackend.ts +0 -17
  178. package/src/production-runtime/backends/WebGL2RendererBackend.ts +0 -30
  179. package/src/production-runtime/backends/WebGPURendererBackend.ts +0 -24
  180. package/src/production-runtime/backends/webgl2/WebGL2Buffer.ts +0 -2
  181. package/src/production-runtime/backends/webgl2/WebGL2Capabilities.ts +0 -2
  182. package/src/production-runtime/backends/webgl2/WebGL2RenderTarget.ts +0 -2
  183. package/src/production-runtime/backends/webgl2/WebGL2Shader.ts +0 -2
  184. package/src/production-runtime/backends/webgl2/WebGL2StateCache.ts +0 -1
  185. package/src/production-runtime/backends/webgl2/WebGL2Texture.ts +0 -2
  186. package/src/production-runtime/backends/webgpu/WebGPUBuffer.ts +0 -2
  187. package/src/production-runtime/backends/webgpu/WebGPUCapabilities.ts +0 -2
  188. package/src/production-runtime/backends/webgpu/WebGPURenderTarget.ts +0 -2
  189. package/src/production-runtime/backends/webgpu/WebGPUShader.ts +0 -2
  190. package/src/production-runtime/backends/webgpu/WebGPUTexture.ts +0 -2
  191. package/src/production-runtime/color/ColorManagement.ts +0 -3
  192. package/src/production-runtime/color/ToneMapping.ts +0 -7
  193. package/src/production-runtime/diagnostics/FrameCapture.ts +0 -2
  194. package/src/production-runtime/diagnostics/GPUCapabilities.ts +0 -2
  195. package/src/production-runtime/diagnostics/RendererStats.ts +0 -2
  196. package/src/production-runtime/environment/EnvironmentMap.ts +0 -1
  197. package/src/production-runtime/environment/HDRLoader.ts +0 -57
  198. package/src/production-runtime/environment/PMREMGenerator.ts +0 -713
  199. package/src/production-runtime/framegraph/FrameGraph.ts +0 -18
  200. package/src/production-runtime/framegraph/RenderPass.ts +0 -15
  201. package/src/production-runtime/geometry/ProjectedDecalGeometry.ts +0 -439
  202. package/src/production-runtime/index.ts +0 -127
  203. package/src/production-runtime/lights/LightManager.ts +0 -7
  204. package/src/production-runtime/lights/ShadowMapRenderer.ts +0 -5
  205. package/src/production-runtime/materials/GLTFMaterialAdapter.ts +0 -6
  206. package/src/production-runtime/materials/GLTFPBRMaterialAdapter.ts +0 -2
  207. package/src/production-runtime/materials/MaterialCompiler.ts +0 -7
  208. package/src/production-runtime/materials/MaterialTextureBindings.ts +0 -5
  209. package/src/production-runtime/materials/PBRMaterial.ts +0 -2
  210. package/src/production-runtime/materials/PBRShaderFeatures.ts +0 -2
  211. package/src/production-runtime/passes/ContactShadowPass.ts +0 -184
  212. package/src/production-runtime/passes/DepthPrepass.ts +0 -7
  213. package/src/production-runtime/passes/OpaquePass.ts +0 -7
  214. package/src/production-runtime/passes/ShadowPass.ts +0 -7
  215. package/src/production-runtime/passes/SkyboxPass.ts +0 -7
  216. package/src/production-runtime/passes/ToneMappingPass.ts +0 -7
  217. package/src/production-runtime/passes/TransparentPass.ts +0 -7
  218. package/src/production-runtime/postprocess/BloomPass.ts +0 -51
  219. package/src/production-runtime/postprocess/ColorGradingPass.ts +0 -49
  220. package/src/production-runtime/postprocess/DOFPass.ts +0 -47
  221. package/src/production-runtime/postprocess/FXAAPass.ts +0 -53
  222. package/src/production-runtime/postprocess/ProductionEffectComposer.ts +0 -78
  223. package/src/production-runtime/postprocess/ProductionPostProcessTypes.ts +0 -174
  224. package/src/production-runtime/postprocess/SSAOPass.ts +0 -45
  225. package/src/production-runtime/resources/GPUBuffer.ts +0 -2
  226. package/src/production-runtime/resources/GPUTexture.ts +0 -2
  227. package/src/production-runtime/resources/RenderTarget.ts +0 -3
  228. package/src/production-runtime/resources/ResourceCache.ts +0 -7
  229. package/src/production-runtime/scene/Camera.ts +0 -1
  230. package/src/production-runtime/scene/Lights.ts +0 -2
  231. package/src/production-runtime/scene/RenderableMesh.ts +0 -2
  232. package/src/production-runtime/scene/RenderablePrimitive.ts +0 -1
  233. package/src/production-runtime/scene/RenderableScene.ts +0 -4
  234. package/src/production-runtime/shaders/ShaderProgramLibrary.ts +0 -7
  235. package/src/production-runtime/shaders/chunks/brdf.glsl +0 -2
  236. package/src/production-runtime/shaders/chunks/ibl.glsl +0 -3
  237. package/src/production-runtime/shaders/chunks/pbr.frag.glsl +0 -47
  238. package/src/production-runtime/shaders/chunks/pbr.vert.glsl +0 -8
  239. package/src/production-runtime/shaders/chunks/shadows.glsl +0 -2
  240. package/src/production-runtime/shaders/wgsl/pbr.wgsl +0 -3
  241. package/src/production-runtime/shaders/wgsl/postprocess.wgsl +0 -2
  242. package/src/production-runtime/shaders/wgsl/skybox.wgsl +0 -2
  243. package/src/shaders/depth.frag.glsl +0 -5
  244. package/src/shaders/depth.vert.glsl +0 -8
  245. package/src/shaders/pbr-direct.frag.glsl +0 -687
  246. package/src/shaders/pbr-direct.vert.glsl +0 -18
  247. package/src/shaders/unlit.frag.glsl +0 -18
  248. package/src/shaders/unlit.vert.glsl +0 -13
  249. package/src/shadows/CascadedShadowPipeline.ts +0 -53
  250. package/src/shadows/ContactShadows.ts +0 -106
  251. package/src/shadows/ShadowDebugViews.ts +0 -46
  252. package/src/threejs-compatibility/InstancingSystem.ts +0 -17
  253. package/src/threejs-compatibility/LightingSystem.ts +0 -22
  254. package/src/threejs-compatibility/MaterialSystem.ts +0 -9
  255. package/src/threejs-compatibility/RenderTargetSystem.ts +0 -35
  256. package/src/threejs-compatibility/RendererDiagnostics.ts +0 -61
  257. package/src/threejs-compatibility/SceneRenderer.ts +0 -34
  258. package/src/threejs-compatibility/ShadowSystem.ts +0 -19
  259. package/src/threejs-compatibility/TextureSystem.ts +0 -19
  260. package/src/threejs-compatibility/ThreeCompatRenderer.ts +0 -90
  261. package/src/threejs-compatibility/TransparencySystem.ts +0 -19
  262. package/src/threejs-compatibility/index.ts +0 -29
  263. package/src/threejs-compatibility/performance/BVH.ts +0 -14
  264. package/src/threejs-compatibility/performance/FrustumCulling.ts +0 -10
  265. package/src/threejs-compatibility/performance/Instancing.ts +0 -4
  266. package/src/threejs-compatibility/performance/LODSystem.ts +0 -16
  267. package/src/threejs-compatibility/performance/OcclusionCulling.ts +0 -6
  268. package/src/threejs-compatibility/performance/RaycastAcceleration.ts +0 -12
  269. package/src/threejs-compatibility/performance/RendererProfiler.ts +0 -19
  270. package/src/threejs-compatibility/performance/TextureStreaming.ts +0 -4
  271. package/src/threejs-compatibility/performance/index.ts +0 -12
  272. package/src/threejs-compatibility/postprocess/BloomPass.ts +0 -16
  273. package/src/threejs-compatibility/postprocess/ColorGradingPass.ts +0 -16
  274. package/src/threejs-compatibility/postprocess/DepthOfFieldPass.ts +0 -21
  275. package/src/threejs-compatibility/postprocess/EffectComposer.ts +0 -14
  276. package/src/threejs-compatibility/postprocess/FXAAPass.ts +0 -15
  277. package/src/threejs-compatibility/postprocess/MotionBlurPass.ts +0 -20
  278. package/src/threejs-compatibility/postprocess/OutlinePass.ts +0 -21
  279. package/src/threejs-compatibility/postprocess/PostProcessTypes.ts +0 -169
  280. package/src/threejs-compatibility/postprocess/RenderPass.ts +0 -9
  281. package/src/threejs-compatibility/postprocess/SMAAPass.ts +0 -15
  282. package/src/threejs-compatibility/postprocess/SSAOPass.ts +0 -21
  283. package/src/threejs-compatibility/postprocess/ShaderPass.ts +0 -7
  284. package/src/threejs-compatibility/postprocess/TAAPass.ts +0 -15
  285. package/src/threejs-compatibility/postprocess/VignettePass.ts +0 -16
  286. package/src/threejs-compatibility/postprocess/index.ts +0 -15
  287. package/src/threejs-compatibility/shaders/NodeMaterial.ts +0 -21
  288. package/src/threejs-compatibility/shaders/RawShaderMaterial.ts +0 -6
  289. package/src/threejs-compatibility/shaders/ShaderDiagnostics.ts +0 -17
  290. package/src/threejs-compatibility/shaders/ShaderMaterial.ts +0 -18
  291. package/src/threejs-compatibility/shaders/ThreeCompatShaderChunks.ts +0 -6
  292. package/src/threejs-compatibility/shaders/Uniforms.ts +0 -18
  293. package/src/threejs-compatibility/shaders/index.ts +0 -9
  294. package/src/threejs-compatibility/vfx/GPUPointCloud.ts +0 -7
  295. package/src/threejs-compatibility/vfx/LineRenderer.ts +0 -13
  296. package/src/threejs-compatibility/vfx/ParticleSystem.ts +0 -23
  297. package/src/threejs-compatibility/vfx/SpriteSystem.ts +0 -14
  298. package/src/threejs-compatibility/vfx/TrailRenderer.ts +0 -8
  299. package/src/threejs-compatibility/vfx/VFXDiagnostics.ts +0 -23
  300. package/src/threejs-compatibility/vfx/index.ts +0 -9
  301. package/src/threejs-example-parity/index.ts +0 -205
  302. package/src/webgpu/WebGPUBuffer.ts +0 -1
  303. package/src/webgpu/WebGPUCompute.ts +0 -2
  304. package/src/webgpu/WebGPUPipelineCache.ts +0 -15
  305. package/src/webgpu/WebGPUPostProcess.ts +0 -2
  306. package/src/webgpu/WebGPUTexture.ts +0 -2
  307. package/tsconfig.json +0 -26
  308. package/vitest.config.ts +0 -20
@@ -1,21 +0,0 @@
1
- import type { DisposableResource } from "./RenderDevice";
2
-
3
- export class ResourceLifecycle {
4
- private readonly resources = new Set<DisposableResource>();
5
-
6
- track<T extends DisposableResource>(resource: T): T {
7
- this.resources.add(resource);
8
- return resource;
9
- }
10
-
11
- dispose(): void {
12
- for (const resource of this.resources) {
13
- if (!resource.disposed) resource.dispose();
14
- }
15
- this.resources.clear();
16
- }
17
-
18
- leakCount(): number {
19
- return [...this.resources].filter((resource) => !resource.disposed).length;
20
- }
21
- }
package/src/Sampler.ts DELETED
@@ -1,37 +0,0 @@
1
- export type TextureMagFilter = "nearest" | "linear";
2
- export type TextureMinFilter =
3
- | TextureMagFilter
4
- | "nearest-mipmap-nearest"
5
- | "linear-mipmap-nearest"
6
- | "nearest-mipmap-linear"
7
- | "linear-mipmap-linear";
8
- export type TextureFilter = TextureMinFilter;
9
- export type TextureAddressMode = "clamp-to-edge" | "repeat" | "mirror-repeat";
10
-
11
- export interface SamplerDescriptor {
12
- readonly minFilter?: TextureMinFilter;
13
- readonly magFilter?: TextureMagFilter;
14
- readonly addressU?: TextureAddressMode;
15
- readonly addressV?: TextureAddressMode;
16
- readonly maxAnisotropy?: number;
17
- }
18
-
19
- export class Sampler {
20
- public readonly minFilter: TextureMinFilter;
21
- public readonly magFilter: TextureMagFilter;
22
- public readonly addressU: TextureAddressMode;
23
- public readonly addressV: TextureAddressMode;
24
- public readonly maxAnisotropy: number;
25
-
26
- constructor(descriptor: SamplerDescriptor = {}) {
27
- this.minFilter = descriptor.minFilter ?? "linear";
28
- this.magFilter = descriptor.magFilter ?? "linear";
29
- this.addressU = descriptor.addressU ?? "clamp-to-edge";
30
- this.addressV = descriptor.addressV ?? "clamp-to-edge";
31
- const maxAnisotropy = descriptor.maxAnisotropy ?? 1;
32
- if (!Number.isFinite(maxAnisotropy) || maxAnisotropy < 1) {
33
- throw new RangeError("Sampler maxAnisotropy must be finite and at least 1");
34
- }
35
- this.maxAnisotropy = maxAnisotropy;
36
- }
37
- }
@@ -1,518 +0,0 @@
1
- import { Box3, Ray, Vector3 } from "@aura3d/math";
2
- import { Geometry } from "./Geometry";
3
- import { MAX_GPU_INSTANCES, type RenderItem, type RenderMaterial } from "./ForwardPass";
4
-
5
- export interface LodLevel {
6
- readonly name: string;
7
- readonly geometry: Geometry;
8
- readonly material?: RenderMaterial;
9
- readonly maxDistance?: number;
10
- readonly minScreenSize?: number;
11
- }
12
-
13
- export interface LodSelectionInput {
14
- readonly distance: number;
15
- readonly screenSize: number;
16
- readonly levels: readonly LodLevel[];
17
- }
18
-
19
- export interface LodSelection {
20
- readonly level: LodLevel;
21
- readonly levelIndex: number;
22
- readonly reason: "distance" | "screen-size" | "fallback";
23
- }
24
-
25
- export interface StaticBatchInput {
26
- readonly geometry: Geometry;
27
- readonly material: RenderMaterial;
28
- readonly modelMatrix: Float32Array | readonly number[];
29
- readonly batchKey: string;
30
- readonly label?: string;
31
- }
32
-
33
- export interface StaticBatchOptions {
34
- readonly maxInstancesPerBatch?: number;
35
- readonly labelPrefix?: string;
36
- }
37
-
38
- export interface StaticBatchResult {
39
- readonly renderItems: readonly RenderItem[];
40
- readonly logicalItems: number;
41
- readonly submittedItems: number;
42
- readonly batches: number;
43
- readonly unbatchedItems: number;
44
- readonly maxInstancesPerBatch: number;
45
- readonly drawCallReduction: number;
46
- }
47
-
48
- export interface StaticSpatialItem<T = unknown> {
49
- readonly id: string;
50
- readonly bounds: StaticSpatialBounds;
51
- readonly payload?: T;
52
- }
53
-
54
- export interface StaticSpatialBounds {
55
- readonly min: readonly [number, number, number];
56
- readonly max: readonly [number, number, number];
57
- }
58
-
59
- export interface StaticBoundsIntersector {
60
- intersectsBox(box: Box3): boolean;
61
- }
62
-
63
- export interface StaticBoundsBvhOptions {
64
- readonly maxLeafSize?: number;
65
- readonly maxDepth?: number;
66
- }
67
-
68
- export interface StaticBoundsBvh<T = unknown> {
69
- readonly root: StaticBoundsBvhNode;
70
- readonly items: readonly StaticSpatialItem<T>[];
71
- readonly diagnostics: StaticBoundsBvhBuildDiagnostics;
72
- }
73
-
74
- export interface StaticBoundsBvhNode {
75
- readonly id: number;
76
- readonly bounds: StaticSpatialBounds;
77
- readonly depth: number;
78
- readonly itemCount: number;
79
- readonly itemIndices?: readonly number[];
80
- readonly left?: StaticBoundsBvhNode;
81
- readonly right?: StaticBoundsBvhNode;
82
- }
83
-
84
- export interface StaticBoundsBvhBuildDiagnostics {
85
- readonly objectCount: number;
86
- readonly bvhNodes: number;
87
- readonly leafNodes: number;
88
- readonly maxDepth: number;
89
- readonly buildTimeMs: number;
90
- }
91
-
92
- export interface StaticBoundsBvhQueryOptions {
93
- readonly bounds?: StaticSpatialBounds;
94
- readonly frustum?: StaticBoundsIntersector;
95
- }
96
-
97
- export interface StaticBoundsBvhQueryResult<T = unknown> {
98
- readonly items: readonly StaticSpatialItem<T>[];
99
- readonly diagnostics: StaticBoundsBvhTraversalDiagnostics;
100
- }
101
-
102
- export interface StaticBoundsBvhTraversalDiagnostics {
103
- readonly totalObjects: number;
104
- readonly visibleObjects: number;
105
- readonly culledObjects: number;
106
- readonly bvhNodes: number;
107
- readonly visitedNodes: number;
108
- readonly rejectedNodes: number;
109
- readonly boundsTests: number;
110
- readonly leafTests: number;
111
- readonly traversalTimeMs: number;
112
- }
113
-
114
- export interface StaticBoundsBvhUpdateResult<T = unknown> {
115
- readonly bvh: StaticBoundsBvh<T>;
116
- readonly updatedObjects: number;
117
- readonly strategy: "rebuild";
118
- }
119
-
120
- export interface StaticBoundsBvhRaycastHit<T = unknown> {
121
- readonly item: StaticSpatialItem<T>;
122
- readonly distance: number;
123
- readonly point: readonly [number, number, number];
124
- }
125
-
126
- export interface StaticBoundsBvhRaycastResult<T = unknown> {
127
- readonly hits: readonly StaticBoundsBvhRaycastHit<T>[];
128
- readonly diagnostics: StaticBoundsBvhRaycastDiagnostics;
129
- }
130
-
131
- export interface StaticBoundsBvhRaycastDiagnostics {
132
- readonly totalObjects: number;
133
- readonly hitObjects: number;
134
- readonly bvhNodes: number;
135
- readonly visitedNodes: number;
136
- readonly rejectedNodes: number;
137
- readonly boundsTests: number;
138
- readonly leafTests: number;
139
- readonly traversalTimeMs: number;
140
- }
141
-
142
- export function selectLodLevel(input: LodSelectionInput): LodSelection {
143
- if (input.levels.length === 0) {
144
- throw new Error("LOD selection requires at least one level.");
145
- }
146
- if (!Number.isFinite(input.distance) || input.distance < 0) {
147
- throw new Error("LOD distance must be finite and non-negative.");
148
- }
149
- if (!Number.isFinite(input.screenSize) || input.screenSize < 0) {
150
- throw new Error("LOD screen size must be finite and non-negative.");
151
- }
152
-
153
- for (let index = 0; index < input.levels.length; index += 1) {
154
- const level = input.levels[index]!;
155
- if (level.maxDistance !== undefined && input.distance <= level.maxDistance) {
156
- return { level, levelIndex: index, reason: "distance" };
157
- }
158
- if (level.minScreenSize !== undefined && input.screenSize >= level.minScreenSize) {
159
- return { level, levelIndex: index, reason: "screen-size" };
160
- }
161
- }
162
-
163
- const levelIndex = input.levels.length - 1;
164
- return { level: input.levels[levelIndex]!, levelIndex, reason: "fallback" };
165
- }
166
-
167
- export function batchStaticRenderItems(items: readonly StaticBatchInput[], options: StaticBatchOptions = {}): StaticBatchResult {
168
- const maxInstancesPerBatch = options.maxInstancesPerBatch ?? MAX_GPU_INSTANCES;
169
- if (!Number.isInteger(maxInstancesPerBatch) || maxInstancesPerBatch <= 0 || maxInstancesPerBatch > MAX_GPU_INSTANCES) {
170
- throw new Error(`Static batch maxInstancesPerBatch must be an integer in [1, ${MAX_GPU_INSTANCES}].`);
171
- }
172
-
173
- const groups = new Map<string, StaticBatchInput[]>();
174
- for (const item of items) {
175
- const matrix = Array.from(item.modelMatrix);
176
- if (matrix.length !== 16 || !matrix.every(Number.isFinite)) {
177
- throw new Error(`Static batch item ${item.label ?? item.batchKey} must provide a finite mat4 modelMatrix.`);
178
- }
179
- const group = groups.get(item.batchKey);
180
- if (group) {
181
- group.push(item);
182
- } else {
183
- groups.set(item.batchKey, [item]);
184
- }
185
- }
186
-
187
- const renderItems: RenderItem[] = [];
188
- let unbatchedItems = 0;
189
- const labelPrefix = options.labelPrefix ?? "static-batch";
190
-
191
- for (const [batchKey, group] of groups) {
192
- for (let start = 0; start < group.length; start += maxInstancesPerBatch) {
193
- const chunk = group.slice(start, start + maxInstancesPerBatch);
194
- if (chunk.length === 1) {
195
- const item = chunk[0]!;
196
- renderItems.push({
197
- geometry: item.geometry,
198
- material: item.material,
199
- modelMatrix: item.modelMatrix,
200
- label: item.label ?? `${labelPrefix}-${batchKey}-${start}`
201
- });
202
- unbatchedItems += 1;
203
- continue;
204
- }
205
-
206
- const transforms = new Float32Array(chunk.length * 16);
207
- for (let index = 0; index < chunk.length; index += 1) {
208
- transforms.set(Array.from(chunk[index]!.modelMatrix), index * 16);
209
- }
210
- renderItems.push({
211
- geometry: chunk[0]!.geometry,
212
- material: chunk[0]!.material,
213
- modelMatrix: identityMatrix(),
214
- instanceTransforms: transforms,
215
- label: `${labelPrefix}-${batchKey}-${Math.floor(start / maxInstancesPerBatch)}`
216
- });
217
- }
218
- }
219
-
220
- return {
221
- renderItems,
222
- logicalItems: items.length,
223
- submittedItems: renderItems.length,
224
- batches: renderItems.length - unbatchedItems,
225
- unbatchedItems,
226
- maxInstancesPerBatch,
227
- drawCallReduction: items.length - renderItems.length
228
- };
229
- }
230
-
231
- export function buildStaticBoundsBvh<T = unknown>(
232
- items: readonly StaticSpatialItem<T>[],
233
- options: StaticBoundsBvhOptions = {}
234
- ): StaticBoundsBvh<T> {
235
- const startedAt = performanceNow();
236
- const maxLeafSize = options.maxLeafSize ?? 8;
237
- const maxDepth = options.maxDepth ?? 32;
238
- if (!Number.isInteger(maxLeafSize) || maxLeafSize <= 0) {
239
- throw new Error("Static bounds BVH maxLeafSize must be a positive integer.");
240
- }
241
- if (!Number.isInteger(maxDepth) || maxDepth <= 0) {
242
- throw new Error("Static bounds BVH maxDepth must be a positive integer.");
243
- }
244
- if (items.length === 0) {
245
- throw new Error("Static bounds BVH requires at least one item.");
246
- }
247
-
248
- const copiedItems = items.map((item, index) => validateSpatialItem(item, index));
249
- let nextNodeId = 1;
250
- let nodeCount = 0;
251
- let leafCount = 0;
252
- let deepest = 0;
253
-
254
- const buildNode = (indices: readonly number[], depth: number): StaticBoundsBvhNode => {
255
- nodeCount += 1;
256
- deepest = Math.max(deepest, depth);
257
- const bounds = mergeStaticBounds(indices.map((index) => copiedItems[index]!.bounds));
258
- if (indices.length <= maxLeafSize || depth >= maxDepth) {
259
- leafCount += 1;
260
- return {
261
- id: nextNodeId++,
262
- bounds,
263
- depth,
264
- itemCount: indices.length,
265
- itemIndices: [...indices]
266
- };
267
- }
268
-
269
- const axis = longestBoundsAxis(bounds);
270
- const sorted = [...indices].sort((a, b) => boundsCenter(copiedItems[a]!.bounds, axis) - boundsCenter(copiedItems[b]!.bounds, axis));
271
- const split = Math.max(1, Math.floor(sorted.length / 2));
272
- const left = buildNode(sorted.slice(0, split), depth + 1);
273
- const right = buildNode(sorted.slice(split), depth + 1);
274
- return {
275
- id: nextNodeId++,
276
- bounds,
277
- depth,
278
- itemCount: indices.length,
279
- left,
280
- right
281
- };
282
- };
283
-
284
- const root = buildNode(copiedItems.map((_, index) => index), 0);
285
- return {
286
- root,
287
- items: copiedItems,
288
- diagnostics: {
289
- objectCount: copiedItems.length,
290
- bvhNodes: nodeCount,
291
- leafNodes: leafCount,
292
- maxDepth: deepest,
293
- buildTimeMs: performanceNow() - startedAt
294
- }
295
- };
296
- }
297
-
298
- export function queryStaticBoundsBvh<T = unknown>(
299
- bvh: StaticBoundsBvh<T>,
300
- options: StaticBoundsBvhQueryOptions = {}
301
- ): StaticBoundsBvhQueryResult<T> {
302
- const startedAt = performanceNow();
303
- const queryBounds = options.bounds ? validateBounds(options.bounds, "query bounds") : undefined;
304
- const result: StaticSpatialItem<T>[] = [];
305
- let visitedNodes = 0;
306
- let rejectedNodes = 0;
307
- let boundsTests = 0;
308
- let leafTests = 0;
309
- let culledObjects = 0;
310
-
311
- const intersects = (bounds: StaticSpatialBounds): boolean => {
312
- boundsTests += 1;
313
- if (queryBounds && !boundsIntersect(bounds, queryBounds)) return false;
314
- if (options.frustum && !options.frustum.intersectsBox(toBox3(bounds))) return false;
315
- return true;
316
- };
317
-
318
- const visit = (node: StaticBoundsBvhNode): void => {
319
- visitedNodes += 1;
320
- if (!intersects(node.bounds)) {
321
- rejectedNodes += 1;
322
- culledObjects += node.itemCount;
323
- return;
324
- }
325
- if (node.itemIndices) {
326
- for (const index of node.itemIndices) {
327
- leafTests += 1;
328
- const item = bvh.items[index]!;
329
- if (intersects(item.bounds)) {
330
- result.push(item);
331
- } else {
332
- culledObjects += 1;
333
- }
334
- }
335
- return;
336
- }
337
- if (node.left) visit(node.left);
338
- if (node.right) visit(node.right);
339
- };
340
-
341
- visit(bvh.root);
342
- return {
343
- items: result,
344
- diagnostics: {
345
- totalObjects: bvh.items.length,
346
- visibleObjects: result.length,
347
- culledObjects,
348
- bvhNodes: bvh.diagnostics.bvhNodes,
349
- visitedNodes,
350
- rejectedNodes,
351
- boundsTests,
352
- leafTests,
353
- traversalTimeMs: performanceNow() - startedAt
354
- }
355
- };
356
- }
357
-
358
- export function updateStaticBoundsBvh<T = unknown>(
359
- bvh: StaticBoundsBvh<T>,
360
- updatedItems: readonly StaticSpatialItem<T>[],
361
- options: StaticBoundsBvhOptions = {}
362
- ): StaticBoundsBvhUpdateResult<T> {
363
- return {
364
- bvh: buildStaticBoundsBvh(updatedItems, options),
365
- updatedObjects: countUpdatedSpatialItems(bvh.items, updatedItems),
366
- strategy: "rebuild"
367
- };
368
- }
369
-
370
- export function raycastStaticBoundsBvh<T = unknown>(
371
- bvh: StaticBoundsBvh<T>,
372
- ray: Ray
373
- ): StaticBoundsBvhRaycastResult<T> {
374
- const startedAt = performanceNow();
375
- const hits: StaticBoundsBvhRaycastHit<T>[] = [];
376
- let visitedNodes = 0;
377
- let rejectedNodes = 0;
378
- let boundsTests = 0;
379
- let leafTests = 0;
380
-
381
- const intersectBounds = (bounds: StaticSpatialBounds): { readonly distance: number; readonly point: readonly [number, number, number] } | undefined => {
382
- boundsTests += 1;
383
- const point = ray.intersectBox(toBox3(bounds));
384
- if (!point) return undefined;
385
- return { distance: point.distanceTo(ray.origin), point: point.toArray() };
386
- };
387
-
388
- const visit = (node: StaticBoundsBvhNode): void => {
389
- visitedNodes += 1;
390
- if (!intersectBounds(node.bounds)) {
391
- rejectedNodes += 1;
392
- return;
393
- }
394
- if (node.itemIndices) {
395
- for (const index of node.itemIndices) {
396
- leafTests += 1;
397
- const item = bvh.items[index]!;
398
- const hit = intersectBounds(item.bounds);
399
- if (hit) {
400
- hits.push({ item, distance: hit.distance, point: hit.point });
401
- }
402
- }
403
- return;
404
- }
405
- if (node.left) visit(node.left);
406
- if (node.right) visit(node.right);
407
- };
408
-
409
- visit(bvh.root);
410
- hits.sort((a, b) => a.distance - b.distance);
411
- return {
412
- hits,
413
- diagnostics: {
414
- totalObjects: bvh.items.length,
415
- hitObjects: hits.length,
416
- bvhNodes: bvh.diagnostics.bvhNodes,
417
- visitedNodes,
418
- rejectedNodes,
419
- boundsTests,
420
- leafTests,
421
- traversalTimeMs: performanceNow() - startedAt
422
- }
423
- };
424
- }
425
-
426
- function identityMatrix(): readonly number[] {
427
- return [
428
- 1, 0, 0, 0,
429
- 0, 1, 0, 0,
430
- 0, 0, 1, 0,
431
- 0, 0, 0, 1
432
- ];
433
- }
434
-
435
- function validateSpatialItem<T>(item: StaticSpatialItem<T>, index: number): StaticSpatialItem<T> {
436
- if (!item.id) {
437
- throw new Error(`Static bounds BVH item ${index} requires an id.`);
438
- }
439
- return {
440
- ...item,
441
- bounds: validateBounds(item.bounds, item.id)
442
- };
443
- }
444
-
445
- function validateBounds(bounds: StaticSpatialBounds, label: string): StaticSpatialBounds {
446
- const values = [...bounds.min, ...bounds.max];
447
- if (bounds.min.length !== 3 || bounds.max.length !== 3 || !values.every(Number.isFinite)) {
448
- throw new Error(`Static bounds BVH ${label} bounds must contain finite min/max vec3 values.`);
449
- }
450
- if (bounds.max[0] < bounds.min[0] || bounds.max[1] < bounds.min[1] || bounds.max[2] < bounds.min[2]) {
451
- throw new Error(`Static bounds BVH ${label} bounds max must be greater than or equal to min.`);
452
- }
453
- return {
454
- min: [bounds.min[0], bounds.min[1], bounds.min[2]],
455
- max: [bounds.max[0], bounds.max[1], bounds.max[2]]
456
- };
457
- }
458
-
459
- function mergeStaticBounds(bounds: readonly StaticSpatialBounds[]): StaticSpatialBounds {
460
- const merged = bounds.reduce((box, current) => box.union(toBox3(current)), new Box3());
461
- return fromBox3(merged);
462
- }
463
-
464
- function boundsIntersect(a: StaticSpatialBounds, b: StaticSpatialBounds): boolean {
465
- return !(b.max[0] < a.min[0] || b.min[0] > a.max[0] ||
466
- b.max[1] < a.min[1] || b.min[1] > a.max[1] ||
467
- b.max[2] < a.min[2] || b.min[2] > a.max[2]);
468
- }
469
-
470
- function longestBoundsAxis(bounds: StaticSpatialBounds): 0 | 1 | 2 {
471
- const sizes = [
472
- bounds.max[0] - bounds.min[0],
473
- bounds.max[1] - bounds.min[1],
474
- bounds.max[2] - bounds.min[2]
475
- ];
476
- if (sizes[1]! >= sizes[0]! && sizes[1]! >= sizes[2]!) return 1;
477
- if (sizes[2]! >= sizes[0]! && sizes[2]! >= sizes[1]!) return 2;
478
- return 0;
479
- }
480
-
481
- function boundsCenter(bounds: StaticSpatialBounds, axis: 0 | 1 | 2): number {
482
- return (bounds.min[axis] + bounds.max[axis]) / 2;
483
- }
484
-
485
- function toBox3(bounds: StaticSpatialBounds): Box3 {
486
- return new Box3(
487
- new Vector3(bounds.min[0], bounds.min[1], bounds.min[2]),
488
- new Vector3(bounds.max[0], bounds.max[1], bounds.max[2])
489
- );
490
- }
491
-
492
- function fromBox3(box: Box3): StaticSpatialBounds {
493
- return {
494
- min: [box.min.x, box.min.y, box.min.z],
495
- max: [box.max.x, box.max.y, box.max.z]
496
- };
497
- }
498
-
499
- function countUpdatedSpatialItems<T>(previous: readonly StaticSpatialItem<T>[], next: readonly StaticSpatialItem<T>[]): number {
500
- const previousById = new Map(previous.map((item) => [item.id, item.bounds] as const));
501
- let changed = 0;
502
- for (const item of next) {
503
- const oldBounds = previousById.get(item.id);
504
- if (!oldBounds || !sameBounds(oldBounds, item.bounds)) {
505
- changed += 1;
506
- }
507
- }
508
- return changed;
509
- }
510
-
511
- function sameBounds(a: StaticSpatialBounds, b: StaticSpatialBounds): boolean {
512
- return a.min[0] === b.min[0] && a.min[1] === b.min[1] && a.min[2] === b.min[2] &&
513
- a.max[0] === b.max[0] && a.max[1] === b.max[1] && a.max[2] === b.max[2];
514
- }
515
-
516
- function performanceNow(): number {
517
- return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
518
- }