@woosh/meep-engine 2.43.36 → 2.43.38

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.
@@ -37,7 +37,6 @@ export class AABB3 {
37
37
  z1 = 0
38
38
  ) {
39
39
  this.setBounds(x0, y0, z0, x1, y1, z1);
40
- this._surfaceArea = -1;
41
40
  }
42
41
 
43
42
  /**
@@ -96,10 +95,7 @@ export class AABB3 {
96
95
  * @returns {number}
97
96
  */
98
97
  getSurfaceArea() {
99
- if (typeof this._surfaceArea !== "number" || this._surfaceArea <= 0) {
100
- this._surfaceArea = this.computeSurfaceArea();
101
- }
102
- return this._surfaceArea;
98
+ return this.computeSurfaceArea();
103
99
  }
104
100
 
105
101
  /**
@@ -128,11 +124,35 @@ export class AABB3 {
128
124
  * @param {Number} z1
129
125
  */
130
126
  setBounds(x0, y0, z0, x1, y1, z1) {
127
+ /**
128
+ *
129
+ * @type {number}
130
+ */
131
131
  this.x0 = x0;
132
+ /**
133
+ *
134
+ * @type {number}
135
+ */
132
136
  this.y0 = y0;
137
+ /**
138
+ *
139
+ * @type {number}
140
+ */
133
141
  this.z0 = z0;
142
+ /**
143
+ *
144
+ * @type {number}
145
+ */
134
146
  this.x1 = x1;
147
+ /**
148
+ *
149
+ * @type {number}
150
+ */
135
151
  this.y1 = y1;
152
+ /**
153
+ *
154
+ * @type {number}
155
+ */
136
156
  this.z1 = z1;
137
157
  }
138
158
 
@@ -0,0 +1,30 @@
1
+ /**
2
+ * evaluate the basis functions
3
+ * shBasis is an Array[ 9 ]
4
+ *
5
+ * @param {number} x
6
+ * @param {number} y
7
+ * @param {number} z
8
+ * @param {number[]|ArrayLike<number>|Float32Array|Float64Array} shBasis
9
+ */
10
+ export function sh3_basis_at(x, y, z, shBasis) {
11
+
12
+ // normal is assumed to be unit length
13
+
14
+
15
+ // band 0
16
+ shBasis[0] = 0.282095;
17
+
18
+ // band 1
19
+ shBasis[1] = 0.488603 * y;
20
+ shBasis[2] = 0.488603 * z;
21
+ shBasis[3] = 0.488603 * x;
22
+
23
+ // band 2
24
+ shBasis[4] = 1.092548 * x * y;
25
+ shBasis[5] = 1.092548 * y * z;
26
+ shBasis[6] = 0.315392 * (3 * z * z - 1);
27
+ shBasis[7] = 1.092548 * x * z;
28
+ shBasis[8] = 0.546274 * (x * x - y * y);
29
+
30
+ }
@@ -27,21 +27,22 @@ export function sh3_sample_by_direction(
27
27
  let channel_value;
28
28
 
29
29
  for (let i = 0; i < dimension_count; i++) {
30
+ const offset = harmonics_offset + dimension_count * i;
30
31
 
31
32
  // band 0
32
- channel_value = harmonics[harmonics_offset + i] * 0.282095;
33
+ channel_value = harmonics[offset] * 0.282095;
33
34
 
34
35
  // band 1
35
- channel_value += harmonics[harmonics_offset + dimension_count + i] * 0.488603 * y;
36
- channel_value += harmonics[harmonics_offset + dimension_count * 2 + i] * 0.488603 * z;
37
- channel_value += harmonics[harmonics_offset + dimension_count * 3 + i] * 0.488603 * x;
36
+ channel_value += harmonics[offset + 1] * 0.488603 * y;
37
+ channel_value += harmonics[offset + 2] * 0.488603 * z;
38
+ channel_value += harmonics[offset + 3] * 0.488603 * x;
38
39
 
39
40
  // band 2
40
- channel_value += harmonics[harmonics_offset + dimension_count * 4 + i] * 1.092548 * (x * y);
41
- channel_value += harmonics[harmonics_offset + dimension_count * 5 + i] * 1.092548 * (y * z);
42
- channel_value += harmonics[harmonics_offset + dimension_count * 6 + i] * 0.315392 * (3.0 * z * z - 1.0);
43
- channel_value += harmonics[harmonics_offset + dimension_count * 7 + i] * 1.092548 * (x * z);
44
- channel_value += harmonics[harmonics_offset + dimension_count * 8 + i] * 0.546274 * (x * x - y * y);
41
+ channel_value += harmonics[offset + 4] * 1.092548 * (x * y);
42
+ channel_value += harmonics[offset + 5] * 1.092548 * (y * z);
43
+ channel_value += harmonics[offset + 6] * 0.315392 * (3.0 * z * z - 1.0);
44
+ channel_value += harmonics[offset + 7] * 1.092548 * (x * z);
45
+ channel_value += harmonics[offset + 8] * 0.546274 * (x * x - y * y);
45
46
 
46
47
  // write out
47
48
  result[result_offset + i] = channel_value;
@@ -0,0 +1,19 @@
1
+ /**
2
+ *
3
+ * @param {string} source
4
+ * @param {string} term
5
+ * @param {string} extra
6
+ * @returns {string}
7
+ */
8
+ export function insert_before(source, term, extra) {
9
+ const i = source.indexOf(term);
10
+
11
+ if (i === -1) {
12
+ console.warn(`Term '${term}' not found in the source`, source, extra);
13
+ return source;
14
+ }
15
+
16
+ const injection_position = i;
17
+
18
+ return source.slice(0, injection_position) + extra + source.slice(injection_position);
19
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ *
3
+ * @param {string} source
4
+ * @param {string} insert_term
5
+ * @param {string} replace_term
6
+ * @param {string} value
7
+ * @returns {string}
8
+ */
9
+ export function insert_before_or_replace(source, insert_term, replace_term, value) {
10
+ const insert_term_index = source.indexOf(insert_term);
11
+
12
+ if (insert_term_index !== -1) {
13
+ const injection_position = insert_term_index;
14
+ return source.slice(0, injection_position) + value + source.slice(injection_position);
15
+ }
16
+
17
+ const replace_term_index = source.indexOf(replace_term);
18
+
19
+ if (replace_term_index === -1) {
20
+ // not found
21
+ console.warn(`Neither insert term '${insert_term}', nor replacement term '${replace_term}' were found in the source`, source, value);
22
+ return source;
23
+ }
24
+
25
+
26
+ return source.slice(0, replace_term_index) + value + source.slice(replace_term_index + replace_term.length);
27
+ }
@@ -4,4 +4,8 @@ export class CrossOriginConfig {
4
4
  constructor() {
5
5
  this.kind = CrossOriginKind.Anonymous;
6
6
  }
7
+
7
8
  }
9
+
10
+ const default_coc = new CrossOriginConfig();
11
+ CrossOriginConfig.default = Object.freeze(default_coc);
@@ -1,6 +1,8 @@
1
1
  import { Asset } from "../Asset.js";
2
2
  import { AssetLoader } from "./AssetLoader.js";
3
3
  import { CrossOriginKind } from "../CORS/CrossOriginKind.js";
4
+ import { CrossOriginConfig } from "../CORS/CrossOriginConfig.js";
5
+ import { noop } from "../../../core/function/Functions.js";
4
6
 
5
7
  export class ArrayBufferLoader extends AssetLoader {
6
8
  /**
@@ -20,8 +22,8 @@ export class ArrayBufferLoader extends AssetLoader {
20
22
  this.__fetch_priority = fetch_priority;
21
23
  }
22
24
 
23
- load(path, success, failure, progress) {
24
- const coc = this.assetManager.crossOriginConfig;
25
+ load(path, success, failure = console.error, progress = noop) {
26
+ const coc = this.assetManager !== null ? this.assetManager.crossOriginConfig : CrossOriginConfig.default;
25
27
 
26
28
  const headers = new Headers();
27
29
 
@@ -392,7 +392,9 @@ PNG.prototype.getUint8Data = function () {
392
392
  let data;
393
393
  let itemSize = 0; // note, can take this from this.colors
394
394
 
395
- switch (this.colorType) {
395
+ const color_type = this.colorType;
396
+
397
+ switch (color_type) {
396
398
  case 0:
397
399
  data = this.pixels;
398
400
  itemSize = 1;
@@ -298,7 +298,7 @@ PNGReader.prototype.interlaceNone = function (data) {
298
298
  var bytes_per_pixel = Math.max(1, png.colors * png.bitDepth / 8);
299
299
 
300
300
  // color bytes per row
301
- const cpr = bytes_per_pixel * png.width;
301
+ const color_bytes_per_row = bytes_per_pixel * png.width;
302
302
 
303
303
  var pixels = new Uint8Array(bytes_per_pixel * png.width * png.height);
304
304
  // var scanline;
@@ -306,7 +306,7 @@ PNGReader.prototype.interlaceNone = function (data) {
306
306
 
307
307
  const data_length = data.length;
308
308
 
309
- for (var i = 0; i < data_length; i += cpr + 1) {
309
+ for (var i = 0; i < data_length; i += color_bytes_per_row + 1) {
310
310
 
311
311
  const scanline_address = i + 1;
312
312
 
@@ -316,25 +316,25 @@ PNGReader.prototype.interlaceNone = function (data) {
316
316
 
317
317
  switch (header) {
318
318
  case 0:
319
- this.unFilterNone(data, scanline_address, pixels, bytes_per_pixel, offset, cpr);
319
+ this.unFilterNone(data, scanline_address, pixels, bytes_per_pixel, offset, color_bytes_per_row);
320
320
  break;
321
321
  case 1:
322
- this.unFilterSub(data, scanline_address, pixels, bytes_per_pixel, offset, cpr);
322
+ this.unFilterSub(data, scanline_address, pixels, bytes_per_pixel, offset, color_bytes_per_row);
323
323
  break;
324
324
  case 2:
325
- this.unFilterUp(data, scanline_address, pixels, bytes_per_pixel, offset, cpr);
325
+ this.unFilterUp(data, scanline_address, pixels, bytes_per_pixel, offset, color_bytes_per_row);
326
326
  break;
327
327
  case 3:
328
- this.unFilterAverage(data, scanline_address, pixels, bytes_per_pixel, offset, cpr);
328
+ this.unFilterAverage(data, scanline_address, pixels, bytes_per_pixel, offset, color_bytes_per_row);
329
329
  break;
330
330
  case 4:
331
- this.unFilterPaeth(data, scanline_address, pixels, bytes_per_pixel, offset, cpr);
331
+ this.unFilterPaeth(data, scanline_address, pixels, bytes_per_pixel, offset, color_bytes_per_row);
332
332
  break;
333
333
  default:
334
- throw new Error("unkown filtered scanline");
334
+ throw new Error(`unknown filtered scanline type '${header}'`);
335
335
  }
336
336
 
337
- offset += cpr;
337
+ offset += color_bytes_per_row;
338
338
 
339
339
  }
340
340
 
@@ -0,0 +1,28 @@
1
+ import sampler2D2Canvas from "../../../../graphics/texture/sampler/Sampler2D2Canvas.js";
2
+ import { ArrayBufferLoader } from "../../ArrayBufferLoader.js";
3
+ import { PNGReader } from "./PNGReader.js";
4
+ import { Sampler2D } from "../../../../graphics/texture/sampler/Sampler2D.js";
5
+
6
+ const array_loader = new ArrayBufferLoader();
7
+
8
+
9
+
10
+ array_loader.load('moicon/bad_png_01/splat_height_2_messed_up (1).png',(asset)=>{
11
+
12
+ const array = asset.create();
13
+
14
+ const reader = new PNGReader(array);
15
+
16
+ const png = reader.parse();
17
+
18
+ console.log(png);
19
+
20
+ const uint8Data = png.getUint8Data();
21
+
22
+ const sampler = new Sampler2D(uint8Data.data,uint8Data.itemSize,png.getWidth(), png.getHeight());
23
+
24
+ const canvas = sampler2D2Canvas(sampler,1,0);
25
+
26
+ document.body.appendChild(canvas);
27
+
28
+ });
@@ -6,7 +6,7 @@ export class Transform {
6
6
  public readonly rotation: Quaternion
7
7
  public readonly scale: Vector3
8
8
 
9
- public lookAt(target: Vector3, limit?: number): void
9
+ public lookAt(target: Vector3): void
10
10
 
11
11
  static fromJSON(json: {
12
12
  position?: { x: number, y: number, z: number },
@@ -11,8 +11,6 @@ import { TransformFlags } from "./TransformFlags.js";
11
11
  import { allocate_transform_m4 } from "../../graphics/ecs/mesh-v2/allocate_transform_m4.js";
12
12
  import { assert } from "../../../core/assert.js";
13
13
 
14
- const delta = new Vector3();
15
-
16
14
  const scratch_buffer = new ArrayBuffer(16 * 4);
17
15
 
18
16
  const m4_0 = new Float32Array(scratch_buffer, 0, 16);
@@ -146,14 +144,24 @@ export class Transform {
146
144
  /**
147
145
  *
148
146
  * @param {Vector3} target
149
- * @param {number} [limit] Maximum angular displacement allowed towards the target, no limit by default. Useful for animating rotation towards a desired target.
150
147
  */
151
- lookAt(target, limit = Number.POSITIVE_INFINITY) {
148
+ lookAt(target) {
149
+
150
+ const position = this.position;
152
151
 
153
- delta.copy(target);
154
- delta.sub(this.position);
152
+ const delta_x = target.x - position.x;
153
+ const delta_y = target.y - position.y;
154
+ const delta_z = target.z - position.z;
155
+
156
+ if (delta_x === 0 && delta_y === 0 && delta_z === 0) {
157
+ // target is at the same location as this transform, no valid rotation, keep whatever we have
158
+ return;
159
+ }
155
160
 
156
- Transform.adjustRotation(this.rotation, delta, limit);
161
+ this.rotation._lookRotation(
162
+ delta_x, delta_y, delta_z,
163
+ Vector3.up.x, Vector3.up.y, Vector3.up.z
164
+ );
157
165
  }
158
166
 
159
167
  fromJSON(json) {
@@ -29,40 +29,10 @@ import { build_three_object } from "../ecs/mesh-v2/build_three_object.js";
29
29
  import { ShadedGeometryFlags } from "../ecs/mesh-v2/ShadedGeometryFlags.js";
30
30
  import { v3_length_sqr } from "../../../core/geom/v3_length_sqr.js";
31
31
  import { sh3_dering_optimize_positive } from "../../../core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js";
32
+ import { sh3_basis_at } from "../../../core/geom/3d/sphere/harmonics/sh3_basis_at.js";
32
33
 
33
34
  const TEMP_CONTACT = new SurfacePoint3();
34
35
 
35
- /**
36
- * evaluate the basis functions
37
- * shBasis is an Array[ 9 ]
38
- *
39
- * @param {number} x
40
- * @param {number} y
41
- * @param {number} z
42
- * @param {number[]|ArrayLike<number>|Float32Array|Float64Array} shBasis
43
- */
44
- function getBasisAt(x, y, z, shBasis) {
45
-
46
- // normal is assumed to be unit length
47
-
48
-
49
- // band 0
50
- shBasis[0] = 0.282095;
51
-
52
- // band 1
53
- shBasis[1] = 0.488603 * y;
54
- shBasis[2] = 0.488603 * z;
55
- shBasis[3] = 0.488603 * x;
56
-
57
- // band 2
58
- shBasis[4] = 1.092548 * x * y;
59
- shBasis[5] = 1.092548 * y * z;
60
- shBasis[6] = 0.315392 * (3 * z * z - 1);
61
- shBasis[7] = 1.092548 * x * z;
62
- shBasis[8] = 0.546274 * (x * x - y * y);
63
-
64
- }
65
-
66
36
  /**
67
37
  *
68
38
  * @param {Uint8Array} data
@@ -160,7 +130,7 @@ function fromCubeRenderTarget(data, renderer, cubeRenderTarget) {
160
130
  normal_z /= length;
161
131
 
162
132
  // evaluate SH basis functions in direction dir
163
- getBasisAt(normal_x, normal_y, normal_z, sh_basis);
133
+ sh3_basis_at(normal_x, normal_y, normal_z, sh_basis);
164
134
 
165
135
  // pixel color, already in linear space so no sRGB->Linear conversion necessary
166
136
 
@@ -266,7 +236,7 @@ class CubeRenderer {
266
236
  //
267
237
  // object3D.material.color.copy(source_material.color);
268
238
  // } else {
269
- object3D.material = source_material.clone();
239
+ object3D.material = source_material.clone();
270
240
  // }
271
241
 
272
242
  applyTransformToThreeObject(object3D, t);
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.43.36",
8
+ "version": "2.43.38",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",