-
Notifications
You must be signed in to change notification settings - Fork 254
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
Conversation
// 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) { |
There was a problem hiding this comment.
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)) {
There was a problem hiding this comment.
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'); | |||
|
|||
|
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 || |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 getNormals
and 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?
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`| |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
Can you please add new tests to https://github.com/AnalyticalGraphicsInc/gltf-pipeline/tree/master/specs/lib? |
Just those comments and this is ready! Thanks again for contributing and moving forward PBR so quickly! |
@mlimper also note that binormal should be renamed to bitangent, KhronosGroup/glTF#812 (comment) |
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: EDIT: Issue with conflict / duplicate commits in history fixed. Should be fine and ready for merge now. |
…mals with existing getAllPrimitives (not via nodes)
… generateNormals and generateTangentsBinormals)
@@ -88,7 +89,7 @@ Pipeline.processJSONWithExtras = function(gltfWithExtras, options) { | |||
} | |||
addDefaults(gltfWithExtras, options); | |||
RemoveUnusedProperties.removeAll(gltfWithExtras); | |||
generateNormals(gltfWithExtras, options); | |||
generateNormals(gltfWithExtras, options); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
Great, thanks again @mlimper! |
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: