@gg-web-engine/core 0.0.28 → 0.0.30
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/components/physics/i-physics-world-2d.component.d.ts +2 -3
- package/dist/2d/components/physics/i-rigid-body-2d.component.d.ts +2 -2
- package/dist/2d/components/physics/i-trigger-2d.component.d.ts +4 -5
- package/dist/2d/components/rendering/i-display-object-2d.component.d.ts +2 -2
- package/dist/2d/components/rendering/i-renderer-2d.component.d.ts +2 -2
- package/dist/2d/components/rendering/i-visual-scene-2d.component.d.ts +3 -5
- package/dist/2d/entities/controllers/entity-2d-positioning.animator.d.ts +2 -2
- package/dist/2d/entities/entity-2d.d.ts +6 -9
- package/dist/2d/entities/i-renderable-2d.entity.d.ts +2 -3
- package/dist/2d/entities/renderer-2d.entity.d.ts +2 -3
- package/dist/2d/entities/trigger-2d.entity.d.ts +4 -3
- package/dist/2d/factories.d.ts +13 -10
- package/dist/2d/factories.js +8 -5
- package/dist/2d/gg-2d-world.d.ts +22 -6
- package/dist/2d/gg-2d-world.js +2 -2
- package/dist/3d/components/physics/i-physics-world-3d.component.d.ts +3 -5
- package/dist/3d/components/physics/i-raycast-vehicle.component.d.ts +3 -2
- package/dist/3d/components/physics/i-rigid-body-3d.component.d.ts +2 -2
- package/dist/3d/components/physics/i-trigger-3d.component.d.ts +4 -5
- package/dist/3d/components/rendering/i-camera.component.d.ts +2 -2
- package/dist/3d/components/rendering/i-display-object-3d.component.d.ts +2 -2
- package/dist/3d/components/rendering/i-renderer-3d.component.d.ts +3 -4
- package/dist/3d/components/rendering/i-visual-scene-3d.component.d.ts +4 -8
- package/dist/3d/entities/controllers/animators/camera-3d.animator.d.ts +6 -6
- package/dist/3d/entities/controllers/animators/entity-3d-positioning.animator.d.ts +2 -2
- package/dist/3d/entities/controllers/input/free-camera.controller.d.ts +1 -1
- package/dist/3d/entities/controllers/input/free-camera.controller.js +1 -1
- package/dist/3d/entities/controllers/input/orbit-camera.controller.d.ts +1 -1
- package/dist/3d/entities/controllers/input/orbit-camera.controller.js +1 -1
- package/dist/3d/entities/entity-3d.d.ts +5 -6
- package/dist/3d/entities/gg-car/gg-car.entity.d.ts +9 -8
- package/dist/3d/entities/gg-car/gg-car.entity.js +20 -8
- package/dist/3d/entities/i-renderable-3d.entity.d.ts +2 -3
- package/dist/3d/entities/map-graph-3d.entity.d.ts +20 -14
- package/dist/3d/entities/raycast-vehicle-3d.entity.d.ts +4 -4
- package/dist/3d/entities/raycast-vehicle-3d.entity.js +0 -1
- package/dist/3d/entities/renderer-3d.entity.d.ts +3 -5
- package/dist/3d/entities/trigger-3d.entity.d.ts +4 -3
- package/dist/3d/factories.d.ts +29 -13
- package/dist/3d/factories.js +12 -6
- package/dist/3d/gg-3d-world.d.ts +28 -7
- package/dist/3d/gg-3d-world.js +2 -2
- package/dist/3d/loader.d.ts +12 -14
- package/dist/3d/loaders.d.ts +5 -6
- package/dist/3d/models/shapes.d.ts +2 -0
- package/dist/base/components/i-world-component.d.ts +4 -6
- package/dist/base/components/physics/i-body.component.d.ts +10 -7
- package/dist/base/components/physics/i-physics-world.component.d.ts +6 -3
- package/dist/base/components/physics/i-rigid-body.component.d.ts +3 -3
- package/dist/base/components/physics/i-trigger.component.d.ts +5 -5
- package/dist/base/components/rendering/i-display-object.component.d.ts +6 -6
- package/dist/base/components/rendering/i-renderer.component.d.ts +7 -7
- package/dist/base/components/rendering/i-visual-scene.component.d.ts +4 -3
- package/dist/base/data-structures/bitmask.d.ts +30 -0
- package/dist/base/data-structures/bitmask.js +55 -0
- package/dist/base/entities/controllers/animation-mixer.d.ts +3 -3
- package/dist/base/entities/i-entity.d.ts +8 -10
- package/dist/base/entities/i-renderable.entity.d.ts +2 -3
- package/dist/base/entities/i-renderer.entity.d.ts +6 -7
- package/dist/base/gg-world.d.ts +17 -6
- package/dist/base/index.d.ts +1 -0
- package/dist/base/index.js +1 -0
- package/dist/base/interfaces/i-debug-physics-drawer.d.ts +2 -2
- package/dist/base/math/quaternion.d.ts +14 -0
- package/dist/base/math/quaternion.js +18 -0
- package/dist/base/models/body-options.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
|
2
2
|
import { Graph, IEntity, Point3, Point4, TickOrder } from '../../base';
|
|
3
|
-
import { Gg3dWorld } from '../gg-3d-world';
|
|
3
|
+
import { Gg3dWorld, PhysicsTypeDocRepo3D, VisualTypeDocRepo3D } from '../gg-3d-world';
|
|
4
4
|
import { Entity3d } from './entity-3d';
|
|
5
5
|
import { LoadOptions, LoadResultWithProps } from '../loader';
|
|
6
6
|
import { IPositionable3d } from '../interfaces/i-positionable-3d';
|
|
@@ -37,7 +37,7 @@ export declare type Gg3dMapGraphEntityOptions = {
|
|
|
37
37
|
loadDepth: number;
|
|
38
38
|
inertia: number;
|
|
39
39
|
};
|
|
40
|
-
export declare class MapGraph3dEntity extends IRenderable3dEntity {
|
|
40
|
+
export declare class MapGraph3dEntity<VTypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D, PTypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> extends IRenderable3dEntity<VTypeDoc, PTypeDoc> {
|
|
41
41
|
readonly mapGraph: MapGraph;
|
|
42
42
|
readonly tickOrder = TickOrder.POST_RENDERING;
|
|
43
43
|
readonly loaderCursorEntity$: BehaviorSubject<IPositionable3d | null>;
|
|
@@ -46,21 +46,27 @@ export declare class MapGraph3dEntity extends IRenderable3dEntity {
|
|
|
46
46
|
get initialLoadComplete$(): Observable<boolean>;
|
|
47
47
|
private _nearestDummy$;
|
|
48
48
|
get nearestDummy(): Graph<MapGraphNodeType> | null;
|
|
49
|
-
protected _chunkLoaded$: Subject<[
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
protected _chunkLoaded$: Subject<[
|
|
50
|
+
LoadResultWithProps<VTypeDoc, PTypeDoc>,
|
|
51
|
+
{
|
|
52
|
+
position: Point3;
|
|
53
|
+
rotation: Point4;
|
|
54
|
+
}
|
|
55
|
+
]>;
|
|
56
|
+
get chunkLoaded$(): Observable<[
|
|
57
|
+
LoadResultWithProps<VTypeDoc, PTypeDoc>,
|
|
58
|
+
{
|
|
59
|
+
position: Point3;
|
|
60
|
+
rotation: Point4;
|
|
61
|
+
}
|
|
62
|
+
]>;
|
|
63
|
+
get world(): Gg3dWorld<VTypeDoc, PTypeDoc> | null;
|
|
64
|
+
protected _world: Gg3dWorld<VTypeDoc, PTypeDoc> | null;
|
|
59
65
|
protected readonly mapGraphNodes: MapGraph[];
|
|
60
66
|
protected readonly options: Gg3dMapGraphEntityOptions;
|
|
61
67
|
constructor(mapGraph: MapGraph, options?: Partial<Gg3dMapGraphEntityOptions>);
|
|
62
|
-
onSpawned(world: Gg3dWorld): void;
|
|
68
|
+
onSpawned(world: Gg3dWorld<VTypeDoc, PTypeDoc>): void;
|
|
63
69
|
onRemoved(): void;
|
|
64
|
-
protected loadChunk(node: MapGraphNodeType): Promise<[Entity3d[], LoadResultWithProps]>;
|
|
70
|
+
protected loadChunk(node: MapGraphNodeType): Promise<[Entity3d<VTypeDoc, PTypeDoc>[], LoadResultWithProps<VTypeDoc, PTypeDoc>]>;
|
|
65
71
|
protected disposeChunk(node: MapGraphNodeType): void;
|
|
66
72
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AxisDirection3,
|
|
1
|
+
import { AxisDirection3, Point3, Point4 } from '../../base';
|
|
2
2
|
import { Entity3d } from './entity-3d';
|
|
3
3
|
import { IDisplayObject3dComponent } from '../components/rendering/i-display-object-3d.component';
|
|
4
4
|
import { IRaycastVehicleComponent, SuspensionOptions } from '../components/physics/i-raycast-vehicle.component';
|
|
5
5
|
import { IRigidBody3dComponent } from '../components/physics/i-rigid-body-3d.component';
|
|
6
|
-
import {
|
|
6
|
+
import { PhysicsTypeDocRepo3D, VisualTypeDocRepo3D } from '../gg-3d-world';
|
|
7
7
|
export declare type WheelDisplayOptions = {
|
|
8
8
|
displayObject?: IDisplayObject3dComponent;
|
|
9
9
|
wheelObjectDirection?: AxisDirection3;
|
|
@@ -39,11 +39,11 @@ export declare type RVEntityProperties = {
|
|
|
39
39
|
})[];
|
|
40
40
|
sharedWheelOptions?: RVEntitySharedWheelOptions;
|
|
41
41
|
});
|
|
42
|
-
export declare class RaycastVehicle3dEntity extends Entity3d {
|
|
42
|
+
export declare class RaycastVehicle3dEntity<VTypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D, PTypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> extends Entity3d<VTypeDoc, PTypeDoc> {
|
|
43
43
|
readonly carProperties: RVEntityProperties;
|
|
44
44
|
readonly chassis3D: IDisplayObject3dComponent | null;
|
|
45
45
|
readonly chassisBody: IRaycastVehicleComponent;
|
|
46
|
-
protected readonly wheels: (
|
|
46
|
+
protected readonly wheels: (Entity3d<VTypeDoc, PTypeDoc> | null)[];
|
|
47
47
|
protected readonly wheelLocalRotation: (Point4 | null)[];
|
|
48
48
|
protected readonly frontWheelsIndices: number[];
|
|
49
49
|
protected readonly rearWheelsIndices: number[];
|
|
@@ -124,7 +124,6 @@ export class RaycastVehicle3dEntity extends Entity3d {
|
|
|
124
124
|
}
|
|
125
125
|
runTransformBinding(objectBody, object3D) {
|
|
126
126
|
super.runTransformBinding(objectBody, object3D);
|
|
127
|
-
const carRotation = this.rotation;
|
|
128
127
|
for (const [i, wheel] of (this.wheels || []).entries()) {
|
|
129
128
|
if (!wheel) {
|
|
130
129
|
continue;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { IRendererEntity, Point3, Point4 } from '../../base';
|
|
2
|
-
import { IRenderer3dComponent } from '../components/rendering/i-renderer-3d.component';
|
|
3
|
-
import { IVisualScene3dComponent } from '../components/rendering/i-visual-scene-3d.component';
|
|
4
|
-
import { ICameraComponent } from '../components/rendering/i-camera.component';
|
|
5
2
|
import { IPositionable3d } from '../interfaces/i-positionable-3d';
|
|
6
|
-
|
|
3
|
+
import { VisualTypeDocRepo3D } from '../gg-3d-world';
|
|
4
|
+
export declare class Renderer3dEntity<TypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D> extends IRendererEntity<Point3, Point4, TypeDoc> implements IPositionable3d {
|
|
7
5
|
get position(): Point3;
|
|
8
6
|
set position(value: Point3);
|
|
9
7
|
get rotation(): Point4;
|
|
10
8
|
set rotation(value: Point4);
|
|
11
|
-
get camera():
|
|
9
|
+
get camera(): TypeDoc['camera'];
|
|
12
10
|
}
|
|
@@ -2,11 +2,12 @@ import { Observable } from 'rxjs';
|
|
|
2
2
|
import { ITrigger3dComponent } from '../components/physics/i-trigger-3d.component';
|
|
3
3
|
import { IPositionable3d } from '../interfaces/i-positionable-3d';
|
|
4
4
|
import { IEntity, Point3, Point4, TickOrder } from '../../base';
|
|
5
|
-
|
|
5
|
+
import { PhysicsTypeDocRepo3D, VisualTypeDocRepo3D } from '../gg-3d-world';
|
|
6
|
+
export declare class Trigger3dEntity<TypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> extends IEntity<Point3, Point4, VisualTypeDocRepo3D, TypeDoc> implements IPositionable3d {
|
|
6
7
|
readonly objectBody: ITrigger3dComponent;
|
|
7
8
|
readonly tickOrder = TickOrder.OBJECTS_BINDING;
|
|
8
|
-
get onEntityEntered(): Observable<IEntity & IPositionable3d>;
|
|
9
|
-
get onEntityLeft(): Observable<(IEntity & IPositionable3d) | null>;
|
|
9
|
+
get onEntityEntered(): Observable<IEntity<Point3, Point4, VisualTypeDocRepo3D, TypeDoc> & IPositionable3d>;
|
|
10
|
+
get onEntityLeft(): Observable<(IEntity<Point3, Point4, VisualTypeDocRepo3D, TypeDoc> & IPositionable3d) | null>;
|
|
10
11
|
private _position;
|
|
11
12
|
get position(): Point3;
|
|
12
13
|
set position(value: Point3);
|
package/dist/3d/factories.d.ts
CHANGED
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
import { BodyShape3DDescriptor, Shape3DDescriptor } from './models/shapes';
|
|
2
2
|
import { Point3, Point4 } from '../base';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
import { PhysicsTypeDocRepo3D, VisualTypeDocRepo3D } from './gg-3d-world';
|
|
4
|
+
export declare type DisplayObject3dOpts<Tex> = {
|
|
5
|
+
color?: number;
|
|
6
|
+
shading?: 'unlit' | 'standart' | 'phong';
|
|
7
|
+
diffuse?: Tex;
|
|
8
|
+
castShadow?: boolean;
|
|
9
|
+
receiveShadow?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare abstract class IDisplayObject3dComponentFactory<TypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D> {
|
|
12
|
+
abstract createPrimitive(descriptor: Shape3DDescriptor, material?: DisplayObject3dOpts<TypeDoc['texture']>): TypeDoc['displayObject'];
|
|
13
|
+
abstract createPerspectiveCamera(settings: {
|
|
14
|
+
fov?: number;
|
|
15
|
+
aspectRatio?: number;
|
|
16
|
+
frustrum?: {
|
|
17
|
+
near: number;
|
|
18
|
+
far: number;
|
|
19
|
+
};
|
|
20
|
+
}): TypeDoc['camera'];
|
|
21
|
+
randomColor(): number;
|
|
22
|
+
createPlane(material?: DisplayObject3dOpts<TypeDoc['texture']>): TypeDoc['displayObject'];
|
|
23
|
+
createBox(dimensions: Point3, material?: DisplayObject3dOpts<TypeDoc['texture']>): TypeDoc['displayObject'];
|
|
24
|
+
createCapsule(radius: number, centersDistance: number, material?: DisplayObject3dOpts<TypeDoc['texture']>): TypeDoc['displayObject'];
|
|
25
|
+
createCylinder(radius: number, height: number, material?: DisplayObject3dOpts<TypeDoc['texture']>): TypeDoc['displayObject'];
|
|
26
|
+
createCone(radius: number, height: number, material?: DisplayObject3dOpts<TypeDoc['texture']>): TypeDoc['displayObject'];
|
|
27
|
+
createSphere(radius: number, material?: DisplayObject3dOpts<TypeDoc['texture']>): TypeDoc['displayObject'];
|
|
13
28
|
}
|
|
14
|
-
export interface IPhysicsBody3dComponentFactory<
|
|
29
|
+
export interface IPhysicsBody3dComponentFactory<TypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> {
|
|
15
30
|
createRigidBody(descriptor: BodyShape3DDescriptor, transform?: {
|
|
16
31
|
position?: Point3;
|
|
17
32
|
rotation?: Point4;
|
|
18
|
-
}):
|
|
33
|
+
}): TypeDoc['rigidBody'];
|
|
19
34
|
createTrigger(descriptor: Shape3DDescriptor, transform?: {
|
|
20
35
|
position?: Point3;
|
|
21
36
|
rotation?: Point4;
|
|
22
|
-
}):
|
|
37
|
+
}): TypeDoc['trigger'];
|
|
38
|
+
createRaycastVehicle(chassis: TypeDoc['rigidBody']): TypeDoc['raycastVehicle'];
|
|
23
39
|
}
|
package/dist/3d/factories.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
export class IDisplayObject3dComponentFactory {
|
|
2
|
+
randomColor() {
|
|
3
|
+
return ((Math.floor(Math.random() * 256) << 16) | (Math.floor(Math.random() * 256) << 8) | Math.floor(Math.random() * 256));
|
|
4
|
+
}
|
|
2
5
|
// shortcuts
|
|
3
|
-
|
|
6
|
+
createPlane(material = {}) {
|
|
7
|
+
return this.createPrimitive({ shape: 'PLANE' }, material);
|
|
8
|
+
}
|
|
9
|
+
createBox(dimensions, material = {}) {
|
|
4
10
|
return this.createPrimitive({ shape: 'BOX', dimensions }, material);
|
|
5
11
|
}
|
|
6
|
-
createCapsule(radius, centersDistance, material) {
|
|
12
|
+
createCapsule(radius, centersDistance, material = {}) {
|
|
7
13
|
return this.createPrimitive({ shape: 'CAPSULE', radius, centersDistance }, material);
|
|
8
14
|
}
|
|
9
|
-
createCylinder(radius, height, material) {
|
|
15
|
+
createCylinder(radius, height, material = {}) {
|
|
10
16
|
return this.createPrimitive({ shape: 'CYLINDER', radius, height }, material);
|
|
11
17
|
}
|
|
12
|
-
createCone(radius, height, material) {
|
|
18
|
+
createCone(radius, height, material = {}) {
|
|
13
19
|
return this.createPrimitive({ shape: 'CONE', radius, height }, material);
|
|
14
20
|
}
|
|
15
|
-
createSphere(radius) {
|
|
16
|
-
return this.createPrimitive({ shape: 'SPHERE', radius });
|
|
21
|
+
createSphere(radius, material = {}) {
|
|
22
|
+
return this.createPrimitive({ shape: 'SPHERE', radius }, material);
|
|
17
23
|
}
|
|
18
24
|
}
|
package/dist/3d/gg-3d-world.d.ts
CHANGED
|
@@ -7,11 +7,32 @@ import { Renderer3dEntity } from './entities/renderer-3d.entity';
|
|
|
7
7
|
import { ICameraComponent } from './components/rendering/i-camera.component';
|
|
8
8
|
import { IRenderer3dComponent } from './components/rendering/i-renderer-3d.component';
|
|
9
9
|
import { IPhysicsWorld3dComponent } from './components/physics/i-physics-world-3d.component';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
import { DisplayObject3dOpts, IDisplayObject3dComponentFactory, IPhysicsBody3dComponentFactory } from './factories';
|
|
11
|
+
import { IDisplayObject3dComponent } from './components/rendering/i-display-object-3d.component';
|
|
12
|
+
import { IRaycastVehicleComponent } from './components/physics/i-raycast-vehicle.component';
|
|
13
|
+
import { IRigidBody3dComponent } from './components/physics/i-rigid-body-3d.component';
|
|
14
|
+
import { ITrigger3dComponent } from './components/physics/i-trigger-3d.component';
|
|
15
|
+
import { IDisplayObject3dComponentLoader, IPhysicsBody3dComponentLoader } from './loaders';
|
|
16
|
+
export declare type VisualTypeDocRepo3D = {
|
|
17
|
+
factory: IDisplayObject3dComponentFactory;
|
|
18
|
+
loader: IDisplayObject3dComponentLoader;
|
|
19
|
+
displayObject: IDisplayObject3dComponent;
|
|
20
|
+
renderer: IRenderer3dComponent;
|
|
21
|
+
camera: ICameraComponent;
|
|
22
|
+
texture: unknown;
|
|
23
|
+
};
|
|
24
|
+
export declare type PhysicsTypeDocRepo3D = {
|
|
25
|
+
factory: IPhysicsBody3dComponentFactory;
|
|
26
|
+
loader: IPhysicsBody3dComponentLoader;
|
|
27
|
+
rigidBody: IRigidBody3dComponent;
|
|
28
|
+
trigger: ITrigger3dComponent;
|
|
29
|
+
raycastVehicle: IRaycastVehicleComponent;
|
|
30
|
+
};
|
|
31
|
+
export declare class Gg3dWorld<VTypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D, PTypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D, VS extends IVisualScene3dComponent<VTypeDoc> = IVisualScene3dComponent<VTypeDoc>, PW extends IPhysicsWorld3dComponent<PTypeDoc> = IPhysicsWorld3dComponent<PTypeDoc>> extends GgWorld<Point3, Point4, VTypeDoc, PTypeDoc, VS, PW> {
|
|
32
|
+
readonly visualScene: VS;
|
|
33
|
+
readonly physicsWorld: PW;
|
|
34
|
+
readonly loader: Gg3dLoader<VTypeDoc, PTypeDoc>;
|
|
35
|
+
constructor(visualScene: VS, physicsWorld: PW);
|
|
36
|
+
addPrimitiveRigidBody(descr: BodyShape3DDescriptor, position?: Point3, rotation?: Point4, material?: DisplayObject3dOpts<VTypeDoc['texture']>): Entity3d<VTypeDoc, PTypeDoc>;
|
|
37
|
+
addRenderer(camera: VTypeDoc['camera'], canvas?: HTMLCanvasElement, rendererOptions?: Partial<RendererOptions>): Renderer3dEntity<VTypeDoc>;
|
|
17
38
|
}
|
package/dist/3d/gg-3d-world.js
CHANGED
|
@@ -30,8 +30,8 @@ export class Gg3dWorld extends GgWorld {
|
|
|
30
30
|
'{x: 0, y: 0, z: -value}, 3 arguments set the whole vector. Default value is "9.82" or "0 0 -9.82"');
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
addPrimitiveRigidBody(descr, position = Pnt3.O, rotation = Qtrn.O) {
|
|
34
|
-
const entity = new Entity3d(this.visualScene.factory.createPrimitive(descr.shape), this.physicsWorld.factory.createRigidBody(descr));
|
|
33
|
+
addPrimitiveRigidBody(descr, position = Pnt3.O, rotation = Qtrn.O, material = {}) {
|
|
34
|
+
const entity = new Entity3d(this.visualScene.factory.createPrimitive(descr.shape, material), this.physicsWorld.factory.createRigidBody(descr));
|
|
35
35
|
entity.position = position;
|
|
36
36
|
entity.rotation = rotation;
|
|
37
37
|
this.addEntity(entity);
|
package/dist/3d/loader.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { Gg3dWorld } from './gg-3d-world';
|
|
1
|
+
import { Gg3dWorld, PhysicsTypeDocRepo3D, VisualTypeDocRepo3D } from './gg-3d-world';
|
|
2
2
|
import { GgMeta } from './models/gg-meta';
|
|
3
3
|
import { Entity3d } from './entities/entity-3d';
|
|
4
4
|
import { Point3, Point4 } from '../base';
|
|
5
|
-
import { IDisplayObject3dComponent } from './components/rendering/i-display-object-3d.component';
|
|
6
|
-
import { IRigidBody3dComponent } from './components/physics/i-rigid-body-3d.component';
|
|
7
5
|
export declare enum CachingStrategy {
|
|
8
6
|
Nothing = 0,
|
|
9
7
|
Files = 1,
|
|
@@ -16,26 +14,26 @@ export declare type LoadOptions = {
|
|
|
16
14
|
loadProps: boolean;
|
|
17
15
|
propsPath?: string;
|
|
18
16
|
};
|
|
19
|
-
export declare type LoadResourcesResult = {
|
|
17
|
+
export declare type LoadResourcesResult<VTypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D, PTypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> = {
|
|
20
18
|
resources: {
|
|
21
|
-
object3D:
|
|
22
|
-
body:
|
|
19
|
+
object3D: VTypeDoc['displayObject'] | null;
|
|
20
|
+
body: PTypeDoc['rigidBody'] | null;
|
|
23
21
|
}[];
|
|
24
22
|
meta: GgMeta;
|
|
25
23
|
};
|
|
26
|
-
export declare type LoadResult = {
|
|
27
|
-
entities: Entity3d[];
|
|
24
|
+
export declare type LoadResult<VTypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D, PTypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> = {
|
|
25
|
+
entities: Entity3d<VTypeDoc, PTypeDoc>[];
|
|
28
26
|
meta: GgMeta;
|
|
29
27
|
};
|
|
30
|
-
export declare type LoadResultWithProps = LoadResult & {
|
|
31
|
-
props?: LoadResult[];
|
|
28
|
+
export declare type LoadResultWithProps<VTypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D, PTypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> = LoadResult<VTypeDoc, PTypeDoc> & {
|
|
29
|
+
props?: LoadResult<VTypeDoc, PTypeDoc>[];
|
|
32
30
|
};
|
|
33
|
-
export declare class Gg3dLoader {
|
|
31
|
+
export declare class Gg3dLoader<VTypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D, PTypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> {
|
|
34
32
|
protected readonly world: Gg3dWorld;
|
|
35
33
|
readonly filesCache: Map<string, [ArrayBuffer, GgMeta] | Promise<[ArrayBuffer, GgMeta]>>;
|
|
36
|
-
readonly loadResultCache: Map<string, LoadResourcesResult | Promise<LoadResourcesResult
|
|
34
|
+
readonly loadResultCache: Map<string, LoadResourcesResult<VTypeDoc, PTypeDoc> | Promise<LoadResourcesResult<VTypeDoc, PTypeDoc>>>;
|
|
37
35
|
constructor(world: Gg3dWorld);
|
|
38
36
|
loadGgGlbFiles(path: string, useCache?: boolean): Promise<[ArrayBuffer, GgMeta]>;
|
|
39
|
-
loadGgGlbResources(path: string, cachingStrategy?: CachingStrategy): Promise<LoadResourcesResult
|
|
40
|
-
loadGgGlb(path: string, options?: Partial<LoadOptions>): Promise<LoadResultWithProps
|
|
37
|
+
loadGgGlbResources(path: string, cachingStrategy?: CachingStrategy): Promise<LoadResourcesResult<VTypeDoc, PTypeDoc>>;
|
|
38
|
+
loadGgGlb(path: string, options?: Partial<LoadOptions>): Promise<LoadResultWithProps<VTypeDoc, PTypeDoc>>;
|
|
41
39
|
}
|
package/dist/3d/loaders.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { GgMeta } from './models/gg-meta';
|
|
2
|
-
import { IRigidBody3dComponent } from './components/physics/i-rigid-body-3d.component';
|
|
3
|
-
import { IDisplayObject3dComponent } from './components/rendering/i-display-object-3d.component';
|
|
4
2
|
import { IPhysicsWorld3dComponent } from './components/physics/i-physics-world-3d.component';
|
|
5
|
-
|
|
3
|
+
import { PhysicsTypeDocRepo3D, VisualTypeDocRepo3D } from './gg-3d-world';
|
|
4
|
+
export declare abstract class IPhysicsBody3dComponentLoader<TypeDoc extends PhysicsTypeDocRepo3D = PhysicsTypeDocRepo3D> {
|
|
6
5
|
protected readonly world: IPhysicsWorld3dComponent;
|
|
7
6
|
protected constructor(world: IPhysicsWorld3dComponent);
|
|
8
|
-
loadFromGgGlb(glbFile: ArrayBuffer, meta: GgMeta): Promise<
|
|
7
|
+
loadFromGgGlb(glbFile: ArrayBuffer, meta: GgMeta): Promise<TypeDoc['rigidBody'][]>;
|
|
9
8
|
}
|
|
10
|
-
export interface IDisplayObject3dComponentLoader {
|
|
11
|
-
loadFromGgGlb(glbFile: ArrayBuffer, meta: GgMeta): Promise<
|
|
9
|
+
export interface IDisplayObject3dComponentLoader<TypeDoc extends VisualTypeDocRepo3D = VisualTypeDocRepo3D> {
|
|
10
|
+
loadFromGgGlb(glbFile: ArrayBuffer, meta: GgMeta): Promise<TypeDoc['displayObject'] | null>;
|
|
12
11
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { IEntity } from '../entities/i-entity';
|
|
2
|
-
import { GgWorld } from '../gg-world';
|
|
3
|
-
|
|
4
|
-
import { IPhysicsWorldComponent } from './physics/i-physics-world.component';
|
|
5
|
-
export interface IWorldComponent<D, R, V extends IVisualSceneComponent<D, R> = IVisualSceneComponent<D, R>, P extends IPhysicsWorldComponent<D, R> = IPhysicsWorldComponent<D, R>> {
|
|
2
|
+
import { GgWorld, PhysicsTypeDocRepo, VisualTypeDocRepo } from '../gg-world';
|
|
3
|
+
export interface IWorldComponent<D, R, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>, PTypeDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>> {
|
|
6
4
|
entity: IEntity | null;
|
|
7
|
-
addToWorld(world: GgWorld<D, R,
|
|
8
|
-
removeFromWorld(world: GgWorld<D, R,
|
|
5
|
+
addToWorld(world: GgWorld<D, R, VTypeDoc, PTypeDoc>): void;
|
|
6
|
+
removeFromWorld(world: GgWorld<D, R, VTypeDoc, PTypeDoc>, dispose?: boolean): void;
|
|
9
7
|
dispose(): void;
|
|
10
8
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { IEntity } from '../../entities/i-entity';
|
|
2
|
-
import { IPhysicsWorldComponent } from './i-physics-world.component';
|
|
3
2
|
import { IWorldComponent } from '../i-world-component';
|
|
4
|
-
import { GgWorld } from '../../gg-world';
|
|
5
|
-
import {
|
|
6
|
-
export interface IBodyComponent<D, R,
|
|
3
|
+
import { GgWorld, PhysicsTypeDocRepo, VisualTypeDocRepo } from '../../gg-world';
|
|
4
|
+
import { CollisionGroup } from '../../models/body-options';
|
|
5
|
+
export interface IBodyComponent<D, R, TypeDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>> extends IWorldComponent<D, R, VisualTypeDocRepo<D, R>, TypeDoc> {
|
|
7
6
|
entity: IEntity | null;
|
|
8
7
|
position: D;
|
|
9
8
|
rotation: R;
|
|
10
9
|
name: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
get ownCollisionGroups(): CollisionGroup[];
|
|
11
|
+
set ownCollisionGroups(value: CollisionGroup[] | 'all');
|
|
12
|
+
get interactWithCollisionGroups(): CollisionGroup[];
|
|
13
|
+
set interactWithCollisionGroups(value: CollisionGroup[] | 'all');
|
|
14
|
+
clone(): IBodyComponent<D, R, TypeDoc>;
|
|
15
|
+
addToWorld(world: GgWorld<D, R, VisualTypeDocRepo<D, R>, TypeDoc>): void;
|
|
16
|
+
removeFromWorld(world: GgWorld<D, R, VisualTypeDocRepo<D, R>, TypeDoc>): void;
|
|
14
17
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { GgWorld } from '../../gg-world';
|
|
1
|
+
import { GgWorld, PhysicsTypeDocRepo } from '../../gg-world';
|
|
2
2
|
import { IDebugPhysicsDrawer } from '../../interfaces/i-debug-physics-drawer';
|
|
3
3
|
import { IComponent } from '../i-component';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { CollisionGroup } from '../../models/body-options';
|
|
5
|
+
export interface IPhysicsWorldComponent<D, R, TypeDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>> extends IComponent {
|
|
6
|
+
readonly factory: TypeDoc['factory'];
|
|
6
7
|
gravity: D;
|
|
7
8
|
timeScale: number;
|
|
8
9
|
get physicsDebugViewActive(): boolean;
|
|
@@ -13,6 +14,8 @@ export interface IPhysicsWorldComponent<D, R> extends IComponent {
|
|
|
13
14
|
* @param delta delta time from last tick in milliseconds.
|
|
14
15
|
*/
|
|
15
16
|
simulate(delta: number): void;
|
|
17
|
+
registerCollisionGroup(): CollisionGroup;
|
|
18
|
+
deregisterCollisionGroup(group: CollisionGroup): void;
|
|
16
19
|
startDebugger(world: GgWorld<D, R>, drawer: IDebugPhysicsDrawer<D, R>): void;
|
|
17
20
|
stopDebugger(world: GgWorld<D, R>): void;
|
|
18
21
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IPhysicsWorldComponent } from './i-physics-world.component';
|
|
2
1
|
import { IBodyComponent } from './i-body.component';
|
|
3
|
-
|
|
2
|
+
import { PhysicsTypeDocRepo } from '../../gg-world';
|
|
3
|
+
export interface IRigidBodyComponent<D, R, TypeDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>> extends IBodyComponent<D, R, TypeDoc> {
|
|
4
4
|
linearVelocity: D;
|
|
5
5
|
angularVelocity: R | D;
|
|
6
|
-
clone(): IRigidBodyComponent<D, R,
|
|
6
|
+
clone(): IRigidBodyComponent<D, R, TypeDoc>;
|
|
7
7
|
/** clear velocities etc. */
|
|
8
8
|
resetMotion(): void;
|
|
9
9
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { IRigidBodyComponent } from './i-rigid-body.component';
|
|
3
|
-
import { IPhysicsWorldComponent } from './i-physics-world.component';
|
|
4
3
|
import { IBodyComponent } from './i-body.component';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
get
|
|
8
|
-
|
|
4
|
+
import { PhysicsTypeDocRepo } from '../../gg-world';
|
|
5
|
+
export interface ITriggerComponent<D, R, TypDoc extends PhysicsTypeDocRepo<D, R> = PhysicsTypeDocRepo<D, R>> extends IBodyComponent<D, R, TypDoc> {
|
|
6
|
+
get onEntityEntered(): Observable<IRigidBodyComponent<D, R, TypDoc>>;
|
|
7
|
+
get onEntityLeft(): Observable<IRigidBodyComponent<D, R, TypDoc> | null>;
|
|
8
|
+
clone(): ITriggerComponent<D, R, TypDoc>;
|
|
9
9
|
checkOverlaps(): void;
|
|
10
10
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { GgBox, GgWorld,
|
|
1
|
+
import { GgBox, GgWorld, VisualTypeDocRepo } from '../../../base';
|
|
2
2
|
import { IWorldComponent } from '../i-world-component';
|
|
3
|
-
export interface IDisplayObjectComponent<D, R,
|
|
3
|
+
export interface IDisplayObjectComponent<D, R, TypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> extends IWorldComponent<D, R, TypeDoc> {
|
|
4
4
|
position: D;
|
|
5
5
|
rotation: R;
|
|
6
6
|
scale: D;
|
|
7
7
|
visible: boolean;
|
|
8
8
|
name: string;
|
|
9
9
|
isEmpty(): boolean;
|
|
10
|
-
popChild(name: string): IDisplayObjectComponent<D, R,
|
|
10
|
+
popChild(name: string): IDisplayObjectComponent<D, R, TypeDoc> | null;
|
|
11
11
|
getBoundings(): GgBox<D>;
|
|
12
|
-
clone(): IDisplayObjectComponent<D, R,
|
|
13
|
-
addToWorld(world: GgWorld<D, R,
|
|
14
|
-
removeFromWorld(world: GgWorld<D, R,
|
|
12
|
+
clone(): IDisplayObjectComponent<D, R, TypeDoc>;
|
|
13
|
+
addToWorld(world: GgWorld<D, R, TypeDoc>): void;
|
|
14
|
+
removeFromWorld(world: GgWorld<D, R, TypeDoc>): void;
|
|
15
15
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Point2 } from '../../models/points';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { IVisualSceneComponent } from './i-visual-scene.component';
|
|
4
3
|
import { IWorldComponent } from '../i-world-component';
|
|
5
|
-
import { GgWorld } from '../../gg-world';
|
|
4
|
+
import { GgWorld, VisualTypeDocRepo } from '../../gg-world';
|
|
6
5
|
import { IEntity } from '../../entities/i-entity';
|
|
6
|
+
import { IVisualSceneComponent } from './i-visual-scene.component';
|
|
7
7
|
/**
|
|
8
8
|
* Represents the options that can be passed to a renderer.
|
|
9
9
|
* @typedef {Object} RendererOptions
|
|
@@ -20,19 +20,19 @@ export declare type RendererOptions = {
|
|
|
20
20
|
forceResolution?: number;
|
|
21
21
|
antialias: boolean;
|
|
22
22
|
};
|
|
23
|
-
export declare abstract class IRendererComponent<D, R,
|
|
24
|
-
readonly scene:
|
|
23
|
+
export declare abstract class IRendererComponent<D, R, VTypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> implements IWorldComponent<D, R, VTypeDoc> {
|
|
24
|
+
readonly scene: IVisualSceneComponent<D, R, VTypeDoc>;
|
|
25
25
|
readonly canvas?: HTMLCanvasElement | undefined;
|
|
26
26
|
entity: IEntity | null;
|
|
27
27
|
/** Specifies the options for the renderer. */
|
|
28
28
|
readonly rendererOptions: RendererOptions;
|
|
29
|
-
protected constructor(scene:
|
|
29
|
+
protected constructor(scene: IVisualSceneComponent<D, R, VTypeDoc>, canvas?: HTMLCanvasElement | undefined, options?: Partial<RendererOptions>);
|
|
30
30
|
/**
|
|
31
31
|
* Renders the scene.
|
|
32
32
|
*/
|
|
33
33
|
abstract render(): void;
|
|
34
|
-
abstract addToWorld(world: GgWorld<D, R,
|
|
35
|
-
abstract removeFromWorld(world: GgWorld<D, R,
|
|
34
|
+
abstract addToWorld(world: GgWorld<D, R, VTypeDoc>): void;
|
|
35
|
+
abstract removeFromWorld(world: GgWorld<D, R, VTypeDoc>): void;
|
|
36
36
|
/**
|
|
37
37
|
* Resizes the renderer to the specified size.
|
|
38
38
|
* @param {Point2} newSize - The new size of the renderer.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IDebugPhysicsDrawer } from '../../interfaces/i-debug-physics-drawer';
|
|
2
2
|
import { IComponent } from '../i-component';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { VisualTypeDocRepo } from '../../gg-world';
|
|
4
|
+
export interface IVisualSceneComponent<D, R, TypeDoc extends VisualTypeDocRepo<D, R> = VisualTypeDocRepo<D, R>> extends IComponent {
|
|
5
|
+
readonly factory: TypeDoc['factory'];
|
|
5
6
|
readonly debugPhysicsDrawerClass?: {
|
|
6
|
-
new (): IDebugPhysicsDrawer<D, R>;
|
|
7
|
+
new (): IDebugPhysicsDrawer<D, R, TypeDoc>;
|
|
7
8
|
};
|
|
8
9
|
init(): Promise<void>;
|
|
9
10
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BitMask class provides static methods to manipulate bits in a number.
|
|
3
|
+
*/ /**
|
|
4
|
+
* BitMask class provides static methods to manipulate bits in a number.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BitMask {
|
|
7
|
+
/**
|
|
8
|
+
* Generates a bitmask with all bits set to 1 upto the provided bit count
|
|
9
|
+
* @param bits - The number of bits to be set to 1
|
|
10
|
+
*/
|
|
11
|
+
static full(bits: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Generates an array with elements being consecutive numbers starting from 0 up to the provided number
|
|
14
|
+
* @param bits - The length of the array to be created
|
|
15
|
+
*/
|
|
16
|
+
static fullArray(bits: number): number[];
|
|
17
|
+
/**
|
|
18
|
+
* Packs an array of bit indices into a single number
|
|
19
|
+
* @param value - The bit indices to be set to 1
|
|
20
|
+
* @param bits - The maximum bit index that can be used
|
|
21
|
+
* @throws Will throw an Error if a bit index in `value` is larger than `bits`
|
|
22
|
+
*/
|
|
23
|
+
static pack(value: number[], bits: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* Unpacks a bitmask into an array of bit indices
|
|
26
|
+
* @param mask - The bit mask to be unpacked
|
|
27
|
+
* @param bits - The number of bits to be unpacked from the mask
|
|
28
|
+
*/
|
|
29
|
+
static unpack(mask: number, bits: number): number[];
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BitMask class provides static methods to manipulate bits in a number.
|
|
3
|
+
*/ /**
|
|
4
|
+
* BitMask class provides static methods to manipulate bits in a number.
|
|
5
|
+
*/
|
|
6
|
+
export class BitMask {
|
|
7
|
+
/**
|
|
8
|
+
* Generates a bitmask with all bits set to 1 upto the provided bit count
|
|
9
|
+
* @param bits - The number of bits to be set to 1
|
|
10
|
+
*/
|
|
11
|
+
static full(bits) {
|
|
12
|
+
return Math.pow(2, bits) - 1;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generates an array with elements being consecutive numbers starting from 0 up to the provided number
|
|
16
|
+
* @param bits - The length of the array to be created
|
|
17
|
+
*/
|
|
18
|
+
static fullArray(bits) {
|
|
19
|
+
return new Array(bits).fill(null).map((_, i) => i);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Packs an array of bit indices into a single number
|
|
23
|
+
* @param value - The bit indices to be set to 1
|
|
24
|
+
* @param bits - The maximum bit index that can be used
|
|
25
|
+
* @throws Will throw an Error if a bit index in `value` is larger than `bits`
|
|
26
|
+
*/
|
|
27
|
+
static pack(value, bits) {
|
|
28
|
+
let ret = 0;
|
|
29
|
+
for (const g of value) {
|
|
30
|
+
if (g >= bits) {
|
|
31
|
+
throw new Error('Too big bit index');
|
|
32
|
+
}
|
|
33
|
+
ret |= 1 << g;
|
|
34
|
+
}
|
|
35
|
+
return ret;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Unpacks a bitmask into an array of bit indices
|
|
39
|
+
* @param mask - The bit mask to be unpacked
|
|
40
|
+
* @param bits - The number of bits to be unpacked from the mask
|
|
41
|
+
*/
|
|
42
|
+
static unpack(mask, bits) {
|
|
43
|
+
// It's better to keep the ret array capacity as there won't be more bits set than the size itself.
|
|
44
|
+
const ret = new Array(bits);
|
|
45
|
+
let idx = 0;
|
|
46
|
+
for (let i = 0; i < bits; i++) {
|
|
47
|
+
if (mask & (1 << i)) {
|
|
48
|
+
ret[idx++] = i;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Truncate the ret array to include only valid indices.
|
|
52
|
+
ret.length = idx;
|
|
53
|
+
return ret;
|
|
54
|
+
}
|
|
55
|
+
}
|