@woosh/meep-engine 2.33.23 → 2.33.24

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 (204) hide show
  1. package/core/bvh2/BinaryNode.js +1 -1
  2. package/core/bvh2/aabb3/AABB3.js +18 -0
  3. package/core/bvh2/aabb3/AABB3Math.js +1 -1
  4. package/core/bvh2/binary/2/BinaryUint32BVH.js +498 -0
  5. package/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
  6. package/core/bvh2/binary/IndexedBinaryBVH.js +22 -26
  7. package/core/collection/ArrayUtils.js +1 -1
  8. package/core/collection/array/arrayQuickSort.js +9 -6
  9. package/core/collection/array/array_swap.js +22 -0
  10. package/core/collection/array/computeHashArray.js +22 -0
  11. package/core/collection/array/computeHashIntegerArray.js +15 -0
  12. package/core/collection/table/DataType2TypedArrayConstructorMapping.js +15 -0
  13. package/core/color/Color.js +2 -1
  14. package/core/function/FunctionCompiler.js +2 -1
  15. package/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane.js +9 -33
  16. package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
  17. package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +41 -0
  18. package/core/geom/3d/morton/mortonEncode_magicbits.js +2 -1
  19. package/core/geom/3d/morton/reinterpret_float32_as_int32.js +13 -0
  20. package/core/geom/3d/morton/v3_morton_encode_transformed.js +33 -0
  21. package/core/geom/3d/ray/ray_computeNearestPointToPoint.js +37 -0
  22. package/core/geom/3d/shape/AbstractShape3D.js +29 -0
  23. package/core/geom/3d/shape/CompositeShape.js +60 -0
  24. package/core/geom/3d/shape/TransformedShape3D.js +70 -0
  25. package/core/geom/3d/shape/UnitCubeShape3D.js +13 -0
  26. package/core/geom/3d/shape/UnitSphereShape3D.js +16 -0
  27. package/core/geom/AABB2.js +1 -1
  28. package/core/geom/ConicRay.js +3 -1
  29. package/core/geom/LineSegment.js +0 -78
  30. package/core/geom/Matrix4.js +7 -8
  31. package/core/geom/Rectangle.js +2 -1
  32. package/core/geom/Vector1.js +1 -1
  33. package/core/geom/Vector3.js +2 -1
  34. package/core/geom/Vector4.js +2 -1
  35. package/core/geom/random/randomPointInBox.js +7 -3
  36. package/core/geom/random/randomPointInPoint.js +6 -3
  37. package/core/geom/random/randomPointInSphere.js +6 -3
  38. package/core/geom/random/randomPointOnBox.js +7 -3
  39. package/core/geom/random/randomPointOnSphere.js +6 -3
  40. package/core/geom/v3_length.js +8 -3
  41. package/core/graph/graph_k_means_cluster.js +1 -1
  42. package/core/math/MathUtils.js +0 -354
  43. package/core/math/MathUtils.spec.js +7 -1
  44. package/core/math/gaussian.js +9 -0
  45. package/core/math/hash/computeHashFloat.js +17 -0
  46. package/core/math/hash/computeHashFloatArray.js +34 -0
  47. package/core/math/hash/computeObjectHash.js +54 -0
  48. package/core/math/intersects1D.js +19 -0
  49. package/core/math/interval/NumericInterval.js +2 -2
  50. package/core/math/isValueBetween.js +10 -0
  51. package/core/math/isValueBetweenInclusive.js +10 -0
  52. package/core/math/noise/curl_noise_3dt.js +1 -1
  53. package/core/math/noise/sdnoise.js +10 -10
  54. package/core/math/overlap1D.js +19 -0
  55. package/core/math/pingpong.js +17 -0
  56. package/core/math/random/makeRangedRandom.js +19 -0
  57. package/core/math/random/randomFloatBetween.js +14 -0
  58. package/core/math/random/randomFromArray.js +19 -0
  59. package/core/math/random/randomGaussian.js +15 -0
  60. package/core/math/random/randomIntegerBetween.js +14 -0
  61. package/core/math/random/roundFair.js +15 -0
  62. package/core/math/separation1D.js +21 -0
  63. package/core/math/solveQuadratic.js +25 -0
  64. package/core/model/BoundedValue.js +1 -1
  65. package/core/model/node-graph/node/NodeInstancePortReference.js +1 -1
  66. package/core/model/node-graph/node/Port.js +1 -1
  67. package/core/model/reactive/evaluation/MultiPredicateEvaluator.spec.js +3 -1
  68. package/core/model/reactive/model/ReactiveBinaryExpression.js +1 -1
  69. package/core/model/reactive/model/terminal/ReactiveLiteralNumber.js +1 -1
  70. package/core/model/reactive/model/terminal/ReactiveReference.js +1 -1
  71. package/core/model/reactive/model/util/createRandomReactiveExpression.js +1 -1
  72. package/core/model/stat/LinearModifier.js +1 -1
  73. package/engine/animation/curve/AnimationCurve.js +72 -0
  74. package/engine/animation/curve/Keyframe.js +27 -0
  75. package/engine/animation/keyed2/AnimationTrack.js +27 -3
  76. package/engine/asset/Asset.js +1 -1
  77. package/engine/asset/loaders/GLTFAssetLoader.d.ts +1 -1
  78. package/engine/asset/loaders/GLTFAssetLoader.js +10 -0
  79. package/engine/asset/loaders/image/ImageRGBADataAsset.js +8 -1
  80. package/engine/asset/loaders/material/computeMaterialHash.js +3 -1
  81. package/engine/asset/loaders/material/computeTextureHash.js +2 -1
  82. package/engine/ecs/animation/Animation.js +2 -1
  83. package/engine/ecs/animation/InverseKinematics.js +2 -1
  84. package/engine/ecs/dynamic_actions/DynamicActorSystem.js +2 -1
  85. package/engine/ecs/dynamic_actions/DynamicRuleDescriptionTable.spec.js +3 -5
  86. package/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +1 -1
  87. package/engine/ecs/evaluation/complex/PointFitnessGaussianBlur.js +1 -1
  88. package/engine/ecs/foliage/ecs/Foliage2.js +1 -1
  89. package/engine/ecs/fow/shader/FogOfWarRenderer.js +1 -1
  90. package/engine/ecs/gui/GUIElement.js +1 -1
  91. package/engine/ecs/gui/hud/HeadsUpDisplay.js +1 -1
  92. package/engine/ecs/gui/position/ViewportPosition.js +2 -1
  93. package/engine/ecs/systems/RangedAttackSystem.js +1 -1
  94. package/engine/ecs/systems/SteeringSystem.js +1 -1
  95. package/engine/ecs/terrain/tiles/TerrainTileManager.js +1 -1
  96. package/engine/ecs/tooltip/TooltipComponent.js +15 -0
  97. package/engine/graphics/ecs/animation/animator/AnimationClip.js +2 -1
  98. package/engine/graphics/ecs/animation/animator/AnimationClipDefinition.js +2 -1
  99. package/engine/graphics/ecs/animation/animator/AnimationNotification.js +2 -1
  100. package/engine/graphics/ecs/animation/animator/AnimationNotificationDefinition.js +2 -1
  101. package/engine/graphics/ecs/animation/animator/graph/AnimationGraph.js +2 -1
  102. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +2 -1
  103. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationStateDefinition.js +1 -1
  104. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.js +2 -1
  105. package/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
  106. package/engine/graphics/ecs/highlight/HighlightDefinition.js +2 -1
  107. package/engine/graphics/ecs/light/Light.d.ts +1 -1
  108. package/engine/graphics/ecs/light/Light.js +3 -0
  109. package/engine/graphics/ecs/mesh/Mesh.js +2 -1
  110. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +13 -0
  111. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
  112. package/engine/graphics/geometry/AttributeSpec.js +105 -0
  113. package/engine/graphics/{micron/format/MicronVertexDataSpec.js → geometry/VertexDataSpec.js} +56 -25
  114. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +7 -7
  115. package/engine/graphics/micron/build/fill_patch_geometry_data.js +1 -1
  116. package/engine/graphics/micron/buildPatchwork.js +1 -1
  117. package/engine/graphics/micron/format/MicronGeometry.js +3 -3
  118. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +2 -2
  119. package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +1 -1
  120. package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +1 -1
  121. package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
  122. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +5 -5
  123. package/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +1 -1
  124. package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js +80 -16
  125. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +57 -52
  126. package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +2 -1
  127. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +51 -12
  128. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +3 -2
  129. package/engine/graphics/particles/particular/engine/emitter/computeEmissionFunction.js +1 -1
  130. package/engine/graphics/particles/particular/engine/emitter/serde/ParameterLookupTableSerializationAdapter.js +8 -2
  131. package/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +2 -1
  132. package/engine/graphics/particles/particular/engine/parameter/ParameterTrack.js +1 -1
  133. package/engine/graphics/particles/particular/engine/parameter/ParticleParameter.js +1 -1
  134. package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +21 -0
  135. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +0 -20
  136. package/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +9 -9
  137. package/engine/graphics/particles/particular/engine/simulator/SimulationStepApplyForce.js +2 -5
  138. package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseAcceleration.js +2 -6
  139. package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseVelocity.js +2 -7
  140. package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +2 -5
  141. package/engine/graphics/particles/particular/engine/simulator/update_parameters.js +1 -1
  142. package/engine/graphics/particles/particular/engine/utils/distributeParticlesOnObject3D.js +1 -1
  143. package/engine/graphics/particles/particular/engine/utils/distrubuteParticlesOnMesh.js +1 -1
  144. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +384 -0
  145. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +558 -0
  146. package/engine/graphics/particles/particular/group/Operation.js +18 -0
  147. package/engine/graphics/particles/particular/group/OperationType.js +9 -0
  148. package/engine/graphics/particles/particular/group/ParticleAttribute.js +2 -1
  149. package/engine/graphics/particles/particular/group/ParticleAttributeType.js +11 -0
  150. package/engine/graphics/particles/particular/group/ParticleDataType.js +10 -0
  151. package/engine/graphics/particles/particular/group/ParticleGroup.js +7 -245
  152. package/engine/graphics/particles/particular/group/ParticleGroup.spec.js +3 -1
  153. package/engine/graphics/particles/particular/group/ParticleSpecification.js +21 -14
  154. package/engine/graphics/particles/particular/group/itemSizeFromAttributeType.js +20 -0
  155. package/engine/graphics/particles/particular/group/optimizeCommandQueue.js +162 -0
  156. package/engine/graphics/particles/particular/group/typedArrayConstructorFromDataType.js +19 -0
  157. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +1 -1
  158. package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameter.js +2 -1
  159. package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +1 -1
  160. package/engine/graphics/render/forward_plus/LightManager.js +117 -94
  161. package/engine/graphics/render/forward_plus/PointLight.js +9 -0
  162. package/engine/graphics/render/forward_plus/PointLightData.js +1 -1
  163. package/engine/graphics/render/forward_plus/SpotLight.js +9 -0
  164. package/engine/graphics/render/forward_plus/cluster/compute_light_data_hash_0.js +2 -2
  165. package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
  166. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +5 -5
  167. package/engine/graphics/render/forward_plus/prototypeLightManager.js +180 -86
  168. package/engine/graphics/render/forward_plus/query/analytical_triplanar_corner_mapping.js +8 -0
  169. package/engine/graphics/render/forward_plus/query/cube_mapping.js +38 -0
  170. package/engine/graphics/render/forward_plus/query/detailed_sphere_frustum_intersection_test.js +86 -0
  171. package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +73 -0
  172. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +131 -0
  173. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +129 -0
  174. package/engine/graphics/render/forward_plus/query/spot_light_inside_volume.js +33 -0
  175. package/engine/graphics/render/forward_plus/read_frustum_corner.js +14 -0
  176. package/engine/graphics/render/forward_plus/testClusterEquality.js +22 -0
  177. package/engine/graphics/render/visibility/IncrementalDeltaSet.js +11 -0
  178. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +1 -1
  179. package/engine/graphics/texture/sampler/HarmonicDiffusionGrid.spec.js +1 -1
  180. package/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
  181. package/engine/graphics/texture/sampler/distanceField.spec.js +1 -1
  182. package/engine/grid/components/GridObstacle.js +1 -1
  183. package/engine/intelligence/behavior/selector/WeightedElement.js +2 -1
  184. package/engine/intelligence/optimization/RandomOptimizer.js +1 -1
  185. package/engine/navigation/ecs/components/Path.js +1 -1
  186. package/engine/navigation/grid/FastBinaryHeap.spec.js +1 -1
  187. package/engine/sound/ecs/emitter/SoundEmitter.js +2 -1
  188. package/engine/sound/ecs/emitter/SoundTrack.js +2 -1
  189. package/engine/sound/material/concrete/RandomSoundMaterial.js +1 -1
  190. package/engine/ui/notification/notificationGenerator.js +1 -1
  191. package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +1 -1
  192. package/generation/grid/generation/GridTaskExecuteRuleTimes.js +2 -1
  193. package/generation/markers/actions/MarkerNodeActionSelectRandom.js +1 -1
  194. package/generation/markers/transform/MarkerNodeTransformerRecordUniqueRandomEnum.js +1 -1
  195. package/generation/placement/action/random/CellActionSelectRandom.js +1 -1
  196. package/generation/theme/ThemeEngine.js +1 -1
  197. package/misc/makeMaterialIconCached.js +2 -2
  198. package/package.json +1 -1
  199. package/view/elements/image/HTMLElementCacheKey.js +2 -1
  200. package/view/elements/radial/RadialText.js +2 -1
  201. package/view/minimap/gl/MinimapMarkersGL.js +6 -100
  202. package/view/minimap/gl/buildMaterial.js +94 -0
  203. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +0 -71
  204. package/engine/graphics/render/forward_plus/queryBVH_Frustum.js +0 -357
@@ -1,11 +1,11 @@
1
1
  import {
2
- Color,
3
- GridHelper,
4
2
  Group,
5
3
  HemisphereLight,
6
4
  Line,
7
5
  LineBasicMaterial,
8
6
  Mesh,
7
+ MeshBasicMaterial,
8
+ OctahedronBufferGeometry,
9
9
  PerspectiveCamera,
10
10
  PlaneHelper,
11
11
  Scene,
@@ -16,12 +16,11 @@ import {
16
16
  import { min2 } from "../../../../core/math/min2.js";
17
17
  import { seededRandom } from "../../../../core/math/random/seededRandom.js";
18
18
  import { PointLight } from "./PointLight.js";
19
- import { randomFloatBetween } from "../../../../core/math/MathUtils.js";
20
19
  import { makeHelperSphereGeometry } from "../../../../editor/process/symbolic/makeHelperSphereGeometry.js";
21
20
  import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
22
21
  import { MouseEvents } from "../../../input/devices/events/MouseEvents.js";
23
22
  import { RingBuffer } from "../../../../core/collection/RingBuffer.js";
24
- import { queryBVH_Frustum } from "./queryBVH_Frustum.js";
23
+ import { query_bvh_frustum_from_objects } from "./query/query_bvh_frustum_from_objects.js";
25
24
  import { prettyPrint } from "../../../../core/NumberFormat.js";
26
25
  import { FPlusDebugMaterial } from "./materials/FPlusDebugMaterial.js";
27
26
  import { parseColor } from "../../../../core/color/ColorUtils.js";
@@ -38,6 +37,12 @@ import Vector3 from "../../../../core/geom/Vector3.js";
38
37
  import { MetricCollection } from "../../../development/performance/MetricCollection.js";
39
38
  import { MetricStatistics } from "../../../development/performance/MetricStatistics.js";
40
39
  import { SpotLight } from "./SpotLight.js";
40
+ import { randomFloatBetween } from "../../../../core/math/random/randomFloatBetween.js";
41
+ import Signal from "../../../../core/events/signal/Signal.js";
42
+ import SimplexNoise from "simplex-noise";
43
+ import Stats from "three/examples/jsm/libs/stats.module.js";
44
+
45
+ const on_render = new Signal();
41
46
 
42
47
  const lm = new LightManager();
43
48
 
@@ -45,7 +50,7 @@ const camera = new PerspectiveCamera(30);
45
50
  camera.position.z = 1;
46
51
 
47
52
  camera.layers.enable(3);
48
- camera.layers.enable(1);
53
+ // camera.layers.enable(1);
49
54
 
50
55
  camera.near = 1;
51
56
  camera.far = 15;
@@ -56,14 +61,17 @@ camera.updateMatrixWorld(true);
56
61
 
57
62
  // lm.setTileMapResolution(32,32,32);
58
63
  lm.setTileMapResolution(24, 14, 8);
64
+ // lm.setTileMapResolution(16, 8, 10);
59
65
 
60
66
  console.log(lm);
67
+ window.lights = lm;
61
68
 
62
69
  const random = seededRandom(0);
63
70
 
64
71
  const scene = new Scene();
65
72
 
66
- const sphere_geometry = makeHelperSphereGeometry(1);
73
+ const sphere_geometry = new OctahedronBufferGeometry(1, 2);
74
+ const sphere_geometry_shell = makeHelperSphereGeometry(1);
67
75
  // const sphere_geometry = new SphereBufferGeometry(1, 8, 8);
68
76
 
69
77
  // const directionalLight = new DirectionalLight(0xffffff, 0.7);
@@ -77,6 +85,7 @@ scene.add(new HemisphereLight("rgb(107,187,255)", "rgb(105,97,83)", 0.2));
77
85
 
78
86
 
79
87
  const fp_materials = [];
88
+ const scratch_v2 = new Vector2();
80
89
 
81
90
  function getFPStandard() {
82
91
  const r = new FPlusStandardMaterial();
@@ -85,12 +94,6 @@ function getFPStandard() {
85
94
  r.attach_lights(lm);
86
95
  }
87
96
 
88
- if (renderer !== undefined) {
89
-
90
- renderer.getSize(
91
- r.uniforms.resolution.value
92
- );
93
- }
94
97
 
95
98
  fp_materials.push(r);
96
99
 
@@ -165,18 +168,27 @@ function addSpotLight(position, direction, color, distance = 1, angle = 1, penum
165
168
  lm.addLight(light);
166
169
  }
167
170
 
171
+ const noise = new SimplexNoise(random);
172
+
168
173
  /**
169
174
  *
170
175
  * @param {number[]} position
171
176
  * @param {number} radius
172
177
  * @param {string|number} color
173
178
  * @param {number} intensity
179
+ * @param {boolean} wander
180
+ * @param {number} [wander_radius]
174
181
  */
175
- function addPointLight(position, radius, color, intensity = 1) {
182
+ function addPointLight({
183
+ position, radius, color, intensity = 1,
184
+ wander = false,
185
+ wander_radius = 5
186
+ }) {
176
187
 
177
188
  const light = new PointLight();
178
189
 
179
- light.position.set(
190
+ const p = light.position;
191
+ p.set(
180
192
  position[0],
181
193
  position[1],
182
194
  position[2],
@@ -199,23 +211,74 @@ function addPointLight(position, radius, color, intensity = 1) {
199
211
 
200
212
  lm.addLight(light);
201
213
 
214
+ // outer shell
215
+ const visual_group = new Group();
216
+
217
+ const color_uint = light.color.toUint();
202
218
  const sphere_material = new LineBasicMaterial({
203
219
  depthTest: true,
204
220
  depthWrite: false,
205
221
  transparent: true,
206
222
  linewidth: 1,
207
223
  fog: false,
208
- color: light.color.toUint(),
224
+ color: color_uint,
209
225
  opacity: min2(intensity, 1)
210
226
  });
211
227
 
212
- const mesh = new Line(sphere_geometry, sphere_material);
228
+ const mesh = new Line(sphere_geometry_shell, sphere_material);
213
229
 
214
230
  mesh.layers.set(1);
215
- mesh.position.set(light.position.x, light.position.y, light.position.z);
216
231
  mesh.scale.setScalar(light.radius.getValue());
217
232
 
218
- scene.add(mesh)
233
+ // center
234
+ const mesh_center_0 = new Mesh(sphere_geometry, new MeshBasicMaterial({
235
+ color: color_uint
236
+ }));
237
+ mesh_center_0.scale.setScalar(0.02);
238
+
239
+ visual_group.add(mesh_center_0);
240
+
241
+ const mesh_center_1 = new Mesh(sphere_geometry, new MeshBasicMaterial({
242
+ color: color_uint,
243
+ transparent: true,
244
+ opacity: 0.033
245
+ }));
246
+ mesh_center_1.scale.setScalar(0.1);
247
+
248
+ visual_group.add(mesh_center_1);
249
+
250
+
251
+ visual_group.add(mesh);
252
+ visual_group.position.set(p.x, p.y, p.z);
253
+
254
+ scene.add(visual_group);
255
+
256
+ if (wander) {
257
+ const source_p_x = position[0];
258
+ const source_p_y = position[1];
259
+ const source_p_z = position[2];
260
+
261
+ on_render.add((renderer, camera, scene, time_delta, time) => {
262
+
263
+ const t = time * 0.0001;
264
+
265
+ const noise_x = noise.noise4D(source_p_x, source_p_y, source_p_z, t) * wander_radius;
266
+ const noise_y = noise.noise4D(source_p_x + 31.341, source_p_y - 43.23, source_p_z + 12.34, t) * wander_radius;
267
+ const noise_z = noise.noise4D(source_p_x - 231.141, source_p_y + 124.123, source_p_z - 54.4341, t) * wander_radius;
268
+
269
+ p.set(
270
+ source_p_x + noise_x,
271
+ source_p_y + noise_y,
272
+ source_p_z + noise_z,
273
+ );
274
+
275
+ visual_group.position.set(
276
+ p.x,
277
+ p.y,
278
+ p.z,
279
+ );
280
+ });
281
+ }
219
282
  }
220
283
 
221
284
  const box_geometry = new TorusKnotBufferGeometry(1, 0.3, 128, 128);
@@ -235,17 +298,18 @@ function prepare_scene_0() {
235
298
 
236
299
  const bounds_size = 15;
237
300
 
301
+ const light_radius = 5;
302
+
238
303
  for (let i = 0; i < 5000; i++) {
239
- const radius = randomFloatBetween(random, 2, 2);
304
+ const radius = randomFloatBetween(random, light_radius, light_radius);
240
305
  const intensity = randomFloatBetween(random, 2, 2);
241
- addPointLight([
242
- randomFloatBetween(random, -bounds_size, bounds_size),
243
- randomFloatBetween(random, -bounds_size, bounds_size),
244
- randomFloatBetween(random, -bounds_size, bounds_size),
245
- ],
246
- radius,
247
- `hsv(${random().toFixed(4)}, 0.8, 1)`,
248
- intensity
306
+ addPointLight({
307
+ position: [
308
+ randomFloatBetween(random, -bounds_size, bounds_size),
309
+ randomFloatBetween(random, -bounds_size, bounds_size),
310
+ randomFloatBetween(random, -bounds_size, bounds_size),
311
+ ], radius: radius, color: `hsv(${random().toFixed(4)}, 0.8, 1)`, intensity: intensity
312
+ }
249
313
  );
250
314
  }
251
315
 
@@ -264,10 +328,11 @@ function prepare_scene_0() {
264
328
  }
265
329
 
266
330
  function prepare_scene_1() {
267
- addPointLight([
268
- 0, 0, -3
269
- ], 1,
270
- 0xFF0000
331
+ addPointLight({
332
+ position: [
333
+ 0, 0, -3
334
+ ], radius: 1, color: 0xFF0000
335
+ }
271
336
  );
272
337
 
273
338
  // tight planes around the light
@@ -279,10 +344,11 @@ function prepare_scene_1() {
279
344
  }
280
345
 
281
346
  function prepare_scene_3() {
282
- addPointLight([
283
- 0, 0, -4
284
- ], 1,
285
- 0xFF0000
347
+ addPointLight({
348
+ position: [
349
+ 0, 0, -4
350
+ ], radius: 1, color: 0xFF0000
351
+ }
286
352
  );
287
353
 
288
354
  // tight planes around the light
@@ -298,17 +364,17 @@ function prepare_scene_3() {
298
364
  }
299
365
 
300
366
  function prepare_scene_2() {
301
- addPointLight([
302
- 1.5, 0, -4
303
- ], 1.5,
304
- 0xFF0000,
305
- 1
367
+ addPointLight({
368
+ position: [
369
+ 1.5, 0, -4
370
+ ], radius: 1.5, color: 0xFF0000, intensity: 1
371
+ }
306
372
  );
307
- addPointLight([
308
- -1.5, 0, -4
309
- ], 1.5,
310
- 0x00FF00,
311
- 1
373
+ addPointLight({
374
+ position: [
375
+ -1.5, 0, -4
376
+ ], radius: 1.5, color: 0x00FF00, intensity: 1
377
+ }
312
378
  );
313
379
 
314
380
  addKnot([0, 0, -5], 1, [0, 0, 0]);
@@ -325,17 +391,17 @@ function prepare_scene_5() {
325
391
  const offset = new Vector3(100, 100, 100);
326
392
 
327
393
 
328
- addPointLight([
329
- 1.5 + offset.x, 0 + offset.y, -4 + offset.z
330
- ], 1.5,
331
- 0xFF0000,
332
- 10
394
+ addPointLight({
395
+ position: [
396
+ 1.5 + offset.x, 0 + offset.y, -4 + offset.z
397
+ ], radius: 1.5, color: 0xFF0000, intensity: 10
398
+ }
333
399
  );
334
- addPointLight([
335
- -1.5 + offset.x, 0 + offset.y, -4 + offset.z
336
- ], 1.5,
337
- 0x00FF00,
338
- 10
400
+ addPointLight({
401
+ position: [
402
+ -1.5 + offset.x, 0 + offset.y, -4 + offset.z
403
+ ], radius: 1.5, color: 0x00FF00, intensity: 10
404
+ }
339
405
  );
340
406
 
341
407
  addKnot(
@@ -360,7 +426,7 @@ function prepare_scene_5() {
360
426
  function addSponza() {
361
427
  const loader = new GLTFLoader();
362
428
 
363
- loader.load("data/models/sponza-pbr/sponza.glb", (gltf) => {
429
+ loader.load("data/models/sponza-pbr/gltf/sponza.glb", (gltf) => {
364
430
 
365
431
  gltf.scene.traverse(m => {
366
432
  if (m.isLight) {
@@ -407,8 +473,8 @@ function addSponza() {
407
473
 
408
474
  function prepare_scene_4() {
409
475
 
410
- controls.target.set(2.1731179577352857, 1.7178052208111272, -0.4444756234843362);
411
- camera.position.set(-3.6592606144314597, 3.7632561258064934, -0.3287586440078351);
476
+ controls.target.set(2.1731179577352857, 2.4, -0.26);
477
+ camera.position.set(-8, 3.3, -0.26);
412
478
 
413
479
  camera.near = 1;
414
480
  camera.far = 50;
@@ -418,16 +484,19 @@ function prepare_scene_4() {
418
484
  controls.update();
419
485
 
420
486
 
421
- for (let i = 0; i < 2000; i++) {
487
+ for (let i = 0; i < 500; i++) {
422
488
  const radius = randomFloatBetween(random, 2, 2);
423
- addPointLight([
424
- randomFloatBetween(random, -18, 18),
425
- randomFloatBetween(random, -3, 16),
426
- randomFloatBetween(random, -11, 11),
427
- ],
428
- radius,
429
- `hsv(${random().toFixed(4)}, 0.8, 1)`,
430
- randomFloatBetween(random, 3, 3)
489
+ addPointLight({
490
+ position: [
491
+ randomFloatBetween(random, -17, 17),
492
+ randomFloatBetween(random, -2, 13),
493
+ randomFloatBetween(random, -10, 10),
494
+ ],
495
+ radius: radius,
496
+ color: `hsv(${random().toFixed(4)}, 0.8, 1)`,
497
+ intensity: randomFloatBetween(random, 6, 6),
498
+ wander: true
499
+ }
431
500
  );
432
501
  }
433
502
 
@@ -460,14 +529,13 @@ function prepare_scene_6() {
460
529
  controls.update();
461
530
 
462
531
 
463
- addPointLight([
464
- 11,
465
- 1,
466
- 0,
467
- ],
468
- 2,
469
- `hsv(0.5, 0.8, 1)`,
470
- 3
532
+ addPointLight({
533
+ position: [
534
+ 11,
535
+ 1,
536
+ 0,
537
+ ], radius: 2, color: `hsv(0.5, 0.8, 1)`, intensity: 3
538
+ }
471
539
  );
472
540
 
473
541
  //
@@ -541,8 +609,12 @@ camera.aspect = window.innerWidth / window.innerHeight;
541
609
  camera.updateProjectionMatrix();
542
610
 
543
611
 
544
- scene.add(new GridHelper());
545
- scene.background = new Color(0x666666);
612
+ // scene.add(new GridHelper());
613
+ // scene.background = new Color(0x666666);
614
+
615
+ const stats = new Stats();
616
+ stats.dom.style.cssText = 'position:fixed;top:0;right:0;cursor:pointer;opacity:0.9;z-index:10000';
617
+ document.body.appendChild(stats.dom);
546
618
 
547
619
  const controls = new OrbitControls(camera, renderer.domElement);
548
620
 
@@ -586,10 +658,17 @@ function animate() {
586
658
  material_fp_standard.uniforms.fp_f_camera_near.value = camera.near;
587
659
  material_fp_standard.uniforms.fp_f_camera_far.value = camera.far;
588
660
 
661
+
662
+ renderer.getSize(scratch_v2);
663
+ scratch_v2.multiplyScalar(renderer.getPixelRatio());
664
+
589
665
  fp_materials.forEach(m => {
590
666
 
591
667
  m.uniforms.fp_f_camera_near.value = camera.near;
592
668
  m.uniforms.fp_f_camera_far.value = camera.far;
669
+
670
+
671
+ m.uniforms.resolution.value.set(scratch_v2.x, scratch_v2.y);
593
672
  });
594
673
 
595
674
  lightClusterWidget.update();
@@ -597,7 +676,9 @@ function animate() {
597
676
 
598
677
  renderer.render(scene, camera);
599
678
 
679
+ on_render.send6(renderer, camera, scene, time_delta, t);
600
680
 
681
+ stats.update();
601
682
  }
602
683
 
603
684
  const metrics = new MetricCollection();
@@ -628,20 +709,20 @@ function print_perf_stats() {
628
709
  setInterval(print_perf_stats, 2000);
629
710
 
630
711
  function do_sample() {
631
- queryBVH_Frustum.iteration_count = 0;
632
- queryBVH_Frustum.rejection_count = 0;
633
- queryBVH_Frustum.rejection_sphere_count = 0;
634
- queryBVH_Frustum.plane_tests = 0;
635
- queryBVH_Frustum.plane_tests_early_exits = 0;
712
+ query_bvh_frustum_from_objects.iteration_count = 0;
713
+ query_bvh_frustum_from_objects.rejection_count = 0;
714
+ query_bvh_frustum_from_objects.rejection_sphere_count = 0;
715
+ query_bvh_frustum_from_objects.plane_tests = 0;
716
+ query_bvh_frustum_from_objects.plane_tests_early_exits = 0;
636
717
 
637
718
  const t0 = performance.now();
638
719
  lm.buildTiles(camera);
639
720
  const t1 = performance.now();
640
721
 
641
722
  metrics.get("time").record(t1 - t0);
642
- metrics.get("iterations").record(queryBVH_Frustum.iteration_count);
643
- metrics.get("rejections").record(queryBVH_Frustum.rejection_count);
644
- metrics.get("sphere_rejections").record(queryBVH_Frustum.rejection_sphere_count);
723
+ metrics.get("iterations").record(query_bvh_frustum_from_objects.iteration_count);
724
+ metrics.get("rejections").record(query_bvh_frustum_from_objects.rejection_count);
725
+ metrics.get("sphere_rejections").record(query_bvh_frustum_from_objects.rejection_sphere_count);
645
726
  }
646
727
 
647
728
  function draw_camera_view_planes() {
@@ -654,7 +735,7 @@ function draw_camera_view_planes() {
654
735
  });
655
736
  }
656
737
 
657
- prepare_scene_0();
738
+ prepare_scene_4();
658
739
  animate();
659
740
 
660
741
  // draw_camera_view_planes();
@@ -714,3 +795,16 @@ document.body.appendChild(debugger_button.el);
714
795
  const layerSwitcher = createLayerSwitcher(camera);
715
796
 
716
797
  document.body.appendChild(layerSwitcher.domElement);
798
+
799
+ function onWindowResize() {
800
+
801
+ const w = window.innerWidth;
802
+ const h = window.innerHeight;
803
+
804
+ camera.aspect = w / h;
805
+ camera.updateProjectionMatrix();
806
+
807
+ renderer.setSize(w, h);
808
+ }
809
+
810
+ window.addEventListener("resize", onWindowResize);
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * @param {number} field
4
+ * @returns {number}
5
+ */
6
+ export function analytical_triplanar_corner_mapping(field) {
7
+ return ((field << 1) & 0b100) | ((field >> 2) & 0b10) | ((field >> 5) & 0b1);
8
+ }
@@ -0,0 +1,38 @@
1
+ const _lut_array_buffer = new ArrayBuffer(84);
2
+ /**
3
+ * Mapping from 3 plane bitfield, corresponding to intersection point of the planes
4
+ * @type {number[]}
5
+ */
6
+ export const triplanar_corner_mapping = new Uint8Array(_lut_array_buffer, 0, 43);
7
+
8
+ triplanar_corner_mapping[0b010101] = 0;
9
+ triplanar_corner_mapping[0b100101] = 1;
10
+ triplanar_corner_mapping[0b011001] = 2;
11
+ triplanar_corner_mapping[0b101001] = 3;
12
+ triplanar_corner_mapping[0b010110] = 4;
13
+ triplanar_corner_mapping[0b100110] = 5;
14
+ triplanar_corner_mapping[0b011010] = 6;
15
+ triplanar_corner_mapping[0b101010] = 7;
16
+ /**
17
+ * Mapping from 2 plane bitfield to 2 corner bitfield, corresponding to corner indices of intersecting planes
18
+ * @type {number[]}
19
+ */
20
+ export const biplanar_edge_mapping = new Uint8Array(_lut_array_buffer, 43, 41);
21
+
22
+ biplanar_edge_mapping[0b000101] = 0 | (1 << 3);
23
+ biplanar_edge_mapping[0b000110] = 4 | (5 << 3);
24
+
25
+ biplanar_edge_mapping[0b001001] = 2 | (3 << 3);
26
+ biplanar_edge_mapping[0b001010] = 6 | (7 << 3);
27
+
28
+ biplanar_edge_mapping[0b010100] = 0 | (4 << 3);
29
+ biplanar_edge_mapping[0b011000] = 2 | (6 << 3);
30
+
31
+ biplanar_edge_mapping[0b100100] = 1 | (5 << 3);
32
+ biplanar_edge_mapping[0b101000] = 3 | (7 << 3);
33
+
34
+ biplanar_edge_mapping[0b010001] = 0 | (2 << 3);
35
+ biplanar_edge_mapping[0b010010] = 4 | (6 << 3);
36
+
37
+ biplanar_edge_mapping[0b100001] = 1 | (3 << 3);
38
+ biplanar_edge_mapping[0b100010] = 5 | (7 << 3);
@@ -0,0 +1,86 @@
1
+ import { v3_distance_sqr } from "../../../../../core/geom/v3_distance_sqr.js";
2
+ import { biplanar_edge_mapping, triplanar_corner_mapping } from "./cube_mapping.js";
3
+ import { line3_computeSegmentPointDistance_sqr } from "../../../../../core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js";
4
+
5
+ /**
6
+ *
7
+ * @param {number} radius
8
+ * @param {number} light_x
9
+ * @param {number} light_y
10
+ * @param {number} light_z
11
+ * @param {number} outside_plane_count
12
+ * @param {number} outside_plane_bitfield
13
+ * @param {number[]} points
14
+ * @return {boolean}
15
+ */
16
+ export function detailed_sphere_frustum_intersection_test(
17
+ radius, light_x, light_y, light_z,
18
+ outside_plane_count, outside_plane_bitfield,
19
+ points
20
+ ) {
21
+
22
+ const radius_sqr = radius * radius;
23
+
24
+ if (outside_plane_count === 3) {
25
+ // nearest point in a corner, find the corner
26
+ const point_index = triplanar_corner_mapping[outside_plane_bitfield];
27
+
28
+ const point_address = point_index * 3;
29
+
30
+ const point_x = points[point_address];
31
+ const point_y = points[point_address + 1];
32
+ const point_z = points[point_address + 2];
33
+
34
+ const distance_to_light_sqr = v3_distance_sqr(
35
+ point_x, point_y, point_z,
36
+ light_x, light_y, light_z
37
+ );
38
+
39
+ // query_bvh_frustum_from_objects.checks_sphere_frustum_corner++;
40
+
41
+ // return distance_to_light_sqr <= radius_sqr;
42
+
43
+ if (distance_to_light_sqr > radius_sqr) {
44
+
45
+ // query_bvh_frustum_from_objects.rejection_sphere_count++;
46
+ return false;
47
+ }
48
+
49
+ } else if (outside_plane_count === 2) {
50
+ // nearest point is on an edge of two plane intersection
51
+ const edge_bitfield = biplanar_edge_mapping[outside_plane_bitfield];
52
+
53
+ // get 2 corners from edge bitfield
54
+ const corner_index_0 = edge_bitfield & 0b111;
55
+ const corner_address_0 = corner_index_0 * 3;
56
+
57
+ const corner_index_1 = (edge_bitfield >> 3) & 0b111;
58
+ const corner_address_1 = corner_index_1 * 3;
59
+
60
+ const point_0_x = points[corner_address_0];
61
+ const point_0_y = points[corner_address_0 + 1];
62
+ const point_0_z = points[corner_address_0 + 2];
63
+
64
+ const point_1_x = points[corner_address_1];
65
+ const point_1_y = points[corner_address_1 + 1];
66
+ const point_1_z = points[corner_address_1 + 2];
67
+
68
+ const distance_to_frustum_sqr = line3_computeSegmentPointDistance_sqr(
69
+ point_0_x, point_0_y, point_0_z,
70
+ point_1_x, point_1_y, point_1_z,
71
+ light_x, light_y, light_z
72
+ );
73
+
74
+ // query_bvh_frustum_from_objects.checks_sphere_frustum_edge++;
75
+
76
+ // return distance_to_frustum_sqr <= radius_sqr;
77
+
78
+ if (distance_to_frustum_sqr > radius_sqr) {
79
+
80
+ // query_bvh_frustum_from_objects.rejection_sphere_count++;
81
+ return false;
82
+ }
83
+ }
84
+
85
+ return true;
86
+ }
@@ -0,0 +1,73 @@
1
+ import { detailed_sphere_frustum_intersection_test } from "./detailed_sphere_frustum_intersection_test.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number} light_x
6
+ * @param {number} light_y
7
+ * @param {number} light_z
8
+ * @param {number} radius
9
+ * @param {number[]} points
10
+ * @param {number[]|Float32Array|Float64Array} planes
11
+ * @returns {boolean}
12
+ */
13
+ export function point_light_inside_volume(
14
+ light_x, light_y, light_z, radius,
15
+ points, planes
16
+ ) {
17
+ let j = 0;
18
+ let outside_plane_count = 0;
19
+ let outside_plane_bitfield = 0;
20
+
21
+ // validate if the sphere intersects the plane-bound space
22
+
23
+ // query_bvh_frustum_from_objects.checks_sphere++;
24
+
25
+ for (; j < 6; j++) {
26
+
27
+ const plane_address = j * 4;
28
+
29
+ const plane_normal_x = planes[plane_address];
30
+ const plane_normal_y = planes[plane_address + 1];
31
+ const plane_normal_z = planes[plane_address + 2];
32
+ const plane_constant = planes[plane_address + 3];
33
+
34
+ /*
35
+ compute distance from the center of the sphere to the plane
36
+ NOTE: inlined computation of distance from point to plane
37
+ */
38
+ const distance = (plane_normal_x * light_x + plane_normal_y * light_y + plane_normal_z * light_z) + plane_constant;
39
+
40
+ // query_bvh_frustum_from_objects.checks_sphere_plane++;
41
+
42
+ if (distance < 0) {
43
+ // center of the sphere is below the plane
44
+
45
+ if (distance < -radius) {
46
+ // sphere is entirely below the plane
47
+
48
+ // query_bvh_frustum_from_objects.rejection_sphere_count++;
49
+
50
+ return false;
51
+ }
52
+
53
+ // sphere intersects the plane
54
+
55
+ outside_plane_count++;
56
+
57
+ const plane_bit_mask = 1 << j;
58
+
59
+ outside_plane_bitfield |= plane_bit_mask;
60
+ }
61
+
62
+ }
63
+
64
+ if (outside_plane_count < 2) {
65
+ return true;
66
+ } else {
67
+ return detailed_sphere_frustum_intersection_test(
68
+ radius, light_x, light_y, light_z,
69
+ outside_plane_count, outside_plane_bitfield,
70
+ points
71
+ );
72
+ }
73
+ }