@woosh/meep-engine 2.35.9 → 2.35.10

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.
@@ -1,37 +1,10 @@
1
- import { VirtualGeometryBuilder } from "../VirtualGeometryBuilder.js";
2
1
  import Vector2 from "../../../../../core/geom/Vector2.js";
3
- import { VirtualGeometry } from "../../format/VirtualGeometry.js";
4
2
  import { MaterialContext } from "./MaterialContext.js";
5
- import { MaterialVertexSpec } from "./MaterialVertexSpec.js";
6
- import { HashMap } from "../../../../../core/collection/HashMap.js";
7
- import Signal from "../../../../../core/events/signal/Signal.js";
8
3
  import { array_copy } from "../../../../../core/collection/array/copyArray.js";
9
-
10
- /**
11
- *
12
- * @type {MaterialVertexSpec}
13
- */
14
- const scratch_mvc = new MaterialVertexSpec();
4
+ import { MicronRenderContext } from "./MicronRenderContext.js";
15
5
 
16
6
  export class VGThreeRenderer {
17
7
  constructor() {
18
- this.geometry = new VirtualGeometry();
19
-
20
- this.builder = new VirtualGeometryBuilder();
21
-
22
- /**
23
- *
24
- * @type {Map<MaterialVertexSpec, MaterialContext>}
25
- */
26
- this.material_contexts = new HashMap();
27
-
28
- /**
29
- *
30
- * @type {MaterialContext[]}
31
- * @private
32
- */
33
- this.__contexts_array = [];
34
-
35
8
  /**
36
9
  *
37
10
  * @type {Object3D[]}
@@ -39,82 +12,51 @@ export class VGThreeRenderer {
39
12
  */
40
13
  this.__inputs = [];
41
14
 
15
+ this.ctx = new MicronRenderContext();
16
+
42
17
  this.on = {
43
18
  /**
44
19
  * @type {Signal<MaterialContext>}
45
20
  */
46
- contextAdded: new Signal()
21
+ contextAdded: this.ctx.on.contextAdded
47
22
  };
48
23
  }
49
24
 
25
+ get geometry() {
26
+ return this.ctx.geometry;
27
+ }
28
+
50
29
  /**
51
30
  * Enable/disable wireframe rendering
52
31
  * @param {boolean} x
53
32
  */
54
33
  set wireframe(x) {
55
- this.material_contexts.forEach((ctx, mv) => {
56
-
57
-
58
- ctx.compiled_material.wireframe = x;
59
-
60
- });
34
+ this.ctx.wireframe = x;
61
35
  }
62
36
 
63
- /**
64
- *
65
- * @param {VertexDataSpec} spec
66
- * @param {Material} m
67
- * @returns {MaterialContext}
68
- * @private
69
- */
70
- __obtain_material(spec, m) {
71
- scratch_mvc.material = m;
72
- scratch_mvc.spec = spec;
73
-
74
- const existing = this.material_contexts.get(scratch_mvc);
75
-
76
- if (existing !== undefined) {
77
- return existing;
78
- }
79
-
80
- // create a separate instance to be stored alongside the context
81
- const key = scratch_mvc.clone();
82
-
83
- const ctx = new MaterialContext(spec, m);
84
-
85
- ctx.init();
86
-
87
- this.material_contexts.set(key, ctx);
88
- this.__contexts_array.push(ctx);
89
-
90
- this.on.contextAdded.send1(ctx);
91
-
92
- return ctx;
93
- }
94
-
95
-
96
37
  /**
97
38
  *
98
39
  * @param {THREE.Scene} scene
99
40
  */
100
41
  attach(scene) {
101
42
  this.__inputs.push(scene);
102
- this.builder.appendToScene([scene]);
43
+ this.ctx.builder.appendToScene([scene]);
103
44
  }
104
45
 
105
46
  attachMany(objects) {
106
47
  array_copy(objects, 0, this.__inputs, this.__inputs.length, objects.length);
107
- this.builder.appendToScene(objects);
48
+ this.ctx.builder.appendToScene(objects);
108
49
  }
109
50
 
110
51
  clear() {
111
52
  this.__inputs = [];
112
- this.builder.clearScene();
53
+ this.ctx.builder.clearScene();
113
54
  }
114
55
 
115
56
  __prepare_contexts() {
116
57
  // clear contexts
117
- const contexts = this.__contexts_array;
58
+ const render_context = this.ctx;
59
+ const contexts = render_context.__contexts_array;
118
60
  const context_count = contexts.length;
119
61
 
120
62
  for (let i = 0; i < context_count; i++) {
@@ -131,7 +73,7 @@ export class VGThreeRenderer {
131
73
  */
132
74
  const m = o;
133
75
 
134
- const ctx = this.__obtain_material(m.geometry.vertex_spec, m.material);
76
+ const ctx = render_context.obtain_material(m.geometry.vertex_spec, m.material);
135
77
 
136
78
  ctx.instances.add(o.instance_id);
137
79
  }
@@ -149,54 +91,7 @@ export class VGThreeRenderer {
149
91
  }
150
92
 
151
93
  render() {
152
- const contexts = this.__contexts_array;
153
- const context_count = contexts.length;
154
-
155
- /**
156
- *
157
- * @type {Map<number, MaterialContext>}
158
- */
159
- const instance_to_ctx = new Map();
160
-
161
- for (let i = 0; i < context_count; i++) {
162
- const ctx = contexts[i];
163
- ctx.__patch_count = 0;
164
-
165
- for (const instance of ctx.instances) {
166
- instance_to_ctx.set(instance, ctx);
167
- }
168
- }
169
-
170
- // sort patches into relevant contexts
171
- const geometry = this.geometry;
172
- const patch_count = geometry.patch_count;
173
- const patches = geometry.patches;
174
-
175
- for (let i = 0; i < patch_count; i++) {
176
- const i3 = i * 3;
177
-
178
- const instance_id = patches[i3];
179
- const geometry_id = patches[i3 + 1];
180
- const patch_id = patches[i3 + 2];
181
-
182
- const ctx = instance_to_ctx.get(instance_id);
183
-
184
- const target_address = ctx.__patch_count * 3;
185
- ctx.__patch_count++;
186
-
187
- const ctx_patches = ctx.__patches;
188
-
189
- ctx_patches[target_address] = instance_id;
190
- ctx_patches[target_address + 1] = geometry_id;
191
- ctx_patches[target_address + 2] = patch_id;
192
- }
193
-
194
- // build each context
195
- for (let i = 0; i < context_count; i++) {
196
- const ctx = contexts[i];
197
-
198
- ctx.build(this.geometry);
199
- }
94
+ this.ctx.render();
200
95
  }
201
96
 
202
97
 
@@ -224,11 +119,11 @@ export class VGThreeRenderer {
224
119
  pixelRatio = renderer.getPixelRatio();
225
120
  }
226
121
 
227
- const vg_builder = this.builder;
122
+ const vg_builder = this.ctx.builder;
228
123
 
229
124
  vg_builder.resolution.set(resolution.x * pixelRatio, resolution.y * pixelRatio);
230
125
  vg_builder.setMatricesFromCamera(camera);
231
- vg_builder.setOutput(this.geometry);
126
+ vg_builder.setOutput(this.ctx.geometry);
232
127
 
233
128
  vg_builder.build();
234
129
  }
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.35.9",
8
+ "version": "2.35.10",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",