diff --git a/Apps/Sandcastle/gallery/development/3D Models.html b/Apps/Sandcastle/gallery/development/3D Models.html index ffc969e4dc54..9739f74752ef 100644 --- a/Apps/Sandcastle/gallery/development/3D Models.html +++ b/Apps/Sandcastle/gallery/development/3D Models.html @@ -97,13 +97,13 @@ Cesium.knockout.getObservable(viewModel, 'color').subscribe( function(newValue) { - model.color = Cesium.Color.fromAlpha(getColor(newValue), viewModel.alpha); + model.color = Cesium.Color.fromAlpha(getColor(newValue), Number(viewModel.alpha)); } ); Cesium.knockout.getObservable(viewModel, 'alpha').subscribe( function(newValue) { - model.color = Cesium.Color.fromAlpha(getColor(viewModel.color), newValue); + model.color = Cesium.Color.fromAlpha(getColor(viewModel.color), Number(newValue)); } ); @@ -139,7 +139,7 @@ })); model.readyPromise.then(function(model) { - model.color = Cesium.Color.fromAlpha(getColor(viewModel.color), viewModel.alpha); + model.color = Cesium.Color.fromAlpha(getColor(viewModel.color), Number(viewModel.alpha)); model.colorBlendMode = getColorBlendMode(viewModel.colorBlendMode); model.colorBlendAmount = viewModel.colorBlendAmount; // Play and loop all animations at half-speed diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index 6ce2026fda55..7db1c61386cb 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -341,7 +341,15 @@ define([ if (gltfByteLength === 0) { throw new RuntimeError('glTF byte length must be greater than 0.'); } - var gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength); + + var gltfView; + if (byteOffset % 4 === 0) { + gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength); + } else { + // Create a copy of the glb so that it is 4-byte aligned + Batched3DModel3DTileContent._deprecationWarning('b3dm-glb-unaligned', 'The embedded glb is not aligned to a 4-byte boundary.'); + gltfView = new Uint8Array(uint8Array.subarray(byteOffset, byteOffset + gltfByteLength)); + } var pickObject = { content : content, diff --git a/Source/Scene/Cesium3DTileBatchTable.js b/Source/Scene/Cesium3DTileBatchTable.js index 7526fe2cbdf0..c92e393c3ed4 100644 --- a/Source/Scene/Cesium3DTileBatchTable.js +++ b/Source/Scene/Cesium3DTileBatchTable.js @@ -851,11 +851,15 @@ define([ var that = this; return function(source) { var renamedSource = ShaderSource.replaceMain(source, 'tile_main'); - var newMain; + var newMain = ''; + + if (source.indexOf(batchIdAttributeName) === -1) { + newMain += 'attribute float ' + batchIdAttributeName + ';\n'; + } if (ContextLimits.maximumVertexTextureImageUnits > 0) { // When VTF is supported, perform per-feature show/hide in the vertex shader - newMain = + newMain += 'uniform sampler2D tile_batchTexture; \n' + 'uniform bool tile_translucentCommand; \n' + 'varying vec4 tile_featureColor; \n' + @@ -888,7 +892,7 @@ define([ ' tile_featureColor = featureProperties; \n' + '}'; } else { - newMain = + newMain += 'varying vec2 tile_featureSt; \n' + 'void main() \n' + '{ \n' + @@ -1094,11 +1098,15 @@ define([ var that = this; return function(source) { var renamedSource = ShaderSource.replaceMain(source, 'tile_main'); - var newMain; + var newMain = ''; + + if (source.indexOf(batchIdAttributeName) === -1) { + newMain += 'attribute float ' + batchIdAttributeName + ';\n'; + } if (ContextLimits.maximumVertexTextureImageUnits > 0) { // When VTF is supported, perform per-feature show/hide in the vertex shader - newMain = + newMain += 'uniform sampler2D tile_batchTexture; \n' + 'varying vec2 tile_featureSt; \n' + 'void main() \n' + @@ -1111,7 +1119,7 @@ define([ ' tile_featureSt = st; \n' + '}'; } else { - newMain = + newMain += 'varying vec2 tile_featureSt; \n' + 'void main() \n' + '{ \n' + diff --git a/Source/Scene/Instanced3DModel3DTileContent.js b/Source/Scene/Instanced3DModel3DTileContent.js index 429f51d35200..2bd40a0ae6db 100644 --- a/Source/Scene/Instanced3DModel3DTileContent.js +++ b/Source/Scene/Instanced3DModel3DTileContent.js @@ -6,6 +6,7 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', + '../Core/deprecationWarning', '../Core/destroyObject', '../Core/DeveloperError', '../Core/Ellipsoid', @@ -34,6 +35,7 @@ define([ defaultValue, defined, defineProperties, + deprecationWarning, destroyObject, DeveloperError, Ellipsoid, @@ -91,6 +93,9 @@ define([ initialize(this, arrayBuffer, byteOffset); } + // This can be overridden for testing purposes + Instanced3DModel3DTileContent._deprecationWarning = deprecationWarning; + defineProperties(Instanced3DModel3DTileContent.prototype, { /** * @inheritdoc Cesium3DTileContent#featuresLength @@ -292,8 +297,15 @@ define([ if (gltfByteLength === 0) { throw new RuntimeError('glTF byte length is zero, i3dm must have a glTF to instance.'); } - var gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength); - byteOffset += gltfByteLength; + + var gltfView; + if (byteOffset % 4 === 0) { + gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength); + } else { + // Create a copy of the glb so that it is 4-byte aligned + Instanced3DModel3DTileContent._deprecationWarning('i3dm-glb-unaligned', 'The embedded glb is not aligned to a 4-byte boundary.'); + gltfView = new Uint8Array(uint8Array.subarray(byteOffset, byteOffset + gltfByteLength)); + } // Create model instance collection var collectionOptions = { diff --git a/Source/ThirdParty/GltfPipeline/addDefaults.js b/Source/ThirdParty/GltfPipeline/addDefaults.js index 91f5ae73ef8c..c58701b24981 100644 --- a/Source/ThirdParty/GltfPipeline/addDefaults.js +++ b/Source/ThirdParty/GltfPipeline/addDefaults.js @@ -384,53 +384,6 @@ define([ } } - function enableDiffuseTransparency(gltf) { - var materials = gltf.materials; - var techniques = gltf.techniques; - - var materialsLength = materials.length; - for (var materialId = 0; materialId < materialsLength; materialId++) { - var material = materials[materialId]; - if (defined(material.values) && defined(material.values.diffuse)) { - // Check if the diffuse texture/color is transparent - var diffuse = material.values.diffuse; - var diffuseTransparent = false; - if (defined(diffuse.index)) { - diffuseTransparent = gltf.images[gltf.textures[diffuse.index].source].extras._pipeline.transparent; - } else { - diffuseTransparent = diffuse[3] < 1.0; - } - - var technique = techniques[material.technique]; - var blendingEnabled = technique.states.enable.indexOf(WebGLConstants.BLEND) > -1; - - // Override the technique's states if blending isn't already enabled - if (diffuseTransparent && !blendingEnabled) { - technique.states = { - enable: [ - WebGLConstants.DEPTH_TEST, - WebGLConstants.BLEND - ], - depthMask: false, - functions: { - blendEquationSeparate: [ - WebGLConstants.FUNC_ADD, - WebGLConstants.FUNC_ADD - ], - blendFuncSeparate: [ - WebGLConstants.ONE, - WebGLConstants.ONE_MINUS_SRC_ALPHA, - WebGLConstants.ONE, - WebGLConstants.ONE_MINUS_SRC_ALPHA - ] - } - }; - } - - } - } - } - function selectDefaultScene(gltf) { var scenes = gltf.scenes; @@ -534,7 +487,6 @@ define([ addDefaultMaterial(gltf); addDefaultTechnique(gltf); addDefaultByteOffsets(gltf); - enableDiffuseTransparency(gltf); selectDefaultScene(gltf); inferBufferViewTargets(gltf); if (options.optimizeForCesium) { diff --git a/Source/ThirdParty/GltfPipeline/processPbrMetallicRoughness.js b/Source/ThirdParty/GltfPipeline/processPbrMetallicRoughness.js index 75ecf73534dc..01beebfa1ee5 100644 --- a/Source/ThirdParty/GltfPipeline/processPbrMetallicRoughness.js +++ b/Source/ThirdParty/GltfPipeline/processPbrMetallicRoughness.js @@ -57,7 +57,7 @@ define([ ForEach.material(gltf, function(material) { if (defined(material.pbrMetallicRoughness)) { var pbrMetallicRoughness = material.pbrMetallicRoughness; - var technique = generateTechnique(gltf, material, options.optimizeForCesium); + var technique = generateTechnique(gltf, material, options); var newMaterial = { values : pbrMetallicRoughness, @@ -76,7 +76,11 @@ define([ return gltf; } - function generateTechnique(gltf, material, optimizeForCesium) { + function generateTechnique(gltf, material, options) { + var optimizeForCesium = defaultValue(options.optimizeForCesium, false); + var hasCesiumRTCExtension = defined(gltf.extensions) && defined(gltf.extensions.CESIUM_RTC); + var addBatchIdToGeneratedShaders = defaultValue(options.addBatchIdToGeneratedShaders, false); + var techniques = gltf.techniques; var shaders = gltf.shaders; var programs = gltf.programs; @@ -124,7 +128,7 @@ define([ var techniqueParameters = { // Add matrices modelViewMatrix : { - semantic : 'MODELVIEW', + semantic : hasCesiumRTCExtension ? 'CESIUM_RTC_MODELVIEW' : 'MODELVIEW', type : WebGLConstants.FLOAT_MAT4 }, projectionMatrix : { @@ -353,6 +357,15 @@ define([ vertexShader += 'attribute ' + attributeType + ' a_weight;\n'; } + if (addBatchIdToGeneratedShaders) { + techniqueAttributes.a_batchId = 'batchId'; + techniqueParameters.batchId = { + semantic: '_BATCHID', + type: WebGLConstants.FLOAT + }; + vertexShader += 'attribute float a_batchId;\n'; + } + vertexShader += 'void main(void) \n{\n'; vertexShader += vertexShaderMain; vertexShader += '}\n'; diff --git a/Source/ThirdParty/GltfPipeline/updateVersion.js b/Source/ThirdParty/GltfPipeline/updateVersion.js index 1c8fc24ca923..20d7e89ca310 100644 --- a/Source/ThirdParty/GltfPipeline/updateVersion.js +++ b/Source/ThirdParty/GltfPipeline/updateVersion.js @@ -591,8 +591,10 @@ define([ if (mappedSemantics.hasOwnProperty(semantic)) { var mappedSemantic = mappedSemantics[semantic]; var accessorId = primitive.attributes[semantic]; - delete primitive.attributes[semantic]; - primitive.attributes[mappedSemantic] = accessorId; + if (defined(accessorId)) { + delete primitive.attributes[semantic]; + primitive.attributes[mappedSemantic] = accessorId; + } } } }); @@ -802,6 +804,8 @@ define([ } var asset = gltf.asset; asset.version = '2.0'; + // material.instanceTechnique properties should be directly on the material. instanceTechnique is a gltf 0.8 property but is seen in some 1.0 models. + updateInstanceTechniques(gltf); // animation.samplers now refers directly to accessors and animation.parameters should be removed removeAnimationSamplersIndirection(gltf); // top-level objects are now arrays referenced by index instead of id @@ -814,8 +818,6 @@ define([ requireByteLength(gltf); // byteStride moved from accessor to bufferView moveByteStrideToBufferView(gltf); - // accessor.min and accessor.max must be defined - requireAccessorMinMax(gltf); // buffer.type is unnecessary and should be removed removeBufferType(gltf); // TEXCOORD and COLOR attributes must be written with a set index (TEXCOORD_#)