Skip to content
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

Fix model crash by adding default pbr material #6906

Merged
merged 4 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Change Log
==========

### 1.49 - 2018-09-03
### 1.49 - 2018-09-04

##### Breaking Changes :mega:
* Removed `ClippingPlaneCollection.clone` [#6872](https://github.com/AnalyticalGraphicsInc/cesium/pull/6872)
Expand Down Expand Up @@ -33,6 +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 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)
Expand Down
34 changes: 30 additions & 4 deletions Source/ThirdParty/GltfPipeline/addDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ define([
});
}

var defaultPbrMaterial = {
emissiveFactor: [0.0, 0.0, 0.0],
alphaMode: 'OPAQUE',
doubleSided: false,
extras : {
_pipeline: {}
}
};

var defaultMaterial = {
values : {
emission : [
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
}
}
Expand Down Expand Up @@ -512,6 +536,8 @@ define([
if (gltf.asset.extras.gltf_pipeline_upgrade_10to20) {
addDefaultMaterial(gltf);
addDefaultTechnique(gltf);
} else {
addDefaultPbrMaterial(gltf);
}

addDefaultByteOffsets(gltf);
Expand Down