@woosh/meep-engine 2.43.35 → 2.43.37
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.
- package/core/bvh2/aabb3/AABB3.js +25 -5
- package/core/geom/Quaternion.js +20 -0
- package/core/primitives/strings/insert_before.js +19 -0
- package/core/primitives/strings/insert_before_or_replace.js +27 -0
- package/engine/asset/CORS/CrossOriginConfig.js +4 -0
- package/engine/asset/loaders/ArrayBufferLoader.js +4 -2
- package/engine/asset/loaders/image/png/PNG.js +3 -1
- package/engine/asset/loaders/image/png/PNGReader.js +9 -9
- package/engine/asset/loaders/image/png/prototypePNG.js +28 -0
- package/engine/ecs/transform/Transform.d.ts +1 -1
- package/engine/ecs/transform/Transform.js +15 -7
- package/package.json +1 -1
package/core/bvh2/aabb3/AABB3.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
package/core/geom/Quaternion.js
CHANGED
|
@@ -168,6 +168,26 @@ class Quaternion {
|
|
|
168
168
|
forward.normalize();
|
|
169
169
|
|
|
170
170
|
right._crossVectors(ux, uy, uz, forward.x, forward.y, forward.z);
|
|
171
|
+
|
|
172
|
+
if(right.lengthSq() === 0){
|
|
173
|
+
// up and forward are parallel
|
|
174
|
+
|
|
175
|
+
/*
|
|
176
|
+
adjust forward direction slightly
|
|
177
|
+
code take from : https://github.com/mrdoob/three.js/blob/88e8954b69377dad4ad1ceaf1a383f3536e88e5a/src/math/Matrix4.js#L304
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
if(Math.abs(uz) === 1){
|
|
181
|
+
forward.x += 0.001;
|
|
182
|
+
}else{
|
|
183
|
+
forward.z += 0.001;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
forward.normalize();
|
|
187
|
+
right._crossVectors(ux,uy,uz, forward.x, forward.y, forward.z);
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
171
191
|
right.normalize();
|
|
172
192
|
|
|
173
193
|
up.crossVectors(forward, right);
|
|
@@ -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
|
+
}
|
|
@@ -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
|
-
|
|
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
|
|
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 +=
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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(
|
|
334
|
+
throw new Error(`unknown filtered scanline type '${header}'`);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
offset +=
|
|
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
|
|
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
|
|
148
|
+
lookAt(target) {
|
|
149
|
+
|
|
150
|
+
const position = this.position;
|
|
152
151
|
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
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) {
|
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.
|
|
8
|
+
"version": "2.43.37",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|