@gg-web-engine/core 0.0.2 → 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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AnimationFunction, AnimationMixer } from '../../../base/entities/controllers/animation-mixer';
|
|
2
|
+
import { Point2 } from '../../../base/models/points';
|
|
3
|
+
import { Gg2dEntity } from '../gg-2d-entity';
|
|
4
|
+
import { Gg2dWorld } from '../../gg-2d-world';
|
|
5
|
+
declare type Positioning2d = {
|
|
6
|
+
position: Point2;
|
|
7
|
+
rotation: number;
|
|
8
|
+
};
|
|
9
|
+
export declare class Entity2dPositioningAnimator<T extends Gg2dEntity = Gg2dEntity> extends AnimationMixer<Positioning2d> {
|
|
10
|
+
entity: T;
|
|
11
|
+
protected _animationFunction: AnimationFunction<Positioning2d>;
|
|
12
|
+
constructor(entity: T, _animationFunction: AnimationFunction<Positioning2d>);
|
|
13
|
+
onSpawned(world: Gg2dWorld): void;
|
|
14
|
+
protected applyPositioning(value: Positioning2d): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity2dPositioningAnimator = void 0;
|
|
4
|
+
const animation_mixer_1 = require("../../../base/entities/controllers/animation-mixer");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const point2_1 = require("../../../base/math/point2");
|
|
7
|
+
const numbers_1 = require("../../../base/math/numbers");
|
|
8
|
+
class Entity2dPositioningAnimator extends animation_mixer_1.AnimationMixer {
|
|
9
|
+
constructor(entity, _animationFunction) {
|
|
10
|
+
super(_animationFunction, (a, b, t) => ({
|
|
11
|
+
position: point2_1.Pnt2.lerp(a.position, b.position, t),
|
|
12
|
+
rotation: (0, numbers_1.lerpNumber)(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.removed$)).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.Entity2dPositioningAnimator = Entity2dPositioningAnimator;
|
|
@@ -9,10 +9,18 @@ export declare class Gg2dEntity extends GgPositionable2dEntity implements ITickL
|
|
|
9
9
|
readonly objectBody: IGg2dBody | null;
|
|
10
10
|
readonly tick$: Subject<[number, number]>;
|
|
11
11
|
readonly tickOrder = 750;
|
|
12
|
-
|
|
12
|
+
get position(): Point2;
|
|
13
13
|
set position(value: Point2);
|
|
14
|
+
get rotation(): number;
|
|
14
15
|
set rotation(value: number);
|
|
16
|
+
get scale(): Point2;
|
|
15
17
|
set scale(value: Point2);
|
|
18
|
+
get visible(): boolean;
|
|
19
|
+
set visible(value: boolean);
|
|
20
|
+
/**
|
|
21
|
+
* Synchronize physics body transform with entity (and object2d if defined)
|
|
22
|
+
* */
|
|
23
|
+
protected runTransformBinding(objectBody: IGg2dBody, object2D: IGg2dObject | null): void;
|
|
16
24
|
constructor(object2D: IGg2dObject | null, objectBody: IGg2dBody | null);
|
|
17
25
|
onSpawned(world: Gg2dWorld): void;
|
|
18
26
|
onRemoved(): void;
|
|
@@ -10,25 +10,27 @@ class Gg2dEntity extends gg_positionable_2d_entity_1.GgPositionable2dEntity {
|
|
|
10
10
|
this.objectBody = objectBody;
|
|
11
11
|
this.tick$ = new rxjs_1.Subject();
|
|
12
12
|
this.tickOrder = 750;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
const pos = objectBody.position;
|
|
18
|
-
const rot = objectBody.rotation;
|
|
19
|
-
object2D.position = pos;
|
|
20
|
-
object2D.rotation = rot;
|
|
21
|
-
this._position$.next(pos);
|
|
22
|
-
this._rotation$.next(rot);
|
|
13
|
+
if (objectBody) {
|
|
14
|
+
objectBody.entity = this;
|
|
15
|
+
this.tick$.subscribe(() => {
|
|
16
|
+
this.runTransformBinding(objectBody, object2D);
|
|
23
17
|
});
|
|
18
|
+
this.runTransformBinding(objectBody, object2D);
|
|
19
|
+
this.name = objectBody.name;
|
|
24
20
|
}
|
|
25
|
-
else if (
|
|
26
|
-
|
|
21
|
+
else if (object2D) {
|
|
22
|
+
super.position = object2D.position;
|
|
23
|
+
super.rotation = object2D.rotation;
|
|
24
|
+
super.scale = object2D.scale;
|
|
25
|
+
this.name = object2D.name;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
else {
|
|
28
|
+
throw new Error('Cannot create entity without an object2D and a body');
|
|
30
29
|
}
|
|
31
30
|
}
|
|
31
|
+
get position() {
|
|
32
|
+
return super.position;
|
|
33
|
+
}
|
|
32
34
|
set position(value) {
|
|
33
35
|
if (this.object2D) {
|
|
34
36
|
this.object2D.position = value;
|
|
@@ -38,6 +40,9 @@ class Gg2dEntity extends gg_positionable_2d_entity_1.GgPositionable2dEntity {
|
|
|
38
40
|
}
|
|
39
41
|
super.position = value;
|
|
40
42
|
}
|
|
43
|
+
get rotation() {
|
|
44
|
+
return super.rotation;
|
|
45
|
+
}
|
|
41
46
|
set rotation(value) {
|
|
42
47
|
if (this.object2D) {
|
|
43
48
|
this.object2D.rotation = value;
|
|
@@ -47,6 +52,9 @@ class Gg2dEntity extends gg_positionable_2d_entity_1.GgPositionable2dEntity {
|
|
|
47
52
|
}
|
|
48
53
|
super.rotation = value;
|
|
49
54
|
}
|
|
55
|
+
get scale() {
|
|
56
|
+
return super.scale;
|
|
57
|
+
}
|
|
50
58
|
set scale(value) {
|
|
51
59
|
if (this.object2D) {
|
|
52
60
|
this.object2D.scale = value;
|
|
@@ -56,6 +64,33 @@ class Gg2dEntity extends gg_positionable_2d_entity_1.GgPositionable2dEntity {
|
|
|
56
64
|
}
|
|
57
65
|
super.scale = value;
|
|
58
66
|
}
|
|
67
|
+
get visible() {
|
|
68
|
+
var _a;
|
|
69
|
+
return !!((_a = this.object2D) === null || _a === void 0 ? void 0 : _a.visible);
|
|
70
|
+
}
|
|
71
|
+
set visible(value) {
|
|
72
|
+
if (this.object2D) {
|
|
73
|
+
this.object2D.visible = value;
|
|
74
|
+
}
|
|
75
|
+
for (const entity of this._children) {
|
|
76
|
+
if (entity instanceof Gg2dEntity) {
|
|
77
|
+
entity.visible = value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Synchronize physics body transform with entity (and object2d if defined)
|
|
83
|
+
* */
|
|
84
|
+
runTransformBinding(objectBody, object2D) {
|
|
85
|
+
const pos = objectBody.position;
|
|
86
|
+
const quat = objectBody.rotation;
|
|
87
|
+
if (object2D) {
|
|
88
|
+
object2D.position = pos;
|
|
89
|
+
object2D.rotation = quat;
|
|
90
|
+
}
|
|
91
|
+
this._position$.next(pos);
|
|
92
|
+
this._rotation$.next(quat);
|
|
93
|
+
}
|
|
59
94
|
onSpawned(world) {
|
|
60
95
|
var _a, _b;
|
|
61
96
|
super.onSpawned(world);
|
|
@@ -69,10 +104,8 @@ class Gg2dEntity extends gg_positionable_2d_entity_1.GgPositionable2dEntity {
|
|
|
69
104
|
super.onRemoved();
|
|
70
105
|
}
|
|
71
106
|
dispose() {
|
|
72
|
-
var _a;
|
|
73
107
|
super.dispose();
|
|
74
|
-
|
|
75
|
-
this.tickSub = null;
|
|
108
|
+
this.tick$.unsubscribe();
|
|
76
109
|
if (this.object2D) {
|
|
77
110
|
this.object2D.dispose();
|
|
78
111
|
}
|
package/dist/2d/gg-2d-world.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { GgWorld } from '../base/gg-world';
|
|
2
2
|
import { Point2 } from '../base/models/points';
|
|
3
3
|
import { IGg2dPhysicsWorld, IGg2dVisualScene } from './interfaces';
|
|
4
|
+
import { BodyShape2DDescriptor } from './models/shapes';
|
|
5
|
+
import { Gg2dEntity } from './entities/gg-2d-entity';
|
|
4
6
|
export declare class Gg2dWorld<V extends IGg2dVisualScene = IGg2dVisualScene, P extends IGg2dPhysicsWorld = IGg2dPhysicsWorld> extends GgWorld<Point2, number, V, P> {
|
|
5
7
|
readonly visualScene: V;
|
|
6
8
|
readonly physicsWorld: P;
|
|
7
9
|
protected readonly consoleEnabled: boolean;
|
|
8
10
|
constructor(visualScene: V, physicsWorld: P, consoleEnabled?: boolean);
|
|
11
|
+
addPrimitiveRigidBody(descr: BodyShape2DDescriptor, position?: Point2, rotation?: number): Gg2dEntity;
|
|
9
12
|
}
|
package/dist/2d/gg-2d-world.js
CHANGED
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Gg2dWorld = void 0;
|
|
13
13
|
const gg_world_1 = require("../base/gg-world");
|
|
14
|
+
const gg_2d_entity_1 = require("./entities/gg-2d-entity");
|
|
14
15
|
class Gg2dWorld extends gg_world_1.GgWorld {
|
|
15
16
|
constructor(visualScene, physicsWorld, consoleEnabled = false) {
|
|
16
17
|
super(visualScene, physicsWorld, consoleEnabled);
|
|
@@ -30,5 +31,15 @@ class Gg2dWorld extends gg_world_1.GgWorld {
|
|
|
30
31
|
'{x: 0, y: value}, 2 arguments set the whole vector. Default value is "9.82" or "0 9.82"');
|
|
31
32
|
}
|
|
32
33
|
}
|
|
34
|
+
addPrimitiveRigidBody(descr, position = {
|
|
35
|
+
x: 0,
|
|
36
|
+
y: 0,
|
|
37
|
+
}, rotation = 0) {
|
|
38
|
+
const entity = new gg_2d_entity_1.Gg2dEntity(this.visualScene.factory.createPrimitive(descr.shape), this.physicsWorld.factory.createRigidBody(descr));
|
|
39
|
+
entity.position = position;
|
|
40
|
+
entity.rotation = rotation;
|
|
41
|
+
this.addEntity(entity);
|
|
42
|
+
return entity;
|
|
43
|
+
}
|
|
33
44
|
}
|
|
34
45
|
exports.Gg2dWorld = Gg2dWorld;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { BehaviorSubject } from 'rxjs';
|
|
1
|
+
import { BehaviorSubject, Subject } from 'rxjs';
|
|
2
2
|
import { IController } from '../../base/controllers/i-controller';
|
|
3
3
|
import { KeyboardController } from '../../base/controllers/keyboard.controller';
|
|
4
4
|
import { Gg3dRaycastVehicleEntity } from '../entities/gg-3d-raycast-vehicle.entity';
|
|
5
5
|
import { DirectionKeymap } from '../../base/controllers/common';
|
|
6
|
-
declare type CarKeyboardControllerOptions = {
|
|
6
|
+
export declare type CarKeyboardControllerOptions = {
|
|
7
7
|
keymap: DirectionKeymap;
|
|
8
8
|
gearUpDownKeys: [string, string];
|
|
9
9
|
};
|
|
10
10
|
export declare class CarKeyboardController implements IController {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
protected readonly keyboardController: KeyboardController;
|
|
12
|
+
protected readonly options: CarKeyboardControllerOptions;
|
|
13
|
+
protected readonly x$: BehaviorSubject<number>;
|
|
14
|
+
protected readonly y$: BehaviorSubject<number>;
|
|
15
|
+
protected lastX: number;
|
|
16
|
+
protected readonly stop$: Subject<void>;
|
|
17
17
|
protected readonly car$: BehaviorSubject<Gg3dRaycastVehicleEntity>;
|
|
18
|
-
pairTickerPipe: import("rxjs").UnaryFunction<import("rxjs").Observable<number>, import("rxjs").Observable<number>>;
|
|
19
18
|
set car(value: Gg3dRaycastVehicleEntity);
|
|
20
19
|
get car(): Gg3dRaycastVehicleEntity;
|
|
20
|
+
switchingGearsEnabled: boolean;
|
|
21
|
+
pairTickerPipe: import("rxjs").UnaryFunction<import("rxjs").Observable<number>, import("rxjs").Observable<number>>;
|
|
21
22
|
constructor(keyboardController: KeyboardController, car: Gg3dRaycastVehicleEntity, options?: CarKeyboardControllerOptions);
|
|
22
23
|
start(): Promise<void>;
|
|
23
24
|
stop(): Promise<void>;
|
|
24
25
|
}
|
|
25
|
-
export {};
|
|
@@ -28,6 +28,7 @@ class CarKeyboardController {
|
|
|
28
28
|
this.lastX = 0;
|
|
29
29
|
this.stop$ = new rxjs_1.Subject();
|
|
30
30
|
this.car$ = new rxjs_1.BehaviorSubject(null);
|
|
31
|
+
this.switchingGearsEnabled = true;
|
|
31
32
|
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 => {
|
|
32
33
|
this.lastX = x;
|
|
33
34
|
}))));
|
|
@@ -42,6 +43,26 @@ class CarKeyboardController {
|
|
|
42
43
|
start() {
|
|
43
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
45
|
let moveDirection = {};
|
|
46
|
+
this.keyboardController
|
|
47
|
+
.bind(this.options.gearUpDownKeys[0])
|
|
48
|
+
.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, rxjs_1.filter)(x => this.switchingGearsEnabled && !!x))
|
|
49
|
+
.subscribe(() => {
|
|
50
|
+
if (this.car$.getValue() &&
|
|
51
|
+
(!this.car$.getValue().carProperties.transmission.isAuto || this.car$.getValue().gear <= 0)) {
|
|
52
|
+
this.car$.getValue().gear++;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.keyboardController
|
|
56
|
+
.bind(this.options.gearUpDownKeys[1])
|
|
57
|
+
.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, rxjs_1.filter)(x => this.switchingGearsEnabled && !!x))
|
|
58
|
+
.subscribe(() => {
|
|
59
|
+
if (this.car$.getValue().carProperties.transmission.isAuto && this.car.gear > 1) {
|
|
60
|
+
this.car$.getValue().gear = 0;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.car$.getValue().gear--;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
45
66
|
(0, common_1.bindDirectionKeys)(this.keyboardController, this.options.keymap)
|
|
46
67
|
.pipe((0, rxjs_1.takeUntil)(this.stop$))
|
|
47
68
|
.subscribe(d => {
|
|
@@ -67,26 +88,6 @@ class CarKeyboardController {
|
|
|
67
88
|
this.car$.getValue().setXAxisControlValue(x);
|
|
68
89
|
this.car$.getValue().setYAxisControlValue(y);
|
|
69
90
|
});
|
|
70
|
-
this.keyboardController
|
|
71
|
-
.bind(this.options.gearUpDownKeys[0])
|
|
72
|
-
.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, rxjs_1.filter)(x => !!x))
|
|
73
|
-
.subscribe(() => {
|
|
74
|
-
if (this.car$.getValue() &&
|
|
75
|
-
(!this.car$.getValue().carProperties.transmission.isAuto || this.car$.getValue().gear <= 0)) {
|
|
76
|
-
this.car$.getValue().gear++;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
this.keyboardController
|
|
80
|
-
.bind(this.options.gearUpDownKeys[1])
|
|
81
|
-
.pipe((0, rxjs_1.takeUntil)(this.stop$), (0, rxjs_1.filter)(x => !!x))
|
|
82
|
-
.subscribe(() => {
|
|
83
|
-
if (this.car$.getValue().carProperties.transmission.isAuto && this.car.gear > 1) {
|
|
84
|
-
this.car$.getValue().gear = 0;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.car$.getValue().gear--;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
93
|
stop() {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IController } from '../../base/controllers/i-controller';
|
|
2
|
-
import {
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
3
|
+
import { MouseController, MouseControllerOptions } from '../../base/controllers/mouse.controller';
|
|
3
4
|
import { Gg3dCameraEntity } from '../entities/gg-3d-camera.entity';
|
|
4
5
|
import { KeyboardController } from '../../base/controllers/keyboard.controller';
|
|
5
6
|
import { DirectionKeymap } from '../../base/controllers/common';
|
|
6
|
-
declare type FreeCameraControllerOptions = {
|
|
7
|
+
export declare type FreeCameraControllerOptions = {
|
|
7
8
|
keymap: DirectionKeymap;
|
|
8
9
|
movementOptions: {
|
|
9
10
|
speed: number;
|
|
@@ -11,13 +12,12 @@ declare type FreeCameraControllerOptions = {
|
|
|
11
12
|
mouseOptions: MouseControllerOptions;
|
|
12
13
|
};
|
|
13
14
|
export declare class FreeCameraController implements IController {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
protected readonly keyboardController: KeyboardController;
|
|
16
|
+
protected readonly camera: Gg3dCameraEntity;
|
|
17
|
+
protected readonly options: FreeCameraControllerOptions;
|
|
18
|
+
protected readonly mController: MouseController;
|
|
19
|
+
protected readonly stop$: Subject<void>;
|
|
19
20
|
constructor(keyboardController: KeyboardController, camera: Gg3dCameraEntity, options?: FreeCameraControllerOptions);
|
|
20
21
|
start(): Promise<void>;
|
|
21
22
|
stop(unlockPointer?: boolean): Promise<void>;
|
|
22
23
|
}
|
|
23
|
-
export {};
|
|
@@ -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.removed$)).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.removed$)).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;
|
|
@@ -3,5 +3,7 @@ import { Gg3dEntity } from './gg-3d-entity';
|
|
|
3
3
|
export declare class Gg3dCameraEntity<T extends IGg3dCamera = IGg3dCamera> extends Gg3dEntity {
|
|
4
4
|
readonly object3D: T;
|
|
5
5
|
readonly objectBody: IGg3dBody | null;
|
|
6
|
+
get fov(): number;
|
|
7
|
+
set fov(value: number);
|
|
6
8
|
constructor(object3D: T, objectBody?: IGg3dBody | null);
|
|
7
9
|
}
|
|
@@ -8,5 +8,11 @@ class Gg3dCameraEntity extends gg_3d_entity_1.Gg3dEntity {
|
|
|
8
8
|
this.object3D = object3D;
|
|
9
9
|
this.objectBody = objectBody;
|
|
10
10
|
}
|
|
11
|
+
get fov() {
|
|
12
|
+
return this.object3D.fov;
|
|
13
|
+
}
|
|
14
|
+
set fov(value) {
|
|
15
|
+
this.object3D.fov = value;
|
|
16
|
+
}
|
|
11
17
|
}
|
|
12
18
|
exports.Gg3dCameraEntity = Gg3dCameraEntity;
|
|
@@ -17,7 +17,10 @@ export declare class Gg3dEntity extends GgPositionable3dEntity implements ITickL
|
|
|
17
17
|
set scale(value: Point3);
|
|
18
18
|
get visible(): boolean;
|
|
19
19
|
set visible(value: boolean);
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Synchronize physics body transform with entity (and mesh if defined)
|
|
22
|
+
* */
|
|
23
|
+
protected runTransformBinding(objectBody: IGg3dBody, object3D: IGg3dObject | null): void;
|
|
21
24
|
constructor(object3D: IGg3dObject | null, objectBody?: IGg3dBody | null);
|
|
22
25
|
onSpawned(world: Gg3dWorld): void;
|
|
23
26
|
onRemoved(): void;
|
|
@@ -10,17 +10,22 @@ class Gg3dEntity extends gg_positionable_3d_entity_1.GgPositionable3dEntity {
|
|
|
10
10
|
this.objectBody = objectBody;
|
|
11
11
|
this.tick$ = new rxjs_1.Subject();
|
|
12
12
|
this.tickOrder = 750;
|
|
13
|
-
if (objectBody
|
|
13
|
+
if (objectBody) {
|
|
14
|
+
objectBody.entity = this;
|
|
14
15
|
this.tick$.subscribe(() => {
|
|
15
16
|
this.runTransformBinding(objectBody, object3D);
|
|
16
17
|
});
|
|
17
18
|
this.runTransformBinding(objectBody, object3D);
|
|
19
|
+
this.name = objectBody.name;
|
|
18
20
|
}
|
|
19
|
-
else if (
|
|
20
|
-
|
|
21
|
+
else if (object3D) {
|
|
22
|
+
super.position = object3D.position;
|
|
23
|
+
super.rotation = object3D.rotation;
|
|
24
|
+
super.scale = object3D.scale;
|
|
25
|
+
this.name = object3D.name;
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
else {
|
|
28
|
+
throw new Error('Cannot create entity without a mesh and a body');
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
get position() {
|
|
@@ -68,17 +73,21 @@ class Gg3dEntity extends gg_positionable_3d_entity_1.GgPositionable3dEntity {
|
|
|
68
73
|
this.object3D.visible = value;
|
|
69
74
|
}
|
|
70
75
|
for (const entity of this._children) {
|
|
71
|
-
if (entity instanceof Gg3dEntity
|
|
72
|
-
entity.
|
|
76
|
+
if (entity instanceof Gg3dEntity) {
|
|
77
|
+
entity.visible = value;
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Synchronize physics body transform with entity (and mesh if defined)
|
|
83
|
+
* */
|
|
76
84
|
runTransformBinding(objectBody, object3D) {
|
|
77
|
-
// bind physics body transform to mesh transform
|
|
78
85
|
const pos = objectBody.position;
|
|
79
86
|
const quat = objectBody.rotation;
|
|
80
|
-
object3D
|
|
81
|
-
|
|
87
|
+
if (object3D) {
|
|
88
|
+
object3D.position = pos;
|
|
89
|
+
object3D.rotation = quat;
|
|
90
|
+
}
|
|
82
91
|
this._position$.next(pos);
|
|
83
92
|
this._rotation$.next(quat);
|
|
84
93
|
}
|
|
@@ -7,7 +7,7 @@ import { GgPositionable3dEntity } from './gg-positionable-3d-entity';
|
|
|
7
7
|
import { Gg3dWorld } from '../gg-3d-world';
|
|
8
8
|
import { Gg3dEntity } from './gg-3d-entity';
|
|
9
9
|
import { LoadOptions, LoadResultWithProps } from '../loader';
|
|
10
|
-
declare type MapGraphNodeType = {
|
|
10
|
+
export declare type MapGraphNodeType = {
|
|
11
11
|
path: string;
|
|
12
12
|
position: Point3;
|
|
13
13
|
rotation?: Point4;
|
|
@@ -33,19 +33,21 @@ export declare class Gg3dMapGraphEntity extends GgEntity implements ITickListene
|
|
|
33
33
|
get initialLoadComplete$(): Observable<boolean>;
|
|
34
34
|
private _nearestDummy$;
|
|
35
35
|
get nearestDummy(): Graph<MapGraphNodeType> | null;
|
|
36
|
-
|
|
36
|
+
protected _chunkLoaded$: Subject<[LoadResultWithProps, {
|
|
37
|
+
position: Point3;
|
|
38
|
+
rotation: Point4;
|
|
39
|
+
}]>;
|
|
37
40
|
get chunkLoaded$(): Observable<[LoadResultWithProps, {
|
|
38
41
|
position: Point3;
|
|
39
42
|
rotation: Point4;
|
|
40
43
|
}]>;
|
|
41
44
|
get world(): Gg3dWorld | null;
|
|
42
45
|
protected _world: Gg3dWorld | null;
|
|
43
|
-
|
|
46
|
+
protected readonly mapGraphNodes: MapGraph[];
|
|
44
47
|
protected readonly options: Gg3dMapGraphEntityOptions;
|
|
45
48
|
constructor(mapGraph: MapGraph, options?: Partial<Gg3dMapGraphEntityOptions>);
|
|
46
49
|
onSpawned(world: Gg3dWorld): void;
|
|
47
50
|
onRemoved(): void;
|
|
48
|
-
protected loadChunk(node: MapGraphNodeType): Promise<Gg3dEntity[]>;
|
|
51
|
+
protected loadChunk(node: MapGraphNodeType): Promise<[Gg3dEntity[], LoadResultWithProps]>;
|
|
49
52
|
protected disposeChunk(node: MapGraphNodeType): void;
|
|
50
53
|
}
|
|
51
|
-
export {};
|
|
@@ -150,7 +150,7 @@ class Gg3dMapGraphEntity extends gg_entity_1.GgEntity {
|
|
|
150
150
|
loaded,
|
|
151
151
|
{ position: node.position, rotation: node.rotation || { x: 0, y: 0, z: 0, w: 1 } },
|
|
152
152
|
]);
|
|
153
|
-
return entities;
|
|
153
|
+
return [entities, loaded];
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
disposeChunk(node) {
|
|
@@ -2,6 +2,7 @@ import { Point3, Point4 } from '../../base/models/points';
|
|
|
2
2
|
import { Gg3dEntity } from './gg-3d-entity';
|
|
3
3
|
import { IGg3dBody, IGg3dObject, IGg3dRaycastVehicle } from '../interfaces';
|
|
4
4
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
5
|
+
import { GgPositionable3dEntity } from './gg-positionable-3d-entity';
|
|
5
6
|
import { Gg3dWorld } from '../gg-3d-world';
|
|
6
7
|
import { AxisDirection3 } from '../../base/models/axis-directions';
|
|
7
8
|
export declare type WheelOptions = {
|
|
@@ -52,9 +53,9 @@ export declare class Gg3dRaycastVehicleEntity extends Gg3dEntity {
|
|
|
52
53
|
readonly chassisBody: IGg3dRaycastVehicle;
|
|
53
54
|
readonly wheelObject: IGg3dObject | null;
|
|
54
55
|
readonly wheelObjectDirection: AxisDirection3;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
protected readonly wheels: (GgPositionable3dEntity | null)[];
|
|
57
|
+
protected readonly wheelLocalRotation: (Point4 | null)[];
|
|
58
|
+
protected readonly wheelLocalTranslation: Point3[];
|
|
58
59
|
protected readonly frontWheelsIndices: number[];
|
|
59
60
|
protected readonly tractionWheelIndices: number[];
|
|
60
61
|
readonly tractionWheelRadius: number;
|
|
@@ -96,8 +97,8 @@ export declare class Gg3dRaycastVehicleEntity extends Gg3dEntity {
|
|
|
96
97
|
constructor(carProperties: CarProperties, chassis3D: IGg3dObject | null, chassisBody: IGg3dRaycastVehicle, wheelObject?: IGg3dObject | null, wheelObjectDirection?: AxisDirection3);
|
|
97
98
|
onSpawned(world: Gg3dWorld): void;
|
|
98
99
|
protected runTransformBinding(objectBody: IGg3dBody, object3D: IGg3dObject): void;
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
protected get isTouchingGround(): boolean;
|
|
101
|
+
protected updateEngine(delta: number): void;
|
|
101
102
|
resetTo(options?: {
|
|
102
103
|
position?: Point3;
|
|
103
104
|
rotation?: Point4;
|
package/dist/3d/gg-3d-world.d.ts
CHANGED
|
@@ -2,10 +2,13 @@ import { GgWorld } from '../base/gg-world';
|
|
|
2
2
|
import { Point3, Point4 } from '../base/models/points';
|
|
3
3
|
import { IGg3dPhysicsWorld, IGg3dVisualScene } from './interfaces';
|
|
4
4
|
import { Gg3dLoader } from './loader';
|
|
5
|
+
import { Gg3dEntity } from './entities/gg-3d-entity';
|
|
6
|
+
import { BodyShape3DDescriptor } from './models/shapes';
|
|
5
7
|
export declare class Gg3dWorld<V extends IGg3dVisualScene = IGg3dVisualScene, P extends IGg3dPhysicsWorld = IGg3dPhysicsWorld> extends GgWorld<Point3, Point4, V, P> {
|
|
6
8
|
readonly visualScene: V;
|
|
7
9
|
readonly physicsWorld: P;
|
|
8
10
|
protected readonly consoleEnabled: boolean;
|
|
9
11
|
readonly loader: Gg3dLoader;
|
|
10
12
|
constructor(visualScene: V, physicsWorld: P, consoleEnabled?: boolean);
|
|
13
|
+
addPrimitiveRigidBody(descr: BodyShape3DDescriptor, position?: Point3, rotation?: Point4): Gg3dEntity;
|
|
11
14
|
}
|
package/dist/3d/gg-3d-world.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.Gg3dWorld = void 0;
|
|
13
13
|
const gg_world_1 = require("../base/gg-world");
|
|
14
14
|
const loader_1 = require("./loader");
|
|
15
|
+
const gg_3d_entity_1 = require("./entities/gg-3d-entity");
|
|
15
16
|
class Gg3dWorld extends gg_world_1.GgWorld {
|
|
16
17
|
constructor(visualScene, physicsWorld, consoleEnabled = false) {
|
|
17
18
|
super(visualScene, physicsWorld, consoleEnabled);
|
|
@@ -32,5 +33,16 @@ class Gg3dWorld extends gg_world_1.GgWorld {
|
|
|
32
33
|
'{x: 0, y: 0, z: -value}, 3 arguments set the whole vector. Default value is "9.82" or "0 0 -9.82"');
|
|
33
34
|
}
|
|
34
35
|
}
|
|
36
|
+
addPrimitiveRigidBody(descr, position = {
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
z: 0,
|
|
40
|
+
}, rotation = { x: 0, y: 0, z: 0, w: 1 }) {
|
|
41
|
+
const entity = new gg_3d_entity_1.Gg3dEntity(this.visualScene.factory.createPrimitive(descr.shape), this.physicsWorld.factory.createRigidBody(descr));
|
|
42
|
+
entity.position = position;
|
|
43
|
+
entity.rotation = rotation;
|
|
44
|
+
this.addEntity(entity);
|
|
45
|
+
return entity;
|
|
46
|
+
}
|
|
35
47
|
}
|
|
36
48
|
exports.Gg3dWorld = Gg3dWorld;
|