Skip to content

[FIX] Handle case where pbrMetallicRoughness is not present #7198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions src/framework/parsers/glb-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,17 +1112,22 @@ const extensionIridescence = (data, material, textures) => {
const createMaterial = (gltfMaterial, textures) => {
const material = new StandardMaterial();

if (gltfMaterial.hasOwnProperty('name')) {
material.name = gltfMaterial.name;
}

// glTF doesn't define how to occlude specular
material.occludeSpecular = SPECOCC_AO;

material.diffuseVertexColor = true;

material.specularTint = true;
material.specularVertexColor = true;

if (gltfMaterial.hasOwnProperty('name')) {
material.name = gltfMaterial.name;
}
// Set glTF spec defaults
material.specular.set(1, 1, 1);
material.gloss = 0;
material.glossInvert = true;
material.useMetalness = true;

let color, texture;
if (gltfMaterial.hasOwnProperty('pbrMetallicRoughness')) {
Expand All @@ -1133,9 +1138,6 @@ const createMaterial = (gltfMaterial, textures) => {
// Convert from linear space to sRGB space
material.diffuse.set(Math.pow(color[0], 1 / 2.2), Math.pow(color[1], 1 / 2.2), Math.pow(color[2], 1 / 2.2));
material.opacity = color[3];
} else {
material.diffuse.set(1, 1, 1);
material.opacity = 1;
}
if (pbrData.hasOwnProperty('baseColorTexture')) {
const baseColorTexture = pbrData.baseColorTexture;
Expand All @@ -1148,19 +1150,12 @@ const createMaterial = (gltfMaterial, textures) => {

extractTextureTransform(baseColorTexture, material, ['diffuse', 'opacity']);
}
material.useMetalness = true;
material.specular.set(1, 1, 1);
if (pbrData.hasOwnProperty('metallicFactor')) {
material.metalness = pbrData.metallicFactor;
} else {
material.metalness = 1;
}
if (pbrData.hasOwnProperty('roughnessFactor')) {
material.gloss = pbrData.roughnessFactor;
} else {
material.gloss = 1;
}
material.glossInvert = true;
if (pbrData.hasOwnProperty('metallicRoughnessTexture')) {
const metallicRoughnessTexture = pbrData.metallicRoughnessTexture;
material.metalnessMap = material.glossMap = textures[metallicRoughnessTexture.index];
Expand Down Expand Up @@ -1195,8 +1190,6 @@ const createMaterial = (gltfMaterial, textures) => {
color = gltfMaterial.emissiveFactor;
// Convert from linear space to sRGB space
material.emissive.set(Math.pow(color[0], 1 / 2.2), Math.pow(color[1], 1 / 2.2), Math.pow(color[2], 1 / 2.2));
} else {
material.emissive.set(0, 0, 0);
}

if (gltfMaterial.hasOwnProperty('emissiveTexture')) {
Expand Down
Loading