@gg-web-engine/core 0.0.56 → 0.0.58

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.
Files changed (78) hide show
  1. package/dist/2d/components/physics/i-physics-world-2d.component.d.ts +1 -1
  2. package/dist/2d/components/physics/i-rigid-body-2d.component.d.ts +1 -1
  3. package/dist/2d/components/physics/i-trigger-2d.component.d.ts +3 -3
  4. package/dist/2d/components/rendering/i-display-object-2d.component.d.ts +1 -1
  5. package/dist/2d/components/rendering/i-renderer-2d.component.d.ts +1 -1
  6. package/dist/2d/components/rendering/i-visual-scene-2d.component.d.ts +2 -2
  7. package/dist/2d/entities/controllers/entity-2d-positioning.animator.d.ts +2 -2
  8. package/dist/2d/entities/entity-2d.d.ts +7 -7
  9. package/dist/2d/entities/i-renderable-2d.entity.d.ts +4 -4
  10. package/dist/2d/entities/renderer-2d.entity.d.ts +1 -1
  11. package/dist/2d/entities/trigger-2d.entity.d.ts +8 -4
  12. package/dist/2d/factories.d.ts +7 -7
  13. package/dist/2d/gg-2d-world.d.ts +34 -6
  14. package/dist/2d/gg-2d-world.js +23 -19
  15. package/dist/2d/models/body-options.d.ts +4 -4
  16. package/dist/2d/models/body-options.js +6 -1
  17. package/dist/3d/components/physics/i-physics-world-3d.component.d.ts +5 -5
  18. package/dist/3d/components/physics/i-raycast-vehicle.component.d.ts +1 -1
  19. package/dist/3d/components/physics/i-rigid-body-3d.component.d.ts +1 -1
  20. package/dist/3d/components/physics/i-trigger-3d.component.d.ts +3 -3
  21. package/dist/3d/components/rendering/i-camera.component.d.ts +1 -1
  22. package/dist/3d/components/rendering/i-display-object-3d.component.d.ts +1 -1
  23. package/dist/3d/components/rendering/i-renderer-3d.component.d.ts +2 -2
  24. package/dist/3d/components/rendering/i-visual-scene-3d.component.d.ts +3 -3
  25. package/dist/3d/entities/controllers/animators/camera-3d.animator.d.ts +3 -3
  26. package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.d.ts +2 -2
  27. package/dist/3d/entities/entity-3d.d.ts +6 -6
  28. package/dist/3d/entities/gg-car/gg-car.entity.d.ts +5 -5
  29. package/dist/3d/entities/i-renderable-3d.entity.d.ts +4 -4
  30. package/dist/3d/entities/map-graph-3d.entity.d.ts +6 -6
  31. package/dist/3d/entities/raycast-vehicle-3d.entity.d.ts +3 -3
  32. package/dist/3d/entities/renderer-3d.entity.d.ts +2 -2
  33. package/dist/3d/entities/surface-following.entity.d.ts +96 -0
  34. package/dist/3d/entities/surface-following.entity.js +299 -0
  35. package/dist/3d/entities/trigger-3d.entity.d.ts +8 -4
  36. package/dist/3d/factories.d.ts +14 -14
  37. package/dist/3d/gg-3d-world.d.ts +35 -7
  38. package/dist/3d/gg-3d-world.js +23 -19
  39. package/dist/3d/index.d.ts +1 -0
  40. package/dist/3d/index.js +1 -0
  41. package/dist/3d/loader.d.ts +12 -12
  42. package/dist/3d/loader.js +6 -5
  43. package/dist/3d/loaders.d.ts +4 -4
  44. package/dist/3d/models/body-options.d.ts +4 -4
  45. package/dist/3d/models/body-options.js +6 -1
  46. package/dist/base/components/i-world-component.d.ts +5 -5
  47. package/dist/base/components/physics/i-body.component.d.ts +10 -10
  48. package/dist/base/components/physics/i-physics-world.component.d.ts +56 -10
  49. package/dist/base/components/physics/i-rigid-body.component.d.ts +2 -2
  50. package/dist/base/components/physics/i-trigger.component.d.ts +4 -4
  51. package/dist/base/components/rendering/i-display-object.component.d.ts +6 -6
  52. package/dist/base/components/rendering/i-renderer.component.d.ts +4 -4
  53. package/dist/base/components/rendering/i-visual-scene.component.d.ts +2 -2
  54. package/dist/base/data-structures/bitmask.d.ts +5 -4
  55. package/dist/base/data-structures/bitmask.js +4 -3
  56. package/dist/base/entities/controllers/animation-mixer.d.ts +3 -3
  57. package/dist/base/entities/i-entity.d.ts +8 -8
  58. package/dist/base/entities/i-renderable.entity.d.ts +2 -2
  59. package/dist/base/entities/i-renderer.entity.d.ts +5 -5
  60. package/dist/base/gg-world.d.ts +31 -6
  61. package/dist/base/gg-world.js +27 -14
  62. package/dist/base/index.d.ts +1 -0
  63. package/dist/base/index.js +1 -0
  64. package/dist/base/math/numbers.d.ts +2 -1
  65. package/dist/base/math/numbers.js +7 -1
  66. package/dist/base/math/point2.d.ts +19 -1
  67. package/dist/base/math/point2.js +41 -3
  68. package/dist/base/math/point3.d.ts +4 -0
  69. package/dist/base/math/point3.js +20 -3
  70. package/dist/base/models/body-options.d.ts +27 -9
  71. package/dist/base/models/body-options.js +65 -1
  72. package/dist/base/models/points.d.ts +20 -16
  73. package/dist/base/models/raycasting.d.ts +52 -0
  74. package/dist/base/models/raycasting.js +1 -0
  75. package/dist/dev/gg-debugger.ui.js +5 -13
  76. package/dist/version.d.ts +1 -1
  77. package/dist/version.js +1 -1
  78. package/package.json +1 -1
@@ -1,4 +1,10 @@
1
- export const averageAngle = (angleA, angleB, factor = 0.5) => {
1
+ export const averageAngle = (angleA, angleB) => {
2
+ while (Math.abs(angleA - angleB) > Math.PI) {
3
+ angleB += Math.PI * (angleA > angleB ? 2 : -2);
4
+ }
5
+ return (angleA + angleB) / 2;
6
+ };
7
+ export const lerpAngle = (angleA, angleB, factor) => {
2
8
  while (Math.abs(angleA - angleB) > Math.PI) {
3
9
  angleB += Math.PI * (angleA > angleB ? 2 : -2);
4
10
  }
@@ -1,4 +1,4 @@
1
- import { Point2 } from '../models/points';
1
+ import { Point2, Polar } from '../models/points';
2
2
  export declare class Pnt2 {
3
3
  /** empty vector */
4
4
  static get O(): Point2;
@@ -36,12 +36,30 @@ export declare class Pnt2 {
36
36
  static norm(p: Point2): Point2;
37
37
  /** scalar multiplication */
38
38
  static scalarMult(p: Point2, m: number): Point2;
39
+ /** dot multiplication */
40
+ static dot(a: Point2, b: Point2): number;
39
41
  /** linear interpolation */
40
42
  static lerp(a: Point2, b: Point2, t: number): Point2;
43
+ /** linear interpolation (spherical/polar) */
44
+ static slerp(a: Point2, b: Point2, t: number): Point2;
41
45
  /** angle between vectors in radians */
42
46
  static angle(a: Point2, b: Point2): number;
43
47
  /** rotate point around zero by provided angle */
44
48
  static rot(p: Point2, angle: number): Point2;
45
49
  /** rotate point around pivot by provided angle */
46
50
  static rotAround(p: Point2, pivot: Point2, angle: number): Point2;
51
+ /**
52
+ * Converts a cartesian 2D point to a polar coordinate system,
53
+ * phi == 0 is faced towards X axis direction
54
+ * @param p - The cartesian 2D point.
55
+ * @returns The polar coordinates as an object with radius and phi properties.
56
+ */
57
+ static toPolar(p: Point2): Polar;
58
+ /**
59
+ * Converts a polar coordinate system to a cartesian 2D point. Used polar coordinates,
60
+ * where phi == 0 is faced towards X axis direction
61
+ * @param p - The polar coordinate system.
62
+ * @returns The cartesian 2D point as an object with x and y properties.
63
+ */
64
+ static fromPolar(p: Polar): Point2;
47
65
  }
@@ -1,3 +1,4 @@
1
+ import { lerpAngle } from './numbers';
1
2
  export class Pnt2 {
2
3
  /** empty vector */
3
4
  static get O() {
@@ -78,6 +79,10 @@ export class Pnt2 {
78
79
  y: p.y * m,
79
80
  };
80
81
  }
82
+ /** dot multiplication */
83
+ static dot(a, b) {
84
+ return a.x * b.x + a.y * b.y;
85
+ }
81
86
  /** linear interpolation */
82
87
  static lerp(a, b, t) {
83
88
  return {
@@ -85,11 +90,19 @@ export class Pnt2 {
85
90
  y: a.y + t * (b.y - a.y),
86
91
  };
87
92
  }
93
+ /** linear interpolation (spherical/polar) */
94
+ static slerp(a, b, t) {
95
+ const as = Pnt2.toPolar(a);
96
+ const bs = Pnt2.toPolar(b);
97
+ return Pnt2.fromPolar({
98
+ radius: as.radius + t * (bs.radius - as.radius),
99
+ phi: lerpAngle(as.phi, bs.phi, t),
100
+ });
101
+ }
88
102
  /** angle between vectors in radians */
89
103
  static angle(a, b) {
90
- const dotProduct = a.x * b.x + a.y * b.y;
91
- const magnitudeProduct = Math.sqrt(a.x ** 2 + a.y ** 2) * Math.sqrt(b.x ** 2 + b.y ** 2);
92
- return Math.acos(dotProduct / magnitudeProduct);
104
+ const magnitudeProduct = Pnt2.len(a) * Pnt2.len(b);
105
+ return Math.acos(Pnt2.dot(a, b) / magnitudeProduct);
93
106
  }
94
107
  /** rotate point around zero by provided angle */
95
108
  static rot(p, angle) {
@@ -110,4 +123,29 @@ export class Pnt2 {
110
123
  y: p0.x * sin + p0.y * cos + pivot.y,
111
124
  };
112
125
  }
126
+ /**
127
+ * Converts a cartesian 2D point to a polar coordinate system,
128
+ * phi == 0 is faced towards X axis direction
129
+ * @param p - The cartesian 2D point.
130
+ * @returns The polar coordinates as an object with radius and phi properties.
131
+ */
132
+ static toPolar(p) {
133
+ const radius = Math.sqrt(p.x * p.x + p.y * p.y);
134
+ return {
135
+ radius,
136
+ phi: radius == 0 ? 0 : Math.atan2(p.y, p.x),
137
+ };
138
+ }
139
+ /**
140
+ * Converts a polar coordinate system to a cartesian 2D point. Used polar coordinates,
141
+ * where phi == 0 is faced towards X axis direction
142
+ * @param p - The polar coordinate system.
143
+ * @returns The cartesian 2D point as an object with x and y properties.
144
+ */
145
+ static fromPolar(p) {
146
+ return {
147
+ x: p.radius * Math.cos(p.phi),
148
+ y: p.radius * Math.sin(p.phi),
149
+ };
150
+ }
113
151
  }
@@ -42,8 +42,12 @@ export declare class Pnt3 {
42
42
  static norm(p: Point3): Point3;
43
43
  /** scalar multiplication */
44
44
  static scalarMult(p: Point3, m: number): Point3;
45
+ /** dot multiplication */
46
+ static dot(a: Point3, b: Point3): number;
45
47
  /** linear interpolation */
46
48
  static lerp(a: Point3, b: Point3, t: number): Point3;
49
+ /** linear interpolation (spherical) */
50
+ static slerp(a: Point3, b: Point3, t: number): Point3;
47
51
  /** angle between vectors in radians */
48
52
  static angle(a: Point3, b: Point3): number;
49
53
  /** rotate point a with quaternion q */
@@ -1,4 +1,5 @@
1
1
  import { Qtrn } from './quaternion';
2
+ import { lerpAngle } from './numbers';
2
3
  export class Pnt3 {
3
4
  /** empty vector */
4
5
  static get O() {
@@ -102,6 +103,10 @@ export class Pnt3 {
102
103
  z: p.z * m,
103
104
  };
104
105
  }
106
+ /** dot multiplication */
107
+ static dot(a, b) {
108
+ return a.x * b.x + a.y * b.y + a.z * b.z;
109
+ }
105
110
  /** linear interpolation */
106
111
  static lerp(a, b, t) {
107
112
  return {
@@ -110,11 +115,23 @@ export class Pnt3 {
110
115
  z: a.z + t * (b.z - a.z),
111
116
  };
112
117
  }
118
+ /** linear interpolation (spherical) */
119
+ static slerp(a, b, t) {
120
+ const as = Pnt3.toSpherical(a);
121
+ const bs = Pnt3.toSpherical(b);
122
+ return Pnt3.fromSpherical({
123
+ radius: as.radius + t * (bs.radius - as.radius),
124
+ phi: lerpAngle(as.phi, bs.phi, t),
125
+ theta: lerpAngle(as.theta, bs.theta, t),
126
+ });
127
+ }
113
128
  /** angle between vectors in radians */
114
129
  static angle(a, b) {
115
- const dotProduct = a.x * b.x + a.y * b.y + a.z * b.z;
116
- const magnitudeProduct = Math.sqrt(a.x ** 2 + a.y ** 2 + a.z ** 2) * Math.sqrt(b.x ** 2 + b.y ** 2 + b.z ** 2);
117
- return Math.acos(dotProduct / magnitudeProduct);
130
+ const magnitudeProduct = Pnt3.len(a) * Pnt3.len(b);
131
+ let cos = Pnt3.dot(a, b) / magnitudeProduct;
132
+ // this can happen due to precision error
133
+ cos = Math.min(1, Math.max(cos, -1));
134
+ return Math.acos(cos);
118
135
  }
119
136
  /** rotate point a with quaternion q */
120
137
  static rot(p, q) {
@@ -4,15 +4,33 @@ export interface BodyOptions {
4
4
  mass: number;
5
5
  restitution: number;
6
6
  friction: number;
7
- ownCollisionGroups: CollisionGroup[] | 'all';
8
- interactWithCollisionGroups: CollisionGroup[] | 'all';
7
+ ownCollisionGroups: ReadonlyArray<CollisionGroup> | 'all';
8
+ interactWithCollisionGroups: ReadonlyArray<CollisionGroup> | 'all';
9
9
  }
10
- export type DebugBodySettings = {
11
- shape: any;
12
- ignoreTransform?: boolean;
13
- } & ({
14
- type: 'RIGID_STATIC' | 'TRIGGER';
10
+ export type DebugBodyType = {
11
+ type: 'RIGID_STATIC';
12
+ } | {
13
+ type: 'TRIGGER';
14
+ activated: () => boolean;
15
15
  } | {
16
16
  type: 'RIGID_DYNAMIC';
17
- sleeping: boolean;
18
- });
17
+ sleeping: () => boolean;
18
+ };
19
+ export declare abstract class DebugBodySettings<S> {
20
+ private _type;
21
+ private _shape;
22
+ private _ignoreTransform;
23
+ private _color;
24
+ private _revision;
25
+ get revision(): number;
26
+ get type(): DebugBodyType;
27
+ set type(value: DebugBodyType);
28
+ get shape(): S;
29
+ set shape(value: S);
30
+ get ignoreTransform(): boolean;
31
+ set ignoreTransform(value: boolean);
32
+ private lastRetrievedColorCache;
33
+ get color(): number;
34
+ set color(value: number | undefined);
35
+ protected constructor(_type: DebugBodyType, _shape: S, _ignoreTransform?: boolean, _color?: number | undefined);
36
+ }
@@ -1 +1,65 @@
1
- export {};
1
+ export class DebugBodySettings {
2
+ get revision() {
3
+ // force check of color
4
+ let _ = this.color;
5
+ return this._revision;
6
+ }
7
+ get type() {
8
+ return this._type;
9
+ }
10
+ set type(value) {
11
+ this._type = value;
12
+ this._revision++;
13
+ }
14
+ get shape() {
15
+ return this._shape;
16
+ }
17
+ set shape(value) {
18
+ this._shape = value;
19
+ this._revision++;
20
+ }
21
+ get ignoreTransform() {
22
+ return this._ignoreTransform;
23
+ }
24
+ set ignoreTransform(value) {
25
+ this._ignoreTransform = value;
26
+ this._revision++;
27
+ }
28
+ get color() {
29
+ let color = 0;
30
+ if (this._color !== undefined) {
31
+ color = this._color;
32
+ }
33
+ else {
34
+ switch (this.type.type) {
35
+ case 'RIGID_DYNAMIC':
36
+ color = this.type.sleeping() ? 0x0000ff : 0xff0000;
37
+ break;
38
+ case 'RIGID_STATIC':
39
+ color = 0x00ff00;
40
+ break;
41
+ case 'TRIGGER':
42
+ color = this.type.activated() ? 0xff9900 : 0xffff00;
43
+ break;
44
+ }
45
+ }
46
+ if (color !== this.lastRetrievedColorCache) {
47
+ this._revision++;
48
+ this.lastRetrievedColorCache = color;
49
+ }
50
+ return color;
51
+ }
52
+ set color(value) {
53
+ this._color = value;
54
+ }
55
+ constructor(_type, _shape, _ignoreTransform = false, _color = undefined) {
56
+ this._type = _type;
57
+ this._shape = _shape;
58
+ this._ignoreTransform = _ignoreTransform;
59
+ this._color = _color;
60
+ // this value changes on each change inside the settings.
61
+ // Debug view skips updating anything if value stays the same
62
+ this._revision = 0;
63
+ this.lastRetrievedColorCache = 0;
64
+ }
65
+ }
@@ -1,25 +1,29 @@
1
- export type Point2 = {
2
- readonly x: number;
3
- readonly y: number;
1
+ export type MutablePoint2 = {
2
+ x: number;
3
+ y: number;
4
4
  };
5
- export type Point3 = {
6
- readonly x: number;
7
- readonly y: number;
8
- readonly z: number;
5
+ export type MutablePoint3 = {
6
+ x: number;
7
+ y: number;
8
+ z: number;
9
9
  };
10
- export type Point4 = {
11
- readonly x: number;
12
- readonly y: number;
13
- readonly z: number;
14
- readonly w: number;
10
+ export type MutablePoint4 = {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ w: number;
15
15
  };
16
- export type Spherical = {
17
- readonly radius: number;
18
- readonly phi: number;
19
- readonly theta: number;
16
+ export type MutablePolar = {
17
+ radius: number;
18
+ phi: number;
20
19
  };
21
20
  export type MutableSpherical = {
22
21
  radius: number;
23
22
  phi: number;
24
23
  theta: number;
25
24
  };
25
+ export type Point2 = Readonly<MutablePoint2>;
26
+ export type Point3 = Readonly<MutablePoint3>;
27
+ export type Point4 = Readonly<MutablePoint4>;
28
+ export type Polar = Readonly<MutablePolar>;
29
+ export type Spherical = Readonly<MutableSpherical>;
@@ -0,0 +1,52 @@
1
+ import { CollisionGroup } from './body-options';
2
+ /**
3
+ * Interface representing the result of a raycast operation.
4
+ *
5
+ * @template D - Data type used for representing physics properties (Point3 for 3D, Point2 for 2D).
6
+ * @template B - Type representing the physics engine's body object.
7
+ */
8
+ export interface RaycastResult<D, B> {
9
+ /**
10
+ * Whether the ray hit something.
11
+ */
12
+ hasHit: boolean;
13
+ /**
14
+ * The hit body, if any.
15
+ */
16
+ hitBody?: B;
17
+ /**
18
+ * The hit point in world space, if any.
19
+ */
20
+ hitPoint?: D;
21
+ /**
22
+ * The hit normal in world space, if any.
23
+ */
24
+ hitNormal?: D;
25
+ /**
26
+ * The distance from the ray origin to the hit point, if any.
27
+ */
28
+ hitDistance?: number;
29
+ }
30
+ /**
31
+ * Interface representing options for a raycast operation.
32
+ *
33
+ * @template D - Data type used for representing physics properties (typically Point3 for 3D).
34
+ */
35
+ export interface RaycastOptions<D> {
36
+ /**
37
+ * The starting point of the ray.
38
+ */
39
+ from: D;
40
+ /**
41
+ * The end point of the ray.
42
+ */
43
+ to: D;
44
+ /**
45
+ * Optional collision filter groups for the ray.
46
+ */
47
+ collisionFilterGroups?: CollisionGroup[];
48
+ /**
49
+ * Optional collision filter mask for the ray.
50
+ */
51
+ collisionFilterMask?: CollisionGroup[];
52
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { createInlineTickController, IRendererEntity } from '../base';
1
+ import { createInlineTickController } from '../base';
2
2
  import { animationFrameScheduler, fromEvent, of, Subject, takeUntil } from 'rxjs';
3
3
  import Stats from 'stats.js';
4
4
  import { repeat } from 'rxjs/operators';
@@ -139,19 +139,11 @@ export class GgDebuggerUI {
139
139
  }
140
140
  }
141
141
  makeSnapshot() {
142
- var _a, _b;
143
- const renderers = [];
144
- let performanceMeter = null;
145
- for (const e of ((_a = this.currentWorld) === null || _a === void 0 ? void 0 : _a.children) || []) {
146
- if (e instanceof IRendererEntity) {
147
- renderers.push(e);
148
- }
149
- else if (e instanceof PerformanceMeterEntity) {
150
- performanceMeter = e;
151
- }
152
- }
142
+ var _a, _b, _c;
143
+ const renderers = ((_a = this.currentWorld) === null || _a === void 0 ? void 0 : _a.renderers) || [];
144
+ let performanceMeter = (((_b = this.currentWorld) === null || _b === void 0 ? void 0 : _b.children) || []).find(e => e instanceof PerformanceMeterEntity);
153
145
  return {
154
- timeScale: ((_b = this.currentWorld) === null || _b === void 0 ? void 0 : _b.worldClock.timeScale) || NaN,
146
+ timeScale: ((_c = this.currentWorld) === null || _c === void 0 ? void 0 : _c.worldClock.timeScale) || NaN,
155
147
  renderers: renderers.map(r => ({
156
148
  name: r.name,
157
149
  entity: r,
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.0.56";
1
+ export declare const VERSION = "0.0.58";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.0.56';
1
+ export const VERSION = '0.0.58';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gg-web-engine/core",
3
- "version": "0.0.56",
3
+ "version": "0.0.58",
4
4
  "description": "An attempt to create open source game engine for browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",