@woosh/meep-engine 2.119.45 → 2.119.47

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.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.119.45",
8
+ "version": "2.119.47",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {Engine} engine
4
+ * @param {string} path
5
+ * @param {LightProbeVolume} [volume]
6
+ * @param {number} [density] only used when building mesh, if loading this parameter is ignored
7
+ * @return {Promise<LightProbeVolume>}
8
+ */
9
+ export function lpv_obtain_storage_cached_volume({ engine, path, volume, density }: Engine): Promise<LightProbeVolume>;
10
+ import { LightProbeVolume } from "./LightProbeVolume.js";
11
+ //# sourceMappingURL=lpv_obtain_storage_cached_volume.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lpv_obtain_storage_cached_volume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/lpv_obtain_storage_cached_volume.js"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,6FAFY,QAAQ,gBAAgB,CAAC,CAsEpC;iCA/EgC,uBAAuB"}
@@ -0,0 +1,86 @@
1
+ import { BinaryBuffer } from "../../../../core/binary/BinaryBuffer.js";
2
+ import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
3
+ import { number_pretty_print } from "../../../../core/primitives/numbers/number_pretty_print.js";
4
+ import { Transform } from "../../../ecs/transform/Transform.js";
5
+ import { ShadedGeometry } from "../../ecs/mesh-v2/ShadedGeometry.js";
6
+ import { build_probes_for_scene } from "./build_probes_for_scene.js";
7
+ import { LightProbeVolume } from "./LightProbeVolume.js";
8
+ import { LightProbeVolumeSerializationAdapter } from "./serialization/LightProbeVolumeSerializationAdapter.js";
9
+
10
+ /**
11
+ *
12
+ * @param {Engine} engine
13
+ * @param {string} path
14
+ * @param {LightProbeVolume} [volume]
15
+ * @param {number} [density] only used when building mesh, if loading this parameter is ignored
16
+ * @return {Promise<LightProbeVolume>}
17
+ */
18
+ export async function lpv_obtain_storage_cached_volume({
19
+ engine,
20
+ path,
21
+ volume = new LightProbeVolume(),
22
+ density = 500
23
+ }) {
24
+
25
+ volume.clear();
26
+
27
+ const key = `lpv:${path}`;
28
+
29
+ const adapter = new LightProbeVolumeSerializationAdapter();
30
+
31
+ if (await engine.storage.promiseContains(key)
32
+ // && false // TODO re-enable
33
+ ) {
34
+ const data = await engine.storage.promiseLoadBinary(key);
35
+
36
+ console.log(`LPV data size ${number_pretty_print(data.byteLength)} bytes`);
37
+
38
+ const buffer = BinaryBuffer.fromArrayBuffer(data);
39
+
40
+ adapter.deserialize(buffer, volume);
41
+
42
+ return volume;
43
+ }
44
+
45
+
46
+ const ecd = engine.entityManager.dataset;
47
+
48
+ // build bounding box for the scene
49
+ const mesh_bounds = new AABB3();
50
+ mesh_bounds.setNegativelyInfiniteBounds();
51
+
52
+ ecd.traverseEntities([ShadedGeometry, Transform],
53
+ /**
54
+ *
55
+ * @param {ShadedGeometry} sg
56
+ * @param transform
57
+ * @param entity
58
+ */
59
+ (sg, transform, entity) => {
60
+
61
+ const box = new AABB3();
62
+
63
+ sg.getBoundingBox(box);
64
+
65
+ mesh_bounds.expandToFit(box);
66
+
67
+ });
68
+
69
+ await build_probes_for_scene({
70
+ volume,
71
+ engine,
72
+ ecd,
73
+ bounds: mesh_bounds,
74
+ density: density
75
+ });
76
+
77
+ const buffer = new BinaryBuffer();
78
+
79
+ adapter.serialize(buffer, volume);
80
+
81
+ buffer.trim();
82
+
83
+ engine.storage.promiseStoreBinary(key, buffer.data)
84
+
85
+ return volume;
86
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAiCA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;IAkF7C,iBAOC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,QAAQ,oBAKxB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,IAAI,QA0Cd;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAsCnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACZ,MAAM,CA+CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,QAkElB;;CACJ;oBAjhB8B,mCAAmC;+BAmBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B;qBALzC,kCAAkC"}
1
+ {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAmDA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;IAkF7C,iBAOC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,QAAQ,oBAKxB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,IAAI,QA0Cd;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAsCnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACZ,MAAM,CA+CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,QAwHlB;;CACJ;oBAzlB8B,mCAAmC;+BAqBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B;qBAPzC,kCAAkC"}
@@ -12,6 +12,8 @@ import { v3_morton_encode_bounded } from "../../../../core/geom/3d/morton/v3_mor
12
12
  import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
13
13
  import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
14
14
  import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
15
+ import { v3_length } from "../../../../core/geom/vec3/v3_length.js";
16
+ import { saturate } from "../../../../core/math/clamp01.js";
15
17
  import { max2 } from "../../../../core/math/max2.js";
16
18
  import { compute_geometry_polycount } from "../../geometry/compute_geometry_polycount.js";
17
19
  import { AbstractLight } from "../../render/forward_plus/model/AbstractLight.js";
@@ -21,6 +23,22 @@ import { MaterialConverter } from "./material/MaterialConverter.js";
21
23
  import { PathTracedMesh } from "./PathTracedMesh.js";
22
24
  import { sample_material } from "./texture/sample_material.js";
23
25
 
26
+ function light_getDistanceAttenuation( distance, cutoff_distance, decay_exponent){
27
+
28
+ let distanceFalloff = 1.0 / Math.max( Math.pow( distance, decay_exponent ), 0.01 );
29
+
30
+ if ( cutoff_distance > 0.0 ) {
31
+ const b = distance / cutoff_distance;
32
+ const b2 = b*b;
33
+ const b4 = b2*b2;
34
+
35
+ const c= saturate( 1.0 - b4 );
36
+
37
+ distanceFalloff *= c*c;
38
+ }
39
+
40
+ return distanceFalloff;
41
+ }
24
42
  /**
25
43
  *
26
44
  * @type {number[]|Uint32Array}
@@ -473,6 +491,14 @@ export class PathTracedScene {
473
491
  out[out_offset + i] = 0;
474
492
  }
475
493
 
494
+ const ray_origin_x = ray[0];
495
+ const ray_origin_y = ray[1];
496
+ const ray_origin_z = ray[2];
497
+
498
+ const ray_direction_x = ray[3];
499
+ const ray_direction_y = ray[4];
500
+ const ray_direction_z = ray[5];
501
+
476
502
  for (let i = 0; i < light_count; i++) {
477
503
  const light = lights[i];
478
504
 
@@ -481,10 +507,6 @@ export class PathTracedScene {
481
507
 
482
508
  // see https://github.com/mrdoob/three.js/blob/f0a9e0cf90a2f1ba5017fcb7fd46f02748b920cf/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js#L172
483
509
 
484
- const ray_direction_x = ray[3];
485
- const ray_direction_y = ray[4];
486
- const ray_direction_z = ray[5];
487
-
488
510
  const light_dir_inv_x = -dir.x;
489
511
  const light_dir_inv_y = -dir.y;
490
512
  const light_dir_inv_z = -dir.z;
@@ -499,9 +521,6 @@ export class PathTracedScene {
499
521
  continue;
500
522
  }
501
523
 
502
- const ray_origin_x = ray[0];
503
- const ray_origin_y = ray[1];
504
- const ray_origin_z = ray[2];
505
524
 
506
525
  ray3_array_compose(_ray_1,
507
526
  ray_origin_x, ray_origin_y, ray_origin_z,
@@ -525,6 +544,59 @@ export class PathTracedScene {
525
544
  out[out_offset + 2] += light_color.b * intensity;
526
545
 
527
546
 
547
+ } else if (light.isPointLight === true) {
548
+
549
+ const light_offset_x = ray_origin_x - light.position.x;
550
+ const light_offset_y = ray_origin_y - light.position.y;
551
+ const light_offset_z = ray_origin_z - light.position.z;
552
+
553
+ const distance_to_light = v3_length(light_offset_x, light_offset_y, light_offset_z);
554
+
555
+ const radius = light.radius.getValue();
556
+
557
+ if (distance_to_light > radius) {
558
+ // too far
559
+ continue;
560
+ }
561
+
562
+ const light_norm_inv = 1 / distance_to_light;
563
+
564
+ // see https://github.com/mrdoob/three.js/blob/f0a9e0cf90a2f1ba5017fcb7fd46f02748b920cf/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js#L172
565
+
566
+ const light_dir_inv_x = -light_offset_x * light_norm_inv;
567
+ const light_dir_inv_y = -light_offset_y * light_norm_inv;
568
+ const light_dir_inv_z = -light_offset_z * light_norm_inv;
569
+
570
+ const dotNL = v3_dot(
571
+ ray_direction_x, ray_direction_y, ray_direction_z,
572
+ light_dir_inv_x, light_dir_inv_y, light_dir_inv_z
573
+ );
574
+
575
+ if (dotNL <= 0) {
576
+ // no contribution, facing away from the light
577
+ continue;
578
+ }
579
+ ray3_array_compose(_ray_1,
580
+ ray_origin_x, ray_origin_y, ray_origin_z,
581
+ light_dir_inv_x, light_dir_inv_y, light_dir_inv_z
582
+ );
583
+
584
+ _ray_1.tMax = radius;
585
+
586
+ // check if there are any obstacles in the direction of the light
587
+ if (this.occluded(_ray_1)) {
588
+ // light is occluded
589
+ continue;
590
+ }
591
+
592
+ const attenuation = light_getDistanceAttenuation(distance_to_light,radius,2);
593
+
594
+ const intensity = dotNL * light.intensity.getValue()*attenuation;
595
+ const light_color = light.color;
596
+
597
+ out[out_offset] += light_color.r * intensity;
598
+ out[out_offset + 1] += light_color.g * intensity;
599
+ out[out_offset + 2] += light_color.b * intensity;
528
600
  }
529
601
  }
530
602
  }
@@ -19,6 +19,7 @@ import { array_copy } from "../../../core/collection/array/array_copy.js";
19
19
  import { is_typed_array_equals } from "../../../core/collection/array/typed/is_typed_array_equals.js";
20
20
  import { Color } from "../../../core/color/Color.js";
21
21
  import { kelvin_to_rgb } from "../../../core/color/kelvin/kelvin_to_rgb.js";
22
+ import { AABB3 } from "../../../core/geom/3d/aabb/AABB3.js";
22
23
  import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
23
24
  import { visualize_tetrahedral_mesh } from "../../../core/geom/3d/tetrahedra/visualize_tetrahedral_mesh.js";
24
25
  import Quaternion from "../../../core/geom/Quaternion.js";
@@ -29,7 +30,6 @@ import { min2 } from "../../../core/math/min2.js";
29
30
  import { RAD_TO_DEG } from "../../../core/math/RAD_TO_DEG.js";
30
31
  import { randomFloatBetween } from "../../../core/math/random/randomFloatBetween.js";
31
32
  import { seededRandom } from "../../../core/math/random/seededRandom.js";
32
- import { number_pretty_print } from "../../../core/primitives/numbers/number_pretty_print.js";
33
33
  import { delay } from "../../../core/process/delay.js";
34
34
  import ButtonView from "../../../view/elements/button/ButtonView.js";
35
35
  import { GLTFAssetLoader } from "../../asset/loaders/GLTFAssetLoader.js";
@@ -53,11 +53,10 @@ import { ShadedGeometrySystem } from "../ecs/mesh-v2/ShadedGeometrySystem.js";
53
53
  import { three_object_to_entity_composition } from "../ecs/mesh-v2/three_object_to_entity_composition.js";
54
54
  import { GizmoRenderingPlugin } from "../render/gizmo/GizmoRenderingPlugin.js";
55
55
  import { MaterialTransformer } from "./gi/material/MaterialTransformer.js";
56
- import { build_probes_for_scene } from "./lpv/build_probes_for_scene.js";
57
56
  import { OctahedralDepthDebuggerWidget } from "./lpv/depth/octahedral/OctahedralDepthDebuggerWidget.js";
58
57
  import { VLPDepthMapVisualisation } from "./lpv/depth/octahedral/v2/VLPDepthMapVisualisation.js";
59
58
  import { LightProbeVolume } from "./lpv/LightProbeVolume.js";
60
- import { LightProbeVolumeSerializationAdapter } from "./lpv/serialization/LightProbeVolumeSerializationAdapter.js";
59
+ import { lpv_obtain_storage_cached_volume } from "./lpv/lpv_obtain_storage_cached_volume.js";
61
60
  import { lpv_visualize_probes } from "./lpv/util/lpv_visualise_probes.js";
62
61
 
63
62
  /**
@@ -203,63 +202,6 @@ function make_test_texture(t = 1) {
203
202
  return tex;
204
203
  }
205
204
 
206
- /**
207
- *
208
- * @param {Engine} engine
209
- * @param {string} path
210
- * @param {LightProbeVolume} volume
211
- * @return {Promise<LightProbeVolume>}
212
- */
213
- async function getVolume({
214
- engine,
215
- path,
216
- volume = new LightProbeVolume()
217
- }) {
218
-
219
- volume.clear();
220
-
221
- const key = `lpv:${path}`;
222
-
223
- const adapter = new LightProbeVolumeSerializationAdapter();
224
-
225
- if (await engine.storage.promiseContains(key)
226
- // && false // TODO re-enable
227
- ) {
228
- const data = await engine.storage.promiseLoadBinary(key);
229
-
230
- console.log(`LPV data size ${number_pretty_print(data.byteLength)} bytes`);
231
-
232
- const buffer = BinaryBuffer.fromArrayBuffer(data);
233
-
234
- adapter.deserialize(buffer, volume);
235
-
236
- return volume;
237
- }
238
-
239
- const mesh_asset = await engine.assetManager.promise(path, 'model/gltf+json');
240
- const mesh_bounds = mesh_asset.boundingBox;
241
-
242
- const ecd = engine.entityManager.dataset;
243
-
244
- await build_probes_for_scene({
245
- volume,
246
- engine,
247
- ecd,
248
- bounds: mesh_bounds,
249
- density: 500
250
- });
251
-
252
- const buffer = new BinaryBuffer();
253
-
254
- adapter.serialize(buffer, volume);
255
-
256
- buffer.trim();
257
-
258
- engine.storage.promiseStoreBinary(key, buffer.data)
259
-
260
- return volume;
261
- }
262
-
263
205
  /**
264
206
  *
265
207
  * @param {EntityComponentDataset} ecd
@@ -495,7 +437,7 @@ async function main(engine) {
495
437
 
496
438
  console.time('getVolume');
497
439
  // console.profile('getVolume');
498
- await getVolume({ engine, path, volume });
440
+ await lpv_obtain_storage_cached_volume({ engine, path, volume });
499
441
  // console.profileEnd('getVolume');
500
442
  console.timeEnd('getVolume');
501
443