@zephyr3d/scene 0.6.0 → 0.7.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 (723) hide show
  1. package/README.md +1 -1
  2. package/dist/animation/animation.js +149 -27
  3. package/dist/animation/animation.js.map +1 -1
  4. package/dist/animation/animationset.js +173 -73
  5. package/dist/animation/animationset.js.map +1 -1
  6. package/dist/animation/animationtrack.js +65 -10
  7. package/dist/animation/animationtrack.js.map +1 -1
  8. package/dist/animation/eulerrotationtrack.js +41 -20
  9. package/dist/animation/eulerrotationtrack.js.map +1 -1
  10. package/dist/animation/morphtarget.js +14 -38
  11. package/dist/animation/morphtarget.js.map +1 -1
  12. package/dist/animation/morphtrack.js +59 -22
  13. package/dist/animation/morphtrack.js.map +1 -1
  14. package/dist/animation/proptrack.js +190 -0
  15. package/dist/animation/proptrack.js.map +1 -0
  16. package/dist/animation/rotationtrack.js +29 -11
  17. package/dist/animation/rotationtrack.js.map +1 -1
  18. package/dist/animation/scaletrack.js +29 -11
  19. package/dist/animation/scaletrack.js.map +1 -1
  20. package/dist/animation/skeleton.js +241 -78
  21. package/dist/animation/skeleton.js.map +1 -1
  22. package/dist/animation/translationtrack.js +30 -11
  23. package/dist/animation/translationtrack.js.map +1 -1
  24. package/dist/app/api.js +43 -0
  25. package/dist/app/api.js.map +1 -0
  26. package/dist/app/app.js +153 -0
  27. package/dist/app/app.js.map +1 -0
  28. package/dist/app/engine.js +312 -0
  29. package/dist/app/engine.js.map +1 -0
  30. package/dist/app/inputmgr.js +351 -0
  31. package/dist/app/inputmgr.js.map +1 -0
  32. package/dist/app/runtimescript.js +62 -0
  33. package/dist/app/runtimescript.js.map +1 -0
  34. package/dist/app/scriptingsystem.js +220 -0
  35. package/dist/app/scriptingsystem.js.map +1 -0
  36. package/dist/app/scriptregistry.js +432 -0
  37. package/dist/app/scriptregistry.js.map +1 -0
  38. package/dist/asset/assetmanager.js +772 -291
  39. package/dist/asset/assetmanager.js.map +1 -1
  40. package/dist/asset/builtin.js +7 -43
  41. package/dist/asset/builtin.js.map +1 -1
  42. package/dist/asset/loaders/dds/dds.js +17 -93
  43. package/dist/asset/loaders/dds/dds.js.map +1 -1
  44. package/dist/asset/loaders/dds/dds_loader.js +8 -18
  45. package/dist/asset/loaders/dds/dds_loader.js.map +1 -1
  46. package/dist/asset/loaders/gltf/gltf_loader.js +36 -42
  47. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  48. package/dist/asset/loaders/gltf/helpers.js +27 -14
  49. package/dist/asset/loaders/gltf/helpers.js.map +1 -1
  50. package/dist/asset/loaders/hdr/hdr.js +17 -12
  51. package/dist/asset/loaders/hdr/hdr.js.map +1 -1
  52. package/dist/asset/loaders/image/tga_Loader.js +13 -16
  53. package/dist/asset/loaders/image/tga_Loader.js.map +1 -1
  54. package/dist/asset/loaders/image/webimage_loader.js +51 -50
  55. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  56. package/dist/asset/loaders/loader.js.map +1 -1
  57. package/dist/asset/model.js +158 -4
  58. package/dist/asset/model.js.map +1 -1
  59. package/dist/blitter/bilateralblur.js +0 -1
  60. package/dist/blitter/bilateralblur.js.map +1 -1
  61. package/dist/blitter/blitter.js +22 -23
  62. package/dist/blitter/blitter.js.map +1 -1
  63. package/dist/blitter/box.js.map +1 -1
  64. package/dist/blitter/copy.js.map +1 -1
  65. package/dist/blitter/gaussianblur.js +23 -23
  66. package/dist/blitter/gaussianblur.js.map +1 -1
  67. package/dist/camera/base.js +141 -34
  68. package/dist/camera/base.js.map +1 -1
  69. package/dist/camera/camera.js +653 -149
  70. package/dist/camera/camera.js.map +1 -1
  71. package/dist/camera/fps.js +2 -10
  72. package/dist/camera/fps.js.map +1 -1
  73. package/dist/camera/orbit.js +132 -59
  74. package/dist/camera/orbit.js.map +1 -1
  75. package/dist/camera/orthocamera.js +37 -12
  76. package/dist/camera/orthocamera.js.map +1 -1
  77. package/dist/camera/perspectivecamera.js +37 -20
  78. package/dist/camera/perspectivecamera.js.map +1 -1
  79. package/dist/index.d.ts +18268 -6982
  80. package/dist/index.js +49 -16
  81. package/dist/index.js.map +1 -1
  82. package/dist/material/blinn.js +5 -0
  83. package/dist/material/blinn.js.map +1 -1
  84. package/dist/material/grassmaterial.js +6 -1
  85. package/dist/material/grassmaterial.js.map +1 -1
  86. package/dist/material/lambert.js +6 -1
  87. package/dist/material/lambert.js.map +1 -1
  88. package/dist/material/material.js +346 -73
  89. package/dist/material/material.js.map +1 -1
  90. package/dist/material/meshmaterial.js +498 -156
  91. package/dist/material/meshmaterial.js.map +1 -1
  92. package/dist/material/mixins/albedocolor.js +5 -1
  93. package/dist/material/mixins/albedocolor.js.map +1 -1
  94. package/dist/material/mixins/foliage.js +3 -3
  95. package/dist/material/mixins/foliage.js.map +1 -1
  96. package/dist/material/mixins/lightmodel/blinnphong.js +18 -5
  97. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  98. package/dist/material/mixins/lightmodel/lambert.js +6 -6
  99. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  100. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +235 -0
  101. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -0
  102. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +52 -15
  103. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  104. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +27 -9
  105. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  106. package/dist/material/mixins/lit.js +16 -4
  107. package/dist/material/mixins/lit.js.map +1 -1
  108. package/dist/material/mixins/pbr/brdf.js +134 -0
  109. package/dist/material/mixins/pbr/brdf.js.map +1 -0
  110. package/dist/material/mixins/pbr/common.js +68 -85
  111. package/dist/material/mixins/pbr/common.js.map +1 -1
  112. package/dist/material/mixins/texture.js +98 -83
  113. package/dist/material/mixins/texture.js.map +1 -1
  114. package/dist/material/mixins/vertexcolor.js +6 -2
  115. package/dist/material/mixins/vertexcolor.js.map +1 -1
  116. package/dist/material/particle.js +272 -0
  117. package/dist/material/particle.js.map +1 -0
  118. package/dist/material/pbrblueprint.js +186 -0
  119. package/dist/material/pbrblueprint.js.map +1 -0
  120. package/dist/material/pbrmr.js +10 -0
  121. package/dist/material/pbrmr.js.map +1 -1
  122. package/dist/material/pbrsg.js +10 -0
  123. package/dist/material/pbrsg.js.map +1 -1
  124. package/dist/material/shader/helper.js +521 -287
  125. package/dist/material/shader/helper.js.map +1 -1
  126. package/dist/material/terrain-cm.js +607 -0
  127. package/dist/material/terrain-cm.js.map +1 -0
  128. package/dist/material/terrainmaterial.js +59 -54
  129. package/dist/material/terrainmaterial.js.map +1 -1
  130. package/dist/material/unlit.js +5 -0
  131. package/dist/material/unlit.js.map +1 -1
  132. package/dist/material/water.js +415 -0
  133. package/dist/material/water.js.map +1 -0
  134. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  135. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  136. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  137. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  138. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  139. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  140. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  141. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  142. package/dist/node_modules/es-module-lexer/dist/lexer.js +5 -0
  143. package/dist/node_modules/es-module-lexer/dist/lexer.js.map +1 -0
  144. package/dist/posteffect/bloom.js +39 -54
  145. package/dist/posteffect/bloom.js.map +1 -1
  146. package/dist/posteffect/compositor.js +95 -128
  147. package/dist/posteffect/compositor.js.map +1 -1
  148. package/dist/posteffect/fxaa.js +10 -18
  149. package/dist/posteffect/fxaa.js.map +1 -1
  150. package/dist/posteffect/grayscale.js +9 -17
  151. package/dist/posteffect/grayscale.js.map +1 -1
  152. package/dist/posteffect/motionblur.js +105 -0
  153. package/dist/posteffect/motionblur.js.map +1 -0
  154. package/dist/posteffect/posteffect.js +66 -35
  155. package/dist/posteffect/posteffect.js.map +1 -1
  156. package/dist/posteffect/sao.js +13 -21
  157. package/dist/posteffect/sao.js.map +1 -1
  158. package/dist/posteffect/ssr.js +60 -100
  159. package/dist/posteffect/ssr.js.map +1 -1
  160. package/dist/posteffect/taa.js +175 -0
  161. package/dist/posteffect/taa.js.map +1 -0
  162. package/dist/posteffect/tonemap.js +12 -20
  163. package/dist/posteffect/tonemap.js.map +1 -1
  164. package/dist/render/abuffer_oit.js +30 -19
  165. package/dist/render/abuffer_oit.js.map +1 -1
  166. package/dist/render/clipmap.js +429 -101
  167. package/dist/render/clipmap.js.map +1 -1
  168. package/dist/render/cluster_light.js +7 -5
  169. package/dist/render/cluster_light.js.map +1 -1
  170. package/dist/render/cull_visitor.js +43 -3
  171. package/dist/render/cull_visitor.js.map +1 -1
  172. package/dist/render/depthpass.js +14 -5
  173. package/dist/render/depthpass.js.map +1 -1
  174. package/dist/render/drawable_mixin.js +113 -40
  175. package/dist/render/drawable_mixin.js.map +1 -1
  176. package/dist/render/envlight.js +86 -141
  177. package/dist/render/envlight.js.map +1 -1
  178. package/dist/render/fbm_wavegenerator.js +234 -0
  179. package/dist/render/fbm_wavegenerator.js.map +1 -0
  180. package/dist/render/fft_wavegenerator.js +64 -50
  181. package/dist/render/fft_wavegenerator.js.map +1 -1
  182. package/dist/render/fullscreenquad.js +2 -2
  183. package/dist/render/fullscreenquad.js.map +1 -1
  184. package/dist/render/gerstner_wavegenerator.js +98 -48
  185. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  186. package/dist/render/globalbindgroup_allocator.js +4 -2
  187. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  188. package/dist/render/hzb.js +6 -3
  189. package/dist/render/hzb.js.map +1 -1
  190. package/dist/render/lightpass.js +19 -18
  191. package/dist/render/lightpass.js.map +1 -1
  192. package/dist/render/objectcolorpass.js +4 -4
  193. package/dist/render/objectcolorpass.js.map +1 -1
  194. package/dist/render/primitive.js +213 -104
  195. package/dist/render/primitive.js.map +1 -1
  196. package/dist/render/render_queue.js +40 -20
  197. package/dist/render/render_queue.js.map +1 -1
  198. package/dist/render/renderbundle_wrapper.js +65 -15
  199. package/dist/render/renderbundle_wrapper.js.map +1 -1
  200. package/dist/render/renderer.js +326 -185
  201. package/dist/render/renderer.js.map +1 -1
  202. package/dist/render/renderpass.js +20 -36
  203. package/dist/render/renderpass.js.map +1 -1
  204. package/dist/render/shadowmap_pass.js +3 -3
  205. package/dist/render/shadowmap_pass.js.map +1 -1
  206. package/dist/render/sky.js +864 -541
  207. package/dist/render/sky.js.map +1 -1
  208. package/dist/render/weightedblended_oit.js +13 -15
  209. package/dist/render/weightedblended_oit.js.map +1 -1
  210. package/dist/scene/batchgroup.js +18 -5
  211. package/dist/scene/batchgroup.js.map +1 -1
  212. package/dist/scene/environment.js +78 -48
  213. package/dist/scene/environment.js.map +1 -1
  214. package/dist/scene/graph_node.js +2 -3
  215. package/dist/scene/graph_node.js.map +1 -1
  216. package/dist/scene/light.js +28 -89
  217. package/dist/scene/light.js.map +1 -1
  218. package/dist/scene/mesh.js +218 -87
  219. package/dist/scene/mesh.js.map +1 -1
  220. package/dist/scene/octree.js +371 -162
  221. package/dist/scene/octree.js.map +1 -1
  222. package/dist/scene/particlesys.js +684 -0
  223. package/dist/scene/particlesys.js.map +1 -0
  224. package/dist/scene/raycast_visitor.js +34 -5
  225. package/dist/scene/raycast_visitor.js.map +1 -1
  226. package/dist/scene/scene.js +309 -85
  227. package/dist/scene/scene.js.map +1 -1
  228. package/dist/scene/scene_node.js +675 -102
  229. package/dist/scene/scene_node.js.map +1 -1
  230. package/dist/scene/terrain/grass.js +48 -49
  231. package/dist/scene/terrain/grass.js.map +1 -1
  232. package/dist/scene/terrain/heightfield.js +46 -44
  233. package/dist/scene/terrain/heightfield.js.map +1 -1
  234. package/dist/scene/terrain/patch.js +20 -29
  235. package/dist/scene/terrain/patch.js.map +1 -1
  236. package/dist/scene/terrain/quadtree.js +58 -27
  237. package/dist/scene/terrain/quadtree.js.map +1 -1
  238. package/dist/scene/terrain/terrain.js +31 -45
  239. package/dist/scene/terrain/terrain.js.map +1 -1
  240. package/dist/scene/terrain-cm/grass.js +603 -0
  241. package/dist/scene/terrain-cm/grass.js.map +1 -0
  242. package/dist/scene/terrain-cm/grassmaterial.js +160 -0
  243. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -0
  244. package/dist/scene/terrain-cm/terrain-cm.js +533 -0
  245. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -0
  246. package/dist/scene/water.js +378 -0
  247. package/dist/scene/water.js.map +1 -0
  248. package/dist/shaders/atmosphere.js +957 -0
  249. package/dist/shaders/atmosphere.js.map +1 -0
  250. package/dist/shaders/fog.js +116 -0
  251. package/dist/shaders/fog.js.map +1 -0
  252. package/dist/shaders/misc.js.map +1 -1
  253. package/dist/shaders/noise.js +217 -8
  254. package/dist/shaders/noise.js.map +1 -1
  255. package/dist/shaders/pbr.js.map +1 -1
  256. package/dist/shaders/shadow.js +8 -8
  257. package/dist/shaders/shadow.js.map +1 -1
  258. package/dist/shaders/ssr.js +87 -39
  259. package/dist/shaders/ssr.js.map +1 -1
  260. package/dist/shaders/temporal.js +216 -0
  261. package/dist/shaders/temporal.js.map +1 -0
  262. package/dist/shaders/water.js +42 -20
  263. package/dist/shaders/water.js.map +1 -1
  264. package/dist/shadow/esm.js +31 -13
  265. package/dist/shadow/esm.js.map +1 -1
  266. package/dist/shadow/pcf_opt.js +12 -13
  267. package/dist/shadow/pcf_opt.js.map +1 -1
  268. package/dist/shadow/pcf_pd.js +12 -13
  269. package/dist/shadow/pcf_pd.js.map +1 -1
  270. package/dist/shadow/shader.js +38 -0
  271. package/dist/shadow/shader.js.map +1 -0
  272. package/dist/shadow/shadow_impl.js.map +1 -1
  273. package/dist/shadow/shadowmapper.js +67 -26
  274. package/dist/shadow/shadowmapper.js.map +1 -1
  275. package/dist/shadow/ssm.js +15 -16
  276. package/dist/shadow/ssm.js.map +1 -1
  277. package/dist/shadow/vsm.js +33 -16
  278. package/dist/shadow/vsm.js.map +1 -1
  279. package/dist/shapes/box.js +181 -83
  280. package/dist/shapes/box.js.map +1 -1
  281. package/dist/shapes/cylinder.js +101 -43
  282. package/dist/shapes/cylinder.js.map +1 -1
  283. package/dist/shapes/plane.js +70 -29
  284. package/dist/shapes/plane.js.map +1 -1
  285. package/dist/shapes/shape.js +120 -17
  286. package/dist/shapes/shape.js.map +1 -1
  287. package/dist/shapes/sphere.js +78 -44
  288. package/dist/shapes/sphere.js.map +1 -1
  289. package/dist/shapes/tetrahedron.js +256 -0
  290. package/dist/shapes/tetrahedron.js.map +1 -0
  291. package/dist/shapes/torus.js +76 -55
  292. package/dist/shapes/torus.js.map +1 -1
  293. package/dist/src/animation/animation.js +127 -0
  294. package/dist/src/animation/animation.js.map +1 -0
  295. package/dist/src/animation/animationset.js +255 -0
  296. package/dist/src/animation/animationset.js.map +1 -0
  297. package/dist/src/animation/animationtrack.js +34 -0
  298. package/dist/src/animation/animationtrack.js.map +1 -0
  299. package/dist/src/animation/eulerrotationtrack.js +52 -0
  300. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  301. package/dist/src/animation/morphtarget.js +93 -0
  302. package/dist/src/animation/morphtarget.js.map +1 -0
  303. package/dist/src/animation/morphtrack.js +70 -0
  304. package/dist/src/animation/morphtrack.js.map +1 -0
  305. package/dist/src/animation/proptrack.js +161 -0
  306. package/dist/src/animation/proptrack.js.map +1 -0
  307. package/dist/src/animation/rotationtrack.js +51 -0
  308. package/dist/src/animation/rotationtrack.js.map +1 -0
  309. package/dist/src/animation/scaletrack.js +50 -0
  310. package/dist/src/animation/scaletrack.js.map +1 -0
  311. package/dist/src/animation/skeleton.js +204 -0
  312. package/dist/src/animation/skeleton.js.map +1 -0
  313. package/dist/src/animation/translationtrack.js +50 -0
  314. package/dist/src/animation/translationtrack.js.map +1 -0
  315. package/dist/{app.js → src/app/app.js} +18 -40
  316. package/dist/src/app/app.js.map +1 -0
  317. package/dist/{input → src/app}/inputmgr.js +41 -16
  318. package/dist/src/app/inputmgr.js.map +1 -0
  319. package/dist/src/asset/assetmanager.js +404 -0
  320. package/dist/src/asset/assetmanager.js.map +1 -0
  321. package/dist/src/asset/builtin.js +337 -0
  322. package/dist/src/asset/builtin.js.map +1 -0
  323. package/dist/src/asset/loaders/dds/dds.js +470 -0
  324. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  325. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  326. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  327. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  328. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  329. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  330. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  331. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  332. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  333. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  334. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  335. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  336. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  337. package/dist/src/asset/loaders/loader.js +45 -0
  338. package/dist/src/asset/loaders/loader.js.map +1 -0
  339. package/dist/src/asset/model.js +414 -0
  340. package/dist/src/asset/model.js.map +1 -0
  341. package/dist/{blitter/depthlimitedgaussion.js → src/blitter/bilateralblur.js} +1 -2
  342. package/dist/src/blitter/bilateralblur.js.map +1 -0
  343. package/dist/src/blitter/blitter.js +390 -0
  344. package/dist/src/blitter/blitter.js.map +1 -0
  345. package/dist/src/blitter/box.js +118 -0
  346. package/dist/src/blitter/box.js.map +1 -0
  347. package/dist/src/blitter/copy.js +22 -0
  348. package/dist/src/blitter/copy.js.map +1 -0
  349. package/dist/src/blitter/gaussianblur.js +228 -0
  350. package/dist/src/blitter/gaussianblur.js.map +1 -0
  351. package/dist/src/camera/base.js +92 -0
  352. package/dist/src/camera/base.js.map +1 -0
  353. package/dist/src/camera/camera.js +1005 -0
  354. package/dist/src/camera/camera.js.map +1 -0
  355. package/dist/src/camera/fps.js +238 -0
  356. package/dist/src/camera/fps.js.map +1 -0
  357. package/dist/src/camera/orbit.js +245 -0
  358. package/dist/src/camera/orbit.js.map +1 -0
  359. package/dist/src/camera/orthocamera.js +167 -0
  360. package/dist/src/camera/orthocamera.js.map +1 -0
  361. package/dist/src/camera/perspectivecamera.js +141 -0
  362. package/dist/src/camera/perspectivecamera.js.map +1 -0
  363. package/dist/src/index.js +120 -0
  364. package/dist/src/index.js.map +1 -0
  365. package/dist/src/material/blinn.js +81 -0
  366. package/dist/src/material/blinn.js.map +1 -0
  367. package/dist/src/material/grassmaterial.js +113 -0
  368. package/dist/src/material/grassmaterial.js.map +1 -0
  369. package/dist/src/material/lambert.js +92 -0
  370. package/dist/src/material/lambert.js.map +1 -0
  371. package/dist/src/material/material.js +301 -0
  372. package/dist/src/material/material.js.map +1 -0
  373. package/dist/src/material/meshmaterial.js +704 -0
  374. package/dist/src/material/meshmaterial.js.map +1 -0
  375. package/dist/src/material/mixins/albedocolor.js +76 -0
  376. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  377. package/dist/src/material/mixins/foliage.js +47 -0
  378. package/dist/src/material/mixins/foliage.js.map +1 -0
  379. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  380. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  381. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  382. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  383. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  384. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  385. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  386. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  387. package/dist/src/material/mixins/lit.js +476 -0
  388. package/dist/src/material/mixins/lit.js.map +1 -0
  389. package/dist/src/material/mixins/pbr/common.js +918 -0
  390. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  391. package/dist/src/material/mixins/texture.js +172 -0
  392. package/dist/src/material/mixins/texture.js.map +1 -0
  393. package/dist/src/material/mixins/vertexcolor.js +56 -0
  394. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  395. package/dist/src/material/particle.js +178 -0
  396. package/dist/src/material/particle.js.map +1 -0
  397. package/dist/src/material/pbrmr.js +97 -0
  398. package/dist/src/material/pbrmr.js.map +1 -0
  399. package/dist/src/material/pbrsg.js +97 -0
  400. package/dist/src/material/pbrsg.js.map +1 -0
  401. package/dist/src/material/shader/helper.js +1209 -0
  402. package/dist/src/material/shader/helper.js.map +1 -0
  403. package/dist/src/material/terrain-cm.js +606 -0
  404. package/dist/src/material/terrain-cm.js.map +1 -0
  405. package/dist/src/material/terrainmaterial.js +375 -0
  406. package/dist/src/material/terrainmaterial.js.map +1 -0
  407. package/dist/src/material/unlit.js +41 -0
  408. package/dist/src/material/unlit.js.map +1 -0
  409. package/dist/src/material/water.js +417 -0
  410. package/dist/src/material/water.js.map +1 -0
  411. package/dist/src/posteffect/bloom.js +361 -0
  412. package/dist/src/posteffect/bloom.js.map +1 -0
  413. package/dist/src/posteffect/compositor.js +226 -0
  414. package/dist/src/posteffect/compositor.js.map +1 -0
  415. package/dist/src/posteffect/fxaa.js +273 -0
  416. package/dist/src/posteffect/fxaa.js.map +1 -0
  417. package/dist/src/posteffect/grayscale.js +69 -0
  418. package/dist/src/posteffect/grayscale.js.map +1 -0
  419. package/dist/src/posteffect/motionblur.js +96 -0
  420. package/dist/src/posteffect/motionblur.js.map +1 -0
  421. package/dist/src/posteffect/posteffect.js +126 -0
  422. package/dist/src/posteffect/posteffect.js.map +1 -0
  423. package/dist/src/posteffect/sao.js +324 -0
  424. package/dist/src/posteffect/sao.js.map +1 -0
  425. package/dist/src/posteffect/ssr.js +489 -0
  426. package/dist/src/posteffect/ssr.js.map +1 -0
  427. package/dist/src/posteffect/taa.js +172 -0
  428. package/dist/src/posteffect/taa.js.map +1 -0
  429. package/dist/src/posteffect/tonemap.js +94 -0
  430. package/dist/src/posteffect/tonemap.js.map +1 -0
  431. package/dist/src/render/abuffer_oit.js +361 -0
  432. package/dist/src/render/abuffer_oit.js.map +1 -0
  433. package/dist/src/render/clipmap.js +851 -0
  434. package/dist/src/render/clipmap.js.map +1 -0
  435. package/dist/src/render/cluster_light.js +333 -0
  436. package/dist/src/render/cluster_light.js.map +1 -0
  437. package/dist/src/render/cull_visitor.js +187 -0
  438. package/dist/src/render/cull_visitor.js.map +1 -0
  439. package/dist/src/render/depthpass.js +68 -0
  440. package/dist/src/render/depthpass.js.map +1 -0
  441. package/dist/src/render/drawable_mixin.js +227 -0
  442. package/dist/src/render/drawable_mixin.js.map +1 -0
  443. package/dist/src/render/envlight.js +463 -0
  444. package/dist/src/render/envlight.js.map +1 -0
  445. package/dist/src/render/fbm_wavegenerator.js +251 -0
  446. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  447. package/dist/src/render/fft_wavegenerator.js +1006 -0
  448. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  449. package/dist/src/render/fullscreenquad.js +38 -0
  450. package/dist/src/render/fullscreenquad.js.map +1 -0
  451. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  452. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  453. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  454. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  455. package/dist/src/render/hzb.js +273 -0
  456. package/dist/src/render/hzb.js.map +1 -0
  457. package/dist/src/render/lightpass.js +172 -0
  458. package/dist/src/render/lightpass.js.map +1 -0
  459. package/dist/src/render/objectcolorpass.js +51 -0
  460. package/dist/src/render/objectcolorpass.js.map +1 -0
  461. package/dist/src/render/primitive.js +364 -0
  462. package/dist/src/render/primitive.js.map +1 -0
  463. package/dist/src/render/render_queue.js +467 -0
  464. package/dist/src/render/render_queue.js.map +1 -0
  465. package/dist/src/render/renderbundle_wrapper.js +152 -0
  466. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  467. package/dist/src/render/renderer.js +455 -0
  468. package/dist/src/render/renderer.js.map +1 -0
  469. package/dist/src/render/renderpass.js +200 -0
  470. package/dist/src/render/renderpass.js.map +1 -0
  471. package/dist/src/render/shadowmap_pass.js +56 -0
  472. package/dist/src/render/shadowmap_pass.js.map +1 -0
  473. package/dist/src/render/sky.js +1103 -0
  474. package/dist/src/render/sky.js.map +1 -0
  475. package/dist/src/render/weightedblended_oit.js +168 -0
  476. package/dist/src/render/weightedblended_oit.js.map +1 -0
  477. package/dist/src/scene/batchgroup.js +162 -0
  478. package/dist/src/scene/batchgroup.js.map +1 -0
  479. package/dist/src/scene/environment.js +209 -0
  480. package/dist/src/scene/environment.js.map +1 -0
  481. package/dist/src/scene/graph_node.js +72 -0
  482. package/dist/src/scene/graph_node.js.map +1 -0
  483. package/dist/src/scene/light.js +416 -0
  484. package/dist/src/scene/light.js.map +1 -0
  485. package/dist/src/scene/mesh.js +341 -0
  486. package/dist/src/scene/mesh.js.map +1 -0
  487. package/dist/src/scene/octree.js +649 -0
  488. package/dist/src/scene/octree.js.map +1 -0
  489. package/dist/src/scene/particlesys.js +738 -0
  490. package/dist/src/scene/particlesys.js.map +1 -0
  491. package/dist/src/scene/raycast_visitor.js +103 -0
  492. package/dist/src/scene/raycast_visitor.js.map +1 -0
  493. package/dist/src/scene/scene.js +284 -0
  494. package/dist/src/scene/scene.js.map +1 -0
  495. package/dist/src/scene/scene_node.js +732 -0
  496. package/dist/src/scene/scene_node.js.map +1 -0
  497. package/dist/src/scene/terrain/grass.js +278 -0
  498. package/dist/src/scene/terrain/grass.js.map +1 -0
  499. package/dist/src/scene/terrain/heightfield.js +475 -0
  500. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  501. package/dist/src/scene/terrain/patch.js +530 -0
  502. package/dist/src/scene/terrain/patch.js.map +1 -0
  503. package/dist/src/scene/terrain/quadtree.js +461 -0
  504. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  505. package/dist/src/scene/terrain/terrain.js +246 -0
  506. package/dist/src/scene/terrain/terrain.js.map +1 -0
  507. package/dist/src/scene/terrain-cm/grass.js +594 -0
  508. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  509. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  510. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  511. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  512. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  513. package/dist/src/scene/water.js +374 -0
  514. package/dist/src/scene/water.js.map +1 -0
  515. package/dist/src/shaders/atmosphere.js +957 -0
  516. package/dist/src/shaders/atmosphere.js.map +1 -0
  517. package/dist/src/shaders/fog.js +112 -0
  518. package/dist/src/shaders/fog.js.map +1 -0
  519. package/dist/src/shaders/misc.js +266 -0
  520. package/dist/src/shaders/misc.js.map +1 -0
  521. package/dist/src/shaders/noise.js +222 -0
  522. package/dist/src/shaders/noise.js.map +1 -0
  523. package/dist/src/shaders/pbr.js +51 -0
  524. package/dist/src/shaders/pbr.js.map +1 -0
  525. package/dist/src/shaders/shadow.js +636 -0
  526. package/dist/src/shaders/shadow.js.map +1 -0
  527. package/dist/src/shaders/ssr.js +490 -0
  528. package/dist/src/shaders/ssr.js.map +1 -0
  529. package/dist/src/shaders/temporal.js +215 -0
  530. package/dist/src/shaders/temporal.js.map +1 -0
  531. package/dist/src/shaders/water.js +756 -0
  532. package/dist/src/shaders/water.js.map +1 -0
  533. package/dist/src/shadow/esm.js +237 -0
  534. package/dist/src/shadow/esm.js.map +1 -0
  535. package/dist/src/shadow/pcf_opt.js +181 -0
  536. package/dist/src/shadow/pcf_opt.js.map +1 -0
  537. package/dist/src/shadow/pcf_pd.js +189 -0
  538. package/dist/src/shadow/pcf_pd.js.map +1 -0
  539. package/dist/src/shadow/shader.js +37 -0
  540. package/dist/src/shadow/shader.js.map +1 -0
  541. package/dist/src/shadow/shadow_impl.js +15 -0
  542. package/dist/src/shadow/shadow_impl.js.map +1 -0
  543. package/dist/src/shadow/shadowmapper.js +790 -0
  544. package/dist/src/shadow/shadowmapper.js.map +1 -0
  545. package/dist/src/shadow/ssm.js +159 -0
  546. package/dist/src/shadow/ssm.js.map +1 -0
  547. package/dist/src/shadow/vsm.js +297 -0
  548. package/dist/src/shadow/vsm.js.map +1 -0
  549. package/dist/src/shapes/box.js +386 -0
  550. package/dist/src/shapes/box.js.map +1 -0
  551. package/dist/src/shapes/cylinder.js +125 -0
  552. package/dist/src/shapes/cylinder.js.map +1 -0
  553. package/dist/src/shapes/plane.js +88 -0
  554. package/dist/src/shapes/plane.js.map +1 -0
  555. package/dist/src/shapes/shape.js +87 -0
  556. package/dist/src/shapes/shape.js.map +1 -0
  557. package/dist/src/shapes/sphere.js +114 -0
  558. package/dist/src/shapes/sphere.js.map +1 -0
  559. package/dist/src/shapes/tetrahedron.js +188 -0
  560. package/dist/src/shapes/tetrahedron.js.map +1 -0
  561. package/dist/src/shapes/torus.js +111 -0
  562. package/dist/src/shapes/torus.js.map +1 -0
  563. package/dist/src/utility/aabbtree.js +400 -0
  564. package/dist/src/utility/aabbtree.js.map +1 -0
  565. package/dist/src/utility/bounding_volume.js +29 -0
  566. package/dist/src/utility/bounding_volume.js.map +1 -0
  567. package/dist/src/utility/debug.js +28 -0
  568. package/dist/src/utility/debug.js.map +1 -0
  569. package/dist/src/utility/draco/decoder.js +116 -0
  570. package/dist/src/utility/draco/decoder.js.map +1 -0
  571. package/dist/src/utility/misc.js +105 -0
  572. package/dist/src/utility/misc.js.map +1 -0
  573. package/dist/src/utility/panorama.js +163 -0
  574. package/dist/src/utility/panorama.js.map +1 -0
  575. package/dist/src/utility/pmrem.js +354 -0
  576. package/dist/src/utility/pmrem.js.map +1 -0
  577. package/dist/src/utility/rendermipmap.js +115 -0
  578. package/dist/src/utility/rendermipmap.js.map +1 -0
  579. package/dist/src/utility/serialization/json.js +402 -0
  580. package/dist/src/utility/serialization/json.js.map +1 -0
  581. package/dist/src/utility/serialization/manager.js +623 -0
  582. package/dist/src/utility/serialization/manager.js.map +1 -0
  583. package/dist/src/utility/serialization/scene/animation.js +248 -0
  584. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  585. package/dist/src/utility/serialization/scene/batch.js +59 -0
  586. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  587. package/dist/src/utility/serialization/scene/camera.js +790 -0
  588. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  589. package/dist/src/utility/serialization/scene/common.js +222 -0
  590. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  591. package/dist/src/utility/serialization/scene/light.js +575 -0
  592. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  593. package/dist/src/utility/serialization/scene/material.js +1111 -0
  594. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  595. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  596. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  597. package/dist/src/utility/serialization/scene/misc.js +39 -0
  598. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  599. package/dist/src/utility/serialization/scene/node.js +451 -0
  600. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  601. package/dist/src/utility/serialization/scene/particle.js +425 -0
  602. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  603. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  604. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  605. package/dist/src/utility/serialization/scene/scene.js +704 -0
  606. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  607. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  608. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  609. package/dist/src/utility/serialization/scene/water.js +465 -0
  610. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  611. package/dist/src/utility/shprojector.js +297 -0
  612. package/dist/src/utility/shprojector.js.map +1 -0
  613. package/dist/{material/mixins → src/utility/textures}/ggxlut.js +1 -1
  614. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  615. package/dist/src/utility/textures/gradientnoise.js +62 -0
  616. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  617. package/dist/src/utility/textures/randomnoise.js +41 -0
  618. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  619. package/dist/src/values.js +162 -0
  620. package/dist/src/values.js.map +1 -0
  621. package/dist/utility/aabbtree.js +15 -5
  622. package/dist/utility/aabbtree.js.map +1 -1
  623. package/dist/utility/blueprint/common/constants.js +851 -0
  624. package/dist/utility/blueprint/common/constants.js.map +1 -0
  625. package/dist/utility/blueprint/common/math.js +2045 -0
  626. package/dist/utility/blueprint/common/math.js.map +1 -0
  627. package/dist/utility/blueprint/common.js +7 -0
  628. package/dist/utility/blueprint/common.js.map +1 -0
  629. package/dist/utility/blueprint/material/common.js +7 -0
  630. package/dist/utility/blueprint/material/common.js.map +1 -0
  631. package/dist/utility/blueprint/material/func.js +521 -0
  632. package/dist/utility/blueprint/material/func.js.map +1 -0
  633. package/dist/utility/blueprint/material/inputs.js +1659 -0
  634. package/dist/utility/blueprint/material/inputs.js.map +1 -0
  635. package/dist/utility/blueprint/material/ir.js +1311 -0
  636. package/dist/utility/blueprint/material/ir.js.map +1 -0
  637. package/dist/utility/blueprint/material/pbr.js +362 -0
  638. package/dist/utility/blueprint/material/pbr.js.map +1 -0
  639. package/dist/utility/blueprint/material/texture.js +1099 -0
  640. package/dist/utility/blueprint/material/texture.js.map +1 -0
  641. package/dist/utility/blueprint/node.js +187 -0
  642. package/dist/utility/blueprint/node.js.map +1 -0
  643. package/dist/utility/bounding_volume.js +0 -1
  644. package/dist/utility/bounding_volume.js.map +1 -1
  645. package/dist/utility/debug.js +26 -0
  646. package/dist/utility/debug.js.map +1 -0
  647. package/dist/utility/draco/decoder.js +1 -1
  648. package/dist/utility/draco/decoder.js.map +1 -1
  649. package/dist/utility/misc.js +18 -6
  650. package/dist/utility/misc.js.map +1 -1
  651. package/dist/utility/panorama.js +8 -6
  652. package/dist/utility/panorama.js.map +1 -1
  653. package/dist/utility/pmrem.js +30 -18
  654. package/dist/utility/pmrem.js.map +1 -1
  655. package/dist/utility/rendermipmap.js +116 -0
  656. package/dist/utility/rendermipmap.js.map +1 -0
  657. package/dist/utility/serialization/blueprint/constants.js +255 -0
  658. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  659. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  660. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  661. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  662. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  663. package/dist/utility/serialization/json.js +402 -0
  664. package/dist/utility/serialization/json.js.map +1 -0
  665. package/dist/utility/serialization/manager.js +1176 -0
  666. package/dist/utility/serialization/manager.js.map +1 -0
  667. package/dist/utility/serialization/scene/animation.js +699 -0
  668. package/dist/utility/serialization/scene/animation.js.map +1 -0
  669. package/dist/utility/serialization/scene/batch.js +53 -0
  670. package/dist/utility/serialization/scene/batch.js.map +1 -0
  671. package/dist/utility/serialization/scene/camera.js +808 -0
  672. package/dist/utility/serialization/scene/camera.js.map +1 -0
  673. package/dist/utility/serialization/scene/common.js +224 -0
  674. package/dist/utility/serialization/scene/common.js.map +1 -0
  675. package/dist/utility/serialization/scene/light.js +589 -0
  676. package/dist/utility/serialization/scene/light.js.map +1 -0
  677. package/dist/utility/serialization/scene/material.js +942 -0
  678. package/dist/utility/serialization/scene/material.js.map +1 -0
  679. package/dist/utility/serialization/scene/mesh.js +374 -0
  680. package/dist/utility/serialization/scene/mesh.js.map +1 -0
  681. package/dist/utility/serialization/scene/misc.js +39 -0
  682. package/dist/utility/serialization/scene/misc.js.map +1 -0
  683. package/dist/utility/serialization/scene/node.js +391 -0
  684. package/dist/utility/serialization/scene/node.js.map +1 -0
  685. package/dist/utility/serialization/scene/particle.js +425 -0
  686. package/dist/utility/serialization/scene/particle.js.map +1 -0
  687. package/dist/utility/serialization/scene/primitive.js +582 -0
  688. package/dist/utility/serialization/scene/primitive.js.map +1 -0
  689. package/dist/utility/serialization/scene/scene.js +763 -0
  690. package/dist/utility/serialization/scene/scene.js.map +1 -0
  691. package/dist/utility/serialization/scene/terrain.js +495 -0
  692. package/dist/utility/serialization/scene/terrain.js.map +1 -0
  693. package/dist/utility/serialization/scene/water.js +465 -0
  694. package/dist/utility/serialization/scene/water.js.map +1 -0
  695. package/dist/utility/shprojector.js +313 -0
  696. package/dist/utility/shprojector.js.map +1 -0
  697. package/dist/utility/textures/ggxlut.js +4 -5
  698. package/dist/utility/textures/ggxlut.js.map +1 -1
  699. package/dist/utility/textures/gradientnoise.js +2 -1
  700. package/dist/utility/textures/gradientnoise.js.map +1 -1
  701. package/dist/utility/textures/randomnoise.js +1 -0
  702. package/dist/utility/textures/randomnoise.js.map +1 -1
  703. package/dist/values.js +91 -4
  704. package/dist/values.js.map +1 -1
  705. package/package.json +29 -15
  706. package/dist/app.js.map +0 -1
  707. package/dist/blitter/depthlimitedgaussion.js.map +0 -1
  708. package/dist/input/inputmgr.js.map +0 -1
  709. package/dist/material/mixins/ggxlut.js.map +0 -1
  710. package/dist/posteffect/water.js +0 -508
  711. package/dist/posteffect/water.js.map +0 -1
  712. package/dist/render/oit.js +0 -16
  713. package/dist/render/oit.js.map +0 -1
  714. package/dist/render/scatteringlut.js +0 -634
  715. package/dist/render/scatteringlut.js.map +0 -1
  716. package/dist/render/watermesh.js +0 -193
  717. package/dist/render/watermesh.js.map +0 -1
  718. package/dist/render/wavegenerator.js +0 -8
  719. package/dist/render/wavegenerator.js.map +0 -1
  720. package/dist/scene/xform.js +0 -247
  721. package/dist/scene/xform.js.map +0 -1
  722. package/dist/utility/shprojection.js +0 -442
  723. package/dist/utility/shprojection.js.map +0 -1
@@ -1,97 +1,334 @@
1
- import { XForm } from './xform.js';
1
+ import { makeObservable, Disposable, randomUUID, DRef, ObservableVector3, ObservableQuaternion, Matrix4x4, Vector3, Vector4 } from '@zephyr3d/base';
2
+ import { AnimationSet } from '../animation/animationset.js';
3
+ import '../animation/eulerrotationtrack.js';
4
+ import '../values.js';
5
+ import { getEngine } from '../app/api.js';
6
+ import '../animation/skeleton.js';
2
7
 
3
8
  /**
4
- * The base class for any kind of scene objects
9
+ * The base class of all scene graph objects.
5
10
  *
6
11
  * @remarks
7
- * We use a data structure called SceneGraph to store scenes,
8
- * which consists of a couple of scene objects forming a
9
- * hierarchical structure. This is the base class for any kind
10
- * of the scene object, which contains the basic properties such
11
- * as position, rotation, and scale of the object.
12
+ * Responsibilities:
13
+ * - Defines hierarchical transform (position, rotation, scale) with lazily computed matrices.
14
+ * - Integrates with the scene graph (parent/children, attachment notifications).
15
+ * - Provides traversal utilities (`iterate`, `iterateBottomToTop`, `traverse`).
16
+ * - Manages visibility state and CPU/GPU picking flags.
17
+ * - Computes and caches local/world bounding volumes, notifies scene for spatial updates.
18
+ * - Supports cloning and shared model instancing.
19
+ * - Emits events on visibility, transform, bounding volume, attachment, and disposal.
20
+ *
21
+ * Performance:
22
+ * - `localMatrix`, `worldMatrix`, and `invWorldMatrix` are cached until invalidated.
23
+ * - Transform mutations and `invalidateBoundingVolume` update caches and spatial structures.
24
+ *
25
+ * Events:
26
+ * - `nodeattached`, `noderemoved`, `visiblechanged`, `transformchanged`, `bvchanged`, `dispose`.
12
27
  *
13
28
  * @public
14
- */ class SceneNode extends XForm {
29
+ */ class SceneNode extends makeObservable(Disposable)() {
30
+ static _runTimeId = 1;
15
31
  /*
16
32
  static readonly PICK_INHERITED = -1;
17
33
  static readonly PICK_DISABLED = 0;
18
34
  static readonly PICK_ENABLED = 1;
19
- */ static BBOXDRAW_INHERITED = -1;
20
- static BBOXDRAW_DISABLED = 0;
21
- static BBOXDRAW_LOCAL = 1;
22
- static BBOXDRAW_WORLD = 2;
23
- /** @internal */ _clipMode;
24
- /** @internal */ _boxDrawMode;
25
- /** @internal */ _visible;
26
- /** @internal */ _pickMode;
27
- /** @internal */ _name;
28
- /** @internal */ _scene;
29
- /** @internal */ _bv;
30
- /** @internal */ _bvDirty;
31
- /** @internal */ _bvWorld;
32
- /** @internal */ _placeToOctree;
33
- /**
34
- * Creates a new scene node
35
- * @param scene - Which scene the node belongs to
35
+ */ /** Bounding-box draw mode inherited from nearest graph ancestor. */ static BBOXDRAW_INHERITED = -1;
36
+ /** Disable bounding-box visualization. */ static BBOXDRAW_DISABLED = 0;
37
+ /** Draw local-space bounding box. */ static BBOXDRAW_LOCAL = 1;
38
+ /** Draw world-space bounding box. */ static BBOXDRAW_WORLD = 2;
39
+ /** @internal Runtime unique id. */ _runtimeId;
40
+ /** @internal Unique persistent id. */ _id;
41
+ /** @internal Prefab id */ _prefabId;
42
+ /** @internal Animation set reference. */ _animationSet;
43
+ /** @internal Optional shared model reference for instancing. */ _sharedModel;
44
+ /** @internal */ _jointTypeT;
45
+ /** @internal */ _jointTypeS;
46
+ /** @internal */ _jointTypeR;
47
+ /** @internal Clip test flag used by renderer. */ _clipMode;
48
+ /** @internal Bounding-box visualization mode. */ _boxDrawMode;
49
+ /** @internal Visibility state ('visible'|'hidden'|'inherit'). */ _visible;
50
+ /** @internal CPU picking flag. */ _pickable;
51
+ /** @internal GPU picking flag. */ _gpuPickable;
52
+ /** @internal Friendly name for debugging/UI. */ _name;
53
+ /** @internal Owning scene. */ _scene;
54
+ /** @internal Local-space bounding volume cache. */ _bv;
55
+ /** @internal True if local BV needs recomputing. */ _bvDirty;
56
+ /** @internal World-space bounding volume cache. */ _bvWorld;
57
+ /** @internal Whether this node participates in scene spatial structures (octree). */ _placeToOctree;
58
+ /** @internal If true, this node cannot be cloned/attached as a child (engine policy). */ _sealed;
59
+ /** @internal Parent node. */ _parent;
60
+ /** @internal Children list (DRef for memory/resource mgmt). */ _children;
61
+ /** @internal Local position (observable). */ _position;
62
+ /** @internal Local scale (observable). */ _scaling;
63
+ /** @internal Local rotation (observable quaternion). */ _rotation;
64
+ /** @internal Local transform matrix cache. */ _localMatrix;
65
+ /** @internal World transform matrix cache. */ _worldMatrix;
66
+ /** @internal Determinant of world transform (cached). */ _worldMatrixDet;
67
+ /** @internal Inverse world transform matrix cache. */ _invWorldMatrix;
68
+ /** @internal Scratch local matrix to avoid allocations. */ _tmpLocalMatrix;
69
+ /** @internal Scratch world matrix to avoid allocations. */ _tmpWorldMatrix;
70
+ /** @internal Monotonically increasing tag for transform changes. */ _transformTag;
71
+ /** @internal Shared callback used by observables on transform mutation. */ _transformChangeCallback;
72
+ /** @internal Arbitrary metadata payload for this node. */ _metaData;
73
+ /** @internal If true, suppress transform-change callbacks (during bulk updates). */ _disableCallback;
74
+ /** @internal User-attached script entry (engine-defined). */ _script;
75
+ /**
76
+ * Construct a scene node.
77
+ *
78
+ * @remarks
79
+ * If a `scene` is provided and this is not the root node, the node is reparented
80
+ * under the scene's root immediately.
81
+ *
82
+ * @param scene - Scene that will own this node.
36
83
  */ constructor(scene){
37
84
  super();
85
+ this._runtimeId = SceneNode._runTimeId++;
86
+ this._id = randomUUID();
87
+ this._prefabId = '';
38
88
  this._scene = scene;
39
89
  this._name = '';
90
+ this._animationSet = new DRef();
91
+ this._sharedModel = new DRef();
92
+ this._jointTypeT = 'none';
93
+ this._jointTypeS = 'none';
94
+ this._jointTypeR = 'none';
40
95
  this._bv = null;
41
96
  this._bvWorld = null;
42
97
  this._bvDirty = true;
43
98
  this._clipMode = true;
44
99
  this._boxDrawMode = SceneNode.BBOXDRAW_DISABLED;
45
100
  this._visible = 'inherit';
46
- this._pickMode = false;
101
+ this._pickable = false;
102
+ this._gpuPickable = true;
47
103
  this._placeToOctree = true;
104
+ this._parent = null;
105
+ this._sealed = false;
106
+ this._children = [];
107
+ this._transformChangeCallback = ()=>this._onTransformChanged(true);
108
+ this._position = new ObservableVector3(0, 0, 0);
109
+ this._position.callback = this._transformChangeCallback;
110
+ this._scaling = new ObservableVector3(1, 1, 1);
111
+ this._scaling.callback = this._transformChangeCallback;
112
+ this._rotation = new ObservableQuaternion();
113
+ this._rotation.callback = this._transformChangeCallback;
114
+ this._worldMatrix = null;
115
+ this._worldMatrixDet = null;
116
+ this._invWorldMatrix = null;
117
+ this._localMatrix = null;
118
+ this._transformTag = 0;
119
+ this._disableCallback = false;
120
+ this._tmpLocalMatrix = Matrix4x4.identity();
121
+ this._tmpWorldMatrix = Matrix4x4.identity();
122
+ this._script = '';
123
+ this._metaData = null;
48
124
  if (scene && this !== scene.rootNode) {
49
125
  this.reparent(scene.rootNode);
50
126
  }
51
127
  }
52
- /** @internal */ get placeToOctree() {
128
+ /**
129
+ * Whether the node should be inserted into the scene's spatial structure.
130
+ *
131
+ * @remarks
132
+ * Toggling this hints the scene to (re)place the node in octree/acceleration structures.
133
+ */ get placeToOctree() {
53
134
  return this._placeToOctree;
54
135
  }
55
136
  set placeToOctree(val) {
56
137
  if (!!val !== this._placeToOctree) {
57
138
  this._placeToOctree = !!val;
58
139
  if (this.isGraphNode()) {
59
- this.scene.invalidateNodePlacement(this);
140
+ this.scene?.invalidateNodePlacement(this);
60
141
  }
61
142
  }
62
143
  }
63
144
  /**
64
- * Name of the scene node
145
+ * Node's runtime unique identifier
146
+ */ get runtimeId() {
147
+ return this._runtimeId;
148
+ }
149
+ /**
150
+ * Node's persistent identifier.
151
+ *
152
+ * @remarks
153
+ * Changing this affects serialization and registry lookup; ensure uniqueness.
154
+ */ get persistentId() {
155
+ return this._id;
156
+ }
157
+ set persistentId(id) {
158
+ this._id = id;
159
+ }
160
+ /**
161
+ * If not empty, this node was loaded from a prefab
162
+ *
163
+ * @remarks
164
+ * Internal used for serialization
165
+ */ get prefabId() {
166
+ return this._prefabId;
167
+ }
168
+ set prefabId(id) {
169
+ this._prefabId = id;
170
+ }
171
+ /**
172
+ * Get prefab node this node belongs to, or null if this node does not belongs to any prefab
173
+ * @returns prefab node this node belongs to
174
+ */ getPrefabNode() {
175
+ return this._prefabId ? this : this.parent?.getPrefabNode() ?? null;
176
+ }
177
+ /**
178
+ * Translation type if this is a joint node of any skeleton
179
+ *
180
+ * @remarks
181
+ * Internal used for serialization
182
+ */ get jointTypeT() {
183
+ return this._jointTypeT;
184
+ }
185
+ set jointTypeT(val) {
186
+ this._jointTypeT = val;
187
+ }
188
+ /**
189
+ * Scale type if this is a joint node of any skeleton
190
+ *
191
+ * @remarks
192
+ * Internal used for serialization
193
+ */ get jointTypeS() {
194
+ return this._jointTypeS;
195
+ }
196
+ set jointTypeS(val) {
197
+ this._jointTypeS = val;
198
+ }
199
+ /**
200
+ * Rotation type if this is a joint node of any skeleton
201
+ *
202
+ * @remarks
203
+ * Internal used for serialization
204
+ */ get jointTypeR() {
205
+ return this._jointTypeR;
206
+ }
207
+ set jointTypeR(val) {
208
+ this._jointTypeR = val;
209
+ }
210
+ /**
211
+ * Arbitrary metadata associated with this node.
212
+ *
213
+ * @remarks
214
+ * Stored and transported with the node; format is application-defined.
215
+ */ get metaData() {
216
+ return this._metaData;
217
+ }
218
+ set metaData(val) {
219
+ this._metaData = val;
220
+ }
221
+ /**
222
+ * Attached script filename or identifier (engine-specific).
223
+ *
224
+ * @remarks
225
+ * Integrates with the engine’s scripting system if available.
226
+ */ get script() {
227
+ return this._script;
228
+ }
229
+ set script(fileName) {
230
+ this._script = fileName ?? '';
231
+ }
232
+ /**
233
+ * Display name of the node (for UI/debugging).
65
234
  */ get name() {
66
235
  return this._name;
67
236
  }
68
237
  set name(val) {
69
238
  this._name = val || '';
70
239
  }
71
- /** The scene to which the node belongs */ get scene() {
240
+ /** The owning scene. */ get scene() {
72
241
  return this._scene;
73
242
  }
74
- /** true if the node is attached to the scene node, false otherwise */ get attached() {
75
- return !!this._scene?.rootNode?.isParentOf(this);
243
+ /**
244
+ * Whether this node is currently attached under the scene's root.
245
+ */ get attached() {
246
+ let node = this;
247
+ while(node && node !== this._scene.rootNode){
248
+ node = node.parent;
249
+ }
250
+ return node === this._scene.rootNode;
251
+ }
252
+ /**
253
+ * If true, the node is logically sealed; some operations (like cloning as child)
254
+ * may be restricted by engine policies.
255
+ */ get sealed() {
256
+ return this._sealed;
257
+ }
258
+ set sealed(val) {
259
+ this._sealed = val;
76
260
  }
77
261
  /**
78
- * Check if given node is a direct child of the node
262
+ * Lazily created animation set for this node.
263
+ *
264
+ * @remarks
265
+ * Accessing this schedules the node for update in the scene.
266
+ */ get animationSet() {
267
+ if (!this._animationSet.get()) {
268
+ this._animationSet.set(new AnimationSet(this));
269
+ this.scene.queueUpdateNode(this);
270
+ }
271
+ return this._animationSet.get();
272
+ }
273
+ /**
274
+ * Shared model reference for instancing/streaming systems.
275
+ */ get sharedModel() {
276
+ return this._sharedModel.get();
277
+ }
278
+ set sharedModel(model) {
279
+ this._sharedModel.set(model);
280
+ }
281
+ /**
282
+ * Clone this node.
283
+ *
284
+ * @remarks
285
+ * If a shared model exists, it may create an instanced node. The clone is
286
+ * attached under the same parent; children are cloned based on `method` and `recursive`.
287
+ *
288
+ * @param method - Clone method ('deep' or 'instance').
289
+ * @param recursive - Whether children are cloned recursively.
290
+ * @returns New node instance
291
+ */ async clone() {
292
+ this.iterate((node)=>{
293
+ if (node.isTerrain() || node.isClipmapTerrain()) {
294
+ throw new Error('Cloning terrain node is not allowed');
295
+ }
296
+ });
297
+ const parent = this.parent;
298
+ const tmpParent = new SceneNode(this.scene);
299
+ const data = await getEngine().resourceManager.serializeObject(this);
300
+ const other = await getEngine().resourceManager.deserializeObject(tmpParent, data);
301
+ other.persistentId = randomUUID();
302
+ other.parent = parent;
303
+ tmpParent.dispose();
304
+ const postClonePromises = [];
305
+ other.iterate((node)=>{
306
+ const P = node.onPostClone();
307
+ if (P instanceof Promise) {
308
+ postClonePromises.push(P);
309
+ }
310
+ });
311
+ if (postClonePromises.length > 0) {
312
+ await Promise.all(postClonePromises);
313
+ }
314
+ return other;
315
+ }
316
+ /**
317
+ * Whether the given node is a direct child of this node.
79
318
  * @param child - The node to be checked
80
319
  * @returns true if the given node is a direct child of this node, false otherwise
81
320
  */ hasChild(child) {
82
- return this._children.indexOf(child) >= 0;
321
+ return child && child.parent === this;
83
322
  }
84
323
  /**
85
- * Removes all children from this node
324
+ * Remove all children from this node.
86
325
  */ removeChildren() {
87
326
  while(this._children.length){
88
- this._children[0].remove();
327
+ this._children[0].get().remove();
89
328
  }
90
329
  }
91
330
  /**
92
- * Checks if this node is the direct parent or indirect parent of a given node
93
- * @param child - The node to be checked
94
- * @returns true if this node is the direct parent or indirect parent of the given node, false otherwise
331
+ * Whether this node is an ancestor (direct or indirect) of the given node.
95
332
  */ isParentOf(child) {
96
333
  while(child && child !== this){
97
334
  child = child.parent;
@@ -99,55 +336,82 @@ import { XForm } from './xform.js';
99
336
  return child === this;
100
337
  }
101
338
  /**
102
- * Removes this node from it's parent
103
- * @returns self
339
+ * Detach this node from its parent.
340
+ *
341
+ * @returns this
104
342
  */ remove() {
105
343
  this.parent = null;
106
344
  return this;
107
345
  }
108
346
  /**
109
- * Traverse the entire subtree of this node by a visitor
110
- * @param v - The visitor that will travel the subtree of this node
111
- * @param inverse - true if traversing from bottom to top, otherwise top to bottom
112
- */ traverse(v, inverse) {
113
- if (inverse) {
114
- for(let i = this._children.length - 1; i >= 0; i--){
115
- this._children[i].traverse(v, inverse);
116
- }
117
- v.visit(this);
118
- } else {
119
- v.visit(this);
120
- for (const child of this._children){
121
- child.traverse(v);
122
- }
347
+ * Depth-first traversal of this node's subtree (pre-order).
348
+ *
349
+ * @param v - Visitor invoked on each node.
350
+ */ traverse(v) {
351
+ v.visit(this);
352
+ for (const child of this._children){
353
+ child.get().traverse(v);
123
354
  }
124
355
  }
125
356
  /**
126
- * Iterate self and all of the children
357
+ * Iterate self and descendants in pre-order.
127
358
  *
128
- * @remarks
129
- * DO NOT remove child duration iteration!
359
+ * Warning: Do not remove children during this iteration. To allow removal, use `iterateBottomToTop`.
130
360
  *
131
- * @param callback - callback function that will be called on each node
361
+ * @param callback - Called for each node; if returns true, iteration stops.
362
+ * @returns true if iteration was aborted early.
132
363
  */ iterate(callback) {
133
- callback(this);
364
+ if (callback(this)) {
365
+ return true;
366
+ }
134
367
  for (const child of this._children){
135
- child.iterate(callback);
368
+ if (child.get().iterate(callback)) {
369
+ return true;
370
+ }
371
+ }
372
+ return false;
373
+ }
374
+ /**
375
+ * Iterate self and descendants in reverse post-order (bottom-to-top).
376
+ *
377
+ * Child nodes can be safely removed during this iteration.
378
+ *
379
+ * @param callback - Called for each node; if returns true, iteration stops.
380
+ * @returns true if iteration was aborted early.
381
+ */ iterateBottomToTop(callback) {
382
+ for(let i = this._children.length - 1; i >= 0; i--){
383
+ const child = this._children[i];
384
+ if (child.get().iterateBottomToTop(callback)) {
385
+ return true;
386
+ }
136
387
  }
388
+ if (callback(this)) {
389
+ return true;
390
+ }
391
+ return false;
392
+ }
393
+ /** Type guard: true if this node is a graph node. */ isGraphNode() {
394
+ return false;
395
+ }
396
+ /** Type guard: true if this node is a light. */ isLight() {
397
+ return false;
137
398
  }
138
- /** true if this is a graph node, false otherwise */ isGraphNode() {
399
+ /** Type guard: true if this node is a mesh. */ isMesh() {
139
400
  return false;
140
401
  }
141
- /** true if this is a light node, false otherwise */ isLight() {
402
+ /** Type guard: true if this node is a water node. */ isWater() {
142
403
  return false;
143
404
  }
144
- /** true if this is a mesh node, false otherwise */ isMesh() {
405
+ /** Type guard: true if this node is a particle system. */ isParticleSystem() {
145
406
  return false;
146
407
  }
147
- /** true if this is a batch group, false otherwise */ isBatchGroup() {
408
+ /** Type guard: true if this node is a batch group. */ isBatchGroup() {
148
409
  return false;
149
410
  }
150
- /** true if this is a terrain node, false otherwise */ isTerrain() {
411
+ /** Type guard: true if this node is a terrain. */ isTerrain() {
412
+ return false;
413
+ }
414
+ /** Type guard: true if this node is a clipmap terrain. */ isClipmapTerrain() {
151
415
  return false;
152
416
  }
153
417
  /** true if this is a camera node, false otherwise */ isCamera() {
@@ -156,10 +420,6 @@ import { XForm } from './xform.js';
156
420
  /** true if this is a punctual light node, false otherwise */ isPunctualLight() {
157
421
  return false;
158
422
  }
159
- /** Disposes the node */ dispose() {
160
- this.remove();
161
- this.removeChildren();
162
- }
163
423
  /**
164
424
  * Computes the bounding volume of the node
165
425
  * @returns The output bounding volume
@@ -191,11 +451,17 @@ import { XForm } from './xform.js';
191
451
  * @returns The world space bounding volume of the node
192
452
  */ getWorldBoundingVolume() {
193
453
  if (!this._bvWorld) {
194
- this._bvWorld = this.getBoundingVolume()?.transform(this.worldMatrix) ?? null;
454
+ this._bvWorld = this.computeWorldBoundingVolume(this.getBoundingVolume());
195
455
  }
196
456
  return this._bvWorld;
197
457
  }
198
458
  /**
459
+ * Computes the world space bounding volume of the node
460
+ * @returns The output bounding volume
461
+ */ computeWorldBoundingVolume(localBV) {
462
+ return localBV?.transform(this.worldMatrix) ?? null;
463
+ }
464
+ /**
199
465
  * Force the bounding volume to be recalculated
200
466
  */ invalidateBoundingVolume() {
201
467
  this._bvDirty = true;
@@ -213,7 +479,7 @@ import { XForm } from './xform.js';
213
479
  } else if (this.isGraphNode()) {
214
480
  this._scene.invalidateNodePlacement(this);
215
481
  }
216
- this.dispatchEvent(this, 'bvchanged');
482
+ this.dispatchEvent('bvchanged', this);
217
483
  }
218
484
  }
219
485
  /** Clip mode */ get clipTestEnabled() {
@@ -238,17 +504,79 @@ import { XForm } from './xform.js';
238
504
  this._visible = val;
239
505
  if (prevHidden !== this.hidden) {
240
506
  if (this.isGraphNode()) {
241
- this._scene.invalidateNodePlacement(this);
507
+ this._scene?.invalidateNodePlacement(this);
508
+ }
509
+ let parent = this;
510
+ while(parent){
511
+ parent.dispatchEvent('visiblechanged', this);
512
+ parent = parent.parent;
242
513
  }
243
514
  this.notifyHiddenChanged();
244
515
  }
245
516
  }
246
517
  }
247
- /** Computed value of pick mode */ get pickable() {
248
- return this._pickMode;
518
+ /** Whether this node is enabled for CPU picking */ get pickable() {
519
+ return this._pickable;
249
520
  }
250
521
  set pickable(val) {
251
- this._pickMode = !!val;
522
+ this._pickable = !!val;
523
+ }
524
+ /** Whether this node is enabled for GPU picking */ get gpuPickable() {
525
+ return this._gpuPickable;
526
+ }
527
+ set gpuPickable(val) {
528
+ this._gpuPickable = !!val;
529
+ }
530
+ /**
531
+ * Finds a scene node by its persistent ID.
532
+ *
533
+ * @typeParam T - Expected node type.
534
+ * @param id - Persistent identifier to match against `SceneNode.persistentId`.
535
+ * @returns The first matching node, or `null` if not found.
536
+ */ findNodeById(id) {
537
+ let node = null;
538
+ this.iterate((child)=>{
539
+ if (child.persistentId === id) {
540
+ node = child;
541
+ return true;
542
+ }
543
+ });
544
+ return node;
545
+ }
546
+ /**
547
+ * Finds a skeleton object by its persistent ID.
548
+ * @param id - Persistent identifier to match against `Skeleton.persistentId`.
549
+ * @returns The first matchign node, or `null` if not found.
550
+ */ findSkeletonById(id) {
551
+ const prefabNode = this.getPrefabNode() ?? this;
552
+ let sk = null;
553
+ prefabNode.iterate((node)=>{
554
+ sk = node.animationSet.skeletons.find((s)=>s.get().persistentId === id);
555
+ return !!sk;
556
+ });
557
+ return sk?.get() ?? null;
558
+ }
559
+ /**
560
+ * Finds a scene node by name.
561
+ *
562
+ * If multiple nodes share the same name, returns the first match encountered
563
+ * during traversal.
564
+ *
565
+ * @typeParam T - Expected node type.
566
+ * @param name - Node name to match.
567
+ * @returns The first matching node, or `null` if not found.
568
+ *
569
+ * @remarks
570
+ * Names are not guaranteed unique. Prefer IDs for stable references.
571
+ */ findNodeByName(name) {
572
+ let node = null;
573
+ this.iterate((child)=>{
574
+ if (child.name === name) {
575
+ node = child;
576
+ return true;
577
+ }
578
+ });
579
+ return node;
252
580
  }
253
581
  /** Computed value for bounding box draw mode */ get computedBoundingBoxDrawMode() {
254
582
  if (this._boxDrawMode === SceneNode.BBOXDRAW_INHERITED) {
@@ -266,48 +594,293 @@ import { XForm } from './xform.js';
266
594
  set boundingBoxDrawMode(mode) {
267
595
  this._boxDrawMode = mode;
268
596
  }
597
+ /** Get called when the node was just created by cloning from other node */ onPostClone() {}
598
+ /** Disposes the node */ onDispose() {
599
+ super.onDispose();
600
+ this.remove();
601
+ this.removeChildren();
602
+ this._animationSet?.dispose();
603
+ this._animationSet = null;
604
+ this._sharedModel?.dispose();
605
+ this._sharedModel = null;
606
+ }
269
607
  /** @internal */ _setParent(p) {
608
+ if (p && p._scene !== this._scene) {
609
+ throw new Error('Parent node and child node must belongs to the same scene');
610
+ }
270
611
  let lastParent = this._parent;
271
612
  let newParent = p;
272
613
  if (newParent !== lastParent) {
273
- const sceneLast = this.attached ? this.scene : null;
274
- const sceneNew = newParent?.attached ? newParent.scene : null;
275
- const willDetach = sceneLast && sceneLast !== sceneNew;
276
- const willAttach = sceneNew && sceneLast !== sceneNew;
277
- willDetach && this._willDetach();
278
- willAttach && this._willAttach();
279
- super._setParent(newParent);
280
- willDetach && this._detached();
281
- willAttach && this._attached();
282
- }
283
- while(lastParent){
284
- lastParent.dispatchEvent(this, 'noderemoved');
285
- lastParent = lastParent.parent;
286
- }
287
- while(newParent){
288
- newParent.dispatchEvent(this, 'nodeattached');
289
- newParent = newParent.parent;
614
+ const willDetach = (!p || !p.attached) && this.attached;
615
+ const willAttach = !this.attached && p && p.attached;
616
+ if (newParent) {
617
+ newParent._children.push(new DRef(this));
618
+ }
619
+ if (this._parent) {
620
+ const index = this._parent._children.findIndex((val)=>val.get() === this);
621
+ this._parent.children[index].dispose();
622
+ this._parent._children.splice(index, 1);
623
+ }
624
+ this._parent = p;
625
+ this._onTransformChanged(false);
626
+ if (willDetach) {
627
+ this._detached();
628
+ }
629
+ if (willAttach) {
630
+ this._attached();
631
+ }
632
+ while(lastParent){
633
+ lastParent.dispatchEvent('noderemoved', this);
634
+ lastParent = lastParent.parent;
635
+ }
636
+ while(newParent){
637
+ newParent.dispatchEvent('nodeattached', this);
638
+ newParent = newParent.parent;
639
+ }
290
640
  }
291
641
  }
292
642
  /** @internal */ _onTransformChanged(invalidateLocal) {
293
- super._onTransformChanged(invalidateLocal);
643
+ if (this._disableCallback) {
644
+ return;
645
+ }
646
+ if (invalidateLocal) {
647
+ this._localMatrix = null;
648
+ }
649
+ this._worldMatrix = null;
650
+ this._invWorldMatrix = null;
651
+ this._worldMatrixDet = null;
652
+ this._transformTag++;
653
+ for (const child of this._children){
654
+ child.get()._onTransformChanged(false);
655
+ }
294
656
  this.invalidateWorldBoundingVolume(true);
295
- this.dispatchEvent(this, 'transformchanged');
657
+ this.dispatchEvent('transformchanged', this);
658
+ }
659
+ /**
660
+ * Get called when this node is attached to scene
661
+ */ _onAttached() {}
662
+ /**
663
+ * Get called when this node is detached from scene
664
+ */ _onDetached() {}
665
+ /** @internal */ _attached() {
666
+ this.iterate((child)=>{
667
+ this.scene.queueUpdateNode(child);
668
+ child._onAttached();
669
+ });
670
+ }
671
+ /** @internal */ _detached() {
672
+ this.iterate((child)=>{
673
+ child._onDetached();
674
+ });
296
675
  }
297
- /** @internal */ _willAttach() {}
298
- /** @internal */ _attached() {}
299
- /** @internal */ _willDetach() {}
300
- /** @internal */ _detached() {}
301
676
  /** @internal */ notifyHiddenChanged() {
302
677
  this._visibleChanged();
303
- this.dispatchEvent(this, 'visiblechanged');
304
678
  for (const child of this._children){
305
- if (child.showState === 'inherit') {
306
- child.notifyHiddenChanged();
679
+ if (child.get().showState === 'inherit') {
680
+ child.get().notifyHiddenChanged();
307
681
  }
308
682
  }
309
683
  }
310
684
  /** @internal */ _visibleChanged() {}
685
+ /** Parent of the xform */ get parent() {
686
+ return this._parent;
687
+ }
688
+ set parent(p) {
689
+ p = p || null;
690
+ if (p !== this._parent) {
691
+ this._setParent(p);
692
+ }
693
+ }
694
+ /** Children of this xform */ get children() {
695
+ return this._children;
696
+ }
697
+ /**
698
+ * Position of the xform relative to it's parent
699
+ */ get position() {
700
+ return this._position;
701
+ }
702
+ set position(val) {
703
+ this._position.setXYZ(val[0], val[1], val[2]);
704
+ }
705
+ /**
706
+ * Scaling of the xform
707
+ */ get scale() {
708
+ return this._scaling;
709
+ }
710
+ set scale(val) {
711
+ this._scaling.setXYZ(val[0], val[1], val[2]);
712
+ }
713
+ /**
714
+ * Rotation of the xform
715
+ */ get rotation() {
716
+ return this._rotation;
717
+ }
718
+ set rotation(val) {
719
+ this._rotation.setXYZW(val[0], val[1], val[2], val[3]);
720
+ }
721
+ worldToThis(v, result) {
722
+ if (v instanceof Vector3) {
723
+ result = result || new Vector3();
724
+ this.invWorldMatrix.transformPointAffine(v, result);
725
+ return result;
726
+ } else {
727
+ result = result || new Vector4();
728
+ this.invWorldMatrix.transformAffine(v, result);
729
+ return result;
730
+ }
731
+ }
732
+ otherToThis(other, v, result) {
733
+ return this.worldToThis(other.thisToWorld(v, result), result);
734
+ }
735
+ thisToWorld(v, result) {
736
+ if (v instanceof Vector3) {
737
+ result = result || new Vector3();
738
+ this.worldMatrix.transformPointAffine(v, result);
739
+ return result;
740
+ } else {
741
+ result = result || new Vector4();
742
+ this.worldMatrix.transformAffine(v, result);
743
+ return result;
744
+ }
745
+ }
746
+ thisToOther(other, v, result) {
747
+ return other.worldToThis(this.thisToWorld(v, result), result);
748
+ }
749
+ /**
750
+ * Gets the position of the xform in world space
751
+ * @returns position of the xform in world space
752
+ */ getWorldPosition(outPos) {
753
+ return outPos?.setXYZ(this.worldMatrix.m03, this.worldMatrix.m13, this.worldMatrix.m23) ?? new Vector3(this.worldMatrix.m03, this.worldMatrix.m13, this.worldMatrix.m23);
754
+ }
755
+ /**
756
+ * Moves the xform by an offset vector
757
+ * @param delta - The offset vector
758
+ * @returns self
759
+ */ moveBy(delta) {
760
+ this._position.addBy(delta);
761
+ return this;
762
+ }
763
+ /**
764
+ * Scales the xform by a given scale factor
765
+ * @param factor - The scale factor
766
+ * @returns self
767
+ */ scaleBy(factor) {
768
+ this._scaling.mulBy(factor);
769
+ return this;
770
+ }
771
+ /**
772
+ * Sets the local transform matrix of the xform
773
+ * @param matrix - The transform matrix to set
774
+ * @returns self
775
+ */ setLocalTransform(matrix) {
776
+ this._disableCallback = true;
777
+ matrix.decompose(this._scaling, this._rotation, this._position);
778
+ this._disableCallback = false;
779
+ this._onTransformChanged(true);
780
+ /*
781
+ this._localMatrix = matrix;
782
+ this._disableCallback = true;
783
+ this._localMatrix.decompose(this._scaling, this._rotation, this._position);
784
+ this._disableCallback = false;
785
+ this._onTransformChanged(false);
786
+ */ return this;
787
+ }
788
+ /** Local transformation matrix of the xform */ get localMatrix() {
789
+ if (!this._localMatrix) {
790
+ this.calculateLocalTransform(this._tmpLocalMatrix);
791
+ this._localMatrix = this._tmpLocalMatrix;
792
+ /*
793
+ this._localMatrix
794
+ .scaling(this._scaling)
795
+ .rotateLeft(new Matrix4x4(this._rotation))
796
+ .translateLeft(this._position);
797
+ */ }
798
+ return this._localMatrix;
799
+ }
800
+ set localMatrix(matrix) {
801
+ this.setLocalTransform(matrix);
802
+ }
803
+ /** World transformation matrix of the xform */ get worldMatrix() {
804
+ if (!this._worldMatrix) {
805
+ this._worldMatrix = this._tmpWorldMatrix;
806
+ this.calculateWorldTransform(this._worldMatrix);
807
+ }
808
+ return this._worldMatrix;
809
+ }
810
+ /** The determinant of world matrix */ get worldMatrixDet() {
811
+ if (this._worldMatrixDet === null) {
812
+ this._worldMatrixDet = this.worldMatrix.det();
813
+ }
814
+ return this._worldMatrixDet;
815
+ }
816
+ /** Inverse of the world transformation matrix of the xform */ get invWorldMatrix() {
817
+ if (!this._invWorldMatrix) {
818
+ this._invWorldMatrix = Matrix4x4.invertAffine(this.worldMatrix);
819
+ }
820
+ return this._invWorldMatrix;
821
+ }
822
+ /**
823
+ * Calculate local transform matrix
824
+ * @param outMatrix - Matrix object that holds the result of calculation
825
+ */ calculateLocalTransform(outMatrix) {
826
+ outMatrix.compose(this._scaling, this._rotation, this._position);
827
+ }
828
+ /**
829
+ * Calculate world transform matrix
830
+ * @param outMatrix - Matrix object that holds the result of calculation
831
+ */ calculateWorldTransform(outMatrix) {
832
+ if (this._parent) {
833
+ Matrix4x4.multiplyAffine(this._parent.worldMatrix, this.localMatrix, outMatrix);
834
+ } else {
835
+ outMatrix.set(this.localMatrix);
836
+ }
837
+ }
838
+ /**
839
+ * Sets the local tranformation matrix by a look-at matrix
840
+ * @param eye - The eye position used to make the look-at matrix
841
+ * @param target - The target position used to make the look-at matrix
842
+ * @param up - The up vector used to make the look-at matrix
843
+ * @returns self
844
+ */ lookAt(eye, target, up) {
845
+ this.setLocalTransform(Matrix4x4.lookAt(eye, target, up));
846
+ return this;
847
+ }
848
+ /**
849
+ * Update node state once per-frame
850
+ * @param frameId - Current frame id
851
+ * @param elapsedInSeconds - Elapsed time from game start in seconds
852
+ * @param deltaInSeconds - Elapsed time since previous frame in seconds
853
+ */ update(frameId, elapsedInSeconds, deltaInSeconds) {
854
+ if (!this.attached) {
855
+ return;
856
+ }
857
+ const animationSet = this._animationSet.get();
858
+ if (animationSet) {
859
+ if (animationSet.numAnimations > 0 || animationSet.skeletons.length > 0) {
860
+ animationSet.update(deltaInSeconds);
861
+ this.scene.queueUpdateNode(this);
862
+ } else {
863
+ this._animationSet.dispose();
864
+ }
865
+ }
866
+ }
867
+ /**
868
+ * Update node state once per-camera
869
+ * @param _camera - Updates according to which camera
870
+ * @param _elapsedInSeconds - Elapsed time from game start in seconds
871
+ * @param _deltaInSeconds - Elapsed time since previous frame in seconds
872
+ */ updatePerCamera(_camera, _elapsedInSeconds, _deltaInSeconds) {}
873
+ /**
874
+ * Removes this node from it's parent and add this node to another parent node if required
875
+ * @param p - The new parent node that this node should be added to or null
876
+ * @returns self
877
+ */ reparent(p) {
878
+ this.parent = p;
879
+ return this;
880
+ }
881
+ /** @internal */ get transformTag() {
882
+ return this._transformTag;
883
+ }
311
884
  }
312
885
 
313
886
  export { SceneNode };