Skip to content

Commit

Permalink
fix for converting KHR_materials_common CONSTANT technique to KHR_mat…
Browse files Browse the repository at this point in the history
…erials_unlit
  • Loading branch information
deng0 committed Feb 9, 2024
1 parent adcfeff commit 58b138d
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions lib/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,23 +1094,37 @@ function convertMaterialsCommonToPbr(gltf) {

if (defined(materialsCommon)) {
const technique = materialsCommon.technique;

const values = defined(materialsCommon.values)
? materialsCommon.values
: {};

ambient = values.ambient;
diffuse = values.diffuse;
emission = values.emission;
const transparency = values.transparency;

if (technique === "CONSTANT") {
// Add the KHR_materials_unlit extension
addExtensionsUsed(gltf, "KHR_materials_unlit");
material.extensions = defined(material.extensions)
? material.extensions
: {};
material.extensions["KHR_materials_unlit"] = {};
}

const values = defined(materialsCommon.values)
? materialsCommon.values
: {};

const ambient = values.ambient;
const diffuse = values.diffuse;
const emission = values.emission;
const transparency = values.transparency;
if (!defined(diffuse))
{
// diffuse shouldn't be used for CONSTANT technique, only emission/ambient
// therefore copy emission/ambient to diffuse so it will be used as baseColor
if(defined(emission)) {
diffuse = emission;
emission = undefined;
}else if (defined(ambient)) {
diffuse = ambient;
ambient = undefined;
}
}
}

// These actually exist on the extension object, not the values object despite what's shown in the spec
const doubleSided = materialsCommon.doubleSided;
Expand Down

0 comments on commit 58b138d

Please sign in to comment.