@gg-web-engine/rapier3d 0.0.37 → 0.0.39

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.
@@ -1,4 +1,4 @@
1
- import { Body3DOptions, CollisionGroup, Entity3d, Gg3dWorld, IRigidBody3dComponent, Point3, Point4, VisualTypeDocRepo3D } from '@gg-web-engine/core';
1
+ import { Body3DOptions, CollisionGroup, DebugBody3DSettings, Entity3d, Gg3dWorld, IRigidBody3dComponent, Point3, Point4, Shape3DDescriptor, VisualTypeDocRepo3D } from '@gg-web-engine/core';
2
2
  import { Collider, ColliderDesc, RigidBody, RigidBodyDesc } from '@dimforge/rapier3d-compat';
3
3
  import { Rapier3dWorldComponent } from './rapier-3d-world.component';
4
4
  import { Rapier3dPhysicsTypeDocRepo } from '../types';
@@ -6,6 +6,7 @@ import { InteractionGroups } from '@dimforge/rapier3d-compat/geometry/interactio
6
6
  export declare class Rapier3dRigidBodyComponent implements IRigidBody3dComponent<Rapier3dPhysicsTypeDocRepo> {
7
7
  protected readonly world: Rapier3dWorldComponent;
8
8
  protected _colliderDescr: ColliderDesc[];
9
+ readonly shape: Shape3DDescriptor;
9
10
  protected _bodyDescr: RigidBodyDesc;
10
11
  protected _colliderOptions: Omit<Omit<Body3DOptions, 'dynamic'>, 'mass'>;
11
12
  entity: Entity3d | null;
@@ -17,13 +18,19 @@ export declare class Rapier3dRigidBodyComponent implements IRigidBody3dComponent
17
18
  set linearVelocity(value: Point3);
18
19
  get angularVelocity(): Point3;
19
20
  set angularVelocity(value: Point3);
21
+ get debugBodySettings(): DebugBody3DSettings;
20
22
  protected _nativeBody: RigidBody | null;
21
23
  protected _nativeBodyColliders: Collider[] | null;
22
24
  get nativeBody(): RigidBody | null;
23
25
  set nativeBody(value: RigidBody | null);
24
26
  name: string;
25
- get factoryProps(): [ColliderDesc[], RigidBodyDesc, Omit<Omit<Body3DOptions, 'dynamic'>, 'mass'>];
26
- constructor(world: Rapier3dWorldComponent, _colliderDescr: ColliderDesc[], _bodyDescr: RigidBodyDesc, _colliderOptions: Omit<Omit<Body3DOptions, 'dynamic'>, 'mass'>);
27
+ get factoryProps(): [
28
+ ColliderDesc[],
29
+ Shape3DDescriptor,
30
+ RigidBodyDesc,
31
+ Omit<Omit<Body3DOptions, 'dynamic'>, 'mass'>
32
+ ];
33
+ constructor(world: Rapier3dWorldComponent, _colliderDescr: ColliderDesc[], shape: Shape3DDescriptor, _bodyDescr: RigidBodyDesc, _colliderOptions: Omit<Omit<Body3DOptions, 'dynamic'>, 'mass'>);
27
34
  protected collisionGroups: InteractionGroups;
28
35
  get interactWithCollisionGroups(): CollisionGroup[];
29
36
  set interactWithCollisionGroups(value: CollisionGroup[] | 'all');
@@ -1,9 +1,10 @@
1
1
  import { BitMask, Pnt3, Qtrn, } from '@gg-web-engine/core';
2
2
  import { ColliderDesc, Quaternion, RigidBodyDesc, Vector3 } from '@dimforge/rapier3d-compat';
3
3
  export class Rapier3dRigidBodyComponent {
4
- constructor(world, _colliderDescr, _bodyDescr, _colliderOptions) {
4
+ constructor(world, _colliderDescr, shape, _bodyDescr, _colliderOptions) {
5
5
  this.world = world;
6
6
  this._colliderDescr = _colliderDescr;
7
+ this.shape = shape;
7
8
  this._bodyDescr = _bodyDescr;
8
9
  this._colliderOptions = _colliderOptions;
9
10
  this.entity = null;
@@ -54,6 +55,15 @@ export class Rapier3dRigidBodyComponent {
54
55
  this.nativeBody.setAngvel(new Vector3(value.x, value.y, value.z), false);
55
56
  }
56
57
  }
58
+ get debugBodySettings() {
59
+ var _a;
60
+ if (this._bodyDescr.mass > 0) {
61
+ return { shape: this.shape, type: 'RIGID_DYNAMIC', sleeping: !!((_a = this._nativeBody) === null || _a === void 0 ? void 0 : _a.isSleeping()) };
62
+ }
63
+ else {
64
+ return { shape: this.shape, type: 'RIGID_STATIC' };
65
+ }
66
+ }
57
67
  get nativeBody() {
58
68
  return this._nativeBody;
59
69
  }
@@ -80,7 +90,7 @@ export class Rapier3dRigidBodyComponent {
80
90
  bd.setTranslation(this._bodyDescr.translation.x, this._bodyDescr.translation.y, this._bodyDescr.translation.z);
81
91
  bd.setRotation(Object.assign({}, this._bodyDescr.rotation));
82
92
  // TODO more fields here?
83
- return [colliderDescr, bd, this._colliderOptions];
93
+ return [colliderDescr, this.shape, bd, this._colliderOptions];
84
94
  }
85
95
  get interactWithCollisionGroups() {
86
96
  return BitMask.unpack(this.collisionGroups, 16);
@@ -144,6 +154,7 @@ export class Rapier3dRigidBodyComponent {
144
154
  return col;
145
155
  });
146
156
  this.world.handleIdEntityMap.set(this._nativeBody.handle, this);
157
+ this.world.added$.next(this);
147
158
  }
148
159
  removeFromWorld(world) {
149
160
  if (world.physicsWorld != this.world) {
@@ -158,6 +169,7 @@ export class Rapier3dRigidBodyComponent {
158
169
  this._nativeBody = null;
159
170
  this._nativeBodyColliders = null;
160
171
  }
172
+ this.world.removed$.next(this);
161
173
  }
162
174
  resetMotion() {
163
175
  this._nativeBody.setAngvel(new Vector3(0, 0, 0), false);
@@ -1,18 +1,20 @@
1
1
  import { Observable, Subject } from 'rxjs';
2
2
  import { ColliderDesc, RigidBodyDesc } from '@dimforge/rapier3d-compat';
3
3
  import { Rapier3dRigidBodyComponent } from './rapier-3d-rigid-body.component';
4
- import { Gg3dWorld, ITrigger3dComponent, VisualTypeDocRepo3D } from '@gg-web-engine/core';
4
+ import { DebugBody3DSettings, Gg3dWorld, ITrigger3dComponent, Shape3DDescriptor, VisualTypeDocRepo3D } from '@gg-web-engine/core';
5
5
  import { Rapier3dWorldComponent } from './rapier-3d-world.component';
6
6
  import { Rapier3dPhysicsTypeDocRepo } from '../types';
7
7
  export declare class Rapier3dTriggerComponent extends Rapier3dRigidBodyComponent implements ITrigger3dComponent<Rapier3dPhysicsTypeDocRepo> {
8
8
  protected readonly world: Rapier3dWorldComponent;
9
9
  protected _colliderDescr: ColliderDesc[];
10
+ readonly shape: Shape3DDescriptor;
10
11
  protected _bodyDescr: RigidBodyDesc;
11
12
  get onEntityEntered(): Observable<Rapier3dRigidBodyComponent>;
12
13
  get onEntityLeft(): Observable<Rapier3dRigidBodyComponent>;
13
14
  protected readonly onEnter$: Subject<Rapier3dRigidBodyComponent>;
14
15
  protected readonly onLeft$: Subject<Rapier3dRigidBodyComponent>;
15
- constructor(world: Rapier3dWorldComponent, _colliderDescr: ColliderDesc[], _bodyDescr: RigidBodyDesc);
16
+ get debugBodySettings(): DebugBody3DSettings;
17
+ constructor(world: Rapier3dWorldComponent, _colliderDescr: ColliderDesc[], shape: Shape3DDescriptor, _bodyDescr: RigidBodyDesc);
16
18
  addToWorld(world: Gg3dWorld<VisualTypeDocRepo3D, Rapier3dPhysicsTypeDocRepo>): void;
17
19
  checkOverlaps(): void;
18
20
  clone(): Rapier3dTriggerComponent;
@@ -1,10 +1,11 @@
1
1
  import { Subject } from 'rxjs';
2
2
  import { Rapier3dRigidBodyComponent } from './rapier-3d-rigid-body.component';
3
3
  export class Rapier3dTriggerComponent extends Rapier3dRigidBodyComponent {
4
- constructor(world, _colliderDescr, _bodyDescr) {
5
- super(world, _colliderDescr, _bodyDescr, null);
4
+ constructor(world, _colliderDescr, shape, _bodyDescr) {
5
+ super(world, _colliderDescr, shape, _bodyDescr, null);
6
6
  this.world = world;
7
7
  this._colliderDescr = _colliderDescr;
8
+ this.shape = shape;
8
9
  this._bodyDescr = _bodyDescr;
9
10
  this.onEnter$ = new Subject();
10
11
  this.onLeft$ = new Subject();
@@ -15,6 +16,9 @@ export class Rapier3dTriggerComponent extends Rapier3dRigidBodyComponent {
15
16
  get onEntityLeft() {
16
17
  return this.onLeft$.asObservable();
17
18
  }
19
+ get debugBodySettings() {
20
+ return { shape: this.shape, type: 'TRIGGER' };
21
+ }
18
22
  addToWorld(world) {
19
23
  if (world.physicsWorld != this.world) {
20
24
  throw new Error('Rapier3D bodies cannot be shared between different worlds');
@@ -22,6 +26,7 @@ export class Rapier3dTriggerComponent extends Rapier3dRigidBodyComponent {
22
26
  this._nativeBody = this.world.nativeWorld.createRigidBody(this._bodyDescr);
23
27
  this._nativeBodyColliders = this._colliderDescr.map(c => this.world.nativeWorld.createCollider(c, this._nativeBody));
24
28
  this.world.handleIdEntityMap.set(this._nativeBody.handle, this);
29
+ this.world.added$.next(this);
25
30
  }
26
31
  checkOverlaps() {
27
32
  this.world.eventQueue.drainCollisionEvents((h1, h2, started) => {
@@ -39,7 +44,7 @@ export class Rapier3dTriggerComponent extends Rapier3dRigidBodyComponent {
39
44
  });
40
45
  }
41
46
  clone() {
42
- const [colliderDescr, bd] = super.factoryProps;
43
- return new Rapier3dTriggerComponent(this.world, colliderDescr, bd);
47
+ const [colliderDescr, sd, bd] = super.factoryProps;
48
+ return new Rapier3dTriggerComponent(this.world, colliderDescr, sd, bd);
44
49
  }
45
50
  }
@@ -1,32 +1,31 @@
1
- import { CollisionGroup, Gg3dWorld, IDebugPhysicsDrawer, IPhysicsWorld3dComponent, Point3, Point4 } from '@gg-web-engine/core';
1
+ import { CollisionGroup, IPhysicsWorld3dComponent, Point3 } from '@gg-web-engine/core';
2
2
  import { EventQueue, World } from '@dimforge/rapier3d-compat';
3
3
  import { Rapier3dRigidBodyComponent } from './rapier-3d-rigid-body.component';
4
4
  import { Rapier3dFactory } from '../rapier-3d-factory';
5
5
  import { Rapier3dLoader } from '../rapier-3d-loader';
6
6
  import { Rapier3dPhysicsTypeDocRepo } from '../types';
7
+ import { Subject } from 'rxjs';
7
8
  export declare class Rapier3dWorldComponent implements IPhysicsWorld3dComponent<Rapier3dPhysicsTypeDocRepo> {
8
9
  private _factory;
9
10
  get factory(): Rapier3dFactory;
10
11
  private _loader;
11
12
  get loader(): Rapier3dLoader;
13
+ readonly added$: Subject<Rapier3dRigidBodyComponent>;
14
+ readonly removed$: Subject<Rapier3dRigidBodyComponent>;
15
+ readonly children: Rapier3dRigidBodyComponent[];
12
16
  private _gravity;
13
17
  get gravity(): Point3;
14
18
  set gravity(value: Point3);
15
- private _timeScale;
16
- get timeScale(): number;
17
- set timeScale(value: number);
18
- get physicsDebugViewActive(): boolean;
19
19
  protected _nativeWorld: World | null;
20
20
  get nativeWorld(): World;
21
21
  private _eventQueue;
22
22
  get eventQueue(): EventQueue;
23
23
  readonly handleIdEntityMap: Map<number, Rapier3dRigidBodyComponent>;
24
+ constructor();
24
25
  init(): Promise<void>;
25
26
  simulate(delta: number): void;
26
27
  protected lockedCollisionGroups: number[];
27
28
  registerCollisionGroup(): CollisionGroup;
28
29
  deregisterCollisionGroup(group: CollisionGroup): void;
29
- startDebugger(world: Gg3dWorld, drawer: IDebugPhysicsDrawer<Point3, Point4>): void;
30
- stopDebugger(): void;
31
30
  dispose(): void;
32
31
  }
@@ -10,16 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { EventQueue, init, Vector3, World } from '@dimforge/rapier3d-compat';
11
11
  import { Rapier3dFactory } from '../rapier-3d-factory';
12
12
  import { Rapier3dLoader } from '../rapier-3d-loader';
13
+ import { Subject } from 'rxjs';
13
14
  export class Rapier3dWorldComponent {
14
15
  constructor() {
15
16
  this._factory = null;
16
17
  this._loader = null;
18
+ this.added$ = new Subject();
19
+ this.removed$ = new Subject();
20
+ this.children = [];
17
21
  this._gravity = { x: 0, y: 0, z: -9.82 };
18
- this._timeScale = 1;
19
22
  this._nativeWorld = null;
20
23
  this._eventQueue = null;
21
24
  this.handleIdEntityMap = new Map();
22
25
  this.lockedCollisionGroups = [];
26
+ this.added$.subscribe(c => this.children.push(c));
27
+ this.removed$.subscribe(c => this.children.splice(this.children.indexOf(c), 1));
23
28
  }
24
29
  get factory() {
25
30
  if (!this._factory) {
@@ -44,15 +49,6 @@ export class Rapier3dWorldComponent {
44
49
  this.nativeWorld.gravity.z = value.z;
45
50
  }
46
51
  }
47
- get timeScale() {
48
- return this._timeScale;
49
- }
50
- set timeScale(value) {
51
- this._timeScale = value;
52
- }
53
- get physicsDebugViewActive() {
54
- return false;
55
- }
56
52
  get nativeWorld() {
57
53
  if (!this._nativeWorld) {
58
54
  throw new Error('Rapier3d world not initialized');
@@ -76,7 +72,7 @@ export class Rapier3dWorldComponent {
76
72
  }
77
73
  simulate(delta) {
78
74
  var _a;
79
- this._nativeWorld.timestep = (this.timeScale * delta) / 1000;
75
+ this._nativeWorld.timestep = delta / 1000;
80
76
  (_a = this._nativeWorld) === null || _a === void 0 ? void 0 : _a.step(this.eventQueue);
81
77
  }
82
78
  registerCollisionGroup() {
@@ -91,14 +87,6 @@ export class Rapier3dWorldComponent {
91
87
  deregisterCollisionGroup(group) {
92
88
  this.lockedCollisionGroups = this.lockedCollisionGroups.filter(x => x !== group);
93
89
  }
94
- startDebugger(world, drawer) {
95
- // TODO
96
- throw new Error('rapier-3d DebugDrawer not implemented');
97
- }
98
- stopDebugger() {
99
- // TODO
100
- throw new Error('rapier-3d DebugDrawer not implemented');
101
- }
102
90
  dispose() {
103
91
  var _a;
104
92
  (_a = this._nativeWorld) === null || _a === void 0 ? void 0 : _a.free();
@@ -7,7 +7,7 @@ export class Rapier3dFactory {
7
7
  this.world = world;
8
8
  }
9
9
  createRigidBody(descriptor, transform) {
10
- return new Rapier3dRigidBodyComponent(this.world, this.createColliderDescr(descriptor.shape), this.createRigidBodyDescr(descriptor.body, transform), Object.assign({ friction: 0.5, restitution: 0.1, ownCollisionGroups: 'all', interactWithCollisionGroups: 'all' }, descriptor.body));
10
+ return new Rapier3dRigidBodyComponent(this.world, this.createColliderDescr(descriptor.shape), descriptor.shape, this.createRigidBodyDescr(descriptor.body, transform), Object.assign({ friction: 0.5, restitution: 0.1, ownCollisionGroups: 'all', interactWithCollisionGroups: 'all' }, descriptor.body));
11
11
  }
12
12
  createTrigger(descriptor, transform) {
13
13
  const colliderDescr = this.createColliderDescr(descriptor);
@@ -15,7 +15,7 @@ export class Rapier3dFactory {
15
15
  c.isSensor = true;
16
16
  c.setActiveEvents(ActiveEvents.COLLISION_EVENTS);
17
17
  });
18
- return new Rapier3dTriggerComponent(this.world, colliderDescr, this.createRigidBodyDescr({ dynamic: false }, transform));
18
+ return new Rapier3dTriggerComponent(this.world, colliderDescr, descriptor, this.createRigidBodyDescr({ dynamic: false }, transform));
19
19
  }
20
20
  createRaycastVehicle(chassis) {
21
21
  throw new Error('Raycast vehicle bindings for rapier3D are not implemented');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gg-web-engine/rapier3d",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "description": "An attempt to create open source game engine for browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,20 +27,20 @@
27
27
  },
28
28
  "homepage": "https://github.com/AndyGura/gg-web-engine#readme",
29
29
  "devDependencies": {
30
- "@dimforge/rapier3d-compat": "0.0.0-c23a138-20231001",
31
- "@gg-web-engine/core": "0.0.37",
30
+ "@dimforge/rapier3d-compat": "0.0.0-98015b1-20240128",
31
+ "@gg-web-engine/core": "0.0.39",
32
32
  "@types/jest": "^29.5.0",
33
33
  "jest": "^29.5.0",
34
34
  "jest-environment-jsdom": "^29.5.0",
35
35
  "prettier": "^2.8.6",
36
- "rxjs": "7.8.0",
36
+ "rxjs": "7.8.1",
37
37
  "ts-jest": "^29.0.5",
38
38
  "typescript": "~4.7.2"
39
39
  },
40
40
  "peerDependencies": {
41
- "@dimforge/rapier3d-compat": "0.0.0-c23a138-20231001",
42
- "@gg-web-engine/core": "0.0.37",
43
- "rxjs": "7.8.0"
41
+ "@dimforge/rapier3d-compat": "0.0.0-98015b1-20240128",
42
+ "@gg-web-engine/core": "0.0.39",
43
+ "rxjs": "7.8.1"
44
44
  },
45
45
  "jest": {
46
46
  "rootDir": ".",