@zephyr3d/scene 0.4.0 → 0.6.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 (233) hide show
  1. package/dist/animation/animation.js +25 -117
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +191 -51
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js +6 -18
  6. package/dist/animation/animationtrack.js.map +1 -1
  7. package/dist/animation/eulerrotationtrack.js +16 -6
  8. package/dist/animation/eulerrotationtrack.js.map +1 -1
  9. package/dist/animation/morphtarget.js +104 -0
  10. package/dist/animation/morphtarget.js.map +1 -0
  11. package/dist/animation/morphtrack.js +70 -0
  12. package/dist/animation/morphtrack.js.map +1 -0
  13. package/dist/animation/rotationtrack.js +15 -7
  14. package/dist/animation/rotationtrack.js.map +1 -1
  15. package/dist/animation/scaletrack.js +15 -7
  16. package/dist/animation/scaletrack.js.map +1 -1
  17. package/dist/animation/skeleton.js +107 -5
  18. package/dist/animation/skeleton.js.map +1 -1
  19. package/dist/animation/translationtrack.js +15 -7
  20. package/dist/animation/translationtrack.js.map +1 -1
  21. package/dist/app.js +4 -26
  22. package/dist/app.js.map +1 -1
  23. package/dist/asset/assetmanager.js +60 -109
  24. package/dist/asset/assetmanager.js.map +1 -1
  25. package/dist/asset/loaders/dds/dds.js +77 -3
  26. package/dist/asset/loaders/dds/dds.js.map +1 -1
  27. package/dist/asset/loaders/dds/dds_loader.js +1 -1
  28. package/dist/asset/loaders/gltf/gltf_loader.js +287 -40
  29. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  30. package/dist/asset/loaders/image/tga_Loader.js +1 -1
  31. package/dist/asset/loaders/image/webimage_loader.js +16 -0
  32. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  33. package/dist/asset/model.js +16 -9
  34. package/dist/asset/model.js.map +1 -1
  35. package/dist/blitter/bilateralblur.js +222 -0
  36. package/dist/{render/temporalcache.js.map → blitter/bilateralblur.js.map} +1 -1
  37. package/dist/blitter/blitter.js +9 -3
  38. package/dist/blitter/blitter.js.map +1 -1
  39. package/dist/blitter/depthlimitedgaussion.js +96 -39
  40. package/dist/blitter/depthlimitedgaussion.js.map +1 -1
  41. package/dist/blitter/gaussianblur.js +21 -21
  42. package/dist/camera/camera.js +200 -4
  43. package/dist/camera/camera.js.map +1 -1
  44. package/dist/index.d.ts +6406 -5786
  45. package/dist/index.js +12 -10
  46. package/dist/index.js.map +1 -1
  47. package/dist/material/blinn.js +15 -4
  48. package/dist/material/blinn.js.map +1 -1
  49. package/dist/material/lambert.js +26 -17
  50. package/dist/material/lambert.js.map +1 -1
  51. package/dist/material/material.js +13 -2
  52. package/dist/material/material.js.map +1 -1
  53. package/dist/material/meshmaterial.js +103 -31
  54. package/dist/material/meshmaterial.js.map +1 -1
  55. package/dist/material/mixins/albedocolor.js +5 -4
  56. package/dist/material/mixins/albedocolor.js.map +1 -1
  57. package/dist/material/mixins/lightmodel/blinnphong.js +17 -7
  58. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  59. package/dist/material/mixins/lightmodel/lambert.js +5 -5
  60. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +16 -7
  61. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  62. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -7
  63. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  64. package/dist/material/mixins/lit.js +2 -2
  65. package/dist/material/mixins/pbr/common.js +454 -19
  66. package/dist/material/mixins/pbr/common.js.map +1 -1
  67. package/dist/material/pbrmr.js +28 -6
  68. package/dist/material/pbrmr.js.map +1 -1
  69. package/dist/material/pbrsg.js +27 -9
  70. package/dist/material/pbrsg.js.map +1 -1
  71. package/dist/material/shader/helper.js +128 -23
  72. package/dist/material/shader/helper.js.map +1 -1
  73. package/dist/material/unlit.js +8 -4
  74. package/dist/material/unlit.js.map +1 -1
  75. package/dist/posteffect/bloom.js +34 -53
  76. package/dist/posteffect/bloom.js.map +1 -1
  77. package/dist/posteffect/compositor.js +48 -58
  78. package/dist/posteffect/compositor.js.map +1 -1
  79. package/dist/posteffect/fxaa.js +3 -11
  80. package/dist/posteffect/fxaa.js.map +1 -1
  81. package/dist/posteffect/grayscale.js +3 -11
  82. package/dist/posteffect/grayscale.js.map +1 -1
  83. package/dist/posteffect/posteffect.js +4 -0
  84. package/dist/posteffect/posteffect.js.map +1 -1
  85. package/dist/posteffect/sao.js +55 -48
  86. package/dist/posteffect/sao.js.map +1 -1
  87. package/dist/posteffect/ssr.js +536 -0
  88. package/dist/{material/lit.js.map → posteffect/ssr.js.map} +1 -1
  89. package/dist/posteffect/tonemap.js +3 -11
  90. package/dist/posteffect/tonemap.js.map +1 -1
  91. package/dist/posteffect/water.js +306 -340
  92. package/dist/posteffect/water.js.map +1 -1
  93. package/dist/render/abuffer_oit.js +2 -2
  94. package/dist/render/clipmap.js +16 -19
  95. package/dist/render/clipmap.js.map +1 -1
  96. package/dist/render/cull_visitor.js +8 -6
  97. package/dist/render/cull_visitor.js.map +1 -1
  98. package/dist/render/depthpass.js +30 -14
  99. package/dist/render/depthpass.js.map +1 -1
  100. package/dist/render/drawable_mixin.js +70 -22
  101. package/dist/render/drawable_mixin.js.map +1 -1
  102. package/dist/render/envlight.js +169 -33
  103. package/dist/render/envlight.js.map +1 -1
  104. package/dist/render/fft_wavegenerator.js +989 -0
  105. package/dist/{shaders/framework.js.map → render/fft_wavegenerator.js.map} +1 -1
  106. package/dist/render/gerstner_wavegenerator.js +265 -0
  107. package/dist/{material/standard.js.map → render/gerstner_wavegenerator.js.map} +1 -1
  108. package/dist/render/globalbindgroup_allocator.js +2 -1
  109. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  110. package/dist/render/hzb.js +273 -0
  111. package/dist/{material/terrainlightmodel.js.map → render/hzb.js.map} +1 -1
  112. package/dist/render/lightpass.js +68 -28
  113. package/dist/render/lightpass.js.map +1 -1
  114. package/dist/render/objectcolorpass.js +51 -0
  115. package/dist/render/objectcolorpass.js.map +1 -0
  116. package/dist/render/render_queue.js +211 -158
  117. package/dist/render/render_queue.js.map +1 -1
  118. package/dist/render/renderbundle_wrapper.js +79 -0
  119. package/dist/render/renderbundle_wrapper.js.map +1 -1
  120. package/dist/render/renderer.js +151 -35
  121. package/dist/render/renderer.js.map +1 -1
  122. package/dist/render/renderpass.js +27 -20
  123. package/dist/render/renderpass.js.map +1 -1
  124. package/dist/render/shadowmap_pass.js +20 -14
  125. package/dist/render/shadowmap_pass.js.map +1 -1
  126. package/dist/render/sky.js +12 -13
  127. package/dist/render/sky.js.map +1 -1
  128. package/dist/render/watermesh.js +94 -828
  129. package/dist/render/watermesh.js.map +1 -1
  130. package/dist/render/wavegenerator.js +8 -0
  131. package/dist/render/wavegenerator.js.map +1 -0
  132. package/dist/render/weightedblended_oit.js +11 -28
  133. package/dist/render/weightedblended_oit.js.map +1 -1
  134. package/dist/scene/batchgroup.js +60 -14
  135. package/dist/scene/batchgroup.js.map +1 -1
  136. package/dist/scene/environment.js +24 -3
  137. package/dist/scene/environment.js.map +1 -1
  138. package/dist/scene/graph_node.js +0 -14
  139. package/dist/scene/graph_node.js.map +1 -1
  140. package/dist/scene/light.js +5 -5
  141. package/dist/scene/mesh.js +62 -15
  142. package/dist/scene/mesh.js.map +1 -1
  143. package/dist/scene/octree.js +5 -2
  144. package/dist/scene/octree.js.map +1 -1
  145. package/dist/scene/raycast_visitor.js +4 -2
  146. package/dist/scene/raycast_visitor.js.map +1 -1
  147. package/dist/scene/scene.js +6 -9
  148. package/dist/scene/scene.js.map +1 -1
  149. package/dist/scene/scene_node.js +11 -8
  150. package/dist/scene/scene_node.js.map +1 -1
  151. package/dist/scene/terrain/grass.js +10 -2
  152. package/dist/scene/terrain/grass.js.map +1 -1
  153. package/dist/scene/terrain/heightfield.js +135 -53
  154. package/dist/scene/terrain/heightfield.js.map +1 -1
  155. package/dist/scene/terrain/patch.js +10 -2
  156. package/dist/scene/terrain/patch.js.map +1 -1
  157. package/dist/scene/terrain/quadtree.js +2 -2
  158. package/dist/scene/terrain/terrain.js +1 -1
  159. package/dist/scene/xform.js +7 -9
  160. package/dist/scene/xform.js.map +1 -1
  161. package/dist/shaders/misc.js +10 -1
  162. package/dist/shaders/misc.js.map +1 -1
  163. package/dist/shaders/noise.js +81 -16
  164. package/dist/shaders/noise.js.map +1 -1
  165. package/dist/shaders/shadow.js +1 -9
  166. package/dist/shaders/shadow.js.map +1 -1
  167. package/dist/shaders/ssr.js +442 -0
  168. package/dist/{material/terrainmat.js.map → shaders/ssr.js.map} +1 -1
  169. package/dist/shaders/water.js +377 -250
  170. package/dist/shaders/water.js.map +1 -1
  171. package/dist/shadow/esm.js +4 -22
  172. package/dist/shadow/esm.js.map +1 -1
  173. package/dist/shadow/shadowmapper.js +56 -31
  174. package/dist/shadow/shadowmapper.js.map +1 -1
  175. package/dist/shadow/vsm.js +4 -24
  176. package/dist/shadow/vsm.js.map +1 -1
  177. package/dist/shapes/cylinder.js +6 -5
  178. package/dist/shapes/cylinder.js.map +1 -1
  179. package/dist/utility/bounding_volume.js +1 -53
  180. package/dist/utility/bounding_volume.js.map +1 -1
  181. package/dist/utility/draco/decoder.js +116 -0
  182. package/dist/utility/draco/decoder.js.map +1 -0
  183. package/dist/utility/misc.js +93 -0
  184. package/dist/utility/misc.js.map +1 -0
  185. package/dist/utility/shprojection.js +2 -7
  186. package/dist/utility/shprojection.js.map +1 -1
  187. package/dist/utility/textures/ggxlut.js +213 -0
  188. package/dist/utility/textures/ggxlut.js.map +1 -0
  189. package/dist/utility/textures/gradientnoise.js +61 -0
  190. package/dist/utility/textures/gradientnoise.js.map +1 -0
  191. package/dist/utility/textures/randomnoise.js +41 -0
  192. package/dist/utility/textures/randomnoise.js.map +1 -0
  193. package/dist/values.js +25 -1
  194. package/dist/values.js.map +1 -1
  195. package/package.json +5 -8
  196. package/dist/animation/usertrack.js +0 -47
  197. package/dist/animation/usertrack.js.map +0 -1
  198. package/dist/material/grassmat.js +0 -127
  199. package/dist/material/grassmat.js.map +0 -1
  200. package/dist/material/lightmodel.js +0 -2074
  201. package/dist/material/lightmodel.js.map +0 -1
  202. package/dist/material/lit.js +0 -578
  203. package/dist/material/mixins/pbr/metallicroughness.js +0 -126
  204. package/dist/material/mixins/pbr/metallicroughness.js.map +0 -1
  205. package/dist/material/mixins/pbr/specularglossness.js +0 -104
  206. package/dist/material/mixins/pbr/specularglossness.js.map +0 -1
  207. package/dist/material/pbr.js +0 -27
  208. package/dist/material/pbr.js.map +0 -1
  209. package/dist/material/standard.js +0 -282
  210. package/dist/material/terrainlightmodel.js +0 -259
  211. package/dist/material/terrainmat.js +0 -357
  212. package/dist/render/depth_pass.js +0 -47
  213. package/dist/render/depth_pass.js.map +0 -1
  214. package/dist/render/forward.js +0 -186
  215. package/dist/render/forward.js.map +0 -1
  216. package/dist/render/forward_pass.js +0 -137
  217. package/dist/render/forward_pass.js.map +0 -1
  218. package/dist/render/helper.js +0 -38
  219. package/dist/render/helper.js.map +0 -1
  220. package/dist/render/renderscheme.js +0 -61
  221. package/dist/render/renderscheme.js.map +0 -1
  222. package/dist/render/temporalcache.js +0 -222
  223. package/dist/scene/model.js +0 -111
  224. package/dist/scene/model.js.map +0 -1
  225. package/dist/scene/octree_update_visitor.js +0 -20
  226. package/dist/scene/octree_update_visitor.js.map +0 -1
  227. package/dist/shaders/builtins.js +0 -110
  228. package/dist/shaders/builtins.js.map +0 -1
  229. package/dist/shaders/framework.js +0 -723
  230. package/dist/shaders/lighting.js +0 -335
  231. package/dist/shaders/lighting.js.map +0 -1
  232. package/dist/utility/sheenlut.js +0 -196
  233. package/dist/utility/sheenlut.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"watermesh.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"watermesh.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Abstract class for wave generators.
3
+ * @public
4
+ */ class WaveGenerator {
5
+ }
6
+
7
+ export { WaveGenerator };
8
+ //# sourceMappingURL=wavegenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wavegenerator.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -14,12 +14,10 @@ import { Vector4 } from '@zephyr3d/base';
14
14
  static _compositeProgram;
15
15
  static _compositeBindGroup;
16
16
  static _compositeRenderStates;
17
- _accumBuffer;
18
17
  /**
19
18
  * Creates an instance of WeightedBlendedOIT class.
20
19
  */ constructor(){
21
20
  super();
22
- this._accumBuffer = null;
23
21
  }
24
22
  /**
25
23
  * {@inheritDoc OIT.getType}
@@ -121,32 +119,17 @@ import { Vector4 } from '@zephyr3d/base';
121
119
  drawFullscreenQuad(WeightedBlendedOIT._compositeRenderStates);
122
120
  }
123
121
  /** @internal */ getAccumFramebuffer(ctx, device) {
124
- const vp = device.getViewport();
125
- const width = device.screenToDevice(vp.width);
126
- const height = device.screenToDevice(vp.height);
127
- if (this._accumBuffer) {
128
- if (this._accumBuffer.getWidth() !== width || this._accumBuffer.getHeight() !== height || this._accumBuffer.getDepthAttachment() !== ctx.depthTexture) {
129
- this._accumBuffer.dispose();
130
- this._accumBuffer = null;
131
- }
132
- }
133
- if (!this._accumBuffer) {
134
- const accumColor = device.createTexture2D('rgba16f', width, height, {
135
- samplerOptions: {
136
- mipFilter: 'none'
137
- }
138
- });
139
- const accumAlpha = device.createTexture2D(device.type === 'webgl' ? 'rgba16f' : 'r16f', width, height, {
140
- samplerOptions: {
141
- mipFilter: 'none'
142
- }
143
- });
144
- this._accumBuffer = device.createFrameBuffer([
145
- accumColor,
146
- accumAlpha
147
- ], ctx.depthTexture);
148
- }
149
- return this._accumBuffer;
122
+ const width = ctx.depthTexture.width;
123
+ const height = ctx.depthTexture.height;
124
+ const accumColor = device.pool.fetchTemporalTexture2D(false, 'rgba16f', width, height, false);
125
+ const accumAlpha = device.pool.fetchTemporalTexture2D(false, device.type === 'webgl' ? 'rgba16f' : 'r16f', width, height, false);
126
+ const fb = device.pool.createTemporalFramebuffer(true, [
127
+ accumColor,
128
+ accumAlpha
129
+ ], ctx.depthTexture);
130
+ device.pool.releaseTexture(accumColor);
131
+ device.pool.releaseTexture(accumAlpha);
132
+ return fb;
150
133
  }
151
134
  /** @internal */ static getCompositeProgram(device) {
152
135
  if (!this._compositeProgram) {
@@ -1 +1 @@
1
- {"version":3,"file":"weightedblended_oit.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"weightedblended_oit.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { GraphNode } from './graph_node.js';
2
- import '@zephyr3d/base';
2
+ import { Matrix4x4 } from '@zephyr3d/base';
3
3
  import './octree.js';
4
+ import '../values.js';
4
5
  import '../app.js';
5
6
  import { InstanceBindGroupAllocator, RenderQueue } from '../render/render_queue.js';
6
7
  import '../material/shader/helper.js';
@@ -8,7 +9,6 @@ import '../render/renderer.js';
8
9
  import '../render/sky.js';
9
10
  import '../render/clipmap.js';
10
11
  import '@zephyr3d/device';
11
- import '../render/watermesh.js';
12
12
  import '../material/lambert.js';
13
13
  import '../material/blinn.js';
14
14
  import '../material/unlit.js';
@@ -17,7 +17,9 @@ import '../material/grassmaterial.js';
17
17
  import '../material/terrainmaterial.js';
18
18
  import '../material/pbrmr.js';
19
19
  import '../material/pbrsg.js';
20
+ import { BoundingBox } from '../utility/bounding_volume.js';
20
21
 
22
+ const tmpMatrix = new Matrix4x4();
21
23
  /**
22
24
  * Batch group node
23
25
  * @public
@@ -25,32 +27,44 @@ import '../material/pbrsg.js';
25
27
  _renderQueueMap;
26
28
  _bindGroupAllocator;
27
29
  _changeTag;
30
+ _staticBV;
28
31
  /**
29
32
  * Creates an instance of mesh node
30
33
  * @param scene - The scene to which the mesh node belongs
31
34
  */ constructor(scene){
32
35
  super(scene);
33
- this._renderQueueMap = new WeakMap();
36
+ this._renderQueueMap = new Map();
34
37
  this._changeTag = 0;
35
38
  this._bindGroupAllocator = new InstanceBindGroupAllocator();
39
+ this._staticBV = false;
40
+ const bvCallback = (function() {
41
+ if (!this._staticBV) {
42
+ this.invalidateBoundingVolume();
43
+ }
44
+ }).bind(this);
36
45
  this.on('nodeattached', (node)=>{
37
46
  node.iterate((child)=>{
38
- if (child.isGraphNode()) {
39
- if (!child.isMesh()) {
40
- console.error('Only mesh node can be added to batch group');
41
- }
47
+ if (child.isMesh()) {
42
48
  child.placeToOctree = false;
49
+ if (!this._staticBV) {
50
+ this.invalidateBoundingVolume();
51
+ }
52
+ child.on('bvchanged', bvCallback);
53
+ this._changeTag++;
43
54
  }
44
55
  });
45
- this._changeTag++;
46
56
  });
47
57
  this.on('noderemoved', (node)=>{
48
58
  node.iterate((child)=>{
49
- if (child.isGraphNode()) {
59
+ if (child.isMesh()) {
50
60
  child.placeToOctree = true;
61
+ if (!this._staticBV) {
62
+ this.invalidateBoundingVolume();
63
+ }
64
+ child.off('bvchanged', bvCallback);
65
+ this._changeTag++;
51
66
  }
52
67
  });
53
- this._changeTag++;
54
68
  });
55
69
  }
56
70
  /**
@@ -63,10 +77,42 @@ import '../material/pbrsg.js';
63
77
  */ isBatchGroup() {
64
78
  return true;
65
79
  }
66
- /** @internal */ computeBoundingVolume(bv) {
67
- return super.computeBoundingVolume(bv);
80
+ /**
81
+ * Force the batch state to be rebuilt
82
+ */ invalidate() {
83
+ this._changeTag++;
84
+ }
85
+ /** @internal */ _detached() {
86
+ // Usually the node will be garbage collected after it is detached,
87
+ // We should reset the render queue to release the render bundles.
88
+ this._renderQueueMap.forEach((val)=>{
89
+ val.queue.reset();
90
+ });
91
+ this.invalidate();
92
+ }
93
+ /** @internal */ _attached() {
94
+ // Reset the render queue when attached to a new scene.
95
+ this.invalidate();
96
+ }
97
+ /** @internal */ computeBoundingVolume() {
98
+ const bv = new BoundingBox();
99
+ const invWorldMatrix = Matrix4x4.invertAffine(this.worldMatrix);
100
+ bv.beginExtend();
101
+ this.iterate((node)=>{
102
+ if (node.isMesh()) {
103
+ Matrix4x4.multiplyAffine(invWorldMatrix, node.worldMatrix, tmpMatrix);
104
+ const wb = node.getBoundingVolume().transform(tmpMatrix).toAABB();
105
+ bv.extend(wb.minPoint);
106
+ bv.extend(wb.maxPoint);
107
+ }
108
+ });
109
+ return bv.isValid() ? bv : null;
110
+ }
111
+ /** @internal */ setBoundingVolume(bv) {
112
+ this._staticBV = !!bv;
113
+ super.setBoundingVolume(bv);
68
114
  }
69
- getRenderQueue(cullVisitor) {
115
+ /** @internal */ cull(cullVisitor) {
70
116
  let queueInfo = this._renderQueueMap.get(cullVisitor.renderPass);
71
117
  if (!queueInfo) {
72
118
  queueInfo = {
@@ -91,7 +137,7 @@ import '../material/pbrsg.js';
91
137
  cullVisitor.frustumCulling = frustumCulling;
92
138
  cullVisitor.renderQueue = renderQueue;
93
139
  }
94
- return queueInfo.queue;
140
+ cullVisitor.pushRenderQueue(queueInfo.queue);
95
141
  }
96
142
  }
97
143
 
@@ -1 +1 @@
1
- {"version":3,"file":"batchgroup.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"batchgroup.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,6 @@
1
1
  import { Vector4 } from '@zephyr3d/base';
2
2
  import './octree.js';
3
+ import '../values.js';
3
4
  import '../app.js';
4
5
  import '@zephyr3d/device';
5
6
  import '../material/shader/helper.js';
@@ -14,8 +15,7 @@ import '../material/pbrsg.js';
14
15
  import '../render/renderer.js';
15
16
  import { SkyRenderer } from '../render/sky.js';
16
17
  import '../render/clipmap.js';
17
- import { EnvIBL, EnvHemisphericAmbient, EnvConstantAmbient } from '../render/envlight.js';
18
- import '../render/watermesh.js';
18
+ import { EnvIBL, EnvHemisphericAmbient, EnvConstantAmbient, EnvShIBL } from '../render/envlight.js';
19
19
 
20
20
  /**
21
21
  * Wrapper for environmant lighting
@@ -27,6 +27,7 @@ import '../render/watermesh.js';
27
27
  _ambientUp;
28
28
  _radianceMap;
29
29
  _irradianceMap;
30
+ _irradianceSH;
30
31
  _strength;
31
32
  /** @internal */ constructor(){
32
33
  this._envLight = new EnvIBL();
@@ -38,7 +39,7 @@ import '../render/watermesh.js';
38
39
  this._strength = 1;
39
40
  }
40
41
  /** @internal */ getHash(ctx) {
41
- return ctx.drawEnvLight ? `${this.type}:${this._envLight.hasRadiance() ? '1' : '0'}:${this._envLight.hasIrradiance() ? '1' : '0'}` : 'none';
42
+ return !ctx || ctx.drawEnvLight ? `${this.type}:${this._envLight.hasRadiance() ? '1' : '0'}:${this._envLight.hasIrradiance() ? '1' : '0'}` : 'none';
42
43
  }
43
44
  /** @internal */ get envLight() {
44
45
  return this._envLight;
@@ -83,6 +84,8 @@ import '../render/watermesh.js';
83
84
  this._radianceMap = tex ?? null;
84
85
  if (this.type === 'ibl') {
85
86
  this._envLight.radianceMap = this._radianceMap;
87
+ } else if (this.type === 'ibl-sh') {
88
+ this._envLight.radianceMap = this._radianceMap;
86
89
  }
87
90
  }
88
91
  /** Irradiance map for environment light type ibl */ get irradianceMap() {
@@ -94,6 +97,15 @@ import '../render/watermesh.js';
94
97
  this._envLight.irradianceMap = this._irradianceMap;
95
98
  }
96
99
  }
100
+ /** Irradiance SH for environment light type ibl-sh */ get irradianceSH() {
101
+ return this._irradianceSH;
102
+ }
103
+ set irradianceSH(value) {
104
+ this._irradianceSH = value ?? null;
105
+ if (this.type === 'ibl-sh') {
106
+ this._envLight.irradianceSH = this._irradianceSH;
107
+ }
108
+ }
97
109
  /** The environment light type */ get type() {
98
110
  return this._envLight?.getType() ?? 'none';
99
111
  }
@@ -106,6 +118,15 @@ import '../render/watermesh.js';
106
118
  if (this._envLight?.getType() !== val) {
107
119
  this._envLight = new EnvIBL(this._radianceMap, this._irradianceMap);
108
120
  }
121
+ this._envLight.radianceMap = this.radianceMap;
122
+ this._envLight.irradianceMap = this.irradianceMap;
123
+ break;
124
+ case 'ibl-sh':
125
+ if (this._envLight?.getType() !== val) {
126
+ this._envLight = new EnvShIBL(this._radianceMap, this._irradianceSH);
127
+ }
128
+ this._envLight.radianceMap = this.radianceMap;
129
+ this._envLight.irradianceSH = this.irradianceSH;
109
130
  break;
110
131
  case 'constant':
111
132
  if (this._envLight?.getType() !== val) {
@@ -1 +1 @@
1
- {"version":3,"file":"environment.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"environment.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -15,7 +15,6 @@ import { SceneNode } from './scene_node.js';
15
15
  * @param scene - The scene to which the node belongs
16
16
  */ constructor(scene){
17
17
  super(scene);
18
- this._renderOrder = 0;
19
18
  this._octreeNode = null;
20
19
  }
21
20
  /** @internal */ get octreeNode() {
@@ -24,14 +23,6 @@ import { SceneNode } from './scene_node.js';
24
23
  set octreeNode(node) {
25
24
  this._octreeNode = node;
26
25
  }
27
- /**
28
- * Render order of the node
29
- */ get renderOrder() {
30
- return this._renderOrder;
31
- }
32
- set renderOrder(val) {
33
- this._renderOrder = val;
34
- }
35
26
  /** Gets the name */ getName() {
36
27
  return this._name;
37
28
  }
@@ -52,11 +43,6 @@ import { SceneNode } from './scene_node.js';
52
43
  return null;
53
44
  }
54
45
  /**
55
- * {@inheritDoc Drawable.getInvBindMatrix}
56
- */ getInvBindMatrix() {
57
- return null;
58
- }
59
- /**
60
46
  * {@inheritDoc Drawable.getSortDistance}
61
47
  */ getSortDistance(camera) {
62
48
  const cameraWorldMatrix = camera.worldMatrix;
@@ -1 +1 @@
1
- {"version":3,"file":"graph_node.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"graph_node.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -293,7 +293,7 @@ export class HemiSphericLight extends AmbientLight {
293
293
  */ isDirectionLight() {
294
294
  return true;
295
295
  }
296
- /** @internal */ computeBoundingVolume(bv) {
296
+ /** @internal */ computeBoundingVolume() {
297
297
  return null;
298
298
  }
299
299
  /** @internal */ computeUniforms() {
@@ -342,8 +342,8 @@ export class HemiSphericLight extends AmbientLight {
342
342
  */ isPointLight() {
343
343
  return true;
344
344
  }
345
- /** @internal */ computeBoundingVolume(bv) {
346
- const bbox = bv ? bv : new BoundingBox();
345
+ /** @internal */ computeBoundingVolume() {
346
+ const bbox = new BoundingBox();
347
347
  bbox.minPoint = new Vector3(-this._range, -this._range, -this._range);
348
348
  bbox.maxPoint = new Vector3(this._range, this._range, this._range);
349
349
  return bbox;
@@ -415,8 +415,8 @@ export class HemiSphericLight extends AmbientLight {
415
415
  */ isSpotLight() {
416
416
  return true;
417
417
  }
418
- /** @internal */ computeBoundingVolume(bv) {
419
- const bbox = bv ? bv : new BoundingBox();
418
+ /** @internal */ computeBoundingVolume() {
419
+ const bbox = new BoundingBox();
420
420
  const cosCutoff = Math.cos(this._cutoff);
421
421
  const r = this._range / cosCutoff * Math.sqrt(1 - cosCutoff * cosCutoff);
422
422
  bbox.minPoint = new Vector3(-r, -r, 0);
@@ -8,6 +8,7 @@ import { LambertMaterial } from '../material/lambert.js';
8
8
  import '../material/blinn.js';
9
9
  import '../material/unlit.js';
10
10
  import { QUEUE_OPAQUE } from '../values.js';
11
+ import { RenderBundleWrapper } from '../render/renderbundle_wrapper.js';
11
12
  import '../material/meshmaterial.js';
12
13
  import '../material/grassmaterial.js';
13
14
  import '../material/terrainmaterial.js';
@@ -25,9 +26,11 @@ import { mixinDrawable } from '../render/drawable_mixin.js';
25
26
  /** @internal */ _bboxChangeCallback;
26
27
  /** @internal */ _animatedBoundingBox;
27
28
  /** @internal */ _boneMatrices;
28
- /** @internal */ _invBindMatrix;
29
+ /** @internal */ _morphData;
30
+ /** @internal */ _morphInfo;
29
31
  /** @internal */ _instanceHash;
30
32
  /** @internal */ _batchable;
33
+ /** @internal */ _pickTarget;
31
34
  /** @internal */ _boundingBoxNode;
32
35
  /** @internal */ _instanceColor;
33
36
  /**
@@ -40,8 +43,12 @@ import { mixinDrawable } from '../render/drawable_mixin.js';
40
43
  this._castShadow = true;
41
44
  this._animatedBoundingBox = null;
42
45
  this._boneMatrices = null;
43
- this._invBindMatrix = null;
46
+ this._morphData = null;
47
+ this._morphInfo = null;
44
48
  this._instanceHash = null;
49
+ this._pickTarget = {
50
+ node: this
51
+ };
45
52
  this._boundingBoxNode = null;
46
53
  this._instanceColor = Vector4.zero();
47
54
  this._batchable = Application.instance.deviceType !== 'webgl';
@@ -73,7 +80,13 @@ import { mixinDrawable } from '../render/drawable_mixin.js';
73
80
  /**
74
81
  * {@inheritDoc Drawable.getPickTarget }
75
82
  */ getPickTarget() {
76
- return this;
83
+ return this._pickTarget;
84
+ }
85
+ setPickTarget(node, label) {
86
+ this._pickTarget = {
87
+ node,
88
+ label
89
+ };
77
90
  }
78
91
  /** Wether the mesh node casts shadows */ get castShadow() {
79
92
  return this._castShadow;
@@ -95,6 +108,7 @@ import { mixinDrawable } from '../render/drawable_mixin.js';
95
108
  }
96
109
  this._instanceHash = this._primitive && this._material ? `${this.constructor.name}:${this._scene.id}:${this._primitive.id}:${this._material.instanceId}` : null;
97
110
  this.invalidateBoundingVolume();
111
+ RenderBundleWrapper.drawableChanged(this);
98
112
  }
99
113
  }
100
114
  /** Material of the mesh */ get material() {
@@ -102,8 +116,15 @@ import { mixinDrawable } from '../render/drawable_mixin.js';
102
116
  }
103
117
  set material(m) {
104
118
  if (this._material !== m) {
119
+ if (this._material) {
120
+ RenderBundleWrapper.materialDetached(this._material.coreMaterial, this);
121
+ }
105
122
  this._material = m;
123
+ if (this._material) {
124
+ RenderBundleWrapper.materialAttached(this._material.coreMaterial, this);
125
+ }
106
126
  this._instanceHash = this._primitive && this._material ? `${this.constructor.name}:${this._scene.id}:${this._primitive.id}:${this._material.instanceId}` : null;
127
+ RenderBundleWrapper.drawableChanged(this);
107
128
  }
108
129
  }
109
130
  /** Wether to draw the bounding box of the mesh node */ get drawBoundingBox() {
@@ -142,23 +163,49 @@ import { mixinDrawable } from '../render/drawable_mixin.js';
142
163
  * Sets the texture that contains the bone matrices for skeletal animation
143
164
  * @param matrices - The texture that contains the bone matrices
144
165
  */ setBoneMatrices(matrices) {
145
- this._boneMatrices = matrices;
166
+ if (this._boneMatrices !== matrices) {
167
+ this._boneMatrices = matrices;
168
+ RenderBundleWrapper.drawableChanged(this);
169
+ }
146
170
  }
147
171
  /**
148
- * Sets the inverse bind matrix for skeletal animation
149
- * @param matrix - The matrix to set
150
- */ setInvBindMatrix(matrix) {
151
- this._invBindMatrix = matrix;
172
+ * Sets the texture that contains the morph target data
173
+ * @param data - The texture that contains the morph target data
174
+ */ setMorphData(data) {
175
+ if (this._morphData !== data) {
176
+ this._morphData = data;
177
+ RenderBundleWrapper.drawableChanged(this);
178
+ }
179
+ }
180
+ /**
181
+ * {@inheritDoc Drawable.getMorphData}
182
+ */ getMorphData() {
183
+ return this._morphData;
184
+ }
185
+ /**
186
+ * Sets the buffer that contains the morph target information
187
+ * @param info - The buffer that contains the morph target information
188
+ */ setMorphInfo(info) {
189
+ if (this._morphInfo !== info) {
190
+ this._morphInfo = info;
191
+ RenderBundleWrapper.drawableChanged(this);
192
+ }
193
+ }
194
+ /**
195
+ * {@inheritDoc Drawable.getMorphInfo}
196
+ */ getMorphInfo() {
197
+ return this._morphInfo;
152
198
  }
153
199
  /**
154
200
  * {@inheritDoc Drawable.isBatchable}
155
201
  */ isBatchable() {
156
- return this._batchable && !this._boneMatrices && this._material?.isBatchable();
202
+ return this._batchable && !this._boneMatrices && !this._morphData && this._material?.isBatchable();
157
203
  }
158
204
  /** Disposes the mesh node */ dispose() {
159
205
  this._primitive = null;
160
206
  this._material = null;
161
207
  super.dispose();
208
+ RenderBundleWrapper.drawableChanged(this);
162
209
  }
163
210
  /**
164
211
  * {@inheritDoc Drawable.getQueueType}
@@ -171,6 +218,11 @@ import { mixinDrawable } from '../render/drawable_mixin.js';
171
218
  return !this.material?.supportLighting();
172
219
  }
173
220
  /**
221
+ * {@inheritDoc Drawable.needSceneColor}
222
+ */ needSceneColor() {
223
+ return this.material?.needSceneColor();
224
+ }
225
+ /**
174
226
  * {@inheritDoc Drawable.draw}
175
227
  */ draw(ctx) {
176
228
  this.bind(ctx);
@@ -187,17 +239,12 @@ import { mixinDrawable } from '../render/drawable_mixin.js';
187
239
  return this._boneMatrices;
188
240
  }
189
241
  /**
190
- * {@inheritDoc Drawable.getInvBindMatrix}
191
- */ getInvBindMatrix() {
192
- return this._invBindMatrix;
193
- }
194
- /**
195
242
  * {@inheritDoc Drawable.getXForm}
196
243
  */ getXForm() {
197
244
  // mesh transform should be ignored when skinned
198
245
  return this;
199
246
  }
200
- /** @internal */ computeBoundingVolume(bv) {
247
+ /** @internal */ computeBoundingVolume() {
201
248
  let bbox;
202
249
  if (this._animatedBoundingBox) {
203
250
  bbox = this._animatedBoundingBox;
@@ -1 +1 @@
1
- {"version":3,"file":"mesh.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"mesh.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -515,9 +515,12 @@ var OctreePlacement;
515
515
  * @returns Head node of the located node chain
516
516
  */ locateNodeChain(candidate, center, radius) {
517
517
  let level = this._chunks.length - 1;
518
- while(level && this._chunks[level].getNodeSize() < 4 * radius){
518
+ while(level >= 0 && this._chunks[level].getNodeSize() < 4 * radius){
519
519
  --level;
520
520
  }
521
+ if (level < 0) {
522
+ return null;
523
+ }
521
524
  const dim = this._chunks[level].getDimension();
522
525
  const inv_node_size = 1 / this._chunks[level].getNodeSize();
523
526
  const px = Math.floor((center.x + this._rootSize * 0.5) * inv_node_size);
@@ -595,7 +598,7 @@ var OctreePlacement;
595
598
  }
596
599
  }
597
600
  resize(size) {
598
- size = Math.max(nextPowerOf2(size), this._leafSize);
601
+ size = Math.max(nextPowerOf2(Math.ceil(size)), this._leafSize);
599
602
  if (size === this._rootSize) {
600
603
  return;
601
604
  }
@@ -1 +1 @@
1
- {"version":3,"file":"octree.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"octree.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -38,7 +38,9 @@ import { OctreeNode } from './octree.js';
38
38
  const d = node.rayIntersect(this._rayLocal); // this._rayLocal.bboxIntersectionTestEx(node.getBoundingVolume().toAABB());
39
39
  if (d !== null && d < this._intersectedDist) {
40
40
  this._intersectedDist = d;
41
- this._intersected = node;
41
+ this._intersected = {
42
+ node
43
+ };
42
44
  return true;
43
45
  }
44
46
  }
@@ -50,7 +52,7 @@ import { OctreeNode } from './octree.js';
50
52
  const d = node.primitive.raycast(this._rayLocal);
51
53
  if (d !== null && d < this._intersectedDist) {
52
54
  this._intersectedDist = d;
53
- this._intersected = node.getPickTarget() ?? node;
55
+ this._intersected = node.getPickTarget();
54
56
  return true;
55
57
  }
56
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"raycast_visitor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"raycast_visitor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -81,18 +81,15 @@ import { Environment } from './environment.js';
81
81
  }
82
82
  /**
83
83
  * Cast a ray into the scene to get the closest object hit by the ray
84
- * @param camera - The camera used to compute the ray
85
- * @param screenX - The x position on screen
86
- * @param screenY - The y position on screen
84
+ *
85
+ * @param ray - The ray in world coordinate space
86
+ * @param length - Length of the ray
87
87
  * @returns The closest object hit by the ray
88
- */ raycast(camera, screenX, screenY) {
89
- const width = camera.viewport ? camera.viewport[2] : Application.instance.device.getViewport().width;
90
- const height = camera.viewport ? camera.viewport[3] : Application.instance.device.getViewport().height;
91
- const ray = this.constructRay(camera, width, height, screenX, screenY);
92
- const raycastVisitor = new RaycastVisitor(ray, camera.getFarPlane());
88
+ */ raycast(ray, length = Infinity) {
89
+ const raycastVisitor = new RaycastVisitor(ray, length);
93
90
  this.octree.getRootNode().traverse(raycastVisitor);
94
91
  return raycastVisitor.intersected ? {
95
- node: raycastVisitor.intersected,
92
+ target: raycastVisitor.intersected,
96
93
  dist: raycastVisitor.intersectedDist,
97
94
  point: raycastVisitor.intersectedPoint
98
95
  } : null;
@@ -1 +1 @@
1
- {"version":3,"file":"scene.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"scene.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}