From 7d947fccabf0a50b6aa84ef013635b7e23116df1 Mon Sep 17 00:00:00 2001 From: Chau Tran Date: Wed, 1 Dec 2021 00:57:20 -0600 Subject: [PATCH] feat(cannon): add physic bodies --- packages/cannon/bodies/src/index.ts | 9 ++++ .../bodies/src/lib/box/box.directive.ts | 6 ++- .../src/lib/compound/compound.directive.ts | 28 +++++++++++++ .../convex-polyhedron.directive.ts | 42 +++++++++++++++++++ .../src/lib/cylinder/cylinder.directive.ts | 33 +++++++++++++++ .../lib/heightfield/heightfield.directive.ts | 28 +++++++++++++ .../src/lib/particle/particle.directive.ts | 30 +++++++++++++ .../bodies/src/lib/plane/plane.directive.ts | 28 +++++++++++++ .../bodies/src/lib/sphere/sphere.directive.ts | 35 ++++++++++++++++ .../src/lib/trimesh/trimesh.directive.ts | 26 ++++++++++++ .../cannon/src/lib/bodies/body.controller.ts | 13 +++++- .../object-3d-inputs.controller.ts | 34 ++++++++++----- 12 files changed, 300 insertions(+), 12 deletions(-) create mode 100644 packages/cannon/bodies/src/lib/compound/compound.directive.ts create mode 100644 packages/cannon/bodies/src/lib/convex-polyhedron/convex-polyhedron.directive.ts create mode 100644 packages/cannon/bodies/src/lib/cylinder/cylinder.directive.ts create mode 100644 packages/cannon/bodies/src/lib/heightfield/heightfield.directive.ts create mode 100644 packages/cannon/bodies/src/lib/particle/particle.directive.ts create mode 100644 packages/cannon/bodies/src/lib/plane/plane.directive.ts create mode 100644 packages/cannon/bodies/src/lib/sphere/sphere.directive.ts create mode 100644 packages/cannon/bodies/src/lib/trimesh/trimesh.directive.ts diff --git a/packages/cannon/bodies/src/index.ts b/packages/cannon/bodies/src/index.ts index 22eebe978..26147cc21 100644 --- a/packages/cannon/bodies/src/index.ts +++ b/packages/cannon/bodies/src/index.ts @@ -1 +1,10 @@ +// GENERATED export * from './lib/box/box.directive'; +export * from './lib/plane/plane.directive'; +export * from './lib/cylinder/cylinder.directive'; +export * from './lib/heightfield/heightfield.directive'; +export * from './lib/particle/particle.directive'; +export * from './lib/sphere/sphere.directive'; +export * from './lib/trimesh/trimesh.directive'; +export * from './lib/convex-polyhedron/convex-polyhedron.directive'; +export * from './lib/compound/compound.directive'; diff --git a/packages/cannon/bodies/src/lib/box/box.directive.ts b/packages/cannon/bodies/src/lib/box/box.directive.ts index a8c49d41b..88737fda0 100644 --- a/packages/cannon/bodies/src/lib/box/box.directive.ts +++ b/packages/cannon/bodies/src/lib/box/box.directive.ts @@ -1,3 +1,4 @@ +// GENERATED import { BoxProps, GetByIndex, @@ -13,7 +14,10 @@ import { Directive, NgModule } from '@angular/core'; providers: [ NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'Box' }, - { provide: NGT_PHYSIC_BODY_ARGS_FN, useValue: (args = [1, 1, 1]) => args }, + { + provide: NGT_PHYSIC_BODY_ARGS_FN, + useValue: (args: BoxProps['args'] = [1, 1, 1]) => args, + }, ], }) export class NgtPhysicBox { diff --git a/packages/cannon/bodies/src/lib/compound/compound.directive.ts b/packages/cannon/bodies/src/lib/compound/compound.directive.ts new file mode 100644 index 000000000..79326d438 --- /dev/null +++ b/packages/cannon/bodies/src/lib/compound/compound.directive.ts @@ -0,0 +1,28 @@ +// GENERATED +import { + CompoundBodyProps, + GetByIndex, + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + NGT_PHYSIC_BODY_TYPE, +} from '@angular-three/cannon'; +import { Directive, NgModule } from '@angular/core'; + +@Directive({ + selector: '[ngtPhysicCompound]', + exportAs: 'ngtPhysicCompound', + providers: [ + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'Compound' }, + ], +}) +export class NgtPhysicCompound { + static ngAcceptInputType_getPhysicProps: + | GetByIndex + | undefined; +} + +@NgModule({ + declarations: [NgtPhysicCompound], + exports: [NgtPhysicCompound], +}) +export class NgtPhysicCompoundModule {} diff --git a/packages/cannon/bodies/src/lib/convex-polyhedron/convex-polyhedron.directive.ts b/packages/cannon/bodies/src/lib/convex-polyhedron/convex-polyhedron.directive.ts new file mode 100644 index 000000000..58bd3ee4b --- /dev/null +++ b/packages/cannon/bodies/src/lib/convex-polyhedron/convex-polyhedron.directive.ts @@ -0,0 +1,42 @@ +// GENERATED +import { + ConvexPolyhedronProps, + GetByIndex, + NGT_PHYSIC_BODY_ARGS_FN, + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + NGT_PHYSIC_BODY_TYPE, + makeTriplet, +} from '@angular-three/cannon'; +import { Directive, NgModule } from '@angular/core'; + +@Directive({ + selector: '[ngtPhysicConvexPolyhedron]', + exportAs: 'ngtPhysicConvexPolyhedron', + providers: [ + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'ConvexPolyhedron' }, + { + provide: NGT_PHYSIC_BODY_ARGS_FN, + useValue: (args: ConvexPolyhedronProps['args'] = []) => { + return [ + args[0] ? args[0].map(makeTriplet) : undefined, + args[1], + args[2] ? args[2].map(makeTriplet) : undefined, + args[3] ? args[3].map(makeTriplet) : undefined, + args[4], + ]; + }, + }, + ], +}) +export class NgtPhysicConvexPolyhedron { + static ngAcceptInputType_getPhysicProps: + | GetByIndex + | undefined; +} + +@NgModule({ + declarations: [NgtPhysicConvexPolyhedron], + exports: [NgtPhysicConvexPolyhedron], +}) +export class NgtPhysicConvexPolyhedronModule {} diff --git a/packages/cannon/bodies/src/lib/cylinder/cylinder.directive.ts b/packages/cannon/bodies/src/lib/cylinder/cylinder.directive.ts new file mode 100644 index 000000000..59ae1a7b8 --- /dev/null +++ b/packages/cannon/bodies/src/lib/cylinder/cylinder.directive.ts @@ -0,0 +1,33 @@ +// GENERATED +import { + CylinderProps, + GetByIndex, + NGT_PHYSIC_BODY_ARGS_FN, + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + NGT_PHYSIC_BODY_TYPE, +} from '@angular-three/cannon'; +import { Directive, NgModule } from '@angular/core'; + +@Directive({ + selector: '[ngtPhysicCylinder]', + exportAs: 'ngtPhysicCylinder', + providers: [ + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'Cylinder' }, + { + provide: NGT_PHYSIC_BODY_ARGS_FN, + useValue: (args: CylinderProps['args'] = []) => args, + }, + ], +}) +export class NgtPhysicCylinder { + static ngAcceptInputType_getPhysicProps: + | GetByIndex + | undefined; +} + +@NgModule({ + declarations: [NgtPhysicCylinder], + exports: [NgtPhysicCylinder], +}) +export class NgtPhysicCylinderModule {} diff --git a/packages/cannon/bodies/src/lib/heightfield/heightfield.directive.ts b/packages/cannon/bodies/src/lib/heightfield/heightfield.directive.ts new file mode 100644 index 000000000..3f201fec3 --- /dev/null +++ b/packages/cannon/bodies/src/lib/heightfield/heightfield.directive.ts @@ -0,0 +1,28 @@ +// GENERATED +import { + HeightfieldProps, + GetByIndex, + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + NGT_PHYSIC_BODY_TYPE, +} from '@angular-three/cannon'; +import { Directive, NgModule } from '@angular/core'; + +@Directive({ + selector: '[ngtPhysicHeightfield]', + exportAs: 'ngtPhysicHeightfield', + providers: [ + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'Heightfield' }, + ], +}) +export class NgtPhysicHeightfield { + static ngAcceptInputType_getPhysicProps: + | GetByIndex + | undefined; +} + +@NgModule({ + declarations: [NgtPhysicHeightfield], + exports: [NgtPhysicHeightfield], +}) +export class NgtPhysicHeightfieldModule {} diff --git a/packages/cannon/bodies/src/lib/particle/particle.directive.ts b/packages/cannon/bodies/src/lib/particle/particle.directive.ts new file mode 100644 index 000000000..22d40705e --- /dev/null +++ b/packages/cannon/bodies/src/lib/particle/particle.directive.ts @@ -0,0 +1,30 @@ +// GENERATED +import { + ParticleProps, + GetByIndex, + NGT_PHYSIC_BODY_ARGS_FN, + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + NGT_PHYSIC_BODY_TYPE, +} from '@angular-three/cannon'; +import { Directive, NgModule } from '@angular/core'; + +@Directive({ + selector: '[ngtPhysicParticle]', + exportAs: 'ngtPhysicParticle', + providers: [ + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'Particle' }, + { provide: NGT_PHYSIC_BODY_ARGS_FN, useValue: () => [] }, + ], +}) +export class NgtPhysicParticle { + static ngAcceptInputType_getPhysicProps: + | GetByIndex + | undefined; +} + +@NgModule({ + declarations: [NgtPhysicParticle], + exports: [NgtPhysicParticle], +}) +export class NgtPhysicParticleModule {} diff --git a/packages/cannon/bodies/src/lib/plane/plane.directive.ts b/packages/cannon/bodies/src/lib/plane/plane.directive.ts new file mode 100644 index 000000000..f9b901fd9 --- /dev/null +++ b/packages/cannon/bodies/src/lib/plane/plane.directive.ts @@ -0,0 +1,28 @@ +// GENERATED +import { + PlaneProps, + GetByIndex, + NGT_PHYSIC_BODY_ARGS_FN, + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + NGT_PHYSIC_BODY_TYPE, +} from '@angular-three/cannon'; +import { Directive, NgModule } from '@angular/core'; + +@Directive({ + selector: '[ngtPhysicPlane]', + exportAs: 'ngtPhysicPlane', + providers: [ + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'Plane' }, + { provide: NGT_PHYSIC_BODY_ARGS_FN, useValue: () => [] }, + ], +}) +export class NgtPhysicPlane { + static ngAcceptInputType_getPhysicProps: GetByIndex | undefined; +} + +@NgModule({ + declarations: [NgtPhysicPlane], + exports: [NgtPhysicPlane], +}) +export class NgtPhysicPlaneModule {} diff --git a/packages/cannon/bodies/src/lib/sphere/sphere.directive.ts b/packages/cannon/bodies/src/lib/sphere/sphere.directive.ts new file mode 100644 index 000000000..87bc11fea --- /dev/null +++ b/packages/cannon/bodies/src/lib/sphere/sphere.directive.ts @@ -0,0 +1,35 @@ +// GENERATED +import { + SphereProps, + GetByIndex, + NGT_PHYSIC_BODY_ARGS_FN, + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + NGT_PHYSIC_BODY_TYPE, +} from '@angular-three/cannon'; +import { Directive, NgModule } from '@angular/core'; + +@Directive({ + selector: '[ngtPhysicSphere]', + exportAs: 'ngtPhysicSphere', + providers: [ + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'Sphere' }, + { + provide: NGT_PHYSIC_BODY_ARGS_FN, + useValue: (args: SphereProps['args'] = [1]) => { + if (!Array.isArray(args)) + throw new Error('ngtPhysicSphere args must be an array'); + return [args[0]]; + }, + }, + ], +}) +export class NgtPhysicSphere { + static ngAcceptInputType_getPhysicProps: GetByIndex | undefined; +} + +@NgModule({ + declarations: [NgtPhysicSphere], + exports: [NgtPhysicSphere], +}) +export class NgtPhysicSphereModule {} diff --git a/packages/cannon/bodies/src/lib/trimesh/trimesh.directive.ts b/packages/cannon/bodies/src/lib/trimesh/trimesh.directive.ts new file mode 100644 index 000000000..fb0f2341d --- /dev/null +++ b/packages/cannon/bodies/src/lib/trimesh/trimesh.directive.ts @@ -0,0 +1,26 @@ +// GENERATED +import { + TrimeshProps, + GetByIndex, + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + NGT_PHYSIC_BODY_TYPE, +} from '@angular-three/cannon'; +import { Directive, NgModule } from '@angular/core'; + +@Directive({ + selector: '[ngtPhysicTrimesh]', + exportAs: 'ngtPhysicTrimesh', + providers: [ + NGT_PHYSIC_BODY_CONTROLLER_PROVIDER, + { provide: NGT_PHYSIC_BODY_TYPE, useValue: 'Trimesh' }, + ], +}) +export class NgtPhysicTrimesh { + static ngAcceptInputType_getPhysicProps: GetByIndex | undefined; +} + +@NgModule({ + declarations: [NgtPhysicTrimesh], + exports: [NgtPhysicTrimesh], +}) +export class NgtPhysicTrimeshModule {} diff --git a/packages/cannon/src/lib/bodies/body.controller.ts b/packages/cannon/src/lib/bodies/body.controller.ts index 0d9141b04..587ce376f 100644 --- a/packages/cannon/src/lib/bodies/body.controller.ts +++ b/packages/cannon/src/lib/bodies/body.controller.ts @@ -1,3 +1,4 @@ +// GENERATED import { Controller, createControllerProviderFactory, @@ -9,7 +10,17 @@ import { GetByIndex } from '../models/types'; import { NgtPhysicBodyStore } from './body.store'; @Directive({ - selector: '[ngtPhysicBox], [ngtPhysicPlane], [ngtPhysicSphere]', + selector: ` + [ngtPhysicBox], + [ngtPhysicPlane], + [ngtPhysicCylinder], + [ngtPhysicHeightfield], + [ngtPhysicParticle], + [ngtPhysicSphere], + [ngtPhysicTrimesh], + [ngtPhysicConvexPolyhedron], + [ngtPhysicCompound] + `, exportAs: 'ngtPhysicBody', providers: [NgtPhysicBodyStore, NGT_OBJECT_CONTROLLER_PROVIDER], }) diff --git a/packages/core/src/lib/controllers/object-3d-inputs.controller.ts b/packages/core/src/lib/controllers/object-3d-inputs.controller.ts index db5b0717b..57ea9a18e 100644 --- a/packages/core/src/lib/controllers/object-3d-inputs.controller.ts +++ b/packages/core/src/lib/controllers/object-3d-inputs.controller.ts @@ -1,7 +1,22 @@ // GENERATED -import { Directive, EventEmitter, Input, NgModule, NgZone, Output } from '@angular/core'; +import { + Directive, + EventEmitter, + Input, + NgModule, + NgZone, + Output, +} from '@angular/core'; import * as THREE from 'three'; -import { NgtColor, NgtEuler, NgtEvent, NgtObject3dProps, NgtQuaternion, NgtVector3, UnknownRecord } from '../models'; +import { + NgtColor, + NgtEuler, + NgtEvent, + NgtObject3dProps, + NgtQuaternion, + NgtVector3, + UnknownRecord, +} from '../models'; import { makeColor, makeForSet, makeVector3 } from '../utils/make'; import { Controller, createControllerProviderFactory } from './controller'; @@ -49,7 +64,7 @@ import { Controller, createControllerProviderFactory } from './controller'; ngt-stereo-camera, ngt-cube-camera, `, - exportAs: 'ngtObject3dInputsController' + exportAs: 'ngtObject3dInputsController', }) export class NgtObject3dInputsController extends Controller { @Input() name?: string; @@ -159,7 +174,7 @@ export class NgtObject3dInputsController extends Controller { 'pointermove', 'pointermissed', 'pointercancel', - 'wheel' + 'wheel', ]; } @@ -184,22 +199,21 @@ export class NgtObject3dInputsController extends Controller { castShadow: this.castShadow, receiveShadow: this.receiveShadow, visible: this.visible, - matrixAutoUpdate: this.matrixAutoUpdate + matrixAutoUpdate: this.matrixAutoUpdate, }; } } @NgModule({ declarations: [NgtObject3dInputsController], - exports: [NgtObject3dInputsController] + exports: [NgtObject3dInputsController], }) -export class NgtObject3dInputsControllerModule { -} +export class NgtObject3dInputsControllerModule {} export const [ NGT_OBJECT_INPUTS_WATCHED_CONTROLLER, - NGT_OBJECT_INPUTS_CONTROLLER_PROVIDER + NGT_OBJECT_INPUTS_CONTROLLER_PROVIDER, ] = createControllerProviderFactory({ watchedControllerTokenName: 'Watched Object3dInputsController', - controller: NgtObject3dInputsController + controller: NgtObject3dInputsController, });