@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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { GgGlobalClock } from './global-clock';
|
|
3
|
+
/**
|
|
4
|
+
* A class, providing ability to track time, fire ticks, provide time elapsed + tick delta with ability to suspend/resume it.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Clock {
|
|
7
|
+
protected readonly parentClock: Clock | GgGlobalClock;
|
|
8
|
+
private tickSub;
|
|
9
|
+
private readonly _tick$;
|
|
10
|
+
get tick$(): Observable<[number, number]>;
|
|
11
|
+
get isRunning(): boolean;
|
|
12
|
+
get isPaused(): boolean;
|
|
13
|
+
get elapsedTime(): number;
|
|
14
|
+
private startedAt;
|
|
15
|
+
private oldRelativeTime;
|
|
16
|
+
private pausedAt;
|
|
17
|
+
constructor(autoStart?: boolean, parentClock?: Clock | GgGlobalClock);
|
|
18
|
+
createChildClock(autoStart: boolean): Clock;
|
|
19
|
+
start(): void;
|
|
20
|
+
stop(): void;
|
|
21
|
+
pause(): void;
|
|
22
|
+
resume(): void;
|
|
23
|
+
protected startListeningTicks(): void;
|
|
24
|
+
protected stopListeningTicks(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Clock = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const global_clock_1 = require("./global-clock");
|
|
7
|
+
/**
|
|
8
|
+
* A class, providing ability to track time, fire ticks, provide time elapsed + tick delta with ability to suspend/resume it.
|
|
9
|
+
*/
|
|
10
|
+
class Clock {
|
|
11
|
+
constructor(autoStart = false, parentClock = global_clock_1.GgGlobalClock.instance) {
|
|
12
|
+
this.parentClock = parentClock;
|
|
13
|
+
this.tickSub = null;
|
|
14
|
+
this._tick$ = new rxjs_1.Subject();
|
|
15
|
+
// state
|
|
16
|
+
this.startedAt = -1;
|
|
17
|
+
this.oldRelativeTime = 0; // "elapsed", emitted on last tick
|
|
18
|
+
this.pausedAt = -1;
|
|
19
|
+
if (autoStart) {
|
|
20
|
+
this.start();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get tick$() {
|
|
24
|
+
return this._tick$.pipe((0, operators_1.map)(([oldTime, newTime]) => [newTime, newTime - oldTime]));
|
|
25
|
+
}
|
|
26
|
+
get isRunning() {
|
|
27
|
+
return !!this.tickSub;
|
|
28
|
+
}
|
|
29
|
+
get isPaused() {
|
|
30
|
+
return this.pausedAt !== -1;
|
|
31
|
+
}
|
|
32
|
+
get elapsedTime() {
|
|
33
|
+
if (this.isPaused) {
|
|
34
|
+
return this.pausedAt - this.startedAt;
|
|
35
|
+
}
|
|
36
|
+
return this.parentClock.elapsedTime - this.startedAt;
|
|
37
|
+
}
|
|
38
|
+
createChildClock(autoStart) {
|
|
39
|
+
return new Clock(autoStart, this);
|
|
40
|
+
}
|
|
41
|
+
start() {
|
|
42
|
+
if (this.isRunning) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.oldRelativeTime = 0;
|
|
46
|
+
this.startedAt = this.parentClock.elapsedTime;
|
|
47
|
+
this.startListeningTicks();
|
|
48
|
+
}
|
|
49
|
+
stop() {
|
|
50
|
+
this.stopListeningTicks();
|
|
51
|
+
this.startedAt = this.pausedAt = -1;
|
|
52
|
+
}
|
|
53
|
+
pause() {
|
|
54
|
+
this.stopListeningTicks();
|
|
55
|
+
this.pausedAt = this.parentClock.elapsedTime;
|
|
56
|
+
}
|
|
57
|
+
resume() {
|
|
58
|
+
if (this.isRunning || this.pausedAt == -1) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.startedAt += this.parentClock.elapsedTime - this.pausedAt;
|
|
62
|
+
this.pausedAt = -1;
|
|
63
|
+
this.startListeningTicks();
|
|
64
|
+
}
|
|
65
|
+
startListeningTicks() {
|
|
66
|
+
if (this.tickSub) {
|
|
67
|
+
throw new Error('Clock is already ticking!');
|
|
68
|
+
}
|
|
69
|
+
this.tickSub = this.parentClock.tick$
|
|
70
|
+
.pipe((0, operators_1.map)(([parentElapsed, _]) => [this.oldRelativeTime, parentElapsed - this.startedAt]), (0, operators_1.tap)(([_, cur]) => (this.oldRelativeTime = cur)))
|
|
71
|
+
.subscribe(this._tick$);
|
|
72
|
+
}
|
|
73
|
+
stopListeningTicks() {
|
|
74
|
+
var _a;
|
|
75
|
+
(_a = this.tickSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
76
|
+
this.tickSub = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.Clock = Clock;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { Clock } from './clock';
|
|
3
|
+
/**
|
|
4
|
+
* A singleton class, providing ability to track time, fire ticks, provide time elapsed + tick delta.
|
|
5
|
+
* Starts as soon as accessed and counts time from 01/01/1970
|
|
6
|
+
*/
|
|
7
|
+
export declare class GgGlobalClock {
|
|
8
|
+
private static _instance;
|
|
9
|
+
static get instance(): GgGlobalClock;
|
|
10
|
+
private readonly _tick$;
|
|
11
|
+
get tick$(): Observable<[number, number]>;
|
|
12
|
+
get elapsedTime(): number;
|
|
13
|
+
createChildClock(autoStart: boolean): Clock;
|
|
14
|
+
private constructor();
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GgGlobalClock = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const clock_1 = require("./clock");
|
|
7
|
+
/**
|
|
8
|
+
* A singleton class, providing ability to track time, fire ticks, provide time elapsed + tick delta.
|
|
9
|
+
* Starts as soon as accessed and counts time from 01/01/1970
|
|
10
|
+
*/
|
|
11
|
+
class GgGlobalClock {
|
|
12
|
+
constructor() {
|
|
13
|
+
this._tick$ = new rxjs_1.Subject();
|
|
14
|
+
let oldRelativeTime = this.elapsedTime;
|
|
15
|
+
(0, rxjs_1.of)(undefined, rxjs_1.animationFrameScheduler)
|
|
16
|
+
.pipe((0, operators_1.repeat)())
|
|
17
|
+
.pipe((0, operators_1.map)(() => [oldRelativeTime, this.elapsedTime]), (0, operators_1.tap)(([_, cur]) => (oldRelativeTime = cur)))
|
|
18
|
+
.subscribe(this._tick$);
|
|
19
|
+
}
|
|
20
|
+
static get instance() {
|
|
21
|
+
if (!GgGlobalClock._instance) {
|
|
22
|
+
GgGlobalClock._instance = new GgGlobalClock();
|
|
23
|
+
}
|
|
24
|
+
return GgGlobalClock._instance;
|
|
25
|
+
}
|
|
26
|
+
get tick$() {
|
|
27
|
+
return this._tick$.pipe((0, operators_1.map)(([oldTime, newTime]) => [newTime, newTime - oldTime]));
|
|
28
|
+
}
|
|
29
|
+
get elapsedTime() {
|
|
30
|
+
return (typeof performance === 'undefined' ? Date : performance).now();
|
|
31
|
+
}
|
|
32
|
+
createChildClock(autoStart) {
|
|
33
|
+
return new clock_1.Clock(autoStart, this);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.GgGlobalClock = GgGlobalClock;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { GgEntity } from '../gg-entity';
|
|
2
|
+
import { ITickListener } from '../interfaces/i-tick-listener';
|
|
3
|
+
import { Observable, Subject } from 'rxjs';
|
|
4
|
+
import { GgWorld } from '../../gg-world';
|
|
5
|
+
export declare type AnimationFunction<T> = (elapsed: number, delta: number) => T;
|
|
6
|
+
/**
|
|
7
|
+
* A class that performs property animations for a specific type `T` by using provided animation function.
|
|
8
|
+
* Supports smooth transition between animation function by interpolating between values over time.
|
|
9
|
+
* The current value of the animation can be subscribed to using the `subscribeToValue` property.
|
|
10
|
+
* The animation function can be changed with `transitAnimationFunction` or `transitFromStaticState`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AnimationMixer<T> extends GgEntity implements ITickListener {
|
|
13
|
+
protected _animationFunction: AnimationFunction<T>;
|
|
14
|
+
protected _lerp: (a: T, b: T, t: number) => T;
|
|
15
|
+
readonly tick$: Subject<[number, number]>;
|
|
16
|
+
readonly tickOrder: number;
|
|
17
|
+
/**
|
|
18
|
+
* A subject that emits the current value of the animation on every tick.
|
|
19
|
+
*/
|
|
20
|
+
protected readonly _value$: Subject<T>;
|
|
21
|
+
/**
|
|
22
|
+
* A subject that emits when the animator has been removed from the world.
|
|
23
|
+
*/
|
|
24
|
+
protected readonly removed$: Subject<void>;
|
|
25
|
+
/**
|
|
26
|
+
* The current transition time reference `[elapsed, delta]` that interpolates between the old and new functions.
|
|
27
|
+
*/
|
|
28
|
+
private _currentTransitionK;
|
|
29
|
+
/**
|
|
30
|
+
* The current transition subscription, which is null if no transition is currently active.
|
|
31
|
+
*/
|
|
32
|
+
private _currentTransition;
|
|
33
|
+
/**
|
|
34
|
+
* A behavior subject that emits whether the animator is currently in a transition.
|
|
35
|
+
*/
|
|
36
|
+
private _isInTransition$;
|
|
37
|
+
/**
|
|
38
|
+
* Gets an observable of the current value of the animation.
|
|
39
|
+
*/
|
|
40
|
+
get value$(): Observable<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets the current motion control function that determines the animation.
|
|
43
|
+
*/
|
|
44
|
+
get animationFunction(): AnimationFunction<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Sets the current motion control function that determines the animation.
|
|
47
|
+
* @param value The new motion control function.
|
|
48
|
+
*/
|
|
49
|
+
set animationFunction(value: AnimationFunction<T>);
|
|
50
|
+
/**
|
|
51
|
+
* Gets a flag whether the animator is currently in a transition.
|
|
52
|
+
*/
|
|
53
|
+
get isInTransition(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Gets an observable that emits whether the animator is currently in a transition.
|
|
56
|
+
*/
|
|
57
|
+
get isInTransition$(): Observable<boolean>;
|
|
58
|
+
protected get currentTransition(): ((a: [number, number]) => void) | null;
|
|
59
|
+
protected set currentTransition(value: ((a: [number, number]) => void) | null);
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new `AnimationMixer` entity.
|
|
62
|
+
* @param _animationFunction The initial motion control function that determines the animation.
|
|
63
|
+
* @param _lerp The linear interpolation between two values of type `T`.
|
|
64
|
+
*/
|
|
65
|
+
constructor(_animationFunction: AnimationFunction<T>, _lerp?: (a: T, b: T, t: number) => T);
|
|
66
|
+
/**
|
|
67
|
+
* Set output to static value and smoothly transit to new control function
|
|
68
|
+
* @param newFunc a new function
|
|
69
|
+
* @param transitionDuration a duration, after which new function will be fully controlling the output
|
|
70
|
+
* @param easing an easing function for transition
|
|
71
|
+
*/
|
|
72
|
+
transitFromStaticState(state: T, newFunc: AnimationFunction<T>, transitionDuration: number, easing?: (t: number) => number): void;
|
|
73
|
+
/**
|
|
74
|
+
* Smoothly transit to new control function
|
|
75
|
+
* @param newFunc a new function
|
|
76
|
+
* @param transitionDuration a duration, after which new function will be fully controlling the output
|
|
77
|
+
* @param easing an easing function for transition
|
|
78
|
+
*/
|
|
79
|
+
transitAnimationFunction(newFunc: AnimationFunction<T>, transitionDuration: number, easing?: (t: number) => number): void;
|
|
80
|
+
onSpawned(world: GgWorld<any, any>): void;
|
|
81
|
+
onRemoved(): void;
|
|
82
|
+
dispose(): void;
|
|
83
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnimationMixer = void 0;
|
|
4
|
+
const gg_entity_1 = require("../gg-entity");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const operators_1 = require("rxjs/operators");
|
|
7
|
+
/**
|
|
8
|
+
* A class that performs property animations for a specific type `T` by using provided animation function.
|
|
9
|
+
* Supports smooth transition between animation function by interpolating between values over time.
|
|
10
|
+
* The current value of the animation can be subscribed to using the `subscribeToValue` property.
|
|
11
|
+
* The animation function can be changed with `transitAnimationFunction` or `transitFromStaticState`.
|
|
12
|
+
*/
|
|
13
|
+
class AnimationMixer extends gg_entity_1.GgEntity {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new `AnimationMixer` entity.
|
|
16
|
+
* @param _animationFunction The initial motion control function that determines the animation.
|
|
17
|
+
* @param _lerp The linear interpolation between two values of type `T`.
|
|
18
|
+
*/
|
|
19
|
+
constructor(_animationFunction, _lerp = (a, b, t) => b) {
|
|
20
|
+
super();
|
|
21
|
+
this._animationFunction = _animationFunction;
|
|
22
|
+
this._lerp = _lerp;
|
|
23
|
+
this.tick$ = new rxjs_1.Subject();
|
|
24
|
+
this.tickOrder = 850;
|
|
25
|
+
/**
|
|
26
|
+
* A subject that emits the current value of the animation on every tick.
|
|
27
|
+
*/
|
|
28
|
+
this._value$ = new rxjs_1.Subject();
|
|
29
|
+
/**
|
|
30
|
+
* A subject that emits when the animator has been removed from the world.
|
|
31
|
+
*/
|
|
32
|
+
this.removed$ = new rxjs_1.Subject();
|
|
33
|
+
/**
|
|
34
|
+
* The current transition time reference `[elapsed, delta]` that interpolates between the old and new functions.
|
|
35
|
+
*/
|
|
36
|
+
this._currentTransitionK = [0, 0];
|
|
37
|
+
/**
|
|
38
|
+
* The current transition subscription, which is null if no transition is currently active.
|
|
39
|
+
*/
|
|
40
|
+
this._currentTransition = null;
|
|
41
|
+
/**
|
|
42
|
+
* A behavior subject that emits whether the animator is currently in a transition.
|
|
43
|
+
*/
|
|
44
|
+
this._isInTransition$ = new rxjs_1.BehaviorSubject(false);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets an observable of the current value of the animation.
|
|
48
|
+
*/
|
|
49
|
+
get value$() {
|
|
50
|
+
return this._value$.asObservable();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets the current motion control function that determines the animation.
|
|
54
|
+
*/
|
|
55
|
+
get animationFunction() {
|
|
56
|
+
return this._animationFunction;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Sets the current motion control function that determines the animation.
|
|
60
|
+
* @param value The new motion control function.
|
|
61
|
+
*/
|
|
62
|
+
set animationFunction(value) {
|
|
63
|
+
if (this.currentTransition) {
|
|
64
|
+
this.currentTransition = null;
|
|
65
|
+
}
|
|
66
|
+
this._animationFunction = value;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets a flag whether the animator is currently in a transition.
|
|
70
|
+
*/
|
|
71
|
+
get isInTransition() {
|
|
72
|
+
return this._isInTransition$.getValue();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Gets an observable that emits whether the animator is currently in a transition.
|
|
76
|
+
*/
|
|
77
|
+
get isInTransition$() {
|
|
78
|
+
return this._isInTransition$.pipe((0, rxjs_1.distinctUntilChanged)());
|
|
79
|
+
}
|
|
80
|
+
get currentTransition() {
|
|
81
|
+
return this._currentTransition;
|
|
82
|
+
}
|
|
83
|
+
set currentTransition(value) {
|
|
84
|
+
this._currentTransition = value;
|
|
85
|
+
this._isInTransition$.next(!!value);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Set output to static value and smoothly transit to new control function
|
|
89
|
+
* @param newFunc a new function
|
|
90
|
+
* @param transitionDuration a duration, after which new function will be fully controlling the output
|
|
91
|
+
* @param easing an easing function for transition
|
|
92
|
+
*/
|
|
93
|
+
transitFromStaticState(state, newFunc, transitionDuration, easing = x => x) {
|
|
94
|
+
this.animationFunction = () => state;
|
|
95
|
+
return this.transitAnimationFunction(newFunc, transitionDuration, easing);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Smoothly transit to new control function
|
|
99
|
+
* @param newFunc a new function
|
|
100
|
+
* @param transitionDuration a duration, after which new function will be fully controlling the output
|
|
101
|
+
* @param easing an easing function for transition
|
|
102
|
+
*/
|
|
103
|
+
transitAnimationFunction(newFunc, transitionDuration, easing = x => x) {
|
|
104
|
+
let oldAnimFunc;
|
|
105
|
+
if (this.currentTransition) {
|
|
106
|
+
// interrupt it by freezing K, so it will still work as binding, but do not animate further
|
|
107
|
+
this.currentTransition = null;
|
|
108
|
+
const oldTransitionAnimationFunction = this._animationFunction;
|
|
109
|
+
const oldTransitionLatestK = this._currentTransitionK;
|
|
110
|
+
oldAnimFunc = () => oldTransitionAnimationFunction(...oldTransitionLatestK);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
oldAnimFunc = this._animationFunction;
|
|
114
|
+
}
|
|
115
|
+
let k = 0;
|
|
116
|
+
this._animationFunction = (elapsed, delta) => this._lerp(oldAnimFunc(elapsed, delta), newFunc(elapsed, delta), k);
|
|
117
|
+
let startTime;
|
|
118
|
+
this.currentTransition = ([elapsed, delta]) => {
|
|
119
|
+
this._currentTransitionK = [elapsed, delta];
|
|
120
|
+
if (startTime === undefined) {
|
|
121
|
+
startTime = elapsed;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
k = (elapsed - startTime) / transitionDuration;
|
|
125
|
+
if (k >= 1) {
|
|
126
|
+
k = 1;
|
|
127
|
+
this.currentTransition = null;
|
|
128
|
+
this._animationFunction = newFunc;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
k = easing(k);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
onSpawned(world) {
|
|
137
|
+
super.onSpawned(world);
|
|
138
|
+
this.tick$
|
|
139
|
+
.pipe((0, rxjs_1.takeUntil)(this.removed$), (0, operators_1.tap)(([elapsed, delta]) => this.currentTransition && this.currentTransition([elapsed, delta])), (0, operators_1.map)(([elapsed, delta]) => this._animationFunction(elapsed, delta)))
|
|
140
|
+
.subscribe(value => this._value$.next(value));
|
|
141
|
+
}
|
|
142
|
+
onRemoved() {
|
|
143
|
+
super.onRemoved();
|
|
144
|
+
this.removed$.next();
|
|
145
|
+
}
|
|
146
|
+
dispose() {
|
|
147
|
+
super.dispose();
|
|
148
|
+
this.tick$.complete();
|
|
149
|
+
this._value$.complete();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.AnimationMixer = AnimationMixer;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { GgWorld } from '../gg-world';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
2
3
|
export declare abstract class GgEntity {
|
|
3
|
-
get world(): GgWorld<any, any> | null;
|
|
4
4
|
protected _world: GgWorld<any, any> | null;
|
|
5
|
+
get world(): GgWorld<any, any> | null;
|
|
5
6
|
protected _name: string;
|
|
6
7
|
get name(): string;
|
|
7
8
|
set name(value: string);
|
|
8
9
|
protected _children: GgEntity[];
|
|
9
10
|
addChildren(...entities: GgEntity[]): void;
|
|
10
11
|
removeChildren(entities: GgEntity[], dispose?: boolean): void;
|
|
12
|
+
protected _onSpawned$: Subject<void>;
|
|
13
|
+
protected _onRemoved$: Subject<void>;
|
|
11
14
|
onSpawned(world: GgWorld<any, any>): void;
|
|
12
15
|
onRemoved(): void;
|
|
13
16
|
dispose(): void;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GgEntity = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
4
5
|
class GgEntity {
|
|
5
6
|
constructor() {
|
|
6
7
|
this._world = null;
|
|
7
8
|
this._name = '';
|
|
8
9
|
this._children = [];
|
|
10
|
+
this._onSpawned$ = new rxjs_1.Subject();
|
|
11
|
+
this._onRemoved$ = new rxjs_1.Subject();
|
|
9
12
|
}
|
|
10
13
|
get world() {
|
|
11
14
|
return this._world;
|
|
@@ -37,6 +40,7 @@ class GgEntity {
|
|
|
37
40
|
for (const c of this._children) {
|
|
38
41
|
world.addEntity(c);
|
|
39
42
|
}
|
|
43
|
+
this._onSpawned$.next();
|
|
40
44
|
}
|
|
41
45
|
onRemoved() {
|
|
42
46
|
const world = this._world;
|
|
@@ -44,9 +48,12 @@ class GgEntity {
|
|
|
44
48
|
for (const c of this._children) {
|
|
45
49
|
world.removeEntity(c);
|
|
46
50
|
}
|
|
51
|
+
this._onRemoved$.next();
|
|
47
52
|
}
|
|
48
53
|
// TODO add some flag to entity that it is disposed, and throw a normal error when trying to add such entity to world again
|
|
49
54
|
dispose() {
|
|
55
|
+
this._onSpawned$.complete();
|
|
56
|
+
this._onRemoved$.complete();
|
|
50
57
|
for (const c of this._children) {
|
|
51
58
|
c.dispose();
|
|
52
59
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Subject } from 'rxjs';
|
|
2
2
|
import { BaseGgRenderer } from './entities/base-gg-renderer';
|
|
3
|
+
export declare type CanvasAppDescr = {
|
|
4
|
+
canvas: HTMLCanvasElement;
|
|
5
|
+
renderer?: BaseGgRenderer;
|
|
6
|
+
};
|
|
3
7
|
export declare class GgViewportManager {
|
|
4
8
|
private static _instance;
|
|
5
9
|
static get instance(): GgViewportManager;
|
package/dist/base/gg-world.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ import { ITickListener } from './entities/interfaces/i-tick-listener';
|
|
|
3
3
|
import { GgPhysicsWorld } from './interfaces/gg-physics-world';
|
|
4
4
|
import { GgVisualScene } from './interfaces/gg-visual-scene';
|
|
5
5
|
import { KeyboardController } from './controllers/keyboard.controller';
|
|
6
|
+
import { GgPositionableEntity } from './entities/gg-positionable-entity';
|
|
6
7
|
export declare abstract class GgWorld<D, R, V extends GgVisualScene<D, R> = GgVisualScene<D, R>, P extends GgPhysicsWorld<D, R> = GgPhysicsWorld<D, R>> {
|
|
7
8
|
readonly visualScene: V;
|
|
8
9
|
readonly physicsWorld: P;
|
|
9
10
|
protected readonly consoleEnabled: boolean;
|
|
10
|
-
private readonly animationFrameClock;
|
|
11
11
|
private readonly worldClock;
|
|
12
12
|
readonly keyboardController: KeyboardController;
|
|
13
|
+
get worldTime(): number;
|
|
13
14
|
readonly children: GgEntity[];
|
|
14
15
|
protected readonly tickListeners: ITickListener[];
|
|
15
16
|
constructor(visualScene: V, physicsWorld: P, consoleEnabled?: boolean);
|
|
@@ -18,6 +19,7 @@ export declare abstract class GgWorld<D, R, V extends GgVisualScene<D, R> = GgVi
|
|
|
18
19
|
pauseWorld(): void;
|
|
19
20
|
resumeWorld(): void;
|
|
20
21
|
dispose(): void;
|
|
22
|
+
abstract addPrimitiveRigidBody(descr: any, position?: D, rotation?: R): GgPositionableEntity<D, R>;
|
|
21
23
|
addEntity(entity: GgEntity): void;
|
|
22
24
|
removeEntity(entity: GgEntity, dispose?: boolean): void;
|
|
23
25
|
protected commands: {
|
package/dist/base/gg-world.js
CHANGED
|
@@ -10,22 +10,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.GgWorld = void 0;
|
|
13
|
-
const clock_1 = require("./clock");
|
|
14
13
|
const i_tick_listener_1 = require("./entities/interfaces/i-tick-listener");
|
|
15
14
|
const gg_static_1 = require("./gg-static");
|
|
16
15
|
const keyboard_controller_1 = require("./controllers/keyboard.controller");
|
|
17
16
|
const rxjs_1 = require("rxjs");
|
|
18
17
|
const gg_console_ui_1 = require("./ui/gg-console.ui");
|
|
19
18
|
const gg_debugger_ui_1 = require("./ui/gg-debugger.ui");
|
|
19
|
+
const global_clock_1 = require("./clock/global-clock");
|
|
20
20
|
class GgWorld {
|
|
21
21
|
constructor(visualScene, physicsWorld, consoleEnabled = false) {
|
|
22
22
|
this.visualScene = visualScene;
|
|
23
23
|
this.physicsWorld = physicsWorld;
|
|
24
24
|
this.consoleEnabled = consoleEnabled;
|
|
25
|
-
// inner clock, runs constantly
|
|
26
|
-
this.animationFrameClock = clock_1.Clock.animationFrameClock;
|
|
27
25
|
// world clock, can be paused/resumed. Stops when disposing world
|
|
28
|
-
this.worldClock =
|
|
26
|
+
this.worldClock = global_clock_1.GgGlobalClock.instance.createChildClock(false);
|
|
29
27
|
// TODO consider adding mouse controller
|
|
30
28
|
this.keyboardController = new keyboard_controller_1.KeyboardController();
|
|
31
29
|
this.children = [];
|
|
@@ -78,6 +76,9 @@ class GgWorld {
|
|
|
78
76
|
}), 'args: [0 or 1]; turn on/off physics debug view. Default value is 0');
|
|
79
77
|
}
|
|
80
78
|
}
|
|
79
|
+
get worldTime() {
|
|
80
|
+
return this.worldClock.elapsedTime;
|
|
81
|
+
}
|
|
81
82
|
init() {
|
|
82
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
84
|
yield Promise.all([this.physicsWorld.init(), this.visualScene.init()]);
|
|
@@ -103,7 +104,7 @@ class GgWorld {
|
|
|
103
104
|
this.worldClock.pause();
|
|
104
105
|
}
|
|
105
106
|
resumeWorld() {
|
|
106
|
-
this.worldClock.
|
|
107
|
+
this.worldClock.resume();
|
|
107
108
|
}
|
|
108
109
|
dispose() {
|
|
109
110
|
this.worldClock.stop();
|
|
@@ -8,7 +8,7 @@ class Mtrx4 {
|
|
|
8
8
|
let z = point3_1.Pnt3.sub(eye, target);
|
|
9
9
|
if (point3_1.Pnt3.lenSq(z) === 0) {
|
|
10
10
|
// same position
|
|
11
|
-
z.z
|
|
11
|
+
z = Object.assign(Object.assign({}, z), { z: 1 });
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
14
|
z = point3_1.Pnt3.norm(z);
|
|
@@ -17,10 +17,10 @@ class Mtrx4 {
|
|
|
17
17
|
if (point3_1.Pnt3.lenSq(x) === 0) {
|
|
18
18
|
// up and z are parallel
|
|
19
19
|
if (Math.abs(up.z) === 1) {
|
|
20
|
-
z.x
|
|
20
|
+
z = Object.assign(Object.assign({}, z), { x: z.x + 0.0001 });
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
|
-
z.z
|
|
23
|
+
z = Object.assign(Object.assign({}, z), { z: z.z + 0.0001 });
|
|
24
24
|
}
|
|
25
25
|
z = point3_1.Pnt3.norm(z);
|
|
26
26
|
x = point3_1.Pnt3.cross(up, z);
|
package/dist/base/math/point2.js
CHANGED
package/dist/base/math/point3.js
CHANGED