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

Commit

Permalink
fix(materials): adjust how sub materials classes instantiate new mate…
Browse files Browse the repository at this point in the history
…rial
  • Loading branch information
nartc committed Apr 16, 2021
1 parent 69dbdda commit 80d32d0
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Color, Material, MaterialParameters } from 'three';
@Directive()
export abstract class ThreeMaterial<
TMaterial extends Material = Material,
TMaterialParameters extends MaterialParameters = MaterialParameters
TMaterialParameters extends MaterialParameters = MaterialParameters,
TMaterialConstructor extends typeof Material = typeof Material
> {
@Input() ngtId?: string;

Expand All @@ -30,12 +31,14 @@ export abstract class ThreeMaterial<
@SkipSelf() protected readonly canvasStore: CanvasStore
) {}

abstract init(): TMaterial;
abstract materialType: TMaterialConstructor;

private _material?: TMaterial;
get material(): TMaterial {
if (this._material == null) {
this._material = this.init();
this._material = new ((this.materialType as unknown) as new (
params?: TMaterialParameters
) => TMaterial)(this.parameters);
this.instancesStore.saveMaterial({
id: this.ngtId,
material: this._material,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import { ThreeMaterial } from '../abstracts';
})
export class MeshLambertMaterialDirective extends ThreeMaterial<
MeshLambertMaterial,
MeshLambertMaterialParameters
MeshLambertMaterialParameters,
typeof MeshLambertMaterial
> {
static ngAcceptInputType_parameters:
| MeshLambertMaterialParameters
| undefined;

init(): MeshLambertMaterial {
return new MeshLambertMaterial(this.parameters);
}
materialType = MeshLambertMaterial;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { ThreeMaterial } from '../abstracts';
})
export class MeshNormalMaterialDirective extends ThreeMaterial<
MeshNormalMaterial,
MeshNormalMaterialParameters
MeshNormalMaterialParameters,
typeof MeshNormalMaterial
> {
static ngAcceptInputType_parameters: MeshNormalMaterialParameters;

init(): MeshNormalMaterial {
return new MeshNormalMaterial(this.parameters);
}
materialType = MeshNormalMaterial;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { ThreeMaterial } from '../abstracts';
})
export class MeshPhongMaterialDirective extends ThreeMaterial<
MeshPhongMaterial,
MeshPhongMaterialParameters
MeshPhongMaterialParameters,
typeof MeshPhongMaterial
> {
static ngAcceptInputType_parameters: MeshPhongMaterialParameters;

init(): MeshPhongMaterial {
return new MeshPhongMaterial(this.parameters);
}
materialType = MeshPhongMaterial;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { ThreeMaterial } from '../abstracts';
})
export class MeshStandardMaterialDirective extends ThreeMaterial<
MeshStandardMaterial,
MeshStandardMaterialParameters
MeshStandardMaterialParameters,
typeof MeshStandardMaterial
> {
static ngAcceptInputType_parameters: MeshStandardMaterialParameters;

init(): MeshStandardMaterial {
return new MeshStandardMaterial(this.parameters);
}
materialType = MeshStandardMaterial;
}

0 comments on commit 80d32d0

Please sign in to comment.