@woosh/meep-engine 3.11.2 → 3.12.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 (551) hide show
  1. package/README.md +14 -18
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/editor/SelectionVisualizer.js +127 -127
  4. package/editor/entity_world_bounds.js +27 -27
  5. package/editor/particles/rebuildParticleEmitter.js +31 -31
  6. package/editor/process/SymbolicDisplayProcess.js +1 -1
  7. package/editor/process/symbolic/CameraSymbolicDisplay.js +146 -146
  8. package/editor/process/symbolic/LightSymbolicDisplay.js +172 -172
  9. package/editor/prototypeEditorShell.js +156 -156
  10. package/editor/selection/editor_pick.js +130 -130
  11. package/editor/selection/screen_rect_frustum.js +119 -119
  12. package/editor/tools/v2/TransformControls.js +971 -971
  13. package/package.json +1 -1
  14. package/src/engine/Engine.d.ts +3 -3
  15. package/src/engine/Engine.d.ts.map +1 -1
  16. package/src/engine/Engine.js +726 -726
  17. package/src/engine/EngineHarness.d.ts +1 -1
  18. package/src/engine/EngineHarness.js +590 -590
  19. package/src/engine/ecs/HIERARCHY_REVIEW.md +717 -717
  20. package/src/engine/ecs/terrain/ecs/BuildLightTexture.d.ts +1 -1
  21. package/src/engine/ecs/terrain/ecs/BuildLightTexture.js +27 -27
  22. package/src/engine/ecs/terrain/ecs/Terrain.d.ts +1 -5
  23. package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
  24. package/src/engine/ecs/terrain/ecs/Terrain.js +790 -790
  25. package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +129 -129
  26. package/src/engine/graphics/ecs/camera/camera_find_active.d.ts +1 -1
  27. package/src/engine/graphics/ecs/camera/camera_find_active.js +28 -28
  28. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +1 -1
  29. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +428 -428
  30. package/src/engine/graphics/ecs/water/Water.d.ts +1 -1
  31. package/src/engine/graphics/ecs/water/Water.js +104 -104
  32. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts +1 -1
  33. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1 -1
  34. package/src/engine/graphics3/AnimationGraphSystem.d.ts +65 -0
  35. package/src/engine/graphics3/AnimationGraphSystem.d.ts.map +1 -0
  36. package/src/engine/graphics3/AnimationGraphSystem.js +329 -0
  37. package/src/engine/graphics3/AnimationGraphSystem3.d.ts +6 -61
  38. package/src/engine/graphics3/AnimationGraphSystem3.d.ts.map +1 -1
  39. package/src/engine/graphics3/AnimationGraphSystem3.js +6 -325
  40. package/src/engine/graphics3/AnimationSystem.d.ts +76 -0
  41. package/src/engine/graphics3/AnimationSystem.d.ts.map +1 -0
  42. package/src/engine/graphics3/AnimationSystem.js +352 -0
  43. package/src/engine/graphics3/AnimationSystem3.d.ts +6 -72
  44. package/src/engine/graphics3/AnimationSystem3.d.ts.map +1 -1
  45. package/src/engine/graphics3/AnimationSystem3.js +6 -348
  46. package/src/engine/graphics3/CameraSystem.d.ts +49 -0
  47. package/src/engine/graphics3/CameraSystem.d.ts.map +1 -0
  48. package/src/engine/graphics3/CameraSystem.js +170 -0
  49. package/src/engine/graphics3/CameraSystem3.d.ts +6 -45
  50. package/src/engine/graphics3/CameraSystem3.d.ts.map +1 -1
  51. package/src/engine/graphics3/CameraSystem3.js +6 -166
  52. package/src/engine/graphics3/DebugDrawSystem.d.ts +72 -0
  53. package/src/engine/graphics3/DebugDrawSystem.d.ts.map +1 -0
  54. package/src/engine/graphics3/DebugDrawSystem.js +205 -0
  55. package/src/engine/graphics3/DebugDrawSystem3.d.ts +6 -68
  56. package/src/engine/graphics3/DebugDrawSystem3.d.ts.map +1 -1
  57. package/src/engine/graphics3/DebugDrawSystem3.js +6 -201
  58. package/src/engine/graphics3/DecalSystem.d.ts +81 -0
  59. package/src/engine/graphics3/DecalSystem.d.ts.map +1 -0
  60. package/src/engine/graphics3/DecalSystem.js +441 -0
  61. package/src/engine/graphics3/DecalSystem3.d.ts +6 -77
  62. package/src/engine/graphics3/DecalSystem3.d.ts.map +1 -1
  63. package/src/engine/graphics3/DecalSystem3.js +6 -437
  64. package/src/engine/graphics3/FogOfWarSystem.d.ts +74 -0
  65. package/src/engine/graphics3/FogOfWarSystem.d.ts.map +1 -0
  66. package/src/engine/graphics3/FogOfWarSystem.js +265 -0
  67. package/src/engine/graphics3/FogOfWarSystem3.d.ts +6 -70
  68. package/src/engine/graphics3/FogOfWarSystem3.d.ts.map +1 -1
  69. package/src/engine/graphics3/FogOfWarSystem3.js +6 -261
  70. package/src/engine/graphics3/GraphicsEngine.d.ts +340 -0
  71. package/src/engine/graphics3/GraphicsEngine.d.ts.map +1 -0
  72. package/src/engine/graphics3/GraphicsEngine.js +790 -0
  73. package/src/engine/graphics3/GraphicsEngine3.d.ts +6 -336
  74. package/src/engine/graphics3/GraphicsEngine3.d.ts.map +1 -1
  75. package/src/engine/graphics3/GraphicsEngine3.js +6 -786
  76. package/src/engine/graphics3/HighlightSystem.d.ts +82 -0
  77. package/src/engine/graphics3/HighlightSystem.d.ts.map +1 -0
  78. package/src/engine/graphics3/HighlightSystem.js +241 -0
  79. package/src/engine/graphics3/HighlightSystem3.d.ts +6 -78
  80. package/src/engine/graphics3/HighlightSystem3.d.ts.map +1 -1
  81. package/src/engine/graphics3/HighlightSystem3.js +6 -237
  82. package/src/engine/graphics3/LightSystem.d.ts +40 -0
  83. package/src/engine/graphics3/LightSystem.d.ts.map +1 -0
  84. package/src/engine/graphics3/LightSystem.js +211 -0
  85. package/src/engine/graphics3/LightSystem3.d.ts +6 -36
  86. package/src/engine/graphics3/LightSystem3.d.ts.map +1 -1
  87. package/src/engine/graphics3/LightSystem3.js +6 -207
  88. package/src/engine/graphics3/MeshSystem.d.ts +106 -0
  89. package/src/engine/graphics3/MeshSystem.d.ts.map +1 -0
  90. package/src/engine/graphics3/MeshSystem.js +647 -0
  91. package/src/engine/graphics3/MeshSystem3.d.ts +6 -102
  92. package/src/engine/graphics3/MeshSystem3.d.ts.map +1 -1
  93. package/src/engine/graphics3/MeshSystem3.js +6 -642
  94. package/src/engine/graphics3/ParticipatingMedia.d.ts +2 -2
  95. package/src/engine/graphics3/ParticipatingMedia.js +203 -203
  96. package/src/engine/graphics3/ParticipatingMediaSystem.d.ts +87 -0
  97. package/src/engine/graphics3/ParticipatingMediaSystem.d.ts.map +1 -0
  98. package/src/engine/graphics3/ParticipatingMediaSystem.js +184 -0
  99. package/src/engine/graphics3/ParticipatingMediaSystem3.d.ts +6 -83
  100. package/src/engine/graphics3/ParticipatingMediaSystem3.d.ts.map +1 -1
  101. package/src/engine/graphics3/ParticipatingMediaSystem3.js +6 -180
  102. package/src/engine/graphics3/ParticleEmitterSystem.d.ts +76 -0
  103. package/src/engine/graphics3/ParticleEmitterSystem.d.ts.map +1 -0
  104. package/src/engine/graphics3/ParticleEmitterSystem.js +289 -0
  105. package/src/engine/graphics3/ParticleEmitterSystem3.d.ts +6 -72
  106. package/src/engine/graphics3/ParticleEmitterSystem3.d.ts.map +1 -1
  107. package/src/engine/graphics3/ParticleEmitterSystem3.js +6 -285
  108. package/src/engine/graphics3/PathDisplaySystem.d.ts +70 -0
  109. package/src/engine/graphics3/PathDisplaySystem.d.ts.map +1 -0
  110. package/src/engine/graphics3/PathDisplaySystem.js +309 -0
  111. package/src/engine/graphics3/PathDisplaySystem3.d.ts +6 -66
  112. package/src/engine/graphics3/PathDisplaySystem3.d.ts.map +1 -1
  113. package/src/engine/graphics3/PathDisplaySystem3.js +6 -305
  114. package/src/engine/graphics3/Pickable.d.ts +1 -1
  115. package/src/engine/graphics3/Pickable.js +65 -65
  116. package/src/engine/graphics3/PickingQuery.d.ts +1 -1
  117. package/src/engine/graphics3/PickingQuery.js +48 -48
  118. package/src/engine/graphics3/PickingSystem.d.ts +67 -0
  119. package/src/engine/graphics3/PickingSystem.d.ts.map +1 -0
  120. package/src/engine/graphics3/PickingSystem.js +273 -0
  121. package/src/engine/graphics3/PickingSystem3.d.ts +6 -63
  122. package/src/engine/graphics3/PickingSystem3.d.ts.map +1 -1
  123. package/src/engine/graphics3/PickingSystem3.js +6 -269
  124. package/src/engine/graphics3/ShadedGeometrySystem.d.ts +47 -0
  125. package/src/engine/graphics3/ShadedGeometrySystem.d.ts.map +1 -0
  126. package/src/engine/graphics3/ShadedGeometrySystem.js +169 -0
  127. package/src/engine/graphics3/ShadedGeometrySystem3.d.ts +6 -43
  128. package/src/engine/graphics3/ShadedGeometrySystem3.d.ts.map +1 -1
  129. package/src/engine/graphics3/ShadedGeometrySystem3.js +6 -165
  130. package/src/engine/graphics3/TerrainSystem.d.ts +80 -0
  131. package/src/engine/graphics3/TerrainSystem.d.ts.map +1 -0
  132. package/src/engine/graphics3/TerrainSystem.js +566 -0
  133. package/src/engine/graphics3/TerrainSystem3.d.ts +6 -76
  134. package/src/engine/graphics3/TerrainSystem3.d.ts.map +1 -1
  135. package/src/engine/graphics3/TerrainSystem3.js +6 -562
  136. package/src/engine/graphics3/TooltipComponentSystem.d.ts +65 -0
  137. package/src/engine/graphics3/TooltipComponentSystem.d.ts.map +1 -0
  138. package/src/engine/graphics3/TooltipComponentSystem.js +328 -0
  139. package/src/engine/graphics3/TooltipComponentSystem3.d.ts +6 -61
  140. package/src/engine/graphics3/TooltipComponentSystem3.d.ts.map +1 -1
  141. package/src/engine/graphics3/TooltipComponentSystem3.js +6 -324
  142. package/src/engine/graphics3/Trail3DSystem.d.ts +73 -0
  143. package/src/engine/graphics3/Trail3DSystem.d.ts.map +1 -0
  144. package/src/engine/graphics3/Trail3DSystem.js +221 -0
  145. package/src/engine/graphics3/Trail3DSystem3.d.ts +6 -69
  146. package/src/engine/graphics3/Trail3DSystem3.d.ts.map +1 -1
  147. package/src/engine/graphics3/Trail3DSystem3.js +6 -217
  148. package/src/engine/graphics3/VolumetricLightMap.d.ts +2 -2
  149. package/src/engine/graphics3/VolumetricLightMap.js +2 -2
  150. package/src/engine/graphics3/VolumetricLightMapSystem.d.ts +98 -0
  151. package/src/engine/graphics3/VolumetricLightMapSystem.d.ts.map +1 -0
  152. package/src/engine/graphics3/VolumetricLightMapSystem.js +261 -0
  153. package/src/engine/graphics3/VolumetricLightMapSystem3.d.ts +6 -94
  154. package/src/engine/graphics3/VolumetricLightMapSystem3.d.ts.map +1 -1
  155. package/src/engine/graphics3/VolumetricLightMapSystem3.js +10 -261
  156. package/src/engine/graphics3/WaterSystem.d.ts +59 -0
  157. package/src/engine/graphics3/WaterSystem.d.ts.map +1 -0
  158. package/src/engine/graphics3/WaterSystem.js +293 -0
  159. package/src/engine/graphics3/WaterSystem3.d.ts +6 -55
  160. package/src/engine/graphics3/WaterSystem3.d.ts.map +1 -1
  161. package/src/engine/graphics3/WaterSystem3.js +6 -289
  162. package/src/engine/graphics3/animation/AnimationGraphController.d.ts +1 -1
  163. package/src/engine/graphics3/animation/AnimationGraphController.js +518 -518
  164. package/src/engine/graphics3/animation/ClipListPlayer.d.ts +1 -1
  165. package/src/engine/graphics3/animation/ClipListPlayer.js +263 -263
  166. package/src/engine/graphics3/animation/ClipPlayback.d.ts +2 -2
  167. package/src/engine/graphics3/animation/ClipPlayback.js +84 -84
  168. package/src/engine/graphics3/decal/graph_build_decal_clusters.d.ts.map +1 -1
  169. package/src/engine/graphics3/decal/graph_build_decal_clusters.js +6 -8
  170. package/src/engine/graphics3/decal/shader_cluster_assign_decals.d.ts +0 -7
  171. package/src/engine/graphics3/decal/shader_cluster_assign_decals.d.ts.map +1 -1
  172. package/src/engine/graphics3/decal/shader_cluster_assign_decals.js +1 -1
  173. package/src/engine/graphics3/decal/shader_cull_decals_frustum.d.ts +0 -4
  174. package/src/engine/graphics3/decal/shader_cull_decals_frustum.d.ts.map +1 -1
  175. package/src/engine/graphics3/decal/shader_cull_decals_frustum.js +1 -1
  176. package/src/engine/graphics3/highlight/pack_highlight_table.d.ts +2 -2
  177. package/src/engine/graphics3/highlight/pack_highlight_table.d.ts.map +1 -1
  178. package/src/engine/graphics3/highlight/pack_highlight_table.js +74 -74
  179. package/src/engine/graphics3/pose/query_entity_node_world_pose.d.ts +1 -1
  180. package/src/engine/graphics3/pose/query_entity_node_world_pose.js +101 -101
  181. package/src/engine/graphics3/preview/make_model_thumbnail.d.ts +3 -3
  182. package/src/engine/graphics3/preview/make_model_thumbnail.d.ts.map +1 -1
  183. package/src/engine/graphics3/preview/make_model_thumbnail.js +48 -48
  184. package/src/engine/graphics3/shade_camera_projection_ray.d.ts +1 -1
  185. package/src/engine/graphics3/shade_camera_projection_ray.js +77 -77
  186. package/src/engine/graphics3/shade_node_to_entity_composition.d.ts +1 -1
  187. package/src/engine/graphics3/shade_node_to_entity_composition.js +84 -84
  188. package/src/shade/descriptor/pipeline/PipelineLayoutDescriptor.d.ts +16 -2
  189. package/src/shade/descriptor/pipeline/PipelineLayoutDescriptor.d.ts.map +1 -1
  190. package/src/shade/descriptor/pipeline/PipelineLayoutDescriptor.js +28 -4
  191. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.d.ts +1 -1
  192. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.d.ts.map +1 -1
  193. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.js +5 -2
  194. package/src/shade/device/IMMEDIATE_DATA_PLAN_2026_08_28.md +564 -451
  195. package/src/shade/device/ShadeGPUCommandContext.d.ts +18 -2
  196. package/src/shade/device/ShadeGPUCommandContext.d.ts.map +1 -1
  197. package/src/shade/device/ShadeGPUCommandContext.js +994 -940
  198. package/src/shade/device/immediate_data_supported.d.ts +33 -0
  199. package/src/shade/device/immediate_data_supported.d.ts.map +1 -0
  200. package/src/shade/device/immediate_data_supported.js +53 -0
  201. package/src/shade/device/mock/SoftwareGPUCommandEncoder.d.ts +18 -0
  202. package/src/shade/device/mock/SoftwareGPUCommandEncoder.d.ts.map +1 -1
  203. package/src/shade/device/mock/SoftwareGPUCommandEncoder.js +24 -0
  204. package/src/shade/device/mock/SoftwareGPUComputePassEncoder.d.ts +7 -0
  205. package/src/shade/device/mock/SoftwareGPUComputePassEncoder.d.ts.map +1 -1
  206. package/src/shade/device/mock/SoftwareGPUComputePassEncoder.js +49 -1
  207. package/src/shade/device/mock/SoftwareGPUDevice.d.ts.map +1 -1
  208. package/src/shade/device/mock/SoftwareGPUDevice.js +20 -2
  209. package/src/shade/device/mock/SoftwareGPUImmediateData.d.ts +65 -0
  210. package/src/shade/device/mock/SoftwareGPUImmediateData.d.ts.map +1 -0
  211. package/src/shade/device/mock/SoftwareGPUImmediateData.js +160 -0
  212. package/src/shade/device/mock/SoftwareGPURenderPassEncoder.d.ts +7 -0
  213. package/src/shade/device/mock/SoftwareGPURenderPassEncoder.d.ts.map +1 -1
  214. package/src/shade/device/mock/SoftwareGPURenderPassEncoder.js +50 -0
  215. package/src/shade/device/mock/pipeline_immediate_size.d.ts +11 -0
  216. package/src/shade/device/mock/pipeline_immediate_size.d.ts.map +1 -0
  217. package/src/shade/device/mock/pipeline_immediate_size.js +18 -0
  218. package/src/shade/device/pipeline/PipelineLayoutManager.d.ts.map +1 -1
  219. package/src/shade/device/pipeline/PipelineLayoutManager.js +1 -0
  220. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.d.ts.map +1 -1
  221. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_leaf_triangles.js +0 -1
  222. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_points.d.ts.map +1 -1
  223. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_points.js +0 -1
  224. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_visibility.d.ts.map +1 -1
  225. package/src/shade/playground/skinned_blas_refit/shader_blas_audit_visibility.js +133 -134
  226. package/src/shade/playground/skinned_blas_refit/verify_leaf_triangles.js +202 -202
  227. package/src/shade/playground/skinned_blas_refit/verify_traversal_reachability.js +249 -249
  228. package/src/shade/renderer/GraphicsContext.d.ts +9 -2
  229. package/src/shade/renderer/GraphicsContext.d.ts.map +1 -1
  230. package/src/shade/renderer/GraphicsContext.js +13 -1
  231. package/src/shade/renderer/STATIC_GRAPHICS_ENGINE_ASSETS.js +1 -1
  232. package/src/shade/renderer/animation/pose/PosePlayback.d.ts +2 -1
  233. package/src/shade/renderer/animation/pose/PosePlayback.d.ts.map +1 -1
  234. package/src/shade/renderer/animation/pose/PosePlayback.js +2 -1
  235. package/src/shade/renderer/animation/shader_animation_apply.d.ts.map +1 -1
  236. package/src/shade/renderer/animation/shader_animation_apply.js +128 -129
  237. package/src/shade/renderer/animation/shader_animation_pose_resolve.d.ts.map +1 -1
  238. package/src/shade/renderer/animation/shader_animation_pose_resolve.js +176 -177
  239. package/src/shade/renderer/animation/shader_animation_tick.d.ts.map +1 -1
  240. package/src/shade/renderer/animation/shader_animation_tick.js +125 -126
  241. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_geometry_sphere_derive.d.ts.map +1 -1
  242. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_geometry_sphere_derive.js +98 -99
  243. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_reduce.d.ts.map +1 -1
  244. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_reduce.js +212 -213
  245. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_scatter.d.ts.map +1 -1
  246. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_meshlet_bounds_scatter.js +120 -121
  247. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_skinned_mesh_bounds_refresh.d.ts.map +1 -1
  248. package/src/shade/renderer/animation/skinning/bounds_refresh/shader_skinned_mesh_bounds_refresh.js +75 -76
  249. package/src/shade/renderer/animation/skinning/shader_meshlet_apply_skinning.d.ts.map +1 -1
  250. package/src/shade/renderer/animation/skinning/shader_meshlet_apply_skinning.js +371 -372
  251. package/src/shade/renderer/animation/skinning/shader_skin_matrix_prep.d.ts.map +1 -1
  252. package/src/shade/renderer/animation/skinning/shader_skin_matrix_prep.js +104 -105
  253. package/src/shade/renderer/atmosphere/GPUSky.d.ts.map +1 -1
  254. package/src/shade/renderer/atmosphere/GPUSky.js +145 -142
  255. package/src/shade/renderer/atmosphere/MULTISCATTER_LUT_CONFIG.d.ts +34 -0
  256. package/src/shade/renderer/atmosphere/MULTISCATTER_LUT_CONFIG.d.ts.map +1 -0
  257. package/src/shade/renderer/atmosphere/MULTISCATTER_LUT_CONFIG.js +36 -0
  258. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.d.ts +20 -0
  259. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.d.ts.map +1 -0
  260. package/src/shade/renderer/atmosphere/SAMPLER_SKY_LUT.js +25 -0
  261. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.d.ts +14 -1
  262. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.d.ts.map +1 -1
  263. package/src/shade/renderer/atmosphere/chunk_get_multiscatter_values.js +163 -177
  264. package/src/shade/renderer/atmosphere/chunk_multiscatter_sample_direction.d.ts +20 -0
  265. package/src/shade/renderer/atmosphere/chunk_multiscatter_sample_direction.d.ts.map +1 -0
  266. package/src/shade/renderer/atmosphere/chunk_multiscatter_sample_direction.js +46 -0
  267. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.d.ts +11 -1
  268. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.d.ts.map +1 -1
  269. package/src/shade/renderer/atmosphere/chunk_sample_multiscatter_lut.js +57 -27
  270. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.d.ts +19 -1
  271. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.d.ts.map +1 -1
  272. package/src/shade/renderer/atmosphere/chunk_sample_transmittance_lut.js +69 -33
  273. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.d.ts +13 -0
  274. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.d.ts.map +1 -1
  275. package/src/shade/renderer/atmosphere/chunk_sky_lut_compute_uv.js +35 -35
  276. package/src/shade/renderer/atmosphere/chunk_sky_lut_params.d.ts +13 -0
  277. package/src/shade/renderer/atmosphere/chunk_sky_lut_params.d.ts.map +1 -0
  278. package/src/shade/renderer/atmosphere/chunk_sky_lut_params.js +38 -0
  279. package/src/shade/renderer/atmosphere/chunk_sky_lut_texel_to_unit.d.ts +17 -0
  280. package/src/shade/renderer/atmosphere/chunk_sky_lut_texel_to_unit.d.ts.map +1 -0
  281. package/src/shade/renderer/atmosphere/chunk_sky_lut_texel_to_unit.js +29 -0
  282. package/src/shade/renderer/atmosphere/chunk_sky_lut_uv.d.ts +21 -0
  283. package/src/shade/renderer/atmosphere/chunk_sky_lut_uv.d.ts.map +1 -0
  284. package/src/shade/renderer/atmosphere/chunk_sky_lut_uv.js +42 -0
  285. package/src/shade/renderer/atmosphere/shader_multiscatter_lut.d.ts +2 -2
  286. package/src/shade/renderer/atmosphere/shader_multiscatter_lut.d.ts.map +1 -1
  287. package/src/shade/renderer/atmosphere/shader_multiscatter_lut.js +164 -84
  288. package/src/shade/renderer/atmosphere/shader_sky_irradiance_lut.d.ts.map +1 -1
  289. package/src/shade/renderer/atmosphere/shader_sky_irradiance_lut.js +215 -204
  290. package/src/shade/renderer/atmosphere/shader_transmittance_lut.d.ts.map +1 -1
  291. package/src/shade/renderer/atmosphere/shader_transmittance_lut.js +79 -67
  292. package/src/shade/renderer/buffer/graph_inspect_gpu_buffer.js +136 -136
  293. package/src/shade/renderer/buffer/table/GPUDatabase.d.ts.map +1 -1
  294. package/src/shade/renderer/buffer/table/GPUDatabase.js +2 -3
  295. package/src/shade/renderer/buffer/table/single/GPUSingleTypeTable.js +319 -319
  296. package/src/shade/renderer/buffer/util/shader_buffer_copy_storage_to_storage.d.ts.map +1 -1
  297. package/src/shade/renderer/buffer/util/shader_buffer_copy_storage_to_storage.js +41 -42
  298. package/src/shade/renderer/buffer/util/shader_buffer_intra_copy_regions.d.ts.map +1 -1
  299. package/src/shade/renderer/buffer/util/shader_buffer_intra_copy_regions.js +83 -84
  300. package/src/shade/renderer/dynamic/shader_dynamic_mesh.d.ts.map +1 -1
  301. package/src/shade/renderer/dynamic/shader_dynamic_mesh.js +177 -170
  302. package/src/shade/renderer/extension/RENDER_EXTENSION_DESIGN.md +918 -918
  303. package/src/shade/renderer/geometry/bvh/record_blas_refit.js +4 -4
  304. package/src/shade/renderer/geometry/bvh/shader_blas_refit_leaf_bounds.d.ts.map +1 -1
  305. package/src/shade/renderer/geometry/bvh/shader_blas_refit_leaf_bounds.js +121 -122
  306. package/src/shade/renderer/geometry/meshlet/GPUMeshletManager.js +774 -774
  307. package/src/shade/renderer/geometry/meshlet/shader_meshlet_metadata_address_patch.d.ts +1 -1
  308. package/src/shade/renderer/geometry/meshlet/shader_meshlet_metadata_address_patch.d.ts.map +1 -1
  309. package/src/shade/renderer/geometry/meshlet/shader_meshlet_metadata_address_patch.js +69 -70
  310. package/src/shade/renderer/global_illumination/lpv/placement/graph_generate_probe_locations.js +367 -367
  311. package/src/shade/renderer/global_illumination/probe/octahedral/convolve/graph_lvp_atlas_to_sh.js +184 -184
  312. package/src/shade/renderer/gpu_primitive/bvh/GPU_BVH_BUILD_PLAN.md +1115 -1115
  313. package/src/shade/renderer/gpu_primitive/bvh/graph_bvh_build_lbvh.js +217 -217
  314. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_emit_hierarchy.d.ts.map +1 -1
  315. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_emit_hierarchy.js +142 -143
  316. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_morton.d.ts.map +1 -1
  317. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_morton.js +0 -1
  318. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_refit.d.ts.map +1 -1
  319. package/src/shade/renderer/gpu_primitive/bvh/shader_bvh_refit.js +140 -141
  320. package/src/shade/renderer/gpu_primitive/sort/shader_radix_sort_histogram.d.ts.map +1 -1
  321. package/src/shade/renderer/gpu_primitive/sort/shader_radix_sort_histogram.js +0 -1
  322. package/src/shade/renderer/gpu_primitive/sort/shader_radix_sort_scatter.d.ts.map +1 -1
  323. package/src/shade/renderer/gpu_primitive/sort/shader_radix_sort_scatter.js +0 -1
  324. package/src/shade/renderer/light/cluster/cull/graph_cull_lights.d.ts.map +1 -1
  325. package/src/shade/renderer/light/cluster/cull/graph_cull_lights.js +191 -198
  326. package/src/shade/renderer/light/cluster/cull/shader_cull_lights_frustum.d.ts +0 -6
  327. package/src/shade/renderer/light/cluster/cull/shader_cull_lights_frustum.d.ts.map +1 -1
  328. package/src/shade/renderer/light/cluster/cull/shader_cull_lights_frustum.js +120 -120
  329. package/src/shade/renderer/light/cluster/cull/shader_cull_lights_hzb.d.ts +0 -4
  330. package/src/shade/renderer/light/cluster/cull/shader_cull_lights_hzb.d.ts.map +1 -1
  331. package/src/shade/renderer/light/cluster/cull/shader_cull_lights_hzb.js +112 -112
  332. package/src/shade/renderer/light/cluster/graph_assign_clsuters.d.ts.map +1 -1
  333. package/src/shade/renderer/light/cluster/graph_assign_clsuters.js +10 -9
  334. package/src/shade/renderer/light/cluster/shader_cluster_assign_lights.d.ts +0 -6
  335. package/src/shade/renderer/light/cluster/shader_cluster_assign_lights.d.ts.map +1 -1
  336. package/src/shade/renderer/light/cluster/shader_cluster_assign_lights.js +1 -1
  337. package/src/shade/renderer/lightmap/bake/raster/shader_lightmap_to_viz_buffer.js +222 -222
  338. package/src/shade/renderer/lightmap/bake/tile/shader_lightmap_tile_composit.js +81 -81
  339. package/src/shade/renderer/material/GPUMaterialContext.js +380 -380
  340. package/src/shade/renderer/material/standard/fragment_gbuffer_vt.js +169 -169
  341. package/src/shade/renderer/object_property/shader_object_property_process.d.ts.map +1 -1
  342. package/src/shade/renderer/object_property/shader_object_property_process.js +83 -84
  343. package/src/shade/renderer/object_property/shader_refresh_all_mesh_bounds.d.ts.map +1 -1
  344. package/src/shade/renderer/object_property/shader_refresh_all_mesh_bounds.js +57 -58
  345. package/src/shade/renderer/particles/prototypeParticleSystem.js +2 -3
  346. package/src/shade/renderer/particles/shaders/shader_particle_emit.d.ts.map +1 -1
  347. package/src/shade/renderer/particles/shaders/shader_particle_emit.js +117 -118
  348. package/src/shade/renderer/particles/shaders/shader_particle_finalize.d.ts.map +1 -1
  349. package/src/shade/renderer/particles/shaders/shader_particle_finalize.js +77 -79
  350. package/src/shade/renderer/particles/shaders/shader_particle_render.d.ts.map +1 -1
  351. package/src/shade/renderer/particles/shaders/shader_particle_render.js +190 -183
  352. package/src/shade/renderer/particles/shaders/shader_particle_simulate.d.ts.map +1 -1
  353. package/src/shade/renderer/particles/shaders/shader_particle_simulate.js +99 -100
  354. package/src/shade/renderer/particles/sort/shader_particle_sort.d.ts.map +1 -1
  355. package/src/shade/renderer/particles/sort/shader_particle_sort.js +158 -161
  356. package/src/shade/renderer/path_tracer/graph_path_trace_scene.js +184 -184
  357. package/src/shade/renderer/postprocess/denoise/graph_atorus_denoise_luma.js +119 -119
  358. package/src/shade/renderer/postprocess/dof/raymarch/graph_postprocess_dof.js +3 -4
  359. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch_compute.d.ts.map +1 -1
  360. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_raymarch_compute.js +266 -267
  361. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.d.ts.map +1 -1
  362. package/src/shade/renderer/postprocess/dof/raymarch/shader_dof_slice_compute.js +270 -271
  363. package/src/shade/renderer/postprocess/gtao/GTAO.d.ts.map +1 -1
  364. package/src/shade/renderer/postprocess/gtao/GTAO.js +4 -0
  365. package/src/shade/renderer/postprocess/nss/shader_nss_concat.d.ts.map +1 -1
  366. package/src/shade/renderer/postprocess/nss/shader_nss_concat.js +68 -69
  367. package/src/shade/renderer/postprocess/nss/shader_nss_conv_layer.d.ts.map +1 -1
  368. package/src/shade/renderer/postprocess/nss/shader_nss_conv_layer.js +225 -226
  369. package/src/shade/renderer/postprocess/nss/shader_nss_extract_feedback.d.ts.map +1 -1
  370. package/src/shade/renderer/postprocess/nss/shader_nss_extract_feedback.js +49 -50
  371. package/src/shade/renderer/postprocess/nss/shader_nss_postprocess.d.ts.map +1 -1
  372. package/src/shade/renderer/postprocess/nss/shader_nss_postprocess.js +291 -292
  373. package/src/shade/renderer/postprocess/nss/shader_nss_preprocess.d.ts.map +1 -1
  374. package/src/shade/renderer/postprocess/nss/shader_nss_preprocess.js +230 -231
  375. package/src/shade/renderer/postprocess/ssr/reproject/shader_ffx_denoiser_reflections_reproject.d.ts +16 -2
  376. package/src/shade/renderer/postprocess/ssr/reproject/shader_ffx_denoiser_reflections_reproject.d.ts.map +1 -1
  377. package/src/shade/renderer/postprocess/ssr/reproject/shader_ffx_denoiser_reflections_reproject.js +12 -12
  378. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.d.ts.map +1 -1
  379. package/src/shade/renderer/rasterize/bucket/prepare_meshlet_draw_commands_by_material.js +341 -345
  380. package/src/shade/renderer/rasterize/bucket/shader_count_meshlets_by_material.d.ts.map +1 -1
  381. package/src/shade/renderer/rasterize/bucket/shader_count_meshlets_by_material.js +68 -69
  382. package/src/shade/renderer/rasterize/bucket/shader_make_meshlet_indirect_draw_commands_by_material.d.ts.map +1 -1
  383. package/src/shade/renderer/rasterize/bucket/shader_make_meshlet_indirect_draw_commands_by_material.js +59 -60
  384. package/src/shade/renderer/rasterize/bucket/shader_read_out_bucket.d.ts +0 -2
  385. package/src/shade/renderer/rasterize/bucket/shader_read_out_bucket.d.ts.map +1 -1
  386. package/src/shade/renderer/rasterize/bucket/shader_read_out_bucket.js +57 -57
  387. package/src/shade/renderer/rasterize/bucket/shader_sort_meshlets_by_material.d.ts.map +1 -1
  388. package/src/shade/renderer/rasterize/bucket/shader_sort_meshlets_by_material.js +64 -65
  389. package/src/shade/renderer/rasterize/compute/graph_mesh_frustum_cull.d.ts.map +1 -1
  390. package/src/shade/renderer/rasterize/compute/graph_mesh_frustum_cull.js +168 -169
  391. package/src/shade/renderer/rasterize/compute/graph_mesh_sphere_cull.d.ts.map +1 -1
  392. package/src/shade/renderer/rasterize/compute/graph_mesh_sphere_cull.js +160 -161
  393. package/src/shade/renderer/rasterize/cull/hzb/shader_hzb_mesh_filter_2way.d.ts.map +1 -1
  394. package/src/shade/renderer/rasterize/cull/hzb/shader_hzb_mesh_filter_2way.js +109 -110
  395. package/src/shade/renderer/rasterize/cull/hzb/shader_hzb_meshlet_filter_1way_full.d.ts.map +1 -1
  396. package/src/shade/renderer/rasterize/cull/hzb/shader_hzb_meshlet_filter_1way_full.js +115 -116
  397. package/src/shade/renderer/rasterize/expand/bucket/mesh/shader_instances_classify_bucket.d.ts.map +1 -1
  398. package/src/shade/renderer/rasterize/expand/bucket/mesh/shader_instances_classify_bucket.js +139 -140
  399. package/src/shade/renderer/rasterize/expand/bucket/mesh/shader_instances_count_by_rasterization_bucket.d.ts.map +1 -1
  400. package/src/shade/renderer/rasterize/expand/bucket/mesh/shader_instances_count_by_rasterization_bucket.js +91 -92
  401. package/src/shade/renderer/rasterize/expand/bucket/mesh/shader_instances_rasterization_bucket_sort.d.ts.map +1 -1
  402. package/src/shade/renderer/rasterize/expand/bucket/mesh/shader_instances_rasterization_bucket_sort.js +88 -89
  403. package/src/shade/renderer/rasterize/expand/bucket/meshlet/shader_meshlets_count_by_rasterization_bucket.d.ts.map +1 -1
  404. package/src/shade/renderer/rasterize/expand/bucket/meshlet/shader_meshlets_count_by_rasterization_bucket.js +90 -91
  405. package/src/shade/renderer/rasterize/expand/bucket/meshlet/shader_meshlets_extract_bucket.d.ts.map +1 -1
  406. package/src/shade/renderer/rasterize/expand/bucket/meshlet/shader_meshlets_extract_bucket.js +65 -66
  407. package/src/shade/renderer/rasterize/expand/bucket/meshlet/shader_meshlets_rasterization_bucket_sort.d.ts.map +1 -1
  408. package/src/shade/renderer/rasterize/expand/bucket/meshlet/shader_meshlets_rasterization_bucket_sort.js +89 -90
  409. package/src/shade/renderer/rasterize/expand/graph_mesh_filter_one_way.d.ts.map +1 -1
  410. package/src/shade/renderer/rasterize/expand/graph_mesh_filter_one_way.js +169 -170
  411. package/src/shade/renderer/rasterize/expand/mesh/graph_expand_meshes_to_meshlets.d.ts.map +1 -1
  412. package/src/shade/renderer/rasterize/expand/mesh/graph_expand_meshes_to_meshlets.js +7 -3
  413. package/src/shade/renderer/rasterize/expand/mesh/shader_mesh_expand_to_meshlets_prefix.d.ts.map +1 -1
  414. package/src/shade/renderer/rasterize/expand/mesh/shader_mesh_expand_to_meshlets_prefix.js +89 -90
  415. package/src/shade/renderer/rasterize/expand/mesh/shader_meshes_to_meshlet_counts.d.ts.map +1 -1
  416. package/src/shade/renderer/rasterize/expand/mesh/shader_meshes_to_meshlet_counts.js +61 -62
  417. package/src/shade/renderer/rasterize/expand/pass1/filter_meshlets.2-way.compute.d.ts.map +1 -1
  418. package/src/shade/renderer/rasterize/expand/pass1/filter_meshlets.2-way.compute.js +153 -154
  419. package/src/shade/renderer/rasterize/fast/graph_extract_meshes_from_bucket.d.ts.map +1 -1
  420. package/src/shade/renderer/rasterize/fast/graph_extract_meshes_from_bucket.js +77 -81
  421. package/src/shade/renderer/rasterize/native/depth/shadow_rasterization_alpha_tested_pass_descriptor.js +144 -144
  422. package/src/shade/renderer/rasterize/native/depth/shadow_rasterization_pass_descriptor.js +88 -88
  423. package/src/shade/renderer/rasterize/native/oit/shader_oit_generate_moments.js +217 -217
  424. package/src/shade/renderer/rasterize/native/oit/shader_oit_resolve_moments.js +179 -179
  425. package/src/shade/renderer/rasterize/native/oit/shader_oit_resolve_moments_ibl.js +178 -178
  426. package/src/shade/renderer/rasterize/native/viz/viz_rasterization_alpha_tested_pass_descriptor.js +194 -194
  427. package/src/shade/renderer/rasterize/native/viz/viz_rasterization_opaque_pass_descriptor.js +76 -76
  428. package/src/shade/renderer/rasterize/standard/graph_rasterize_scene.d.ts.map +1 -1
  429. package/src/shade/renderer/rasterize/standard/graph_rasterize_scene.js +5 -1
  430. package/src/shade/renderer/restir/di/shader_restir_di_denoise.d.ts.map +1 -1
  431. package/src/shade/renderer/restir/di/shader_restir_di_denoise.js +136 -137
  432. package/src/shade/renderer/restir/di/shader_restir_di_resample.d.ts.map +1 -1
  433. package/src/shade/renderer/restir/di/shader_restir_di_resample.js +129 -130
  434. package/src/shade/renderer/restir/di/shader_restir_di_resolve.d.ts.map +1 -1
  435. package/src/shade/renderer/restir/di/shader_restir_di_resolve.js +99 -100
  436. package/src/shade/renderer/restir/di/shader_restir_di_spatial.d.ts.map +1 -1
  437. package/src/shade/renderer/restir/di/shader_restir_di_spatial.js +116 -117
  438. package/src/shade/renderer/scene/GPUInstancesAccelerationStructure.js +383 -383
  439. package/src/shade/renderer/scene/hierarchy/graph_scene_update_transform_hierarchy_naive.js +123 -123
  440. package/src/shade/renderer/scene/hierarchy/shader_nodes_record_input_positions.d.ts.map +1 -1
  441. package/src/shade/renderer/scene/hierarchy/shader_nodes_record_input_positions.js +64 -65
  442. package/src/shade/renderer/scene/hierarchy/shader_nodes_update_transform_hierarchy.d.ts.map +1 -1
  443. package/src/shade/renderer/scene/hierarchy/shader_nodes_update_transform_hierarchy.js +372 -373
  444. package/src/shade/renderer/scene/hierarchy/shader_nodes_update_transform_hierarchy_naive.d.ts.map +1 -1
  445. package/src/shade/renderer/scene/hierarchy/shader_nodes_update_transform_hierarchy_naive.js +111 -112
  446. package/src/shade/renderer/scene/shader_bvh_extract_instance_leaves.d.ts.map +1 -1
  447. package/src/shade/renderer/scene/shader_bvh_extract_instance_leaves.js +0 -1
  448. package/src/shade/renderer/shader/ComputeShader.d.ts +24 -3
  449. package/src/shade/renderer/shader/ComputeShader.d.ts.map +1 -1
  450. package/src/shade/renderer/shader/ComputeShader.js +350 -292
  451. package/src/shade/renderer/shader/ImageShader.d.ts.map +1 -1
  452. package/src/shade/renderer/shader/ImageShader.js +217 -214
  453. package/src/shade/renderer/shader/ShaderDescriptor.d.ts +5 -0
  454. package/src/shade/renderer/shader/ShaderDescriptor.d.ts.map +1 -1
  455. package/src/shade/renderer/shader/ShaderDescriptor.js +46 -0
  456. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.d.ts +18 -0
  457. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.d.ts.map +1 -0
  458. package/src/shade/renderer/shader/chunk/atmosphere/ATMOSPHERE_RADII_DECLARATION.js +32 -0
  459. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_CENTER_DECLARATION.d.ts +7 -0
  460. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_CENTER_DECLARATION.d.ts.map +1 -1
  461. package/src/shade/renderer/shader/chunk/atmosphere/PLANET_CENTER_DECLARATION.js +17 -6
  462. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_ray_bounds.d.ts +21 -0
  463. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_ray_bounds.d.ts.map +1 -0
  464. package/src/shade/renderer/shader/chunk/atmosphere/chunk_atmosphere_ray_bounds.js +69 -0
  465. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_contains_aabb3.d.ts +9 -0
  466. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_contains_aabb3.d.ts.map +1 -0
  467. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_contains_aabb3.js +22 -0
  468. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_from_transformed_corners.d.ts +16 -0
  469. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_from_transformed_corners.d.ts.map +1 -0
  470. package/src/shade/renderer/shader/chunk/geometry/aabb3/chunk_aabb3_from_transformed_corners.js +41 -0
  471. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_m4.d.ts +11 -0
  472. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_m4.d.ts.map +1 -1
  473. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_m4.js +15 -19
  474. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_plane_matrix.d.ts +23 -0
  475. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_plane_matrix.d.ts.map +1 -0
  476. package/src/shade/renderer/shader/chunk/geometry/frustum/chunk_frustum_transform_plane_matrix.js +44 -0
  477. package/src/shade/renderer/shader/chunk/geometry/octahedron/chunk_uv_octahedral_unit_decode.d.ts.map +1 -1
  478. package/src/shade/renderer/shader/chunk/geometry/octahedron/chunk_uv_octahedral_unit_decode.js +1 -4
  479. package/src/shade/renderer/shader/compiler/CodeChunk.d.ts +7 -1
  480. package/src/shade/renderer/shader/compiler/CodeChunk.d.ts.map +1 -1
  481. package/src/shade/renderer/shader/compiler/CodeChunk.js +37 -2
  482. package/src/shade/renderer/shader/graph/compute/compute_binding_read_names.d.ts.map +1 -1
  483. package/src/shade/renderer/shader/graph/compute/compute_binding_read_names.js +6 -0
  484. package/src/shade/renderer/shader/graph/compute/graph_compute_indirect_pass.js +1 -1
  485. package/src/shade/renderer/shader/graph/compute/graph_compute_pass.js +1 -1
  486. package/src/shade/renderer/shader/graph/graph_image_pass.js +1 -1
  487. package/src/shade/renderer/shader/graph/graph_prepare_bindings.d.ts.map +1 -1
  488. package/src/shade/renderer/shader/graph/graph_prepare_bindings.js +7 -0
  489. package/src/shade/renderer/shader/graph/graph_prepare_pass_input_data.d.ts +3 -1
  490. package/src/shade/renderer/shader/graph/graph_prepare_pass_input_data.d.ts.map +1 -1
  491. package/src/shade/renderer/shader/graph/graph_prepare_pass_input_data.js +12 -1
  492. package/src/shade/renderer/shader/pass/RenderPassDescriptor.d.ts.map +1 -1
  493. package/src/shade/renderer/shader/pass/RenderPassDescriptor.js +1 -0
  494. package/src/shade/renderer/shader/resource/IMMEDIATE_DATA.d.ts +21 -0
  495. package/src/shade/renderer/shader/resource/IMMEDIATE_DATA.d.ts.map +1 -0
  496. package/src/shade/renderer/shader/resource/IMMEDIATE_DATA.js +21 -0
  497. package/src/shade/renderer/shader/resource/ShaderResourceSetDescriptor.d.ts +59 -1
  498. package/src/shade/renderer/shader/resource/ShaderResourceSetDescriptor.d.ts.map +1 -1
  499. package/src/shade/renderer/shader/resource/ShaderResourceSetDescriptor.js +195 -2
  500. package/src/shade/renderer/shader/type/type_has_arrays.d.ts +14 -0
  501. package/src/shade/renderer/shader/type/type_has_arrays.d.ts.map +1 -0
  502. package/src/shade/renderer/shader/type/type_has_arrays.js +33 -0
  503. package/src/shade/renderer/shader/util/compute_infer_workgroup_size_from_source.d.ts +47 -0
  504. package/src/shade/renderer/shader/util/compute_infer_workgroup_size_from_source.d.ts.map +1 -0
  505. package/src/shade/renderer/shader/util/compute_infer_workgroup_size_from_source.js +448 -0
  506. package/src/shade/renderer/shadow/map/csm/graph_csm_setup_cascades.js +3 -3
  507. package/src/shade/renderer/shadow/ray/staged/gen/graph_gen_rays.js +3 -3
  508. package/src/shade/renderer/shadow/ray/staged/trace/graph_trace_rays.js +2 -2
  509. package/src/shade/renderer/shadow/sdf/cascade/CascadedSceneSDF.js +4 -4
  510. package/src/shade/renderer/texture/virtual/build_shader_vt_feedback.d.ts.map +1 -1
  511. package/src/shade/renderer/texture/virtual/build_shader_vt_feedback.js +231 -232
  512. package/src/shade/renderer/view/GPUViewSkyContext.d.ts.map +1 -1
  513. package/src/shade/renderer/view/GPUViewSkyContext.js +169 -173
  514. package/src/shade/renderer/volumetrics/GPUViewVolumetrics.js +1 -1
  515. package/src/shade/renderer/volumetrics/NOTES.md +238 -0
  516. package/src/shade/renderer/volumetrics/chunk_volumetrics_local_light_shadow.js +145 -145
  517. package/src/shade/renderer/volumetrics/chunk_volumetrics_sun_optical_depth.d.ts.map +1 -1
  518. package/src/shade/renderer/volumetrics/chunk_volumetrics_sun_optical_depth.js +38 -15
  519. package/src/shade/renderer/volumetrics/graph_build_volumetrics.d.ts +14 -2
  520. package/src/shade/renderer/volumetrics/graph_build_volumetrics.d.ts.map +1 -1
  521. package/src/shade/renderer/volumetrics/graph_build_volumetrics.js +591 -577
  522. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.d.ts +17 -0
  523. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.d.ts.map +1 -1
  524. package/src/shade/renderer/volumetrics/shader_volumetrics_build_lighting.js +20 -2
  525. package/src/shade/renderer/volumetrics/shader_volumetrics_build_participating_media.d.ts.map +1 -1
  526. package/src/shade/renderer/volumetrics/shader_volumetrics_build_participating_media.js +29 -18
  527. package/src/shade/renderer/volumetrics/shader_volumetrics_build_scattering_lut.js +260 -260
  528. package/src/shade/renderer/volumetrics/shader_volumetrics_build_sun_shadow_volume.d.ts +53 -3
  529. package/src/shade/renderer/volumetrics/shader_volumetrics_build_sun_shadow_volume.d.ts.map +1 -1
  530. package/src/shade/renderer/volumetrics/shader_volumetrics_build_sun_shadow_volume.js +175 -59
  531. package/src/shade/renderer/volumetrics/taa/shader_volumetrics_taa.d.ts +0 -2
  532. package/src/shade/renderer/volumetrics/taa/shader_volumetrics_taa.d.ts.map +1 -1
  533. package/src/shade/renderer/volumetrics/taa/shader_volumetrics_taa.js +17 -6
  534. package/src/shade/renderer/water/shader_water.js +246 -246
  535. package/src/shade/vitest.setup.mjs +1 -1
  536. package/src/shade/wgsl/emulator/ComputeShaderEmulator.js +291 -291
  537. package/src/shade/wgsl/emulator/WGSLJavaScriptCompiler.js +8 -1
  538. package/src/shade/wgsl/emulator/WGSLLanguageCore.d.ts.map +1 -1
  539. package/src/shade/wgsl/emulator/WGSLLanguageCore.js +1325 -1297
  540. package/src/view/minimap/Minimap.d.ts +2 -2
  541. package/src/view/minimap/Minimap.d.ts.map +1 -1
  542. package/src/view/minimap/Minimap.js +225 -225
  543. package/src/view/minimap/dom/MinimapCameraView.d.ts +3 -3
  544. package/src/view/minimap/dom/MinimapCameraView.d.ts.map +1 -1
  545. package/src/view/minimap/dom/MinimapCameraView.js +206 -206
  546. package/src/shade/renderer/shadow/map/csm/shader/shader_setup_cascades.d.ts +0 -3
  547. package/src/shade/renderer/shadow/map/csm/shader/shader_setup_cascades.d.ts.map +0 -1
  548. package/src/shade/renderer/shadow/map/csm/shader/shader_setup_cascades.js +0 -20
  549. package/src/shade/renderer/volumetrics/VOLUMETRICS_WORKGROUP_RESOLUTION.d.ts +0 -2
  550. package/src/shade/renderer/volumetrics/VOLUMETRICS_WORKGROUP_RESOLUTION.d.ts.map +0 -1
  551. package/src/shade/renderer/volumetrics/VOLUMETRICS_WORKGROUP_RESOLUTION.js +0 -1
@@ -1,971 +1,971 @@
1
- import { assert } from "../../../src/core/assert.js";
2
- import Quaternion from "../../../src/core/geom/Quaternion.js";
3
- import Vector3 from "../../../src/core/geom/Vector3.js";
4
- import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
5
- import { FrameRunner } from "../../../src/engine/graphics/FrameRunner.js";
6
- import { GizmoNode } from "./GizmoNode.js";
7
- import { gizmo_drag_plane_normal, gizmo_ray_plane_point } from "./handle/gizmo_drag_plane.js";
8
- import { gizmo_draw } from "./handle/gizmo_draw.js";
9
- import { gizmo_handles_of_mode, gizmo_pick_handle } from "./handle/gizmo_handles.js";
10
- import { TransformMode } from "./TransformMode.js";
11
-
12
- /**
13
- * @type {Object<string, Vector3>}
14
- */
15
- const UNIT = {
16
- X: new Vector3(1, 0, 0),
17
- Y: new Vector3(0, 1, 0),
18
- Z: new Vector3(0, 0, 1)
19
- };
20
-
21
- /**
22
- * How fast a free rotation follows the pointer, in radians per world unit at one unit from the
23
- * camera. Carried over from the three gizmo unchanged, because it is a feel and not a derivation.
24
- *
25
- * @type {number}
26
- */
27
- const ROTATION_SPEED = 20;
28
-
29
- /**
30
- * The largest the gizmo is allowed to grow relative to its distance, which caps how big a very wide
31
- * field of view can make it. three's number, kept for the same reason.
32
- *
33
- * @type {number}
34
- */
35
- const SIZE_CLAMP = 7;
36
-
37
- const _changeEvent = { type: 'change' };
38
- const _mouseDownEvent = { type: 'mouseDown', mode: null };
39
- const _mouseUpEvent = { type: 'mouseUp', mode: null };
40
- const _objectChangeEvent = { type: 'objectChange' };
41
-
42
- /**
43
- * @type {Vector3}
44
- */
45
- const ray_origin = new Vector3();
46
-
47
- /**
48
- * @type {Vector3}
49
- */
50
- const ray_direction = new Vector3();
51
-
52
- /**
53
- * @type {Vector3}
54
- */
55
- const scratch_point = new Vector3();
56
-
57
- /**
58
- * @type {Vector3}
59
- */
60
- const scratch_vector = new Vector3();
61
-
62
- /**
63
- * @type {Vector3}
64
- */
65
- const scratch_vector_2 = new Vector3();
66
-
67
- /**
68
- * @type {Quaternion}
69
- */
70
- const scratch_quaternion = new Quaternion();
71
-
72
- /**
73
- * @readonly
74
- * @type {Transform}
75
- */
76
- const _tempTransform = new Transform();
77
-
78
- /**
79
- * The transform gizmo.
80
- *
81
- * **What it controls is an entity, and what it needs from a renderer is one ray.** Both of those are
82
- * why this can be renderer-neutral at all: `Transform` is world-space by contract, so there is no
83
- * scene graph to walk, and `viewportProjectionRay` is on both graphics engines and answers in world
84
- * space. Everything else — which handle the pointer is on, what surface a drag is measured on, where
85
- * the handles are drawn — is arithmetic, and lives in `handle/`.
86
- *
87
- * The three version answered the first two questions by building meshes and raycasting them: an
88
- * invisible cone per arm, an invisible 100000-unit `PlaneGeometry` per drag. That is why it needed
89
- * a three camera object on the component. It needs none now:
90
- * the ray through the middle of the viewport starts at the eye and points where the camera looks,
91
- * and the ray through the top edge gives the field of view the gizmo is sized against.
92
- *
93
- * The **drag maths is the three version's**, ported to meep `Vector3`/`Quaternion` — this is the
94
- * feel of a tool people have used, not something to redesign. Two things did change:
95
- *
96
- * - the parent transform is gone. It was set to the identity on every update and multiplied through
97
- * the whole of `pointerMove`, because `Transform` is world-space and there is no parent to
98
- * compose with.
99
- * - a drag no longer starts when the drag plane is edge-on to the pointer. three started one anyway,
100
- * from whatever `pointStart` the previous drag left behind.
101
- *
102
- * The three gizmo's `showX`/`showY`/`showZ` are gone with the meshes they hid; nothing in the tree
103
- * set them.
104
- */
105
- class TransformControls extends GizmoNode {
106
- /**
107
- * Entity ID that we are controlling. -1 indicates no entity
108
- * @type {number}
109
- */
110
- object = -1;
111
-
112
- isTransformControls = true;
113
-
114
- /**
115
- * @type {boolean}
116
- */
117
- enabled = true;
118
-
119
- /**
120
- * The handle under the pointer, or the one being dragged. One of the names in
121
- * {@link gizmo_handles_of_mode}, or `null`.
122
- *
123
- * @type {string|null}
124
- */
125
- axis = null;
126
-
127
- /**
128
- * @type {string} one of {@link TransformMode}
129
- */
130
- mode = TransformMode.Translate;
131
-
132
- /**
133
- * @type {string} `'world'` or `'local'`
134
- */
135
- space = 'world';
136
-
137
- /**
138
- * How big the gizmo is drawn, as a multiple of its default screen size.
139
- *
140
- * @type {number}
141
- */
142
- size = 1;
143
-
144
- /**
145
- * @type {boolean}
146
- */
147
- dragging = false;
148
-
149
- /**
150
- * World units per step, or `null` for none.
151
- *
152
- * @type {number|null}
153
- */
154
- translationSnap = null;
155
-
156
- /**
157
- * Radians per step, or `null` for none.
158
- *
159
- * @type {number|null}
160
- */
161
- rotationSnap = null;
162
-
163
- /**
164
- * @type {number|null}
165
- */
166
- scaleSnap = null;
167
-
168
- /**
169
- * @type {Vector3}
170
- */
171
- worldPosition = new Vector3();
172
-
173
- /**
174
- * @type {Quaternion}
175
- */
176
- worldQuaternion = new Quaternion();
177
-
178
- /**
179
- * Where the controlled entity was when the drag started. The tool reads these to build its undo
180
- * state, because by the time it looks the entity has already moved.
181
- *
182
- * @type {Vector3}
183
- */
184
- worldPositionStart = new Vector3();
185
-
186
- /**
187
- * @type {Quaternion}
188
- */
189
- worldQuaternionStart = new Quaternion();
190
-
191
- /**
192
- * @type {Vector3}
193
- */
194
- _worldScaleStart = new Vector3(1, 1, 1);
195
-
196
- /**
197
- * @type {Vector3}
198
- */
199
- _worldScale = new Vector3(1, 1, 1);
200
-
201
- /**
202
- * @type {Quaternion}
203
- */
204
- _worldQuaternionInv = new Quaternion();
205
-
206
- /**
207
- * @type {Vector3}
208
- */
209
- _positionStart = new Vector3();
210
-
211
- /**
212
- * @type {Quaternion}
213
- */
214
- _quaternionStart = new Quaternion();
215
-
216
- /**
217
- * @type {Vector3}
218
- */
219
- _scaleStart = new Vector3(1, 1, 1);
220
-
221
- /**
222
- * Where the pointer met the drag plane when the drag started, relative to the gizmo.
223
- *
224
- * @type {Vector3}
225
- */
226
- pointStart = new Vector3();
227
-
228
- /**
229
- * @type {Vector3}
230
- */
231
- pointEnd = new Vector3();
232
-
233
- /**
234
- * @type {Vector3}
235
- */
236
- _offset = new Vector3();
237
-
238
- /**
239
- * @type {Vector3}
240
- */
241
- _startNorm = new Vector3();
242
-
243
- /**
244
- * @type {Vector3}
245
- */
246
- _endNorm = new Vector3();
247
-
248
- /**
249
- * @type {Vector3}
250
- */
251
- rotationAxis = new Vector3();
252
-
253
- /**
254
- * @type {number}
255
- */
256
- rotationAngle = 0;
257
-
258
- /**
259
- * Where the camera is, and a unit vector from the gizmo towards it.
260
- *
261
- * @type {Vector3}
262
- */
263
- cameraPosition = new Vector3();
264
-
265
- /**
266
- * @type {Vector3}
267
- */
268
- eye = new Vector3(0, 0, 1);
269
-
270
- /**
271
- * The direction the camera looks along.
272
- *
273
- * @type {Vector3}
274
- */
275
- #camera_forward = new Vector3(0, 0, -1);
276
-
277
- /**
278
- * A ray through the top edge of the viewport, which is half a field of view away from
279
- * {@link #camera_forward}.
280
- *
281
- * @type {Vector3}
282
- */
283
- #camera_edge = new Vector3(0, 0, -1);
284
-
285
- /**
286
- * The surface a drag is measured on, rebuilt every update from the current mode, axis, space and
287
- * eye.
288
- *
289
- * A drag measures a delta between two points on this surface, so it would matter if the surface
290
- * moved mid-drag — and it cannot. An arm's plane is built from the part of the eye perpendicular
291
- * to that arm, and moving the object along the arm changes only the part parallel to it; a tile's
292
- * is a basis vector; a free drag's and a rotation's is the view direction. Nothing a drag does to
293
- * the object it is dragging can change any of them.
294
- *
295
- * @type {Vector3}
296
- */
297
- #plane_normal = new Vector3(0, 0, 1);
298
-
299
- /**
300
- * How the handles are turned: the identity in world space, the object's own rotation in local
301
- * space and always in scale mode.
302
- *
303
- * @type {Quaternion}
304
- */
305
- #handle_rotation = new Quaternion();
306
-
307
- /**
308
- * How big the gizmo is in world units, one gizmo unit each.
309
- *
310
- * @type {number}
311
- */
312
- #handle_size = 1;
313
-
314
- /**
315
- * @type {function}
316
- */
317
- #draw;
318
-
319
- /**
320
- * @param {GraphicsEngine|GraphicsEngine3} graphics the only thing a renderer is asked for is
321
- * {@link GraphicsEngine3#viewportProjectionRay} and the `preRender` signal to draw on
322
- * @param {HTMLElement} domElement
323
- * @param {boolean} [autoUpdate] update on a frame loop of its own, rather than being driven
324
- */
325
- constructor(graphics, domElement, autoUpdate = true) {
326
- super();
327
-
328
- assert.defined(graphics, 'graphics');
329
- assert.defined(domElement, 'domElement');
330
-
331
- this.graphics = graphics;
332
- this.domElement = domElement;
333
-
334
- this.domElement.style.touchAction = 'none'; // disable touch scroll
335
-
336
- this.visible = false;
337
-
338
- this._getPointer = getPointer.bind(this);
339
- this._onPointerDown = onPointerDown.bind(this);
340
- this._onPointerHover = onPointerHover.bind(this);
341
- this._onPointerMove = onPointerMove.bind(this);
342
- this._onPointerUp = onPointerUp.bind(this);
343
-
344
- this.domElement.addEventListener('pointerdown', this._onPointerDown);
345
- this.domElement.addEventListener('pointermove', this._onPointerHover);
346
- this.domElement.addEventListener('pointerup', this._onPointerUp);
347
-
348
- this.#draw = () => this.#record();
349
-
350
- if (autoUpdate) {
351
- const fr = new FrameRunner(this.update.bind(this));
352
- this.on.built.add(fr.startup, fr);
353
- this.on.destroyed.add(fr.shutdown, fr);
354
- }
355
- }
356
-
357
- /**
358
- * @param {EntityComponentDataset} ecd
359
- */
360
- build(ecd) {
361
- super.build(ecd);
362
-
363
- this.graphics.on.preRender.add(this.#draw);
364
- }
365
-
366
- /**
367
- * How big one gizmo unit is in world units.
368
- *
369
- * The gizmo is a fixed size on screen, so its world size is the distance to it times the tangent
370
- * of half the vertical field of view — and that tangent comes from the angle between the ray
371
- * through the middle of the viewport and the ray through its top edge, which is the same
372
- * measurement on either renderer and needs no camera object.
373
- *
374
- * A parallel projection has no such angle and would size the gizmo to nothing;
375
- * `viewportProjectionRay` does not describe one on either engine, so nothing here branches on it.
376
- *
377
- * @returns {number}
378
- */
379
- #size_in_world() {
380
- const cos = this.#camera_forward.dot(this.#camera_edge);
381
-
382
- const tan = Math.sqrt(1 - cos * cos) / cos;
383
-
384
- const distance = this.cameraPosition.distanceTo(this.worldPosition);
385
-
386
- return distance * Math.min(1.9 * tan, SIZE_CLAMP) * this.size / 4;
387
- }
388
-
389
- /**
390
- * Key transformation variables, and the drag surface, for this frame.
391
- */
392
- update() {
393
- const graphics = this.graphics;
394
-
395
- // both camera facts come out of the projection itself: the ray through the middle of the
396
- // viewport starts at the eye and points where the camera looks
397
- graphics.viewportProjectionRay(0, 0, this.cameraPosition, this.#camera_forward);
398
- graphics.viewportProjectionRay(0, 1, scratch_point, this.#camera_edge);
399
-
400
- if (this.object !== -1) {
401
-
402
- const object_transform = this.object_transform;
403
-
404
- this.worldPosition.copy(object_transform.position);
405
- this.worldQuaternion.copy(object_transform.rotation);
406
- this._worldScale.copy(object_transform.scale);
407
-
408
- this._worldQuaternionInv.copy(this.worldQuaternion).invert();
409
-
410
- }
411
-
412
- this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize();
413
-
414
- const local = this.mode === TransformMode.Scale || this.space === 'local';
415
-
416
- if (local) {
417
- this.#handle_rotation.copy(this.worldQuaternion);
418
- } else {
419
- this.#handle_rotation.set(0, 0, 0, 1);
420
- }
421
-
422
- this.#handle_size = this.#size_in_world();
423
-
424
- if (this.axis !== null) {
425
- gizmo_drag_plane_normal(
426
- this.#plane_normal,
427
- this.mode, this.axis, this.space,
428
- this.worldQuaternion,
429
- this.eye, this.#camera_forward
430
- );
431
- }
432
-
433
- super.update();
434
- }
435
-
436
- /**
437
- * One frame of the gizmo, onto the debug-draw pass.
438
- */
439
- #record() {
440
- if (!this.visible || this.object === -1) {
441
- return;
442
- }
443
-
444
- gizmo_draw(
445
- this.mode,
446
- this.worldPosition,
447
- this.#handle_rotation,
448
- this.#handle_size,
449
- this.axis,
450
- this.#camera_forward
451
- );
452
- }
453
-
454
- /**
455
- * The world ray under a pointer, into the module's own scratch.
456
- *
457
- * @param {{x:number, y:number}} pointer clip space
458
- */
459
- #pointer_ray(pointer) {
460
- this.graphics.viewportProjectionRay(pointer.x, pointer.y, ray_origin, ray_direction);
461
- }
462
-
463
- pointerHover(pointer) {
464
-
465
- if (this.object === -1 || this.dragging === true) return;
466
-
467
- this.#pointer_ray(pointer);
468
-
469
- this.axis = gizmo_pick_handle(
470
- gizmo_handles_of_mode(this.mode),
471
- ray_origin, ray_direction,
472
- this.worldPosition, this.#handle_rotation, this.#handle_size
473
- );
474
-
475
- }
476
-
477
- pointerDown(pointer) {
478
-
479
- if (this.object === -1 || this.dragging === true || pointer.button !== 0) return;
480
-
481
- if (this.axis === null) return;
482
-
483
- const ot = this.object_transform;
484
-
485
- this.#pointer_ray(pointer);
486
-
487
- gizmo_drag_plane_normal(
488
- this.#plane_normal,
489
- this.mode, this.axis, this.space,
490
- ot.rotation,
491
- this.eye, this.#camera_forward
492
- );
493
-
494
- if (!gizmo_ray_plane_point(
495
- scratch_point, ray_origin, ray_direction, ot.position, this.#plane_normal
496
- )) {
497
- // the drag surface is edge-on to the pointer, so there is no point on it to drag from
498
- return;
499
- }
500
-
501
- this._positionStart.copy(ot.position);
502
- this._quaternionStart.copy(ot.rotation);
503
- this._scaleStart.copy(ot.scale);
504
-
505
- this.worldPositionStart.copy(ot.position);
506
- this.worldQuaternionStart.copy(ot.rotation);
507
- this._worldScaleStart.copy(ot.scale);
508
-
509
- this.pointStart.copy(scratch_point).sub(this.worldPositionStart);
510
-
511
- this.dragging = true;
512
-
513
- _mouseDownEvent.mode = this.mode;
514
- this.dispatchEvent(_mouseDownEvent);
515
-
516
- }
517
-
518
- /**
519
- *
520
- * @param {{type:string}} event
521
- */
522
- dispatchEvent(event) {
523
- this.entity.sendEvent(event.type, event);
524
- }
525
-
526
- pointerMove(pointer) {
527
-
528
- const axis = this.axis;
529
- const mode = this.mode;
530
- const object = this.object;
531
-
532
- let space = this.space;
533
-
534
- if (mode === TransformMode.Scale) {
535
-
536
- space = 'local';
537
-
538
- } else if (axis === 'E' || axis === 'XYZE' || axis === 'XYZ') {
539
-
540
- space = 'world';
541
-
542
- }
543
-
544
- if (object === -1 || axis === null || this.dragging === false || pointer.button !== -1) return;
545
-
546
- const object_transform = this.object_transform;
547
-
548
- this.#pointer_ray(pointer);
549
-
550
- if (!gizmo_ray_plane_point(
551
- scratch_point, ray_origin, ray_direction, this.worldPositionStart, this.#plane_normal
552
- )) {
553
- return;
554
- }
555
-
556
- this.pointEnd.copy(scratch_point).sub(this.worldPositionStart);
557
-
558
- if (mode === TransformMode.Translate) {
559
-
560
- // Apply translate
561
-
562
- this._offset.copy(this.pointEnd).sub(this.pointStart);
563
-
564
- if (space === 'local' && axis !== 'XYZ') {
565
-
566
- this._offset.applyQuaternion(this._worldQuaternionInv);
567
-
568
- }
569
-
570
- if (axis.indexOf('X') === -1) this._offset.x = 0;
571
- if (axis.indexOf('Y') === -1) this._offset.y = 0;
572
- if (axis.indexOf('Z') === -1) this._offset.z = 0;
573
-
574
- if (space === 'local' && axis !== 'XYZ') {
575
-
576
- this._offset.applyQuaternion(this._quaternionStart);
577
-
578
- }
579
-
580
- _tempTransform.position.copy(this._offset);
581
- _tempTransform.position.add(this._positionStart);
582
-
583
- // Apply translation snap; snapping operates on the candidate position — the
584
- // controlled object is an entity id, Transforms are world-space by contract
585
- if (this.translationSnap) {
586
-
587
- if (space === 'local') {
588
-
589
- _tempTransform.position.applyQuaternion(
590
- scratch_quaternion.copy(this._quaternionStart).invert()
591
- );
592
-
593
- }
594
-
595
- if (axis.search('X') !== -1) {
596
-
597
- _tempTransform.position.setX(Math.round(_tempTransform.position.x / this.translationSnap) * this.translationSnap);
598
-
599
- }
600
-
601
- if (axis.search('Y') !== -1) {
602
-
603
- _tempTransform.position.setY(Math.round(_tempTransform.position.y / this.translationSnap) * this.translationSnap);
604
-
605
- }
606
-
607
- if (axis.search('Z') !== -1) {
608
-
609
- _tempTransform.position.setZ(Math.round(_tempTransform.position.z / this.translationSnap) * this.translationSnap);
610
-
611
- }
612
-
613
- if (space === 'local') {
614
-
615
- _tempTransform.position.applyQuaternion(this._quaternionStart);
616
-
617
- }
618
-
619
- }
620
-
621
- // write
622
- object_transform.position.copy(_tempTransform.position);
623
-
624
- } else if (mode === TransformMode.Scale) {
625
-
626
- if (axis.search('XYZ') !== -1) {
627
-
628
- let d = this.pointEnd.length() / this.pointStart.length();
629
-
630
- if (this.pointEnd.dot(this.pointStart) < 0) d *= -1;
631
-
632
- scratch_vector_2.set(d, d, d);
633
-
634
- } else {
635
-
636
- scratch_vector.copy(this.pointStart);
637
- scratch_vector_2.copy(this.pointEnd);
638
-
639
- scratch_vector.applyQuaternion(this._worldQuaternionInv);
640
- scratch_vector_2.applyQuaternion(this._worldQuaternionInv);
641
-
642
- scratch_vector_2.divide(scratch_vector);
643
-
644
- if (axis.search('X') === -1) {
645
-
646
- scratch_vector_2.x = 1;
647
-
648
- }
649
-
650
- if (axis.search('Y') === -1) {
651
-
652
- scratch_vector_2.y = 1;
653
-
654
- }
655
-
656
- if (axis.search('Z') === -1) {
657
-
658
- scratch_vector_2.z = 1;
659
-
660
- }
661
-
662
- }
663
-
664
- // Apply scale
665
-
666
- _tempTransform.scale.copy(this._scaleStart);
667
- _tempTransform.scale.multiply(scratch_vector_2);
668
-
669
- if (this.scaleSnap) {
670
-
671
- if (axis.search('X') !== -1) {
672
-
673
- _tempTransform.scale.setX(Math.round(_tempTransform.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap);
674
-
675
- }
676
-
677
- if (axis.search('Y') !== -1) {
678
-
679
- _tempTransform.scale.setY(Math.round(_tempTransform.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap);
680
-
681
- }
682
-
683
- if (axis.search('Z') !== -1) {
684
-
685
- _tempTransform.scale.setZ(Math.round(_tempTransform.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap);
686
-
687
- }
688
-
689
- }
690
-
691
- object_transform.scale.copy(_tempTransform.scale);
692
-
693
- } else if (mode === TransformMode.Rotate) {
694
-
695
- this._offset.copy(this.pointEnd).sub(this.pointStart);
696
-
697
- const speed = ROTATION_SPEED / this.worldPosition.distanceTo(this.cameraPosition);
698
-
699
- if (axis === 'E') {
700
-
701
- this.rotationAxis.copy(this.eye);
702
- this.rotationAngle = this.pointEnd.angleTo(this.pointStart);
703
-
704
- this._startNorm.copy(this.pointStart).normalize();
705
- this._endNorm.copy(this.pointEnd).normalize();
706
-
707
- this.rotationAngle *= (this._endNorm.cross(this._startNorm).dot(this.eye) < 0 ? 1 : -1);
708
-
709
- } else if (axis === 'XYZE') {
710
-
711
- this.rotationAxis.copy(this._offset).cross(this.eye).normalize();
712
- this.rotationAngle = this._offset.dot(scratch_vector.copy(this.rotationAxis).cross(this.eye)) * speed;
713
-
714
- } else if (axis === 'X' || axis === 'Y' || axis === 'Z') {
715
-
716
- this.rotationAxis.copy(UNIT[axis]);
717
-
718
- scratch_vector.copy(UNIT[axis]);
719
-
720
- if (space === 'local') {
721
-
722
- scratch_vector.applyQuaternion(this.worldQuaternion);
723
-
724
- }
725
-
726
- this.rotationAngle = this._offset.dot(scratch_vector.cross(this.eye).normalize()) * speed;
727
-
728
- }
729
-
730
- // Apply rotation snap
731
-
732
- if (this.rotationSnap) this.rotationAngle = Math.round(this.rotationAngle / this.rotationSnap) * this.rotationSnap;
733
-
734
- // Apply rotate
735
- if (space === 'local' && axis !== 'E' && axis !== 'XYZE') {
736
-
737
- _tempTransform.rotation.copy(this._quaternionStart);
738
- _tempTransform.rotation.multiply(
739
- scratch_quaternion.fromAxisAngle(this.rotationAxis, this.rotationAngle)
740
- ).normalize();
741
-
742
- } else {
743
-
744
- _tempTransform.rotation.copy(
745
- scratch_quaternion.fromAxisAngle(this.rotationAxis, this.rotationAngle)
746
- );
747
- _tempTransform.rotation.multiply(this._quaternionStart);
748
- _tempTransform.rotation.normalize();
749
-
750
- }
751
-
752
- object_transform.rotation.copy(_tempTransform.rotation);
753
- }
754
-
755
- this.dispatchEvent(_changeEvent);
756
- this.dispatchEvent(_objectChangeEvent);
757
-
758
- }
759
-
760
- pointerUp(pointer) {
761
-
762
- if (pointer.button !== 0) return;
763
-
764
- if (this.dragging && (this.axis !== null)) {
765
-
766
- _mouseUpEvent.mode = this.mode;
767
- this.dispatchEvent(_mouseUpEvent);
768
-
769
- }
770
-
771
- this.dragging = false;
772
- this.axis = null;
773
-
774
- }
775
-
776
- dispose() {
777
-
778
- this.domElement.removeEventListener('pointerdown', this._onPointerDown);
779
- this.domElement.removeEventListener('pointermove', this._onPointerHover);
780
- this.domElement.removeEventListener('pointermove', this._onPointerMove);
781
- this.domElement.removeEventListener('pointerup', this._onPointerUp);
782
-
783
- this.graphics.on.preRender.remove(this.#draw);
784
-
785
- }
786
-
787
- /**
788
- * Set current object
789
- * @param {number} entity
790
- * @returns {TransformControls}
791
- */
792
- attach(entity) {
793
- assert.isNonNegativeInteger(entity, 'entity');
794
-
795
- this.object = entity;
796
-
797
- this.visible = true;
798
-
799
- return this;
800
-
801
- }
802
-
803
- /**
804
- *
805
- * @returns {Transform|undefined}
806
- */
807
- get object_transform() {
808
- const ecd = this.entity.dataset;
809
-
810
- return ecd.getComponent(this.object, Transform);
811
- }
812
-
813
- // Detatch from object
814
- detach() {
815
-
816
- this.object = -1;
817
-
818
- this.visible = false;
819
- this.axis = null;
820
-
821
- // a drag in flight has no target anymore
822
- this.dragging = false;
823
-
824
- return this;
825
-
826
- }
827
-
828
- reset() {
829
-
830
- if (!this.enabled) return;
831
-
832
- if (this.dragging) {
833
-
834
- this.object_transform.position.copy(this._positionStart);
835
- this.object_transform.rotation.copy(this._quaternionStart);
836
- this.object_transform.scale.copy(this._scaleStart);
837
-
838
- this.dispatchEvent(_changeEvent);
839
- this.dispatchEvent(_objectChangeEvent);
840
-
841
- this.pointStart.copy(this.pointEnd);
842
-
843
- }
844
-
845
- }
846
-
847
- // TODO: deprecate
848
-
849
- getMode() {
850
-
851
- return this.mode;
852
-
853
- }
854
-
855
- setMode(mode) {
856
-
857
- this.mode = mode;
858
-
859
- }
860
-
861
- setTranslationSnap(translationSnap) {
862
-
863
- this.translationSnap = translationSnap;
864
-
865
- }
866
-
867
- setRotationSnap(rotationSnap) {
868
-
869
- this.rotationSnap = rotationSnap;
870
-
871
- }
872
-
873
- setScaleSnap(scaleSnap) {
874
-
875
- this.scaleSnap = scaleSnap;
876
-
877
- }
878
-
879
- setSize(size) {
880
-
881
- this.size = size;
882
-
883
- }
884
-
885
- setSpace(space) {
886
-
887
- this.space = space;
888
-
889
- }
890
-
891
- }
892
-
893
- // mouse / touch event handlers
894
-
895
- function getPointer(event) {
896
-
897
- if (this.domElement.ownerDocument.pointerLockElement) {
898
-
899
- return {
900
- x: 0,
901
- y: 0,
902
- button: event.button
903
- };
904
-
905
- } else {
906
-
907
- const rect = this.domElement.getBoundingClientRect();
908
-
909
- return {
910
- x: (event.clientX - rect.left) / rect.width * 2 - 1,
911
- y: -(event.clientY - rect.top) / rect.height * 2 + 1,
912
- button: event.button
913
- };
914
-
915
- }
916
-
917
- }
918
-
919
- function onPointerHover(event) {
920
-
921
- if (!this.enabled) return;
922
-
923
- switch (event.pointerType) {
924
-
925
- case 'mouse':
926
- case 'pen':
927
- this.pointerHover(this._getPointer(event));
928
- break;
929
-
930
- }
931
-
932
- }
933
-
934
- function onPointerDown(event) {
935
-
936
- if (!this.enabled) return;
937
-
938
- if (!document.pointerLockElement) {
939
-
940
- this.domElement.setPointerCapture(event.pointerId);
941
-
942
- }
943
-
944
- this.domElement.addEventListener('pointermove', this._onPointerMove);
945
-
946
- this.pointerHover(this._getPointer(event));
947
- this.pointerDown(this._getPointer(event));
948
-
949
- }
950
-
951
- function onPointerMove(event) {
952
-
953
- if (!this.enabled) return;
954
-
955
- this.pointerMove(this._getPointer(event));
956
-
957
- }
958
-
959
- function onPointerUp(event) {
960
-
961
- if (!this.enabled) return;
962
-
963
- this.domElement.releasePointerCapture(event.pointerId);
964
-
965
- this.domElement.removeEventListener('pointermove', this._onPointerMove);
966
-
967
- this.pointerUp(this._getPointer(event));
968
-
969
- }
970
-
971
- export { TransformControls };
1
+ import { assert } from "../../../src/core/assert.js";
2
+ import Quaternion from "../../../src/core/geom/Quaternion.js";
3
+ import Vector3 from "../../../src/core/geom/Vector3.js";
4
+ import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
5
+ import { FrameRunner } from "../../../src/engine/graphics/FrameRunner.js";
6
+ import { GizmoNode } from "./GizmoNode.js";
7
+ import { gizmo_drag_plane_normal, gizmo_ray_plane_point } from "./handle/gizmo_drag_plane.js";
8
+ import { gizmo_draw } from "./handle/gizmo_draw.js";
9
+ import { gizmo_handles_of_mode, gizmo_pick_handle } from "./handle/gizmo_handles.js";
10
+ import { TransformMode } from "./TransformMode.js";
11
+
12
+ /**
13
+ * @type {Object<string, Vector3>}
14
+ */
15
+ const UNIT = {
16
+ X: new Vector3(1, 0, 0),
17
+ Y: new Vector3(0, 1, 0),
18
+ Z: new Vector3(0, 0, 1)
19
+ };
20
+
21
+ /**
22
+ * How fast a free rotation follows the pointer, in radians per world unit at one unit from the
23
+ * camera. Carried over from the three gizmo unchanged, because it is a feel and not a derivation.
24
+ *
25
+ * @type {number}
26
+ */
27
+ const ROTATION_SPEED = 20;
28
+
29
+ /**
30
+ * The largest the gizmo is allowed to grow relative to its distance, which caps how big a very wide
31
+ * field of view can make it. three's number, kept for the same reason.
32
+ *
33
+ * @type {number}
34
+ */
35
+ const SIZE_CLAMP = 7;
36
+
37
+ const _changeEvent = { type: 'change' };
38
+ const _mouseDownEvent = { type: 'mouseDown', mode: null };
39
+ const _mouseUpEvent = { type: 'mouseUp', mode: null };
40
+ const _objectChangeEvent = { type: 'objectChange' };
41
+
42
+ /**
43
+ * @type {Vector3}
44
+ */
45
+ const ray_origin = new Vector3();
46
+
47
+ /**
48
+ * @type {Vector3}
49
+ */
50
+ const ray_direction = new Vector3();
51
+
52
+ /**
53
+ * @type {Vector3}
54
+ */
55
+ const scratch_point = new Vector3();
56
+
57
+ /**
58
+ * @type {Vector3}
59
+ */
60
+ const scratch_vector = new Vector3();
61
+
62
+ /**
63
+ * @type {Vector3}
64
+ */
65
+ const scratch_vector_2 = new Vector3();
66
+
67
+ /**
68
+ * @type {Quaternion}
69
+ */
70
+ const scratch_quaternion = new Quaternion();
71
+
72
+ /**
73
+ * @readonly
74
+ * @type {Transform}
75
+ */
76
+ const _tempTransform = new Transform();
77
+
78
+ /**
79
+ * The transform gizmo.
80
+ *
81
+ * **What it controls is an entity, and what it needs from a renderer is one ray.** Both of those are
82
+ * why this can be renderer-neutral at all: `Transform` is world-space by contract, so there is no
83
+ * scene graph to walk, and `viewportProjectionRay` is on both graphics engines and answers in world
84
+ * space. Everything else — which handle the pointer is on, what surface a drag is measured on, where
85
+ * the handles are drawn — is arithmetic, and lives in `handle/`.
86
+ *
87
+ * The three version answered the first two questions by building meshes and raycasting them: an
88
+ * invisible cone per arm, an invisible 100000-unit `PlaneGeometry` per drag. That is why it needed
89
+ * a three camera object on the component. It needs none now:
90
+ * the ray through the middle of the viewport starts at the eye and points where the camera looks,
91
+ * and the ray through the top edge gives the field of view the gizmo is sized against.
92
+ *
93
+ * The **drag maths is the three version's**, ported to meep `Vector3`/`Quaternion` — this is the
94
+ * feel of a tool people have used, not something to redesign. Two things did change:
95
+ *
96
+ * - the parent transform is gone. It was set to the identity on every update and multiplied through
97
+ * the whole of `pointerMove`, because `Transform` is world-space and there is no parent to
98
+ * compose with.
99
+ * - a drag no longer starts when the drag plane is edge-on to the pointer. three started one anyway,
100
+ * from whatever `pointStart` the previous drag left behind.
101
+ *
102
+ * The three gizmo's `showX`/`showY`/`showZ` are gone with the meshes they hid; nothing in the tree
103
+ * set them.
104
+ */
105
+ class TransformControls extends GizmoNode {
106
+ /**
107
+ * Entity ID that we are controlling. -1 indicates no entity
108
+ * @type {number}
109
+ */
110
+ object = -1;
111
+
112
+ isTransformControls = true;
113
+
114
+ /**
115
+ * @type {boolean}
116
+ */
117
+ enabled = true;
118
+
119
+ /**
120
+ * The handle under the pointer, or the one being dragged. One of the names in
121
+ * {@link gizmo_handles_of_mode}, or `null`.
122
+ *
123
+ * @type {string|null}
124
+ */
125
+ axis = null;
126
+
127
+ /**
128
+ * @type {string} one of {@link TransformMode}
129
+ */
130
+ mode = TransformMode.Translate;
131
+
132
+ /**
133
+ * @type {string} `'world'` or `'local'`
134
+ */
135
+ space = 'world';
136
+
137
+ /**
138
+ * How big the gizmo is drawn, as a multiple of its default screen size.
139
+ *
140
+ * @type {number}
141
+ */
142
+ size = 1;
143
+
144
+ /**
145
+ * @type {boolean}
146
+ */
147
+ dragging = false;
148
+
149
+ /**
150
+ * World units per step, or `null` for none.
151
+ *
152
+ * @type {number|null}
153
+ */
154
+ translationSnap = null;
155
+
156
+ /**
157
+ * Radians per step, or `null` for none.
158
+ *
159
+ * @type {number|null}
160
+ */
161
+ rotationSnap = null;
162
+
163
+ /**
164
+ * @type {number|null}
165
+ */
166
+ scaleSnap = null;
167
+
168
+ /**
169
+ * @type {Vector3}
170
+ */
171
+ worldPosition = new Vector3();
172
+
173
+ /**
174
+ * @type {Quaternion}
175
+ */
176
+ worldQuaternion = new Quaternion();
177
+
178
+ /**
179
+ * Where the controlled entity was when the drag started. The tool reads these to build its undo
180
+ * state, because by the time it looks the entity has already moved.
181
+ *
182
+ * @type {Vector3}
183
+ */
184
+ worldPositionStart = new Vector3();
185
+
186
+ /**
187
+ * @type {Quaternion}
188
+ */
189
+ worldQuaternionStart = new Quaternion();
190
+
191
+ /**
192
+ * @type {Vector3}
193
+ */
194
+ _worldScaleStart = new Vector3(1, 1, 1);
195
+
196
+ /**
197
+ * @type {Vector3}
198
+ */
199
+ _worldScale = new Vector3(1, 1, 1);
200
+
201
+ /**
202
+ * @type {Quaternion}
203
+ */
204
+ _worldQuaternionInv = new Quaternion();
205
+
206
+ /**
207
+ * @type {Vector3}
208
+ */
209
+ _positionStart = new Vector3();
210
+
211
+ /**
212
+ * @type {Quaternion}
213
+ */
214
+ _quaternionStart = new Quaternion();
215
+
216
+ /**
217
+ * @type {Vector3}
218
+ */
219
+ _scaleStart = new Vector3(1, 1, 1);
220
+
221
+ /**
222
+ * Where the pointer met the drag plane when the drag started, relative to the gizmo.
223
+ *
224
+ * @type {Vector3}
225
+ */
226
+ pointStart = new Vector3();
227
+
228
+ /**
229
+ * @type {Vector3}
230
+ */
231
+ pointEnd = new Vector3();
232
+
233
+ /**
234
+ * @type {Vector3}
235
+ */
236
+ _offset = new Vector3();
237
+
238
+ /**
239
+ * @type {Vector3}
240
+ */
241
+ _startNorm = new Vector3();
242
+
243
+ /**
244
+ * @type {Vector3}
245
+ */
246
+ _endNorm = new Vector3();
247
+
248
+ /**
249
+ * @type {Vector3}
250
+ */
251
+ rotationAxis = new Vector3();
252
+
253
+ /**
254
+ * @type {number}
255
+ */
256
+ rotationAngle = 0;
257
+
258
+ /**
259
+ * Where the camera is, and a unit vector from the gizmo towards it.
260
+ *
261
+ * @type {Vector3}
262
+ */
263
+ cameraPosition = new Vector3();
264
+
265
+ /**
266
+ * @type {Vector3}
267
+ */
268
+ eye = new Vector3(0, 0, 1);
269
+
270
+ /**
271
+ * The direction the camera looks along.
272
+ *
273
+ * @type {Vector3}
274
+ */
275
+ #camera_forward = new Vector3(0, 0, -1);
276
+
277
+ /**
278
+ * A ray through the top edge of the viewport, which is half a field of view away from
279
+ * {@link #camera_forward}.
280
+ *
281
+ * @type {Vector3}
282
+ */
283
+ #camera_edge = new Vector3(0, 0, -1);
284
+
285
+ /**
286
+ * The surface a drag is measured on, rebuilt every update from the current mode, axis, space and
287
+ * eye.
288
+ *
289
+ * A drag measures a delta between two points on this surface, so it would matter if the surface
290
+ * moved mid-drag — and it cannot. An arm's plane is built from the part of the eye perpendicular
291
+ * to that arm, and moving the object along the arm changes only the part parallel to it; a tile's
292
+ * is a basis vector; a free drag's and a rotation's is the view direction. Nothing a drag does to
293
+ * the object it is dragging can change any of them.
294
+ *
295
+ * @type {Vector3}
296
+ */
297
+ #plane_normal = new Vector3(0, 0, 1);
298
+
299
+ /**
300
+ * How the handles are turned: the identity in world space, the object's own rotation in local
301
+ * space and always in scale mode.
302
+ *
303
+ * @type {Quaternion}
304
+ */
305
+ #handle_rotation = new Quaternion();
306
+
307
+ /**
308
+ * How big the gizmo is in world units, one gizmo unit each.
309
+ *
310
+ * @type {number}
311
+ */
312
+ #handle_size = 1;
313
+
314
+ /**
315
+ * @type {function}
316
+ */
317
+ #draw;
318
+
319
+ /**
320
+ * @param {GraphicsEngine|GraphicsEngine} graphics the only thing a renderer is asked for is
321
+ * {@link GraphicsEngine#viewportProjectionRay} and the `preRender` signal to draw on
322
+ * @param {HTMLElement} domElement
323
+ * @param {boolean} [autoUpdate] update on a frame loop of its own, rather than being driven
324
+ */
325
+ constructor(graphics, domElement, autoUpdate = true) {
326
+ super();
327
+
328
+ assert.defined(graphics, 'graphics');
329
+ assert.defined(domElement, 'domElement');
330
+
331
+ this.graphics = graphics;
332
+ this.domElement = domElement;
333
+
334
+ this.domElement.style.touchAction = 'none'; // disable touch scroll
335
+
336
+ this.visible = false;
337
+
338
+ this._getPointer = getPointer.bind(this);
339
+ this._onPointerDown = onPointerDown.bind(this);
340
+ this._onPointerHover = onPointerHover.bind(this);
341
+ this._onPointerMove = onPointerMove.bind(this);
342
+ this._onPointerUp = onPointerUp.bind(this);
343
+
344
+ this.domElement.addEventListener('pointerdown', this._onPointerDown);
345
+ this.domElement.addEventListener('pointermove', this._onPointerHover);
346
+ this.domElement.addEventListener('pointerup', this._onPointerUp);
347
+
348
+ this.#draw = () => this.#record();
349
+
350
+ if (autoUpdate) {
351
+ const fr = new FrameRunner(this.update.bind(this));
352
+ this.on.built.add(fr.startup, fr);
353
+ this.on.destroyed.add(fr.shutdown, fr);
354
+ }
355
+ }
356
+
357
+ /**
358
+ * @param {EntityComponentDataset} ecd
359
+ */
360
+ build(ecd) {
361
+ super.build(ecd);
362
+
363
+ this.graphics.on.preRender.add(this.#draw);
364
+ }
365
+
366
+ /**
367
+ * How big one gizmo unit is in world units.
368
+ *
369
+ * The gizmo is a fixed size on screen, so its world size is the distance to it times the tangent
370
+ * of half the vertical field of view — and that tangent comes from the angle between the ray
371
+ * through the middle of the viewport and the ray through its top edge, which is the same
372
+ * measurement on either renderer and needs no camera object.
373
+ *
374
+ * A parallel projection has no such angle and would size the gizmo to nothing;
375
+ * `viewportProjectionRay` does not describe one on either engine, so nothing here branches on it.
376
+ *
377
+ * @returns {number}
378
+ */
379
+ #size_in_world() {
380
+ const cos = this.#camera_forward.dot(this.#camera_edge);
381
+
382
+ const tan = Math.sqrt(1 - cos * cos) / cos;
383
+
384
+ const distance = this.cameraPosition.distanceTo(this.worldPosition);
385
+
386
+ return distance * Math.min(1.9 * tan, SIZE_CLAMP) * this.size / 4;
387
+ }
388
+
389
+ /**
390
+ * Key transformation variables, and the drag surface, for this frame.
391
+ */
392
+ update() {
393
+ const graphics = this.graphics;
394
+
395
+ // both camera facts come out of the projection itself: the ray through the middle of the
396
+ // viewport starts at the eye and points where the camera looks
397
+ graphics.viewportProjectionRay(0, 0, this.cameraPosition, this.#camera_forward);
398
+ graphics.viewportProjectionRay(0, 1, scratch_point, this.#camera_edge);
399
+
400
+ if (this.object !== -1) {
401
+
402
+ const object_transform = this.object_transform;
403
+
404
+ this.worldPosition.copy(object_transform.position);
405
+ this.worldQuaternion.copy(object_transform.rotation);
406
+ this._worldScale.copy(object_transform.scale);
407
+
408
+ this._worldQuaternionInv.copy(this.worldQuaternion).invert();
409
+
410
+ }
411
+
412
+ this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize();
413
+
414
+ const local = this.mode === TransformMode.Scale || this.space === 'local';
415
+
416
+ if (local) {
417
+ this.#handle_rotation.copy(this.worldQuaternion);
418
+ } else {
419
+ this.#handle_rotation.set(0, 0, 0, 1);
420
+ }
421
+
422
+ this.#handle_size = this.#size_in_world();
423
+
424
+ if (this.axis !== null) {
425
+ gizmo_drag_plane_normal(
426
+ this.#plane_normal,
427
+ this.mode, this.axis, this.space,
428
+ this.worldQuaternion,
429
+ this.eye, this.#camera_forward
430
+ );
431
+ }
432
+
433
+ super.update();
434
+ }
435
+
436
+ /**
437
+ * One frame of the gizmo, onto the debug-draw pass.
438
+ */
439
+ #record() {
440
+ if (!this.visible || this.object === -1) {
441
+ return;
442
+ }
443
+
444
+ gizmo_draw(
445
+ this.mode,
446
+ this.worldPosition,
447
+ this.#handle_rotation,
448
+ this.#handle_size,
449
+ this.axis,
450
+ this.#camera_forward
451
+ );
452
+ }
453
+
454
+ /**
455
+ * The world ray under a pointer, into the module's own scratch.
456
+ *
457
+ * @param {{x:number, y:number}} pointer clip space
458
+ */
459
+ #pointer_ray(pointer) {
460
+ this.graphics.viewportProjectionRay(pointer.x, pointer.y, ray_origin, ray_direction);
461
+ }
462
+
463
+ pointerHover(pointer) {
464
+
465
+ if (this.object === -1 || this.dragging === true) return;
466
+
467
+ this.#pointer_ray(pointer);
468
+
469
+ this.axis = gizmo_pick_handle(
470
+ gizmo_handles_of_mode(this.mode),
471
+ ray_origin, ray_direction,
472
+ this.worldPosition, this.#handle_rotation, this.#handle_size
473
+ );
474
+
475
+ }
476
+
477
+ pointerDown(pointer) {
478
+
479
+ if (this.object === -1 || this.dragging === true || pointer.button !== 0) return;
480
+
481
+ if (this.axis === null) return;
482
+
483
+ const ot = this.object_transform;
484
+
485
+ this.#pointer_ray(pointer);
486
+
487
+ gizmo_drag_plane_normal(
488
+ this.#plane_normal,
489
+ this.mode, this.axis, this.space,
490
+ ot.rotation,
491
+ this.eye, this.#camera_forward
492
+ );
493
+
494
+ if (!gizmo_ray_plane_point(
495
+ scratch_point, ray_origin, ray_direction, ot.position, this.#plane_normal
496
+ )) {
497
+ // the drag surface is edge-on to the pointer, so there is no point on it to drag from
498
+ return;
499
+ }
500
+
501
+ this._positionStart.copy(ot.position);
502
+ this._quaternionStart.copy(ot.rotation);
503
+ this._scaleStart.copy(ot.scale);
504
+
505
+ this.worldPositionStart.copy(ot.position);
506
+ this.worldQuaternionStart.copy(ot.rotation);
507
+ this._worldScaleStart.copy(ot.scale);
508
+
509
+ this.pointStart.copy(scratch_point).sub(this.worldPositionStart);
510
+
511
+ this.dragging = true;
512
+
513
+ _mouseDownEvent.mode = this.mode;
514
+ this.dispatchEvent(_mouseDownEvent);
515
+
516
+ }
517
+
518
+ /**
519
+ *
520
+ * @param {{type:string}} event
521
+ */
522
+ dispatchEvent(event) {
523
+ this.entity.sendEvent(event.type, event);
524
+ }
525
+
526
+ pointerMove(pointer) {
527
+
528
+ const axis = this.axis;
529
+ const mode = this.mode;
530
+ const object = this.object;
531
+
532
+ let space = this.space;
533
+
534
+ if (mode === TransformMode.Scale) {
535
+
536
+ space = 'local';
537
+
538
+ } else if (axis === 'E' || axis === 'XYZE' || axis === 'XYZ') {
539
+
540
+ space = 'world';
541
+
542
+ }
543
+
544
+ if (object === -1 || axis === null || this.dragging === false || pointer.button !== -1) return;
545
+
546
+ const object_transform = this.object_transform;
547
+
548
+ this.#pointer_ray(pointer);
549
+
550
+ if (!gizmo_ray_plane_point(
551
+ scratch_point, ray_origin, ray_direction, this.worldPositionStart, this.#plane_normal
552
+ )) {
553
+ return;
554
+ }
555
+
556
+ this.pointEnd.copy(scratch_point).sub(this.worldPositionStart);
557
+
558
+ if (mode === TransformMode.Translate) {
559
+
560
+ // Apply translate
561
+
562
+ this._offset.copy(this.pointEnd).sub(this.pointStart);
563
+
564
+ if (space === 'local' && axis !== 'XYZ') {
565
+
566
+ this._offset.applyQuaternion(this._worldQuaternionInv);
567
+
568
+ }
569
+
570
+ if (axis.indexOf('X') === -1) this._offset.x = 0;
571
+ if (axis.indexOf('Y') === -1) this._offset.y = 0;
572
+ if (axis.indexOf('Z') === -1) this._offset.z = 0;
573
+
574
+ if (space === 'local' && axis !== 'XYZ') {
575
+
576
+ this._offset.applyQuaternion(this._quaternionStart);
577
+
578
+ }
579
+
580
+ _tempTransform.position.copy(this._offset);
581
+ _tempTransform.position.add(this._positionStart);
582
+
583
+ // Apply translation snap; snapping operates on the candidate position — the
584
+ // controlled object is an entity id, Transforms are world-space by contract
585
+ if (this.translationSnap) {
586
+
587
+ if (space === 'local') {
588
+
589
+ _tempTransform.position.applyQuaternion(
590
+ scratch_quaternion.copy(this._quaternionStart).invert()
591
+ );
592
+
593
+ }
594
+
595
+ if (axis.search('X') !== -1) {
596
+
597
+ _tempTransform.position.setX(Math.round(_tempTransform.position.x / this.translationSnap) * this.translationSnap);
598
+
599
+ }
600
+
601
+ if (axis.search('Y') !== -1) {
602
+
603
+ _tempTransform.position.setY(Math.round(_tempTransform.position.y / this.translationSnap) * this.translationSnap);
604
+
605
+ }
606
+
607
+ if (axis.search('Z') !== -1) {
608
+
609
+ _tempTransform.position.setZ(Math.round(_tempTransform.position.z / this.translationSnap) * this.translationSnap);
610
+
611
+ }
612
+
613
+ if (space === 'local') {
614
+
615
+ _tempTransform.position.applyQuaternion(this._quaternionStart);
616
+
617
+ }
618
+
619
+ }
620
+
621
+ // write
622
+ object_transform.position.copy(_tempTransform.position);
623
+
624
+ } else if (mode === TransformMode.Scale) {
625
+
626
+ if (axis.search('XYZ') !== -1) {
627
+
628
+ let d = this.pointEnd.length() / this.pointStart.length();
629
+
630
+ if (this.pointEnd.dot(this.pointStart) < 0) d *= -1;
631
+
632
+ scratch_vector_2.set(d, d, d);
633
+
634
+ } else {
635
+
636
+ scratch_vector.copy(this.pointStart);
637
+ scratch_vector_2.copy(this.pointEnd);
638
+
639
+ scratch_vector.applyQuaternion(this._worldQuaternionInv);
640
+ scratch_vector_2.applyQuaternion(this._worldQuaternionInv);
641
+
642
+ scratch_vector_2.divide(scratch_vector);
643
+
644
+ if (axis.search('X') === -1) {
645
+
646
+ scratch_vector_2.x = 1;
647
+
648
+ }
649
+
650
+ if (axis.search('Y') === -1) {
651
+
652
+ scratch_vector_2.y = 1;
653
+
654
+ }
655
+
656
+ if (axis.search('Z') === -1) {
657
+
658
+ scratch_vector_2.z = 1;
659
+
660
+ }
661
+
662
+ }
663
+
664
+ // Apply scale
665
+
666
+ _tempTransform.scale.copy(this._scaleStart);
667
+ _tempTransform.scale.multiply(scratch_vector_2);
668
+
669
+ if (this.scaleSnap) {
670
+
671
+ if (axis.search('X') !== -1) {
672
+
673
+ _tempTransform.scale.setX(Math.round(_tempTransform.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap);
674
+
675
+ }
676
+
677
+ if (axis.search('Y') !== -1) {
678
+
679
+ _tempTransform.scale.setY(Math.round(_tempTransform.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap);
680
+
681
+ }
682
+
683
+ if (axis.search('Z') !== -1) {
684
+
685
+ _tempTransform.scale.setZ(Math.round(_tempTransform.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap);
686
+
687
+ }
688
+
689
+ }
690
+
691
+ object_transform.scale.copy(_tempTransform.scale);
692
+
693
+ } else if (mode === TransformMode.Rotate) {
694
+
695
+ this._offset.copy(this.pointEnd).sub(this.pointStart);
696
+
697
+ const speed = ROTATION_SPEED / this.worldPosition.distanceTo(this.cameraPosition);
698
+
699
+ if (axis === 'E') {
700
+
701
+ this.rotationAxis.copy(this.eye);
702
+ this.rotationAngle = this.pointEnd.angleTo(this.pointStart);
703
+
704
+ this._startNorm.copy(this.pointStart).normalize();
705
+ this._endNorm.copy(this.pointEnd).normalize();
706
+
707
+ this.rotationAngle *= (this._endNorm.cross(this._startNorm).dot(this.eye) < 0 ? 1 : -1);
708
+
709
+ } else if (axis === 'XYZE') {
710
+
711
+ this.rotationAxis.copy(this._offset).cross(this.eye).normalize();
712
+ this.rotationAngle = this._offset.dot(scratch_vector.copy(this.rotationAxis).cross(this.eye)) * speed;
713
+
714
+ } else if (axis === 'X' || axis === 'Y' || axis === 'Z') {
715
+
716
+ this.rotationAxis.copy(UNIT[axis]);
717
+
718
+ scratch_vector.copy(UNIT[axis]);
719
+
720
+ if (space === 'local') {
721
+
722
+ scratch_vector.applyQuaternion(this.worldQuaternion);
723
+
724
+ }
725
+
726
+ this.rotationAngle = this._offset.dot(scratch_vector.cross(this.eye).normalize()) * speed;
727
+
728
+ }
729
+
730
+ // Apply rotation snap
731
+
732
+ if (this.rotationSnap) this.rotationAngle = Math.round(this.rotationAngle / this.rotationSnap) * this.rotationSnap;
733
+
734
+ // Apply rotate
735
+ if (space === 'local' && axis !== 'E' && axis !== 'XYZE') {
736
+
737
+ _tempTransform.rotation.copy(this._quaternionStart);
738
+ _tempTransform.rotation.multiply(
739
+ scratch_quaternion.fromAxisAngle(this.rotationAxis, this.rotationAngle)
740
+ ).normalize();
741
+
742
+ } else {
743
+
744
+ _tempTransform.rotation.copy(
745
+ scratch_quaternion.fromAxisAngle(this.rotationAxis, this.rotationAngle)
746
+ );
747
+ _tempTransform.rotation.multiply(this._quaternionStart);
748
+ _tempTransform.rotation.normalize();
749
+
750
+ }
751
+
752
+ object_transform.rotation.copy(_tempTransform.rotation);
753
+ }
754
+
755
+ this.dispatchEvent(_changeEvent);
756
+ this.dispatchEvent(_objectChangeEvent);
757
+
758
+ }
759
+
760
+ pointerUp(pointer) {
761
+
762
+ if (pointer.button !== 0) return;
763
+
764
+ if (this.dragging && (this.axis !== null)) {
765
+
766
+ _mouseUpEvent.mode = this.mode;
767
+ this.dispatchEvent(_mouseUpEvent);
768
+
769
+ }
770
+
771
+ this.dragging = false;
772
+ this.axis = null;
773
+
774
+ }
775
+
776
+ dispose() {
777
+
778
+ this.domElement.removeEventListener('pointerdown', this._onPointerDown);
779
+ this.domElement.removeEventListener('pointermove', this._onPointerHover);
780
+ this.domElement.removeEventListener('pointermove', this._onPointerMove);
781
+ this.domElement.removeEventListener('pointerup', this._onPointerUp);
782
+
783
+ this.graphics.on.preRender.remove(this.#draw);
784
+
785
+ }
786
+
787
+ /**
788
+ * Set current object
789
+ * @param {number} entity
790
+ * @returns {TransformControls}
791
+ */
792
+ attach(entity) {
793
+ assert.isNonNegativeInteger(entity, 'entity');
794
+
795
+ this.object = entity;
796
+
797
+ this.visible = true;
798
+
799
+ return this;
800
+
801
+ }
802
+
803
+ /**
804
+ *
805
+ * @returns {Transform|undefined}
806
+ */
807
+ get object_transform() {
808
+ const ecd = this.entity.dataset;
809
+
810
+ return ecd.getComponent(this.object, Transform);
811
+ }
812
+
813
+ // Detatch from object
814
+ detach() {
815
+
816
+ this.object = -1;
817
+
818
+ this.visible = false;
819
+ this.axis = null;
820
+
821
+ // a drag in flight has no target anymore
822
+ this.dragging = false;
823
+
824
+ return this;
825
+
826
+ }
827
+
828
+ reset() {
829
+
830
+ if (!this.enabled) return;
831
+
832
+ if (this.dragging) {
833
+
834
+ this.object_transform.position.copy(this._positionStart);
835
+ this.object_transform.rotation.copy(this._quaternionStart);
836
+ this.object_transform.scale.copy(this._scaleStart);
837
+
838
+ this.dispatchEvent(_changeEvent);
839
+ this.dispatchEvent(_objectChangeEvent);
840
+
841
+ this.pointStart.copy(this.pointEnd);
842
+
843
+ }
844
+
845
+ }
846
+
847
+ // TODO: deprecate
848
+
849
+ getMode() {
850
+
851
+ return this.mode;
852
+
853
+ }
854
+
855
+ setMode(mode) {
856
+
857
+ this.mode = mode;
858
+
859
+ }
860
+
861
+ setTranslationSnap(translationSnap) {
862
+
863
+ this.translationSnap = translationSnap;
864
+
865
+ }
866
+
867
+ setRotationSnap(rotationSnap) {
868
+
869
+ this.rotationSnap = rotationSnap;
870
+
871
+ }
872
+
873
+ setScaleSnap(scaleSnap) {
874
+
875
+ this.scaleSnap = scaleSnap;
876
+
877
+ }
878
+
879
+ setSize(size) {
880
+
881
+ this.size = size;
882
+
883
+ }
884
+
885
+ setSpace(space) {
886
+
887
+ this.space = space;
888
+
889
+ }
890
+
891
+ }
892
+
893
+ // mouse / touch event handlers
894
+
895
+ function getPointer(event) {
896
+
897
+ if (this.domElement.ownerDocument.pointerLockElement) {
898
+
899
+ return {
900
+ x: 0,
901
+ y: 0,
902
+ button: event.button
903
+ };
904
+
905
+ } else {
906
+
907
+ const rect = this.domElement.getBoundingClientRect();
908
+
909
+ return {
910
+ x: (event.clientX - rect.left) / rect.width * 2 - 1,
911
+ y: -(event.clientY - rect.top) / rect.height * 2 + 1,
912
+ button: event.button
913
+ };
914
+
915
+ }
916
+
917
+ }
918
+
919
+ function onPointerHover(event) {
920
+
921
+ if (!this.enabled) return;
922
+
923
+ switch (event.pointerType) {
924
+
925
+ case 'mouse':
926
+ case 'pen':
927
+ this.pointerHover(this._getPointer(event));
928
+ break;
929
+
930
+ }
931
+
932
+ }
933
+
934
+ function onPointerDown(event) {
935
+
936
+ if (!this.enabled) return;
937
+
938
+ if (!document.pointerLockElement) {
939
+
940
+ this.domElement.setPointerCapture(event.pointerId);
941
+
942
+ }
943
+
944
+ this.domElement.addEventListener('pointermove', this._onPointerMove);
945
+
946
+ this.pointerHover(this._getPointer(event));
947
+ this.pointerDown(this._getPointer(event));
948
+
949
+ }
950
+
951
+ function onPointerMove(event) {
952
+
953
+ if (!this.enabled) return;
954
+
955
+ this.pointerMove(this._getPointer(event));
956
+
957
+ }
958
+
959
+ function onPointerUp(event) {
960
+
961
+ if (!this.enabled) return;
962
+
963
+ this.domElement.releasePointerCapture(event.pointerId);
964
+
965
+ this.domElement.removeEventListener('pointermove', this._onPointerMove);
966
+
967
+ this.pointerUp(this._getPointer(event));
968
+
969
+ }
970
+
971
+ export { TransformControls };