Skip to content

Commit

Permalink
Fixed commented tilesets
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jul 29, 2018
1 parent 26be429 commit 86d650f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 59 deletions.
81 changes: 51 additions & 30 deletions samples-generator/bin/3d-tiles-samples-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';
var Cesium = require('cesium');
var fsExtra = require('fs-extra');
var gltfPipeline = require('gltf-pipeline');
var path = require('path');
var Promise = require('bluebird');
var DataUri = require('datauri');
Expand All @@ -15,11 +16,12 @@ var createInstancesTile = require('../lib/createInstancesTile');
var createPointCloudTile = require('../lib/createPointCloudTile');
var createTilesetJsonSingle = require('../lib/createTilesetJsonSingle');
var getProperties = require('../lib/getProperties');
var modifyGltfPaths = require('../lib/modifyGltfPaths');
var saveTile = require('../lib/saveTile');
var saveTilesetJson = require('../lib/saveTilesetJson');
var util = require('../lib/utility');

var processGlb = gltfPipeline.processGlb;

var Cartesian3 = Cesium.Cartesian3;
var CesiumMath = Cesium.Math;
var clone = Cesium.clone;
Expand Down Expand Up @@ -99,10 +101,10 @@ var pointCloudSphereLocal = [0.0, 0.0, 0.0, pointCloudRadius];
var instancesLength = 25;
var instancesGeometricError = 70.0; // Estimated
var instancesTileWidth = tileWidth;
var instancesUrl = 'data/box.glb'; // Model's center is at the origin (and for below)
var instancesRedUrl = 'data/red_box.glb';
var instancesTexturedUrl = 'data/textured_box.glb';
var instancesZUpUrl = 'data/box-z-up.glb';
var instancesUri = 'data/box.glb'; // Model's center is at the origin (and for below)
var instancesRedUri = 'data/red_box.glb';
var instancesTexturedUri = 'data/textured_box.glb';
var instancesZUpUri = 'data/box-z-up.glb';
var instancesModelSize = 20.0;
var instancesHeight = instancesModelSize + 10.0; // Just a little extra padding at the top for aiding Cesium tests
var instancesTransform = wgs84Transform(longitude, latitude, instancesModelSize / 2.0);
Expand Down Expand Up @@ -206,14 +208,12 @@ var promises = [
createBatchedColorsTranslucent(),
createBatchedColorsMix(),
createBatchedTextured(),
//createBatchedCompressedTextures(),
createBatchedWithBoundingSphere(),
createBatchedWithTransformBox(),
createBatchedWithTransformSphere(),
createBatchedWithTransformRegion(),
createBatchedWithRtcCenter(),
createBatchedNoBatchIds(),
//createBatchedWithQuantization(),
createBatchedWGS84(),
createBatchedDeprecated1(),
createBatchedDeprecated2(),
Expand Down Expand Up @@ -251,7 +251,6 @@ var promises = [
createInstancedRedMaterial(),
createInstancedWithBatchIds(),
createInstancedTextured(),
//createInstancedCompressedTextures(),
createInstancedGltfZUp(),
// Composite
createComposite(),
Expand All @@ -267,7 +266,7 @@ var promises = [
createTileset(),
createTilesetEmptyRoot(),
createTilesetOfTilesets(),
//createTilesetWithExternalResources(),
createTilesetWithExternalResources(),
createTilesetRefinementMix(),
createTilesetReplacement1(),
createTilesetReplacement2(),
Expand All @@ -279,7 +278,7 @@ var promises = [
createTilesetPoints(),
// Samples
createDiscreteLOD(),
//createTreeBillboards()
createTreeBillboards(),
createRequestVolume(),
createExpireTileset()
];
Expand Down Expand Up @@ -720,7 +719,7 @@ function createInstancedWithTransform() {

function createInstancedRedMaterial() {
var tileOptions = {
url : instancesRedUrl
uri : instancesRedUri
};
return saveInstancedTileset('InstancedRedMaterial', tileOptions);
}
Expand All @@ -734,14 +733,14 @@ function createInstancedWithBatchIds() {

function createInstancedTextured() {
var tileOptions = {
url : instancesTexturedUrl
uri : instancesTexturedUri
};
return saveInstancedTileset('InstancedTextured', tileOptions);
}

function createInstancedCompressedTextures() {
var tileOptions = {
url : instancesTexturedUrl,
uri : instancesTexturedUri,
textureCompressionOptions : [{
format : 'dxt1',
quality : 10
Expand All @@ -755,7 +754,7 @@ function createInstancedCompressedTextures() {

function createInstancedGltfZUp() {
var tileOptions = {
url : instancesZUpUrl
uri : instancesZUpUri
};
var tilesetOptions = {
gltfUpAxis : 'Z'
Expand All @@ -765,7 +764,7 @@ function createInstancedGltfZUp() {

function createComposite() {
var i3dmOptions = {
url : instancesUrl,
uri : instancesUri,
tileWidth : instancesTileWidth,
transform : instancesTransform,
instancesLength : instancesLength,
Expand Down Expand Up @@ -793,7 +792,7 @@ function createComposite() {

function createCompositeOfComposite() {
var i3dmOptions = {
url : instancesUrl,
uri : instancesUri,
tileWidth : instancesTileWidth,
transform : instancesTransform,
instancesLength : instancesLength,
Expand Down Expand Up @@ -822,7 +821,7 @@ function createCompositeOfComposite() {

function createCompositeOfInstanced() {
var i3dmOptions1 = {
url : instancesUrl,
uri : instancesUri,
tileWidth : instancesTileWidth,
transform : instancesTransform,
instancesLength : instancesLength,
Expand All @@ -832,7 +831,7 @@ function createCompositeOfInstanced() {
};

var i3dmOptions2 = {
url : instancesUrl,
uri : instancesUri,
tileWidth : instancesTileWidth,
transform : instancesTransform,
instancesLength : instancesLength,
Expand All @@ -852,8 +851,8 @@ function createCompositeOfInstanced() {
return saveCompositeTileset('CompositeOfInstanced', [i3dm1, i3dm2], [i3dm1BatchTable, i3dm2BatchTable]);
}).then(function() {
var tilesetDirectory = path.join(outputDirectory, 'Composite', 'CompositeOfInstanced');
var copyPath = path.join(tilesetDirectory, path.basename(instancesUrl));
return fsExtra.copy(instancesUrl, copyPath);
var copyPath = path.join(tilesetDirectory, path.basename(instancesUri));
return fsExtra.copy(instancesUri, copyPath);
});
}

Expand Down Expand Up @@ -888,7 +887,7 @@ function saveInstancedTileset(tilesetName, tileOptions, tilesetOptions) {
var tilesetPath = path.join(tilesetDirectory, 'tileset.json');

tileOptions = defaultValue(tileOptions, {});
tileOptions.url = defaultValue(tileOptions.url, instancesUrl);
tileOptions.uri = defaultValue(tileOptions.uri, instancesUri);
tileOptions.tileWidth = instancesTileWidth;
tileOptions.transform = defaultValue(tileOptions.transform, instancesTransform);
tileOptions.instancesLength = instancesLength;
Expand All @@ -913,8 +912,8 @@ function saveInstancedTileset(tilesetName, tileOptions, tilesetOptions) {
saveTile(tilePath, i3dm, gzip)
];
if (tileOptions.embed === false) {
var copyPath = path.join(tilesetDirectory, path.basename(tileOptions.url));
promises.push(fsExtra.copy(tileOptions.url, copyPath));
var copyPath = path.join(tilesetDirectory, path.basename(tileOptions.uri));
promises.push(fsExtra.copy(tileOptions.uri, copyPath));
}
return Promise.all(promises);
});
Expand Down Expand Up @@ -1304,6 +1303,22 @@ function createTilesetOfTilesets() {
});
}

function modifyImageUri(glb, resourceDirectory, newResourceDirectory) {
var gltfOptions = {
resourceDirectory : resourceDirectory,
customStages : [
function(gltf) {
gltf.images[0].uri = newResourceDirectory + gltf.images[0].uri;
return gltf;
}
]
};
return processGlb(glb, gltfOptions)
.then(function(results) {
return results.glb;
})
}

function createTilesetWithExternalResources() {
// Create a tileset that references an external tileset where tiles reference external resources
var tilesetName = 'TilesetWithExternalResources';
Expand Down Expand Up @@ -1453,9 +1468,15 @@ function createTilesetWithExternalResources() {

return fsExtra.readFile(glbPath)
.then(function(glb) {
return Promise.all([
modifyImageUri(glb, glbBasePath, 'textured_box_separate/'),
modifyImageUri(glb, glbBasePath, '../textured_box_separate/')
])
})
.then(function(glbs) {
var tiles = [
createB3dm({
glb : modifyGltfPaths(glb, 'textured_box_separate/')
glb : glbs[0]
}),
createI3dm({
featureTableJson : featureTableJson,
Expand All @@ -1465,10 +1486,10 @@ function createTilesetWithExternalResources() {
createI3dm({
featureTableJson : featureTableJson,
featureTableBinary : featureTableBinary,
glb : modifyGltfPaths(glb, 'textured_box_separate/')
glb : glbs[0]
}),
createB3dm({
glb : modifyGltfPaths(glb, '../textured_box_separate/')
glb : glbs[1]
}),
createI3dm({
featureTableJson : featureTableJson,
Expand All @@ -1478,7 +1499,7 @@ function createTilesetWithExternalResources() {
createI3dm({
featureTableJson : featureTableJson,
featureTableBinary : featureTableBinary,
glb : modifyGltfPaths(glb, '../textured_box_separate/')
glb : glbs[1]
})
];
return Promise.map(tiles, function(tile, index) {
Expand Down Expand Up @@ -1888,7 +1909,7 @@ function createTilesetWithTransforms() {
tileWidth : instancesTileWidth,
transform : Matrix4.IDENTITY,
instancesLength : instancesLength,
url : instancesUrl,
uri : instancesUri,
modelSize : instancesModelSize,
eastNorthUp : false
};
Expand Down Expand Up @@ -2446,11 +2467,11 @@ function createTreeBillboards() {
};

var treeOptions = clone(options);
treeOptions.url = glbPaths[0];
treeOptions.uri = glbPaths[0];
treeOptions.transform = wgs84Transform(longitude, latitude, 0.0); // Detailed model's base is at the origin

var billboardOptions = clone(options);
billboardOptions.url = glbPaths[1];
billboardOptions.uri = glbPaths[1];
billboardOptions.transform = wgs84Transform(longitude, latitude, treesHeight / 2.0); // Billboard model is centered about the origin

var optionsArray = [treeOptions, billboardOptions];
Expand Down
12 changes: 6 additions & 6 deletions samples-generator/lib/createI3dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ var defined = Cesium.defined;
module.exports = createI3dm;

/**
* Create an Instanced 3D Model (i3dm) tile from a feature table, batch table, and gltf buffer or url.
* Create an Instanced 3D Model (i3dm) tile from a feature table, batch table, and gltf buffer or uri.
*
* @param {Object} options An object with the following properties:
* @param {Object} options.featureTableJson The feature table JSON.
* @param {Buffer} options.featureTableBinary The feature table binary.
* @param {Object} [options.batchTableJson] Batch table describing the per-feature metadata.
* @param {Buffer} [options.batchTableBinary] The batch table binary.
* @param {Buffer} [options.glb] The binary glTF buffer.
* @param {String} [options.url] Url to an external glTF model when options.glb is not specified.
* @param {String} [options.uri] Uri to an external glTF model when options.glb is not specified.
* @returns {Buffer} The generated i3dm tile buffer.
*/
function createI3dm(options) {
Expand All @@ -26,7 +26,7 @@ function createI3dm(options) {
var batchTableBinary = getBufferPadded(options.batchTableBinary);

var gltfFormat = defined(options.glb) ? 1 : 0;
var gltfBuffer = defined(options.glb) ? options.glb : getGltfUrlBuffer(options.url);
var gltfBuffer = defined(options.glb) ? options.glb : getGltfUriBuffer(options.uri);

var version = 1;
var headerByteLength = 32;
Expand All @@ -50,7 +50,7 @@ function createI3dm(options) {
return Buffer.concat([header, featureTableJson, featureTableBinary, batchTableJson, batchTableBinary, gltfBuffer]);
}

function getGltfUrlBuffer(url) {
url = url.replace(/\\/g, '/');
return Buffer.from(url);
function getGltfUriBuffer(uri) {
uri = uri.replace(/\\/g, '/');
return Buffer.from(uri);
}
10 changes: 5 additions & 5 deletions samples-generator/lib/createInstancesTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var sizeOfFloat32 = 4;
* Creates a i3dm tile that represents a set of instances.
*
* @param {Object} options Object with the following properties:
* @param {Object} options.url Url to the instanced binary glTF model.
* @param {Object} options.uri Uri to the instanced binary glTF model.
* @param {Number} [options.tileWidth=200.0] The width of the tile in meters.
* @param {Matrix4} [options.transform=Matrix4.IDENTITY] A transform to bake into the tile, for example a transform into WGS84.
* @param {Number} [options.instancesLength=25] The number of instances.
Expand Down Expand Up @@ -50,7 +50,7 @@ function createInstancesTile(options) {
var tileWidth = defaultValue(options.tileWidth, 200.0);
var transform = defaultValue(options.transform, Matrix4.IDENTITY);
var instancesLength = defaultValue(options.instancesLength, 25);
var url = options.url;
var uri = options.uri;
var embed = defaultValue(options.embed, true);
var modelSize = defaultValue(options.modelSize, 20.0);
var createBatchTable = defaultValue(options.createBatchTable, true);
Expand Down Expand Up @@ -142,17 +142,17 @@ function createInstancesTile(options) {
textureCompressionOptions : textureCompressionOptions
};

return fsExtra.readFile(url)
return fsExtra.readFile(uri)
.then(function(glb) {
glb = embed ? glb : undefined;
url = path.basename(url);
uri = path.basename(uri);
var i3dm = createI3dm({
featureTableJson : featureTableJson,
featureTableBinary : featureTableBinary,
batchTableJson : batchTableJson,
batchTableBinary : batchTableBinary,
glb : glb,
url : url
uri : uri
});
return {
i3dm : i3dm,
Expand Down
17 changes: 0 additions & 17 deletions samples-generator/lib/modifyGltfPaths.js

This file was deleted.

2 changes: 1 addition & 1 deletion samples-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"bluebird": "^3.5.1",
"cesium": "^1.39",
"fs-extra": "^4.0.2",
"gltf-pipeline": "AnalyticalGraphicsInc/gltf-pipeline#2.0",
"gltf-pipeline": "gltf-pipeline",
"mime": "^2.0.3",
"simplex-noise": "^2.3.0"
},
Expand Down

0 comments on commit 86d650f

Please sign in to comment.