diff --git a/CHANGES.md b/CHANGES.md index 316cf359b41b..93f7114c8507 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Change Log ##### Fixes :wrench: Disabled HDR by default to improve visual quality in most standard use cases. Set `viewer.scene.highDynamicRange = true` to re-enable it. [#7966](https://github.com/AnalyticalGraphicsInc/cesium/issues/7966) +* Fixed glTF models with missing sampler to load with default properties. [#7916](https://github.com/AnalyticalGraphicsInc/cesium/issues/7916) ### 1.60 - 2019-08-01 diff --git a/Source/Scene/processPbrMaterials.js b/Source/Scene/processPbrMaterials.js index 9dd5ec113dc0..9e1796dff15b 100644 --- a/Source/Scene/processPbrMaterials.js +++ b/Source/Scene/processPbrMaterials.js @@ -90,11 +90,17 @@ define([ function addTextureCoordinates(gltf, textureName, generatedMaterialValues, defaultTexCoord, result) { var texCoord; if (defined(generatedMaterialValues[textureName + 'Offset'])) { + var repeatS = 'true'; + var repeatT = 'true'; + var textureIndex = generatedMaterialValues[textureName].index; - var sampler = gltf.samplers[gltf.textures[textureIndex].sampler]; + var samplerName = gltf.textures[textureIndex].sampler; - var repeatS = sampler.wrapS === WebGLConstants.REPEAT ? 'true' : 'false'; - var repeatT = sampler.wrapT === WebGLConstants.REPEAT ? 'true' : 'false'; + if (defined(samplerName) && defined(gltf.samplers)) { + var sampler = gltf.samplers[samplerName]; + repeatS = sampler.wrapS === WebGLConstants.REPEAT ? 'true' : 'false'; + repeatT = sampler.wrapT === WebGLConstants.REPEAT ? 'true' : 'false'; + } texCoord = textureName + 'Coord'; result.fragmentShaderMain += ' vec2 ' + texCoord + ' = computeTexCoord(' + defaultTexCoord + ', ' + textureName + 'Offset, ' + textureName + 'Rotation, ' + textureName + 'Scale, ' + repeatS + ', ' + repeatT + ');\n';