@woosh/meep-engine 2.39.36 → 2.39.39

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 (85) hide show
  1. package/LICENSE +13 -0
  2. package/core/assert.js +14 -5
  3. package/core/binary/Base64.js +58 -31
  4. package/core/binary/Base64.spec.js +14 -0
  5. package/core/bvh2/aabb3/AABB3.js +2 -2
  6. package/core/bvh2/aabb3/aabb3_detailed_volume_intersection.js +3 -2
  7. package/core/bvh2/aabb3/aabb3_intersects_frustum_array.js +2 -2
  8. package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +7 -0
  9. package/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +149 -6
  10. package/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.spec.js +41 -0
  11. package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +2 -2
  12. package/core/bvh2/traversal/__process_point_if_within_planes.js +2 -2
  13. package/core/bvh2/traversal/aabb3_detailed_volume_intersection_callback_based.js +3 -0
  14. package/core/collection/array/computeHashArray.d.ts +1 -0
  15. package/core/color/Color.js +7 -3
  16. package/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane_max.spec.js +8 -0
  17. package/core/geom/3d/aabb/{aabb3_computeDistanceAbovePlane.js → aabb3_compute_distance_above_plane_max.js} +3 -2
  18. package/core/geom/3d/aabb/computeAABB3PlaneSide.js +3 -3
  19. package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +3 -2
  20. package/core/geom/3d/plane/is_point_within_planes.js +2 -2
  21. package/core/geom/3d/plane/plane3_projectPoint.js +2 -2
  22. package/core/geom/3d/plane/plane3_projectPoint.spec.js +54 -0
  23. package/core/geom/Plane.js +0 -19
  24. package/core/geom/Quaternion.js +52 -38
  25. package/core/geom/v3_distance_above_plane.js +20 -0
  26. package/core/geom/v3_distance_above_plane.spec.js +40 -0
  27. package/core/math/statistics/halton_sequence.js +26 -0
  28. package/core/model/ModuleRegistry.js +1 -1
  29. package/core/model/reactive/model/terminal/ReactiveReference.js +1 -1
  30. package/core/model/reactive/trigger/ReactiveTrigger.js +14 -4
  31. package/editor/ecs/component/editors/ImagePathEditor.js +83 -0
  32. package/engine/asset/loaders/ArrayBufferLoader.js +76 -16
  33. package/engine/ecs/EntityComponentDataset.js +18 -28
  34. package/engine/ecs/terrain/ecs/splat/SplatMapping.js +27 -4
  35. package/engine/graphics/GraphicsEngine.d.ts +2 -2
  36. package/engine/graphics/GraphicsEngine.js +11 -15
  37. package/engine/graphics/composit/LayerCompositer.js +1 -0
  38. package/engine/graphics/ecs/camera/Camera.js +2 -2
  39. package/engine/graphics/ecs/camera/CameraSystem.js +6 -0
  40. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +1 -1
  41. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +14 -6
  42. package/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js +2 -1
  43. package/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +17 -2
  44. package/engine/graphics/ecs/mesh-v2/aggregate/prototypeSGMesh.js +17 -20
  45. package/engine/graphics/filter/FlipArrayInPlace.js +11 -6
  46. package/engine/graphics/geometry/clipping/ClippedGeometry.js +4 -4
  47. package/engine/graphics/micron/prototypeVirtualGeometry.js +3 -1
  48. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +2 -0
  49. package/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +95 -0
  50. package/engine/graphics/render/buffer/simple-fx/taa/prototypeTAA.js +61 -0
  51. package/engine/graphics/render/forward_plus/LightManager.js +4 -4
  52. package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +6 -7
  53. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +6 -2
  54. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +4 -2
  55. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +4 -2
  56. package/engine/graphics/render/frame_graph/GraphNode.js +22 -0
  57. package/engine/graphics/render/frame_graph/RenderGraph.js +405 -0
  58. package/engine/graphics/render/frame_graph/RenderGraphBuilder.js +77 -0
  59. package/engine/graphics/render/frame_graph/RenderPass.js +30 -12
  60. package/engine/graphics/render/frame_graph/RenderPassNode.js +103 -0
  61. package/engine/graphics/render/frame_graph/RenderPassResources.js +54 -4
  62. package/engine/graphics/render/frame_graph/ResourceEntry.js +77 -0
  63. package/engine/graphics/render/frame_graph/ResourceNode.js +23 -0
  64. package/engine/graphics/render/frame_graph/TextureDescriptor.js +38 -4
  65. package/engine/graphics/render/frame_graph/sample/deferred/GBufferDrawPass.js +11 -5
  66. package/engine/graphics/render/frame_graph/sample/deferred/LightingPass.js +24 -0
  67. package/engine/graphics/render/frame_graph/sample/deferred/run.js +31 -0
  68. package/engine/graphics/render/frame_graph/sample/meep-v1/ColorDepthPass.js +38 -0
  69. package/engine/graphics/render/frame_graph/sample/meep-v1/OutlinePass.js +9 -0
  70. package/engine/graphics/render/frame_graph/sample/meep-v1/SSAOPass.js +5 -0
  71. package/engine/graphics/render/frame_graph/sample/meep-v1/render.js +7 -0
  72. package/engine/graphics/render/frame_graph/webgl/WebGLRenderContext.js +5 -0
  73. package/engine/graphics/render/layers/RenderLayerUtils.js +5 -3
  74. package/engine/graphics/render/view/CameraView.js +38 -0
  75. package/engine/graphics/texture/sampler/Sampler2D.js +22 -2
  76. package/engine/knowledge/database/DATABASE_SERIALIZATION_IGNORE_PROPERTY.js +1 -0
  77. package/engine/knowledge/database/StaticKnowledgeDataTable.js +5 -4
  78. package/package.json +1 -1
  79. package/view/elements/button/ButtonView.js +12 -1
  80. package/core/geom/Plane.spec.js +0 -12
  81. package/engine/graphics/render/frame_graph/FrameGraphBuilder.js +0 -36
  82. package/engine/graphics/render/frame_graph/Resource.js +0 -21
  83. package/engine/graphics/render/frame_graph/ResourceReference.js +0 -14
  84. package/engine/graphics/render/frame_graph/UsageModeType.js +0 -5
  85. package/engine/graphics/render/frame_graph/sample/deferred/PresentPass.js +0 -17
@@ -949,11 +949,9 @@ export class EntityComponentDataset {
949
949
  */
950
950
  addComponentToEntity(entityIndex, componentInstance) {
951
951
 
952
- if (!ENV_PRODUCTION) {
953
- assert.notNull(componentInstance, "componentInstance");
952
+ assert.notNull(componentInstance, "componentInstance");
954
953
 
955
- assert.defined(componentInstance, "componentInstance");
956
- }
954
+ assert.defined(componentInstance, "componentInstance");
957
955
 
958
956
  const klass = componentInstance.constructor;
959
957
 
@@ -976,15 +974,13 @@ export class EntityComponentDataset {
976
974
  */
977
975
  addComponentToEntityByIndex(entityIndex, componentIndex, componentInstance) {
978
976
 
979
- if (!ENV_PRODUCTION) {
977
+ assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
978
+ assert.ok(this.componentIndexExists(componentIndex), `componentIndex ${componentIndex} is out of bounds`);
980
979
 
981
- assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
982
- assert.ok(this.componentIndexExists(componentIndex), `componentIndex ${componentIndex} is out of bounds`);
980
+ assert.notEqual(componentInstance, undefined, "componentInstance is undefined");
983
981
 
984
- assert.notEqual(componentInstance, undefined, "componentInstance is undefined");
982
+ assert.equal(this.getComponentByIndex(entityIndex, componentIndex), undefined, `entity ${entityIndex} already has component ${componentIndex}`);
985
983
 
986
- assert.equal(this.getComponentByIndex(entityIndex, componentIndex), undefined, `entity ${entityIndex} already has component ${componentIndex}`);
987
- }
988
984
 
989
985
  const componentOccupancyIndex = entityIndex * this.componentTypeCount + componentIndex;
990
986
 
@@ -1011,10 +1007,10 @@ export class EntityComponentDataset {
1011
1007
  * @returns {C|undefined}
1012
1008
  */
1013
1009
  getComponentByIndex(entityIndex, componentIndex) {
1014
- if (!ENV_PRODUCTION) {
1015
- assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
1016
- assert.ok(this.componentIndexExists(componentIndex), `componentIndex ${componentIndex} is out of bounds`);
1017
- }
1010
+
1011
+ assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
1012
+ assert.ok(this.componentIndexExists(componentIndex), `componentIndex ${componentIndex} is out of bounds`);
1013
+
1018
1014
 
1019
1015
  return this.components[componentIndex][entityIndex];
1020
1016
  }
@@ -1037,10 +1033,8 @@ export class EntityComponentDataset {
1037
1033
  * @returns {T|undefined}
1038
1034
  */
1039
1035
  getComponent(entityIndex, klass) {
1040
- if (!ENV_PRODUCTION) {
1041
- assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
1042
- assert.defined(klass, "klass");
1043
- }
1036
+ assert.ok(this.entityExists(entityIndex), `entity ${entityIndex} does not exist`);
1037
+ assert.defined(klass, "klass");
1044
1038
 
1045
1039
  const componentIndex = this.computeComponentTypeIndex(klass);
1046
1040
 
@@ -1078,11 +1072,9 @@ export class EntityComponentDataset {
1078
1072
  */
1079
1073
  traverseEntities(classes, visitor, thisArg) {
1080
1074
 
1081
- if (!ENV_PRODUCTION) {
1082
- assert.isArray(classes, "classes");
1083
- // assert.notOk(classes.some((c, i) => classes.indexOf(c) !== i), 'classes contains duplicates');
1084
- assert.isFunction(visitor, "visitor");
1085
- }
1075
+ assert.isArray(classes, "classes");
1076
+ // assert.notOk(classes.some((c, i) => classes.indexOf(c) !== i), 'classes contains duplicates');
1077
+ assert.isFunction(visitor, "visitor");
1086
1078
 
1087
1079
  let entityIndex, i;
1088
1080
 
@@ -1152,7 +1144,7 @@ export class EntityComponentDataset {
1152
1144
  }
1153
1145
 
1154
1146
  /**
1155
- * does traversal on a subset of entities which have only the specified components.
1147
+ * does traversal on a subset of entities which have only the specified components and no others
1156
1148
  * @example traverseEntitiesExact([Transform,Renderable,Tag],function(transform, renderable, tag, entity){ ... }, this);
1157
1149
  * @param {Array.<class>} classes
1158
1150
  * @param {Function} visitor
@@ -1472,10 +1464,8 @@ export class EntityComponentDataset {
1472
1464
  */
1473
1465
  addEntityEventListener(entity, eventName, listener, thisArg) {
1474
1466
 
1475
- if (!ENV_PRODUCTION) {
1476
- assert.isString(eventName, "eventName");
1477
- assert.isFunction(listener, "listener");
1478
- }
1467
+ assert.isString(eventName, "eventName");
1468
+ assert.isFunction(listener, "listener");
1479
1469
 
1480
1470
  if (!this.entityExists(entity)) {
1481
1471
  throw new Error(`Entity '${entity}' does not exist`);
@@ -8,6 +8,7 @@ import { scaleSampler2D } from "../../../../graphics/texture/sampler/scaleSample
8
8
  import { countTask } from "../../../../../core/process/task/TaskUtils.js";
9
9
  import { array_copy } from "../../../../../core/collection/array/copyArray.js";
10
10
  import { typed_array_copy } from "../../../../../core/collection/array/typed/typed_array_copy.js";
11
+ import { Base64 } from "../../../../../core/binary/Base64.js";
11
12
 
12
13
 
13
14
  /**
@@ -52,20 +53,42 @@ export class SplatMapping {
52
53
  }
53
54
 
54
55
  toJSON() {
56
+ const encoded = Base64.encode(this.weightData.buffer);
57
+
55
58
  return {
56
59
  size: this.size.toJSON(),
57
60
  depth: this.depth,
58
- data: Array.from(this.weightData)
61
+ data: encoded
59
62
  };
60
63
  }
61
64
 
62
65
  fromJSON({
63
66
  size = { x: 1, y: 1 },
64
67
  depth = 0,
65
- data = []
66
- } = {}) {
68
+ data
69
+ } = {}) {
67
70
  this.resize(size.x, size.y, depth);
68
- array_copy(data, 0, this.weightData, 0, data.length);
71
+
72
+ let uint_data;
73
+
74
+ if (typeof data === "string") {
75
+
76
+ const decoded_data = Base64.decode(data);
77
+ uint_data = new Uint8Array(decoded_data);
78
+
79
+ } else if (Array.isArray(data)) {
80
+
81
+ // deprecated
82
+ console.warn('Array JSON format is deprecated, please upgrade your data as soon as possible');
83
+ uint_data = data;
84
+
85
+ } else {
86
+
87
+ throw new Error('Unsupported data format');
88
+
89
+ }
90
+
91
+ array_copy(uint_data, 0, this.weightData, 0, data.length);
69
92
 
70
93
  this.weightTexture.needsUpdate = true;
71
94
  }
@@ -1,4 +1,4 @@
1
- import {PerspectiveCamera, Scene, WebGLRenderer, WebGLRenderTarget} from "three";
1
+ import {PerspectiveCamera, Scene, WebGLRenderer} from "three";
2
2
  import {RenderLayerManager} from "./render/layers/RenderLayerManager";
3
3
  import Vector3 from "../../core/geom/Vector3";
4
4
  import Vector2 from "../../core/geom/Vector2";
@@ -28,7 +28,7 @@ export class GraphicsEngine {
28
28
  public needDraw: boolean
29
29
  public autoDraw: boolean
30
30
 
31
- render(renderTarget?: WebGLRenderTarget): void
31
+ render(): void
32
32
 
33
33
  normalizeViewportPoint(input: Vector3 | Vector2, result: Vector2 | Vector3): void
34
34
 
@@ -11,8 +11,7 @@ import {
11
11
  Scene as ThreeScene,
12
12
  Vector3 as ThreeVector3,
13
13
  VSMShadowMap,
14
- WebGLRenderer,
15
- WebGLRenderTarget
14
+ WebGLRenderer
16
15
  } from "three";
17
16
 
18
17
  import Signal from "../../core/events/signal/Signal.js";
@@ -232,6 +231,12 @@ function GraphicsEngine(camera, entityManger) {
232
231
  * @type {boolean}
233
232
  */
234
233
  this.autoDraw = true;
234
+
235
+ /**
236
+ * Monotonically increasing rendered-frame counter
237
+ * @type {number}
238
+ */
239
+ this.frameIndex = 0;
235
240
  }
236
241
 
237
242
  /**
@@ -625,14 +630,14 @@ GraphicsEngine.prototype.renderTransparent = function () {
625
630
 
626
631
  /**
627
632
  *
628
- * @param {WebGLRenderTarget} [renderTarget] if not present - renders to screen
629
633
  */
630
- GraphicsEngine.prototype.render = function (renderTarget) {
631
-
634
+ GraphicsEngine.prototype.render = function () {
632
635
  if (this.needDraw && !this.autoDraw) {
633
636
  this.needDraw = false;
634
637
  }
635
638
 
639
+ this.frameIndex++;
640
+
636
641
  const renderer = this.renderer;
637
642
 
638
643
  //reset renderer statistics (used for debug)
@@ -653,14 +658,10 @@ GraphicsEngine.prototype.render = function (renderTarget) {
653
658
 
654
659
  this.constructVisibleScene(renderer, camera, scene);
655
660
 
656
- if (renderTarget !== undefined) {
657
- renderer.setRenderTarget(renderTarget);
658
- }
659
-
660
661
  //dispatch pre-render event
661
662
  this.on.preRender.send3(renderer, camera, scene);
662
663
 
663
- this.main_view.on.preRender.send0();
664
+ this.main_view.on.preRender.send1(this.main_view);
664
665
 
665
666
  //do the opaque pass
666
667
  this.renderOpaque();
@@ -674,12 +675,7 @@ GraphicsEngine.prototype.render = function (renderTarget) {
674
675
 
675
676
  this.layerComposer.composite(renderer, CompositingStages.POST_TRANSPARENT);
676
677
 
677
-
678
678
  //dispatch post-render event
679
679
  this.on.postRender.send3(renderer, camera, scene);
680
-
681
- if (renderTarget !== undefined) {
682
- renderer.setRenderTarget(null);
683
- }
684
680
  };
685
681
  export { GraphicsEngine };
@@ -50,6 +50,7 @@ class LayerCompositer {
50
50
 
51
51
  this.layerTargets.splice(i, 1);
52
52
 
53
+ // cleanup memory
53
54
  layer.renderTarget.dispose();
54
55
 
55
56
  return true;
@@ -8,11 +8,11 @@ import ObservedEnum from "../../../../core/model/ObservedEnum.js";
8
8
  import { Frustum } from 'three';
9
9
  import { assert } from "../../../../core/assert.js";
10
10
  import Vector1 from "../../../../core/geom/Vector1.js";
11
- import { computePointDistanceToPlane } from "../../../../core/geom/Plane.js";
12
11
  import { unprojectPoint } from "./unprojectPoint.js";
13
12
  import Vector3 from "../../../../core/geom/Vector3.js";
14
13
  import { frustum_from_camera } from "./frustum_from_camera.js";
15
14
  import { invertQuaternionOrientation } from "./InvertQuaternionOrientation.js";
15
+ import { v3_distance_above_plane } from "../../../../core/geom/v3_distance_above_plane.js";
16
16
 
17
17
  /**
18
18
  *
@@ -248,7 +248,7 @@ export class Camera {
248
248
 
249
249
  const normal = near.normal;
250
250
 
251
- const distance_to_plane = computePointDistanceToPlane(x, y, z, normal.x, normal.y, normal.z, near.constant);
251
+ const distance_to_plane = v3_distance_above_plane(x, y, z, normal.x, normal.y, normal.z, near.constant);
252
252
 
253
253
  const negative_distance_to_plane = -distance_to_plane;
254
254
 
@@ -212,6 +212,12 @@ export class CameraSystem extends System {
212
212
  return;
213
213
  }
214
214
 
215
+ if(c.object.updateProjectionMatrix !== undefined) {
216
+ c.object.updateProjectionMatrix();
217
+ c.object.updateMatrix();
218
+ c.object.updateMatrixWorld(true);
219
+ }
220
+
215
221
  if (c.autoClip === true) {
216
222
  auto_set_camera_clipping_planes(c, layers);
217
223
  } else {
@@ -239,7 +239,7 @@ export class ThreeLightBinding extends LightBinding {
239
239
  const cameraView = this.__shadow_map.views[0];
240
240
 
241
241
  // signal that we're about to render this view
242
- cameraView.on.preRender.send0();
242
+ cameraView.on.preRender.send1(cameraView);
243
243
 
244
244
  /**
245
245
  *
@@ -281,15 +281,23 @@ export class ShadedGeometry {
281
281
 
282
282
  const min = gbb.min;
283
283
 
284
- scratch_aabb3_array[0] = min.x;
285
- scratch_aabb3_array[1] = min.y;
286
- scratch_aabb3_array[2] = min.z;
284
+ const x0 = min.x;
285
+ const y0 = min.y;
286
+ const z0 = min.z;
287
287
 
288
288
  const max = gbb.max;
289
289
 
290
- scratch_aabb3_array[3] = max.x;
291
- scratch_aabb3_array[4] = max.y;
292
- scratch_aabb3_array[5] = max.z;
290
+ const x1 = max.x;
291
+ const y1 = max.y;
292
+ const z1 = max.z;
293
+
294
+ scratch_aabb3_array[0] = x0;
295
+ scratch_aabb3_array[1] = y0;
296
+ scratch_aabb3_array[2] = z0;
297
+
298
+ scratch_aabb3_array[3] = x1;
299
+ scratch_aabb3_array[4] = y1;
300
+ scratch_aabb3_array[5] = z1;
293
301
 
294
302
  aabb3_matrix4_project(this.__bvh_aabb, scratch_aabb3_array, this.transform);
295
303
  }
@@ -3,7 +3,8 @@ import { AABB3 } from "../../../../../core/bvh2/aabb3/AABB3.js";
3
3
 
4
4
  export const SGMeshFlags = {
5
5
  CastShadow: 1,
6
- ReceiveShadow: 2
6
+ ReceiveShadow: 2,
7
+ Loaded: 4
7
8
  };
8
9
 
9
10
  export class SGMesh {
@@ -17,6 +17,13 @@ import { min2 } from "../../../../../core/math/min2.js";
17
17
  */
18
18
  const MAX_CYCLE_COUNT = 128;
19
19
 
20
+ /**
21
+ * In milliseconds
22
+ * @readonly
23
+ * @type {number}
24
+ */
25
+ const MAX_CYCLE_TIME = 40;
26
+
20
27
  export class SGMeshSystem extends System {
21
28
  /**
22
29
  *
@@ -235,10 +242,11 @@ export class SGMeshSystem extends System {
235
242
 
236
243
  if (l > 0) {
237
244
 
238
- let pointer = this.__wait_queue_process_index;
245
+ const time_0 = performance.now();
239
246
 
247
+ let pointer = this.__wait_queue_process_index;
240
248
 
241
- let pointer_limit = pointer + min2(l, MAX_CYCLE_COUNT);
249
+ const pointer_limit = pointer + min2(l, MAX_CYCLE_COUNT);
242
250
 
243
251
  while (pointer < pointer_limit) {
244
252
 
@@ -260,6 +268,13 @@ export class SGMeshSystem extends System {
260
268
 
261
269
  this.process(entity, mesh, transform);
262
270
 
271
+ const time_1 = performance.now();
272
+
273
+ if ((time_1 - time_0) > MAX_CYCLE_TIME) {
274
+ // too much time has passed
275
+ break;
276
+ }
277
+
263
278
  }
264
279
 
265
280
  this.__wait_queue_process_index = pointer;
@@ -20,10 +20,7 @@ import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
20
20
  import { BehaviorComponent } from "../../../../intelligence/behavior/ecs/BehaviorComponent.js";
21
21
  import { OrbitingBehavior } from "../../../../../../model/game/util/behavior/OrbitingBehavior.js";
22
22
  import Vector2 from "../../../../../core/geom/Vector2.js";
23
- import { GizmoRenderingPlugin } from "../../../render/gizmo/GizmoRenderingPlugin.js";
24
- import { Gizmo } from "../../../render/gizmo/Gizmo.js";
25
23
  import { AABB3 } from "../../../../../core/bvh2/aabb3/AABB3.js";
26
- import { MicronRenderPlugin } from "../../../micron/plugin/MicronRenderPlugin.js";
27
24
  import { randomFloatBetween } from "../../../../../core/math/random/randomFloatBetween.js";
28
25
 
29
26
  new EngineHarness().initialize({
@@ -38,8 +35,8 @@ new EngineHarness().initialize({
38
35
  new ShadedGeometryHighlightSystem(engine)
39
36
  );
40
37
 
41
- config.addPlugin(GizmoRenderingPlugin);
42
- config.addPlugin(MicronRenderPlugin);
38
+ // config.addPlugin(GizmoRenderingPlugin);
39
+ // config.addPlugin(MicronRenderPlugin);
43
40
 
44
41
  const gltfAssetLoader = new GLTFAssetLoader();
45
42
 
@@ -79,11 +76,11 @@ function make_grid(ecd, engine) {
79
76
  radius: 5
80
77
  });
81
78
 
82
- const ctx = {
83
- time: Math.sin(i * Math.PI / (GRID_FREQUENCY_SIZE - 1)) + Math.cos(j * Math.PI / (GRID_FREQUENCY_SIZE - 1))
84
- };
85
-
86
- const color = [random(), random(), random(), 1];
79
+ // const ctx = {
80
+ // time: Math.sin(i * Math.PI / (GRID_FREQUENCY_SIZE - 1)) + Math.cos(j * Math.PI / (GRID_FREQUENCY_SIZE - 1))
81
+ // };
82
+ //
83
+ // const color = [random(), random(), random(), 1];
87
84
 
88
85
  engine.graphics.on.preRender.add(() => {
89
86
 
@@ -93,16 +90,16 @@ function make_grid(ecd, engine) {
93
90
 
94
91
  // mesh.getBoundingBox(bounds);
95
92
 
96
- Gizmo.color = color;
97
-
98
- Gizmo.draw_wire_cube(
99
- [
100
- bounds.getCenterX(), bounds.getCenterY(), bounds.getCenterZ()
101
- ],
102
- [
103
- bounds.getExtentsX(), bounds.getExtentsY(), bounds.getExtentsZ()
104
- ]
105
- );
93
+ // Gizmo.color = color;
94
+ //
95
+ // Gizmo.draw_wire_cube(
96
+ // [
97
+ // bounds.getCenterX(), bounds.getCenterY(), bounds.getCenterZ()
98
+ // ],
99
+ // [
100
+ // bounds.getExtentsX(), bounds.getExtentsY(), bounds.getExtentsZ()
101
+ // ]
102
+ // );
106
103
  });
107
104
 
108
105
 
@@ -5,21 +5,26 @@
5
5
  * @param {number} channel_count
6
6
  */
7
7
  export function flipArrayInPlace(input, width, height, channel_count = 4) {
8
- const rowLength = width * channel_count;
8
+ const row_size = width * channel_count;
9
9
  let t, x0, x1;
10
10
  let i = 0;
11
- const l = height >> 1;
11
+ const column_count = height >> 1;
12
+
13
+ for (; i < column_count; i++) {
12
14
 
13
- for (; i < l; i++) {
14
15
  //swap lines
15
- const k = (height - i - 1) * rowLength;
16
- const m = i * rowLength;
17
- for (let j = 0; j < rowLength; j++) {
16
+ const k = (height - i - 1) * row_size;
17
+ const m = i * row_size;
18
+
19
+ for (let j = 0; j < row_size; j++) {
18
20
  x0 = m + j;
19
21
  x1 = k + j;
22
+
20
23
  t = input[x0];
24
+
21
25
  input[x0] = input[x1];
22
26
  input[x1] = t;
23
27
  }
28
+
24
29
  }
25
30
  }
@@ -1,4 +1,4 @@
1
- import { computePointDistanceToPlane } from "../../../../core/geom/Plane.js";
1
+ import { v3_distance_above_plane } from "../../../../core/geom/v3_distance_above_plane.js";
2
2
 
3
3
 
4
4
  // TODO incomplete
@@ -107,9 +107,9 @@ export class ClippedGeometry {
107
107
 
108
108
  const plane_constant = plane.constant;
109
109
 
110
- const a_distance = computePointDistanceToPlane(a_x, a_y, a_z, normal_x, normal_y, normal_z, plane_constant);
111
- const b_distance = computePointDistanceToPlane(b_x, b_y, b_z, normal_x, normal_y, normal_z, plane_constant);
112
- const c_distance = computePointDistanceToPlane(c_x, c_y, c_z, normal_x, normal_y, normal_z, plane_constant);
110
+ const a_distance = v3_distance_above_plane(a_x, a_y, a_z, normal_x, normal_y, normal_z, plane_constant);
111
+ const b_distance = v3_distance_above_plane(b_x, b_y, b_z, normal_x, normal_y, normal_z, plane_constant);
112
+ const c_distance = v3_distance_above_plane(c_x, c_y, c_z, normal_x, normal_y, normal_z, plane_constant);
113
113
 
114
114
  const a_out = a_distance <= 0;
115
115
  const b_out = b_distance <= 0;
@@ -516,7 +516,9 @@ function init() {
516
516
  // gltf_sample('moicon/A4/A4/model.gltf');
517
517
  // gltf_sample('moicon/06_04_hapro/08-clickable-assets-new/model.gltf');
518
518
  // gltf_grid('moicon/ztest_object_many_pieces/model.gltf', 3, 3);
519
- gltf_sample('moicon/ztest_object_many_pieces/model.gltf');
519
+ // gltf_sample('moicon/ztest_object_many_pieces/model.gltf');
520
+ // gltf_sample('moicon/62cf22227f7b8f0012ca5988/model.gltf');
521
+ gltf_sample('moicon/gnutti_not_optimized/model.gltf');
520
522
  // gltf_grid('data/models/moicon/Kople/EVCharger1.gltf');
521
523
  // gltf_sample('data/models/moicon/Kople/EVCharger1.gltf');
522
524
  // gltf_sample('data/models/moicon/isiflow_Oct_15_21/0/model.gltf');
@@ -356,7 +356,9 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
356
356
  this.__composit_layer.on.preRender.remove(this.__render, this);
357
357
  graphics.viewport.size.onChanged.add(this.__update_render_target_size, this);
358
358
 
359
+ // release memory
359
360
  this.__blur.dispose();
361
+ this.__render_target.dispose();
360
362
 
361
363
  return super.shutdown();
362
364
  }
@@ -0,0 +1,95 @@
1
+ import { EnginePlugin } from "../../../../../plugin/EnginePlugin.js";
2
+ import { halton_sequence } from "../../../../../../core/math/statistics/halton_sequence.js";
3
+ import { array_copy } from "../../../../../../core/collection/array/copyArray.js";
4
+
5
+ /**
6
+ * Generates a number of 2d jitter offsets in range -1...1
7
+ * @param {number} point_count
8
+ * @return {Float32Array}
9
+ */
10
+ function generate_jitter(point_count) {
11
+ const result = new Float32Array(point_count * 2);
12
+
13
+ for (let i = 0; i < point_count; i++) {
14
+ const i2 = i * 2;
15
+ result[i2] = halton_sequence(2, i) * 2 - 1;
16
+ result[i2 + 1] = halton_sequence(3, i) * 2 - 1;
17
+ }
18
+
19
+ return result;
20
+ }
21
+
22
+ export class TemporalSupersamplingRenderPlugin extends EnginePlugin {
23
+ constructor() {
24
+ super();
25
+
26
+ /**
27
+ *
28
+ * @type {number}
29
+ * @private
30
+ */
31
+ this.__frame_index = 0;
32
+
33
+ this.__sample_count = 16;
34
+ this.__jitter_offset = generate_jitter(this.__sample_count);
35
+
36
+
37
+ this.__projection_modifier = {
38
+ /**
39
+ *
40
+ * @param {number[]} input
41
+ * @param {number[]} output
42
+ */
43
+ transform: (input, output) => {
44
+
45
+ const viewport_width = this.engine.graphics.viewport.size.x;
46
+ const viewport_height = this.engine.graphics.viewport.size.y;
47
+
48
+ // apply jitter to projection matrix
49
+ const jitter_index = this.__frame_index % this.__sample_count;
50
+
51
+ const jitter_offset_x = this.__jitter_offset[jitter_index * 2];
52
+ const jitter_offset_y = this.__jitter_offset[jitter_index * 2 + 1];
53
+
54
+ array_copy(input, 0, output, 0, 16);
55
+
56
+ output[8] = jitter_offset_x / viewport_width;
57
+ output[9] = jitter_offset_y / viewport_height;
58
+ }
59
+ };
60
+ }
61
+
62
+ __hook_post_render() {
63
+
64
+ // increment frame index
65
+ this.__frame_index++;
66
+ }
67
+
68
+ initialize(engine) {
69
+ super.initialize(engine);
70
+ }
71
+
72
+ finalize() {
73
+ super.finalize();
74
+ }
75
+
76
+ async startup() {
77
+ // modify projection matrix
78
+ this.engine.graphics.main_view.addProjectionModifier(this.__projection_modifier);
79
+
80
+
81
+ this.engine.graphics.on.postRender.add(this.__hook_post_render, this);
82
+
83
+ // reset frame counter
84
+ this.__frame_index = 0;
85
+
86
+ return super.startup();
87
+ }
88
+
89
+ async shutdown() {
90
+ this.engine.graphics.main_view.removeProjectionModifier(this.__projection_modifier);
91
+ this.engine.graphics.on.postRender.remove(this.__hook_post_render, this);
92
+
93
+ return super.shutdown();
94
+ }
95
+ }