@gg-web-engine/core 0.0.1 → 0.0.3
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/dist/2d/entities/controllers/entity-2d-positioning.animator.d.ts +16 -0
- package/dist/2d/entities/controllers/entity-2d-positioning.animator.js +26 -0
- package/dist/2d/entities/gg-2d-entity.d.ts +9 -1
- package/dist/2d/entities/gg-2d-entity.js +50 -17
- package/dist/2d/gg-2d-world.d.ts +3 -0
- package/dist/2d/gg-2d-world.js +11 -0
- package/dist/3d/controllers/car-keyboard.controller.d.ts +10 -10
- package/dist/3d/controllers/car-keyboard.controller.js +21 -20
- package/dist/3d/controllers/free-camera.controller.d.ts +8 -8
- package/dist/3d/entities/controllers/camera-3d.animator.d.ts +17 -0
- package/dist/3d/entities/controllers/camera-3d.animator.js +32 -0
- package/dist/3d/entities/controllers/entity-3d-positioning.animator.d.ts +16 -0
- package/dist/3d/entities/controllers/entity-3d-positioning.animator.js +26 -0
- package/dist/3d/entities/gg-3d-camera.entity.d.ts +2 -0
- package/dist/3d/entities/gg-3d-camera.entity.js +6 -0
- package/dist/3d/entities/gg-3d-entity.d.ts +4 -1
- package/dist/3d/entities/gg-3d-entity.js +19 -10
- package/dist/3d/entities/gg-3d-map-graph.entity.d.ts +7 -5
- package/dist/3d/entities/gg-3d-map-graph.entity.js +1 -1
- package/dist/3d/entities/gg-3d-raycast-vehicle.entity.d.ts +6 -5
- package/dist/3d/gg-3d-world.d.ts +3 -0
- package/dist/3d/gg-3d-world.js +12 -0
- package/dist/base/clock/clock.d.ts +25 -0
- package/dist/base/clock/clock.js +79 -0
- package/dist/base/clock/global-clock.d.ts +15 -0
- package/dist/base/clock/global-clock.js +36 -0
- package/dist/base/entities/controllers/animation-mixer.d.ts +83 -0
- package/dist/base/entities/controllers/animation-mixer.js +152 -0
- package/dist/base/entities/gg-entity.d.ts +4 -1
- package/dist/base/entities/gg-entity.js +7 -0
- package/dist/base/entities/inline-controller.js +0 -1
- package/dist/base/gg-viewport-manager.d.ts +4 -0
- package/dist/base/gg-world.d.ts +3 -1
- package/dist/base/gg-world.js +6 -5
- package/dist/base/math/matrix4.js +3 -3
- package/dist/base/math/point2.js +1 -1
- package/dist/base/math/point3.js +1 -1
- package/dist/base/math/quaternion.d.ts +83 -9
- package/dist/base/math/quaternion.js +93 -10
- package/dist/base/models/points.d.ts +9 -9
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/package.json +1 -1
- package/.prettierrc +0 -8
- package/src/2d/entities/gg-2d-entity.ts +0 -86
- package/src/2d/entities/gg-2d-trigger.entity.ts +0 -17
- package/src/2d/entities/gg-positionable-2d-entity.ts +0 -16
- package/src/2d/factories.ts +0 -20
- package/src/2d/gg-2d-world.ts +0 -32
- package/src/2d/interfaces.ts +0 -31
- package/src/2d/models/body-options.ts +0 -3
- package/src/2d/models/shapes.ts +0 -7
- package/src/3d/controllers/car-keyboard.controller.ts +0 -128
- package/src/3d/controllers/free-camera.controller.ts +0 -86
- package/src/3d/entities/controllers/entity-motion.controller.ts +0 -122
- package/src/3d/entities/gg-3d-camera.entity.ts +0 -8
- package/src/3d/entities/gg-3d-entity.ts +0 -116
- package/src/3d/entities/gg-3d-map-graph.entity.ts +0 -204
- package/src/3d/entities/gg-3d-raycast-vehicle.entity.ts +0 -468
- package/src/3d/entities/gg-3d-trigger.entity.ts +0 -22
- package/src/3d/entities/gg-positionable-3d-entity.ts +0 -31
- package/src/3d/factories.ts +0 -29
- package/src/3d/gg-3d-world.ts +0 -36
- package/src/3d/interfaces.ts +0 -96
- package/src/3d/loader.ts +0 -165
- package/src/3d/models/body-options.ts +0 -3
- package/src/3d/models/gg-meta.ts +0 -12
- package/src/3d/models/shapes.ts +0 -13
- package/src/base/clock.ts +0 -97
- package/src/base/controllers/common.ts +0 -37
- package/src/base/controllers/i-controller.ts +0 -5
- package/src/base/controllers/keyboard.controller.ts +0 -109
- package/src/base/controllers/mouse.controller.ts +0 -73
- package/src/base/data-structures/graph.ts +0 -125
- package/src/base/entities/base-gg-renderer.ts +0 -77
- package/src/base/entities/gg-entity.ts +0 -61
- package/src/base/entities/gg-positionable-entity.ts +0 -64
- package/src/base/entities/inline-controller.ts +0 -31
- package/src/base/entities/interfaces/i-tick-listener.ts +0 -15
- package/src/base/gg-static.ts +0 -30
- package/src/base/gg-viewport-manager.ts +0 -122
- package/src/base/gg-viewport.ts +0 -159
- package/src/base/gg-world.ts +0 -198
- package/src/base/interfaces/gg-body.ts +0 -23
- package/src/base/interfaces/gg-debug-physics-drawer.ts +0 -10
- package/src/base/interfaces/gg-object.ts +0 -26
- package/src/base/interfaces/gg-physics-world.ts +0 -24
- package/src/base/interfaces/gg-trigger.ts +0 -10
- package/src/base/interfaces/gg-visual-scene.ts +0 -11
- package/src/base/math/box.ts +0 -19
- package/src/base/math/matrix4.ts +0 -29
- package/src/base/math/numbers.ts +0 -10
- package/src/base/math/point2.ts +0 -43
- package/src/base/math/point3.ts +0 -119
- package/src/base/math/quaternion.ts +0 -172
- package/src/base/models/axis-directions.ts +0 -3
- package/src/base/models/body-options.ts +0 -6
- package/src/base/models/geometry-nodes.ts +0 -5
- package/src/base/models/points.ts +0 -3
- package/src/base/ui/gg-console.ui.ts +0 -165
- package/src/base/ui/gg-debugger.ui.ts +0 -69
- package/src/index.ts +0 -53
- package/test/base/data-structures/graph.spec.ts +0 -76
|
@@ -1,28 +1,102 @@
|
|
|
1
1
|
import { Point3, Point4 } from '../models/points';
|
|
2
|
+
/**
|
|
3
|
+
* Helper class with static functions, containing util functions, related to Quaternion (represented as Point4 type).
|
|
4
|
+
* In terms of rotation, a quaternion is a mathematical representation of an orientation or rotation in 3D space.
|
|
5
|
+
* It consists of a scalar component and a vector component, and can be written as q = w + xi + yj + zk, where w is the
|
|
6
|
+
* scalar component, and i, j, and k are the vector components. The scalar component, w, represents the amount of
|
|
7
|
+
* rotation, and the vector component, (x, y, z), represents the axis of rotation. The length of the vector component
|
|
8
|
+
* represents the amount of rotation around the axis. Quaternions are often used in 3D computer graphics and animation
|
|
9
|
+
* because they can be used to interpolate between two rotations, and they can avoid some of the issues with using
|
|
10
|
+
* Euler angles (such as gimbal lock).
|
|
11
|
+
*/
|
|
2
12
|
export declare class Qtrn {
|
|
3
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Returns a new quaternion instance with the same values as the given quaternion object.
|
|
15
|
+
* @param q The Point4 object to clone.
|
|
16
|
+
* @returns A new Point4 instance with the same values as the given Point4 object.
|
|
17
|
+
*/
|
|
4
18
|
static clone(q: Point4): Point4;
|
|
5
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Returns the sum of two Point4 objects.
|
|
21
|
+
* @param a The first Point4 object to add.
|
|
22
|
+
* @param b The second Point4 object to add.
|
|
23
|
+
* @returns The sum of the two Point4 objects.
|
|
24
|
+
*/
|
|
6
25
|
static add(a: Point4, b: Point4): Point4;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the result of multiplying two Point4 objects. This can be used for combining rotations
|
|
28
|
+
* @param a The first Point4 object to multiply.
|
|
29
|
+
* @param b The second Point4 object to multiply.
|
|
30
|
+
* @returns The product of the two Point4 objects.
|
|
31
|
+
*/
|
|
7
32
|
static mult(a: Point4, b: Point4): Point4;
|
|
33
|
+
/**
|
|
34
|
+
* Combines an arbitrary number of quaternions by multiplying them together in order.
|
|
35
|
+
* @param quaternions The quaternions to combine.
|
|
36
|
+
* @returns The combined quaternion.
|
|
37
|
+
*/
|
|
8
38
|
static combineRotations(...quaternions: Point4[]): Point4;
|
|
9
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Performs a linear interpolation between two Point4 objects.
|
|
41
|
+
* @param a The first Point4 object.
|
|
42
|
+
* @param b The second Point4 object.
|
|
43
|
+
* @param t The interpolation factor.
|
|
44
|
+
* @returns The interpolated Point4 object.
|
|
45
|
+
*/
|
|
10
46
|
static lerp(a: Point4, b: Point4, t: number): Point4;
|
|
11
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Performs a spherical linear interpolation between two Point4 objects.
|
|
49
|
+
* @param a The first Point4 object.
|
|
50
|
+
* @param b The second Point4 object.
|
|
51
|
+
* @param t The interpolation factor.
|
|
52
|
+
* @returns The interpolated Point4 object.
|
|
53
|
+
*/
|
|
12
54
|
static slerp(a: Point4, b: Point4, t: number): Point4;
|
|
13
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Converts an angle and an axis of rotation into a quaternion
|
|
57
|
+
* @param axis the axis of rotation
|
|
58
|
+
* @param angle the angle of rotation in radians
|
|
59
|
+
* @returns a quaternion representing the rotation
|
|
60
|
+
*/
|
|
14
61
|
static fromAngle(axis: Point3, angle: number): {
|
|
15
62
|
w: number;
|
|
16
63
|
x: number;
|
|
17
64
|
y: number;
|
|
18
65
|
z: number;
|
|
19
66
|
};
|
|
20
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Converts a 4x4 matrix representing a rotation into a quaternion
|
|
69
|
+
* @param m the matrix representing the rotation
|
|
70
|
+
* @returns a quaternion representing the rotation
|
|
71
|
+
*/
|
|
21
72
|
static fromMatrix4(m: number[]): Point4;
|
|
22
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Creates a quaternion from euler
|
|
75
|
+
* @param e the euler vector
|
|
76
|
+
* @returns a quaternion representing the rotation
|
|
77
|
+
*/
|
|
23
78
|
static fromEuler(e: Point3): Point4;
|
|
24
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Converts a quaternion to euler
|
|
81
|
+
* @param q Point4 object
|
|
82
|
+
* @returns an Euler vector, representing the same rotation
|
|
83
|
+
*/
|
|
25
84
|
static toEuler(q: Point4): Point3;
|
|
26
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Returns a quaternion that represents the rotation required to align an object to face towards a target point.
|
|
87
|
+
* @param eye - The position of the camera or object that needs to be rotated to face the target point.
|
|
88
|
+
* @param target - The target point to look at
|
|
89
|
+
* @param up - The up direction of the object
|
|
90
|
+
* @returns A new quaternion representing the rotation required to face towards the target point.
|
|
91
|
+
*/
|
|
27
92
|
static lookAt(eye: Point3, target: Point3, up: Point3): Point4;
|
|
93
|
+
/**
|
|
94
|
+
* Returns a quaternion that represents the input quaternion, rotated around provided axis vector by provided angle.
|
|
95
|
+
* Assumes that axis vector is already normalized
|
|
96
|
+
* @param q - Input quaternion.
|
|
97
|
+
* @param axis - Axis vector
|
|
98
|
+
* @param angle - Angle
|
|
99
|
+
* @returns A new quaternion representing the updated rotation.
|
|
100
|
+
*/
|
|
101
|
+
static rotAround(q: Point4, axis: Point3, angle: number): Point4;
|
|
28
102
|
}
|
|
@@ -3,12 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Qtrn = void 0;
|
|
4
4
|
const point3_1 = require("./point3");
|
|
5
5
|
const matrix4_1 = require("./matrix4");
|
|
6
|
+
/**
|
|
7
|
+
* Helper class with static functions, containing util functions, related to Quaternion (represented as Point4 type).
|
|
8
|
+
* In terms of rotation, a quaternion is a mathematical representation of an orientation or rotation in 3D space.
|
|
9
|
+
* It consists of a scalar component and a vector component, and can be written as q = w + xi + yj + zk, where w is the
|
|
10
|
+
* scalar component, and i, j, and k are the vector components. The scalar component, w, represents the amount of
|
|
11
|
+
* rotation, and the vector component, (x, y, z), represents the axis of rotation. The length of the vector component
|
|
12
|
+
* represents the amount of rotation around the axis. Quaternions are often used in 3D computer graphics and animation
|
|
13
|
+
* because they can be used to interpolate between two rotations, and they can avoid some of the issues with using
|
|
14
|
+
* Euler angles (such as gimbal lock).
|
|
15
|
+
*/
|
|
6
16
|
class Qtrn {
|
|
7
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Returns a new quaternion instance with the same values as the given quaternion object.
|
|
19
|
+
* @param q The Point4 object to clone.
|
|
20
|
+
* @returns A new Point4 instance with the same values as the given Point4 object.
|
|
21
|
+
*/
|
|
8
22
|
static clone(q) {
|
|
9
|
-
return
|
|
23
|
+
return { x: q.x, y: q.y, z: q.z, w: q.w };
|
|
10
24
|
}
|
|
11
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Returns the sum of two Point4 objects.
|
|
27
|
+
* @param a The first Point4 object to add.
|
|
28
|
+
* @param b The second Point4 object to add.
|
|
29
|
+
* @returns The sum of the two Point4 objects.
|
|
30
|
+
*/
|
|
12
31
|
static add(a, b) {
|
|
13
32
|
const w = a.w + b.w;
|
|
14
33
|
const x = a.x + b.x;
|
|
@@ -17,6 +36,12 @@ class Qtrn {
|
|
|
17
36
|
const magnitude = Math.sqrt(w * w + x * x + y * y + z * z);
|
|
18
37
|
return { w: w / magnitude, x: x / magnitude, y: y / magnitude, z: z / magnitude };
|
|
19
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the result of multiplying two Point4 objects. This can be used for combining rotations
|
|
41
|
+
* @param a The first Point4 object to multiply.
|
|
42
|
+
* @param b The second Point4 object to multiply.
|
|
43
|
+
* @returns The product of the two Point4 objects.
|
|
44
|
+
*/
|
|
20
45
|
static mult(a, b) {
|
|
21
46
|
return {
|
|
22
47
|
w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
|
|
@@ -25,6 +50,11 @@ class Qtrn {
|
|
|
25
50
|
z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
|
|
26
51
|
};
|
|
27
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Combines an arbitrary number of quaternions by multiplying them together in order.
|
|
55
|
+
* @param quaternions The quaternions to combine.
|
|
56
|
+
* @returns The combined quaternion.
|
|
57
|
+
*/
|
|
28
58
|
static combineRotations(...quaternions) {
|
|
29
59
|
let result = { w: 1, x: 0, y: 0, z: 0 };
|
|
30
60
|
for (const quat of quaternions) {
|
|
@@ -32,7 +62,13 @@ class Qtrn {
|
|
|
32
62
|
}
|
|
33
63
|
return result;
|
|
34
64
|
}
|
|
35
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Performs a linear interpolation between two Point4 objects.
|
|
67
|
+
* @param a The first Point4 object.
|
|
68
|
+
* @param b The second Point4 object.
|
|
69
|
+
* @param t The interpolation factor.
|
|
70
|
+
* @returns The interpolated Point4 object.
|
|
71
|
+
*/
|
|
36
72
|
static lerp(a, b, t) {
|
|
37
73
|
return {
|
|
38
74
|
x: a.x + t * (b.x - a.x),
|
|
@@ -41,7 +77,13 @@ class Qtrn {
|
|
|
41
77
|
w: a.w + t * (b.w - a.w),
|
|
42
78
|
};
|
|
43
79
|
}
|
|
44
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Performs a spherical linear interpolation between two Point4 objects.
|
|
82
|
+
* @param a The first Point4 object.
|
|
83
|
+
* @param b The second Point4 object.
|
|
84
|
+
* @param t The interpolation factor.
|
|
85
|
+
* @returns The interpolated Point4 object.
|
|
86
|
+
*/
|
|
45
87
|
static slerp(a, b, t) {
|
|
46
88
|
let dot = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
|
47
89
|
let theta = Math.acos(dot);
|
|
@@ -56,13 +98,22 @@ class Qtrn {
|
|
|
56
98
|
}
|
|
57
99
|
return { x, y, z, w };
|
|
58
100
|
}
|
|
59
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Converts an angle and an axis of rotation into a quaternion
|
|
103
|
+
* @param axis the axis of rotation
|
|
104
|
+
* @param angle the angle of rotation in radians
|
|
105
|
+
* @returns a quaternion representing the rotation
|
|
106
|
+
*/
|
|
60
107
|
static fromAngle(axis, angle) {
|
|
61
108
|
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
|
|
62
109
|
const halfAngle = angle / 2, s = Math.sin(halfAngle);
|
|
63
110
|
return Object.assign(Object.assign({}, point3_1.Pnt3.scalarMult(axis, s)), { w: Math.cos(halfAngle) });
|
|
64
111
|
}
|
|
65
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Converts a 4x4 matrix representing a rotation into a quaternion
|
|
114
|
+
* @param m the matrix representing the rotation
|
|
115
|
+
* @returns a quaternion representing the rotation
|
|
116
|
+
*/
|
|
66
117
|
static fromMatrix4(m) {
|
|
67
118
|
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
|
|
68
119
|
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
@@ -104,7 +155,11 @@ class Qtrn {
|
|
|
104
155
|
};
|
|
105
156
|
}
|
|
106
157
|
}
|
|
107
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Creates a quaternion from euler
|
|
160
|
+
* @param e the euler vector
|
|
161
|
+
* @returns a quaternion representing the rotation
|
|
162
|
+
*/
|
|
108
163
|
static fromEuler(e) {
|
|
109
164
|
const roll = e.x;
|
|
110
165
|
const pitch = e.y;
|
|
@@ -121,7 +176,11 @@ class Qtrn {
|
|
|
121
176
|
const qz = cr * cp * sy - sr * sp * cy;
|
|
122
177
|
return { w: qw, x: qx, y: qy, z: qz };
|
|
123
178
|
}
|
|
124
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Converts a quaternion to euler
|
|
181
|
+
* @param q Point4 object
|
|
182
|
+
* @returns an Euler vector, representing the same rotation
|
|
183
|
+
*/
|
|
125
184
|
static toEuler(q) {
|
|
126
185
|
const qw = q.w;
|
|
127
186
|
const qx = q.x;
|
|
@@ -137,9 +196,33 @@ class Qtrn {
|
|
|
137
196
|
const yaw = Math.atan2(siny_cosp, cosy_cosp);
|
|
138
197
|
return { x: roll, y: pitch, z: yaw };
|
|
139
198
|
}
|
|
140
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Returns a quaternion that represents the rotation required to align an object to face towards a target point.
|
|
201
|
+
* @param eye - The position of the camera or object that needs to be rotated to face the target point.
|
|
202
|
+
* @param target - The target point to look at
|
|
203
|
+
* @param up - The up direction of the object
|
|
204
|
+
* @returns A new quaternion representing the rotation required to face towards the target point.
|
|
205
|
+
*/
|
|
141
206
|
static lookAt(eye, target, up) {
|
|
142
207
|
return this.fromMatrix4(matrix4_1.Mtrx4.lookAt(eye, target, up));
|
|
143
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Returns a quaternion that represents the input quaternion, rotated around provided axis vector by provided angle.
|
|
211
|
+
* Assumes that axis vector is already normalized
|
|
212
|
+
* @param q - Input quaternion.
|
|
213
|
+
* @param axis - Axis vector
|
|
214
|
+
* @param angle - Angle
|
|
215
|
+
* @returns A new quaternion representing the updated rotation.
|
|
216
|
+
*/
|
|
217
|
+
static rotAround(q, axis, angle) {
|
|
218
|
+
const sinHalfAngle = Math.sin(angle / 2);
|
|
219
|
+
const rotationQuat = {
|
|
220
|
+
w: Math.cos(angle / 2),
|
|
221
|
+
x: axis.x * sinHalfAngle,
|
|
222
|
+
y: axis.y * sinHalfAngle,
|
|
223
|
+
z: axis.z * sinHalfAngle,
|
|
224
|
+
};
|
|
225
|
+
return this.mult(rotationQuat, q);
|
|
226
|
+
}
|
|
144
227
|
}
|
|
145
228
|
exports.Qtrn = Qtrn;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export declare type Point2 = {
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
2
|
+
readonly x: number;
|
|
3
|
+
readonly y: number;
|
|
4
4
|
};
|
|
5
5
|
export declare type Point3 = {
|
|
6
|
-
x: number;
|
|
7
|
-
y: number;
|
|
8
|
-
z: number;
|
|
6
|
+
readonly x: number;
|
|
7
|
+
readonly y: number;
|
|
8
|
+
readonly z: number;
|
|
9
9
|
};
|
|
10
10
|
export declare type Point4 = {
|
|
11
|
-
x: number;
|
|
12
|
-
y: number;
|
|
13
|
-
z: number;
|
|
14
|
-
w: number;
|
|
11
|
+
readonly x: number;
|
|
12
|
+
readonly y: number;
|
|
13
|
+
readonly z: number;
|
|
14
|
+
readonly w: number;
|
|
15
15
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export * from './base/clock';
|
|
1
|
+
export * from './base/clock/clock';
|
|
2
|
+
export * from './base/clock/global-clock';
|
|
2
3
|
export * from './base/gg-viewport';
|
|
3
4
|
export * from './base/gg-viewport-manager';
|
|
5
|
+
export * from './base/entities/controllers/animation-mixer';
|
|
4
6
|
export * from './base/entities/interfaces/i-tick-listener';
|
|
5
7
|
export * from './base/entities/gg-entity';
|
|
6
8
|
export * from './base/entities/base-gg-renderer';
|
|
@@ -25,6 +27,7 @@ export * from './base/controllers/common';
|
|
|
25
27
|
export * from './base/controllers/i-controller';
|
|
26
28
|
export * from './base/controllers/keyboard.controller';
|
|
27
29
|
export * from './base/controllers/mouse.controller';
|
|
30
|
+
export * from './2d/entities/controllers/entity-2d-positioning.animator';
|
|
28
31
|
export * from './2d/entities/gg-2d-entity';
|
|
29
32
|
export * from './2d/entities/gg-positionable-2d-entity';
|
|
30
33
|
export * from './2d/entities/gg-2d-trigger.entity';
|
|
@@ -35,7 +38,8 @@ export * from './2d/factories';
|
|
|
35
38
|
export * from './2d/gg-2d-world';
|
|
36
39
|
export * from './3d/controllers/car-keyboard.controller';
|
|
37
40
|
export * from './3d/controllers/free-camera.controller';
|
|
38
|
-
export * from './3d/entities/controllers/
|
|
41
|
+
export * from './3d/entities/controllers/camera-3d.animator';
|
|
42
|
+
export * from './3d/entities/controllers/entity-3d-positioning.animator';
|
|
39
43
|
export * from './3d/entities/gg-3d-entity';
|
|
40
44
|
export * from './3d/entities/gg-positionable-3d-entity';
|
|
41
45
|
export * from './3d/entities/gg-3d-camera.entity';
|
package/dist/index.js
CHANGED
|
@@ -14,9 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./base/clock"), exports);
|
|
17
|
+
__exportStar(require("./base/clock/clock"), exports);
|
|
18
|
+
__exportStar(require("./base/clock/global-clock"), exports);
|
|
18
19
|
__exportStar(require("./base/gg-viewport"), exports);
|
|
19
20
|
__exportStar(require("./base/gg-viewport-manager"), exports);
|
|
21
|
+
__exportStar(require("./base/entities/controllers/animation-mixer"), exports);
|
|
20
22
|
__exportStar(require("./base/entities/interfaces/i-tick-listener"), exports);
|
|
21
23
|
__exportStar(require("./base/entities/gg-entity"), exports);
|
|
22
24
|
__exportStar(require("./base/entities/base-gg-renderer"), exports);
|
|
@@ -41,6 +43,7 @@ __exportStar(require("./base/controllers/common"), exports);
|
|
|
41
43
|
__exportStar(require("./base/controllers/i-controller"), exports);
|
|
42
44
|
__exportStar(require("./base/controllers/keyboard.controller"), exports);
|
|
43
45
|
__exportStar(require("./base/controllers/mouse.controller"), exports);
|
|
46
|
+
__exportStar(require("./2d/entities/controllers/entity-2d-positioning.animator"), exports);
|
|
44
47
|
__exportStar(require("./2d/entities/gg-2d-entity"), exports);
|
|
45
48
|
__exportStar(require("./2d/entities/gg-positionable-2d-entity"), exports);
|
|
46
49
|
__exportStar(require("./2d/entities/gg-2d-trigger.entity"), exports);
|
|
@@ -51,7 +54,8 @@ __exportStar(require("./2d/factories"), exports);
|
|
|
51
54
|
__exportStar(require("./2d/gg-2d-world"), exports);
|
|
52
55
|
__exportStar(require("./3d/controllers/car-keyboard.controller"), exports);
|
|
53
56
|
__exportStar(require("./3d/controllers/free-camera.controller"), exports);
|
|
54
|
-
__exportStar(require("./3d/entities/controllers/
|
|
57
|
+
__exportStar(require("./3d/entities/controllers/camera-3d.animator"), exports);
|
|
58
|
+
__exportStar(require("./3d/entities/controllers/entity-3d-positioning.animator"), exports);
|
|
55
59
|
__exportStar(require("./3d/entities/gg-3d-entity"), exports);
|
|
56
60
|
__exportStar(require("./3d/entities/gg-positionable-3d-entity"), exports);
|
|
57
61
|
__exportStar(require("./3d/entities/gg-3d-camera.entity"), exports);
|
package/package.json
CHANGED
package/.prettierrc
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Subject, Subscription } from 'rxjs';
|
|
2
|
-
import { GgPositionable2dEntity } from './gg-positionable-2d-entity';
|
|
3
|
-
import { ITickListener } from '../../base/entities/interfaces/i-tick-listener';
|
|
4
|
-
import { Point2 } from '../../base/models/points';
|
|
5
|
-
import { IGg2dBody, IGg2dObject } from '../interfaces';
|
|
6
|
-
import { Gg2dWorld } from '../gg-2d-world';
|
|
7
|
-
|
|
8
|
-
export class Gg2dEntity extends GgPositionable2dEntity implements ITickListener {
|
|
9
|
-
public readonly tick$: Subject<[number, number]> = new Subject<[number, number]>();
|
|
10
|
-
public readonly tickOrder = 750;
|
|
11
|
-
private tickSub: Subscription | null = null;
|
|
12
|
-
|
|
13
|
-
set position(value: Point2) {
|
|
14
|
-
if (this.object2D) {
|
|
15
|
-
this.object2D.position = value;
|
|
16
|
-
}
|
|
17
|
-
if (this.objectBody) {
|
|
18
|
-
this.objectBody.position = value;
|
|
19
|
-
}
|
|
20
|
-
super.position = value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
set rotation(value: number) {
|
|
24
|
-
if (this.object2D) {
|
|
25
|
-
this.object2D.rotation = value;
|
|
26
|
-
}
|
|
27
|
-
if (this.objectBody) {
|
|
28
|
-
this.objectBody.rotation = value;
|
|
29
|
-
}
|
|
30
|
-
super.rotation = value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
set scale(value: Point2) {
|
|
34
|
-
if (this.object2D) {
|
|
35
|
-
this.object2D.scale = value;
|
|
36
|
-
}
|
|
37
|
-
if (this.objectBody) {
|
|
38
|
-
this.objectBody.scale = value;
|
|
39
|
-
}
|
|
40
|
-
super.scale = value;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
constructor(public readonly object2D: IGg2dObject | null, public readonly objectBody: IGg2dBody | null) {
|
|
44
|
-
super();
|
|
45
|
-
if (objectBody && object2D) {
|
|
46
|
-
this.tickSub = this.tick$.subscribe(() => {
|
|
47
|
-
// bind physics body transform to object transform
|
|
48
|
-
const pos = objectBody.position;
|
|
49
|
-
const rot = objectBody.rotation;
|
|
50
|
-
object2D.position = pos;
|
|
51
|
-
object2D.rotation = rot;
|
|
52
|
-
this._position$.next(pos);
|
|
53
|
-
this._rotation$.next(rot);
|
|
54
|
-
});
|
|
55
|
-
} else if (!objectBody && !object2D) {
|
|
56
|
-
throw new Error('Cannot create entity without a sprite and a body');
|
|
57
|
-
}
|
|
58
|
-
if (objectBody) {
|
|
59
|
-
objectBody.entity = this;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
onSpawned(world: Gg2dWorld) {
|
|
64
|
-
super.onSpawned(world);
|
|
65
|
-
this.object2D?.addToWorld(world.visualScene);
|
|
66
|
-
this.objectBody?.addToWorld(world.physicsWorld);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
onRemoved() {
|
|
70
|
-
this.object2D?.removeFromWorld(this.world!.visualScene);
|
|
71
|
-
this.objectBody?.removeFromWorld(this.world!.physicsWorld);
|
|
72
|
-
super.onRemoved();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
dispose(): void {
|
|
76
|
-
super.dispose();
|
|
77
|
-
this.tickSub?.unsubscribe();
|
|
78
|
-
this.tickSub = null;
|
|
79
|
-
if (this.object2D) {
|
|
80
|
-
this.object2D.dispose();
|
|
81
|
-
}
|
|
82
|
-
if (this.objectBody) {
|
|
83
|
-
this.objectBody.dispose();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IGg2dTrigger } from '../interfaces';
|
|
2
|
-
import { Gg2dEntity } from './gg-2d-entity';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
import { GgPositionable2dEntity } from './gg-positionable-2d-entity';
|
|
5
|
-
|
|
6
|
-
export class Gg2dTriggerEntity extends Gg2dEntity {
|
|
7
|
-
get onEntityEntered(): Observable<GgPositionable2dEntity> {
|
|
8
|
-
return this.objectBody.onEntityEntered;
|
|
9
|
-
}
|
|
10
|
-
get onEntityLeft(): Observable<GgPositionable2dEntity | null> {
|
|
11
|
-
return this.objectBody.onEntityLeft;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
constructor(public readonly objectBody: IGg2dTrigger) {
|
|
15
|
-
super(null, objectBody);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Point2 } from '../../base/models/points';
|
|
2
|
-
import { GgPositionableEntity } from '../../base/entities/gg-positionable-entity';
|
|
3
|
-
|
|
4
|
-
export abstract class GgPositionable2dEntity extends GgPositionableEntity<Point2, number> {
|
|
5
|
-
getDefaultPosition(): Point2 {
|
|
6
|
-
return { x: 0, y: 0 };
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
getDefaultRotation(): number {
|
|
10
|
-
return 0;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
getDefaultScale(): Point2 {
|
|
14
|
-
return { x: 1, y: 1 };
|
|
15
|
-
}
|
|
16
|
-
}
|
package/src/2d/factories.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { BodyShape2DDescriptor, Shape2DDescriptor } from './models/shapes';
|
|
2
|
-
import { Point2 } from '../base/models/points';
|
|
3
|
-
import { IGg2dBody, IGg2dObject, IGg2dTrigger } from './interfaces';
|
|
4
|
-
|
|
5
|
-
export abstract class IGg2dObjectFactory<T extends IGg2dObject = IGg2dObject> {
|
|
6
|
-
abstract createPrimitive(descriptor: Shape2DDescriptor): T;
|
|
7
|
-
|
|
8
|
-
// shortcuts
|
|
9
|
-
createSquare(dimensions: Point2): T {
|
|
10
|
-
return this.createPrimitive({ shape: 'SQUARE', dimensions });
|
|
11
|
-
}
|
|
12
|
-
createCircle(radius: number): T {
|
|
13
|
-
return this.createPrimitive({ shape: 'CIRCLE', radius });
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface IGg2dBodyFactory<T extends IGg2dBody = IGg2dBody, K extends IGg2dTrigger = IGg2dTrigger> {
|
|
18
|
-
createRigidBody(descriptor: BodyShape2DDescriptor, transform?: { position?: Point2; rotation?: number }): T;
|
|
19
|
-
createTrigger(descriptor: Shape2DDescriptor, transform?: { position?: Point2; rotation?: number }): K;
|
|
20
|
-
}
|
package/src/2d/gg-2d-world.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { GgWorld } from '../base/gg-world';
|
|
2
|
-
import { Point2 } from '../base/models/points';
|
|
3
|
-
import { IGg2dPhysicsWorld, IGg2dVisualScene } from './interfaces';
|
|
4
|
-
|
|
5
|
-
export class Gg2dWorld<
|
|
6
|
-
V extends IGg2dVisualScene = IGg2dVisualScene,
|
|
7
|
-
P extends IGg2dPhysicsWorld = IGg2dPhysicsWorld,
|
|
8
|
-
> extends GgWorld<Point2, number, V, P> {
|
|
9
|
-
constructor(
|
|
10
|
-
public readonly visualScene: V,
|
|
11
|
-
public readonly physicsWorld: P,
|
|
12
|
-
protected readonly consoleEnabled: boolean = false,
|
|
13
|
-
) {
|
|
14
|
-
super(visualScene, physicsWorld, consoleEnabled);
|
|
15
|
-
if (consoleEnabled) {
|
|
16
|
-
this.registerConsoleCommand(
|
|
17
|
-
'ph_gravity',
|
|
18
|
-
async (...args: string[]) => {
|
|
19
|
-
if (args.length == 1) {
|
|
20
|
-
args = ['0', args[0]]; // mean Y axis
|
|
21
|
-
}
|
|
22
|
-
if (args.length > 0) {
|
|
23
|
-
this.physicsWorld.gravity = { x: +args[0], y: +args[1] };
|
|
24
|
-
}
|
|
25
|
-
return JSON.stringify(this.physicsWorld.gravity);
|
|
26
|
-
},
|
|
27
|
-
'args: [float] or [float float]; change 2D world gravity vector. 1 argument means ' +
|
|
28
|
-
'{x: 0, y: value}, 2 arguments set the whole vector. Default value is "9.82" or "0 9.82"',
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/2d/interfaces.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { GgBody } from '../base/interfaces/gg-body';
|
|
2
|
-
import { Point2 } from '../base/models/points';
|
|
3
|
-
import { GgObject } from '../base/interfaces/gg-object';
|
|
4
|
-
import { GgPhysicsWorld } from '../base/interfaces/gg-physics-world';
|
|
5
|
-
import { GgVisualScene } from '../base/interfaces/gg-visual-scene';
|
|
6
|
-
import { BaseGgRenderer } from '../base/entities/base-gg-renderer';
|
|
7
|
-
import { GgTrigger } from '../base/interfaces/gg-trigger';
|
|
8
|
-
import { Observable } from 'rxjs';
|
|
9
|
-
import { GgPositionable2dEntity } from './entities/gg-positionable-2d-entity';
|
|
10
|
-
import { IGg2dBodyFactory, IGg2dObjectFactory } from './factories';
|
|
11
|
-
|
|
12
|
-
// These interfaces have to be implemented for a particular 2D physics engine
|
|
13
|
-
export interface IGg2dPhysicsWorld extends GgPhysicsWorld<Point2, number> {
|
|
14
|
-
readonly factory: IGg2dBodyFactory;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export abstract class Gg2dRenderer extends BaseGgRenderer {}
|
|
18
|
-
|
|
19
|
-
export interface IGg2dBody extends GgBody<Point2, number> {}
|
|
20
|
-
|
|
21
|
-
export interface IGg2dTrigger extends GgTrigger<Point2, number> {
|
|
22
|
-
get onEntityEntered(): Observable<GgPositionable2dEntity>;
|
|
23
|
-
get onEntityLeft(): Observable<GgPositionable2dEntity | null>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// These interfaces have to be implemented for a particular 2D rendering engine
|
|
27
|
-
export interface IGg2dVisualScene extends GgVisualScene<Point2, number> {
|
|
28
|
-
readonly factory: IGg2dObjectFactory;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface IGg2dObject extends GgObject<Point2, number> {}
|
package/src/2d/models/shapes.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Point2 } from '../../base/models/points';
|
|
2
|
-
import { Body2DOptions } from './body-options';
|
|
3
|
-
|
|
4
|
-
export type Shape2DDescriptor = { shape: 'SQUARE'; dimensions: Point2 } | { shape: 'CIRCLE'; radius: number };
|
|
5
|
-
// TODO add more shapes
|
|
6
|
-
|
|
7
|
-
export type BodyShape2DDescriptor = { shape: Shape2DDescriptor; body: Partial<Body2DOptions> };
|