@woosh/meep-engine 2.42.3 → 2.42.5
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/engine/graphics/material/manager/ManagedMaterial.js +10 -0
- package/engine/graphics/material/manager/MaterialManager.js +28 -5
- package/engine/graphics/micron/render/v1/MaterialContext.js +1 -1
- package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +23 -2
- package/package.json +1 -1
|
@@ -8,6 +8,12 @@ export class ManagedMaterial {
|
|
|
8
8
|
* @param {Material} m
|
|
9
9
|
*/
|
|
10
10
|
constructor(m) {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type {Material|null}
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
this.__source = null;
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
*
|
|
@@ -30,6 +36,10 @@ export class ManagedMaterial {
|
|
|
30
36
|
this.onLastReleased = new Signal();
|
|
31
37
|
}
|
|
32
38
|
|
|
39
|
+
getSource() {
|
|
40
|
+
return this.__source;
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
/**
|
|
34
44
|
*
|
|
35
45
|
* @returns {Material}
|
|
@@ -8,7 +8,7 @@ export class MaterialManager {
|
|
|
8
8
|
constructor() {
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Stores links from uncompiled (source) materials to managed containers
|
|
12
12
|
* @type {HashMap<Material, ManagedMaterial>}
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
@@ -29,6 +29,17 @@ export class MaterialManager {
|
|
|
29
29
|
maxWeight: 100
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Stores links from compiled materials back to the container
|
|
34
|
+
* @type {HashMap<Material, ManagedMaterial>}
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
this.__reverse_library = new HashMap({
|
|
38
|
+
keyHashFunction: computeMaterialHash,
|
|
39
|
+
keyEqualityFunction: computeMaterialEquality,
|
|
40
|
+
capacity: 1024
|
|
41
|
+
});
|
|
42
|
+
|
|
32
43
|
this.__cache.onEvicted.add(this.__dispose_material, this);
|
|
33
44
|
|
|
34
45
|
/**
|
|
@@ -55,13 +66,15 @@ export class MaterialManager {
|
|
|
55
66
|
* @private
|
|
56
67
|
*/
|
|
57
68
|
__handle_last_reference_removed(material) {
|
|
58
|
-
const
|
|
69
|
+
const compiled_material = material.getMaterial();
|
|
59
70
|
|
|
60
71
|
// remove from library
|
|
61
|
-
|
|
72
|
+
const source = material.getSource();
|
|
73
|
+
this.__library.delete(source);
|
|
74
|
+
this.__reverse_library.delete(compiled_material);
|
|
62
75
|
|
|
63
76
|
// put material into cache
|
|
64
|
-
this.__cache.put(
|
|
77
|
+
this.__cache.put(source, material);
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
/**
|
|
@@ -118,7 +131,16 @@ export class MaterialManager {
|
|
|
118
131
|
* @returns {Reference<Material>}
|
|
119
132
|
*/
|
|
120
133
|
obtain(source) {
|
|
121
|
-
|
|
134
|
+
// reverse check to see if this is actually an already compiled/managed material
|
|
135
|
+
let material = this.__reverse_library.get(source);
|
|
136
|
+
|
|
137
|
+
if (material !== undefined) {
|
|
138
|
+
// already compiled material
|
|
139
|
+
return material.getRef();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// forward check
|
|
143
|
+
material = this.__library.get(source);
|
|
122
144
|
|
|
123
145
|
if (material === undefined) {
|
|
124
146
|
// not found in library, check cache
|
|
@@ -138,6 +160,7 @@ export class MaterialManager {
|
|
|
138
160
|
material.onLastReleased.addOne(this.__handle_last_reference_removed, this);
|
|
139
161
|
|
|
140
162
|
this.__library.set(source, material);
|
|
163
|
+
this.__reverse_library.set(material.getMaterial(), material);
|
|
141
164
|
}
|
|
142
165
|
|
|
143
166
|
return material.getRef();
|
|
@@ -69,7 +69,7 @@ export class MaterialContext {
|
|
|
69
69
|
|
|
70
70
|
const rewrite_material = this.adapter.rewriteMaterial.bind(this.adapter);
|
|
71
71
|
|
|
72
|
-
if (material[MATERIAL_FLAG] === undefined) {
|
|
72
|
+
if (this.material[MATERIAL_FLAG] === undefined) {
|
|
73
73
|
material.onBeforeCompile = composeCompile(this.material.onBeforeCompile, rewrite_material);
|
|
74
74
|
material.needsUpdate = true;
|
|
75
75
|
|
|
@@ -6,6 +6,12 @@ import { fp_build_fragment_shader } from "../materials/fp_build_fragment_shader.
|
|
|
6
6
|
import { fp_build_vertex_shader } from "../materials/fp_build_vertex_shader.js";
|
|
7
7
|
import { fp_build_vertex_lighting_shared } from "../materials/fp_build_vertex_lighting_shared.js";
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @readonly
|
|
11
|
+
* @type {string}
|
|
12
|
+
*/
|
|
13
|
+
const PROPERTY_TRANSFORMER_MARKER = '@forward-plus-material-transformer';
|
|
14
|
+
|
|
9
15
|
export class MaterialTransformer extends AbstractMaterialTransformer {
|
|
10
16
|
|
|
11
17
|
/**
|
|
@@ -88,6 +94,17 @@ export class MaterialTransformer extends AbstractMaterialTransformer {
|
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
transform(source) {
|
|
97
|
+
if (source.hasOwnProperty(PROPERTY_TRANSFORMER_MARKER)) {
|
|
98
|
+
// already transformed
|
|
99
|
+
|
|
100
|
+
if (source[PROPERTY_TRANSFORMER_MARKER] !== this) {
|
|
101
|
+
throw new Error('The material is already transformed, but is associated with a different transformer instance');
|
|
102
|
+
} else {
|
|
103
|
+
return source;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
91
108
|
let result = source;
|
|
92
109
|
|
|
93
110
|
if (isLitMaterial(source)) {
|
|
@@ -96,12 +113,16 @@ export class MaterialTransformer extends AbstractMaterialTransformer {
|
|
|
96
113
|
// inherit uniforms directly
|
|
97
114
|
|
|
98
115
|
if (source.isShaderMaterial) {
|
|
99
|
-
|
|
100
|
-
result.
|
|
116
|
+
// TODO use Proxy
|
|
117
|
+
result.uniforms = Object.assign({}, source.uniforms);
|
|
118
|
+
result.defines = Object.assign({}, source.defines);
|
|
101
119
|
}
|
|
102
120
|
|
|
103
121
|
result.onBeforeCompile = composeCompile(source.onBeforeCompile, this.__on_before_compile);
|
|
104
122
|
|
|
123
|
+
|
|
124
|
+
result[PROPERTY_TRANSFORMER_MARKER] = this;
|
|
125
|
+
|
|
105
126
|
}
|
|
106
127
|
|
|
107
128
|
return result;
|
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.42.
|
|
8
|
+
"version": "2.42.5",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|