Skip to content

Commit

Permalink
Update gltf-pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
mramato committed Jun 3, 2023
1 parent d11b746 commit 6ddd80e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
27 changes: 27 additions & 0 deletions packages/engine/Source/Scene/GltfPipeline/removeUnusedElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ Remove.accessor = function (gltf, accessorId) {
if (defined(indices) && indices > accessorId) {
primitive.indices--;
}

const ext = primitive.extensions;
if (
defined(ext) &&
defined(ext.CESIUM_primitive_outline) &&
ext.CESIUM_primitive_outline.indices > accessorId
) {
--ext.CESIUM_primitive_outline.indices;
}
});
});

Expand Down Expand Up @@ -546,6 +555,24 @@ getListOfElementsIdsInUse.accessor = function (gltf) {
});
}

if (usesExtension(gltf, "CESIUM_primitive_outline")) {
ForEach.mesh(gltf, function (mesh) {
ForEach.meshPrimitive(mesh, function (primitive) {
const extensions = primitive.extensions;
if (
defined(extensions) &&
defined(extensions.CESIUM_primitive_outline)
) {
const extension = extensions.CESIUM_primitive_outline;
const indicesAccessorId = extension.indices;
if (defined(indicesAccessorId)) {
usedAccessorIds[indicesAccessorId] = true;
}
}
});
});
}

return usedAccessorIds;
};

Expand Down
25 changes: 21 additions & 4 deletions packages/engine/Source/Scene/GltfPipeline/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const updateFunctions = {
* @param {object} gltf A javascript object containing a glTF asset.
* @param {object} [options] Options for updating the glTF.
* @param {string} [options.targetVersion] The glTF will be upgraded until it hits the specified version.
* @param {string[]} [options.baseColorTextureNames] Names of uniforms that indicate base color textures.
* @param {string[]} [options.baseColorFactorNames] Names of uniforms that indicate base color factors.
* @returns {object} The updated glTF asset.
*
* @private
Expand Down Expand Up @@ -73,7 +75,7 @@ function updateVersion(gltf, options) {
}

if (!options.keepLegacyExtensions) {
convertTechniquesToPbr(gltf);
convertTechniquesToPbr(gltf, options);
convertMaterialsCommonToPbr(gltf);
}

Expand Down Expand Up @@ -1003,8 +1005,13 @@ function glTF10to20(gltf) {
// It's not possible to upgrade glTF 1.0 shaders to 2.0 PBR materials in a generic way,
// but we can look for certain uniform names that are commonly found in glTF 1.0 assets
// and create PBR materials out of those.
const baseColorTextureNames = ["u_tex", "u_diffuse", "u_emission"];
const baseColorFactorNames = ["u_diffuse"];
const defaultBaseColorTextureNames = [
"u_tex",
"u_diffuse",
"u_emission",
"u_diffuse_tex",
];
const defaultBaseColorFactorNames = ["u_diffuse", "u_diffuse_mat"];

function initializePbrMaterial(material) {
material.pbrMetallicRoughness = defined(material.pbrMetallicRoughness)
Expand Down Expand Up @@ -1044,7 +1051,17 @@ function srgbToLinear(srgb) {
return linear;
}

function convertTechniquesToPbr(gltf) {
function convertTechniquesToPbr(gltf, options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
const baseColorTextureNames = defaultValue(
options.baseColorTextureNames,
defaultBaseColorTextureNames
);
const baseColorFactorNames = defaultValue(
options.baseColorFactorNames,
defaultBaseColorFactorNames
);

// Future work: convert other values like emissive, specular, etc. Only handling diffuse right now.
ForEach.material(gltf, function (material) {
ForEach.materialValue(material, function (value, name) {
Expand Down

0 comments on commit 6ddd80e

Please sign in to comment.