Skip to content

Commit

Permalink
Fixes for a variety of tilesets
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jul 31, 2017
1 parent b61b5a8 commit 2a7e727
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 67 deletions.
6 changes: 3 additions & 3 deletions Apps/Sandcastle/gallery/development/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
);

Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 14 additions & 6 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down Expand Up @@ -888,7 +892,7 @@ define([
' tile_featureColor = featureProperties; \n' +
'}';
} else {
newMain =
newMain +=
'varying vec2 tile_featureSt; \n' +
'void main() \n' +
'{ \n' +
Expand Down Expand Up @@ -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' +
Expand All @@ -1111,7 +1119,7 @@ define([
' tile_featureSt = st; \n' +
'}';
} else {
newMain =
newMain +=
'varying vec2 tile_featureSt; \n' +
'void main() \n' +
'{ \n' +
Expand Down
16 changes: 14 additions & 2 deletions Source/Scene/Instanced3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define([
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
'../Core/deprecationWarning',
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/Ellipsoid',
Expand Down Expand Up @@ -34,6 +35,7 @@ define([
defaultValue,
defined,
defineProperties,
deprecationWarning,
destroyObject,
DeveloperError,
Ellipsoid,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
48 changes: 0 additions & 48 deletions Source/ThirdParty/GltfPipeline/addDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -534,7 +487,6 @@ define([
addDefaultMaterial(gltf);
addDefaultTechnique(gltf);
addDefaultByteOffsets(gltf);
enableDiffuseTransparency(gltf);
selectDefaultScene(gltf);
inferBufferViewTargets(gltf);
if (options.optimizeForCesium) {
Expand Down
19 changes: 16 additions & 3 deletions Source/ThirdParty/GltfPipeline/processPbrMetallicRoughness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -124,7 +128,7 @@ define([
var techniqueParameters = {
// Add matrices
modelViewMatrix : {
semantic : 'MODELVIEW',
semantic : hasCesiumRTCExtension ? 'CESIUM_RTC_MODELVIEW' : 'MODELVIEW',
type : WebGLConstants.FLOAT_MAT4
},
projectionMatrix : {
Expand Down Expand Up @@ -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';
Expand Down
10 changes: 6 additions & 4 deletions Source/ThirdParty/GltfPipeline/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
});
Expand Down Expand Up @@ -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
Expand All @@ -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_#)
Expand Down

0 comments on commit 2a7e727

Please sign in to comment.