Skip to content

Commit

Permalink
[core] Extend texture, textureInfo, and extension checks in material.…
Browse files Browse the repository at this point in the history
…equals().
  • Loading branch information
donmccurdy committed Oct 31, 2021
1 parent e27344a commit 7db0ffd
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions packages/core/src/properties/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export class Material extends ExtensibleProperty {
* including possible {@link TextureInfo}.
*/
public equals(other: Material): boolean {
// Factors and modes.

if (this.getAlphaMode() !== other.getAlphaMode()) return false;
if (this.getAlphaCutoff() !== other.getAlphaCutoff()) return false;
if (this.getDoubleSided() !== other.getDoubleSided()) return false;
Expand All @@ -207,45 +209,52 @@ export class Material extends ExtensibleProperty {
if (this.getRoughnessFactor() !== other.getRoughnessFactor()) return false;
if (this.getMetallicFactor() !== other.getMetallicFactor()) return false;

// Texture Checks
if (this.getBaseColorTextureInfo() && other.getBaseColorTextureInfo()) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// ! For some reason my editor does not grasp the non-null assertion below
// ! Nulls should be addressed above
if (!this!.getBaseColorTextureInfo().equals(other!.getBaseColorTextureInfo())) {
// Textures.

if (this.getBaseColorTexture() && other.getBaseColorTexture()) {
if (this.getBaseColorTexture() !== other.getBaseColorTexture()) return false;
if (!this.getBaseColorTextureInfo()!.equals(other.getBaseColorTextureInfo()!)) {
return false;
}
}
if (this.getEmissiveTextureInfo() && other.getEmissiveTextureInfo()) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (!this.getEmissiveTextureInfo().equals(other.getEmissiveTextureInfo())) {
if (this.getEmissiveTexture() && other.getEmissiveTexture()) {
if (this.getEmissiveTexture() !== other.getEmissiveTexture()) return false;
if (!this.getEmissiveTextureInfo()!.equals(other.getEmissiveTextureInfo()!)) {
return false;
}
}
if (this.getNormalTextureInfo() && other.getNormalTextureInfo()) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (!this.getNormalTextureInfo().equals(other.getNormalTextureInfo())) {
if (this.getNormalTexture() && other.getNormalTexture()) {
if (this.getNormalTexture() !== other.getNormalTexture()) return false;
if (!this.getNormalTextureInfo()!.equals(other.getNormalTextureInfo()!)) {
return false;
}
}
if (this.getOcclusionTextureInfo() && other.getOcclusionTextureInfo()) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (!this.getOcclusionTextureInfo().equals(other.getOcclusionTextureInfo())) {
if (this.getOcclusionTexture() && other.getOcclusionTexture()) {
if (this.getOcclusionTexture() !== other.getOcclusionTexture()) return false;
if (!this.getOcclusionTextureInfo()!.equals(other.getOcclusionTextureInfo()!)) {
return false;
}
}
if (this.getMetallicRoughnessTextureInfo() && other.getMetallicRoughnessTextureInfo()) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line max-len
if (!this.getMetallicRoughnessTextureInfo().equals(other.getMetallicRoughnessTextureInfo())) {
if (this.getMetallicRoughnessTexture() && other.getMetallicRoughnessTexture()) {
if (this.getMetallicRoughnessTexture() !== other.getMetallicRoughnessTexture()) {
return false;
}
if (!this.getMetallicRoughnessTextureInfo()!
.equals(other.getMetallicRoughnessTextureInfo()!)) {
return false;
}
}

// Extensions.

const extensions = this.listExtensions();
const otherExtensions = other.listExtensions();
if (extensions.length !== otherExtensions.length) return false;
for (let i = 0; i < extensions.length; i++) {
// TODO(feat): Implement deep equality checks for material extensions.
if (extensions[i] !== otherExtensions[i]) return false;
}

return true;
}

Expand Down

0 comments on commit 7db0ffd

Please sign in to comment.