Skip to content

Commit 82d5f8e

Browse files
authored
Merge pull request #6906 from AnalyticalGraphicsInc/default-material-fix
Fix model crash by adding default pbr material
2 parents 40b8f64 + 92ffe03 commit 82d5f8e

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Change Log
22
==========
33

4-
### 1.49 - 2018-09-03
4+
### 1.49 - 2018-09-04
55

66
##### Breaking Changes :mega:
77
* Removed `ClippingPlaneCollection.clone` [#6872](https://github.com/AnalyticalGraphicsInc/cesium/pull/6872)
@@ -33,6 +33,7 @@ Change Log
3333
* Improved `Plane` entities so they are better aligned with the globe surface [#6887](https://github.com/AnalyticalGraphicsInc/cesium/pull/6887)
3434
* 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)
3535
* Fixed night shading in 2D and Columbus view. [#4122](https://github.com/AnalyticalGraphicsInc/cesium/issues/4122)
36+
* Fixed model loading failure when a glTF 2.0 primitive does not have a material. [6906](https://github.com/AnalyticalGraphicsInc/cesium/pull/6906)
3637
* Fixed a crash when setting show to `false` on a polyline clamped to the ground. [#6912](https://github.com/AnalyticalGraphicsInc/cesium/issues/6912)
3738
* Fixed a bug where `Cesium3DTileset` wasn't using the correct tilesetVersion [#6933](https://github.com/AnalyticalGraphicsInc/cesium/pull/6933)
3839
* Fixed crash that happened when calling `scene.pick` after setting a new terrain provider [#6918](https://github.com/AnalyticalGraphicsInc/cesium/pull/6918)

Source/ThirdParty/GltfPipeline/addDefaults.js

+30-4
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ define([
242242
});
243243
}
244244

245+
var defaultPbrMaterial = {
246+
emissiveFactor: [0.0, 0.0, 0.0],
247+
alphaMode: 'OPAQUE',
248+
doubleSided: false,
249+
extras : {
250+
_pipeline: {}
251+
}
252+
};
253+
245254
var defaultMaterial = {
246255
values : {
247256
emission : [
@@ -335,6 +344,24 @@ define([
335344
}
336345
};
337346

347+
function addDefaultPbrMaterial(gltf) {
348+
var materials = gltf.materials;
349+
var meshes = gltf.meshes;
350+
351+
var meshesLength = meshes.length;
352+
for (var meshId = 0; meshId < meshesLength; meshId++) {
353+
var mesh = meshes[meshId];
354+
var primitives = mesh.primitives;
355+
var primitivesLength = primitives.length;
356+
for (var j = 0; j < primitivesLength; j++) {
357+
var primitive = primitives[j];
358+
if (!defined(primitive.material)) {
359+
primitive.material = addToArray(materials, clone(defaultPbrMaterial, true));
360+
}
361+
}
362+
}
363+
}
364+
338365
function addDefaultMaterial(gltf) {
339366
var materials = gltf.materials;
340367
var meshes = gltf.meshes;
@@ -349,10 +376,7 @@ define([
349376
for (var j = 0; j < primitivesLength; j++) {
350377
var primitive = primitives[j];
351378
if (!defined(primitive.material)) {
352-
if (!defined(defaultMaterialId)) {
353-
defaultMaterialId = addToArray(materials, clone(defaultMaterial, true));
354-
}
355-
primitive.material = defaultMaterialId;
379+
primitive.material = addToArray(materials, clone(defaultMaterial, true));
356380
}
357381
}
358382
}
@@ -512,6 +536,8 @@ define([
512536
if (gltf.asset.extras.gltf_pipeline_upgrade_10to20) {
513537
addDefaultMaterial(gltf);
514538
addDefaultTechnique(gltf);
539+
} else {
540+
addDefaultPbrMaterial(gltf);
515541
}
516542

517543
addDefaultByteOffsets(gltf);

0 commit comments

Comments
 (0)