@woosh/meep-engine 2.33.64 → 2.33.69

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 (34) hide show
  1. package/core/FilePath.js +28 -2
  2. package/core/binary/BinaryBuffer.js +13 -0
  3. package/core/geom/2d/quad-tree/QuadTreeNode.js +3 -2
  4. package/core/geom/3d/triangle/computeTriangleRayIntersection.js +3 -9
  5. package/engine/asset/AssetManager.js +1 -1
  6. package/engine/asset/AssetTransformer.js +2 -1
  7. package/engine/asset/loaders/GLTFAssetLoader.js +2 -22
  8. package/engine/asset/loaders/async_traverse_three_object.js +24 -0
  9. package/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +2 -10
  10. package/engine/ecs/grid/NormalMap2AOMap.js +10 -13
  11. package/engine/ecs/terrain/ecs/BuildLightTexture.js +106 -0
  12. package/engine/ecs/terrain/ecs/PromiseSamplerHeight.js +59 -0
  13. package/engine/ecs/terrain/ecs/Terrain.js +14 -153
  14. package/engine/graphics/FULL_SCREEN_QUAD_VERTEX_SHADER.js +10 -0
  15. package/engine/graphics/filter/ImageFilter.js +6 -2
  16. package/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +28 -27
  17. package/engine/graphics/geometry/buffered/query/GeometryVisitor.js +29 -2
  18. package/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +28 -27
  19. package/engine/graphics/micron/MICRON_GEOMETRY_FIELD.js +1 -0
  20. package/engine/graphics/micron/MICRON_URI_FIELD.js +1 -0
  21. package/engine/graphics/micron/convert_three_object_to_micron.js +31 -5
  22. package/engine/graphics/micron/format/MicronGeometry.js +6 -0
  23. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +110 -6
  24. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -1
  25. package/engine/graphics/shaders/AmbientOcclusionShader.js +57 -77
  26. package/engine/graphics/shaders/DenoiseShader.js +119 -0
  27. package/engine/graphics/texture/noise_octaves.js +33 -0
  28. package/engine/graphics/texture/sampler/Sampler2D2Texture.js +7 -18
  29. package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +8 -5
  30. package/engine/graphics/texture/sampler/sampler2DToFloat32Texture.js +10 -3
  31. package/generation/example/filters/SampleGroundMoistureFilter.js +2 -1
  32. package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +29 -13
  33. package/generation/grid/GridData.js +17 -2
  34. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ export const FULL_SCREEN_QUAD_VERTEX_SHADER = `
2
+ varying vec2 vUv;
3
+
4
+ void main() {
5
+
6
+ vUv = uv;
7
+
8
+ gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );
9
+
10
+ }`;
@@ -5,13 +5,14 @@
5
5
 
6
6
  import { LinearFilter, Mesh, OrthographicCamera, Scene, ShaderMaterial, WebGLRenderTarget } from 'three';
7
7
  import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
8
+ import { FULL_SCREEN_QUAD_VERTEX_SHADER } from "../FULL_SCREEN_QUAD_VERTEX_SHADER.js";
8
9
 
9
10
  /**
10
11
  *
11
12
  * @param {WebGLRenderer} renderer
12
13
  * @param {number} width
13
14
  * @param {number} height
14
- * @param {{vertexShader:string,fragmentShader:string, uniforms?:Object, defines?:Object}} processShader
15
+ * @param {{vertexShader?:string,fragmentShader:string, uniforms?:Object, defines?:Object}} processShader
15
16
  * @param {Uint8Array} [destination]
16
17
  * @return {{array: Uint8Array, renderer: WebGLRenderer}}
17
18
  */
@@ -34,9 +35,12 @@ function processTexture(
34
35
  scene.add(camera);
35
36
 
36
37
  //make a quad to render
37
- const material = new ShaderMaterial(processShader);
38
+ const material = new ShaderMaterial(Object.assign({ vertexShader: FULL_SCREEN_QUAD_VERTEX_SHADER }, processShader));
39
+
38
40
  material.lights = false;
39
41
  material.fog = false;
42
+ material.uniformsNeedUpdate = true;
43
+ material.needsUpdate = true;
40
44
 
41
45
  const quad = new Mesh(FULL_SCREEN_TRIANGLE_GEOMETRY, material);
42
46
 
@@ -79,21 +79,32 @@ export class ClippingPlaneContainmentComputingVisitor extends GeometrySpatialAcc
79
79
 
80
80
  const index3 = index * 3;
81
81
 
82
- const a = this.__buffer_indices[index3] * 3;
83
- const b = this.__buffer_indices[index3 + 1] * 3;
84
- const c = this.__buffer_indices[index3 + 2] * 3;
82
+ const indices = this.__buffer_indices;
85
83
 
86
- const ax = this.__buffer_vertices[a];
87
- const ay = this.__buffer_vertices[a + 1];
88
- const az = this.__buffer_vertices[a + 2];
84
+ const a = indices[index3];
85
+ const b = indices[index3 + 1];
86
+ const c = indices[index3 + 2];
89
87
 
90
- const bx = this.__buffer_vertices[b];
91
- const by = this.__buffer_vertices[b + 1];
92
- const bz = this.__buffer_vertices[b + 2];
88
+ const vertices = this.__buffer_vertices;
93
89
 
94
- const cx = this.__buffer_vertices[c];
95
- const cy = this.__buffer_vertices[c + 1];
96
- const cz = this.__buffer_vertices[c + 2];
90
+ const stride = this.__buffer_vertex_stride;
91
+ const offset = this.__buffer_position_offset;
92
+
93
+ const a_address = a * stride + offset;
94
+ const b_address = b * stride + offset;
95
+ const c_address = c * stride + offset;
96
+
97
+ const ax = vertices[a_address];
98
+ const ay = vertices[a_address + 1];
99
+ const az = vertices[a_address + 2];
100
+
101
+ const bx = vertices[b_address];
102
+ const by = vertices[b_address + 1];
103
+ const bz = vertices[b_address + 2];
104
+
105
+ const cx = vertices[c_address];
106
+ const cy = vertices[c_address + 1];
107
+ const cz = vertices[c_address + 2];
97
108
 
98
109
  for (let i = 0; i < plane_count; i++) {
99
110
  const plane = planes[i];
@@ -108,15 +119,9 @@ export class ClippingPlaneContainmentComputingVisitor extends GeometrySpatialAcc
108
119
  plane_normal_y,
109
120
  plane_normal_z,
110
121
  plane_constant,
111
- ax,
112
- ay,
113
- az,
114
- bx,
115
- by,
116
- bz,
117
- cx,
118
- cy,
119
- cz
122
+ ax, ay, az,
123
+ bx, by, bz,
124
+ cx, cy, cz
120
125
  );
121
126
 
122
127
  if (side === -3) {
@@ -163,12 +168,8 @@ export class ClippingPlaneContainmentComputingVisitor extends GeometrySpatialAcc
163
168
  plane_normal_z,
164
169
  plane_constant,
165
170
 
166
- x0,
167
- y0,
168
- z0,
169
- x1,
170
- y1,
171
- z1
171
+ x0, y0, z0,
172
+ x1, y1, z1
172
173
  );
173
174
 
174
175
  if (side === -2) {
@@ -1,6 +1,6 @@
1
1
  import { IndexedBinaryBVHVisitor } from "../../../../../core/bvh2/binary/IndexedBinaryBVHVisitor.js";
2
2
 
3
- export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor{
3
+ export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor {
4
4
  constructor() {
5
5
  super();
6
6
 
@@ -25,6 +25,20 @@ export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor{
25
25
  */
26
26
  this.__buffer_vertices = null;
27
27
 
28
+ /**
29
+ *
30
+ * @type {number}
31
+ * @protected
32
+ */
33
+ this.__buffer_vertex_stride = 3;
34
+
35
+ /**
36
+ *
37
+ * @type {number}
38
+ * @protected
39
+ */
40
+ this.__buffer_position_offset = 0;
41
+
28
42
  /**
29
43
  * @protected
30
44
  * @type {IndexedBinaryBVH}
@@ -47,7 +61,20 @@ export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor{
47
61
  this.geometry = geometry;
48
62
 
49
63
  this.__buffer_indices = geometry.getIndex().array;
50
- this.__buffer_vertices = geometry.getAttribute('position').array;
64
+
65
+ const position_attribute = geometry.getAttribute('position');
66
+
67
+ if (position_attribute.isInterleavedBufferAttribute) {
68
+ const data = position_attribute.data;
69
+
70
+ this.__buffer_vertices = data.array;
71
+ this.__buffer_vertex_stride = data.stride;
72
+ this.__buffer_position_offset = position_attribute.offset;
73
+ } else {
74
+ this.__buffer_vertices = position_attribute.array;
75
+ this.__buffer_vertex_stride = 3;
76
+ this.__buffer_position_offset = 0;
77
+ }
51
78
  }
52
79
 
53
80
  }
@@ -96,21 +96,32 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
96
96
 
97
97
  const index3 = index * 3;
98
98
 
99
- const a = this.__buffer_indices[index3] * 3;
100
- const b = this.__buffer_indices[index3 + 1] * 3;
101
- const c = this.__buffer_indices[index3 + 2] * 3;
99
+ const indices = this.__buffer_indices;
102
100
 
103
- const ax = this.__buffer_vertices[a];
104
- const ay = this.__buffer_vertices[a + 1];
105
- const az = this.__buffer_vertices[a + 2];
101
+ const a = indices[index3];
102
+ const b = indices[index3 + 1];
103
+ const c = indices[index3 + 2];
106
104
 
107
- const bx = this.__buffer_vertices[b];
108
- const by = this.__buffer_vertices[b + 1];
109
- const bz = this.__buffer_vertices[b + 2];
105
+ const vertices = this.__buffer_vertices;
110
106
 
111
- const cx = this.__buffer_vertices[c];
112
- const cy = this.__buffer_vertices[c + 1];
113
- const cz = this.__buffer_vertices[c + 2];
107
+ const stride = this.__buffer_vertex_stride;
108
+ const offset = this.__buffer_position_offset;
109
+
110
+ const a_address = a * stride + offset;
111
+ const b_address = b * stride + offset;
112
+ const c_address = c * stride + offset;
113
+
114
+ const ax = vertices[a_address];
115
+ const ay = vertices[a_address + 1];
116
+ const az = vertices[a_address + 2];
117
+
118
+ const bx = vertices[b_address];
119
+ const by = vertices[b_address + 1];
120
+ const bz = vertices[b_address + 2];
121
+
122
+ const cx = vertices[c_address];
123
+ const cy = vertices[c_address + 1];
124
+ const cz = vertices[c_address + 2];
114
125
 
115
126
  if (computeTriangleRayIntersection(
116
127
  this.__temp_hit,
@@ -120,15 +131,9 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
120
131
  rayDirection.x,
121
132
  rayDirection.y,
122
133
  rayDirection.z,
123
- ax,
124
- ay,
125
- az,
126
- bx,
127
- by,
128
- bz,
129
- cx,
130
- cy,
131
- cz
134
+ ax, ay, az,
135
+ bx, by, bz,
136
+ cx, cy, cz
132
137
  )) {
133
138
  const d = this.__temp_hit.position.distanceSqrTo(rayOrigin);
134
139
 
@@ -154,12 +159,8 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
154
159
  const z1 = data[address + 5];
155
160
 
156
161
  return intersectRay(
157
- x0,
158
- y0,
159
- z0,
160
- x1,
161
- y1,
162
- z1,
162
+ x0, y0, z0,
163
+ x1, y1, z1,
163
164
 
164
165
  rayOrigin.x,
165
166
  rayOrigin.y,
@@ -0,0 +1 @@
1
+ export const MICRON_GEOMETRY_FIELD = '@micron_geometry';
@@ -0,0 +1 @@
1
+ export const MICRON_URI_FIELD = '@micron_path';
@@ -4,6 +4,7 @@ import { computeGeometryEquality } from "../../asset/loaders/geometry/geometry/c
4
4
  import { buildMicronGeometryFromBufferGeometry } from "./build/buildMicronGeometryFromBufferGeometry.js";
5
5
  import { ThreeMicronMesh } from "./format/ThreeMicronMesh.js";
6
6
  import { AsyncMapWrapper } from "../../../core/collection/map/AsyncMapWrapper.js";
7
+ import { MICRON_GEOMETRY_FIELD } from "./MICRON_GEOMETRY_FIELD.js";
7
8
 
8
9
  /**
9
10
  *
@@ -19,7 +20,6 @@ const pending_cache = new HashMap({
19
20
  keyEqualityFunction: computeGeometryEquality
20
21
  });
21
22
 
22
-
23
23
  /**
24
24
  *
25
25
  * @param {THREE.Object3D} object
@@ -36,10 +36,22 @@ export async function convert_three_object_to_micron(object, micron_cache = defa
36
36
  * @returns {MicronGeometry}
37
37
  */
38
38
  async function obtain_geometry(g) {
39
- const existing = await micron_cache.get(g);
39
+ const attached_micron = g[MICRON_GEOMETRY_FIELD];
40
40
 
41
- if (existing !== undefined && existing !== null) {
42
- return existing;
41
+ if (attached_micron !== undefined && attached_micron.isMicronGeometry) {
42
+ // micron geometry is already attached, use it
43
+ return attached_micron;
44
+ }
45
+
46
+ const cached_micron = await micron_cache.get(g);
47
+
48
+
49
+ if (cached_micron !== undefined && cached_micron !== null) {
50
+
51
+ // set proxy
52
+ cached_micron.proxy = g;
53
+
54
+ return cached_micron;
43
55
  }
44
56
 
45
57
  const pending = pending_cache.get(g);
@@ -54,8 +66,14 @@ export async function convert_three_object_to_micron(object, micron_cache = defa
54
66
 
55
67
  promises.push(micron_geometry_promise);
56
68
 
69
+ /**
70
+ *
71
+ * @type {MicronGeometry}
72
+ */
57
73
  const micron_geometry = await micron_geometry_promise;
58
74
 
75
+ micron_geometry.proxy = g;
76
+
59
77
  await micron_cache.set(g, micron_geometry);
60
78
 
61
79
  return micron_geometry;
@@ -90,7 +108,15 @@ export async function convert_three_object_to_micron(object, micron_cache = defa
90
108
  && !mesh.isSkinnedMesh // skinned meshes not supported
91
109
  ) {
92
110
 
93
- const micronGeometry = await obtain_geometry(mesh.geometry);
111
+ let micronGeometry;
112
+ try {
113
+ micronGeometry = await obtain_geometry(mesh.geometry);
114
+ } catch (e) {
115
+ console.error(`Failed to convert geometry to micron, skipping : ${e}`);
116
+
117
+ // return original
118
+ return mesh;
119
+ }
94
120
 
95
121
  const micron_mesh = new ThreeMicronMesh(micronGeometry, mesh.material);
96
122
 
@@ -117,3 +117,9 @@ export class MicronGeometry {
117
117
  return this.__patches[id];
118
118
  }
119
119
  }
120
+
121
+ /**
122
+ * @readonly
123
+ * @type {boolean}
124
+ */
125
+ MicronGeometry.prototype.isMicronGeometry = true;
@@ -13,6 +13,13 @@ import { AsyncRemoteHashMap } from "../../../../core/collection/map/AsyncRemoteH
13
13
  import { BufferGeometrySerializationAdapter } from "./serialization/BufferGeometrySerializationAdapter.js";
14
14
  import { MicronGeometryBinarySerializationAdapter } from "../format/serialization/MicronGeometryBinarySerializationAdapter.js";
15
15
  import { AsyncMapWrapper } from "../../../../core/collection/map/AsyncMapWrapper.js";
16
+ import { async_traverse_three_object } from "../../../asset/loaders/async_traverse_three_object.js";
17
+ import { computePathDirectory } from "../../../../core/FilePath.js";
18
+ import { BinaryBuffer } from "../../../../core/binary/BinaryBuffer.js";
19
+ import { MicronGeometry } from "../format/MicronGeometry.js";
20
+ import { ArrayBufferLoader } from "../../../asset/loaders/ArrayBufferLoader.js";
21
+ import { MICRON_URI_FIELD } from "../MICRON_URI_FIELD.js";
22
+ import { MICRON_GEOMETRY_FIELD } from "../MICRON_GEOMETRY_FIELD.js";
16
23
 
17
24
  /**
18
25
  *
@@ -20,6 +27,7 @@ import { AsyncMapWrapper } from "../../../../core/collection/map/AsyncMapWrapper
20
27
  */
21
28
  const STORAGE_KEY = '@plugin/virtual-geometry-micron/geometry-cache';
22
29
 
30
+ const ASSET_TYPE_ARRAY_BUFFER = "arraybuffer";
23
31
 
24
32
  class GLTFAssetTransformer extends AssetTransformer {
25
33
  /**
@@ -35,17 +43,100 @@ class GLTFAssetTransformer extends AssetTransformer {
35
43
  * @private
36
44
  */
37
45
  this.__cache = cache;
46
+
47
+ /**
48
+ *
49
+ * @type {AssetManager|null}
50
+ * @private
51
+ */
52
+ this.__am = null;
53
+
54
+ /**
55
+ *
56
+ * @type {MicronGeometryBinarySerializationAdapter}
57
+ * @private
58
+ */
59
+ this.__serde = new MicronGeometryBinarySerializationAdapter();
38
60
  }
39
61
 
40
- async transform(source) {
62
+ /**
63
+ *
64
+ * @param {AssetManager|null} am
65
+ */
66
+ set assetManager(am) {
67
+ this.__am = am;
68
+ }
69
+
70
+
71
+ /**
72
+ * @param {THREE.Object3D} object
73
+ * @param {{asset:AssetDescription}} ctx
74
+ * @return {Promise<void>}
75
+ * @private
76
+ */
77
+ async __visitObjectToLoadMicron(object, ctx) {
78
+ if (!object.isMesh) {
79
+ return;
80
+ }
81
+
82
+ /**
83
+ * @type {THREE.BufferGeometry}
84
+ */
85
+ const geometry = object.geometry;
86
+
87
+ const micron_uri = geometry.userData[MICRON_URI_FIELD];
88
+
89
+ if (typeof micron_uri !== "string") {
90
+ return;
91
+ }
92
+
93
+
94
+ /**
95
+ * @type {AssetDescription}
96
+ */
97
+ const ad = ctx.asset;
98
+
99
+ const base = computePathDirectory(ad.path);
100
+
101
+ const micron_data = await this.__am.promise(`${base}/${micron_uri}`, ASSET_TYPE_ARRAY_BUFFER);
102
+
103
+ // deserialize micron data
104
+ const buffer = BinaryBuffer.fromArrayBuffer(micron_data.create());
105
+ const micron_geometry = new MicronGeometry();
106
+
107
+ this.__serde.deserialize(buffer, micron_geometry);
108
+
109
+ // set proxy for raycasting
110
+ micron_geometry.proxy = geometry;
111
+
112
+ geometry[MICRON_GEOMETRY_FIELD] = micron_geometry;
113
+ }
114
+
115
+
116
+ /**
117
+ *
118
+ * @param {Asset} source
119
+ * @param asset_description
120
+ * @return {Promise<Asset>}
121
+ */
122
+ async transform(source, asset_description) {
41
123
  const animationClips = source.animations;
124
+
42
125
  if (animationClips !== undefined && animationClips.length > 0) {
43
126
  // not suitable
44
127
  return source;
45
128
  }
46
129
 
130
+ /**
131
+ * @type {THREE.Object3D}
132
+ */
47
133
  const root = source.create();
48
134
 
135
+ // attempt to load existing micron geometries
136
+ await async_traverse_three_object(root, this.__visitObjectToLoadMicron, this, {
137
+ asset: asset_description
138
+ });
139
+
49
140
  const micron_root = await convert_three_object_to_micron(root.clone(), this.__cache);
50
141
  micron_root.boundingSphere = root.boundingSphere;
51
142
 
@@ -117,7 +208,7 @@ export class MicronRenderPlugin extends EnginePlugin {
117
208
 
118
209
  /**
119
210
  *
120
- * @type {AssetTransformer}
211
+ * @type {GLTFAssetTransformer}
121
212
  * @private
122
213
  */
123
214
  this.__asset_transformer = new GLTFAssetTransformer(this.__cache);
@@ -180,8 +271,17 @@ export class MicronRenderPlugin extends EnginePlugin {
180
271
 
181
272
  const engine = this.engine;
182
273
 
183
- engine.assetManager.registerTransformer("model/gltf", this.__asset_transformer);
184
- engine.assetManager.registerTransformer("model/gltf+json", this.__asset_transformer);
274
+ const am = engine.assetManager;
275
+
276
+ // ensure that "arraybuffer" asset loader is present
277
+ if (am.getLoaderByType(ASSET_TYPE_ARRAY_BUFFER) === undefined) {
278
+ am.registerLoader(ASSET_TYPE_ARRAY_BUFFER, new ArrayBufferLoader());
279
+ }
280
+
281
+ this.__asset_transformer.assetManager = am;
282
+
283
+ am.registerTransformer("model/gltf", this.__asset_transformer);
284
+ am.registerTransformer("model/gltf+json", this.__asset_transformer);
185
285
 
186
286
  /**
187
287
  *
@@ -207,8 +307,12 @@ export class MicronRenderPlugin extends EnginePlugin {
207
307
 
208
308
  this.__persisted_geometry.detach_storage();
209
309
 
210
- engine.assetManager.unregisterTransformer("model/gltf", this.__asset_transformer);
211
- engine.assetManager.unregisterTransformer("model/gltf+json", this.__asset_transformer);
310
+ const am = engine.assetManager;
311
+
312
+ am.unregisterTransformer("model/gltf", this.__asset_transformer);
313
+ am.unregisterTransformer("model/gltf+json", this.__asset_transformer);
314
+
315
+ this.__asset_transformer.assetManager = null;
212
316
 
213
317
  const ge = engine.graphics;
214
318
 
@@ -433,7 +433,9 @@ async function sample_scene_nam(engine) {
433
433
  "distanceMax": 1000
434
434
  });
435
435
 
436
- load_model('moicon/20_Dec_2021_Nammo/with_assets(for_alex)/model.gltf', ecd)
436
+ // load_model('moicon/20_Dec_2021_Nammo/with_assets(for_alex)/model.gltf', ecd)
437
+ load_model('moicon/20_Dec_2021_Nammo/with_assets_micron_conveted/model.gltf', ecd)
438
+ // load_model('moicon/micron_container/model.gltf', ecd)
437
439
 
438
440
  const P_SIZE_SMALL = 0.15;
439
441
  const P_SIZE_MEDIUM = 0.6;