From 7f8e11dd8076301de5f0b91f06c059b58b47d081 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 9 Aug 2018 20:01:17 -0400 Subject: [PATCH 1/3] Add default pbr material --- Source/ThirdParty/GltfPipeline/addDefaults.js | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/Source/ThirdParty/GltfPipeline/addDefaults.js b/Source/ThirdParty/GltfPipeline/addDefaults.js index bdf07ec0de4b..e9b82ec99fd7 100644 --- a/Source/ThirdParty/GltfPipeline/addDefaults.js +++ b/Source/ThirdParty/GltfPipeline/addDefaults.js @@ -242,6 +242,15 @@ define([ }); } + var defaultPbrMaterial = { + emissiveFactor: [0.0, 0.0, 0.0], + alphaMode: 'OPAQUE', + doubleSided: false, + extras : { + _pipeline: {} + } + }; + var defaultMaterial = { values : { emission : [ @@ -335,6 +344,24 @@ define([ } }; + function addDefaultPbrMaterial(gltf) { + var materials = gltf.materials; + var meshes = gltf.meshes; + + var meshesLength = meshes.length; + for (var meshId = 0; meshId < meshesLength; meshId++) { + var mesh = meshes[meshId]; + var primitives = mesh.primitives; + var primitivesLength = primitives.length; + for (var j = 0; j < primitivesLength; j++) { + var primitive = primitives[j]; + if (!defined(primitive.material)) { + primitive.material = addToArray(materials, clone(defaultPbrMaterial, true)); + } + } + } + } + function addDefaultMaterial(gltf) { var materials = gltf.materials; var meshes = gltf.meshes; @@ -349,10 +376,7 @@ define([ for (var j = 0; j < primitivesLength; j++) { var primitive = primitives[j]; if (!defined(primitive.material)) { - if (!defined(defaultMaterialId)) { - defaultMaterialId = addToArray(materials, clone(defaultMaterial, true)); - } - primitive.material = defaultMaterialId; + primitive.material = addToArray(materials, clone(defaultMaterial, true)); } } } @@ -512,6 +536,8 @@ define([ if (gltf.asset.extras.gltf_pipeline_upgrade_10to20) { addDefaultMaterial(gltf); addDefaultTechnique(gltf); + } else { + addDefaultPbrMaterial(gltf); } addDefaultByteOffsets(gltf); From bf6eb2727be39534027e8b6efd9380aa8bc88dc5 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 9 Aug 2018 20:06:33 -0400 Subject: [PATCH 2/3] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index ab00e827633b..0b63bd9797fb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,7 @@ Change Log * Fixed bug that caused a new `ClippingPlaneCollection` to be created every frame when used with a model entity [#6872](https://github.com/AnalyticalGraphicsInc/cesium/pull/6872) * Fixed crash when rendering translucent objects when all shadow maps in the scene set `fromLightSource` to false. [#6883](https://github.com/AnalyticalGraphicsInc/cesium/pull/6883) * Fixed night shading in 2D and Columbus view. [#4122](https://github.com/AnalyticalGraphicsInc/cesium/issues/4122) +* Fixed model loading failure when a primitive does not have a material. [6906](https://github.com/AnalyticalGraphicsInc/cesium/pull/6906) ### 1.48 - 2018-08-01 From 92ffe03be5d400190d332a2d34a7d5a9a0372cf6 Mon Sep 17 00:00:00 2001 From: Gabby Getz Date: Mon, 27 Aug 2018 14:38:42 -0400 Subject: [PATCH 3/3] Tweak CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 94ff798503ed..31f212d40d7f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -33,7 +33,7 @@ Change Log * Improved `Plane` entities so they are better aligned with the globe surface [#6887](https://github.com/AnalyticalGraphicsInc/cesium/pull/6887) * Fixed crash when rendering translucent objects when all shadow maps in the scene set `fromLightSource` to false. [#6883](https://github.com/AnalyticalGraphicsInc/cesium/pull/6883) * Fixed night shading in 2D and Columbus view. [#4122](https://github.com/AnalyticalGraphicsInc/cesium/issues/4122) -* Fixed model loading failure when a primitive does not have a material. [6906](https://github.com/AnalyticalGraphicsInc/cesium/pull/6906) +* Fixed model loading failure when a glTF 2.0 primitive does not have a material. [6906](https://github.com/AnalyticalGraphicsInc/cesium/pull/6906) * Fixed a crash when setting show to `false` on a polyline clamped to the ground. [#6912](https://github.com/AnalyticalGraphicsInc/cesium/issues/6912) * Fixed a bug where `Cesium3DTileset` wasn't using the correct tilesetVersion [#6933](https://github.com/AnalyticalGraphicsInc/cesium/pull/6933) * Fixed crash that happened when calling `scene.pick` after setting a new terrain provider [#6918](https://github.com/AnalyticalGraphicsInc/cesium/pull/6918)