@woosh/meep-engine 2.36.12 → 2.36.15

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.
@@ -510,6 +510,36 @@ BitSet.prototype.getAndClear = function (index) {
510
510
  return v;
511
511
  };
512
512
 
513
+ /**
514
+ *
515
+ * @param {number} distance
516
+ * @param {number} start_index
517
+ * @param {number} end_index
518
+ */
519
+ BitSet.prototype.shift_right = function (distance, start_index, end_index) {
520
+ assert.isNonNegativeInteger(distance, 'distance');
521
+
522
+ for (let i = end_index; i >= start_index; i--) {
523
+ const v = this.get(i);
524
+ this.set(i + distance, v);
525
+ }
526
+ }
527
+
528
+ /**
529
+ *
530
+ * @param {number} distance
531
+ * @param {number} start_index
532
+ * @param {number} end_index
533
+ */
534
+ BitSet.prototype.shift_left = function (distance, start_index, end_index) {
535
+ assert.isNonNegativeInteger(distance, 'distance');
536
+
537
+ for (let i = start_index; i <= end_index; i++) {
538
+ const v = this.get(i);
539
+ this.set(i - distance, v);
540
+ }
541
+ }
542
+
513
543
  /**
514
544
  *
515
545
  * @param {number} distance
@@ -518,15 +548,9 @@ BitSet.prototype.getAndClear = function (index) {
518
548
  */
519
549
  BitSet.prototype.shift = function (distance, start_index, end_index) {
520
550
  if (distance > 0) {
521
- for (let i = end_index; i >= start_index; i--) {
522
- const v = this.get(i);
523
- this.set(i + distance, v);
524
- }
551
+ this.shift_right(distance, start_index, end_index);
525
552
  } else {
526
- for (let i = start_index; i <= end_index; i++) {
527
- const v = this.get(i);
528
- this.set(i + distance, v);
529
- }
553
+ this.shift_right(-distance, start_index, end_index);
530
554
  }
531
555
  };
532
556
 
@@ -452,3 +452,15 @@ test('performance, next clear from 0', () => {
452
452
  const v = s.nextClearBit(0);
453
453
  }
454
454
  });
455
+
456
+
457
+ test('shift right by 1', () => {
458
+ const s = new BitSet();
459
+
460
+ s.set(0, true);
461
+
462
+ s.shift_right(1, 0, 1);
463
+
464
+ expect(s.get(0)).toBe(true);
465
+ expect(s.get(1)).toBe(true);
466
+ });
@@ -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
  /**
@@ -10,7 +10,12 @@ import { ShadedGeometry } from "./ShadedGeometry.js";
10
10
  export function three_object_to_entity_composition(root) {
11
11
  const node = new EntityNode();
12
12
 
13
- node.transform.fromMatrix4(root.matrix.elements);
13
+ const node_transform = node.transform;
14
+
15
+ // copy object transform
16
+ node_transform.position.copy(root.position);
17
+ node_transform.scale.copy(root.scale);
18
+ node_transform.rotation.copy(root.quaternion);
14
19
 
15
20
  const entity = node.entity;
16
21
 
@@ -265,7 +265,7 @@ export class IncrementalDeltaSet {
265
265
  // element is not in the set
266
266
 
267
267
  // shift flags to make space for it
268
- flags.shift(1, index, existing_size);
268
+ flags.shift_right(1, index, existing_size);
269
269
 
270
270
  // insert
271
271
  elements.splice(index, 0, element);
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.12",
8
+ "version": "2.36.15",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",