@woosh/meep-engine 2.34.35 → 2.34.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 (49) hide show
  1. package/core/binary/BitSet.js +5 -0
  2. package/core/bvh2/BinaryNode.js +873 -1017
  3. package/core/bvh2/LeafNode.js +82 -75
  4. package/core/bvh2/Node.js +112 -114
  5. package/core/bvh2/aabb3/AABB3.js +46 -1
  6. package/core/bvh2/aabb3/AABB3.spec.js +27 -1
  7. package/core/bvh2/aabb3/aabb3_from_v3_array.js +34 -0
  8. package/core/bvh2/aabb3/aabb3_from_v3_array_transformed.js +39 -0
  9. package/core/bvh2/aabb3/aabb3_intersects_frustum_degree.js +46 -0
  10. package/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +16 -35
  11. package/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +52 -0
  12. package/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane.js +1 -1
  13. package/core/geom/3d/aabb/aabb3_matrix4_project.js +3 -4
  14. package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +13 -0
  15. package/core/geom/3d/triangle/computeTriangleRayIntersection.js +1 -2
  16. package/core/geom/Quaternion.d.ts +2 -0
  17. package/core/geom/Vector3.js +22 -11
  18. package/engine/ecs/attachment/TransformAttachmentBinding.js +0 -1
  19. package/engine/ecs/foliage/FoliageVisibilitySetBuilder.js +1 -31
  20. package/engine/ecs/foliage/InstancedFoliage.js +85 -152
  21. package/engine/ecs/foliage/ViewState.js +165 -0
  22. package/engine/ecs/foliage/ecs/Foliage2System.js +82 -19
  23. package/engine/ecs/foliage/ecs/InstancedMeshComponent.js +30 -0
  24. package/engine/ecs/foliage/ecs/InstancedMeshLayer.js +16 -0
  25. package/engine/ecs/foliage/ecs/InstancedMeshUtils.js +2 -2
  26. package/engine/ecs/parent/EntityNode.js +31 -49
  27. package/engine/ecs/transform-attachment/TransformAttachment.js +88 -0
  28. package/engine/ecs/transform-attachment/TransformAttachmentSystem.js +59 -0
  29. package/engine/graphics/GraphicsEngine.js +23 -2
  30. package/engine/graphics/ecs/camera/Camera.js +33 -16
  31. package/engine/graphics/ecs/camera/unprojectPoint.js +14 -0
  32. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +22 -17
  33. package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +21 -21
  34. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +9 -1
  35. package/engine/graphics/ecs/mesh-v2/ShadedGeometryFlags.js +4 -1
  36. package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +32 -8
  37. package/engine/graphics/ecs/water2/shader/AlexWaterShader.js +7 -1
  38. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +18 -12
  39. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +1 -34
  40. package/engine/graphics/micron/build/fill_patch_geometry_data.js +12 -0
  41. package/engine/graphics/micron/format/MicronGeometry.js +21 -0
  42. package/engine/graphics/micron/format/MicronGeometryPatch.js +0 -7
  43. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -3
  44. package/engine/graphics/micron/prototypeVirtualGeometry.js +69 -1
  45. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +5 -1
  46. package/engine/graphics/render/layers/RenderLayer.js +22 -85
  47. package/engine/graphics/render/visibility/VisibilityComputer.js +23 -103
  48. package/package.json +1 -1
  49. package/samples/terrain/editor.js +0 -1
@@ -20,6 +20,8 @@ import {
20
20
  SphereGeometry,
21
21
  sRGBEncoding,
22
22
  TextureLoader,
23
+ Vector2,
24
+ Vector3,
23
25
  VSMShadowMap,
24
26
  WebGLRenderer
25
27
  } from "three";
@@ -46,6 +48,8 @@ import { CanvasView } from "../../../view/elements/CanvasView.js";
46
48
  import { Sampler2D } from "../texture/sampler/Sampler2D.js";
47
49
  import { downsampleSampler2D } from "../texture/sampler/downsampleSampler2D.js";
48
50
  import { ShadowMapRenderer } from "../shadows/ShadowMapRenderer.js";
51
+ import { MouseEvents } from "../../input/devices/events/MouseEvents.js";
52
+ import { mat4 } from "gl-matrix";
49
53
 
50
54
  const background = new TextureLoader().load('data/textures/utility/checkers_white_grey_256x256.png');
51
55
  background.repeat.set(50, 30);
@@ -473,7 +477,8 @@ function init() {
473
477
  // gltf_sample('moicon/03_Jan_22_Demo/3-area_ground_floor/model.gltf');
474
478
  // gltf_sample('moicon/03_Jan_22_Demo/4-area_1st_floor/model.gltf');
475
479
  // gltf_sample('moicon/03_Jan_22_Demo/8-assets/model.gltf');
476
- gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
480
+ // gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
481
+ gltf_sample('moicon/A4/A4/model.gltf');
477
482
 
478
483
  document.addEventListener("mousemove", onDocumentMouseMove);
479
484
 
@@ -735,6 +740,7 @@ shadowmapRenderer.onBeforeRender.add((renderer, camera, scene) => {
735
740
  vgtr.render();
736
741
  });
737
742
 
743
+
738
744
  function render() {
739
745
  if (orbitControls !== undefined) {
740
746
  orbitControls.update();
@@ -790,3 +796,65 @@ function render() {
790
796
  // console.log(`patches:${active_patches.length}, polycount:${polycount}`);
791
797
  }
792
798
 
799
+ window.document.body.addEventListener(MouseEvents.Move, ({ clientX, clientY }) => {
800
+ const direction = new Vector3();
801
+
802
+ const viewport_size = new Vector2();
803
+
804
+ renderer.getSize(viewport_size);
805
+
806
+ const v2_nx = (clientX / viewport_size.x) * 2 - 1;
807
+ const v2_ny = -(clientY / viewport_size.y) * 2 + 1;
808
+
809
+ direction.set(v2_nx, v2_ny, 0.5);
810
+
811
+ direction.unproject(camera);
812
+
813
+ direction.sub(camera.position);
814
+
815
+ direction.normalize();
816
+
817
+ const origin_x = camera.position.x;
818
+ const origin_y = camera.position.y;
819
+ const origin_z = camera.position.z;
820
+
821
+ const direction_x = direction.x;
822
+ const direction_y = direction.y;
823
+ const direction_z = direction.z;
824
+
825
+ const hits = [];
826
+ scene.traverse(o => {
827
+ if (o.isMicronMesh) {
828
+ /**
829
+ * @type {MicronGeometry}
830
+ */
831
+ const micron_geo = o.geometry;
832
+
833
+ const scratch_m4 = new Float32Array(16);
834
+
835
+ // get transform in local space
836
+ mat4.invert(scratch_m4, o.matrixWorld);
837
+
838
+ // transform ray to local space
839
+ const local_origin_x = scratch_m4[0] * origin_x + scratch_m4[4] * origin_y + scratch_m4[8] * origin_z + scratch_m4[12];
840
+ const local_origin_y = scratch_m4[1] * origin_x + scratch_m4[5] * origin_y + scratch_m4[9] * origin_z + scratch_m4[13];
841
+ const local_origin_z = scratch_m4[2] * origin_x + scratch_m4[6] * origin_y + scratch_m4[10] * origin_z + scratch_m4[14];
842
+
843
+ const local_direction_x = scratch_m4[0] * direction_x + scratch_m4[4] * direction_y + scratch_m4[8] * direction_z;
844
+ const local_direction_y = scratch_m4[1] * direction_x + scratch_m4[5] * direction_y + scratch_m4[9] * direction_z;
845
+ const local_direction_z = scratch_m4[2] * direction_x + scratch_m4[6] * direction_y + scratch_m4[10] * direction_z;
846
+ // NOTE: direction is not normalized
847
+
848
+ const point = micron_geo.raycast(local_origin_x, local_origin_y, local_origin_z, local_direction_x, local_direction_y, local_direction_z);
849
+
850
+ Array.prototype.push.apply(hits, point.map(p => {
851
+ return { position: p.position.toJSON(), geometry: micron_geo.id, instance: o.id };
852
+ }));
853
+ }
854
+ });
855
+
856
+ if (hits.length > 0) {
857
+ console.log(`HITS: ${hits.map(JSON.stringify).join(',')}`);
858
+ }
859
+ });
860
+
@@ -464,7 +464,11 @@ export function make_particle_billboard_shader({ lights = false } = {}) {
464
464
  fragmentShader: make_fragment_shader(),
465
465
  blending: CustomBlending,
466
466
  lights: lights,
467
- depthTest: true,
467
+ /*
468
+ forcing transparent pass in Graphics Engine
469
+ three.js and indeed WebGL doesn't provide a way to pass depth buffer into the main draw pass (to canvas), so this is a workaround
470
+ */
471
+ depthTest: false,
468
472
  depthWrite: false,
469
473
  transparent: true,
470
474
  vertexColors: false,
@@ -6,73 +6,19 @@
6
6
  import { BinaryNode } from '../../../../core/bvh2/BinaryNode.js';
7
7
  import { RenderPassType } from "../RenderPassType.js";
8
8
  import { IncrementalDeltaSet } from "../visibility/IncrementalDeltaSet.js";
9
- import { BVHVisitor } from "../../../../core/bvh2/traversal/BVHVisitor.js";
10
- import { noop, passThrough } from "../../../../core/function/Functions.js";
11
- import { ThreeFrustumsIntersectionBVHVisitor } from "../../../../core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js";
9
+ import { passThrough } from "../../../../core/function/Functions.js";
12
10
  import { traverseBinaryNodeUsingVisitor } from "../../../../core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js";
13
11
  import { ThreeClippingPlaneComputingBVHVisitor } from "../../../../core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js";
14
12
  import { RenderLayerState } from "./RenderLayerState.js";
15
13
  import { compare_three_objects } from "../../three/compare_three_objects.js";
14
+ import { queryBinaryNode_FrustumIntersections_Data } from "../../../../core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js";
16
15
 
17
16
 
18
- class VisibleLeafCollector extends BVHVisitor {
19
- constructor() {
20
- super();
21
-
22
- /**
23
- *
24
- * @type {Function[]}
25
- */
26
- this.filters = [];
27
- this.filterCount = 0;
28
-
29
- this.callback = noop;
30
- this.callbackContext = null;
31
-
32
- this.reader = passThrough;
33
-
34
- this.count = 0;
35
- }
36
-
37
- initialize() {
38
- this.filterCount = this.filters.length;
39
- this.count = 0;
40
- }
41
-
42
- visitLeaf(leaf) {
43
- const numFilters = this.filterCount;
44
-
45
- const filters = this.filters;
46
-
47
- for (let i = 0; i < numFilters; i++) {
48
- const filterFunction = filters[i];
49
-
50
- const visibilityFlag = filterFunction(leaf);
51
-
52
- if (!visibilityFlag) {
53
- //not visible, skip
54
- return;
55
- }
56
- }
57
-
58
- const object = leaf.object;
59
-
60
- if (object === null) {
61
- // no payload on the BVH leaf
62
- return;
63
- }
64
-
65
- const renderable = this.reader(object);
66
-
67
- if (renderable === null) {
68
- // no renderable on the payload
69
- return;
70
- }
71
-
72
- this.count++;
73
- this.callback.call(this.callbackContext, renderable, leaf);
74
- }
75
- }
17
+ /**
18
+ *
19
+ * @type {*[]}
20
+ */
21
+ const scratch_array = [];
76
22
 
77
23
  export class RenderLayer {
78
24
  constructor() {
@@ -119,18 +65,6 @@ export class RenderLayer {
119
65
  * @type {RenderPassType|number}
120
66
  */
121
67
  this.renderPass = RenderPassType.Opaque;
122
-
123
- /**
124
- * @private
125
- * @type {VisibleLeafCollector}
126
- */
127
- this.visibilityCollector = new VisibleLeafCollector();
128
- /**
129
- * @private
130
- * @type {ThreeFrustumsIntersectionBVHVisitor}
131
- */
132
- this.bvhVisibilityVisitor = new ThreeFrustumsIntersectionBVHVisitor();
133
- this.bvhVisibilityVisitor.collector = this.visibilityCollector;
134
68
  }
135
69
 
136
70
  /**
@@ -178,29 +112,32 @@ export class RenderLayer {
178
112
 
179
113
  /**
180
114
  *
181
- * @param {Frustum[]} frustums
182
- * @param {function[]} filters
183
- * @param {function(Object3D, NodeDescription)} callback
115
+ * @param {CameraView} view
116
+ * @param {function(THREE.Object3D)} callback
184
117
  * @param {*} [callbackContext]
185
118
  */
186
- buildVisibleSet(frustums, filters, callback, callbackContext) {
119
+ buildVisibleSet(view, callback, callbackContext) {
120
+ const frustum = view.frustum;
121
+
187
122
  const reader = this.extractRenderable;
188
123
 
189
124
 
190
125
  if (typeof reader === "function") {
191
- this.visibilityCollector.callback = callback;
192
- this.visibilityCollector.callbackContext = callbackContext;
193
126
 
194
- this.visibilityCollector.filters = filters;
195
- this.visibilityCollector.reader = reader;
127
+ const hits = queryBinaryNode_FrustumIntersections_Data(scratch_array, 0, this.bvh, frustum);
196
128
 
197
- this.visibilityCollector.initialize();
129
+ for (let i = 0; i < hits; i++) {
130
+ const datum = scratch_array[i];
198
131
 
199
- this.bvhVisibilityVisitor.setFrustums(frustums);
132
+ const object3D = reader(datum);
200
133
 
201
- traverseBinaryNodeUsingVisitor(this.bvh, this.bvhVisibilityVisitor);
134
+ if (!object3D) {
135
+ // null or undefined
136
+ continue;
137
+ }
202
138
 
203
- this.visibilityCollector.finalize();
139
+ callback.call(callbackContext, object3D);
140
+ }
204
141
 
205
142
  }
206
143
 
@@ -1,42 +1,14 @@
1
- import { Frustum } from "three";
2
- import { frustumFromCamera } from "../../ecs/camera/CameraSystem.js";
3
1
  import { assert } from "../../../../core/assert.js";
4
2
 
5
- const frustum = new Frustum();
6
- /**
7
- *
8
- * @type {VisibilityFilter[]}
9
- */
10
- const objectFilters = [];
11
-
12
- /**
13
- *
14
- * @type {function[]}
15
- */
16
- const objectFilterExecutors = [];
17
-
18
- export const SOURCE_RENDER_LAYER_PROPERTY = '@meep-render-layer';
19
-
20
3
  export class VisibilityComputer {
21
4
  constructor() {
22
- /**
23
- *
24
- * @type {VisibilityFilter[]}
25
- */
26
- this.filters = [];
5
+
27
6
  /**
28
7
  *
29
8
  * @type {CameraView}
30
9
  */
31
10
  this.__view = null;
32
11
 
33
- /**
34
- * @deprecated use view.frustum instead
35
- * @type {Frustum[]}
36
- * @private
37
- */
38
- this.__frustums = [];
39
-
40
12
  /**
41
13
  *
42
14
  * @type {RenderLayer}
@@ -53,15 +25,28 @@ export class VisibilityComputer {
53
25
  }
54
26
 
55
27
  /**
56
- *
28
+ * @deprecated
29
+ * @returns {VisibilityFilter[]}
30
+ */
31
+ get filters() {
32
+
33
+ throw new Error('Method is deprecated');
34
+ }
35
+
36
+ /**
37
+ * @deprecated
38
+ * @param {VisibilityFilter[]} v
39
+ */
40
+ set filters(v) {
41
+ throw new Error('Method is deprecated');
42
+ }
43
+
44
+ /**
45
+ * @deprecated
57
46
  * @param {VisibilityFilter} filter
58
47
  */
59
48
  addFilter(filter) {
60
- if (this.filters.find(f => f.name === filter.name)) {
61
- throw new Error(`Filter named '${filter.name}' already exists`);
62
- }
63
-
64
- this.filters.push(filter);
49
+ throw new Error('Method is deprecated');
65
50
  }
66
51
 
67
52
  /**
@@ -70,16 +55,8 @@ export class VisibilityComputer {
70
55
  * @returns {boolean}
71
56
  */
72
57
  removeFilter(filter) {
73
- const i = this.filters.indexOf(filter);
74
-
75
- if (i === -1) {
76
- //not present
77
- return false;
78
- }
79
58
 
80
- //cut
81
- this.filters.splice(i, 1);
82
- return true;
59
+ throw new Error('Method is deprecated');
83
60
  }
84
61
 
85
62
  /**
@@ -97,9 +74,6 @@ export class VisibilityComputer {
97
74
  __includeObject(object3d) {
98
75
  assert.equal(object3d.isObject3D, true, 'object3d.isObject3D !== true');
99
76
 
100
- // mark object, this is a hack, needs to be fixed at some point
101
- object3d[SOURCE_RENDER_LAYER_PROPERTY] = this.__activeLayer;
102
-
103
77
  //object passed all filters, add it to visible set
104
78
  this.__output.push(object3d);
105
79
 
@@ -111,8 +85,6 @@ export class VisibilityComputer {
111
85
  * @param {RenderLayer} layer
112
86
  */
113
87
  __processLayer(layer) {
114
-
115
-
116
88
  if (!layer.state.visible) {
117
89
  //whole layer is hidden
118
90
 
@@ -123,61 +95,13 @@ export class VisibilityComputer {
123
95
  this.__activeLayer = layer;
124
96
 
125
97
  if (layer.managed) {
126
- this.__output.pushOther(layer.visibleSet);
127
98
 
128
- // mark all elements in the layer
129
- const elements = layer.visibleSet.elements;
130
-
131
- const element_count = elements.length;
132
- for (let j = 0; j < element_count; j++) {
133
- const object3D = elements[j];
134
-
135
- object3D[SOURCE_RENDER_LAYER_PROPERTY] = layer;
136
- }
99
+ this.__output.pushOther(layer.visibleSet);
137
100
 
138
101
  return;
139
102
  }
140
103
 
141
- // clear visible set
142
- // this.__output.initializeUpdate();
143
-
144
- const filters = this.filters;
145
- const filterCount = filters.length;
146
-
147
- let objectFilterCount = 0;
148
- let i;
149
- for (i = 0; i < filterCount; i++) {
150
- const f = filters[i];
151
-
152
- if (f.enabled && f.layerPredicate(layer)) {
153
- objectFilters[objectFilterCount] = f;
154
- objectFilterExecutors[objectFilterCount] = f.objectPredicateExecute;
155
-
156
- objectFilterCount++;
157
- }
158
- }
159
-
160
-
161
- //prepare filters
162
- for (i = 0; i < objectFilterCount; i++) {
163
- const f = objectFilters[i];
164
-
165
- f.objectPredicateInitialize(this.__view.camera);
166
- }
167
-
168
- objectFilterExecutors.length = objectFilterCount;
169
-
170
- layer.buildVisibleSet(this.__frustums, objectFilterExecutors, this.__includeObject, this);
171
-
172
- //finalize filters
173
- for (i = 0; i < objectFilterCount; i++) {
174
- const f = objectFilters[i];
175
-
176
- f.objectPredicateFinalize();
177
- }
178
-
179
-
180
- // layer.visibleSet.finalizeUpdate();
104
+ layer.buildVisibleSet(this.__view, this.__includeObject, this);
181
105
  }
182
106
 
183
107
 
@@ -193,10 +117,6 @@ export class VisibilityComputer {
193
117
  * @param {RenderLayerManager} renderLayers
194
118
  */
195
119
  build(renderLayers) {
196
- frustumFromCamera(this.__view.camera, frustum);
197
-
198
- this.__frustums = [frustum];
199
-
200
120
  renderLayers.traverse(this.__processLayer, this);
201
121
  }
202
122
  }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.34.35",
8
+ "version": "2.34.39",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",
@@ -20,7 +20,6 @@ import { copy_Sampler2D_channel_data } from "../../engine/graphics/texture/sampl
20
20
  import { TextureAssetLoader } from "../../engine/asset/loaders/texture/TextureAssetLoader.js";
21
21
  import { CanvasView } from "../../view/elements/CanvasView.js";
22
22
  import convertSampler2D2Canvas from "../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
23
- import { drawSamplerHTML } from "../../engine/graphics/texture/sampler/util/drawSamplerHTML.js";
24
23
 
25
24
  const engineHarness = new EngineHarness();
26
25