Navigation Menu

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

Expose functionality to generate tangents and binormals #203

Merged
merged 14 commits into from Jan 10, 2017

Conversation

mlimper
Copy link
Contributor

@mlimper mlimper commented Jan 2, 2017

Adding command line flag and code to generate tangents and binormals for a glTF asset (for example for usage with PBR pipelines). To perform the actual computation, Cesiums GeometryPipeline.computeBinormalAndTangent is used.

Usage:

node ./bin/gltf-pipeline.js -i input.gltf --tangentsBinormals -o output.gltf

@mlimper mlimper mentioned this pull request Jan 2, 2017
8 tasks
// run AO after optimizeForVertexCache since AO adds new attributes.
// run generation of tangents / binormals and AO after
// optimizeForVertexCache since those steps add new attributes.
if (defined(options.tangentsBinormals) && options.tangentsBinormals) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just

if (defined(options.tangentsBinormals)) {

Copy link
Contributor Author

@mlimper mlimper Jan 6, 2017

Choose a reason for hiding this comment

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

Exchanged by just

if (options.tangentsBinormals) {

(otherwise it evaluates to true when the flag is set to false)

@@ -30,6 +31,7 @@ var writeGltf = require('./writeGltf');
var writeBinaryGltf = require('./writeBinaryGltf');
var writeSource = require('./writeSource');


Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, but extra whitespace.

@@ -1,4 +1,4 @@
'use strict';
'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

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

Throughout, please preserve the existing formatting.

} else if (semantic === 'POSITION' || semantic === 'NORMAL') {
} else if (semantic.indexOf('POSITION') === 0 ||
semantic.indexOf('NORMAL') === 0 ||
semantic.indexOf('TANGENT') === 0 ||
Copy link
Contributor

Choose a reason for hiding this comment

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

The glTF spec does not define NORMAL and TANGENT attributes. See

https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#parametersemantic

Perhaps we should add them for 1.1 since it is trivial?

Otherwise, the PBR extension could define them, but they would need to be prefixed with _ here so the glTF asset is still valid before the extension is added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's discuss in KhronosGroup/glTF#812.

type = 'VEC3';
} else {
throw new DeveloperError('Unsupported attribute semantic: ' + semantic);
}
if (semantics.length <= 0) {
primitive.attributes[semantic] = createAccessor(gltf, packedLength, type, WebGLConstants.FLOAT, WebGLConstants.ARRAY_BUFFER);

var id = 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 don't think this will pass JSHint.

Just var id;.

var id = undefined;

// all attributes but texcoords may occur only once
if (semantic != 'TEXCOORD') {
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't pass JSHint.

Use !== for exact comparison without type coercion.

return gltf;
}

//TODO: copied from generateNormals, could be shared
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please move this to a separate file (mark it @private so it is not part of the public API) add a unit test for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a second look, I just saw that there's also a getPrimitives function in PrimitiveHelpers.js. I used that one now in getNormalsand getTangentsBinormals:
ffa215c

The difference is, however, that this function accesses the primitives directly from the meshes, not via the nodes. I believe this makes more sense in this case - otherwise, when going over the nodes, we would potentially iterate over a single mesh multiple times, if it is being shared by several nodes?

I also moved the old function from generateNormals, which iterates over the nodes, into the PrimitiveHelpers file: ef141f0
However, right now, this function is not being used anywhere.

Does that make sense, should it be kept like this?

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 4, 2017

Thanks @mlimper, this is a nice contribution! More PBR contributions are very welcome.

@@ -41,6 +41,7 @@ node ./bin/gltf-pipeline.js -i ./specs/data/boxTexturedUnoptimized/CesiumTexture
|`--compressTextureCoordinates`, `-c`|Compress the testure coordinates of this glTF asset.|No, default `false`|
|`--removeNormals`, `-r`|Strips off existing normals, allowing them to be regenerated.|No, default `false`|
|`--faceNormals`, `-f`|If normals are missing, they should be generated using the face normal.|No, default `false`|
|`--tangentsBinormals`|If normals and texture coordinates are given, generate tangents and binormals.|No, default `false`|
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also update CHANGES.md please?

Sorry, I forgot to mention last time.

@@ -185,6 +185,31 @@ function getPrimitivesByMaterialMode(primitives) {
return primitivesByMaterialMode;
}

function getPrimitivesFromNodes(gltf) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this isn't used anywhere, I would remove it for now.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 6, 2017

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 6, 2017

Just those comments and this is ready! Thanks again for contributing and moving forward PBR so quickly!

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 7, 2017

@mlimper also note that binormal should be renamed to bitangent, KhronosGroup/glTF#812 (comment)

@mlimper
Copy link
Contributor Author

mlimper commented Jan 9, 2017

Just removed the unused function, refactored to "bitangent" (instead of "binormal") throughout*, and added a test case.

(*)Exception: As Cesium is still using "binormal", the respective parts are still using the old term:
mlimper@2403a93

EDIT: Issue with conflict / duplicate commits in history fixed. Should be fine and ready for merge now.

@@ -88,7 +89,7 @@ Pipeline.processJSONWithExtras = function(gltfWithExtras, options) {
}
addDefaults(gltfWithExtras, options);
RemoveUnusedProperties.removeAll(gltfWithExtras);
generateNormals(gltfWithExtras, options);
generateNormals(gltfWithExtras, options);
Copy link
Contributor

Choose a reason for hiding this comment

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

In future PRs, please be mindful of this extra whitespace added to lines like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, sure - thanks for the pointer, and thanks for the helpful code reviews!

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 10, 2017

Great, thanks again @mlimper!

@pjcozzi pjcozzi merged commit 681f453 into CesiumGS:master Jan 10, 2017
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.

None yet

2 participants