@gg-web-engine/core 0.0.3 → 0.0.4
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.js +1 -1
- package/dist/2d/entities/gg-2d-entity.d.ts +3 -5
- package/dist/2d/entities/gg-2d-entity.js +2 -3
- package/dist/3d/entities/controllers/animators/camera-3d.animator.d.ts +17 -0
- package/dist/3d/entities/controllers/animators/camera-3d.animator.js +32 -0
- package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.d.ts +16 -0
- package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.js +26 -0
- package/dist/3d/entities/controllers/input/car-keyboard-handling.controller.d.ts +25 -0
- package/dist/3d/entities/controllers/input/car-keyboard-handling.controller.js +105 -0
- package/dist/3d/entities/controllers/input/free-camera.controller.d.ts +54 -0
- package/dist/3d/entities/controllers/input/free-camera.controller.js +102 -0
- package/dist/3d/entities/gg-3d-entity.d.ts +3 -5
- package/dist/3d/entities/gg-3d-entity.js +2 -3
- package/dist/3d/entities/gg-3d-map-graph.entity.d.ts +3 -5
- package/dist/3d/entities/gg-3d-map-graph.entity.js +1 -2
- package/dist/3d/inputs/car-keyboard.input.d.ts +25 -0
- package/dist/3d/inputs/car-keyboard.input.js +100 -0
- package/dist/3d/inputs/free-camera.input.d.ts +22 -0
- package/dist/3d/inputs/free-camera.input.js +80 -0
- package/dist/base/clock/global-clock.d.ts +4 -3
- package/dist/base/clock/global-clock.js +2 -2
- package/dist/base/clock/i-clock.d.ts +7 -0
- package/dist/base/clock/i-clock.js +2 -0
- package/dist/base/clock/pausable-clock.d.ts +25 -0
- package/dist/base/clock/pausable-clock.js +79 -0
- package/dist/base/entities/base-gg-renderer.d.ts +3 -15
- package/dist/base/entities/base-gg-renderer.js +2 -30
- package/dist/base/entities/controllers/animation-mixer.d.ts +1 -8
- package/dist/base/entities/controllers/animation-mixer.js +2 -11
- package/dist/base/entities/gg-entity.d.ts +29 -0
- package/dist/base/entities/gg-entity.js +35 -1
- package/dist/base/entities/inline-controller.js +1 -6
- package/dist/base/entities/interfaces/i-tick-listener.d.ts +25 -1
- package/dist/base/entities/interfaces/i-tick-listener.js +17 -1
- package/dist/base/gg-world.d.ts +9 -6
- package/dist/base/gg-world.js +47 -29
- package/dist/base/inputs/direction.keyboard-input.d.ts +41 -0
- package/dist/base/inputs/direction.keyboard-input.js +85 -0
- package/dist/base/inputs/input.d.ts +50 -0
- package/dist/base/inputs/input.js +80 -0
- package/dist/base/inputs/keyboard.input.d.ts +45 -0
- package/dist/base/inputs/keyboard.input.js +130 -0
- package/dist/base/inputs/mouse.input.d.ts +57 -0
- package/dist/base/inputs/mouse.input.js +81 -0
- package/dist/index.d.ts +10 -10
- package/dist/index.js +10 -10
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ class Entity2dPositioningAnimator extends animation_mixer_1.AnimationMixer {
|
|
|
16
16
|
}
|
|
17
17
|
onSpawned(world) {
|
|
18
18
|
super.onSpawned(world);
|
|
19
|
-
this.value$.pipe((0, rxjs_1.takeUntil)(this.
|
|
19
|
+
this.value$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$)).subscribe(value => this.applyPositioning(value));
|
|
20
20
|
}
|
|
21
21
|
applyPositioning(value) {
|
|
22
22
|
this.entity.position = value.position;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
2
1
|
import { GgPositionable2dEntity } from './gg-positionable-2d-entity';
|
|
3
|
-
import { ITickListener } from '../../base/entities/interfaces/i-tick-listener';
|
|
4
2
|
import { Point2 } from '../../base/models/points';
|
|
5
3
|
import { IGg2dBody, IGg2dObject } from '../interfaces';
|
|
6
4
|
import { Gg2dWorld } from '../gg-2d-world';
|
|
7
|
-
|
|
5
|
+
import { GGTickOrder } from '../../base/entities/gg-entity';
|
|
6
|
+
export declare class Gg2dEntity extends GgPositionable2dEntity {
|
|
8
7
|
readonly object2D: IGg2dObject | null;
|
|
9
8
|
readonly objectBody: IGg2dBody | null;
|
|
10
|
-
readonly
|
|
11
|
-
readonly tickOrder = 750;
|
|
9
|
+
readonly tickOrder = GGTickOrder.OBJECTS_BINDING;
|
|
12
10
|
get position(): Point2;
|
|
13
11
|
set position(value: Point2);
|
|
14
12
|
get rotation(): number;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Gg2dEntity = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
4
|
const gg_positionable_2d_entity_1 = require("./gg-positionable-2d-entity");
|
|
5
|
+
const gg_entity_1 = require("../../base/entities/gg-entity");
|
|
6
6
|
class Gg2dEntity extends gg_positionable_2d_entity_1.GgPositionable2dEntity {
|
|
7
7
|
constructor(object2D, objectBody) {
|
|
8
8
|
super();
|
|
9
9
|
this.object2D = object2D;
|
|
10
10
|
this.objectBody = objectBody;
|
|
11
|
-
this.
|
|
12
|
-
this.tickOrder = 750;
|
|
11
|
+
this.tickOrder = gg_entity_1.GGTickOrder.OBJECTS_BINDING;
|
|
13
12
|
if (objectBody) {
|
|
14
13
|
objectBody.entity = this;
|
|
15
14
|
this.tick$.subscribe(() => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AnimationFunction, AnimationMixer } from '../../../../base/entities/controllers/animation-mixer';
|
|
2
|
+
import { Point3 } from '../../../../base/models/points';
|
|
3
|
+
import { Gg3dWorld } from '../../../gg-3d-world';
|
|
4
|
+
import { Gg3dCameraEntity } from '../../gg-3d-camera.entity';
|
|
5
|
+
export declare type Camera3dAnimationArgs = {
|
|
6
|
+
position: Point3;
|
|
7
|
+
target: Point3;
|
|
8
|
+
up?: Point3;
|
|
9
|
+
fov?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare class Camera3dAnimator extends AnimationMixer<Camera3dAnimationArgs> {
|
|
12
|
+
entity: Gg3dCameraEntity;
|
|
13
|
+
protected _animationFunction: AnimationFunction<Camera3dAnimationArgs>;
|
|
14
|
+
constructor(entity: Gg3dCameraEntity, _animationFunction: AnimationFunction<Camera3dAnimationArgs>);
|
|
15
|
+
onSpawned(world: Gg3dWorld): void;
|
|
16
|
+
protected applyPositioning(value: Camera3dAnimationArgs): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Camera3dAnimator = void 0;
|
|
4
|
+
const animation_mixer_1 = require("../../../../base/entities/controllers/animation-mixer");
|
|
5
|
+
const point3_1 = require("../../../../base/math/point3");
|
|
6
|
+
const quaternion_1 = require("../../../../base/math/quaternion");
|
|
7
|
+
const rxjs_1 = require("rxjs");
|
|
8
|
+
const numbers_1 = require("../../../../base/math/numbers");
|
|
9
|
+
const defaultUp = { x: 0, y: 0, z: 1 };
|
|
10
|
+
const defaultFov = 65;
|
|
11
|
+
class Camera3dAnimator extends animation_mixer_1.AnimationMixer {
|
|
12
|
+
constructor(entity, _animationFunction) {
|
|
13
|
+
super(_animationFunction, (a, b, t) => ({
|
|
14
|
+
position: point3_1.Pnt3.lerp(a.position, b.position, t),
|
|
15
|
+
target: point3_1.Pnt3.lerp(a.target, b.target, t),
|
|
16
|
+
up: point3_1.Pnt3.lerp(a.up || defaultUp, b.up || defaultUp, t),
|
|
17
|
+
fov: (0, numbers_1.lerpNumber)(a.fov || defaultFov, b.fov || defaultFov, t),
|
|
18
|
+
}));
|
|
19
|
+
this.entity = entity;
|
|
20
|
+
this._animationFunction = _animationFunction;
|
|
21
|
+
}
|
|
22
|
+
onSpawned(world) {
|
|
23
|
+
super.onSpawned(world);
|
|
24
|
+
this.value$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$)).subscribe(value => this.applyPositioning(value));
|
|
25
|
+
}
|
|
26
|
+
applyPositioning(value) {
|
|
27
|
+
this.entity.position = value.position;
|
|
28
|
+
this.entity.rotation = quaternion_1.Qtrn.lookAt(value.position, value.target, value.up || defaultUp);
|
|
29
|
+
this.entity.fov = value.fov || defaultFov;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Camera3dAnimator = Camera3dAnimator;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Gg3dEntity } from '../../gg-3d-entity';
|
|
2
|
+
import { AnimationFunction, AnimationMixer } from '../../../../base/entities/controllers/animation-mixer';
|
|
3
|
+
import { Point3, Point4 } from '../../../../base/models/points';
|
|
4
|
+
import { Gg3dWorld } from '../../../gg-3d-world';
|
|
5
|
+
declare type Positioning3d = {
|
|
6
|
+
position: Point3;
|
|
7
|
+
rotation: Point4;
|
|
8
|
+
};
|
|
9
|
+
export declare class Entity3dPositioningAnimator<T extends Gg3dEntity = Gg3dEntity> extends AnimationMixer<Positioning3d> {
|
|
10
|
+
entity: T;
|
|
11
|
+
protected _animationFunction: AnimationFunction<Positioning3d>;
|
|
12
|
+
constructor(entity: T, _animationFunction: AnimationFunction<Positioning3d>);
|
|
13
|
+
onSpawned(world: Gg3dWorld): void;
|
|
14
|
+
protected applyPositioning(value: Positioning3d): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity3dPositioningAnimator = void 0;
|
|
4
|
+
const animation_mixer_1 = require("../../../../base/entities/controllers/animation-mixer");
|
|
5
|
+
const point3_1 = require("../../../../base/math/point3");
|
|
6
|
+
const quaternion_1 = require("../../../../base/math/quaternion");
|
|
7
|
+
const rxjs_1 = require("rxjs");
|
|
8
|
+
class Entity3dPositioningAnimator extends animation_mixer_1.AnimationMixer {
|
|
9
|
+
constructor(entity, _animationFunction) {
|
|
10
|
+
super(_animationFunction, (a, b, t) => ({
|
|
11
|
+
position: point3_1.Pnt3.lerp(a.position, b.position, t),
|
|
12
|
+
rotation: quaternion_1.Qtrn.slerp(a.rotation, b.rotation, t),
|
|
13
|
+
}));
|
|
14
|
+
this.entity = entity;
|
|
15
|
+
this._animationFunction = _animationFunction;
|
|
16
|
+
}
|
|
17
|
+
onSpawned(world) {
|
|
18
|
+
super.onSpawned(world);
|
|
19
|
+
this.value$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$)).subscribe(value => this.applyPositioning(value));
|
|
20
|
+
}
|
|
21
|
+
applyPositioning(value) {
|
|
22
|
+
this.entity.position = value.position;
|
|
23
|
+
this.entity.rotation = value.rotation;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Entity3dPositioningAnimator = Entity3dPositioningAnimator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
import { KeyboardInput } from '../../../../base/inputs/keyboard.input';
|
|
3
|
+
import { Gg3dRaycastVehicleEntity } from '../../gg-3d-raycast-vehicle.entity';
|
|
4
|
+
import { DirectionKeyboardInput, DirectionKeyboardKeymap } from '../../../../base/inputs/direction.keyboard-input';
|
|
5
|
+
import { GgEntity, GGTickOrder } from '../../../../base/entities/gg-entity';
|
|
6
|
+
import { GgWorld } from '../../../../base/gg-world';
|
|
7
|
+
export declare type CarKeyboardControllerOptions = {
|
|
8
|
+
keymap: DirectionKeyboardKeymap;
|
|
9
|
+
gearUpDownKeys: [string, string];
|
|
10
|
+
};
|
|
11
|
+
export declare class CarKeyboardHandlingController extends GgEntity {
|
|
12
|
+
protected readonly keyboard: KeyboardInput;
|
|
13
|
+
car: Gg3dRaycastVehicleEntity | null;
|
|
14
|
+
protected readonly options: CarKeyboardControllerOptions;
|
|
15
|
+
readonly tickOrder = GGTickOrder.INPUT_CONTROLLERS;
|
|
16
|
+
protected readonly directionsInput: DirectionKeyboardInput;
|
|
17
|
+
protected readonly x$: BehaviorSubject<number>;
|
|
18
|
+
protected readonly y$: BehaviorSubject<number>;
|
|
19
|
+
protected lastX: number;
|
|
20
|
+
switchingGearsEnabled: boolean;
|
|
21
|
+
pairTickerPipe: import("rxjs").UnaryFunction<import("rxjs").Observable<number>, import("rxjs").Observable<number>>;
|
|
22
|
+
constructor(keyboard: KeyboardInput, car: Gg3dRaycastVehicleEntity | null, options?: CarKeyboardControllerOptions);
|
|
23
|
+
onSpawned(world: GgWorld<any, any>): Promise<void>;
|
|
24
|
+
onRemoved(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CarKeyboardHandlingController = void 0;
|
|
13
|
+
const rxjs_1 = require("rxjs");
|
|
14
|
+
const operators_1 = require("rxjs/operators");
|
|
15
|
+
const direction_keyboard_input_1 = require("../../../../base/inputs/direction.keyboard-input");
|
|
16
|
+
const gg_entity_1 = require("../../../../base/entities/gg-entity");
|
|
17
|
+
// TODO pass as settings
|
|
18
|
+
// TODO smooth y?
|
|
19
|
+
const TICKER_INTERVAL = 16;
|
|
20
|
+
const TICKER_MAX_STEPS = 10;
|
|
21
|
+
class CarKeyboardHandlingController extends gg_entity_1.GgEntity {
|
|
22
|
+
constructor(keyboard, car, options = { keymap: 'arrows', gearUpDownKeys: ['KeyA', 'KeyZ'] }) {
|
|
23
|
+
super();
|
|
24
|
+
this.keyboard = keyboard;
|
|
25
|
+
this.car = car;
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.tickOrder = gg_entity_1.GGTickOrder.INPUT_CONTROLLERS;
|
|
28
|
+
// emits values -1 - 1; -1 = full turn left; 1 = full turn right
|
|
29
|
+
this.x$ = new rxjs_1.BehaviorSubject(0);
|
|
30
|
+
// emits values -1 - 1; -1 = full brake; 1 = full acceleration
|
|
31
|
+
this.y$ = new rxjs_1.BehaviorSubject(0);
|
|
32
|
+
this.lastX = 0;
|
|
33
|
+
this.switchingGearsEnabled = true;
|
|
34
|
+
this.pairTickerPipe = (0, rxjs_1.pipe)((0, operators_1.startWith)(0), (0, operators_1.pairwise)(), (0, operators_1.map)(([beforeValue, afterValue]) => [this.lastX, afterValue]), (0, operators_1.switchMap)(([beforeValue, afterValue]) => (0, rxjs_1.interval)(TICKER_INTERVAL).pipe((0, operators_1.take)(TICKER_MAX_STEPS), (0, operators_1.map)(count => ++count), (0, operators_1.map)(count => beforeValue * ((TICKER_MAX_STEPS - count) / TICKER_MAX_STEPS) + afterValue * (count / TICKER_MAX_STEPS)), (0, operators_1.tap)(x => {
|
|
35
|
+
this.lastX = x;
|
|
36
|
+
}))));
|
|
37
|
+
this.directionsInput = new direction_keyboard_input_1.DirectionKeyboardInput(keyboard, options.keymap);
|
|
38
|
+
}
|
|
39
|
+
onSpawned(world) {
|
|
40
|
+
const _super = Object.create(null, {
|
|
41
|
+
onSpawned: { get: () => super.onSpawned }
|
|
42
|
+
});
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
_super.onSpawned.call(this, world);
|
|
45
|
+
let moveDirection = {};
|
|
46
|
+
this.keyboard
|
|
47
|
+
.bind(this.options.gearUpDownKeys[0])
|
|
48
|
+
.pipe((0, rxjs_1.takeUntil)(this._onRemoved$), (0, rxjs_1.filter)(x => this.switchingGearsEnabled && !!x))
|
|
49
|
+
.subscribe(() => {
|
|
50
|
+
if (this.car && (!this.car.carProperties.transmission.isAuto || this.car.gear <= 0)) {
|
|
51
|
+
this.car.gear++;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this.keyboard
|
|
55
|
+
.bind(this.options.gearUpDownKeys[1])
|
|
56
|
+
.pipe((0, rxjs_1.takeUntil)(this._onRemoved$), (0, rxjs_1.filter)(x => this.switchingGearsEnabled && !!x))
|
|
57
|
+
.subscribe(() => {
|
|
58
|
+
if (this.car) {
|
|
59
|
+
if (this.car.carProperties.transmission.isAuto && this.car.gear > 1) {
|
|
60
|
+
this.car.gear = 0;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.car.gear--;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
this.directionsInput.output$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$)).subscribe(d => {
|
|
68
|
+
moveDirection = d;
|
|
69
|
+
});
|
|
70
|
+
this.tick$
|
|
71
|
+
.pipe((0, rxjs_1.takeUntil)(this._onRemoved$), (0, operators_1.map)(() => {
|
|
72
|
+
const direction = [0, 0];
|
|
73
|
+
if (moveDirection.leftRight !== undefined)
|
|
74
|
+
direction[0] = moveDirection.leftRight ? -1 : 1;
|
|
75
|
+
if (moveDirection.upDown !== undefined)
|
|
76
|
+
direction[1] = moveDirection.upDown ? 1 : -1;
|
|
77
|
+
return direction;
|
|
78
|
+
}))
|
|
79
|
+
.subscribe(([x, y]) => {
|
|
80
|
+
this.x$.next(x);
|
|
81
|
+
this.y$.next(y);
|
|
82
|
+
});
|
|
83
|
+
(0, rxjs_1.combineLatest)([
|
|
84
|
+
this.x$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$), (0, operators_1.distinctUntilChanged)(), this.pairTickerPipe),
|
|
85
|
+
this.y$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$), (0, operators_1.distinctUntilChanged)()),
|
|
86
|
+
]).subscribe(([x, y]) => {
|
|
87
|
+
if (this.car) {
|
|
88
|
+
this.car.setXAxisControlValue(x);
|
|
89
|
+
this.car.setYAxisControlValue(y);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
yield this.directionsInput.start();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
onRemoved() {
|
|
96
|
+
const _super = Object.create(null, {
|
|
97
|
+
onRemoved: { get: () => super.onRemoved }
|
|
98
|
+
});
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
yield _super.onRemoved.call(this);
|
|
101
|
+
yield this.directionsInput.stop();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.CarKeyboardHandlingController = CarKeyboardHandlingController;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { MouseInput, MouseInputOptions } from '../../../../base/inputs/mouse.input';
|
|
2
|
+
import { Gg3dCameraEntity } from '../../gg-3d-camera.entity';
|
|
3
|
+
import { KeyboardInput } from '../../../../base/inputs/keyboard.input';
|
|
4
|
+
import { DirectionKeyboardInput, DirectionKeyboardKeymap } from '../../../../base/inputs/direction.keyboard-input';
|
|
5
|
+
import { GgEntity, GGTickOrder } from '../../../../base/entities/gg-entity';
|
|
6
|
+
import { GgWorld } from '../../../../base/gg-world';
|
|
7
|
+
/**
|
|
8
|
+
* Options for configuring a FreeCameraInput controller.
|
|
9
|
+
*/
|
|
10
|
+
export declare type FreeCameraControllerOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* A keymap for controlling camera movement, where each key corresponds to a movement direction.
|
|
13
|
+
*/
|
|
14
|
+
keymap: DirectionKeyboardKeymap;
|
|
15
|
+
/**
|
|
16
|
+
* Options for configuring camera movement.
|
|
17
|
+
*/
|
|
18
|
+
movementOptions: {
|
|
19
|
+
/**
|
|
20
|
+
* The speed of camera movement.
|
|
21
|
+
*/
|
|
22
|
+
speed: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Options for configuring mouse input.
|
|
26
|
+
*/
|
|
27
|
+
mouseOptions: MouseInputOptions;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A controller for a free-moving camera.
|
|
31
|
+
*/
|
|
32
|
+
export declare class FreeCameraController extends GgEntity {
|
|
33
|
+
protected readonly keyboard: KeyboardInput;
|
|
34
|
+
protected readonly camera: Gg3dCameraEntity;
|
|
35
|
+
protected readonly options: FreeCameraControllerOptions;
|
|
36
|
+
readonly tickOrder = GGTickOrder.INPUT_CONTROLLERS;
|
|
37
|
+
/**
|
|
38
|
+
* The mouse input controller used for camera rotation.
|
|
39
|
+
*/
|
|
40
|
+
protected readonly mouseInput: MouseInput;
|
|
41
|
+
/**
|
|
42
|
+
* The keyboard input controller used for camera movement.
|
|
43
|
+
*/
|
|
44
|
+
protected readonly directionsInput: DirectionKeyboardInput;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new FreeCameraInput instance.
|
|
47
|
+
* @param keyboard The keyboard input controller to use for camera movement.
|
|
48
|
+
* @param camera The camera entity to control.
|
|
49
|
+
* @param options Optional configuration options for the controller.
|
|
50
|
+
*/
|
|
51
|
+
constructor(keyboard: KeyboardInput, camera: Gg3dCameraEntity, options?: FreeCameraControllerOptions);
|
|
52
|
+
onSpawned(world: GgWorld<any, any>): Promise<void>;
|
|
53
|
+
onRemoved(): Promise<void>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FreeCameraController = void 0;
|
|
13
|
+
const rxjs_1 = require("rxjs");
|
|
14
|
+
const mouse_input_1 = require("../../../../base/inputs/mouse.input");
|
|
15
|
+
const point3_1 = require("../../../../base/math/point3");
|
|
16
|
+
const point2_1 = require("../../../../base/math/point2");
|
|
17
|
+
const quaternion_1 = require("../../../../base/math/quaternion");
|
|
18
|
+
const direction_keyboard_input_1 = require("../../../../base/inputs/direction.keyboard-input");
|
|
19
|
+
const gg_entity_1 = require("../../../../base/entities/gg-entity");
|
|
20
|
+
/**
|
|
21
|
+
* A controller for a free-moving camera.
|
|
22
|
+
*/
|
|
23
|
+
class FreeCameraController extends gg_entity_1.GgEntity {
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new FreeCameraInput instance.
|
|
26
|
+
* @param keyboard The keyboard input controller to use for camera movement.
|
|
27
|
+
* @param camera The camera entity to control.
|
|
28
|
+
* @param options Optional configuration options for the controller.
|
|
29
|
+
*/
|
|
30
|
+
constructor(keyboard, camera, options = {
|
|
31
|
+
keymap: 'wasd',
|
|
32
|
+
movementOptions: { speed: 0.5 },
|
|
33
|
+
mouseOptions: {},
|
|
34
|
+
}) {
|
|
35
|
+
super();
|
|
36
|
+
this.keyboard = keyboard;
|
|
37
|
+
this.camera = camera;
|
|
38
|
+
this.options = options;
|
|
39
|
+
this.tickOrder = gg_entity_1.GGTickOrder.INPUT_CONTROLLERS;
|
|
40
|
+
this.mouseInput = new mouse_input_1.MouseInput(options.mouseOptions);
|
|
41
|
+
this.directionsInput = new direction_keyboard_input_1.DirectionKeyboardInput(keyboard, options.keymap);
|
|
42
|
+
}
|
|
43
|
+
onSpawned(world) {
|
|
44
|
+
const _super = Object.create(null, {
|
|
45
|
+
onSpawned: { get: () => super.onSpawned }
|
|
46
|
+
});
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
yield _super.onSpawned.call(this, world);
|
|
49
|
+
// Subscribe to keyboard input for movement controls
|
|
50
|
+
let controls = { direction: {}, rest: [] };
|
|
51
|
+
const keys = ['KeyE', 'KeyQ'];
|
|
52
|
+
if (this.camera.object3D.supportsFov) {
|
|
53
|
+
keys.push('KeyZ', 'KeyC');
|
|
54
|
+
}
|
|
55
|
+
this.directionsInput.output$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$)).subscribe(d => {
|
|
56
|
+
controls.direction = d;
|
|
57
|
+
});
|
|
58
|
+
(0, rxjs_1.combineLatest)(keys.map(c => this.keyboard.bind(c)))
|
|
59
|
+
.pipe((0, rxjs_1.takeUntil)(this._onRemoved$))
|
|
60
|
+
.subscribe((d) => {
|
|
61
|
+
controls.rest = d;
|
|
62
|
+
});
|
|
63
|
+
// Subscribe to mouse input for camera rotation
|
|
64
|
+
let rotationDelta = { x: 0, y: 0 };
|
|
65
|
+
this.mouseInput.delta$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$)).subscribe(delta => {
|
|
66
|
+
rotationDelta = point2_1.Pnt2.add(rotationDelta, delta);
|
|
67
|
+
});
|
|
68
|
+
// Setup updating camera position and rotation based on input
|
|
69
|
+
this.camera.tick$.pipe((0, rxjs_1.takeUntil)(this._onRemoved$)).subscribe(() => {
|
|
70
|
+
let translateVector = { x: 0, y: 0, z: 0 };
|
|
71
|
+
const [u, d, zo, zi] = controls.rest;
|
|
72
|
+
if (controls.direction.upDown !== undefined)
|
|
73
|
+
translateVector.z = controls.direction.upDown ? -1 : 1;
|
|
74
|
+
if (controls.direction.leftRight !== undefined)
|
|
75
|
+
translateVector.x = controls.direction.leftRight ? -1 : 1;
|
|
76
|
+
if (u != d)
|
|
77
|
+
translateVector.y = d ? -1 : 1;
|
|
78
|
+
if (zo != zi)
|
|
79
|
+
this.camera.object3D.fov += zo ? 1 : -1;
|
|
80
|
+
this.camera.position = point3_1.Pnt3.add(this.camera.position, point3_1.Pnt3.rot(point3_1.Pnt3.scalarMult(point3_1.Pnt3.norm(translateVector), this.options.movementOptions.speed), this.camera.rotation));
|
|
81
|
+
if (rotationDelta.x != 0 || rotationDelta.y != 0) {
|
|
82
|
+
this.camera.rotation = quaternion_1.Qtrn.combineRotations(quaternion_1.Qtrn.fromAngle({ x: 0, y: 0, z: 1 }, -rotationDelta.x / 300), this.camera.rotation, quaternion_1.Qtrn.fromAngle({ x: 1, y: 0, z: 0 }, -rotationDelta.y / 300));
|
|
83
|
+
rotationDelta = { x: 0, y: 0 };
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// start input
|
|
87
|
+
yield this.mouseInput.start();
|
|
88
|
+
yield this.directionsInput.start();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
onRemoved() {
|
|
92
|
+
const _super = Object.create(null, {
|
|
93
|
+
onRemoved: { get: () => super.onRemoved }
|
|
94
|
+
});
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
yield _super.onRemoved.call(this);
|
|
97
|
+
yield this.mouseInput.stop(true);
|
|
98
|
+
yield this.directionsInput.stop();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.FreeCameraController = FreeCameraController;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
2
1
|
import { GgPositionable3dEntity } from './gg-positionable-3d-entity';
|
|
3
|
-
import { ITickListener } from '../../base/entities/interfaces/i-tick-listener';
|
|
4
2
|
import { Point3, Point4 } from '../../base/models/points';
|
|
5
3
|
import { Gg3dWorld } from '../gg-3d-world';
|
|
6
4
|
import { IGg3dBody, IGg3dObject } from '../interfaces';
|
|
7
|
-
|
|
5
|
+
import { GGTickOrder } from '../../base/entities/gg-entity';
|
|
6
|
+
export declare class Gg3dEntity extends GgPositionable3dEntity {
|
|
8
7
|
readonly object3D: IGg3dObject | null;
|
|
9
8
|
readonly objectBody: IGg3dBody | null;
|
|
10
|
-
readonly
|
|
11
|
-
readonly tickOrder = 750;
|
|
9
|
+
readonly tickOrder = GGTickOrder.OBJECTS_BINDING;
|
|
12
10
|
get position(): Point3;
|
|
13
11
|
set position(value: Point3);
|
|
14
12
|
get rotation(): Point4;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Gg3dEntity = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
4
|
const gg_positionable_3d_entity_1 = require("./gg-positionable-3d-entity");
|
|
5
|
+
const gg_entity_1 = require("../../base/entities/gg-entity");
|
|
6
6
|
class Gg3dEntity extends gg_positionable_3d_entity_1.GgPositionable3dEntity {
|
|
7
7
|
constructor(object3D, objectBody = null) {
|
|
8
8
|
super();
|
|
9
9
|
this.object3D = object3D;
|
|
10
10
|
this.objectBody = objectBody;
|
|
11
|
-
this.
|
|
12
|
-
this.tickOrder = 750;
|
|
11
|
+
this.tickOrder = gg_entity_1.GGTickOrder.OBJECTS_BINDING;
|
|
13
12
|
if (objectBody) {
|
|
14
13
|
objectBody.entity = this;
|
|
15
14
|
this.tick$.subscribe(() => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
|
2
2
|
import { Point3, Point4 } from '../../base/models/points';
|
|
3
3
|
import { Graph } from '../../base/data-structures/graph';
|
|
4
|
-
import { GgEntity } from '../../base/entities/gg-entity';
|
|
5
|
-
import { ITickListener } from '../../base/entities/interfaces/i-tick-listener';
|
|
4
|
+
import { GgEntity, GGTickOrder } from '../../base/entities/gg-entity';
|
|
6
5
|
import { GgPositionable3dEntity } from './gg-positionable-3d-entity';
|
|
7
6
|
import { Gg3dWorld } from '../gg-3d-world';
|
|
8
7
|
import { Gg3dEntity } from './gg-3d-entity';
|
|
@@ -23,10 +22,9 @@ export declare type Gg3dMapGraphEntityOptions = {
|
|
|
23
22
|
loadDepth: number;
|
|
24
23
|
inertia: number;
|
|
25
24
|
};
|
|
26
|
-
export declare class Gg3dMapGraphEntity extends GgEntity
|
|
25
|
+
export declare class Gg3dMapGraphEntity extends GgEntity {
|
|
27
26
|
readonly mapGraph: MapGraph;
|
|
28
|
-
readonly
|
|
29
|
-
readonly tickOrder = 1500;
|
|
27
|
+
readonly tickOrder = GGTickOrder.POST_RENDERING;
|
|
30
28
|
readonly loaderCursorEntity$: BehaviorSubject<GgPositionable3dEntity | null>;
|
|
31
29
|
readonly loaded: Map<MapGraphNodeType, GgPositionable3dEntity[]>;
|
|
32
30
|
private _initialLoadComplete$;
|
|
@@ -69,8 +69,7 @@ class Gg3dMapGraphEntity extends gg_entity_1.GgEntity {
|
|
|
69
69
|
constructor(mapGraph, options = {}) {
|
|
70
70
|
super();
|
|
71
71
|
this.mapGraph = mapGraph;
|
|
72
|
-
this.
|
|
73
|
-
this.tickOrder = 1500;
|
|
72
|
+
this.tickOrder = gg_entity_1.GGTickOrder.POST_RENDERING;
|
|
74
73
|
this.loaderCursorEntity$ = new rxjs_1.BehaviorSubject(null);
|
|
75
74
|
this.loaded = new Map();
|
|
76
75
|
this._initialLoadComplete$ = new rxjs_1.BehaviorSubject(false);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
import { Input } from '../../base/inputs/input';
|
|
3
|
+
import { KeyboardInput } from '../../base/inputs/keyboard.input';
|
|
4
|
+
import { Gg3dRaycastVehicleEntity } from '../entities/gg-3d-raycast-vehicle.entity';
|
|
5
|
+
import { DirectionKeyboardInput, DirectionKeyboardKeymap } from '../../base/inputs/direction.keyboard-input';
|
|
6
|
+
export declare type CarKeyboardControllerOptions = {
|
|
7
|
+
keymap: DirectionKeyboardKeymap;
|
|
8
|
+
gearUpDownKeys: [string, string];
|
|
9
|
+
};
|
|
10
|
+
export declare class CarKeyboardInput extends Input {
|
|
11
|
+
protected readonly keyboard: KeyboardInput;
|
|
12
|
+
protected readonly options: CarKeyboardControllerOptions;
|
|
13
|
+
protected readonly directionsInput: DirectionKeyboardInput;
|
|
14
|
+
protected readonly x$: BehaviorSubject<number>;
|
|
15
|
+
protected readonly y$: BehaviorSubject<number>;
|
|
16
|
+
protected lastX: number;
|
|
17
|
+
protected readonly car$: BehaviorSubject<Gg3dRaycastVehicleEntity>;
|
|
18
|
+
set car(value: Gg3dRaycastVehicleEntity);
|
|
19
|
+
get car(): Gg3dRaycastVehicleEntity;
|
|
20
|
+
switchingGearsEnabled: boolean;
|
|
21
|
+
pairTickerPipe: import("rxjs").UnaryFunction<import("rxjs").Observable<number>, import("rxjs").Observable<number>>;
|
|
22
|
+
constructor(keyboard: KeyboardInput, car: Gg3dRaycastVehicleEntity, options?: CarKeyboardControllerOptions);
|
|
23
|
+
protected startInternal(): Promise<void>;
|
|
24
|
+
protected stopInternal(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CarKeyboardInput = void 0;
|
|
13
|
+
const rxjs_1 = require("rxjs");
|
|
14
|
+
const operators_1 = require("rxjs/operators");
|
|
15
|
+
const input_1 = require("../../base/inputs/input");
|
|
16
|
+
const direction_keyboard_input_1 = require("../../base/inputs/direction.keyboard-input");
|
|
17
|
+
// TODO pass as settings
|
|
18
|
+
// TODO smooth y?
|
|
19
|
+
const TICKER_INTERVAL = 16;
|
|
20
|
+
const TICKER_MAX_STEPS = 10;
|
|
21
|
+
class CarKeyboardInput extends input_1.Input {
|
|
22
|
+
constructor(keyboard, car, options = { keymap: 'arrows', gearUpDownKeys: ['KeyA', 'KeyZ'] }) {
|
|
23
|
+
super();
|
|
24
|
+
this.keyboard = keyboard;
|
|
25
|
+
this.options = options;
|
|
26
|
+
// emits values -1 - 1; -1 = full turn left; 1 = full turn right
|
|
27
|
+
this.x$ = new rxjs_1.BehaviorSubject(0);
|
|
28
|
+
// emits values -1 - 1; -1 = full brake; 1 = full acceleration
|
|
29
|
+
this.y$ = new rxjs_1.BehaviorSubject(0);
|
|
30
|
+
this.lastX = 0;
|
|
31
|
+
this.car$ = new rxjs_1.BehaviorSubject(null);
|
|
32
|
+
this.switchingGearsEnabled = true;
|
|
33
|
+
this.pairTickerPipe = (0, rxjs_1.pipe)((0, operators_1.startWith)(0), (0, operators_1.pairwise)(), (0, operators_1.map)(([beforeValue, afterValue]) => [this.lastX, afterValue]), (0, operators_1.switchMap)(([beforeValue, afterValue]) => (0, rxjs_1.interval)(TICKER_INTERVAL).pipe((0, operators_1.take)(TICKER_MAX_STEPS), (0, operators_1.map)(count => ++count), (0, operators_1.map)(count => beforeValue * ((TICKER_MAX_STEPS - count) / TICKER_MAX_STEPS) + afterValue * (count / TICKER_MAX_STEPS)), (0, operators_1.tap)(x => {
|
|
34
|
+
this.lastX = x;
|
|
35
|
+
}))));
|
|
36
|
+
this.car$.next(car);
|
|
37
|
+
this.directionsInput = new direction_keyboard_input_1.DirectionKeyboardInput(keyboard, options.keymap);
|
|
38
|
+
}
|
|
39
|
+
set car(value) {
|
|
40
|
+
this.car$.next(value);
|
|
41
|
+
}
|
|
42
|
+
get car() {
|
|
43
|
+
return this.car$.getValue();
|
|
44
|
+
}
|
|
45
|
+
startInternal() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
let moveDirection = {};
|
|
48
|
+
this.keyboard
|
|
49
|
+
.bind(this.options.gearUpDownKeys[0])
|
|
50
|
+
.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, rxjs_1.filter)(x => this.switchingGearsEnabled && !!x))
|
|
51
|
+
.subscribe(() => {
|
|
52
|
+
if (this.car$.getValue() &&
|
|
53
|
+
(!this.car$.getValue().carProperties.transmission.isAuto || this.car$.getValue().gear <= 0)) {
|
|
54
|
+
this.car$.getValue().gear++;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.keyboard
|
|
58
|
+
.bind(this.options.gearUpDownKeys[1])
|
|
59
|
+
.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, rxjs_1.filter)(x => this.switchingGearsEnabled && !!x))
|
|
60
|
+
.subscribe(() => {
|
|
61
|
+
if (this.car$.getValue().carProperties.transmission.isAuto && this.car.gear > 1) {
|
|
62
|
+
this.car$.getValue().gear = 0;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.car$.getValue().gear--;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
this.directionsInput.output$.pipe((0, rxjs_1.takeUntil)(this.stop$)).subscribe(d => {
|
|
69
|
+
moveDirection = d;
|
|
70
|
+
});
|
|
71
|
+
this.car$
|
|
72
|
+
.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, operators_1.switchMap)(c => c.tick$), (0, rxjs_1.takeUntil)(this.stop$), (0, operators_1.map)(() => {
|
|
73
|
+
const direction = [0, 0];
|
|
74
|
+
if (moveDirection.leftRight !== undefined)
|
|
75
|
+
direction[0] = moveDirection.leftRight ? -1 : 1;
|
|
76
|
+
if (moveDirection.upDown !== undefined)
|
|
77
|
+
direction[1] = moveDirection.upDown ? 1 : -1;
|
|
78
|
+
return direction;
|
|
79
|
+
}))
|
|
80
|
+
.subscribe(([x, y]) => {
|
|
81
|
+
this.x$.next(x);
|
|
82
|
+
this.y$.next(y);
|
|
83
|
+
});
|
|
84
|
+
(0, rxjs_1.combineLatest)([
|
|
85
|
+
this.x$.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, operators_1.distinctUntilChanged)(), this.pairTickerPipe),
|
|
86
|
+
this.y$.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, operators_1.distinctUntilChanged)()),
|
|
87
|
+
]).subscribe(([x, y]) => {
|
|
88
|
+
this.car$.getValue().setXAxisControlValue(x);
|
|
89
|
+
this.car$.getValue().setYAxisControlValue(y);
|
|
90
|
+
});
|
|
91
|
+
yield this.directionsInput.start();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
stopInternal() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
yield this.directionsInput.stop();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.CarKeyboardInput = CarKeyboardInput;
|