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

Update sample tilesets to version 1.0 #6857

Merged
merged 2 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 34 additions & 3 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,38 @@ define([
'} \n';
}

function replaceDiffuseTextureCalls(source, diffuseAttributeOrUniformName) {
var functionCall = 'texture2D(' + diffuseAttributeOrUniformName;

var fromIndex = 0;
var startIndex = source.indexOf(functionCall, fromIndex);
var endIndex;

while (startIndex > -1) {
var nestedLevel = 0;
for (var i = startIndex; i < source.length; ++i) {
var character = source.charAt(i);
if (character === '(') {
++nestedLevel;
} else if (character === ')') {
--nestedLevel;
if (nestedLevel === 0) {
endIndex = i + 1;
break;
}
}
}
var extractedFunction = source.slice(startIndex, endIndex);
var replacedFunction = 'tile_diffuse_final(' + extractedFunction + ', tile_diffuse)';

source = source.slice(0, startIndex) + replacedFunction + source.slice(endIndex);
fromIndex = startIndex + replacedFunction.length;
startIndex = source.indexOf(functionCall, fromIndex);
}

return source;
}

function modifyDiffuse(source, diffuseAttributeOrUniformName, applyHighlight) {
// If the glTF does not specify the _3DTILESDIFFUSE semantic, return the default shader.
// Otherwise if _3DTILESDIFFUSE is defined prefer the shader below that can switch the color mode at runtime.
Expand Down Expand Up @@ -1027,11 +1059,10 @@ define([
' tile_diffuse = tile_diffuse_final(source, tile_featureColor); \n' +
' tile_main(); \n';
} else if (type === 'sampler2D') {
// Regex handles up to one level of nested parentheses:
// Handles any number of nested parentheses
// E.g. texture2D(u_diffuse, uv)
// E.g. texture2D(u_diffuse, computeUV(index))
regex = new RegExp('texture2D\\(' + diffuseAttributeOrUniformName + '.*?(\\)\\)|\\))', 'g');
source = source.replace(regex, 'tile_diffuse_final($&, tile_diffuse)');
source = replaceDiffuseTextureCalls(source, diffuseAttributeOrUniformName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex was too fragile before. It failed for a GLSL line from processPbrMetallicRoughness. Updated to support any number of nested parentheses.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see a spec update for this. Can we add a test with the offending line since it sounds like a good test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is tested in Cesium3DTilesetSpec with the colorBlendMode tests. I checked that this area of the code has 100% code coverage (the file is 99%).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sets colorBlendMode for textured tileset passes in master, fails without the replaceDiffuseTextureCalls fix, and passes with the replaceDiffuseTextureCalls fix. So no update is required.

setColor =
' tile_diffuse = tile_featureColor; \n' +
' tile_main(); \n';
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ define([
}

if (tileset.debugShowUrl) {
labelString += '\nUrl: ' + tile._header.content.url;
labelString += '\nUrl: ' + tile._header.content.uri;
attributes++;
}

Expand Down
11 changes: 10 additions & 1 deletion Source/Scene/ClassificationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ define([
'../Core/RuntimeError',
'../Core/Transforms',
'../Core/WebGLConstants',
'../ThirdParty/GltfPipeline/addDefaults',
'../ThirdParty/GltfPipeline/ForEach',
'../ThirdParty/GltfPipeline/getAccessorByteStride',
'../ThirdParty/GltfPipeline/numberOfComponentsForType',
'../ThirdParty/GltfPipeline/parseBinaryGltf',
'../ThirdParty/GltfPipeline/processModelMaterialsCommon',
'../ThirdParty/GltfPipeline/processPbrMetallicRoughness',
'../ThirdParty/when',
'./Axis',
'./ClassificationType',
Expand Down Expand Up @@ -56,10 +59,13 @@ define([
RuntimeError,
Transforms,
WebGLConstants,
addDefaults,
ForEach,
getAccessorByteStride,
numberOfComponentsForType,
parseBinaryGltf,
processModelMaterialsCommon,
processPbrMetallicRoughness,
when,
Axis,
ClassificationType,
Expand Down Expand Up @@ -124,7 +130,10 @@ define([

if (gltf instanceof Uint8Array) {
// Binary glTF
gltf = parseBinaryGltf(gltf);
gltf = parseBinaryGltf(gltf); // Updates to 2.0 and adds pipeline extras
addDefaults(gltf);
processModelMaterialsCommon(gltf);
processPbrMetallicRoughness(gltf);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these lines because other code in ClassificationModel expected gltf.techniques to exist.

@ggetz you may need to add these changes to #6805 as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted in that PR.

} else {
throw new RuntimeError('Only binary glTF is supported as a classifier.');
}
Expand Down
8 changes: 6 additions & 2 deletions Source/ThirdParty/GltfPipeline/addDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,12 @@ define([
options = defaultValue(options, {});
addDefaultsFromTemplate(gltf, gltfTemplate);
addDefaultTransformToAnimatedNodes(gltf);
addDefaultMaterial(gltf);
addDefaultTechnique(gltf);

if (gltf.asset.extras.gltf_pipeline_upgrade_10to20) {
addDefaultMaterial(gltf);
addDefaultTechnique(gltf);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sort of a hack - this tells gltf-pipeline to only add default materials or techniques if the model was a 1.0 model. If the model has pbrMetallicRoughness these lines are not called. This was added to fix a test where 2 shaders were being created instead of 1.

This is temporary until #6805.


addDefaultByteOffsets(gltf);
selectDefaultScene(gltf);
inferBufferViewTargets(gltf);
Expand Down
7 changes: 7 additions & 0 deletions Source/ThirdParty/GltfPipeline/processPbrMetallicRoughness.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ define([
}
}

if (optimizeForCesium) {
var baseColorParameter = defaultValue(techniqueParameters.baseColorTexture, techniqueParameters.baseColorFactor);
if (defined(baseColorParameter)) {
baseColorParameter.semantic = '_3DTILESDIFFUSE';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for tileset.colorBlendMode to work for 2.0 models.

}
}

// Generate uniforms object before attributes are added
var techniqueUniforms = {};
for (var paramName in techniqueParameters) {
Expand Down
Binary file not shown.
14 changes: 7 additions & 7 deletions Specs/Data/Cesium3DTiles/Batched/BatchedColors/tileset.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"maximum": 9
},
"Longitude": {
"minimum": -1.3196972173766555,
"maximum": -1.3196683129064435
"minimum": -1.3196959060375169,
"maximum": -1.3196607462778132
},
"Latitude": {
"minimum": 0.698861998722264,
"maximum": 0.6988888301460953
"minimum": 0.6988590050687061,
"maximum": 0.6988864387845588
},
"Height": {
"minimum": 6.929546581581235,
"maximum": 13.581844886764884
"minimum": 6.1022464875131845,
"maximum": 13.410263679921627
}
},
"geometricError": 70,
Expand All @@ -35,7 +35,7 @@
},
"geometricError": 0,
"content": {
"url": "batchedColors.b3dm"
"uri": "batchedColors.b3dm"
}
}
}
Binary file not shown.
14 changes: 7 additions & 7 deletions Specs/Data/Cesium3DTiles/Batched/BatchedColorsMix/tileset.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"maximum": 9
},
"Longitude": {
"minimum": -1.3196972173766555,
"maximum": -1.3196683129064435
"minimum": -1.3196959060375169,
"maximum": -1.3196607462778132
},
"Latitude": {
"minimum": 0.698861998722264,
"maximum": 0.6988888301460953
"minimum": 0.6988590050687061,
"maximum": 0.6988864387845588
},
"Height": {
"minimum": 6.929546581581235,
"maximum": 13.581844886764884
"minimum": 6.1022464875131845,
"maximum": 13.410263679921627
}
},
"geometricError": 70,
Expand All @@ -35,7 +35,7 @@
},
"geometricError": 0,
"content": {
"url": "batchedColorsMix.b3dm"
"uri": "batchedColorsMix.b3dm"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"maximum": 9
},
"Longitude": {
"minimum": -1.3196972173766555,
"maximum": -1.3196683129064435
"minimum": -1.3196959060375169,
"maximum": -1.3196607462778132
},
"Latitude": {
"minimum": 0.698861998722264,
"maximum": 0.6988888301460953
"minimum": 0.6988590050687061,
"maximum": 0.6988864387845588
},
"Height": {
"minimum": 6.929546581581235,
"maximum": 13.581844886764884
"minimum": 6.1022464875131845,
"maximum": 13.410263679921627
}
},
"geometricError": 70,
Expand All @@ -35,7 +35,7 @@
},
"geometricError": 0,
"content": {
"url": "batchedColorsTranslucent.b3dm"
"uri": "batchedColorsTranslucent.b3dm"
}
}
}
Binary file not shown.

This file was deleted.

Binary file not shown.
32 changes: 25 additions & 7 deletions Specs/Data/Cesium3DTiles/Batched/BatchedDeprecated1/tileset.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,38 @@
"maximum": 9
},
"Longitude": {
"minimum": -1.3196972173766555,
"maximum": -1.3196718547473905
"minimum": -1.3196959060375169,
"maximum": -1.3196607462778132
},
"Latitude": {
"minimum": 0.6988624606923348,
"maximum": 0.6988888301460953
"minimum": 0.6988590050687061,
"maximum": 0.6988864387845588
},
"Height": {
"minimum": 6.2074098233133554,
"maximum": 12.83180232718587
"minimum": 6.1022464875131845,
"maximum": 13.410263679921627
}
},
"geometricError": 70,
"root": {
"transform": [
0.9686356343768792,
0.24848542777253735,
0,
0,
-0.15986460744966327,
0.623177611820219,
0.765567091384559,
0,
0.19023226619126932,
-0.7415555652213445,
0.6433560667227647,
0,
1215011.9317263428,
-4736309.3434217675,
4081602.0044800863,
1
],
"refine": "ADD",
"boundingVolume": {
"region": [
Expand All @@ -35,7 +53,7 @@
},
"geometricError": 0,
"content": {
"url": "batchedDeprecated1.b3dm"
"uri": "batchedDeprecated1.b3dm"
}
}
}
Binary file not shown.
32 changes: 25 additions & 7 deletions Specs/Data/Cesium3DTiles/Batched/BatchedDeprecated2/tileset.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,38 @@
"maximum": 9
},
"Longitude": {
"minimum": -1.3196972173766555,
"maximum": -1.3196718547473905
"minimum": -1.3196959060375169,
"maximum": -1.3196607462778132
},
"Latitude": {
"minimum": 0.6988624606923348,
"maximum": 0.6988888301460953
"minimum": 0.6988590050687061,
"maximum": 0.6988864387845588
},
"Height": {
"minimum": 6.2074098233133554,
"maximum": 12.83180232718587
"minimum": 6.1022464875131845,
"maximum": 13.410263679921627
}
},
"geometricError": 70,
"root": {
"transform": [
0.9686356343768792,
0.24848542777253735,
0,
0,
-0.15986460744966327,
0.623177611820219,
0.765567091384559,
0,
0.19023226619126932,
-0.7415555652213445,
0.6433560667227647,
0,
1215011.9317263428,
-4736309.3434217675,
4081602.0044800863,
1
],
"refine": "ADD",
"boundingVolume": {
"region": [
Expand All @@ -35,7 +53,7 @@
},
"geometricError": 0,
"content": {
"url": "batchedDeprecated2.b3dm"
"uri": "batchedDeprecated2.b3dm"
}
}
}
Binary file not shown.
Loading