@woosh/meep-engine 2.36.14 → 2.36.17
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 +12 -0
- package/engine/graphics/ecs/highlight/Highlight.d.ts +2 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +89 -0
- package/engine/graphics/ecs/mesh-v2/aggregate/SGMeshHighlightSystem.d.ts +7 -0
- package/engine/graphics/ecs/mesh-v2/aggregate/SGMeshHighlightSystem.js +81 -0
- package/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +1 -4
- package/engine/graphics/ecs/mesh-v2/aggregate/prototypeSGMesh.js +12 -6
- package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +17 -11
- package/package.json +1 -1
|
@@ -71,4 +71,16 @@ export class SurfacePoint3 {
|
|
|
71
71
|
this.position.copy(other.position);
|
|
72
72
|
this.normal.copy(other.normal);
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @returns {SurfacePoint3}
|
|
78
|
+
*/
|
|
79
|
+
clone() {
|
|
80
|
+
const r = new SurfacePoint3();
|
|
81
|
+
|
|
82
|
+
r.copy(this);
|
|
83
|
+
|
|
84
|
+
return r;
|
|
85
|
+
}
|
|
74
86
|
}
|
|
@@ -275,6 +275,91 @@ export class ShadedGeometrySystem extends System {
|
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
/**
|
|
279
|
+
*
|
|
280
|
+
* @param {number} origin_x
|
|
281
|
+
* @param {number} origin_y
|
|
282
|
+
* @param {number} origin_z
|
|
283
|
+
* @param {number} direction_x
|
|
284
|
+
* @param {number} direction_y
|
|
285
|
+
* @param {number} direction_z
|
|
286
|
+
* @param {function(entity:number, mesh:ShadedGeometry):boolean} [filter_function]
|
|
287
|
+
* @param {*} [filter_function_context]
|
|
288
|
+
* @returns {{entity:number, mesh:ShadedGeometry, contact: SurfacePoint3}[]}
|
|
289
|
+
*/
|
|
290
|
+
raycast(
|
|
291
|
+
origin_x, origin_y, origin_z,
|
|
292
|
+
direction_x, direction_y, direction_z,
|
|
293
|
+
filter_function = returnTrue, filter_function_context
|
|
294
|
+
) {
|
|
295
|
+
const result = [];
|
|
296
|
+
|
|
297
|
+
const hits = [];
|
|
298
|
+
|
|
299
|
+
const hit_count = bvh_query_leaves_generic(hits, 0, this.__bvh_binary, BVHQueryIntersectsRay.from([origin_x, origin_y, origin_z, direction_x, direction_y, direction_z]));
|
|
300
|
+
|
|
301
|
+
const ecd = this.entityManager.dataset;
|
|
302
|
+
|
|
303
|
+
if (ecd === null) {
|
|
304
|
+
// no ECD set
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const sg_component_index = ecd.computeComponentTypeIndex(ShadedGeometry);
|
|
309
|
+
|
|
310
|
+
for (let i = 0; i < hit_count; i++) {
|
|
311
|
+
const node_id = hits[i];
|
|
312
|
+
|
|
313
|
+
const entity = this.__bvh_binary.node_get_user_data(node_id);
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
*
|
|
317
|
+
* @type {ShadedGeometry}
|
|
318
|
+
*/
|
|
319
|
+
const sg = ecd.getComponentByIndex(entity, sg_component_index);
|
|
320
|
+
|
|
321
|
+
if (!filter_function.call(filter_function_context, entity, sg)) {
|
|
322
|
+
// filtered out
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const m4 = sg.transform;
|
|
327
|
+
|
|
328
|
+
// get transform in local space
|
|
329
|
+
mat4.invert(scratch_m4, m4);
|
|
330
|
+
|
|
331
|
+
ray3_array_compose(
|
|
332
|
+
scratch_ray_0,
|
|
333
|
+
origin_x, origin_y, origin_z,
|
|
334
|
+
direction_x, direction_y, direction_z
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
// transform ray to local space
|
|
338
|
+
ray3_array_apply_matrix4(scratch_ray_0, scratch_ray_0, scratch_m4);
|
|
339
|
+
|
|
340
|
+
const geometry_hit_found = GeometrySpatialQueryAccelerator.INSTANCE.queryRaycastNearest_array(
|
|
341
|
+
scratch_point,
|
|
342
|
+
sg.geometry,
|
|
343
|
+
scratch_ray_0
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
if (!geometry_hit_found) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// transform hit contact into global space
|
|
351
|
+
scratch_point.applyMatrix4(m4);
|
|
352
|
+
|
|
353
|
+
result.push({
|
|
354
|
+
entity,
|
|
355
|
+
mesh: sg,
|
|
356
|
+
contact: scratch_point.clone()
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return result;
|
|
361
|
+
}
|
|
362
|
+
|
|
278
363
|
/**
|
|
279
364
|
*
|
|
280
365
|
* @param {SurfacePoint3} contact
|
|
@@ -327,6 +412,10 @@ export class ShadedGeometrySystem extends System {
|
|
|
327
412
|
continue;
|
|
328
413
|
}
|
|
329
414
|
|
|
415
|
+
/**
|
|
416
|
+
*
|
|
417
|
+
* @type {number[]|mat4|null}
|
|
418
|
+
*/
|
|
330
419
|
const m4 = sg.transform;
|
|
331
420
|
|
|
332
421
|
// get transform in local space
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { System } from "../../../../ecs/System.js";
|
|
2
|
+
import { SGMesh } from "./SGMesh.js";
|
|
3
|
+
import Highlight from "../../highlight/Highlight.js";
|
|
4
|
+
import { SGMeshEvents } from "./SGMeshEvents.js";
|
|
5
|
+
|
|
6
|
+
export class SGMeshHighlightSystem extends System {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.dependencies = [Highlight, SGMesh];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param event
|
|
16
|
+
* @param {number} entity
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
__apply_highlight( event, entity) {
|
|
20
|
+
const ecd = this.entityManager.dataset;
|
|
21
|
+
|
|
22
|
+
const sg_mesh = ecd.getComponent(entity, SGMesh);
|
|
23
|
+
const highlight = ecd.getComponent(entity, Highlight);
|
|
24
|
+
|
|
25
|
+
const node = sg_mesh.__node;
|
|
26
|
+
|
|
27
|
+
node.traverse(t => {
|
|
28
|
+
t.entity.add(highlight);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param event
|
|
35
|
+
* @param {number} entity
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
__remove_highlight( event, entity) {
|
|
39
|
+
|
|
40
|
+
const ecd = this.entityManager.dataset;
|
|
41
|
+
|
|
42
|
+
const sg_mesh = ecd.getComponent(entity, SGMesh);
|
|
43
|
+
|
|
44
|
+
const node = sg_mesh.__node;
|
|
45
|
+
|
|
46
|
+
node.traverse(t => {
|
|
47
|
+
t.entity.removeComponent(Highlight);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {Highlight} highlight
|
|
54
|
+
* @param {SGMesh} mesh
|
|
55
|
+
* @param {number} entity
|
|
56
|
+
*/
|
|
57
|
+
link(highlight, mesh, entity) {
|
|
58
|
+
if (mesh.__node !== null) {
|
|
59
|
+
this.__apply_highlight(undefined, entity);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ecd = this.entityManager.dataset;
|
|
63
|
+
|
|
64
|
+
ecd.addEntityEventListener(entity, SGMeshEvents.AssetLoaded, this.__apply_highlight, this);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param {Highlight} highlight
|
|
70
|
+
* @param {SGMesh} mesh
|
|
71
|
+
* @param {number} entity
|
|
72
|
+
*/
|
|
73
|
+
unlink(highlight, mesh, entity) {
|
|
74
|
+
const ecd = this.entityManager.dataset;
|
|
75
|
+
ecd.removeEntityEventListener(entity, SGMeshEvents.AssetLoaded, this.__apply_highlight, this);
|
|
76
|
+
|
|
77
|
+
if (mesh.__node !== null) {
|
|
78
|
+
this.__remove_highlight(undefined, entity);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -79,10 +79,7 @@ export class SGMeshSystem extends System {
|
|
|
79
79
|
const entity_node = three_object_to_entity_composition(asset.create());
|
|
80
80
|
|
|
81
81
|
// attach parent entity to link hierarchy to this entity
|
|
82
|
-
|
|
83
|
-
parentEntity.entity = entity;
|
|
84
|
-
|
|
85
|
-
entity_node.entity.add(parentEntity)
|
|
82
|
+
entity_node.entity.add(ParentEntity.from(entity));
|
|
86
83
|
|
|
87
84
|
mesh.__node = entity_node;
|
|
88
85
|
|
|
@@ -12,6 +12,9 @@ import { TransformAttachmentSystem } from "../../../../ecs/transform-attachment/
|
|
|
12
12
|
import { SGMeshEvents } from "./SGMeshEvents.js";
|
|
13
13
|
import { ShadedGeometry } from "../ShadedGeometry.js";
|
|
14
14
|
import { MeshSystem } from "../../mesh/MeshSystem.js";
|
|
15
|
+
import { SGMeshHighlightSystem } from "./SGMeshHighlightSystem.js";
|
|
16
|
+
import Highlight from "../../highlight/Highlight.js";
|
|
17
|
+
import { ShadedGeometryHighlightSystem } from "../../highlight/system/ShadedGeometryHighlightSystem.js";
|
|
15
18
|
|
|
16
19
|
new EngineHarness().initialize({
|
|
17
20
|
configuration(config, engine) {
|
|
@@ -20,7 +23,9 @@ new EngineHarness().initialize({
|
|
|
20
23
|
new SGMeshSystem(engine),
|
|
21
24
|
new BehaviorSystem(engine),
|
|
22
25
|
new MeshSystem(engine),
|
|
23
|
-
new TransformAttachmentSystem()
|
|
26
|
+
new TransformAttachmentSystem(),
|
|
27
|
+
new SGMeshHighlightSystem(),
|
|
28
|
+
new ShadedGeometryHighlightSystem(engine)
|
|
24
29
|
);
|
|
25
30
|
|
|
26
31
|
config.addLoader(GameAssetType.ModelGLTF_JSON, new GLTFAssetLoader());
|
|
@@ -46,12 +51,13 @@ function main(engine) {
|
|
|
46
51
|
.add(Transform.fromJSON({
|
|
47
52
|
position: new Vector3(10, 0, 10)
|
|
48
53
|
}))
|
|
54
|
+
.add(Highlight.fromOne(1, 0, 0, 1))
|
|
49
55
|
.add(mesh)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
/* .add(BehaviorComponent.fromOne(OrbitingBehavior.from({
|
|
57
|
+
center: new Vector3(10, 0, 10),
|
|
58
|
+
radius: 5,
|
|
59
|
+
rate: 2
|
|
60
|
+
})))*/
|
|
55
61
|
.addEventListener(SGMeshEvents.AssetLoaded, () => {
|
|
56
62
|
mesh.__node.traverse(n => {
|
|
57
63
|
/**
|
package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js
CHANGED
|
@@ -11,8 +11,6 @@ import {
|
|
|
11
11
|
} from "three";
|
|
12
12
|
import { Vector2 as ThreeVector2 } from "three/src/math/Vector2.js";
|
|
13
13
|
|
|
14
|
-
const DEPTH_ERROR_MARGIN = 0.0001;
|
|
15
|
-
|
|
16
14
|
const CHUNK_LAMBERT_LIGHTING = `
|
|
17
15
|
vec3 diffuse = vec3( 1.0 );
|
|
18
16
|
|
|
@@ -234,24 +232,32 @@ function make_fragment_shader() {
|
|
|
234
232
|
|
|
235
233
|
float d_n = 2.0*z - 1.0;
|
|
236
234
|
|
|
237
|
-
float fn = f*n;
|
|
238
|
-
|
|
239
235
|
float z_diff = f - n;
|
|
240
236
|
|
|
241
237
|
float denominator = (f + n - d_n * z_diff );
|
|
242
|
-
|
|
243
|
-
float z_view = (2.0*
|
|
238
|
+
|
|
239
|
+
float z_view = (2.0*f*n) / denominator;
|
|
244
240
|
|
|
245
241
|
return z_view-n;
|
|
246
242
|
}
|
|
247
243
|
|
|
244
|
+
float depthToLinear_v2(float z){
|
|
245
|
+
float far = cameraFar;
|
|
246
|
+
float near = cameraNear;
|
|
247
|
+
|
|
248
|
+
// perspectiveDepthToViewZ
|
|
249
|
+
float view_z = ( near * far ) / ( ( near-far ) * z + far );
|
|
250
|
+
|
|
251
|
+
return view_z;
|
|
252
|
+
}
|
|
253
|
+
|
|
248
254
|
|
|
249
255
|
float calculateFade(in float particleDepth, in float sceneDepth){
|
|
250
256
|
float zFade;
|
|
251
257
|
|
|
252
|
-
float linearParticleDepth =
|
|
258
|
+
float linearParticleDepth = depthToLinear_v2(particleDepth);
|
|
253
259
|
|
|
254
|
-
float linearSceneDepth =
|
|
260
|
+
float linearSceneDepth = depthToLinear_v2(sceneDepth);
|
|
255
261
|
|
|
256
262
|
float depthDelta = (linearSceneDepth - linearParticleDepth);
|
|
257
263
|
|
|
@@ -266,9 +272,9 @@ function make_fragment_shader() {
|
|
|
266
272
|
}
|
|
267
273
|
|
|
268
274
|
if(inputDepth <= 0.5){
|
|
269
|
-
zFade = 0
|
|
275
|
+
zFade = 2.0 * pow( clamp(inputDepth, 0.0, 1.0), 2.0);
|
|
270
276
|
}else{
|
|
271
|
-
zFade = 1.0 - 0
|
|
277
|
+
zFade = 1.0 - 2.0 * pow( clamp(1.0 - inputDepth, 0.0, 1.0), 2.0);
|
|
272
278
|
}
|
|
273
279
|
|
|
274
280
|
return zFade;
|
|
@@ -335,7 +341,7 @@ function make_fragment_shader() {
|
|
|
335
341
|
|
|
336
342
|
#ifdef DEPTH_READ_ENABLED
|
|
337
343
|
|
|
338
|
-
if(fragmentDepth
|
|
344
|
+
if(fragmentDepth > sceneDepth){
|
|
339
345
|
discard;
|
|
340
346
|
}
|
|
341
347
|
|
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.36.
|
|
8
|
+
"version": "2.36.17",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|