@woosh/meep-engine 2.36.2 → 2.36.4
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/collection/queue/Deque.js +1 -1
- package/core/color/Color.d.ts +32 -2
- package/core/color/Color.js +31 -18
- package/engine/graphics/ecs/highlight/HighlightDefinition.d.ts +1 -1
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +5 -1
- package/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js +122 -0
- package/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +148 -0
- package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.d.ts +4 -0
- package/package.json +1 -1
package/core/color/Color.d.ts
CHANGED
|
@@ -7,7 +7,37 @@ export class Color {
|
|
|
7
7
|
g: number
|
|
8
8
|
b: number
|
|
9
9
|
|
|
10
|
-
onChanged: Signal
|
|
10
|
+
readonly onChanged: Signal<number, number, number, number, number, number>
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
parse(text: string): void
|
|
13
|
+
|
|
14
|
+
setRGB(r: number, g: number, b: number): void
|
|
15
|
+
|
|
16
|
+
setHSL(h: number, s: number, l: number): void
|
|
17
|
+
|
|
18
|
+
setHCL(h: number, c: number, l: number): void
|
|
19
|
+
|
|
20
|
+
setHSI(h: number, s: number, i: number): void
|
|
21
|
+
|
|
22
|
+
setHSV(h: number, s: number, v: number): void
|
|
23
|
+
|
|
24
|
+
getHSV(): { h: number, s: number, v: number }
|
|
25
|
+
|
|
26
|
+
toUint(): number
|
|
27
|
+
|
|
28
|
+
fromUint(v: number): void
|
|
29
|
+
|
|
30
|
+
equals(other: Color): boolean
|
|
31
|
+
|
|
32
|
+
hash(): number
|
|
33
|
+
|
|
34
|
+
copy(other: Color): void
|
|
35
|
+
|
|
36
|
+
clone(): Color
|
|
37
|
+
|
|
38
|
+
fromJSON(json: any): void
|
|
39
|
+
|
|
40
|
+
toJSON(): any
|
|
41
|
+
|
|
42
|
+
writeToArray(destination: ArrayLike<number>, destination_offset: number): void
|
|
13
43
|
}
|
package/core/color/Color.js
CHANGED
|
@@ -10,7 +10,7 @@ import { computeHashFloat } from "../math/hash/computeHashFloat.js";
|
|
|
10
10
|
import { rgb2hsv } from "./rgb2hsv.js";
|
|
11
11
|
import { rgb2uint24 } from "./rgb2uint24.js";
|
|
12
12
|
|
|
13
|
-
class Color {
|
|
13
|
+
export class Color {
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
16
16
|
* @param {number} r value from 0 to 1
|
|
@@ -37,6 +37,10 @@ class Color {
|
|
|
37
37
|
*/
|
|
38
38
|
this.b = b;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @readonly
|
|
42
|
+
* @type {Signal<number,number,number,number,number,number>}
|
|
43
|
+
*/
|
|
40
44
|
this.onChanged = new Signal();
|
|
41
45
|
}
|
|
42
46
|
|
|
@@ -384,30 +388,39 @@ class Color {
|
|
|
384
388
|
this.setRGB(r, g, b);
|
|
385
389
|
}
|
|
386
390
|
|
|
391
|
+
/**
|
|
392
|
+
*
|
|
393
|
+
* @param {string} str CSS-style string
|
|
394
|
+
* @returns {void}
|
|
395
|
+
*/
|
|
387
396
|
parse(str) {
|
|
388
397
|
const c = parseColor(str);
|
|
389
398
|
|
|
390
399
|
this.setRGB(c[0] / 255, c[1] / 255, c[2] / 255);
|
|
391
400
|
}
|
|
392
|
-
}
|
|
393
401
|
|
|
394
|
-
/**
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
402
|
+
/**
|
|
403
|
+
*
|
|
404
|
+
* @param {number} r
|
|
405
|
+
* @param {number} g
|
|
406
|
+
* @param {number} b
|
|
407
|
+
* @returns {Color}
|
|
408
|
+
*/
|
|
409
|
+
static fromRGB(r, g, b) {
|
|
410
|
+
return new Color(r, g, b);
|
|
411
|
+
}
|
|
404
412
|
|
|
405
|
-
Color.parse = function (str) {
|
|
406
|
-
const r = new Color();
|
|
407
413
|
|
|
408
|
-
|
|
414
|
+
/**
|
|
415
|
+
*
|
|
416
|
+
* @param {string} str
|
|
417
|
+
* @return {Color}
|
|
418
|
+
*/
|
|
419
|
+
static parse(str) {
|
|
420
|
+
const r = new Color();
|
|
409
421
|
|
|
410
|
-
|
|
411
|
-
};
|
|
422
|
+
r.parse(str);
|
|
412
423
|
|
|
413
|
-
|
|
424
|
+
return r;
|
|
425
|
+
};
|
|
426
|
+
}
|
|
@@ -10,7 +10,9 @@ import { ShadedGeometryRendererContext } from "./render/ShadedGeometryRendererCo
|
|
|
10
10
|
import { assert } from "../../../../core/assert.js";
|
|
11
11
|
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
12
12
|
import { ray3_array_apply_matrix4 } from "../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
ExplicitBinaryBoundingVolumeHierarchy
|
|
15
|
+
} from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
14
16
|
import { bvh_query_leaves_generic } from "../../../../core/bvh2/bvh3/bvh_query_leaves_generic.js";
|
|
15
17
|
import { BVHQueryIntersectsRay } from "../../../../core/bvh2/bvh3/query/BVHQueryIntersectsRay.js";
|
|
16
18
|
|
|
@@ -157,6 +159,8 @@ export class ShadedGeometrySystem extends System {
|
|
|
157
159
|
|
|
158
160
|
async startup(entityManager, readyCallback, errorCallback) {
|
|
159
161
|
|
|
162
|
+
this.entityManager = entityManager;
|
|
163
|
+
|
|
160
164
|
const engine = this.__engine;
|
|
161
165
|
const graphics = engine.graphics;
|
|
162
166
|
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export const SGMeshFlags = {
|
|
2
|
+
CastShadow: 1,
|
|
3
|
+
ReceiveShadow: 2
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export class SGMesh {
|
|
7
|
+
constructor() {
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @type {string|null}
|
|
11
|
+
*/
|
|
12
|
+
this.__url = null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @type {EntityNode|null}
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
this.__node = null;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @type {number}
|
|
24
|
+
*/
|
|
25
|
+
this.flags = 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @returns {string|null}
|
|
31
|
+
*/
|
|
32
|
+
get url() {
|
|
33
|
+
return this.__url;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param {string|null} v
|
|
39
|
+
*/
|
|
40
|
+
set url(v) {
|
|
41
|
+
if (v === this.__url) {
|
|
42
|
+
// no change
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.__url = v;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {number|SGMeshFlags} flag
|
|
52
|
+
* @returns {void}
|
|
53
|
+
*/
|
|
54
|
+
setFlag(flag) {
|
|
55
|
+
this.flags |= flag;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param {number|SGMeshFlags} flag
|
|
61
|
+
* @returns {void}
|
|
62
|
+
*/
|
|
63
|
+
clearFlag(flag) {
|
|
64
|
+
this.flags &= ~flag;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param {number|SGMeshFlags} flag
|
|
70
|
+
* @param {boolean} value
|
|
71
|
+
*/
|
|
72
|
+
writeFlag(flag, value) {
|
|
73
|
+
if (value) {
|
|
74
|
+
this.setFlag(flag);
|
|
75
|
+
} else {
|
|
76
|
+
this.clearFlag(flag);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param {number|SGMeshFlags} flag
|
|
83
|
+
* @returns {boolean}
|
|
84
|
+
*/
|
|
85
|
+
getFlag(flag) {
|
|
86
|
+
return (this.flags & flag) === flag;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @return {boolean}
|
|
92
|
+
*/
|
|
93
|
+
get castShadow() {
|
|
94
|
+
return this.getFlag(SGMeshFlags.CastShadow);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param {boolean} v
|
|
100
|
+
*/
|
|
101
|
+
set castShadow(v) {
|
|
102
|
+
this.writeFlag(SGMeshFlags.CastShadow, v);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @return {boolean}
|
|
108
|
+
*/
|
|
109
|
+
get receiveShadow() {
|
|
110
|
+
return this.getFlag(SGMeshFlags.ReceiveShadow);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @param {boolean} v
|
|
116
|
+
*/
|
|
117
|
+
set receiveShadow(v) {
|
|
118
|
+
this.writeFlag(SGMeshFlags.ReceiveShadow, v);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
SGMesh.typeName = "SGMesh";
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { System } from "../../../../ecs/System.js";
|
|
2
|
+
import { SGMesh } from "./SGMesh.js";
|
|
3
|
+
import { Transform } from "../../../../ecs/transform/Transform.js";
|
|
4
|
+
import { assetTypeByPath } from "../../mesh/assetTypeByPath.js";
|
|
5
|
+
import { three_object_to_entity_composition } from "../three_object_to_entity_composition.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @readonly
|
|
10
|
+
* @type {number}
|
|
11
|
+
*/
|
|
12
|
+
const CYCLE_COUNT = 128;
|
|
13
|
+
|
|
14
|
+
export class SGMeshSystem extends System {
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {Engine} engine
|
|
18
|
+
*/
|
|
19
|
+
constructor(engine) {
|
|
20
|
+
super();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @type {Engine}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
this.__engine = engine;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @type {AssetManager}
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
this.__assetManager = engine.assetManager;
|
|
35
|
+
|
|
36
|
+
this.dependencies = [SGMesh, Transform];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @type {number[]}
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
this.__wait_queue = [];
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @type {number}
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
this.__wait_queue_process_index = 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param {number} entity
|
|
55
|
+
* @param {SGMesh} mesh
|
|
56
|
+
* @param {Transform} transform
|
|
57
|
+
*/
|
|
58
|
+
async process(entity, mesh, transform) {
|
|
59
|
+
const am = this.__assetManager;
|
|
60
|
+
|
|
61
|
+
const assetType = assetTypeByPath(component.url);
|
|
62
|
+
|
|
63
|
+
const asset = await am.promise(mesh.url, assetType);
|
|
64
|
+
|
|
65
|
+
// TODO check that entity still exists, as we get to this point asynchronously
|
|
66
|
+
|
|
67
|
+
const entity_node = three_object_to_entity_composition(asset.create());
|
|
68
|
+
|
|
69
|
+
mesh.__node = entity_node;
|
|
70
|
+
|
|
71
|
+
entity_node.build(this.entityManager.dataset);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @param {SGMesh} mesh
|
|
77
|
+
* @param {Transform} transform
|
|
78
|
+
* @param {number} entity
|
|
79
|
+
*/
|
|
80
|
+
link(mesh, transform, entity) {
|
|
81
|
+
if (mesh.url === null) {
|
|
82
|
+
this.__wait_queue.push(entity);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.process(entity, mesh, transform);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param {SGMesh} mesh
|
|
92
|
+
* @param {Transform} transform
|
|
93
|
+
* @param {number} entity
|
|
94
|
+
*/
|
|
95
|
+
unlink(mesh, transform, entity) {
|
|
96
|
+
if (mesh.__node !== null) {
|
|
97
|
+
mesh.__node.destroy();
|
|
98
|
+
|
|
99
|
+
mesh.__node = null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// check the queue
|
|
103
|
+
const i = this.__wait_queue.indexOf(entity);
|
|
104
|
+
|
|
105
|
+
if (i !== -1) {
|
|
106
|
+
this.__wait_queue.splice(i, 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
update(time_delta) {
|
|
111
|
+
|
|
112
|
+
const waiting = this.__wait_queue;
|
|
113
|
+
|
|
114
|
+
let l = waiting.length;
|
|
115
|
+
|
|
116
|
+
if (l > 0) {
|
|
117
|
+
|
|
118
|
+
let pointer = this.__wait_queue_process_index;
|
|
119
|
+
|
|
120
|
+
const dataset = this.entityManager.dataset;
|
|
121
|
+
|
|
122
|
+
for (let i = 0; i < CYCLE_COUNT; i++) {
|
|
123
|
+
|
|
124
|
+
const index = pointer % l;
|
|
125
|
+
|
|
126
|
+
const entity = waiting[index];
|
|
127
|
+
|
|
128
|
+
const mesh = dataset.getComponent(entity, SGMesh);
|
|
129
|
+
|
|
130
|
+
if (mesh.url === null) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const transform = dataset.getComponent(entity, Transform);
|
|
135
|
+
|
|
136
|
+
this.process(entity, mesh, transform);
|
|
137
|
+
|
|
138
|
+
waiting.splice(i, 1);
|
|
139
|
+
|
|
140
|
+
i--;
|
|
141
|
+
l--;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this.__wait_queue_process_index = pointer;
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
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.36.
|
|
8
|
+
"version": "2.36.4",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|