@woosh/meep-engine 2.47.32 → 2.47.34
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 +149 -38
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +149 -38
- package/package.json +1 -1
- package/src/core/cache/Cache.js +12 -0
- package/src/core/collection/HashMap.js +33 -5
- package/src/core/collection/HashMap.spec.js +30 -4
- package/src/core/geom/3d/apply_mat4_transform_to_direction_v3_array.js +49 -0
- package/src/core/geom/3d/apply_mat4_transform_to_v3_array.js +4 -3
- package/src/core/model/node-graph/node/NodeDescription.js +9 -0
- package/src/core/model/node-graph/node/NodeInstance.js +10 -1
- package/src/engine/asset/loaders/material/StaticMaterialCache.js +18 -0
- package/src/engine/graphics/ecs/mesh-v2/render/adapters/InstancedRendererAdapter.js +30 -34
- package/src/engine/graphics/ecs/mesh-v2/render/adapters/SGCacheKey.js +59 -0
|
@@ -3,43 +3,34 @@ import { HashMap } from "../../../../../../core/collection/HashMap.js";
|
|
|
3
3
|
import { InstancedMeshGroup } from "../../../../geometry/instancing/InstancedMeshGroup.js";
|
|
4
4
|
import { ShadedGeometryFlags } from "../../ShadedGeometryFlags.js";
|
|
5
5
|
import { StreamDrawUsage } from "three";
|
|
6
|
+
import { SGCacheKey } from "./SGCacheKey.js";
|
|
6
7
|
|
|
7
8
|
const INSTANCED_EQUALITY_FLAGS = ShadedGeometryFlags.CastShadow
|
|
8
9
|
| ShadedGeometryFlags.ReceiveShadow
|
|
9
10
|
;
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @readonly
|
|
14
|
+
* @type {SGCacheKey}
|
|
15
|
+
*/
|
|
16
|
+
const scratch_key = new SGCacheKey();
|
|
17
|
+
|
|
11
18
|
export class InstancedRendererAdapter extends AbstractRenderAdapter {
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* @type {HashMap<ShadedGeometry, InstancedMeshGroup>}
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
this.__instanced_meshes = new HashMap({
|
|
21
|
-
keyHashFunction(sg) {
|
|
22
|
-
return sg.geometry.id
|
|
23
|
-
^ sg.material.id
|
|
24
|
-
^ sg.mode
|
|
25
|
-
;
|
|
26
|
-
},
|
|
27
|
-
keyEqualityFunction(a, b) {
|
|
28
|
-
return a.material.id === b.material.id
|
|
29
|
-
&& a.geometry.id === b.geometry.id
|
|
30
|
-
&& a.mode === b.mode
|
|
31
|
-
&& (a.flags & INSTANCED_EQUALITY_FLAGS) === (b.flags & INSTANCED_EQUALITY_FLAGS)
|
|
32
|
-
;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
19
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @type {HashMap<SGCacheKey, InstancedMeshGroup>}
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
__instanced_meshes = new HashMap();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @type {Set<InstancedMeshGroup>}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
__active_meshes = new Set();
|
|
33
|
+
|
|
43
34
|
|
|
44
35
|
score(geometry, material, instance_count) {
|
|
45
36
|
if (instance_count > 16) {
|
|
@@ -58,7 +49,12 @@ export class InstancedRendererAdapter extends AbstractRenderAdapter {
|
|
|
58
49
|
* @private
|
|
59
50
|
*/
|
|
60
51
|
__get_instanced_mesh(sg) {
|
|
61
|
-
|
|
52
|
+
scratch_key.fromSG(sg);
|
|
53
|
+
|
|
54
|
+
// mask out some flags
|
|
55
|
+
scratch_key.flags &= INSTANCED_EQUALITY_FLAGS
|
|
56
|
+
|
|
57
|
+
let im = this.__instanced_meshes.get(scratch_key);
|
|
62
58
|
|
|
63
59
|
|
|
64
60
|
if (im !== undefined) {
|
|
@@ -79,7 +75,7 @@ export class InstancedRendererAdapter extends AbstractRenderAdapter {
|
|
|
79
75
|
im.mesh.castShadow = sg.getFlag(ShadedGeometryFlags.CastShadow);
|
|
80
76
|
im.mesh.receiveShadow = sg.getFlag(ShadedGeometryFlags.ReceiveShadow);
|
|
81
77
|
|
|
82
|
-
this.__instanced_meshes.set(
|
|
78
|
+
this.__instanced_meshes.set(scratch_key.clone(), im);
|
|
83
79
|
|
|
84
80
|
return im;
|
|
85
81
|
|
|
@@ -131,8 +127,8 @@ export class InstancedRendererAdapter extends AbstractRenderAdapter {
|
|
|
131
127
|
|
|
132
128
|
const meshes = this.__active_meshes;
|
|
133
129
|
|
|
134
|
-
for (const
|
|
135
|
-
|
|
130
|
+
for (const mesh of meshes) {
|
|
131
|
+
mesh.setCount(0);
|
|
136
132
|
}
|
|
137
133
|
|
|
138
134
|
meshes.clear();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DrawMode } from "../../DrawMode.js";
|
|
2
|
+
|
|
3
|
+
export class SGCacheKey {
|
|
4
|
+
geometry = -1;
|
|
5
|
+
material = -1;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @type {DrawMode}
|
|
9
|
+
*/
|
|
10
|
+
mode = DrawMode.Triangles;
|
|
11
|
+
|
|
12
|
+
flags = 0;
|
|
13
|
+
|
|
14
|
+
hash(){
|
|
15
|
+
return this.geometry ^ this.material;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {SGCacheKey} other
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
equals(other){
|
|
24
|
+
return this.geometry === other.geometry
|
|
25
|
+
&& this.material === other.material
|
|
26
|
+
&& this.mode === other.mode
|
|
27
|
+
&& this.flags === other.flags;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {SGCacheKey} other
|
|
33
|
+
*/
|
|
34
|
+
copy(other){
|
|
35
|
+
this.geometry = other.geometry;
|
|
36
|
+
this.material = other.material;
|
|
37
|
+
this.mode = other.mode;
|
|
38
|
+
this.flags = other.flags;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
clone(){
|
|
42
|
+
const r = new SGCacheKey();
|
|
43
|
+
|
|
44
|
+
r.copy(this);
|
|
45
|
+
|
|
46
|
+
return r;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {ShadedGeometry} sg
|
|
52
|
+
*/
|
|
53
|
+
fromSG(sg){
|
|
54
|
+
this.geometry = sg.geometry.id;
|
|
55
|
+
this.material = sg.material.id;
|
|
56
|
+
this.mode = sg.mode;
|
|
57
|
+
this.flags = sg.flags;
|
|
58
|
+
}
|
|
59
|
+
}
|