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

Commit

Permalink
feat(soba): adjust Image
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Apr 16, 2022
1 parent 8916320 commit c5659de
Show file tree
Hide file tree
Showing 2 changed files with 262 additions and 112 deletions.
73 changes: 60 additions & 13 deletions libs/soba/abstractions/src/lib/image/image-shader-material.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { NgtColor, NgtMaterial, shaderMaterial } from '@angular-three/core';
import { Directive, NgModule } from '@angular/core';
import {
AnyConstructor,
NgtColor,
provideCommonMaterialRef,
shaderMaterial,
} from '@angular-three/core';
import { NgtShaderMaterial } from '@angular-three/core/materials';
import {
ChangeDetectionStrategy,
Component,
Input,
NgModule,
} from '@angular/core';
import * as THREE from 'three';

export type NgtSobaImageShaderMaterialParameters =
Expand Down Expand Up @@ -60,22 +71,58 @@ export const ImageShaderMaterial = shaderMaterial(
`
);

@Directive({
@Component({
selector: 'ngt-soba-image-shader-material',
exportAs: 'ngtSobaImageShaderMaterial',
providers: [
{ provide: NgtMaterial, useExisting: NgtSobaImageShaderMaterial },
],
template: `<ng-content></ng-content>`,
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [provideCommonMaterialRef(NgtSobaImageShaderMaterial)],
})
export class NgtSobaImageShaderMaterial extends NgtMaterial<
NgtSobaImageShaderMaterialParameters,
typeof ImageShaderMaterial.prototype
> {
static ngAcceptInputType_parameters:
export class NgtSobaImageShaderMaterial extends NgtShaderMaterial {
static override ngAcceptInputType_parameters:
| NgtSobaImageShaderMaterialParameters
| undefined;

materialType = ImageShaderMaterial;
@Input() set map(map: THREE.Texture) {
this.set({ map });
}

@Input() set scale(scale: number[]) {
this.set({ scale });
}

@Input() set imageBounds(imageBounds: number[]) {
this.set({ imageBounds });
}

@Input() set color(color: NgtColor) {
this.set({ color });
}

@Input() set zoom(zoom: number) {
this.set({ zoom });
}

@Input() set grayscale(grayscale: number) {
this.set({ grayscale });
}

override get materialType(): AnyConstructor<
typeof ImageShaderMaterial.prototype
> {
return ImageShaderMaterial;
}

protected override get optionFields(): Record<string, boolean> {
return {
...super.optionFields,
map: false,
scale: true,
imageBounds: true,
color: true,
zoom: true,
grayscale: true,
};
}
}

@NgModule({
Expand Down
Loading

0 comments on commit c5659de

Please sign in to comment.