@woosh/meep-engine 2.39.12 → 2.39.15

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.
@@ -28,9 +28,10 @@ export function computeTopoMeshBoundingSphere(result, mesh) {
28
28
  const miniball = new Miniball(pointSet);
29
29
 
30
30
  const center = miniball.center();
31
+ const radius = miniball.radius();
31
32
 
32
33
  result[0] = center[0];
33
34
  result[1] = center[1];
34
35
  result[2] = center[2];
35
- result[3] = miniball.radius();
36
+ result[3] = radius;
36
37
  }
@@ -928,38 +928,49 @@ class Terrain {
928
928
  * @param opt
929
929
  * @param {Engine} engine
930
930
  */
931
- fromJSON(opt, engine) {
931
+ fromJSON({
932
+ resolution = 4,
933
+ preview,
934
+ size = 1,
935
+ scale = 1,
936
+ material,
937
+ heights,
938
+ layers,
939
+ splat,
940
+ overlayTileImage
941
+ } = {}, engine) {
932
942
  // mark as needing rebuilding
933
943
  this.clearFlag(TerrainFlags.Built);
934
944
 
935
- if (opt === undefined) {
936
- opt = {};
945
+ if (preview !== undefined) {
946
+ this.preview.fromJSON(preview);
937
947
  }
938
948
 
939
- if (opt.preview !== undefined) {
940
- this.preview.fromJSON(opt.preview);
941
- }
942
-
943
- this.resolution = opt.resolution !== undefined ? opt.resolution : 4;
944
-
945
- const size = this.size;
949
+ this.resolution = resolution;
946
950
 
947
- if (opt.size !== undefined) {
948
- size.fromJSON(opt.size);
949
- }
951
+ this.size.fromJSON(size);
950
952
 
951
- this.gridScale = opt.scale !== undefined ? opt.scale : 2;
953
+ this.gridScale = scale;
952
954
  //
953
955
 
954
- this.materialDesc = opt.material;
956
+ this.materialDesc = material;
957
+
958
+ if (heights !== undefined) {
959
+ this.samplerHeight.fromJSON(heights);
960
+ } else {
961
+ this.samplerHeight.data = new Float32Array(1);
962
+ this.samplerHeight.width = 1;
963
+ this.samplerHeight.height = 1;
964
+ this.samplerHeight.itemSize = 1;
965
+ this.samplerHeight.version++;
966
+ }
955
967
 
956
- this.samplerHeight.fromJSON(opt.heights);
957
- this.layers.fromJSON(opt.layers);
958
- this.splat.fromJSON(opt.splat);
968
+ this.layers.fromJSON(layers);
969
+ this.splat.fromJSON(splat);
959
970
 
960
- if (opt.overlayTileImage !== undefined) {
971
+ if (overlayTileImage !== undefined) {
961
972
 
962
- this.overlay.baseTileImage(opt.overlayTileImage);
973
+ this.overlay.baseTileImage(overlayTileImage);
963
974
 
964
975
  }
965
976
 
@@ -111,6 +111,8 @@ const scaled_texture_cache = new Cache({
111
111
  }
112
112
  });
113
113
 
114
+ const DEFAULT_RESOLUTION = 512;
115
+
114
116
  export class TerrainLayers {
115
117
  constructor() {
116
118
 
@@ -124,7 +126,7 @@ export class TerrainLayers {
124
126
  *
125
127
  * @type {Vector2}
126
128
  */
127
- this.resolution = new Vector2(512, 512);
129
+ this.resolution = new Vector2(DEFAULT_RESOLUTION, DEFAULT_RESOLUTION);
128
130
 
129
131
  /**
130
132
  *
@@ -166,7 +168,7 @@ export class TerrainLayers {
166
168
  };
167
169
  }
168
170
 
169
- fromJSON({ resolution, layers }) {
171
+ fromJSON({ resolution = DEFAULT_RESOLUTION, layers = [] } = {}) {
170
172
  this.resolution.fromJSON(resolution);
171
173
  this.layers.fromJSON(layers, TerrainLayer);
172
174
  }
@@ -59,7 +59,11 @@ export class SplatMapping {
59
59
  };
60
60
  }
61
61
 
62
- fromJSON({ size, depth, data }) {
62
+ fromJSON({
63
+ size = { x: 1, y: 1 },
64
+ depth = 0,
65
+ data = []
66
+ } = {}) {
63
67
  this.resize(size.x, size.y, depth);
64
68
  array_copy(data, 0, this.weightData, 0, data.length);
65
69
 
@@ -16,6 +16,7 @@ import { uint82float } from "../../../../core/binary/uint82float.js";
16
16
  import { float2uint8 } from "../../../../core/binary/float2uint8.js";
17
17
  import { isTypedArray } from "../../../../core/collection/array/typed/isTypedArray.js";
18
18
  import { array_copy } from "../../../../core/collection/array/copyArray.js";
19
+ import { WHITE_PIXEL_DATA_URL } from "../../../graphics/WHITE_PIXEL_DATA_URL.js";
19
20
 
20
21
  class Context {
21
22
  /**
@@ -48,7 +49,6 @@ class Context {
48
49
 
49
50
  const COLOR_UINT_8_TRANSPARENT = [0, 0, 0, 0];
50
51
 
51
-
52
52
  export class TerrainOverlay {
53
53
  /**
54
54
  *
@@ -69,11 +69,11 @@ export class TerrainOverlay {
69
69
  */
70
70
  this.size = new Vector2(size.x, size.y);
71
71
 
72
- /**
72
+ /**
73
73
  *
74
74
  * @type {ObservedString}
75
75
  */
76
- this.tileImage = new ObservedString("");
76
+ this.tileImage = new ObservedString(WHITE_PIXEL_DATA_URL);
77
77
 
78
78
  /**
79
79
  *
@@ -0,0 +1 @@
1
+ export const WHITE_PIXEL_DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdj+P///38ACfsD/QVDRcoAAAAASUVORK5CYII=";
@@ -74,6 +74,7 @@ export function build_merge_graph(leaves) {
74
74
  const connection_weight = computePatchMergeScore(leaf, neighbour);
75
75
 
76
76
  assert.isNumber(connection_weight, 'connection_weight');
77
+ assert.notNaN(connection_weight, 'connection_weight');
77
78
  assert.isFiniteNumber(connection_weight, 'connection_weight');
78
79
 
79
80
  const edge = new WeightedEdge(node_leaf, node_neighbour);
@@ -1,9 +1,12 @@
1
1
  import { ConicRay } from "../../../../../core/geom/ConicRay.js";
2
2
  import { compute_bounding_cone_of_2_cones } from "../../../../../core/geom/3d/cone/compute_bounding_cone_of_2_cones.js";
3
3
  import { compute_patches_shared_vertex_count } from "./compute_patches_shared_vertex_count.js";
4
- import { compute_bounding_sphere_of_2_spheres } from "../../../../../core/geom/3d/compute_bounding_sphere_of_2_spheres.js";
4
+ import {
5
+ compute_bounding_sphere_of_2_spheres
6
+ } from "../../../../../core/geom/3d/compute_bounding_sphere_of_2_spheres.js";
5
7
  import { max2 } from "../../../../../core/math/max2.js";
6
8
  import { min2 } from "../../../../../core/math/min2.js";
9
+ import { assert } from "../../../../../core/assert.js";
7
10
 
8
11
 
9
12
  /**
@@ -74,6 +77,12 @@ function compute_sphere_volume(r) {
74
77
  * @return {number}
75
78
  */
76
79
  function normalized_difference(a, b) {
80
+ assert.isNumber(a, 'a');
81
+ assert.isNumber(b, 'a');
82
+
83
+ assert.notNaN(a,'a');
84
+ assert.notNaN(b,'b');
85
+
77
86
  return Math.abs(a - b) / (max2(a, b) + 0.0001);
78
87
  }
79
88
 
@@ -85,10 +94,13 @@ function normalized_difference(a, b) {
85
94
  */
86
95
  export function computePatchMergeScore(a, b) {
87
96
  // compute common neighbours
88
- const common_neighbours = array_compute_common_element_count(a.neighbours, b.neighbours);
97
+ const a_neighbours = a.neighbours;
98
+ const b_neighbours = b.neighbours;
99
+
100
+ const common_neighbours = array_compute_common_element_count(a_neighbours, b_neighbours);
89
101
 
90
102
  // normalize neighbour count
91
- const common_neighbour_score = common_neighbours / (min2(a.neighbours.length, b.neighbours.length) + 0.01);
103
+ const common_neighbour_score = common_neighbours / (min2(a_neighbours.length, b_neighbours.length) + 0.01);
92
104
 
93
105
  // prefer merging patches of similar LOD level, this creates a more flat hierarchy
94
106
  const lod_score = 1 - normalized_difference(a.lod, b.lod);
@@ -123,10 +135,12 @@ export function computePatchMergeScore(a, b) {
123
135
  */
124
136
  const shared_vertex_count = compute_patches_shared_vertex_count(a, b);
125
137
 
126
- return similar_volume_score * 0.01
138
+ const result = similar_volume_score * 0.01
127
139
  + shared_vertex_count
128
140
  + normal_score * 0.001
129
141
  + common_neighbour_score
130
142
  + lod_score * 0.1
131
143
  + volume_score;
144
+
145
+ return result;
132
146
  }
@@ -91,6 +91,14 @@ export class GLTFAssetTransformer extends AssetTransformer {
91
91
  * @private
92
92
  */
93
93
  this.__active_mesh_micron_cache = [];
94
+
95
+ /**
96
+ * @deprecated
97
+ * Whether override mesh will be created for the asset, this is generally outdated
98
+ * @type {boolean}
99
+ * @private
100
+ */
101
+ this.__settings_build_override_mesh = false;
94
102
  }
95
103
 
96
104
  /**
@@ -198,7 +206,7 @@ export class GLTFAssetTransformer extends AssetTransformer {
198
206
  */
199
207
  const root = source.create();
200
208
 
201
- await this.__load_mesh_micron_data(source.gltf,asset_description);
209
+ await this.__load_mesh_micron_data(source.gltf, asset_description);
202
210
 
203
211
  // attempt to load existing micron geometries
204
212
  await async_traverse_three_object(root, this.__visitObjectToLoadMicron, this, {
@@ -212,12 +220,14 @@ export class GLTFAssetTransformer extends AssetTransformer {
212
220
  return source;
213
221
  }
214
222
 
215
- const micron_root = await convert_three_object_to_micron(root.clone(), this.__cache);
216
- micron_root.boundingSphere = root.boundingSphere;
223
+ if (this.__settings_build_override_mesh) {
224
+ const micron_root = await convert_three_object_to_micron(root.clone(), this.__cache);
225
+ micron_root.boundingSphere = root.boundingSphere;
217
226
 
218
- source.override_mesh = micron_root;
227
+ source.override_mesh = micron_root;
219
228
 
220
- traverseThreeObject(micron_root, ensureProxy);
229
+ traverseThreeObject(micron_root, ensureProxy);
230
+ }
221
231
 
222
232
  return source;
223
233
  }
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.39.12",
8
+ "version": "2.39.15",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",