@woosh/meep-engine 2.36.13 → 2.36.16

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.
@@ -11,4 +11,6 @@ export default class Highlight {
11
11
  fromJSON(j: any): void
12
12
 
13
13
  toJSON(): any
14
+
15
+ static fromOne(r: number, g: number, b: number, a?: number): Highlight
14
16
  }
@@ -0,0 +1,7 @@
1
+ import {System} from "../../../../ecs/System";
2
+ import {SGMesh} from "./SGMesh";
3
+ import Highlight from "../../highlight/Highlight";
4
+
5
+ export class SGMeshHighlightSystem extends System<SGMesh, Highlight> {
6
+ constructor()
7
+ }
@@ -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
+ }
@@ -6,6 +6,7 @@ import { three_object_to_entity_composition } from "../three_object_to_entity_co
6
6
  import { ShadedGeometry } from "../ShadedGeometry.js";
7
7
  import { ShadedGeometryFlags } from "../ShadedGeometryFlags.js";
8
8
  import { SGMeshEvents } from "./SGMeshEvents.js";
9
+ import { ParentEntity } from "../../../../ecs/parent/ParentEntity.js";
9
10
 
10
11
 
11
12
  /**
@@ -77,6 +78,9 @@ export class SGMeshSystem extends System {
77
78
 
78
79
  const entity_node = three_object_to_entity_composition(asset.create());
79
80
 
81
+ // attach parent entity to link hierarchy to this entity
82
+ entity_node.entity.add(ParentEntity.from(entity));
83
+
80
84
  mesh.__node = entity_node;
81
85
 
82
86
  entity_node.transform.copy(transform);
@@ -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
- /* .add(BehaviorComponent.fromOne(OrbitingBehavior.from({
51
- center: new Vector3(10, 0, 10),
52
- radius: 5,
53
- rate: 2
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
  /**
@@ -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*fn) / denominator;
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 = depthToLinear(particleDepth);
258
+ float linearParticleDepth = depthToLinear_v2(particleDepth);
253
259
 
254
- float linearSceneDepth = depthToLinear(sceneDepth);
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.5 * pow( clamp(2.0*inputDepth, 0.0, 1.0), 2.0);
275
+ zFade = 2.0 * pow( clamp(inputDepth, 0.0, 1.0), 2.0);
270
276
  }else{
271
- zFade = 1.0 - 0.5 * pow( clamp(2.0*(1.0 - inputDepth), 0.0, 1.0), 2.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 + ${DEPTH_ERROR_MARGIN} > sceneDepth){
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.13",
8
+ "version": "2.36.16",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",