@zephyr3d/scene 0.9.1 → 0.9.3

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 (522) hide show
  1. package/dist/animation/animationset.js +2 -0
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/cloth/gpu_cloth_system.js +9 -1
  4. package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
  5. package/dist/animation/fixed_geometry_cache_track.js +5 -1
  6. package/dist/animation/fixed_geometry_cache_track.js.map +1 -1
  7. package/dist/animation/geometry_cache_utils.js +20 -4
  8. package/dist/animation/geometry_cache_utils.js.map +1 -1
  9. package/dist/animation/ik/ik_angle_constraint.js +2 -6
  10. package/dist/animation/ik/ik_angle_constraint.js.map +1 -1
  11. package/dist/animation/ik/ik_chain_builder.js +68 -0
  12. package/dist/animation/ik/ik_chain_builder.js.map +1 -0
  13. package/dist/animation/ik/ik_pole_constraint.js +2 -7
  14. package/dist/animation/ik/ik_pole_constraint.js.map +1 -1
  15. package/dist/animation/ik/two_bone_ik_solver.js +2 -6
  16. package/dist/animation/ik/two_bone_ik_solver.js.map +1 -1
  17. package/dist/animation/joint_dynamics/collision.js +60 -12
  18. package/dist/animation/joint_dynamics/collision.js.map +1 -1
  19. package/dist/animation/joint_dynamics/constraints.js +20 -4
  20. package/dist/animation/joint_dynamics/constraints.js.map +1 -1
  21. package/dist/animation/joint_dynamics/controller.js +94 -46
  22. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  23. package/dist/animation/joint_dynamics/math.js +16 -0
  24. package/dist/animation/joint_dynamics/math.js.map +1 -0
  25. package/dist/animation/joint_dynamics/solver.js +21 -11
  26. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  27. package/dist/animation/joint_dynamics/types.js +15 -3
  28. package/dist/animation/joint_dynamics/types.js.map +1 -1
  29. package/dist/animation/pca_geometry_cache_track.js +5 -1
  30. package/dist/animation/pca_geometry_cache_track.js.map +1 -1
  31. package/dist/animation/skeleton.js +2 -2
  32. package/dist/animation/skeleton.js.map +1 -1
  33. package/dist/animation/skeleton_modifier.js +2 -6
  34. package/dist/animation/skeleton_modifier.js.map +1 -1
  35. package/dist/animation/spring/spring_particle.js +4 -4
  36. package/dist/animation/spring/spring_particle.js.map +1 -1
  37. package/dist/animation/spring/spring_system.js +13 -40
  38. package/dist/animation/spring/spring_system.js.map +1 -1
  39. package/dist/animation/spring2/constraints.js.map +1 -1
  40. package/dist/animation/spring2/controller.js +64 -64
  41. package/dist/animation/spring2/controller.js.map +1 -1
  42. package/dist/animation/spring2/math.js.map +1 -1
  43. package/dist/animation/spring2/spring_system.js +8 -8
  44. package/dist/animation/spring2/spring_system.js.map +1 -1
  45. package/dist/app/app.js.map +1 -1
  46. package/dist/app/engine.js +1 -1
  47. package/dist/app/engine.js.map +1 -1
  48. package/dist/app/screen.js +4 -4
  49. package/dist/app/screen.js.map +1 -1
  50. package/dist/app/scriptingsystem.js +24 -1
  51. package/dist/app/scriptingsystem.js.map +1 -1
  52. package/dist/app/scriptregistry.js +22 -1
  53. package/dist/app/scriptregistry.js.map +1 -1
  54. package/dist/asset/assetmanager.js +2 -2
  55. package/dist/asset/assetmanager.js.map +1 -1
  56. package/dist/asset/model.js +60 -60
  57. package/dist/asset/model.js.map +1 -1
  58. package/dist/camera/camera.js +1 -1
  59. package/dist/camera/camera.js.map +1 -1
  60. package/dist/camera/orbit.js.map +1 -1
  61. package/dist/index.d.ts +795 -266
  62. package/dist/index.js +3 -2
  63. package/dist/index.js.map +1 -1
  64. package/dist/material/material.js +3 -1
  65. package/dist/material/material.js.map +1 -1
  66. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  67. package/dist/material/shader/helper.js +281 -278
  68. package/dist/material/shader/helper.js.map +1 -1
  69. package/dist/material/sprite.js +6 -6
  70. package/dist/material/sprite.js.map +1 -1
  71. package/dist/material/terrain-cm.js +2 -2
  72. package/dist/material/terrain-cm.js.map +1 -1
  73. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  74. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  75. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  76. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  77. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  78. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  79. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  80. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  81. package/dist/posteffect/taa.js +31 -39
  82. package/dist/posteffect/taa.js.map +1 -1
  83. package/dist/render/cluster_light.js +3 -4
  84. package/dist/render/cluster_light.js.map +1 -1
  85. package/dist/render/drawable.js +5 -1
  86. package/dist/render/drawable.js.map +1 -1
  87. package/dist/render/rendergraph/device_pool_allocator.js +29 -3
  88. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  89. package/dist/render/rendergraph/executor.js +283 -33
  90. package/dist/render/rendergraph/executor.js.map +1 -1
  91. package/dist/render/rendergraph/forward_plus_builder.js +338 -108
  92. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  93. package/dist/render/rendergraph/history_resource_manager.js +195 -115
  94. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  95. package/dist/render/rendergraph/history_resources.js +10 -0
  96. package/dist/render/rendergraph/history_resources.js.map +1 -0
  97. package/dist/render/rendergraph/rendergraph.js +162 -35
  98. package/dist/render/rendergraph/rendergraph.js.map +1 -1
  99. package/dist/render/rendergraph/types.js +25 -5
  100. package/dist/render/rendergraph/types.js.map +1 -1
  101. package/dist/render/rendertarget.js +5 -1
  102. package/dist/render/rendertarget.js.map +1 -1
  103. package/dist/render/screenrendertarget.js +5 -1
  104. package/dist/render/screenrendertarget.js.map +1 -1
  105. package/dist/render/sky.js +4 -4
  106. package/dist/render/sky.js.map +1 -1
  107. package/dist/scene/basesprite.js +2 -2
  108. package/dist/scene/basesprite.js.map +1 -1
  109. package/dist/scene/graph_node.js +1 -1
  110. package/dist/scene/graph_node.js.map +1 -1
  111. package/dist/scene/mesh.js +81 -97
  112. package/dist/scene/mesh.js.map +1 -1
  113. package/dist/scene/particlesys.js +1 -1
  114. package/dist/scene/particlesys.js.map +1 -1
  115. package/dist/scene/scene_node.js +228 -228
  116. package/dist/scene/scene_node.js.map +1 -1
  117. package/dist/scene/script_attachment.js +15 -3
  118. package/dist/scene/script_attachment.js.map +1 -1
  119. package/dist/scene/terrain-cm/terrain-cm.js +3 -3
  120. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  121. package/dist/shadow/shadowmapper.js.map +1 -1
  122. package/dist/shapes/box.js +1 -1
  123. package/dist/shapes/box.js.map +1 -1
  124. package/dist/shapes/capsule.js +0 -3
  125. package/dist/shapes/capsule.js.map +1 -1
  126. package/dist/shapes/cylinder.js +0 -3
  127. package/dist/shapes/cylinder.js.map +1 -1
  128. package/dist/shapes/plane.js +0 -3
  129. package/dist/shapes/plane.js.map +1 -1
  130. package/dist/shapes/tetrahedron.js +3 -9
  131. package/dist/shapes/tetrahedron.js.map +1 -1
  132. package/dist/shapes/torus.js +94 -66
  133. package/dist/shapes/torus.js.map +1 -1
  134. package/dist/src/animation/animation.js +127 -0
  135. package/dist/src/animation/animation.js.map +1 -0
  136. package/dist/src/animation/animationset.js +255 -0
  137. package/dist/src/animation/animationset.js.map +1 -0
  138. package/dist/src/animation/animationtrack.js +34 -0
  139. package/dist/src/animation/animationtrack.js.map +1 -0
  140. package/dist/src/animation/eulerrotationtrack.js +52 -0
  141. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  142. package/dist/src/animation/morphtarget.js +93 -0
  143. package/dist/src/animation/morphtarget.js.map +1 -0
  144. package/dist/src/animation/morphtrack.js +70 -0
  145. package/dist/src/animation/morphtrack.js.map +1 -0
  146. package/dist/src/animation/proptrack.js +161 -0
  147. package/dist/src/animation/proptrack.js.map +1 -0
  148. package/dist/src/animation/rotationtrack.js +51 -0
  149. package/dist/src/animation/rotationtrack.js.map +1 -0
  150. package/dist/src/animation/scaletrack.js +50 -0
  151. package/dist/src/animation/scaletrack.js.map +1 -0
  152. package/dist/src/animation/skeleton.js +204 -0
  153. package/dist/src/animation/skeleton.js.map +1 -0
  154. package/dist/src/animation/translationtrack.js +50 -0
  155. package/dist/src/animation/translationtrack.js.map +1 -0
  156. package/dist/src/app/app.js +129 -0
  157. package/dist/src/app/app.js.map +1 -0
  158. package/dist/src/app/inputmgr.js +267 -0
  159. package/dist/src/app/inputmgr.js.map +1 -0
  160. package/dist/src/asset/assetmanager.js +404 -0
  161. package/dist/src/asset/assetmanager.js.map +1 -0
  162. package/dist/src/asset/builtin.js +337 -0
  163. package/dist/src/asset/builtin.js.map +1 -0
  164. package/dist/src/asset/loaders/dds/dds.js +470 -0
  165. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  166. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  167. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  168. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  169. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  170. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  171. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  172. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  173. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  174. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  175. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  176. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  177. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  178. package/dist/src/asset/loaders/loader.js +45 -0
  179. package/dist/src/asset/loaders/loader.js.map +1 -0
  180. package/dist/src/asset/model.js +414 -0
  181. package/dist/src/asset/model.js.map +1 -0
  182. package/dist/src/blitter/bilateralblur.js +221 -0
  183. package/dist/src/blitter/bilateralblur.js.map +1 -0
  184. package/dist/src/blitter/blitter.js +390 -0
  185. package/dist/src/blitter/blitter.js.map +1 -0
  186. package/dist/src/blitter/box.js +118 -0
  187. package/dist/src/blitter/box.js.map +1 -0
  188. package/dist/src/blitter/copy.js +22 -0
  189. package/dist/src/blitter/copy.js.map +1 -0
  190. package/dist/src/blitter/gaussianblur.js +228 -0
  191. package/dist/src/blitter/gaussianblur.js.map +1 -0
  192. package/dist/src/camera/base.js +92 -0
  193. package/dist/src/camera/base.js.map +1 -0
  194. package/dist/src/camera/camera.js +1005 -0
  195. package/dist/src/camera/camera.js.map +1 -0
  196. package/dist/src/camera/fps.js +238 -0
  197. package/dist/src/camera/fps.js.map +1 -0
  198. package/dist/src/camera/orbit.js +245 -0
  199. package/dist/src/camera/orbit.js.map +1 -0
  200. package/dist/src/camera/orthocamera.js +167 -0
  201. package/dist/src/camera/orthocamera.js.map +1 -0
  202. package/dist/src/camera/perspectivecamera.js +141 -0
  203. package/dist/src/camera/perspectivecamera.js.map +1 -0
  204. package/dist/src/index.js +120 -0
  205. package/dist/src/index.js.map +1 -0
  206. package/dist/src/material/blinn.js +81 -0
  207. package/dist/src/material/blinn.js.map +1 -0
  208. package/dist/src/material/grassmaterial.js +113 -0
  209. package/dist/src/material/grassmaterial.js.map +1 -0
  210. package/dist/src/material/lambert.js +92 -0
  211. package/dist/src/material/lambert.js.map +1 -0
  212. package/dist/src/material/material.js +301 -0
  213. package/dist/src/material/material.js.map +1 -0
  214. package/dist/src/material/meshmaterial.js +704 -0
  215. package/dist/src/material/meshmaterial.js.map +1 -0
  216. package/dist/src/material/mixins/albedocolor.js +76 -0
  217. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  218. package/dist/src/material/mixins/foliage.js +47 -0
  219. package/dist/src/material/mixins/foliage.js.map +1 -0
  220. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  221. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  222. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  223. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  224. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  225. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  226. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  227. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  228. package/dist/src/material/mixins/lit.js +476 -0
  229. package/dist/src/material/mixins/lit.js.map +1 -0
  230. package/dist/src/material/mixins/pbr/common.js +918 -0
  231. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  232. package/dist/src/material/mixins/texture.js +172 -0
  233. package/dist/src/material/mixins/texture.js.map +1 -0
  234. package/dist/src/material/mixins/vertexcolor.js +56 -0
  235. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  236. package/dist/src/material/particle.js +178 -0
  237. package/dist/src/material/particle.js.map +1 -0
  238. package/dist/src/material/pbrmr.js +97 -0
  239. package/dist/src/material/pbrmr.js.map +1 -0
  240. package/dist/src/material/pbrsg.js +97 -0
  241. package/dist/src/material/pbrsg.js.map +1 -0
  242. package/dist/src/material/shader/helper.js +1209 -0
  243. package/dist/src/material/shader/helper.js.map +1 -0
  244. package/dist/src/material/terrain-cm.js +606 -0
  245. package/dist/src/material/terrain-cm.js.map +1 -0
  246. package/dist/src/material/terrainmaterial.js +375 -0
  247. package/dist/src/material/terrainmaterial.js.map +1 -0
  248. package/dist/src/material/unlit.js +41 -0
  249. package/dist/src/material/unlit.js.map +1 -0
  250. package/dist/src/material/water.js +417 -0
  251. package/dist/src/material/water.js.map +1 -0
  252. package/dist/src/posteffect/bloom.js +361 -0
  253. package/dist/src/posteffect/bloom.js.map +1 -0
  254. package/dist/src/posteffect/compositor.js +226 -0
  255. package/dist/src/posteffect/compositor.js.map +1 -0
  256. package/dist/src/posteffect/fxaa.js +273 -0
  257. package/dist/src/posteffect/fxaa.js.map +1 -0
  258. package/dist/src/posteffect/grayscale.js +69 -0
  259. package/dist/src/posteffect/grayscale.js.map +1 -0
  260. package/dist/src/posteffect/motionblur.js +96 -0
  261. package/dist/src/posteffect/motionblur.js.map +1 -0
  262. package/dist/src/posteffect/posteffect.js +126 -0
  263. package/dist/src/posteffect/posteffect.js.map +1 -0
  264. package/dist/src/posteffect/sao.js +324 -0
  265. package/dist/src/posteffect/sao.js.map +1 -0
  266. package/dist/src/posteffect/ssr.js +489 -0
  267. package/dist/src/posteffect/ssr.js.map +1 -0
  268. package/dist/src/posteffect/taa.js +172 -0
  269. package/dist/src/posteffect/taa.js.map +1 -0
  270. package/dist/src/posteffect/tonemap.js +94 -0
  271. package/dist/src/posteffect/tonemap.js.map +1 -0
  272. package/dist/src/render/abuffer_oit.js +361 -0
  273. package/dist/src/render/abuffer_oit.js.map +1 -0
  274. package/dist/src/render/clipmap.js +851 -0
  275. package/dist/src/render/clipmap.js.map +1 -0
  276. package/dist/src/render/cluster_light.js +333 -0
  277. package/dist/src/render/cluster_light.js.map +1 -0
  278. package/dist/src/render/cull_visitor.js +187 -0
  279. package/dist/src/render/cull_visitor.js.map +1 -0
  280. package/dist/src/render/depthpass.js +68 -0
  281. package/dist/src/render/depthpass.js.map +1 -0
  282. package/dist/src/render/drawable_mixin.js +227 -0
  283. package/dist/src/render/drawable_mixin.js.map +1 -0
  284. package/dist/src/render/envlight.js +463 -0
  285. package/dist/src/render/envlight.js.map +1 -0
  286. package/dist/src/render/fbm_wavegenerator.js +251 -0
  287. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  288. package/dist/src/render/fft_wavegenerator.js +1006 -0
  289. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  290. package/dist/src/render/fullscreenquad.js +38 -0
  291. package/dist/src/render/fullscreenquad.js.map +1 -0
  292. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  293. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  294. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  295. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  296. package/dist/src/render/hzb.js +273 -0
  297. package/dist/src/render/hzb.js.map +1 -0
  298. package/dist/src/render/lightpass.js +172 -0
  299. package/dist/src/render/lightpass.js.map +1 -0
  300. package/dist/src/render/objectcolorpass.js +51 -0
  301. package/dist/src/render/objectcolorpass.js.map +1 -0
  302. package/dist/src/render/primitive.js +364 -0
  303. package/dist/src/render/primitive.js.map +1 -0
  304. package/dist/src/render/render_queue.js +467 -0
  305. package/dist/src/render/render_queue.js.map +1 -0
  306. package/dist/src/render/renderbundle_wrapper.js +152 -0
  307. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  308. package/dist/src/render/renderer.js +455 -0
  309. package/dist/src/render/renderer.js.map +1 -0
  310. package/dist/src/render/renderpass.js +200 -0
  311. package/dist/src/render/renderpass.js.map +1 -0
  312. package/dist/src/render/shadowmap_pass.js +56 -0
  313. package/dist/src/render/shadowmap_pass.js.map +1 -0
  314. package/dist/src/render/sky.js +1103 -0
  315. package/dist/src/render/sky.js.map +1 -0
  316. package/dist/src/render/weightedblended_oit.js +168 -0
  317. package/dist/src/render/weightedblended_oit.js.map +1 -0
  318. package/dist/src/scene/batchgroup.js +162 -0
  319. package/dist/src/scene/batchgroup.js.map +1 -0
  320. package/dist/src/scene/environment.js +209 -0
  321. package/dist/src/scene/environment.js.map +1 -0
  322. package/dist/src/scene/graph_node.js +72 -0
  323. package/dist/src/scene/graph_node.js.map +1 -0
  324. package/dist/src/scene/light.js +416 -0
  325. package/dist/src/scene/light.js.map +1 -0
  326. package/dist/src/scene/mesh.js +341 -0
  327. package/dist/src/scene/mesh.js.map +1 -0
  328. package/dist/src/scene/octree.js +649 -0
  329. package/dist/src/scene/octree.js.map +1 -0
  330. package/dist/src/scene/particlesys.js +738 -0
  331. package/dist/src/scene/particlesys.js.map +1 -0
  332. package/dist/src/scene/raycast_visitor.js +103 -0
  333. package/dist/src/scene/raycast_visitor.js.map +1 -0
  334. package/dist/src/scene/scene.js +284 -0
  335. package/dist/src/scene/scene.js.map +1 -0
  336. package/dist/src/scene/scene_node.js +732 -0
  337. package/dist/src/scene/scene_node.js.map +1 -0
  338. package/dist/src/scene/terrain/grass.js +278 -0
  339. package/dist/src/scene/terrain/grass.js.map +1 -0
  340. package/dist/src/scene/terrain/heightfield.js +475 -0
  341. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  342. package/dist/src/scene/terrain/patch.js +530 -0
  343. package/dist/src/scene/terrain/patch.js.map +1 -0
  344. package/dist/src/scene/terrain/quadtree.js +461 -0
  345. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  346. package/dist/src/scene/terrain/terrain.js +246 -0
  347. package/dist/src/scene/terrain/terrain.js.map +1 -0
  348. package/dist/src/scene/terrain-cm/grass.js +594 -0
  349. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  350. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  351. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  352. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  353. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  354. package/dist/src/scene/water.js +374 -0
  355. package/dist/src/scene/water.js.map +1 -0
  356. package/dist/src/shaders/atmosphere.js +957 -0
  357. package/dist/src/shaders/atmosphere.js.map +1 -0
  358. package/dist/src/shaders/fog.js +112 -0
  359. package/dist/src/shaders/fog.js.map +1 -0
  360. package/dist/src/shaders/misc.js +266 -0
  361. package/dist/src/shaders/misc.js.map +1 -0
  362. package/dist/src/shaders/noise.js +222 -0
  363. package/dist/src/shaders/noise.js.map +1 -0
  364. package/dist/src/shaders/pbr.js +51 -0
  365. package/dist/src/shaders/pbr.js.map +1 -0
  366. package/dist/src/shaders/shadow.js +636 -0
  367. package/dist/src/shaders/shadow.js.map +1 -0
  368. package/dist/src/shaders/ssr.js +490 -0
  369. package/dist/src/shaders/ssr.js.map +1 -0
  370. package/dist/src/shaders/temporal.js +215 -0
  371. package/dist/src/shaders/temporal.js.map +1 -0
  372. package/dist/src/shaders/water.js +756 -0
  373. package/dist/src/shaders/water.js.map +1 -0
  374. package/dist/src/shadow/esm.js +237 -0
  375. package/dist/src/shadow/esm.js.map +1 -0
  376. package/dist/src/shadow/pcf_opt.js +181 -0
  377. package/dist/src/shadow/pcf_opt.js.map +1 -0
  378. package/dist/src/shadow/pcf_pd.js +189 -0
  379. package/dist/src/shadow/pcf_pd.js.map +1 -0
  380. package/dist/src/shadow/shader.js +37 -0
  381. package/dist/src/shadow/shader.js.map +1 -0
  382. package/dist/src/shadow/shadow_impl.js +15 -0
  383. package/dist/src/shadow/shadow_impl.js.map +1 -0
  384. package/dist/src/shadow/shadowmapper.js +790 -0
  385. package/dist/src/shadow/shadowmapper.js.map +1 -0
  386. package/dist/src/shadow/ssm.js +159 -0
  387. package/dist/src/shadow/ssm.js.map +1 -0
  388. package/dist/src/shadow/vsm.js +297 -0
  389. package/dist/src/shadow/vsm.js.map +1 -0
  390. package/dist/src/shapes/box.js +386 -0
  391. package/dist/src/shapes/box.js.map +1 -0
  392. package/dist/src/shapes/cylinder.js +125 -0
  393. package/dist/src/shapes/cylinder.js.map +1 -0
  394. package/dist/src/shapes/plane.js +88 -0
  395. package/dist/src/shapes/plane.js.map +1 -0
  396. package/dist/src/shapes/shape.js +87 -0
  397. package/dist/src/shapes/shape.js.map +1 -0
  398. package/dist/src/shapes/sphere.js +114 -0
  399. package/dist/src/shapes/sphere.js.map +1 -0
  400. package/dist/src/shapes/tetrahedron.js +188 -0
  401. package/dist/src/shapes/tetrahedron.js.map +1 -0
  402. package/dist/src/shapes/torus.js +111 -0
  403. package/dist/src/shapes/torus.js.map +1 -0
  404. package/dist/src/utility/aabbtree.js +400 -0
  405. package/dist/src/utility/aabbtree.js.map +1 -0
  406. package/dist/src/utility/bounding_volume.js +29 -0
  407. package/dist/src/utility/bounding_volume.js.map +1 -0
  408. package/dist/src/utility/debug.js +28 -0
  409. package/dist/src/utility/debug.js.map +1 -0
  410. package/dist/src/utility/draco/decoder.js +116 -0
  411. package/dist/src/utility/draco/decoder.js.map +1 -0
  412. package/dist/src/utility/misc.js +105 -0
  413. package/dist/src/utility/misc.js.map +1 -0
  414. package/dist/src/utility/panorama.js +163 -0
  415. package/dist/src/utility/panorama.js.map +1 -0
  416. package/dist/src/utility/pmrem.js +354 -0
  417. package/dist/src/utility/pmrem.js.map +1 -0
  418. package/dist/src/utility/rendermipmap.js +115 -0
  419. package/dist/src/utility/rendermipmap.js.map +1 -0
  420. package/dist/src/utility/serialization/json.js +402 -0
  421. package/dist/src/utility/serialization/json.js.map +1 -0
  422. package/dist/src/utility/serialization/manager.js +623 -0
  423. package/dist/src/utility/serialization/manager.js.map +1 -0
  424. package/dist/src/utility/serialization/scene/animation.js +248 -0
  425. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  426. package/dist/src/utility/serialization/scene/batch.js +59 -0
  427. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  428. package/dist/src/utility/serialization/scene/camera.js +790 -0
  429. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  430. package/dist/src/utility/serialization/scene/common.js +222 -0
  431. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  432. package/dist/src/utility/serialization/scene/light.js +575 -0
  433. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  434. package/dist/src/utility/serialization/scene/material.js +1111 -0
  435. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  436. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  437. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  438. package/dist/src/utility/serialization/scene/misc.js +39 -0
  439. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  440. package/dist/src/utility/serialization/scene/node.js +451 -0
  441. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  442. package/dist/src/utility/serialization/scene/particle.js +425 -0
  443. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  444. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  445. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  446. package/dist/src/utility/serialization/scene/scene.js +704 -0
  447. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  448. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  449. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  450. package/dist/src/utility/serialization/scene/water.js +465 -0
  451. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  452. package/dist/src/utility/shprojector.js +297 -0
  453. package/dist/src/utility/shprojector.js.map +1 -0
  454. package/dist/src/utility/textures/ggxlut.js +213 -0
  455. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  456. package/dist/src/utility/textures/gradientnoise.js +62 -0
  457. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  458. package/dist/src/utility/textures/randomnoise.js +41 -0
  459. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  460. package/dist/src/values.js +162 -0
  461. package/dist/src/values.js.map +1 -0
  462. package/dist/utility/blueprint/material/common.js +7 -0
  463. package/dist/utility/blueprint/material/common.js.map +1 -0
  464. package/dist/utility/blueprint/material/inputs.js +3 -3
  465. package/dist/utility/blueprint/material/inputs.js.map +1 -1
  466. package/dist/utility/blueprint/material/ir.js +4 -4
  467. package/dist/utility/blueprint/material/ir.js.map +1 -1
  468. package/dist/utility/serialization/blueprint/constants.js +255 -0
  469. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  470. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  471. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  472. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  473. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  474. package/dist/utility/serialization/manager.js +299 -268
  475. package/dist/utility/serialization/manager.js.map +1 -1
  476. package/dist/utility/serialization/scene/animation.js +45 -0
  477. package/dist/utility/serialization/scene/animation.js.map +1 -1
  478. package/dist/utility/serialization/scene/camera.js +53 -0
  479. package/dist/utility/serialization/scene/camera.js.map +1 -1
  480. package/dist/utility/serialization/scene/common.js +10 -0
  481. package/dist/utility/serialization/scene/common.js.map +1 -1
  482. package/dist/utility/serialization/scene/light.js +30 -0
  483. package/dist/utility/serialization/scene/light.js.map +1 -1
  484. package/dist/utility/serialization/scene/material.js +63 -0
  485. package/dist/utility/serialization/scene/material.js.map +1 -1
  486. package/dist/utility/serialization/scene/mesh.js +11 -0
  487. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  488. package/dist/utility/serialization/scene/misc.js +2 -0
  489. package/dist/utility/serialization/scene/misc.js.map +1 -1
  490. package/dist/utility/serialization/scene/node.js +19 -0
  491. package/dist/utility/serialization/scene/node.js.map +1 -1
  492. package/dist/utility/serialization/scene/particle.js +22 -0
  493. package/dist/utility/serialization/scene/particle.js.map +1 -1
  494. package/dist/utility/serialization/scene/primitive.js +33 -0
  495. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  496. package/dist/utility/serialization/scene/scene.js +39 -0
  497. package/dist/utility/serialization/scene/scene.js.map +1 -1
  498. package/dist/utility/serialization/scene/script.js +2 -0
  499. package/dist/utility/serialization/scene/script.js.map +1 -1
  500. package/dist/utility/serialization/scene/sprite.js +6 -0
  501. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  502. package/dist/utility/serialization/scene/terrain.js +9 -0
  503. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  504. package/dist/utility/serialization/scene/water.js +21 -0
  505. package/dist/utility/serialization/scene/water.js.map +1 -1
  506. package/dist/utility/serialization/types.js +5 -1
  507. package/dist/utility/serialization/types.js.map +1 -1
  508. package/dist/values.js +49 -53
  509. package/dist/values.js.map +1 -1
  510. package/package.json +2 -2
  511. package/dist/animation/joint_dynamics/vrm_spring_bone.js +0 -46
  512. package/dist/animation/joint_dynamics/vrm_spring_bone.js.map +0 -1
  513. package/dist/animation/spring/spring_bone.js +0 -240
  514. package/dist/animation/spring/spring_bone.js.map +0 -1
  515. package/dist/animation/spring/spring_bone_collider.js +0 -198
  516. package/dist/animation/spring/spring_bone_collider.js.map +0 -1
  517. package/dist/animation/spring/spring_bone_constraint.js +0 -170
  518. package/dist/animation/spring/spring_bone_constraint.js.map +0 -1
  519. package/dist/animation/spring/spring_bone_system.js +0 -328
  520. package/dist/animation/spring/spring_bone_system.js.map +0 -1
  521. package/dist/render/sky_motion_vector.js +0 -85
  522. package/dist/render/sky_motion_vector.js.map +0 -1
@@ -0,0 +1,851 @@
1
+ import { AABB, Vector3, Matrix4x4, ClipState, Vector2 } from '@zephyr3d/base';
2
+ import { Primitive } from './primitive.js';
3
+ import { getVertexAttributeIndex, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_TEXCOORD0, getVertexAttributeFormat } from '@zephyr3d/device';
4
+
5
+ const tmpAABB = new AABB();
6
+ const tmpV3 = new Vector3();
7
+ const rotationValues = [
8
+ 0,
9
+ Math.PI * 1.5,
10
+ Math.PI * 0.5,
11
+ Math.PI
12
+ ];
13
+ /** @internal */ class Clipmap {
14
+ _instanceDataPool;
15
+ _instanceDataPoolSize;
16
+ _mipLevelDataPool;
17
+ _mipLevelDataPoolSize;
18
+ _nonInstanceDataPool;
19
+ _nonInstanceDataPoolSize;
20
+ _nonInstanceMipLevelDataPool;
21
+ _nonInstanceMipLevelDataPoolSize;
22
+ _extraInstanceBuffers;
23
+ _tileResolution;
24
+ _maxMipLevels;
25
+ _tileMesh;
26
+ _tileMeshLines;
27
+ _tileMeshBBox;
28
+ _fillerMesh;
29
+ _fillerMeshLines;
30
+ _fillerMeshAABB;
31
+ _trimMesh;
32
+ _trimMeshLines;
33
+ _trimMeshAABB;
34
+ _crossMesh;
35
+ _crossMeshLines;
36
+ _crossMeshAABB;
37
+ _seamMesh;
38
+ _seamMeshLines;
39
+ _seamMeshAABB;
40
+ _wireframe;
41
+ constructor(resolution, extraInstanceBuffers, maxMipLevels = 64){
42
+ if (extraInstanceBuffers && extraInstanceBuffers.findIndex((val)=>getVertexAttributeIndex(val) === VERTEX_ATTRIB_POSITION || getVertexAttributeIndex(val) === VERTEX_ATTRIB_TEXCOORD0 || getVertexAttributeFormat(val) !== 'f32') >= 0) {
43
+ throw new Error('Extra instance buffers must be f32 format and cannot have vertex attribute of POSITOIN and TEXCOORD0');
44
+ }
45
+ this._extraInstanceBuffers = extraInstanceBuffers?.slice() ?? [];
46
+ this._tileResolution = resolution;
47
+ this._maxMipLevels = Math.min(64, Math.max(1, maxMipLevels >>> 0));
48
+ this._instanceDataPool = [];
49
+ this._instanceDataPoolSize = 0;
50
+ this._mipLevelDataPool = [];
51
+ this._mipLevelDataPoolSize = 0;
52
+ this._nonInstanceDataPool = [];
53
+ this._nonInstanceDataPoolSize = 0;
54
+ this._nonInstanceMipLevelDataPool = [];
55
+ this._nonInstanceMipLevelDataPoolSize = 0;
56
+ this._wireframe = false;
57
+ this.generateCrossMesh();
58
+ this.generateFillerMesh();
59
+ this.generateSeamMesh();
60
+ this.generateTileMesh();
61
+ this.generateTrimMesh();
62
+ }
63
+ get wireframe() {
64
+ return this._wireframe;
65
+ }
66
+ set wireframe(val) {
67
+ this._wireframe = !!val;
68
+ }
69
+ get tileResolution() {
70
+ return this._tileResolution;
71
+ }
72
+ set tileResolution(val) {
73
+ if (val !== this._tileResolution) {
74
+ this._tileResolution = val;
75
+ this.generateCrossMesh();
76
+ this.generateFillerMesh();
77
+ this.generateSeamMesh();
78
+ this.generateTileMesh();
79
+ this.generateTrimMesh();
80
+ }
81
+ }
82
+ allocInstanceBuffer() {
83
+ if (this._instanceDataPoolSize === 0) {
84
+ const buffer = new Float32Array(this._maxMipLevels * 16 * 4);
85
+ this._instanceDataPool.push(buffer);
86
+ return buffer;
87
+ } else {
88
+ return this._instanceDataPool[--this._instanceDataPoolSize];
89
+ }
90
+ }
91
+ allocNonInstanceBuffer(x, y, z, w) {
92
+ let buffer;
93
+ if (this._nonInstanceDataPoolSize === 0) {
94
+ buffer = new Float32Array(4);
95
+ this._nonInstanceDataPool.push(buffer);
96
+ } else {
97
+ buffer = this._nonInstanceDataPool[--this._nonInstanceDataPoolSize];
98
+ }
99
+ buffer[0] = x;
100
+ buffer[1] = y;
101
+ buffer[2] = z;
102
+ buffer[3] = w;
103
+ return buffer;
104
+ }
105
+ allocMipLevelBuffer() {
106
+ if (this._mipLevelDataPoolSize === 0) {
107
+ const buffer = new Float32Array(this._maxMipLevels * 16);
108
+ this._mipLevelDataPool.push(buffer);
109
+ return buffer;
110
+ } else {
111
+ return this._mipLevelDataPool[--this._mipLevelDataPoolSize];
112
+ }
113
+ }
114
+ allocNonInstanceMipLevelBuffer(val) {
115
+ let buffer;
116
+ if (this._nonInstanceMipLevelDataPoolSize === 0) {
117
+ buffer = new Float32Array(1);
118
+ this._nonInstanceMipLevelDataPool.push(buffer);
119
+ } else {
120
+ buffer = this._nonInstanceMipLevelDataPool[--this._nonInstanceMipLevelDataPoolSize];
121
+ }
122
+ buffer[0] = val;
123
+ return buffer;
124
+ }
125
+ patch2d(tileResolution, x, y) {
126
+ return y * (tileResolution + 1) + x;
127
+ }
128
+ calcAABB(vertices) {
129
+ let maxX = -Number.MAX_VALUE;
130
+ let maxY = -Number.MAX_VALUE;
131
+ let minX = Number.MAX_VALUE;
132
+ let minY = Number.MAX_VALUE;
133
+ for(let i = 0; i < vertices.length / 3; i++){
134
+ const x = vertices[i * 3 + 0];
135
+ const y = vertices[i * 3 + 1];
136
+ if (x > maxX) {
137
+ maxX = x;
138
+ }
139
+ if (x < minX) {
140
+ minX = x;
141
+ }
142
+ if (y > maxY) {
143
+ maxY = y;
144
+ }
145
+ if (y < minY) {
146
+ minY = y;
147
+ }
148
+ }
149
+ return new AABB(new Vector3(minX, minY, 0), new Vector3(maxX, maxY, 0));
150
+ }
151
+ generateTileMesh() {
152
+ this._tileMesh?.dispose();
153
+ this._tileMesh = new Primitive();
154
+ const patchVertResolution = this._tileResolution + 1;
155
+ const vertices = new Float32Array(patchVertResolution * patchVertResolution * 3);
156
+ let n = 0;
157
+ for(let y = 0; y < patchVertResolution; y++){
158
+ for(let x = 0; x < patchVertResolution; x++){
159
+ vertices[n++] = x;
160
+ vertices[n++] = y;
161
+ vertices[n++] = 0;
162
+ }
163
+ }
164
+ n = 0;
165
+ const indices = new Uint16Array(this._tileResolution * this._tileResolution * 6);
166
+ for(let y = 0; y < this._tileResolution; y++){
167
+ for(let x = 0; x < this._tileResolution; x++){
168
+ indices[n++] = this.patch2d(this._tileResolution, x, y);
169
+ indices[n++] = this.patch2d(this._tileResolution, x, y + 1);
170
+ indices[n++] = this.patch2d(this._tileResolution, x + 1, y + 1);
171
+ indices[n++] = this.patch2d(this._tileResolution, x, y);
172
+ indices[n++] = this.patch2d(this._tileResolution, x + 1, y + 1);
173
+ indices[n++] = this.patch2d(this._tileResolution, x + 1, y);
174
+ }
175
+ }
176
+ this._tileMesh.createAndSetVertexBuffer('position_f32x3', vertices);
177
+ this._tileMesh.createAndSetVertexBuffer('tex0_f32x4', this.allocInstanceBuffer(), 'instance');
178
+ this._instanceDataPoolSize++;
179
+ for (const fmt of this._extraInstanceBuffers){
180
+ this._tileMesh.createAndSetVertexBuffer(fmt, this.allocInstanceBuffer(), 'instance');
181
+ this._instanceDataPoolSize++;
182
+ }
183
+ this._tileMesh.createAndSetIndexBuffer(indices);
184
+ this._tileMesh.indexStart = 0;
185
+ this._tileMesh.indexCount = indices.length;
186
+ this._tileMesh.primitiveType = 'triangle-list';
187
+ this._tileMeshBBox = this.calcAABB(vertices);
188
+ const indicesLines = new Uint16Array(indices.length * 2);
189
+ for(let i = 0; i < indices.length / 3; i++){
190
+ indicesLines[i * 6 + 0] = indices[i * 3 + 0];
191
+ indicesLines[i * 6 + 1] = indices[i * 3 + 1];
192
+ indicesLines[i * 6 + 2] = indices[i * 3 + 1];
193
+ indicesLines[i * 6 + 3] = indices[i * 3 + 2];
194
+ indicesLines[i * 6 + 4] = indices[i * 3 + 2];
195
+ indicesLines[i * 6 + 5] = indices[i * 3 + 0];
196
+ }
197
+ this._tileMeshLines?.dispose();
198
+ this._tileMeshLines = new Primitive();
199
+ this._tileMeshLines.setVertexBuffer(this._tileMesh.getVertexBuffer('position'));
200
+ this._tileMeshLines.createAndSetVertexBuffer('tex0_f32x4', this.allocInstanceBuffer(), 'instance');
201
+ this._instanceDataPoolSize++;
202
+ for (const fmt of this._extraInstanceBuffers){
203
+ this._tileMeshLines.createAndSetVertexBuffer(fmt, this.allocInstanceBuffer(), 'instance');
204
+ this._instanceDataPoolSize++;
205
+ }
206
+ this._tileMeshLines.createAndSetIndexBuffer(indicesLines);
207
+ this._tileMeshLines.indexStart = 0;
208
+ this._tileMeshLines.indexCount = indicesLines.length;
209
+ this._tileMeshLines.primitiveType = 'line-list';
210
+ }
211
+ generateFillerMesh() {
212
+ this._fillerMesh?.dispose();
213
+ this._fillerMesh = new Primitive();
214
+ const patchVertResolution = this._tileResolution + 1;
215
+ const vertices = new Float32Array(patchVertResolution * 8 * 3);
216
+ let n = 0;
217
+ const offset = this._tileResolution;
218
+ for(let i = 0; i < patchVertResolution; i++){
219
+ vertices[n++] = offset + i + 1;
220
+ vertices[n++] = 0;
221
+ vertices[n++] = 0;
222
+ vertices[n++] = offset + i + 1;
223
+ vertices[n++] = 1;
224
+ vertices[n++] = 0;
225
+ }
226
+ for(let i = 0; i < patchVertResolution; i++){
227
+ vertices[n++] = 1;
228
+ vertices[n++] = offset + i + 1;
229
+ vertices[n++] = 0;
230
+ vertices[n++] = 0;
231
+ vertices[n++] = offset + i + 1;
232
+ vertices[n++] = 0;
233
+ }
234
+ for(let i = 0; i < patchVertResolution; i++){
235
+ vertices[n++] = -offset - i;
236
+ vertices[n++] = 1;
237
+ vertices[n++] = 0;
238
+ vertices[n++] = -offset - i;
239
+ vertices[n++] = 0;
240
+ vertices[n++] = 0;
241
+ }
242
+ for(let i = 0; i < patchVertResolution; i++){
243
+ vertices[n++] = 0;
244
+ vertices[n++] = -offset - i;
245
+ vertices[n++] = 0;
246
+ vertices[n++] = 1;
247
+ vertices[n++] = -offset - i;
248
+ vertices[n++] = 0;
249
+ }
250
+ n = 0;
251
+ const indices = new Uint16Array(this._tileResolution * 24);
252
+ for(let i = 0; i < this._tileResolution * 4; i++){
253
+ const arm = i / this._tileResolution >> 0;
254
+ const bl = (arm + i) * 2 + 0;
255
+ const br = (arm + i) * 2 + 1;
256
+ const tl = (arm + i) * 2 + 2;
257
+ const tr = (arm + i) * 2 + 3;
258
+ if (arm % 2 === 0) {
259
+ indices[n++] = br;
260
+ indices[n++] = tr;
261
+ indices[n++] = bl;
262
+ indices[n++] = bl;
263
+ indices[n++] = tr;
264
+ indices[n++] = tl;
265
+ } else {
266
+ indices[n++] = br;
267
+ indices[n++] = tl;
268
+ indices[n++] = bl;
269
+ indices[n++] = br;
270
+ indices[n++] = tr;
271
+ indices[n++] = tl;
272
+ }
273
+ }
274
+ this._fillerMesh.createAndSetVertexBuffer('position_f32x3', vertices);
275
+ this._fillerMesh.createAndSetVertexBuffer('tex0_f32x4', this.allocInstanceBuffer(), 'instance');
276
+ this._instanceDataPoolSize++;
277
+ for (const fmt of this._extraInstanceBuffers){
278
+ this._fillerMesh.createAndSetVertexBuffer(fmt, this.allocInstanceBuffer(), 'instance');
279
+ this._instanceDataPoolSize++;
280
+ }
281
+ this._fillerMesh.createAndSetIndexBuffer(indices);
282
+ this._fillerMesh.indexStart = 0;
283
+ this._fillerMesh.indexCount = indices.length;
284
+ this._fillerMesh.primitiveType = 'triangle-list';
285
+ this._fillerMeshAABB = this.calcAABB(vertices);
286
+ const indicesLines = new Uint16Array(indices.length * 2);
287
+ for(let i = 0; i < indices.length / 3; i++){
288
+ indicesLines[i * 6 + 0] = indices[i * 3 + 0];
289
+ indicesLines[i * 6 + 1] = indices[i * 3 + 1];
290
+ indicesLines[i * 6 + 2] = indices[i * 3 + 1];
291
+ indicesLines[i * 6 + 3] = indices[i * 3 + 2];
292
+ indicesLines[i * 6 + 4] = indices[i * 3 + 2];
293
+ indicesLines[i * 6 + 5] = indices[i * 3 + 0];
294
+ }
295
+ this._fillerMeshLines?.dispose();
296
+ this._fillerMeshLines = new Primitive();
297
+ this._fillerMeshLines.setVertexBuffer(this._fillerMesh.getVertexBuffer('position'));
298
+ this._fillerMeshLines.createAndSetVertexBuffer('tex0_f32x4', this.allocInstanceBuffer(), 'instance');
299
+ this._instanceDataPoolSize++;
300
+ for (const fmt of this._extraInstanceBuffers){
301
+ this._fillerMeshLines.createAndSetVertexBuffer(fmt, this.allocInstanceBuffer(), 'instance');
302
+ this._instanceDataPoolSize++;
303
+ }
304
+ this._fillerMeshLines.createAndSetIndexBuffer(indicesLines);
305
+ this._fillerMeshLines.indexStart = 0;
306
+ this._fillerMeshLines.indexCount = indicesLines.length;
307
+ this._fillerMeshLines.primitiveType = 'line-list';
308
+ }
309
+ generateTrimMesh() {
310
+ this._trimMesh?.dispose();
311
+ this._trimMesh = new Primitive();
312
+ const clipmapVertResolution = this._tileResolution * 4 + 2;
313
+ const vertices = new Float32Array((clipmapVertResolution * 2 + 1) * 2 * 3);
314
+ let n = 0;
315
+ const d = 0.5 * (clipmapVertResolution + 1);
316
+ for(let i = 0; i < clipmapVertResolution + 1; i++){
317
+ vertices[n++] = 0 - d;
318
+ vertices[n++] = clipmapVertResolution - i - d;
319
+ vertices[n++] = 0;
320
+ vertices[n++] = 1 - d;
321
+ vertices[n++] = clipmapVertResolution - i - d;
322
+ vertices[n++] = 0;
323
+ }
324
+ const startOfHorizonal = n / 3;
325
+ for(let i = 0; i < clipmapVertResolution; i++){
326
+ vertices[n++] = i + 1 - d;
327
+ vertices[n++] = 0 - d;
328
+ vertices[n++] = 0;
329
+ vertices[n++] = i + 1 - d;
330
+ vertices[n++] = 1 - d;
331
+ vertices[n++] = 0;
332
+ }
333
+ n = 0;
334
+ const indices = new Uint16Array((clipmapVertResolution * 2 - 1) * 6);
335
+ for(let i = 0; i < clipmapVertResolution; i++){
336
+ indices[n++] = (i + 0) * 2 + 1;
337
+ indices[n++] = (i + 1) * 2 + 0;
338
+ indices[n++] = (i + 0) * 2 + 0;
339
+ indices[n++] = (i + 1) * 2 + 1;
340
+ indices[n++] = (i + 1) * 2 + 0;
341
+ indices[n++] = (i + 0) * 2 + 1;
342
+ }
343
+ for(let i = 0; i < clipmapVertResolution - 1; i++){
344
+ indices[n++] = startOfHorizonal + (i + 0) * 2 + 1;
345
+ indices[n++] = startOfHorizonal + (i + 1) * 2 + 0;
346
+ indices[n++] = startOfHorizonal + (i + 0) * 2 + 0;
347
+ indices[n++] = startOfHorizonal + (i + 1) * 2 + 1;
348
+ indices[n++] = startOfHorizonal + (i + 1) * 2 + 0;
349
+ indices[n++] = startOfHorizonal + (i + 0) * 2 + 1;
350
+ }
351
+ this._trimMesh.createAndSetVertexBuffer('position_f32x3', vertices);
352
+ this._trimMesh.createAndSetVertexBuffer('tex0_f32x4', this.allocInstanceBuffer(), 'instance');
353
+ this._instanceDataPoolSize++;
354
+ for (const fmt of this._extraInstanceBuffers){
355
+ this._trimMesh.createAndSetVertexBuffer(fmt, this.allocInstanceBuffer(), 'instance');
356
+ this._instanceDataPoolSize++;
357
+ }
358
+ this._trimMesh.createAndSetIndexBuffer(indices);
359
+ this._trimMesh.indexStart = 0;
360
+ this._trimMesh.indexCount = indices.length;
361
+ this._trimMesh.primitiveType = 'triangle-list';
362
+ this._trimMeshAABB = this.calcAABB(vertices);
363
+ const indicesLines = new Uint16Array(indices.length * 2);
364
+ for(let i = 0; i < indices.length / 3; i++){
365
+ indicesLines[i * 6 + 0] = indices[i * 3 + 0];
366
+ indicesLines[i * 6 + 1] = indices[i * 3 + 1];
367
+ indicesLines[i * 6 + 2] = indices[i * 3 + 1];
368
+ indicesLines[i * 6 + 3] = indices[i * 3 + 2];
369
+ indicesLines[i * 6 + 4] = indices[i * 3 + 2];
370
+ indicesLines[i * 6 + 5] = indices[i * 3 + 0];
371
+ }
372
+ this._trimMeshLines?.dispose();
373
+ this._trimMeshLines = new Primitive();
374
+ this._trimMeshLines.setVertexBuffer(this._trimMesh.getVertexBuffer('position'));
375
+ this._trimMeshLines.createAndSetVertexBuffer('tex0_f32x4', this.allocInstanceBuffer(), 'instance');
376
+ this._instanceDataPoolSize++;
377
+ for (const fmt of this._extraInstanceBuffers){
378
+ this._trimMeshLines.createAndSetVertexBuffer(fmt, this.allocInstanceBuffer(), 'instance');
379
+ this._instanceDataPoolSize++;
380
+ }
381
+ this._trimMeshLines.createAndSetIndexBuffer(indicesLines);
382
+ this._trimMeshLines.indexStart = 0;
383
+ this._trimMeshLines.indexCount = indicesLines.length;
384
+ this._trimMeshLines.primitiveType = 'line-list';
385
+ }
386
+ generateCrossMesh() {
387
+ const patchVertResolution = this._tileResolution + 1;
388
+ const vertices = new Float32Array(patchVertResolution * 8 * 3);
389
+ let n = 0;
390
+ for(let i = 0; i < patchVertResolution * 2; i++){
391
+ vertices[n++] = i - this._tileResolution;
392
+ vertices[n++] = 0;
393
+ vertices[n++] = 0;
394
+ vertices[n++] = i - this._tileResolution;
395
+ vertices[n++] = 1;
396
+ vertices[n++] = 0;
397
+ }
398
+ const startOfVertical = n / 3;
399
+ for(let i = 0; i < patchVertResolution * 2; i++){
400
+ vertices[n++] = 0;
401
+ vertices[n++] = i - this._tileResolution;
402
+ vertices[n++] = 0;
403
+ vertices[n++] = 1;
404
+ vertices[n++] = i - this._tileResolution;
405
+ vertices[n++] = 0;
406
+ }
407
+ n = 0;
408
+ const indices = new Uint16Array(this._tileResolution * 24 + 6);
409
+ for(let i = 0; i < this._tileResolution * 2 + 1; i++){
410
+ const bl = i * 2 + 0;
411
+ const br = i * 2 + 1;
412
+ const tl = i * 2 + 2;
413
+ const tr = i * 2 + 3;
414
+ indices[n++] = br;
415
+ indices[n++] = tr;
416
+ indices[n++] = bl;
417
+ indices[n++] = bl;
418
+ indices[n++] = tr;
419
+ indices[n++] = tl;
420
+ }
421
+ for(let i = 0; i < this._tileResolution * 2 + 1; i++){
422
+ if (i === this._tileResolution) {
423
+ continue;
424
+ }
425
+ const bl = i * 2 + 0;
426
+ const br = i * 2 + 1;
427
+ const tl = i * 2 + 2;
428
+ const tr = i * 2 + 3;
429
+ indices[n++] = startOfVertical + br;
430
+ indices[n++] = startOfVertical + bl;
431
+ indices[n++] = startOfVertical + tr;
432
+ indices[n++] = startOfVertical + bl;
433
+ indices[n++] = startOfVertical + tl;
434
+ indices[n++] = startOfVertical + tr;
435
+ }
436
+ this._crossMesh?.dispose();
437
+ this._crossMesh = new Primitive();
438
+ this._crossMesh.createAndSetVertexBuffer('position_f32x3', vertices);
439
+ this._crossMesh.createAndSetVertexBuffer('tex0_f32x4', this.allocNonInstanceBuffer(0, 0, 0, 0), 'instance');
440
+ this._nonInstanceDataPoolSize++;
441
+ for (const fmt of this._extraInstanceBuffers){
442
+ this._crossMesh.createAndSetVertexBuffer(fmt, this.allocNonInstanceBuffer(0, 0, 0, 0), 'instance');
443
+ this._nonInstanceDataPoolSize++;
444
+ }
445
+ this._crossMesh.createAndSetIndexBuffer(indices);
446
+ this._crossMesh.indexStart = 0;
447
+ this._crossMesh.indexCount = indices.length;
448
+ this._crossMesh.primitiveType = 'triangle-list';
449
+ this._crossMeshAABB = this.calcAABB(vertices);
450
+ const indicesLines = new Uint16Array(indices.length * 2);
451
+ for(let i = 0; i < indices.length / 3; i++){
452
+ indicesLines[i * 6 + 0] = indices[i * 3 + 0];
453
+ indicesLines[i * 6 + 1] = indices[i * 3 + 1];
454
+ indicesLines[i * 6 + 2] = indices[i * 3 + 1];
455
+ indicesLines[i * 6 + 3] = indices[i * 3 + 2];
456
+ indicesLines[i * 6 + 4] = indices[i * 3 + 2];
457
+ indicesLines[i * 6 + 5] = indices[i * 3 + 0];
458
+ }
459
+ this._crossMeshLines?.dispose();
460
+ this._crossMeshLines = new Primitive();
461
+ this._crossMeshLines.setVertexBuffer(this._crossMesh.getVertexBuffer('position'));
462
+ this._crossMeshLines.createAndSetVertexBuffer('tex0_f32x4', this.allocNonInstanceBuffer(0, 0, 0, 0), 'instance');
463
+ this._nonInstanceDataPoolSize++;
464
+ for (const fmt of this._extraInstanceBuffers){
465
+ this._crossMeshLines.createAndSetVertexBuffer(fmt, this.allocNonInstanceBuffer(0, 0, 0, 0), 'instance');
466
+ this._nonInstanceDataPoolSize++;
467
+ }
468
+ this._crossMeshLines.createAndSetIndexBuffer(indicesLines);
469
+ this._crossMeshLines.indexStart = 0;
470
+ this._crossMeshLines.indexCount = indicesLines.length;
471
+ this._crossMeshLines.primitiveType = 'line-list';
472
+ }
473
+ generateSeamMesh() {
474
+ this._seamMesh?.dispose();
475
+ this._seamMesh = new Primitive();
476
+ const clipmapVertResolution = this._tileResolution * 4 + 2;
477
+ const vertices = new Float32Array(clipmapVertResolution * 4 * 3);
478
+ for(let i = 0; i < clipmapVertResolution; i++){
479
+ vertices[(clipmapVertResolution * 0 + i) * 3 + 0] = i;
480
+ vertices[(clipmapVertResolution * 0 + i) * 3 + 1] = 0;
481
+ vertices[(clipmapVertResolution * 0 + i) * 3 + 2] = 0;
482
+ vertices[(clipmapVertResolution * 1 + i) * 3 + 0] = clipmapVertResolution;
483
+ vertices[(clipmapVertResolution * 1 + i) * 3 + 1] = i;
484
+ vertices[(clipmapVertResolution * 1 + i) * 3 + 2] = 0;
485
+ vertices[(clipmapVertResolution * 2 + i) * 3 + 0] = clipmapVertResolution - i;
486
+ vertices[(clipmapVertResolution * 2 + i) * 3 + 1] = clipmapVertResolution;
487
+ vertices[(clipmapVertResolution * 2 + i) * 3 + 2] = 0;
488
+ vertices[(clipmapVertResolution * 3 + i) * 3 + 0] = 0;
489
+ vertices[(clipmapVertResolution * 3 + i) * 3 + 1] = clipmapVertResolution - i;
490
+ vertices[(clipmapVertResolution * 3 + i) * 3 + 2] = 0;
491
+ }
492
+ const indices = new Uint16Array(clipmapVertResolution * 6);
493
+ let n = 0;
494
+ for(let i = 0; i < clipmapVertResolution * 4; i += 2){
495
+ indices[n++] = i + 1;
496
+ indices[n++] = i + 2;
497
+ indices[n++] = i;
498
+ }
499
+ indices[indices.length - 1] = 0;
500
+ this._seamMesh.createAndSetVertexBuffer('position_f32x3', vertices);
501
+ this._seamMesh.createAndSetVertexBuffer('tex0_f32x4', this.allocInstanceBuffer(), 'instance');
502
+ this._instanceDataPoolSize++;
503
+ for (const fmt of this._extraInstanceBuffers){
504
+ this._seamMesh.createAndSetVertexBuffer(fmt, this.allocInstanceBuffer(), 'instance');
505
+ this._instanceDataPoolSize++;
506
+ }
507
+ this._seamMesh.createAndSetIndexBuffer(indices);
508
+ this._seamMesh.indexStart = 0;
509
+ this._seamMesh.indexCount = indices.length;
510
+ this._seamMesh.primitiveType = 'triangle-list';
511
+ this._seamMeshAABB = this.calcAABB(vertices);
512
+ const indicesLines = new Uint16Array(indices.length * 2);
513
+ for(let i = 0; i < indices.length / 3; i++){
514
+ indicesLines[i * 6 + 0] = indices[i * 3 + 0];
515
+ indicesLines[i * 6 + 1] = indices[i * 3 + 1];
516
+ indicesLines[i * 6 + 2] = indices[i * 3 + 1];
517
+ indicesLines[i * 6 + 3] = indices[i * 3 + 2];
518
+ indicesLines[i * 6 + 4] = indices[i * 3 + 2];
519
+ indicesLines[i * 6 + 5] = indices[i * 3 + 0];
520
+ }
521
+ this._seamMeshLines?.dispose();
522
+ this._seamMeshLines = new Primitive();
523
+ this._seamMeshLines.setVertexBuffer(this._seamMesh.getVertexBuffer('position'));
524
+ this._seamMeshLines.createAndSetVertexBuffer('tex0_f32x4', this.allocInstanceBuffer(), 'instance');
525
+ this._instanceDataPoolSize++;
526
+ for (const fmt of this._extraInstanceBuffers){
527
+ this._seamMeshLines.createAndSetVertexBuffer(fmt, this.allocInstanceBuffer(), 'instance');
528
+ this._instanceDataPoolSize++;
529
+ }
530
+ this._seamMeshLines.createAndSetIndexBuffer(indicesLines);
531
+ this._seamMeshLines.indexStart = 0;
532
+ this._seamMeshLines.indexCount = indicesLines.length;
533
+ this._seamMeshLines.primitiveType = 'line-list';
534
+ }
535
+ intervalsOverlap(a0, a1, b0, b1) {
536
+ return a0 <= b1 && b0 <= a1;
537
+ }
538
+ updateAABB(aabb, rotation, offset, scale, gridScale, outAABB) {
539
+ if (!rotation) {
540
+ tmpAABB.minPoint.set(aabb.minPoint);
541
+ tmpAABB.maxPoint.set(aabb.maxPoint);
542
+ } else {
543
+ AABB.transform(aabb, Matrix4x4.rotationZ(rotation), tmpAABB);
544
+ }
545
+ const minX = (tmpAABB.minPoint.x * scale + offset.x) * gridScale;
546
+ const maxX = (tmpAABB.maxPoint.x * scale + offset.x) * gridScale;
547
+ const minZ = (tmpAABB.minPoint.y * scale + offset.y) * gridScale;
548
+ const maxZ = (tmpAABB.maxPoint.y * scale + offset.y) * gridScale;
549
+ if (minX < outAABB.minPoint.x) {
550
+ outAABB.minPoint.x = minX;
551
+ }
552
+ if (maxX > outAABB.maxPoint.x) {
553
+ outAABB.maxPoint.x = maxX;
554
+ }
555
+ if (minZ < outAABB.minPoint.z) {
556
+ outAABB.minPoint.z = minZ;
557
+ }
558
+ if (maxZ > outAABB.maxPoint.z) {
559
+ outAABB.maxPoint.z = maxZ;
560
+ }
561
+ }
562
+ visible(ctx, aabb, camera, rotation, offset, scale, gridScale, level) {
563
+ if (!rotation) {
564
+ tmpAABB.minPoint.set(aabb.minPoint);
565
+ tmpAABB.maxPoint.set(aabb.maxPoint);
566
+ } else {
567
+ AABB.transform(aabb, Matrix4x4.rotationZ(rotation), tmpAABB);
568
+ }
569
+ const minX = (tmpAABB.minPoint.x * scale + offset.x) * gridScale;
570
+ const maxX = (tmpAABB.maxPoint.x * scale + offset.x) * gridScale;
571
+ const minZ = (tmpAABB.minPoint.y * scale + offset.y) * gridScale;
572
+ const maxZ = (tmpAABB.maxPoint.y * scale + offset.y) * gridScale;
573
+ ctx.calcAABB(ctx.userData, minX, maxX, minZ, maxZ, tmpAABB, level);
574
+ return tmpAABB.getClipStateWithFrustum(camera.frustum) !== ClipState.NOT_CLIPPED;
575
+ }
576
+ calcLevelAABB(camera, minMaxWorldPos, gridScale) {
577
+ const mipLevels = this.calcMipLevels(camera, minMaxWorldPos, gridScale);
578
+ camera.getWorldPosition(tmpV3);
579
+ const snappedPos = new Vector2();
580
+ const tileSize = new Vector2();
581
+ const base = new Vector2();
582
+ const offset = new Vector2();
583
+ const posX = tmpV3.x / gridScale;
584
+ const posY = tmpV3.z / gridScale;
585
+ const outAABB = [];
586
+ for(let i = 0; i < mipLevels; i++){
587
+ const aabb = new AABB();
588
+ aabb.beginExtend();
589
+ outAABB.push(aabb);
590
+ }
591
+ snappedPos.setXY(Math.floor(posX), Math.floor(posY));
592
+ // cross
593
+ this.updateAABB(this._crossMeshAABB, null, snappedPos, 1, gridScale, outAABB[0]);
594
+ for(let l = 0; l < mipLevels; l++){
595
+ const aabb = outAABB[l];
596
+ const scale = 1 << l;
597
+ snappedPos.setXY(Math.floor(posX / scale) * scale, Math.floor(posY / scale) * scale);
598
+ // draw tiles
599
+ tileSize.setXY(this._tileResolution << l, this._tileResolution << l);
600
+ base.setXY(snappedPos.x - (this._tileResolution << l + 1), snappedPos.y - (this._tileResolution << l + 1));
601
+ for(let x = 0; x < 4; x++){
602
+ for(let y = 0; y < 4; y++){
603
+ if (l !== 0 && (x === 1 || x === 2) && (y === 1 || y === 2)) {
604
+ continue;
605
+ }
606
+ const fillX = x >= 2 ? scale : 0;
607
+ const fillY = y >= 2 ? scale : 0;
608
+ offset.setXY(base.x + x * tileSize.x + fillX, base.y + y * tileSize.y + fillY);
609
+ this.updateAABB(this._tileMeshBBox, null, offset, scale, gridScale, aabb);
610
+ }
611
+ }
612
+ // draw filler
613
+ this.updateAABB(this._fillerMeshAABB, null, snappedPos, scale, gridScale, aabb);
614
+ const nextScale = scale * 2;
615
+ const nextSnappedPos = new Vector2(Math.floor(posX / nextScale) * nextScale, Math.floor(posY / nextScale) * nextScale);
616
+ // draw trim
617
+ const tileCentre = new Vector2(snappedPos.x + scale * 0.5, snappedPos.y + scale * 0.5);
618
+ const d = new Vector2(posX - nextSnappedPos.x, posY - nextSnappedPos.y);
619
+ let r = 0;
620
+ r |= d.x >= scale ? 0 : 2;
621
+ r |= d.y >= scale ? 0 : 1;
622
+ this.updateAABB(this._trimMeshAABB, rotationValues[r], tileCentre, scale, gridScale, aabb);
623
+ // draw seam
624
+ const nextBase = new Vector2(nextSnappedPos.x - (this._tileResolution << l + 1), nextSnappedPos.y - (this._tileResolution << l + 1));
625
+ this.updateAABB(this._seamMeshAABB, null, nextBase, scale, gridScale, aabb);
626
+ }
627
+ return outAABB;
628
+ }
629
+ calcMipLevels(camera, minMaxWorldPos, gridScale) {
630
+ camera.getWorldPosition(tmpV3);
631
+ const distX = Math.max(Math.abs(tmpV3.x - minMaxWorldPos.x), Math.abs(tmpV3.x - minMaxWorldPos.z));
632
+ const distY = Math.max(Math.abs(tmpV3.z - minMaxWorldPos.y), Math.abs(tmpV3.z - minMaxWorldPos.w));
633
+ const maxDist = Math.min(Math.max(distX, distY), camera.getFarPlane());
634
+ return Math.min(Math.max(Math.ceil(Math.log2(maxDist / (this._tileResolution * gridScale))), 0) + 1, this._maxMipLevels);
635
+ }
636
+ addInstance(info, rotation, offsetX, offsetY, scale, mipLevel) {
637
+ info.mipLevels[info.numInstances] = mipLevel;
638
+ info.instanceDatas[info.numInstances * 4 + 0] = rotation;
639
+ info.instanceDatas[info.numInstances * 4 + 1] = scale;
640
+ info.instanceDatas[info.numInstances * 4 + 2] = offsetX;
641
+ info.instanceDatas[info.numInstances * 4 + 3] = offsetY;
642
+ info.maxMiplevel = mipLevel;
643
+ info.numInstances++;
644
+ }
645
+ gather(context) {
646
+ this._instanceDataPoolSize = this._instanceDataPool.length;
647
+ this._mipLevelDataPoolSize = this._mipLevelDataPool.length;
648
+ this._nonInstanceDataPoolSize = this._nonInstanceDataPool.length;
649
+ this._nonInstanceMipLevelDataPoolSize = this._nonInstanceMipLevelDataPool.length;
650
+ const renderData = [];
651
+ const mipLevels = this.calcMipLevels(context.camera, context.minMaxWorldPos, context.gridScale);
652
+ context.camera.getWorldPosition(tmpV3);
653
+ const snappedPos = new Vector2();
654
+ const tileSize = new Vector2();
655
+ const base = new Vector2();
656
+ const offset = new Vector2();
657
+ const posX = tmpV3.x / context.gridScale;
658
+ const posY = tmpV3.z / context.gridScale;
659
+ // draw cross
660
+ snappedPos.setXY(Math.floor(posX), Math.floor(posY));
661
+ if (this.visible(context, this._crossMeshAABB, context.camera, null, snappedPos, 1, context.gridScale, 0)) {
662
+ const crossPrimitives = {
663
+ primitive: this._wireframe ? this._crossMeshLines : this._crossMesh,
664
+ numInstances: 1,
665
+ instanceDatas: this.allocNonInstanceBuffer(rotationValues[0], 1, snappedPos.x, snappedPos.y),
666
+ mipLevels: this.allocNonInstanceMipLevelBuffer(0),
667
+ maxMiplevel: 0
668
+ };
669
+ renderData.push(crossPrimitives);
670
+ }
671
+ const tilePrimitives = {
672
+ primitive: this._wireframe ? this._tileMeshLines : this._tileMesh,
673
+ numInstances: 0,
674
+ instanceDatas: this.allocInstanceBuffer(),
675
+ mipLevels: this.allocMipLevelBuffer(),
676
+ maxMiplevel: 0
677
+ };
678
+ const fillerPrimitives = {
679
+ primitive: this._wireframe ? this._fillerMeshLines : this._fillerMesh,
680
+ numInstances: 0,
681
+ instanceDatas: this.allocInstanceBuffer(),
682
+ mipLevels: this.allocMipLevelBuffer(),
683
+ maxMiplevel: 0
684
+ };
685
+ const trimPrimitives = {
686
+ primitive: this._wireframe ? this._trimMeshLines : this._trimMesh,
687
+ numInstances: 0,
688
+ instanceDatas: this.allocInstanceBuffer(),
689
+ mipLevels: this.allocMipLevelBuffer(),
690
+ maxMiplevel: 0
691
+ };
692
+ const seamPrimitives = {
693
+ primitive: this._wireframe ? this._seamMeshLines : this._seamMesh,
694
+ numInstances: 0,
695
+ instanceDatas: this.allocInstanceBuffer(),
696
+ mipLevels: this.allocMipLevelBuffer(),
697
+ maxMiplevel: 0
698
+ };
699
+ for(let l = 0; l < mipLevels; l++){
700
+ const scale = 1 << l;
701
+ snappedPos.setXY(Math.floor(posX / scale) * scale, Math.floor(posY / scale) * scale);
702
+ // draw tiles
703
+ tileSize.setXY(this._tileResolution << l, this._tileResolution << l);
704
+ base.setXY(snappedPos.x - (this._tileResolution << l + 1), snappedPos.y - (this._tileResolution << l + 1));
705
+ for(let x = 0; x < 4; x++){
706
+ for(let y = 0; y < 4; y++){
707
+ if (l !== 0 && (x === 1 || x === 2) && (y === 1 || y === 2)) {
708
+ continue;
709
+ }
710
+ const fillX = x >= 2 ? scale : 0;
711
+ const fillY = y >= 2 ? scale : 0;
712
+ offset.setXY(base.x + x * tileSize.x + fillX, base.y + y * tileSize.y + fillY);
713
+ if (this.intervalsOverlap(offset.x * context.gridScale, (offset.x + tileSize.x) * context.gridScale, context.minMaxWorldPos.x, context.minMaxWorldPos.z) && this.intervalsOverlap(offset.y * context.gridScale, (offset.y + tileSize.y) * context.gridScale, context.minMaxWorldPos.y, context.minMaxWorldPos.w)) {
714
+ if (this.visible(context, this._tileMeshBBox, context.camera, null, offset, scale, context.gridScale, l)) {
715
+ this.addInstance(tilePrimitives, rotationValues[0], offset.x, offset.y, scale, l);
716
+ }
717
+ }
718
+ }
719
+ }
720
+ // draw filler
721
+ if (this.visible(context, this._fillerMeshAABB, context.camera, null, snappedPos, scale, context.gridScale, l)) {
722
+ this.addInstance(fillerPrimitives, rotationValues[0], snappedPos.x, snappedPos.y, scale, l);
723
+ }
724
+ if (l !== mipLevels - 1) {
725
+ const nextScale = scale * 2;
726
+ const nextSnappedPos = new Vector2(Math.floor(posX / nextScale) * nextScale, Math.floor(posY / nextScale) * nextScale);
727
+ // draw trim
728
+ const tileCentre = new Vector2(snappedPos.x + scale * 0.5, snappedPos.y + scale * 0.5);
729
+ const d = new Vector2(posX - nextSnappedPos.x, posY - nextSnappedPos.y);
730
+ let r = 0;
731
+ r |= d.x >= scale ? 0 : 2;
732
+ r |= d.y >= scale ? 0 : 1;
733
+ if (this.visible(context, this._trimMeshAABB, context.camera, rotationValues[r], tileCentre, scale, context.gridScale, l)) {
734
+ this.addInstance(trimPrimitives, rotationValues[r], tileCentre.x, tileCentre.y, scale, l);
735
+ }
736
+ // draw seam
737
+ const nextBase = new Vector2(nextSnappedPos.x - (this._tileResolution << l + 1), nextSnappedPos.y - (this._tileResolution << l + 1));
738
+ if (this.visible(context, this._seamMeshAABB, context.camera, null, nextBase, scale, context.gridScale, l)) {
739
+ this.addInstance(seamPrimitives, rotationValues[0], nextBase.x, nextBase.y, scale, l);
740
+ }
741
+ }
742
+ }
743
+ if (tilePrimitives.numInstances > 0) {
744
+ renderData.push(tilePrimitives);
745
+ }
746
+ if (fillerPrimitives.numInstances > 0) {
747
+ renderData.push(fillerPrimitives);
748
+ }
749
+ if (trimPrimitives.numInstances > 0) {
750
+ renderData.push(trimPrimitives);
751
+ }
752
+ if (seamPrimitives.numInstances > 0) {
753
+ renderData.push(seamPrimitives);
754
+ }
755
+ for (const info of renderData){
756
+ info.primitive.getVertexBuffer('texCoord0').bufferSubData(0, info.instanceDatas, 0, info.numInstances * 4);
757
+ }
758
+ return renderData;
759
+ }
760
+ draw(context) {
761
+ let drawn = 0;
762
+ const mipLevels = this.calcMipLevels(context.camera, context.minMaxWorldPos, context.gridScale);
763
+ context.camera.getWorldPosition(tmpV3);
764
+ const snappedPos = new Vector2();
765
+ const tileSize = new Vector2();
766
+ const base = new Vector2();
767
+ const offset = new Vector2();
768
+ const posX = tmpV3.x / context.gridScale;
769
+ const posY = tmpV3.z / context.gridScale;
770
+ // draw cross
771
+ snappedPos.setXY(Math.floor(posX), Math.floor(posY));
772
+ if (this.visible(context, this._crossMeshAABB, context.camera, null, snappedPos, 1, context.gridScale, 0)) {
773
+ context.drawPrimitive(this._wireframe ? this._crossMeshLines : this._crossMesh, rotationValues[0], snappedPos, 1, context.gridScale, 0);
774
+ drawn++;
775
+ }
776
+ for(let l = 0; l < mipLevels; l++){
777
+ const scale = 1 << l;
778
+ snappedPos.setXY(Math.floor(posX / scale) * scale, Math.floor(posY / scale) * scale);
779
+ // draw tiles
780
+ tileSize.setXY(this._tileResolution << l, this._tileResolution << l);
781
+ base.setXY(snappedPos.x - (this._tileResolution << l + 1), snappedPos.y - (this._tileResolution << l + 1));
782
+ for(let x = 0; x < 4; x++){
783
+ for(let y = 0; y < 4; y++){
784
+ if (l !== 0 && (x === 1 || x === 2) && (y === 1 || y === 2)) {
785
+ continue;
786
+ }
787
+ const fillX = x >= 2 ? scale : 0;
788
+ const fillY = y >= 2 ? scale : 0;
789
+ offset.setXY(base.x + x * tileSize.x + fillX, base.y + y * tileSize.y + fillY);
790
+ if (this.intervalsOverlap(offset.x * context.gridScale, (offset.x + tileSize.x) * context.gridScale, context.minMaxWorldPos.x, context.minMaxWorldPos.z) && this.intervalsOverlap(offset.y * context.gridScale, (offset.y + tileSize.y) * context.gridScale, context.minMaxWorldPos.y, context.minMaxWorldPos.w)) {
791
+ if (this.visible(context, this._tileMeshBBox, context.camera, null, offset, scale, context.gridScale, l)) {
792
+ context.drawPrimitive(this._wireframe ? this._tileMeshLines : this._tileMesh, rotationValues[0], offset, scale, context.gridScale, l);
793
+ drawn++;
794
+ }
795
+ }
796
+ }
797
+ }
798
+ // draw filler
799
+ if (this.visible(context, this._fillerMeshAABB, context.camera, null, snappedPos, scale, context.gridScale, l)) {
800
+ context.drawPrimitive(this._wireframe ? this._fillerMeshLines : this._fillerMesh, rotationValues[0], snappedPos, scale, context.gridScale, l);
801
+ drawn++;
802
+ }
803
+ if (l !== mipLevels - 1) {
804
+ const nextScale = scale * 2;
805
+ const nextSnappedPos = new Vector2(Math.floor(posX / nextScale) * nextScale, Math.floor(posY / nextScale) * nextScale);
806
+ // draw trim
807
+ const tileCentre = new Vector2(snappedPos.x + scale * 0.5, snappedPos.y + scale * 0.5);
808
+ const d = new Vector2(posX - nextSnappedPos.x, posY - nextSnappedPos.y);
809
+ let r = 0;
810
+ r |= d.x >= scale ? 0 : 2;
811
+ r |= d.y >= scale ? 0 : 1;
812
+ if (this.visible(context, this._trimMeshAABB, context.camera, rotationValues[r], tileCentre, scale, context.gridScale, l)) {
813
+ context.drawPrimitive(this._wireframe ? this._trimMeshLines : this._trimMesh, rotationValues[r], tileCentre, scale, context.gridScale, l);
814
+ drawn++;
815
+ }
816
+ // draw seam
817
+ const nextBase = new Vector2(nextSnappedPos.x - (this._tileResolution << l + 1), nextSnappedPos.y - (this._tileResolution << l + 1));
818
+ if (this.visible(context, this._seamMeshAABB, context.camera, null, nextBase, scale, context.gridScale, l)) {
819
+ context.drawPrimitive(this._wireframe ? this._seamMeshLines : this._seamMesh, rotationValues[0], nextBase, scale, context.gridScale, l);
820
+ drawn++;
821
+ }
822
+ }
823
+ }
824
+ return drawn;
825
+ }
826
+ dispose() {
827
+ this._crossMesh.dispose();
828
+ this._crossMesh = null;
829
+ this._crossMeshLines.dispose();
830
+ this._crossMeshLines = null;
831
+ this._fillerMesh.dispose();
832
+ this._fillerMesh = null;
833
+ this._fillerMeshLines.dispose();
834
+ this._fillerMeshLines = null;
835
+ this._seamMesh.dispose();
836
+ this._seamMesh = null;
837
+ this._seamMeshLines.dispose();
838
+ this._seamMeshLines = null;
839
+ this._trimMesh.dispose();
840
+ this._trimMesh = null;
841
+ this._trimMeshLines.dispose();
842
+ this._trimMeshLines = null;
843
+ this._tileMesh.dispose();
844
+ this._tileMesh = null;
845
+ this._tileMeshLines.dispose();
846
+ this._tileMeshLines = null;
847
+ }
848
+ }
849
+
850
+ export { Clipmap };
851
+ //# sourceMappingURL=clipmap.js.map