@woosh/meep-engine 2.59.1 → 2.59.3
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/build/meep.cjs +172 -126
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +172 -126
- package/package.json +1 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +2 -2
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.d.ts +3 -0
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js +69 -28
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +21 -15
package/build/meep.module.js
CHANGED
|
@@ -69073,32 +69073,72 @@ const DEFAULT_FLAGS$4 = SGMeshFlags.CastShadow
|
|
|
69073
69073
|
;
|
|
69074
69074
|
|
|
69075
69075
|
class SGMesh {
|
|
69076
|
-
|
|
69077
|
-
|
|
69078
|
-
|
|
69079
|
-
|
|
69080
|
-
|
|
69081
|
-
this.__url = null;
|
|
69076
|
+
/**
|
|
69077
|
+
* Allows settings a new material to all parts of the mesh
|
|
69078
|
+
* @type {Material|null}
|
|
69079
|
+
*/
|
|
69080
|
+
#material_override = null;
|
|
69082
69081
|
|
|
69083
|
-
|
|
69084
|
-
|
|
69085
|
-
|
|
69086
|
-
|
|
69087
|
-
|
|
69088
|
-
this.__node = null;
|
|
69082
|
+
/**
|
|
69083
|
+
*
|
|
69084
|
+
* @type {number}
|
|
69085
|
+
*/
|
|
69086
|
+
flags = DEFAULT_FLAGS$4;
|
|
69089
69087
|
|
|
69090
|
-
|
|
69091
|
-
|
|
69092
|
-
|
|
69093
|
-
|
|
69094
|
-
|
|
69095
|
-
this.__initial_bounds = new AABB3();
|
|
69088
|
+
/**
|
|
69089
|
+
*
|
|
69090
|
+
* @type {string|null}
|
|
69091
|
+
*/
|
|
69092
|
+
__url = null;
|
|
69096
69093
|
|
|
69097
|
-
|
|
69098
|
-
|
|
69099
|
-
|
|
69100
|
-
|
|
69101
|
-
|
|
69094
|
+
/**
|
|
69095
|
+
*
|
|
69096
|
+
* @type {EntityNode|null}
|
|
69097
|
+
* @private
|
|
69098
|
+
*/
|
|
69099
|
+
__node = null;
|
|
69100
|
+
|
|
69101
|
+
/**
|
|
69102
|
+
*
|
|
69103
|
+
* @type {AABB3}
|
|
69104
|
+
* @private
|
|
69105
|
+
*/
|
|
69106
|
+
__initial_bounds = new AABB3();
|
|
69107
|
+
|
|
69108
|
+
/**
|
|
69109
|
+
*
|
|
69110
|
+
* @param {Material} v
|
|
69111
|
+
*/
|
|
69112
|
+
set materialOverride(v) {
|
|
69113
|
+
if (v === this.#material_override) {
|
|
69114
|
+
return;
|
|
69115
|
+
}
|
|
69116
|
+
|
|
69117
|
+
if (v === null) {
|
|
69118
|
+
throw new Error(`Once material override is set it can not be cleared, create a new SGMesh instance if you would like to clear override`);
|
|
69119
|
+
}
|
|
69120
|
+
|
|
69121
|
+
this.#material_override = v;
|
|
69122
|
+
|
|
69123
|
+
this.applyMaterialOverride();
|
|
69124
|
+
}
|
|
69125
|
+
|
|
69126
|
+
get materialOverride() {
|
|
69127
|
+
return this.#material_override;
|
|
69128
|
+
}
|
|
69129
|
+
|
|
69130
|
+
applyMaterialOverride() {
|
|
69131
|
+
if (this.__node === null) {
|
|
69132
|
+
return;
|
|
69133
|
+
}
|
|
69134
|
+
|
|
69135
|
+
this.__node.traverse(node => {
|
|
69136
|
+
const sg = node.entity.getComponent(ShadedGeometry);
|
|
69137
|
+
|
|
69138
|
+
if (sg !== null) {
|
|
69139
|
+
sg.material = this.#material_override;
|
|
69140
|
+
}
|
|
69141
|
+
});
|
|
69102
69142
|
}
|
|
69103
69143
|
|
|
69104
69144
|
/**
|
|
@@ -71980,35 +72020,6 @@ class TerrainSystem extends System {
|
|
|
71980
72020
|
}
|
|
71981
72021
|
}
|
|
71982
72022
|
|
|
71983
|
-
/**
|
|
71984
|
-
*
|
|
71985
|
-
* @param {string} url
|
|
71986
|
-
* @return {String|null}
|
|
71987
|
-
*/
|
|
71988
|
-
function assetTypeByPath(url) {
|
|
71989
|
-
//get extension
|
|
71990
|
-
const dotPosition = url.lastIndexOf(".");
|
|
71991
|
-
if (dotPosition === -1) {
|
|
71992
|
-
console.warn(`No model extension could be deduced for URL: '${url}'`);
|
|
71993
|
-
//no extension
|
|
71994
|
-
return null;
|
|
71995
|
-
} else {
|
|
71996
|
-
//retrieve extension
|
|
71997
|
-
const ext = url.substring(dotPosition + 1);
|
|
71998
|
-
switch (ext) {
|
|
71999
|
-
case "json":
|
|
72000
|
-
return "three.js";
|
|
72001
|
-
case "glb":
|
|
72002
|
-
return "model/gltf";
|
|
72003
|
-
case "gltf":
|
|
72004
|
-
return "model/gltf+json";
|
|
72005
|
-
default:
|
|
72006
|
-
console.warn(`Unknown 3d mesh format extension: '${ext}'`);
|
|
72007
|
-
return null;
|
|
72008
|
-
}
|
|
72009
|
-
}
|
|
72010
|
-
}
|
|
72011
|
-
|
|
72012
72023
|
/**
|
|
72013
72024
|
* Component representing logical attachment to another entity, when parent disappears - so does the child
|
|
72014
72025
|
*/
|
|
@@ -75645,80 +75656,6 @@ class EntityNode {
|
|
|
75645
75656
|
*/
|
|
75646
75657
|
EntityNode.prototype.isEntityNode = true;
|
|
75647
75658
|
|
|
75648
|
-
/**
|
|
75649
|
-
*
|
|
75650
|
-
* @param {Transform} transform
|
|
75651
|
-
* @param {THREE.Object3D} three_object
|
|
75652
|
-
*/
|
|
75653
|
-
function copy_three_transform(transform, three_object) {
|
|
75654
|
-
|
|
75655
|
-
// copy object transform
|
|
75656
|
-
transform.position.copy(three_object.position);
|
|
75657
|
-
transform.scale.copy(three_object.scale);
|
|
75658
|
-
transform.rotation.copy(three_object.quaternion);
|
|
75659
|
-
|
|
75660
|
-
//
|
|
75661
|
-
transform.matrix.set(three_object.matrix.elements);
|
|
75662
|
-
}
|
|
75663
|
-
|
|
75664
|
-
/**
|
|
75665
|
-
*
|
|
75666
|
-
* @param {THREE.Object3D} root
|
|
75667
|
-
* @returns {EntityNode}
|
|
75668
|
-
*/
|
|
75669
|
-
function three_object_to_entity_composition(root) {
|
|
75670
|
-
const node = new EntityNode();
|
|
75671
|
-
|
|
75672
|
-
const node_transform = node.transform;
|
|
75673
|
-
|
|
75674
|
-
// copy object transform
|
|
75675
|
-
copy_three_transform(node_transform, root);
|
|
75676
|
-
|
|
75677
|
-
const entity = node.entity;
|
|
75678
|
-
|
|
75679
|
-
const transform = new Transform();
|
|
75680
|
-
// initialize world transform
|
|
75681
|
-
transform.fromMatrix4(root.matrixWorld.elements);
|
|
75682
|
-
|
|
75683
|
-
entity.add(transform);
|
|
75684
|
-
|
|
75685
|
-
if (root.isMesh) {
|
|
75686
|
-
if (root.isSkinnedMesh) {
|
|
75687
|
-
console.error(`Skinned meshes are not supported`);
|
|
75688
|
-
}
|
|
75689
|
-
|
|
75690
|
-
const sg = ShadedGeometry.from(root.geometry, root.material);
|
|
75691
|
-
|
|
75692
|
-
entity.add(sg);
|
|
75693
|
-
}
|
|
75694
|
-
|
|
75695
|
-
const children = root.children;
|
|
75696
|
-
const child_count = children.length;
|
|
75697
|
-
|
|
75698
|
-
for (let i = 0; i < child_count; i++) {
|
|
75699
|
-
const child = children[i];
|
|
75700
|
-
|
|
75701
|
-
const child_node = three_object_to_entity_composition(child);
|
|
75702
|
-
|
|
75703
|
-
node.addChild(child_node);
|
|
75704
|
-
}
|
|
75705
|
-
|
|
75706
|
-
return node;
|
|
75707
|
-
}
|
|
75708
|
-
|
|
75709
|
-
const SGMeshEvents = {
|
|
75710
|
-
|
|
75711
|
-
/**
|
|
75712
|
-
* When asset is attached/loaded onto the Mesh component.
|
|
75713
|
-
* This is the time when the 3d data becomes renderable
|
|
75714
|
-
*/
|
|
75715
|
-
AssetLoaded: '@ecd-component-SGMesh/asset-attached',
|
|
75716
|
-
/**
|
|
75717
|
-
* Required asset failed to load for whatever reason
|
|
75718
|
-
*/
|
|
75719
|
-
AssetLoadFailed: '@ecd-component-SGMesh/asset-failed',
|
|
75720
|
-
};
|
|
75721
|
-
|
|
75722
75659
|
/**
|
|
75723
75660
|
* @readonly
|
|
75724
75661
|
* @type {number}
|
|
@@ -75941,6 +75878,109 @@ class TransformAttachmentSystem extends System {
|
|
|
75941
75878
|
}
|
|
75942
75879
|
}
|
|
75943
75880
|
|
|
75881
|
+
/**
|
|
75882
|
+
*
|
|
75883
|
+
* @param {string} url
|
|
75884
|
+
* @return {String|null}
|
|
75885
|
+
*/
|
|
75886
|
+
function assetTypeByPath(url) {
|
|
75887
|
+
//get extension
|
|
75888
|
+
const dotPosition = url.lastIndexOf(".");
|
|
75889
|
+
if (dotPosition === -1) {
|
|
75890
|
+
console.warn(`No model extension could be deduced for URL: '${url}'`);
|
|
75891
|
+
//no extension
|
|
75892
|
+
return null;
|
|
75893
|
+
} else {
|
|
75894
|
+
//retrieve extension
|
|
75895
|
+
const ext = url.substring(dotPosition + 1);
|
|
75896
|
+
switch (ext) {
|
|
75897
|
+
case "json":
|
|
75898
|
+
return "three.js";
|
|
75899
|
+
case "glb":
|
|
75900
|
+
return "model/gltf";
|
|
75901
|
+
case "gltf":
|
|
75902
|
+
return "model/gltf+json";
|
|
75903
|
+
default:
|
|
75904
|
+
console.warn(`Unknown 3d mesh format extension: '${ext}'`);
|
|
75905
|
+
return null;
|
|
75906
|
+
}
|
|
75907
|
+
}
|
|
75908
|
+
}
|
|
75909
|
+
|
|
75910
|
+
/**
|
|
75911
|
+
*
|
|
75912
|
+
* @param {Transform} transform
|
|
75913
|
+
* @param {THREE.Object3D} three_object
|
|
75914
|
+
*/
|
|
75915
|
+
function copy_three_transform(transform, three_object) {
|
|
75916
|
+
|
|
75917
|
+
// copy object transform
|
|
75918
|
+
transform.position.copy(three_object.position);
|
|
75919
|
+
transform.scale.copy(three_object.scale);
|
|
75920
|
+
transform.rotation.copy(three_object.quaternion);
|
|
75921
|
+
|
|
75922
|
+
//
|
|
75923
|
+
transform.matrix.set(three_object.matrix.elements);
|
|
75924
|
+
}
|
|
75925
|
+
|
|
75926
|
+
/**
|
|
75927
|
+
*
|
|
75928
|
+
* @param {THREE.Object3D} root
|
|
75929
|
+
* @returns {EntityNode}
|
|
75930
|
+
*/
|
|
75931
|
+
function three_object_to_entity_composition(root) {
|
|
75932
|
+
const node = new EntityNode();
|
|
75933
|
+
|
|
75934
|
+
const node_transform = node.transform;
|
|
75935
|
+
|
|
75936
|
+
// copy object transform
|
|
75937
|
+
copy_three_transform(node_transform, root);
|
|
75938
|
+
|
|
75939
|
+
const entity = node.entity;
|
|
75940
|
+
|
|
75941
|
+
const transform = new Transform();
|
|
75942
|
+
// initialize world transform
|
|
75943
|
+
transform.fromMatrix4(root.matrixWorld.elements);
|
|
75944
|
+
|
|
75945
|
+
entity.add(transform);
|
|
75946
|
+
|
|
75947
|
+
if (root.isMesh) {
|
|
75948
|
+
if (root.isSkinnedMesh) {
|
|
75949
|
+
console.error(`Skinned meshes are not supported`);
|
|
75950
|
+
}
|
|
75951
|
+
|
|
75952
|
+
const sg = ShadedGeometry.from(root.geometry, root.material);
|
|
75953
|
+
|
|
75954
|
+
entity.add(sg);
|
|
75955
|
+
}
|
|
75956
|
+
|
|
75957
|
+
const children = root.children;
|
|
75958
|
+
const child_count = children.length;
|
|
75959
|
+
|
|
75960
|
+
for (let i = 0; i < child_count; i++) {
|
|
75961
|
+
const child = children[i];
|
|
75962
|
+
|
|
75963
|
+
const child_node = three_object_to_entity_composition(child);
|
|
75964
|
+
|
|
75965
|
+
node.addChild(child_node);
|
|
75966
|
+
}
|
|
75967
|
+
|
|
75968
|
+
return node;
|
|
75969
|
+
}
|
|
75970
|
+
|
|
75971
|
+
const SGMeshEvents = {
|
|
75972
|
+
|
|
75973
|
+
/**
|
|
75974
|
+
* When asset is attached/loaded onto the Mesh component.
|
|
75975
|
+
* This is the time when the 3d data becomes renderable
|
|
75976
|
+
*/
|
|
75977
|
+
AssetLoaded: '@ecd-component-SGMesh/asset-attached',
|
|
75978
|
+
/**
|
|
75979
|
+
* Required asset failed to load for whatever reason
|
|
75980
|
+
*/
|
|
75981
|
+
AssetLoadFailed: '@ecd-component-SGMesh/asset-failed',
|
|
75982
|
+
};
|
|
75983
|
+
|
|
75944
75984
|
/**
|
|
75945
75985
|
* @readonly
|
|
75946
75986
|
* @type {number}
|
|
@@ -76105,6 +76145,8 @@ class SGMeshSystem extends System {
|
|
|
76105
76145
|
|
|
76106
76146
|
});
|
|
76107
76147
|
|
|
76148
|
+
const material_override = mesh.materialOverride;
|
|
76149
|
+
|
|
76108
76150
|
// apply flags to the hierarchy
|
|
76109
76151
|
entity_node.traverse(node => {
|
|
76110
76152
|
/**
|
|
@@ -76118,6 +76160,10 @@ class SGMeshSystem extends System {
|
|
|
76118
76160
|
|
|
76119
76161
|
sg.writeFlag(ShadedGeometryFlags.CastShadow, mesh.castShadow);
|
|
76120
76162
|
sg.writeFlag(ShadedGeometryFlags.ReceiveShadow, mesh.receiveShadow);
|
|
76163
|
+
|
|
76164
|
+
if (material_override !== null) {
|
|
76165
|
+
sg.material = material_override;
|
|
76166
|
+
}
|
|
76121
76167
|
});
|
|
76122
76168
|
|
|
76123
76169
|
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@ import {AABB3} from "../../../../core/geom/3d/aabb/AABB3";
|
|
|
3
3
|
import {DrawMode} from "./DrawMode";
|
|
4
4
|
|
|
5
5
|
export class ShadedGeometry {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
geometry: BufferGeometry
|
|
7
|
+
material: Material
|
|
8
8
|
readonly mode: DrawMode
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {Material} from "three";
|
|
1
2
|
import {AABB3} from "../../../../../core/geom/3d/aabb/AABB3";
|
|
2
3
|
|
|
3
4
|
export class SGMesh {
|
|
@@ -6,6 +7,8 @@ export class SGMesh {
|
|
|
6
7
|
castShadow: boolean
|
|
7
8
|
receiveShadow: boolean
|
|
8
9
|
|
|
10
|
+
materialOverride: Material
|
|
11
|
+
|
|
9
12
|
getBoundingBox(out: AABB3): boolean
|
|
10
13
|
|
|
11
14
|
getUntransformedBoundingBox(out: AABB3): void
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {AABB3} from "../../../../../core/geom/3d/aabb/AABB3.js";
|
|
2
|
+
import {entity_node_compute_bounding_box} from "../../../../ecs/parent/entity_node_compute_bounding_box.js";
|
|
3
|
+
import {ShadedGeometry} from "../ShadedGeometry.js";
|
|
3
4
|
|
|
4
5
|
export const SGMeshFlags = {
|
|
5
6
|
CastShadow: 1,
|
|
@@ -16,32 +17,72 @@ const DEFAULT_FLAGS = SGMeshFlags.CastShadow
|
|
|
16
17
|
;
|
|
17
18
|
|
|
18
19
|
export class SGMesh {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Allows settings a new material to all parts of the mesh
|
|
22
|
+
* @type {Material|null}
|
|
23
|
+
*/
|
|
24
|
+
#material_override = null;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @type {number}
|
|
29
|
+
*/
|
|
30
|
+
flags = DEFAULT_FLAGS;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @type {string|null}
|
|
35
|
+
*/
|
|
36
|
+
__url = null;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @type {EntityNode|null}
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
__node = null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @type {AABB3}
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
__initial_bounds = new AABB3();
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param {Material} v
|
|
55
|
+
*/
|
|
56
|
+
set materialOverride(v) {
|
|
57
|
+
if (v === this.#material_override) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (v === null) {
|
|
62
|
+
throw new Error(`Once material override is set it can not be cleared, create a new SGMesh instance if you would like to clear override`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.#material_override = v;
|
|
66
|
+
|
|
67
|
+
this.applyMaterialOverride();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get materialOverride() {
|
|
71
|
+
return this.#material_override;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
applyMaterialOverride() {
|
|
75
|
+
if (this.__node === null) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.__node.traverse(node => {
|
|
80
|
+
const sg = node.entity.getComponent(ShadedGeometry);
|
|
81
|
+
|
|
82
|
+
if (sg !== null) {
|
|
83
|
+
sg.material = this.#material_override;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
45
86
|
}
|
|
46
87
|
|
|
47
88
|
/**
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
1
|
+
import {min2} from "../../../../../core/math/min2.js";
|
|
2
|
+
import {ResourceAccessKind} from "../../../../../core/model/ResourceAccessKind.js";
|
|
3
|
+
import {ResourceAccessSpecification} from "../../../../../core/model/ResourceAccessSpecification.js";
|
|
4
|
+
import {EntityNode} from "../../../../ecs/parent/EntityNode.js";
|
|
5
|
+
import {ParentEntity} from "../../../../ecs/parent/ParentEntity.js";
|
|
6
|
+
import {System} from "../../../../ecs/System.js";
|
|
7
|
+
import {TransformAttachment} from "../../../../ecs/transform-attachment/TransformAttachment.js";
|
|
8
|
+
import {TransformAttachmentSystem} from "../../../../ecs/transform-attachment/TransformAttachmentSystem.js";
|
|
9
|
+
import {Transform} from "../../../../ecs/transform/Transform.js";
|
|
10
|
+
import {assetTypeByPath} from "../../mesh/assetTypeByPath.js";
|
|
11
|
+
import {ShadedGeometry} from "../ShadedGeometry.js";
|
|
12
|
+
import {ShadedGeometryFlags} from "../ShadedGeometryFlags.js";
|
|
13
|
+
import {three_object_to_entity_composition} from "../three_object_to_entity_composition.js";
|
|
14
|
+
import {SGMesh} from "./SGMesh.js";
|
|
15
|
+
import {SGMeshEvents} from "./SGMeshEvents.js";
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -179,6 +179,8 @@ export class SGMeshSystem extends System {
|
|
|
179
179
|
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
+
const material_override = mesh.materialOverride;
|
|
183
|
+
|
|
182
184
|
// apply flags to the hierarchy
|
|
183
185
|
entity_node.traverse(node => {
|
|
184
186
|
/**
|
|
@@ -192,6 +194,10 @@ export class SGMeshSystem extends System {
|
|
|
192
194
|
|
|
193
195
|
sg.writeFlag(ShadedGeometryFlags.CastShadow, mesh.castShadow);
|
|
194
196
|
sg.writeFlag(ShadedGeometryFlags.ReceiveShadow, mesh.receiveShadow);
|
|
197
|
+
|
|
198
|
+
if (material_override !== null) {
|
|
199
|
+
sg.material = material_override;
|
|
200
|
+
}
|
|
195
201
|
});
|
|
196
202
|
|
|
197
203
|
|