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

Make composite tile #4

Closed
wants to merge 21 commits into from
Closed

Make composite tile #4

wants to merge 21 commits into from

Conversation

lasalvavida
Copy link
Contributor

Adds a tool for generating composite tilesets.

var defined = Cesium.defined;

var argv = require('yargs')
.usage('Usage: $0 \<tilesets\> [options]')
Copy link
Contributor

Choose a reason for hiding this comment

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

"tilesets" -> "tiles", right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup! Thank you

@pjcozzi
Copy link
Contributor

pjcozzi commented Aug 19, 2016

Thanks @lasalvavida! Please add doc to the README.md, and add unit tests.

@lilleyse please review and merge when this is ready.

@pjcozzi
Copy link
Contributor

pjcozzi commented Aug 19, 2016

@lasalvavida @lilleyse also please keep the roadmap, CesiumGS/3d-tiles-tools#9, updated when things are merged. I'll leave this 100% up to you guys.

@lasalvavida
Copy link
Contributor Author

Updated


## Example
`node ./bin/makeCompositeTile.js batched.b3dm instanced.i3dm points.pnts -o output/composite.cmpt`
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work with input wildcards? Not a huge deal, but would be fine if it is trivial to implement.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the output directory created if it doesn't exist? I am not familiar with all the Node IO routines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this work with input wildcards? Not a huge deal, but would be fine if it is trivial to implement.

It does not, I'll see how hard that is to do.

Copy link
Contributor Author

@lasalvavida lasalvavida Aug 25, 2016

Choose a reason for hiding this comment

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

Is the output directory created if it doesn't exist? I am not familiar with all the Node IO routines.

It is because writeTile uses fs-extra.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this work with input wildcards? Not a huge deal, but would be fine if it is trivial to implement.

It does not, I'll see how hard that is to do.

Actually I just tried it and it does work. Your shell handles the wildcards and passes the resolved arguments.

@pjcozzi
Copy link
Contributor

pjcozzi commented Aug 24, 2016

Looks great at a quick glance! @lilleyse review and merge please.

@lasalvavida
Copy link
Contributor Author

Updated

@pjcozzi
Copy link
Contributor

pjcozzi commented Aug 25, 2016

Thanks @lasalvavida. @lilleyse can you please do the final review and merge?

@lilleyse
Copy link
Contributor

Sure, I haven't reviewed this at all yet but I'm going to take some time later to review this and finish up #3

Copy link
Contributor

@lilleyse lilleyse left a comment

Choose a reason for hiding this comment

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

This utility fits better in the tools project instead. The generator project will be more for constructing sample tilesets. My comments below assume that it's in the tools repo.

Overall things look good here. Just some organizational comments now that #3 is in.

options.gzip = true;
}
return writeTile(outputPath, makeCompositeTile(tiles), options);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Integrate this into the 3d-tiles-tools.js file.

* @param {Buffer} data A buffer containing the data to test.
* @returns {Boolean} True if the data is gzipped, False if not.
*
* @throws {DeveloperError} Will throw an error if data is undefined.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typically we don't mention Errors that are thrown because of missing arguments.

throw new DeveloperError('data must be defined.');
}
return data[0] === 0x1f && data[1] === 0x8b;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Another file called isGzipped exists that checks if a file is gzipped, so maybe that one can be renamed to isGzippedFile.

I can see several areas where gzipTileset can improve by using this one as well as using readTile and writeTile. I'll make those changes after this PR is in.

/**
* Combines an array of tile buffers into a single composite tile.
*
* @param {Array.<Buffer>} tileBuffers An array of buffers holding tile data.
Copy link
Contributor

Choose a reason for hiding this comment

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

At least in Cesium, we go with the Buffer[] version.

}
return buffer;
});
}
Copy link
Contributor

@lilleyse lilleyse Oct 3, 2016

Choose a reason for hiding this comment

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

This file and writeTile can probable be condensed. See this comment: #3 (comment)

options = defaultValue(options, {});
var gzip = defaultValue(options.gzip, false);
if (gzip) {
return zlibGzip(tileData, undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there was some talk that gzip is faster as a sync operation because it's not actually doing any file reading. @mramato is this correct?

it('throws DeveloperError if data is undefined', function() {
expect(function() {
isGzipped(undefined);
}).toThrowError();
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to toThrowDeveloperError


it('detects when data is gzipped', function(done) {
var data = new Buffer(40);
expect(isGzipped(data)).toBeFalsy();
Copy link
Contributor

Choose a reason for hiding this comment

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

toBe(false) and toBe(true) are more precise.

.then(function(tileData) {
var magic = tileData.toString('utf8', 0, 4);
expect(magic).toEqual('i3dm');
}),done).toResolve();
Copy link
Contributor

Choose a reason for hiding this comment

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

, done spacing

})
.then(function(tileData) {
expect(isGzipped(tileData)).toBeTruthy();
}),done).toResolve();
Copy link
Contributor

Choose a reason for hiding this comment

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

Spacing

@lilleyse
Copy link
Contributor

lilleyse commented Oct 4, 2016

Add makeCompositeTile to index.js.

@lilleyse lilleyse mentioned this pull request Oct 4, 2016
@lasalvavida
Copy link
Contributor Author

@lilleyse This is ready for a look.

return fsExtraOutputFile(outputFile, data);
function getDefaultWriteCallback() {
return function(file, data, options) {
return writeTile(file, data, options);
Copy link
Contributor

@lilleyse lilleyse Oct 7, 2016

Choose a reason for hiding this comment

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

I think it's best to just keep this really simple like it was before where it just gets data and write to a file. Gzipping or anything else should be handled by the calling code. Maybe this makes writeTile not needed anymore.

.on('data', function (item) {
if (!item.stats.isDirectory()) {
++numberOfFiles;
return getFilesInDirectory(inputDirectory, {
Copy link
Contributor

@lilleyse lilleyse Oct 7, 2016

Choose a reason for hiding this comment

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

I used to do a similar approach here, but changed it for this comment: #3 (comment). I'm fine with merging the changes in this file in though.

I have a branch that cleans up gzipTileset and the end result looks similar to this, but walks the directory without buffering the file names up front (through a helper function). And really that too is probably going to get blown away again at some later point.


module.exports = isTileFile;

function isTileFile(file) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Mark as @Private

};
var gzipOptions = {
inputDirectory : tilesetDirectory,
outputDirectory : gzippedDirectory,
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea behind custom write callbacks was that you didn't need to supply an output directory to the stage because that information only needs to be known by the callback. I think the old way with using a closure for getDefaultWriteCallback was more flexible.

@lilleyse
Copy link
Contributor

lilleyse commented Oct 7, 2016

Also add makeCompositeTile to the README and 3d-tiles-tools.js Just make sure it's clearly defined that its not a pipeline stage and doesn't operate over the whole tileset.

@lilleyse
Copy link
Contributor

lilleyse commented Jul 2, 2017

Brought the makeCompositeTile file into #86

@lilleyse lilleyse closed this Jul 2, 2017
@lilleyse lilleyse mentioned this pull request Jul 2, 2017
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants