This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controls): add controls and testing out generator
- Loading branch information
Showing
46 changed files
with
2,516 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts"], | ||
"extends": [ | ||
"plugin:@nrwl/nx/angular", | ||
"plugin:@angular-eslint/template/process-inline-templates" | ||
], | ||
"rules": { | ||
"@angular-eslint/directive-selector": [ | ||
"error", | ||
{ | ||
"type": "attribute", | ||
"prefix": "ngt", | ||
"style": "camelCase" | ||
} | ||
], | ||
"@angular-eslint/component-selector": [ | ||
"error", | ||
{ | ||
"type": "element", | ||
"prefix": "ngt", | ||
"style": "kebab-case" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"files": ["*.html"], | ||
"extends": ["plugin:@nrwl/nx/angular-template"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# controls | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test controls` to execute the unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
displayName: 'controls', | ||
preset: '../../jest.preset.js', | ||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
stringifyContentPathRegex: '\\.(html|svg)$', | ||
}, | ||
}, | ||
coverageDirectory: '../../coverage/packages/controls', | ||
transform: { | ||
'^.+\\.(ts|js|html)$': 'jest-preset-angular', | ||
}, | ||
snapshotSerializers: [ | ||
'jest-preset-angular/build/serializers/no-ng-attributes', | ||
'jest-preset-angular/build/serializers/ng-snapshot', | ||
'jest-preset-angular/build/serializers/html-comment', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json", | ||
"dest": "../../dist/packages/controls", | ||
"lib": { | ||
"entryFile": "src/index.ts", | ||
"umdModuleIds": { | ||
"three": "three" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@angular-three/controls", | ||
"version": "0.0.1", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"peerDependencies": { | ||
"@angular/common": "^12.2.0", | ||
"@angular/core": "^12.2.0" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"projectType": "library", | ||
"root": "packages/controls", | ||
"sourceRoot": "packages/controls/src", | ||
"prefix": "ngt", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/angular:package", | ||
"outputs": ["dist/packages/controls"], | ||
"options": { | ||
"project": "packages/controls/ng-package.json" | ||
}, | ||
"configurations": { | ||
"production": { | ||
"tsConfig": "packages/controls/tsconfig.lib.prod.json" | ||
}, | ||
"development": { | ||
"tsConfig": "packages/controls/tsconfig.lib.json" | ||
} | ||
}, | ||
"defaultConfiguration": "production" | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["coverage/packages/controls"], | ||
"options": { | ||
"jestConfig": "packages/controls/jest.config.js", | ||
"passWithNoTests": true | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/controls/src/**/*.ts", | ||
"packages/controls/src/**/*.html" | ||
] | ||
} | ||
} | ||
}, | ||
"tags": ["scope:controls", "type:library"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib/controls'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
AnimationStore, | ||
CanvasStore, | ||
DestroyedService, | ||
NgtAnimationParticipant, | ||
NgtCamera, | ||
UnknownRecord, | ||
} from '@angular-three/core'; | ||
import { | ||
Directive, | ||
EventEmitter, | ||
NgZone, | ||
OnDestroy, | ||
OnInit, | ||
Output, | ||
SkipSelf, | ||
} from '@angular/core'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
import * as THREE from 'three'; | ||
|
||
@Directive() | ||
export abstract class NgtControls<TControls = unknown> | ||
extends NgtAnimationParticipant<TControls> | ||
implements OnInit, OnDestroy | ||
{ | ||
@Output() ready = new EventEmitter<TControls>(); | ||
|
||
constructor( | ||
ngZone: NgZone, | ||
@SkipSelf() protected canvasStore: CanvasStore, | ||
@SkipSelf() animationStore: AnimationStore, | ||
protected destroyed: DestroyedService | ||
) { | ||
super(animationStore, ngZone); | ||
} | ||
|
||
private _controls?: TControls; | ||
|
||
ngOnInit() { | ||
this.ngZone.runOutsideAngular(() => { | ||
this.canvasStore.selectors.internal$ | ||
.pipe(takeUntil(this.destroyed)) | ||
.subscribe(({ active }) => { | ||
this.ngZone.runOutsideAngular(() => { | ||
const { camera, renderer, scene } = | ||
this.canvasStore.getImperativeState(); | ||
if (active && camera && renderer && scene) { | ||
this._controls = this.initControls(camera, renderer, scene); | ||
if (this.controls) { | ||
this.ready.emit(this.controls); | ||
this.participate(this.controls); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
get controls(): TControls | undefined { | ||
return this._controls; | ||
} | ||
|
||
abstract initControls( | ||
camera: NgtCamera, | ||
renderer: THREE.WebGLRenderer, | ||
scene: THREE.Scene | ||
): TControls; | ||
|
||
ngOnDestroy() { | ||
super.ngOnDestroy(); | ||
this.ngZone.runOutsideAngular(() => { | ||
if (this.controls && (this.controls as UnknownRecord).dispose) { | ||
((this.controls as UnknownRecord).dispose as () => void)(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'jest-preset-angular/setup-jest'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.lib.prod.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"angularCompilerOptions": { | ||
"strictInjectionParameters": true, | ||
"strictInputAccessModifiers": true, | ||
"strictTemplates": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"target": "es2015", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"inlineSources": true, | ||
"types": [], | ||
"lib": ["dom", "es2018"] | ||
}, | ||
"exclude": ["src/test-setup.ts", "**/*.spec.ts", "**/*.test.ts"], | ||
"include": ["**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* To learn more about this file see: https://angular.io/config/tsconfig. */ | ||
{ | ||
"extends": "./tsconfig.lib.json", | ||
"compilerOptions": { | ||
"declarationMap": false | ||
}, | ||
"angularCompilerOptions": { | ||
"compilationMode": "partial" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"files": ["src/test-setup.ts"], | ||
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,5 +54,5 @@ | |
} | ||
} | ||
}, | ||
"tags": ["scope:core", "type:library", "context:core"] | ||
"tags": ["scope:core", "type:library"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as THREE from 'three'; | ||
import type { EntityCollection } from '../models/entity-collection.model'; | ||
|
||
export const attributes: EntityCollection = { | ||
core: [ | ||
THREE.BufferAttribute, | ||
THREE.InstancedBufferAttribute, | ||
THREE.InterleavedBufferAttribute, | ||
THREE.Float16BufferAttribute, | ||
THREE.Float32BufferAttribute, | ||
THREE.Float64BufferAttribute, | ||
THREE.Int8BufferAttribute, | ||
THREE.Int16BufferAttribute, | ||
THREE.Int32BufferAttribute, | ||
THREE.Uint8BufferAttribute, | ||
THREE.Uint16BufferAttribute, | ||
THREE.Uint32BufferAttribute, | ||
THREE.Uint8ClampedBufferAttribute, | ||
].map((m) => m.name), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as THREE from 'three'; | ||
import type { EntityCollection } from '../models/entity-collection.model'; | ||
|
||
export const cameras: EntityCollection = { | ||
core: [ | ||
THREE.Camera, | ||
THREE.PerspectiveCamera, | ||
THREE.OrthographicCamera, | ||
THREE.ArrayCamera, | ||
THREE.StereoCamera, | ||
].map((m) => m.name), | ||
}; |
Oops, something went wrong.