Skip to content

Commit

Permalink
Add Anisotropy
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoteran committed Jul 11, 2023
1 parent 22c0997 commit 78c10ae
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/model-viewer/src/features/scene-graph/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export declare interface Material {
readonly iridescenceThicknessMinimum: number;
readonly iridescenceThicknessMaximum: number;
readonly iridescenceThicknessTexture: TextureInfo;
readonly anisotropyStrength: number;
readonly anisotropyRotation: number;
readonly anisotropyTexture: TextureInfo;

setEmissiveStrength(emissiveStrength: number): void;
setClearcoatFactor(clearcoatFactor: number): void;
Expand All @@ -165,6 +168,8 @@ export declare interface Material {
setIridescenceIor(ior: number): void;
setIridescenceThicknessMinimum(thicknessMin: number): void;
setIridescenceThicknessMaximum(thicknessMax: number): void;
setAnisotropyStrength(strength: number): void;
setAnisotropyRotation(rotation: number): void;

/**
* The PBRMetallicRoughness configuration of the material.
Expand Down
35 changes: 35 additions & 0 deletions packages/model-viewer/src/features/scene-graph/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ export class Material extends ThreeDOMElement implements MaterialInterface {
createTextureInfo(TextureUsage.Thickness);
createTextureInfo(TextureUsage.Specular);
createTextureInfo(TextureUsage.SpecularColor);
createTextureInfo(TextureUsage.Iridescence);
createTextureInfo(TextureUsage.IridescenceThickness);
createTextureInfo(TextureUsage.Anisotropy);
}

async[$getLoadedMaterial](): Promise<MeshPhysicalMaterial> {
Expand Down Expand Up @@ -659,4 +662,36 @@ export class Material extends ThreeDOMElement implements MaterialInterface {
}

// KHR_materials_anisotropy
get anisotropyStrength(): number {
this[$ensureMaterialIsLoaded]();
return (this[$backingThreeMaterial] as any).anisotropy;
}

get anisotropyRotation(): number {
this[$ensureMaterialIsLoaded]();
return (this[$backingThreeMaterial] as any).anisotropyRotation;
}

get anisotropyTexture(): TextureInfo {
this[$ensureMaterialIsLoaded]();
return this[$pbrTextures].get(TextureUsage.Anisotropy)!;
}

setAnisotropyStrength(strength: number) {
this[$ensureMaterialIsLoaded]();
for (const material of this[$correlatedObjects] as
Set<MeshPhysicalMaterial>) {
(material as any).anisotropy = strength;
}
this[$onUpdate]();
}

setAnisotropyRotation(rotation: number) {
this[$ensureMaterialIsLoaded]();
for (const material of this[$correlatedObjects] as
Set<MeshPhysicalMaterial>) {
(material as any).anisotropyRotation = rotation;
}
this[$onUpdate]();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export enum TextureUsage {
SpecularColor,
Iridescence,
IridescenceThickness,
Anisotropy,
}

interface TextureTransform {
Expand Down Expand Up @@ -189,6 +190,9 @@ export class TextureInfo implements TextureInfoInterface {
case TextureUsage.IridescenceThickness:
material.iridescenceThicknessMap = threeTexture;
break;
case TextureUsage.Anisotropy:
(material as any).anisotropyMap = threeTexture;
break;
default:
}
material.needsUpdate = true;
Expand Down

0 comments on commit 78c10ae

Please sign in to comment.