@woosh/meep-engine 2.35.2 → 2.35.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/core/geom/3d/SurfacePoint3.js +6 -6
- package/engine/ecs/EntityManager.d.ts +7 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +11 -1
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +69 -7
- package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +37 -5
- package/engine/graphics/ecs/mesh-v2/render/{AbstractRenderAdapter.js → adapters/AbstractRenderAdapter.js} +13 -1
- package/engine/graphics/ecs/mesh-v2/render/{GenericRendererAdapter.js → adapters/GenericRendererAdapter.js} +8 -3
- package/engine/graphics/ecs/mesh-v2/render/{InstancedRendererAdapter.js → adapters/InstancedRendererAdapter.js} +10 -5
- package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +0 -1
- package/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +150 -0
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +1 -3
- package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -7
- package/engine/graphics/micron/render/v1/MaterialContext.js +1 -2
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +1 -8
- package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +0 -50
- package/package.json +1 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import Quaternion from "../Quaternion.js";
|
|
2
1
|
import Vector3 from "../Vector3.js";
|
|
3
2
|
import { v3_length } from "../v3_length.js";
|
|
4
3
|
|
|
5
|
-
const q = new Quaternion();
|
|
6
|
-
|
|
7
4
|
/**
|
|
8
5
|
* Used for representing points on a 3D surface. Used for raycasting contacts
|
|
9
6
|
*/
|
|
@@ -25,9 +22,12 @@ export class SurfacePoint3 {
|
|
|
25
22
|
const p_y = p.y;
|
|
26
23
|
const p_z = p.z;
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
25
|
+
// compute perspective projection
|
|
26
|
+
const w = 1 / (m4[3] * p_x + m4[7] * p_y + m4[11] * p_z + m4[15]);
|
|
27
|
+
|
|
28
|
+
const result_p_x = (m4[0] * p_x + m4[4] * p_y + m4[8] * p_z + m4[12]) * w;
|
|
29
|
+
const result_p_y = (m4[1] * p_x + m4[5] * p_y + m4[9] * p_z + m4[13]) * w;
|
|
30
|
+
const result_p_z = (m4[2] * p_x + m4[6] * p_y + m4[10] * p_z + m4[14]) * w;
|
|
31
31
|
|
|
32
32
|
this.position.set(
|
|
33
33
|
result_p_x,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import {EntityComponentDataset} from "./EntityComponentDataset";
|
|
2
2
|
import {System} from "./System";
|
|
3
3
|
|
|
4
|
+
interface Type<T> extends Function {
|
|
5
|
+
new(...args: any[]): T;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
|
|
4
9
|
export class EntityManager {
|
|
5
10
|
dataset: EntityComponentDataset
|
|
6
11
|
|
|
@@ -10,6 +15,8 @@ export class EntityManager {
|
|
|
10
15
|
|
|
11
16
|
removeSystem<T>(system: System<T>): Promise<void>
|
|
12
17
|
|
|
18
|
+
getSystem<T>(systemClass: Type<T>): T | null
|
|
19
|
+
|
|
13
20
|
attachDataSet(dataset: EntityComponentDataset): void
|
|
14
21
|
|
|
15
22
|
detachDataSet(): void
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import {System} from "../../../ecs/System";
|
|
2
2
|
import Engine from "../../../Engine";
|
|
3
|
+
import {ShadedGeometry} from "./ShadedGeometry";
|
|
4
|
+
import {SurfacePoint3} from "../../../../core/geom/3d/SurfacePoint3";
|
|
3
5
|
|
|
4
|
-
export class ShadedGeometrySystem extends System {
|
|
6
|
+
export class ShadedGeometrySystem extends System<ShadedGeometry> {
|
|
5
7
|
constructor(engine: Engine)
|
|
8
|
+
|
|
9
|
+
raycastNearest(
|
|
10
|
+
contact: SurfacePoint3,
|
|
11
|
+
origin_x: number, origin_y: number, origin_z: number,
|
|
12
|
+
direction_x: number, direction_y: number, direction_z: number,
|
|
13
|
+
filter_function?: (entity: number, mesh: ShadedGeometry) => boolean,
|
|
14
|
+
filter_function_context?: any
|
|
15
|
+
): { entity: number, mesh: ShadedGeometry } | undefined
|
|
6
16
|
}
|
|
@@ -9,6 +9,7 @@ import { returnTrue } from "../../../../core/function/Functions.js";
|
|
|
9
9
|
import { aabb3_intersects_ray } from "../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
|
|
10
10
|
import { ShadedGeometryRendererContext } from "./render/ShadedGeometryRendererContext.js";
|
|
11
11
|
import { BinaryNode } from "../../../../core/bvh2/BinaryNode.js";
|
|
12
|
+
import { assert } from "../../../../core/assert.js";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
*
|
|
@@ -66,6 +67,58 @@ export class ShadedGeometrySystem extends System {
|
|
|
66
67
|
|
|
67
68
|
this.__bvh = new BinaryNode();
|
|
68
69
|
this.__bvh.setNegativelyInfiniteBounds();
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @type {Map<number, function():AbstractRenderAdapter>}
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
this.__adapter_suppliers = new Map();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param {number} index
|
|
82
|
+
* @param {function():AbstractRenderAdapter} supplier
|
|
83
|
+
*/
|
|
84
|
+
register_render_adapter(index, supplier) {
|
|
85
|
+
assert.isNonNegativeInteger(index, 'index');
|
|
86
|
+
|
|
87
|
+
if (this.__adapter_suppliers.has(index)) {
|
|
88
|
+
// slot is already taken
|
|
89
|
+
console.warn(`Render adapter slot '${index}' is already taken, removing old adapter`);
|
|
90
|
+
this.unregister_render_adapter(index);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.__adapter_suppliers.set(index, supplier);
|
|
94
|
+
|
|
95
|
+
this.__view_contexts.forEach((value, key) => {
|
|
96
|
+
value.setAdapter(index, supplier());
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param {number} index
|
|
103
|
+
* @return {boolean}
|
|
104
|
+
*/
|
|
105
|
+
unregister_render_adapter(index) {
|
|
106
|
+
assert.isNonNegativeInteger(index, 'index');
|
|
107
|
+
|
|
108
|
+
const supplier = this.__adapter_suppliers.get(index);
|
|
109
|
+
|
|
110
|
+
if (supplier === undefined) {
|
|
111
|
+
// not found
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.__adapter_suppliers.delete(index);
|
|
116
|
+
|
|
117
|
+
this.__view_contexts.forEach((value, key) => {
|
|
118
|
+
value.removeAdapter(index);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return true;
|
|
69
122
|
}
|
|
70
123
|
|
|
71
124
|
/**
|
|
@@ -74,7 +127,14 @@ export class ShadedGeometrySystem extends System {
|
|
|
74
127
|
* @private
|
|
75
128
|
*/
|
|
76
129
|
__handle_view_added(view) {
|
|
77
|
-
|
|
130
|
+
const ctx = new ShadedGeometryRendererContext();
|
|
131
|
+
|
|
132
|
+
// attach adapters
|
|
133
|
+
this.__adapter_suppliers.forEach((value, key) => {
|
|
134
|
+
ctx.setAdapter(key, value());
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
this.__view_contexts.set(view, ctx);
|
|
78
138
|
}
|
|
79
139
|
|
|
80
140
|
/**
|
|
@@ -106,7 +166,7 @@ export class ShadedGeometrySystem extends System {
|
|
|
106
166
|
this.__render_layer.buildVisibleSet = ((destination, destination_offset, view) => {
|
|
107
167
|
const ctx = this.__view_contexts.get(view);
|
|
108
168
|
|
|
109
|
-
return ctx.collect(destination, destination_offset, view, this.__bvh);
|
|
169
|
+
return ctx.collect(destination, destination_offset,graphics.renderer, view, this.__bvh);
|
|
110
170
|
});
|
|
111
171
|
|
|
112
172
|
readyCallback();
|
|
@@ -175,7 +235,7 @@ export class ShadedGeometrySystem extends System {
|
|
|
175
235
|
* @param {number} direction_x
|
|
176
236
|
* @param {number} direction_y
|
|
177
237
|
* @param {number} direction_z
|
|
178
|
-
* @param {function(entity:number, mesh:ShadedGeometry)} [filter_function]
|
|
238
|
+
* @param {function(entity:number, mesh:ShadedGeometry):boolean} [filter_function]
|
|
179
239
|
* @param {*} [filter_function_context]
|
|
180
240
|
* @returns {{entity:number, mesh:ShadedGeometry}|undefined}
|
|
181
241
|
*/
|
|
@@ -185,7 +245,7 @@ export class ShadedGeometrySystem extends System {
|
|
|
185
245
|
direction_x, direction_y, direction_z,
|
|
186
246
|
filter_function = returnTrue, filter_function_context
|
|
187
247
|
) {
|
|
188
|
-
const root_bvh = this.
|
|
248
|
+
const root_bvh = this.__bvh;
|
|
189
249
|
const stack_frame_address = traversal_cursor;
|
|
190
250
|
|
|
191
251
|
traversal_stack[traversal_cursor++] = root_bvh;
|
|
@@ -244,9 +304,11 @@ export class ShadedGeometrySystem extends System {
|
|
|
244
304
|
mat4.invert(scratch_m4, m4);
|
|
245
305
|
|
|
246
306
|
// transform ray to local space
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
const
|
|
307
|
+
const inv_w = 1 / (scratch_m4[3] * origin_x + scratch_m4[7] * origin_y + scratch_m4[11] * origin_z + scratch_m4[15]);
|
|
308
|
+
|
|
309
|
+
const local_origin_x = (scratch_m4[0] * origin_x + scratch_m4[4] * origin_y + scratch_m4[8] * origin_z + scratch_m4[12]) * inv_w;
|
|
310
|
+
const local_origin_y = (scratch_m4[1] * origin_x + scratch_m4[5] * origin_y + scratch_m4[9] * origin_z + scratch_m4[13]) * inv_w;
|
|
311
|
+
const local_origin_z = (scratch_m4[2] * origin_x + scratch_m4[6] * origin_y + scratch_m4[10] * origin_z + scratch_m4[14]) * inv_w;
|
|
250
312
|
|
|
251
313
|
const local_direction_x = scratch_m4[0] * direction_x + scratch_m4[4] * direction_y + scratch_m4[8] * direction_z;
|
|
252
314
|
const local_direction_y = scratch_m4[1] * direction_x + scratch_m4[5] * direction_y + scratch_m4[9] * direction_z;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { queryBinaryNode_FrustumIntersections_Data } from "../../../../../core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js";
|
|
2
|
-
import { AbstractRenderAdapter } from "./AbstractRenderAdapter.js";
|
|
3
|
-
import { InstancedRendererAdapter } from "./InstancedRendererAdapter.js";
|
|
4
|
-
import { GenericRendererAdapter } from "./GenericRendererAdapter.js";
|
|
2
|
+
import { AbstractRenderAdapter } from "./adapters/AbstractRenderAdapter.js";
|
|
3
|
+
import { InstancedRendererAdapter } from "./adapters/InstancedRendererAdapter.js";
|
|
4
|
+
import { GenericRendererAdapter } from "./adapters/GenericRendererAdapter.js";
|
|
5
|
+
import { assert } from "../../../../../core/assert.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 1 - collect visible meshes
|
|
@@ -19,7 +20,16 @@ export class ShadedGeometryRendererContext {
|
|
|
19
20
|
];
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {number} index
|
|
26
|
+
* @param {AbstractRenderAdapter} adapter
|
|
27
|
+
*/
|
|
22
28
|
setAdapter(index, adapter) {
|
|
29
|
+
assert.isNonNegativeInteger(index, 'index');
|
|
30
|
+
assert.defined(adapter, 'adapter');
|
|
31
|
+
assert.equal(adapter.isShadedGeometryRenderAdapter, true, 'adapter.isShadedGeometryRenderAdapter !== true');
|
|
32
|
+
|
|
23
33
|
const existing = this.adapters[index];
|
|
24
34
|
if (existing !== undefined) {
|
|
25
35
|
// dispose of existing adapter
|
|
@@ -29,14 +39,36 @@ export class ShadedGeometryRendererContext {
|
|
|
29
39
|
this.adapters[index] = adapter;
|
|
30
40
|
}
|
|
31
41
|
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param {number} index
|
|
45
|
+
* @returns {boolean}
|
|
46
|
+
*/
|
|
47
|
+
removeAdapter(index) {
|
|
48
|
+
assert.isNonNegativeInteger(index, 'index');
|
|
49
|
+
|
|
50
|
+
const adapter = this.adapters[index];
|
|
51
|
+
|
|
52
|
+
if (adapter === undefined) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
delete this.adapters[index];
|
|
57
|
+
|
|
58
|
+
adapter.dispose();
|
|
59
|
+
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
32
63
|
/**
|
|
33
64
|
*
|
|
34
65
|
* @param {THREE.Object3D[]} destination
|
|
35
66
|
* @param {number} destination_offset
|
|
67
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
36
68
|
* @param {CameraView} view
|
|
37
69
|
* @param {BinaryNode<ShadedGeometry>} bvh
|
|
38
70
|
*/
|
|
39
|
-
collect(destination, destination_offset, view, bvh) {
|
|
71
|
+
collect(destination, destination_offset, renderer, view, bvh) {
|
|
40
72
|
const adapters = this.adapters;
|
|
41
73
|
const adapter_count = adapters.length;
|
|
42
74
|
|
|
@@ -44,7 +76,7 @@ export class ShadedGeometryRendererContext {
|
|
|
44
76
|
for (; i < adapter_count; i++) {
|
|
45
77
|
const adapter = adapters[i];
|
|
46
78
|
|
|
47
|
-
adapter.build_start();
|
|
79
|
+
adapter.build_start(renderer, view);
|
|
48
80
|
}
|
|
49
81
|
|
|
50
82
|
|
|
@@ -35,7 +35,13 @@ export class AbstractRenderAdapter {
|
|
|
35
35
|
throw new Error('Not Implemented');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
42
|
+
* @param {CameraView} view
|
|
43
|
+
*/
|
|
44
|
+
build_start(renderer, view) {
|
|
39
45
|
|
|
40
46
|
}
|
|
41
47
|
|
|
@@ -65,3 +71,9 @@ export class AbstractRenderAdapter {
|
|
|
65
71
|
|
|
66
72
|
}
|
|
67
73
|
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @readonly
|
|
77
|
+
* @type {boolean}
|
|
78
|
+
*/
|
|
79
|
+
AbstractRenderAdapter.prototype.isShadedGeometryRenderAdapter = true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractRenderAdapter } from "./AbstractRenderAdapter.js";
|
|
2
|
-
import { array_copy } from "
|
|
3
|
-
import { build_three_object } from "
|
|
2
|
+
import { array_copy } from "../../../../../../core/collection/array/copyArray.js";
|
|
3
|
+
import { build_three_object } from "../../build_three_object.js";
|
|
4
4
|
|
|
5
5
|
export class GenericRendererAdapter extends AbstractRenderAdapter {
|
|
6
6
|
constructor() {
|
|
@@ -19,7 +19,12 @@ export class GenericRendererAdapter extends AbstractRenderAdapter {
|
|
|
19
19
|
return 0;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
25
|
+
* @param {CameraView} view
|
|
26
|
+
*/
|
|
27
|
+
build_start(renderer, view) {
|
|
23
28
|
this.clear();
|
|
24
29
|
}
|
|
25
30
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AbstractRenderAdapter } from "./AbstractRenderAdapter.js";
|
|
2
|
-
import { HashMap } from "
|
|
3
|
-
import { InstancedMeshGroup } from "
|
|
4
|
-
import { ShadedGeometryFlags } from "
|
|
5
|
-
import { DrawMode } from "
|
|
2
|
+
import { HashMap } from "../../../../../../core/collection/HashMap.js";
|
|
3
|
+
import { InstancedMeshGroup } from "../../../../geometry/instancing/InstancedMeshGroup.js";
|
|
4
|
+
import { ShadedGeometryFlags } from "../../ShadedGeometryFlags.js";
|
|
5
|
+
import { DrawMode } from "../../DrawMode.js";
|
|
6
6
|
|
|
7
7
|
const INSTANCED_EQUALITY_FLAGS = ShadedGeometryFlags.CastShadow
|
|
8
8
|
| ShadedGeometryFlags.ReceiveShadow
|
|
@@ -122,7 +122,12 @@ export class InstancedRendererAdapter extends AbstractRenderAdapter {
|
|
|
122
122
|
this.__active_meshes.add(mesh);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
128
|
+
* @param {CameraView} view
|
|
129
|
+
*/
|
|
130
|
+
build_start(renderer, view) {
|
|
126
131
|
this.clear();
|
|
127
132
|
}
|
|
128
133
|
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { AbstractRenderAdapter } from "../../../ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js";
|
|
2
|
+
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
3
|
+
import { MaterialVertexSpec } from "../../render/v1/MaterialVertexSpec.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @type {MaterialVertexSpec}
|
|
8
|
+
*/
|
|
9
|
+
const scratch_mvc = new MaterialVertexSpec();
|
|
10
|
+
|
|
11
|
+
class MicronRenderContext {
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class MicronShadedGeometryRenderAdapter extends AbstractRenderAdapter {
|
|
16
|
+
constructor({
|
|
17
|
+
vgtr
|
|
18
|
+
}) {
|
|
19
|
+
super();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @type {VGThreeRenderer}
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
this.__vgtr = vgtr;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @type {VirtualGeometry|null}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
this.__vg = null;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @type {VirtualGeometryBuilder|null}
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
this.__vgb = null;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @type {Map<number, MicronGeometry>}
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
this.__geometry_map = new Map();
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @type {Set<MaterialContext>}
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
this.__active_contexts = new Set();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
add(sg) {
|
|
57
|
+
|
|
58
|
+
const micron_geometry = this.__geometry_map.get(sg.geometry.id);
|
|
59
|
+
|
|
60
|
+
// populate virtual geometry for this instance
|
|
61
|
+
this.__vgb.buildForMesh(sg.entity, micron_geometry, sg.transform);
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
68
|
+
* @param {CameraView} view
|
|
69
|
+
*/
|
|
70
|
+
build_start(renderer, view) {
|
|
71
|
+
const resolution = new Vector2();
|
|
72
|
+
let pixelRatio = 1;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @type {THREE.RenderTarget}
|
|
77
|
+
*/
|
|
78
|
+
const render_target = renderer.getRenderTarget();
|
|
79
|
+
|
|
80
|
+
if (render_target !== null) {
|
|
81
|
+
resolution.set(render_target.width, render_target.height);
|
|
82
|
+
} else {
|
|
83
|
+
renderer.getSize(resolution);
|
|
84
|
+
pixelRatio = renderer.getPixelRatio();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const vg_builder = this.__vgb;
|
|
88
|
+
|
|
89
|
+
vg_builder.resolution.set(resolution.x * pixelRatio, resolution.y * pixelRatio);
|
|
90
|
+
vg_builder.setMatricesFromCamera(view.camera);
|
|
91
|
+
vg_builder.setOutput(this.__vg);
|
|
92
|
+
|
|
93
|
+
vg_builder.build();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
build_end() {
|
|
97
|
+
const contexts = this.__contexts_array;
|
|
98
|
+
const context_count = contexts.length;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @type {Map<number, MaterialContext>}
|
|
103
|
+
*/
|
|
104
|
+
const instance_to_ctx = new Map();
|
|
105
|
+
|
|
106
|
+
for (let i = 0; i < context_count; i++) {
|
|
107
|
+
const ctx = contexts[i];
|
|
108
|
+
ctx.__patch_count = 0;
|
|
109
|
+
|
|
110
|
+
for (const instance of ctx.instances) {
|
|
111
|
+
instance_to_ctx.set(instance, ctx);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// sort patches into relevant contexts
|
|
116
|
+
const geometry = this.geometry;
|
|
117
|
+
const patch_count = geometry.patch_count;
|
|
118
|
+
const patches = geometry.patches;
|
|
119
|
+
|
|
120
|
+
for (let i = 0; i < patch_count; i++) {
|
|
121
|
+
const i3 = i * 3;
|
|
122
|
+
|
|
123
|
+
const instance_id = patches[i3];
|
|
124
|
+
const geometry_id = patches[i3 + 1];
|
|
125
|
+
const patch_id = patches[i3 + 2];
|
|
126
|
+
|
|
127
|
+
const ctx = instance_to_ctx.get(instance_id);
|
|
128
|
+
|
|
129
|
+
const target_address = ctx.__patch_count * 3;
|
|
130
|
+
ctx.__patch_count++;
|
|
131
|
+
|
|
132
|
+
const ctx_patches = ctx.__patches;
|
|
133
|
+
|
|
134
|
+
ctx_patches[target_address] = instance_id;
|
|
135
|
+
ctx_patches[target_address + 1] = geometry_id;
|
|
136
|
+
ctx_patches[target_address + 2] = patch_id;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// build each context
|
|
140
|
+
for (let i = 0; i < context_count; i++) {
|
|
141
|
+
const ctx = contexts[i];
|
|
142
|
+
|
|
143
|
+
ctx.build(this.geometry);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
dispose() {
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -141,13 +141,11 @@ export class VirtualGeometryBuilder {
|
|
|
141
141
|
* @param {number} instance_id
|
|
142
142
|
* @param {MicronGeometry} geometry
|
|
143
143
|
* @param {number[]} transform world transform matrix of the instance
|
|
144
|
-
* @param {ActivePatchList} apl
|
|
145
144
|
*/
|
|
146
145
|
buildForMesh(
|
|
147
146
|
instance_id,
|
|
148
147
|
geometry,
|
|
149
|
-
transform
|
|
150
|
-
apl
|
|
148
|
+
transform
|
|
151
149
|
) {
|
|
152
150
|
refinement_spec.build(transform, this.view_projection_matrix);
|
|
153
151
|
|
|
@@ -42,13 +42,6 @@ export class ThreeInstancedAdapter {
|
|
|
42
42
|
|
|
43
43
|
this.__uniforms = Object.assign({}, this.__patch_data.genUniforms());
|
|
44
44
|
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @type {WebGL2RenderingContext|null}
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
this.__gl_context = null;
|
|
51
|
-
|
|
52
45
|
/**
|
|
53
46
|
*
|
|
54
47
|
* @type {Signal}
|
|
@@ -19,13 +19,6 @@ export class VGThreeRenderer {
|
|
|
19
19
|
|
|
20
20
|
this.builder = new VirtualGeometryBuilder();
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @type {WebGL2RenderingContext|null}
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
this.__gl_context = null;
|
|
28
|
-
|
|
29
22
|
/**
|
|
30
23
|
*
|
|
31
24
|
* @type {Map<MaterialVertexSpec, MaterialContext>}
|
|
@@ -89,7 +82,7 @@ export class VGThreeRenderer {
|
|
|
89
82
|
|
|
90
83
|
const ctx = new MaterialContext(spec, m);
|
|
91
84
|
|
|
92
|
-
ctx.init(
|
|
85
|
+
ctx.init();
|
|
93
86
|
|
|
94
87
|
this.material_contexts.set(key, ctx);
|
|
95
88
|
this.__contexts_array.push(ctx);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ParticleEmitterFlag } from "../../emitter/ParticleEmitterFlag.js";
|
|
2
2
|
import { PARTICLE_ATTRIBUTE_DEATH_AGE, PARTICLE_ATTRIBUTE_POSITION } from "../../emitter/PARTICLE_ATTRIBUTES.js";
|
|
3
|
-
import { EmissionShapeType } from "../../emitter/EmissionShapeType.js";
|
|
4
3
|
import { Matrix4 } from "three";
|
|
5
4
|
import { composeMatrix4 } from "../../../../../util/composeMatrix4.js";
|
|
6
5
|
import Quaternion from "../../../../../../../core/geom/Quaternion.js";
|
|
@@ -14,55 +13,6 @@ import { SerializationMetadata } from "../../../../../../ecs/components/Serializ
|
|
|
14
13
|
import { UnitCubeShape3D } from "../../../../../../../core/geom/3d/shape/UnitCubeShape3D.js";
|
|
15
14
|
import { shape_from_json } from "../../../../../../../core/geom/3d/shape/json/shape_from_json.js";
|
|
16
15
|
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @param {ParticleLayer} layer
|
|
20
|
-
* @returns {number}
|
|
21
|
-
*/
|
|
22
|
-
function computeLayerVolume(layer) {
|
|
23
|
-
let base_volume = 0;
|
|
24
|
-
|
|
25
|
-
switch (layer.emissionShape) {
|
|
26
|
-
case EmissionShapeType.Box:
|
|
27
|
-
base_volume = 1;
|
|
28
|
-
break;
|
|
29
|
-
case EmissionShapeType.Sphere:
|
|
30
|
-
base_volume = 0.5236;
|
|
31
|
-
break;
|
|
32
|
-
case EmissionShapeType.Point:
|
|
33
|
-
base_volume = 0;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const scale_volume = layer.scale.x * layer.scale.y * layer.scale.z;
|
|
38
|
-
|
|
39
|
-
return base_volume * scale_volume;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @param {ParticleEmitter} emitter
|
|
45
|
-
* @param {Transform} transform
|
|
46
|
-
* @returns {number}
|
|
47
|
-
*/
|
|
48
|
-
function computeEmitterVolume(emitter, transform) {
|
|
49
|
-
|
|
50
|
-
const layers = emitter.layers;
|
|
51
|
-
const n = layers.length;
|
|
52
|
-
|
|
53
|
-
let layer_volume_sum = 0;
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < n; i++) {
|
|
56
|
-
const particleLayer = layers.get(i);
|
|
57
|
-
|
|
58
|
-
layer_volume_sum += computeLayerVolume(particleLayer);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const scale_volume = transform.scale.x * transform.scale.y * transform.scale.z;
|
|
62
|
-
|
|
63
|
-
return layer_volume_sum * scale_volume;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
16
|
const DEFAULT_ATTRIBUTE_VALUES = {
|
|
67
17
|
color: [1, 1, 1, 1],
|
|
68
18
|
age: [0],
|
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.
|
|
8
|
+
"version": "2.35.5",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|