Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
feat(cannon): add physic bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Dec 1, 2021
1 parent de9dafe commit 7d947fc
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 12 deletions.
9 changes: 9 additions & 0 deletions packages/cannon/bodies/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
6 changes: 5 additions & 1 deletion packages/cannon/bodies/src/lib/box/box.directive.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// GENERATED
import {
BoxProps,
GetByIndex,
Expand All @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions packages/cannon/bodies/src/lib/compound/compound.directive.ts
Original file line number Diff line number Diff line change
@@ -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<CompoundBodyProps>
| undefined;
}

@NgModule({
declarations: [NgtPhysicCompound],
exports: [NgtPhysicCompound],
})
export class NgtPhysicCompoundModule {}
Original file line number Diff line number Diff line change
@@ -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<ConvexPolyhedronProps>
| undefined;
}

@NgModule({
declarations: [NgtPhysicConvexPolyhedron],
exports: [NgtPhysicConvexPolyhedron],
})
export class NgtPhysicConvexPolyhedronModule {}
33 changes: 33 additions & 0 deletions packages/cannon/bodies/src/lib/cylinder/cylinder.directive.ts
Original file line number Diff line number Diff line change
@@ -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<CylinderProps>
| undefined;
}

@NgModule({
declarations: [NgtPhysicCylinder],
exports: [NgtPhysicCylinder],
})
export class NgtPhysicCylinderModule {}
Original file line number Diff line number Diff line change
@@ -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<HeightfieldProps>
| undefined;
}

@NgModule({
declarations: [NgtPhysicHeightfield],
exports: [NgtPhysicHeightfield],
})
export class NgtPhysicHeightfieldModule {}
30 changes: 30 additions & 0 deletions packages/cannon/bodies/src/lib/particle/particle.directive.ts
Original file line number Diff line number Diff line change
@@ -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<ParticleProps>
| undefined;
}

@NgModule({
declarations: [NgtPhysicParticle],
exports: [NgtPhysicParticle],
})
export class NgtPhysicParticleModule {}
28 changes: 28 additions & 0 deletions packages/cannon/bodies/src/lib/plane/plane.directive.ts
Original file line number Diff line number Diff line change
@@ -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<PlaneProps> | undefined;
}

@NgModule({
declarations: [NgtPhysicPlane],
exports: [NgtPhysicPlane],
})
export class NgtPhysicPlaneModule {}
35 changes: 35 additions & 0 deletions packages/cannon/bodies/src/lib/sphere/sphere.directive.ts
Original file line number Diff line number Diff line change
@@ -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<SphereProps> | undefined;
}

@NgModule({
declarations: [NgtPhysicSphere],
exports: [NgtPhysicSphere],
})
export class NgtPhysicSphereModule {}
26 changes: 26 additions & 0 deletions packages/cannon/bodies/src/lib/trimesh/trimesh.directive.ts
Original file line number Diff line number Diff line change
@@ -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<TrimeshProps> | undefined;
}

@NgModule({
declarations: [NgtPhysicTrimesh],
exports: [NgtPhysicTrimesh],
})
export class NgtPhysicTrimeshModule {}
13 changes: 12 additions & 1 deletion packages/cannon/src/lib/bodies/body.controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// GENERATED
import {
Controller,
createControllerProviderFactory,
Expand All @@ -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],
})
Expand Down
34 changes: 24 additions & 10 deletions packages/core/src/lib/controllers/object-3d-inputs.controller.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -159,7 +174,7 @@ export class NgtObject3dInputsController extends Controller {
'pointermove',
'pointermissed',
'pointercancel',
'wheel'
'wheel',
];
}

Expand All @@ -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,
});

0 comments on commit 7d947fc

Please sign in to comment.