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

Commit

Permalink
feat(generators): setup passes generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed May 1, 2021
1 parent ce956af commit 75f6c92
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/core/src/lib/typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './scene';
export * from './camera';
export * from './common';
export * from './loader';
export * from './pass';
4 changes: 4 additions & 0 deletions packages/core/src/lib/typings/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type WithoutSceneCameraConstructorParameters<
T,
TReturn = T extends [infer First, infer Second, ...infer Rest] ? Rest : T
> = TReturn;
19 changes: 15 additions & 4 deletions packages/postprocessing/ssao-pass/src/lib/ssao-pass.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { UnknownRecord } from '@angular-three/core';
import type {
UnknownRecord,
WithoutSceneCameraConstructorParameters,
} from '@angular-three/core';
import { ThreePass } from '@angular-three/postprocessing';
import { Directive, Input } from '@angular/core';
import type {
Expand All @@ -18,11 +21,20 @@ import { SSAOPass } from 'three/examples/jsm/postprocessing/SSAOPass';
providers: [{ provide: ThreePass, useExisting: SsaoPassDirective }],
})
export class SsaoPassDirective extends ThreePass<SSAOPass> {
@Input() set args(v: ConstructorParameters<typeof SSAOPass>) {
static ngAcceptInputType_args:
| WithoutSceneCameraConstructorParameters<
ConstructorParameters<typeof SSAOPass>
>
| undefined;

@Input() set args(
v: WithoutSceneCameraConstructorParameters<
ConstructorParameters<typeof SSAOPass>
>
) {
this.extraArgs = v;
}

@Input() clear?: boolean;
@Input() kernelRadius?: number;
@Input() kernelSize?: number;
@Input() kernel?: Vector3[];
Expand All @@ -44,7 +56,6 @@ export class SsaoPassDirective extends ThreePass<SSAOPass> {

passType = SSAOPass;
extraInputs = [
'clear',
'kernelRadius',
'kernelSize',
'kernel',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lib/<%= dasherize(name) %>.module';
export * from './lib/<%= dasherize(name) %>.directive';
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<% if (threeCoreImports.length) { %>import type {<% for (const coreImport of threeCoreImports) { %>
<%= coreImport %>,
<% } %>} from '@angular-three/core';<% } %>
import { ThreePass } from '@angular-three/postprocessing';
import { Directive, Input } from '@angular/core';<% if (threeImports.length) { %>
import type {<% for (const threeImport of threeImports) { %>
<%= threeImport %>,
<% } %>} from 'three';<% } %><% if (passImports.length) { %>
import type {<% for (const passImport of passImports) { %>
<%= passImport %>,
<% } %>} from 'three/examples/jsm/postprocessing/<%= name %>';<% } %>
import { <%= name %> } from 'three/examples/jsm/postprocessing/<%= name %>';

@Directive({
selector: 'ngt-<%= dasherize(name) %>',
exportAs: 'ngt<%= name %>',
providers: [{ provide: ThreePass, useExisting: <%= name %>Directive }],
})
export class <%= name %>Directive extends ThreePass<<%= name %>> {
static ngAcceptInputType_args:
| <% if (withSceneAndCamera) { %>WithoutSceneCameraConstructorParameters<ConstructorParameters<typeof <%= name %>>> <% } else { %>ConstructorParameters<typeof <%= name %>><% } %>
| undefined;

@Input() set args(v: <% if (withSceneAndCamera) { %>WithoutSceneCameraConstructorParameters<ConstructorParameters<typeof <%= name %>>> <% } else { %>ConstructorParameters<typeof <%= name %>><% } %>) {
this.extraArgs = v;
}<% for (const input of inputs) { %>
@Input() <%= input.name %><% if (input.isOptional) { %>?<% } %>: <%= input.import %><% if (input.isArray) { %>[]<% } %><% if (input.default) { %> = <%= input.default %>;<% } else { %>;<% } %>
<% } %>

passType = <%= name %>;<% if (inputs.length) { %>
extraInputs = [<% for (const input of inputs) { %>
'<%= input.name %>',
<% } %>];<% } %>
<% if (withSceneAndCamera) { %>
protected get useSceneAndCamera(): boolean {
return true;
}<% } %>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
import { <%= name %>Directive } from './<%= dasherize(name) %>.directive';

@NgModule({
declarations: [<%= name %>Directive],
exports: [<%= name %>Directive],
})
export class Three<%= name %>Module {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"extends": [
"../../../.eslintrc.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"parserOptions": {
"project": [
"packages/postprocessing/<%= dasherize(name) %>/tsconfig.*?.json"
]
},
"rules": {
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "ngt",
"style": "kebab-case"
}
]
}
},
{
"files": [
"*.html"
],
"extends": [
"plugin:@nrwl/nx/angular-template"
],
"rules": {}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/packages/postprocessing/<%= dasherize(name) %>",
"lib": {
"entryFile": "src/index.ts",
"umdModuleIds": {
"three/examples/jsm/postprocessing/<%= name %>": "three/examples/jsm/postprocessing/<%= name %>",<% if (importThree) { %>
"three": "three",<% } %>
"@angular-three/core": "@angular-three/core"
}
}
}

0 comments on commit 75f6c92

Please sign in to comment.