Skip to content

Remove dead normals check in loadModel() and document computeNormals() for OBJ files without normals - #9407

Open
Prbhtsgh wants to merge 1 commit into
processing:mainfrom
Prbhtsgh:fix/obj-normals-dead-check
Open

Prbhtsgh wants to merge 1 commit into
processing:mainfrom
Prbhtsgh:fix/obj-normals-dead-check

Conversation

@Prbhtsgh

Copy link
Copy Markdown
Contributor

Resolves #9404

Changes:

As discussed in #9404, loadModel() doesn't compute normals automatically for OBJ files without vn lines (that's expected, since it's expensive and not always needed). But the code and tests still said it did, which was confusing. This PR makes them match the actual behaviour:

  • src/webgl/loading.js: removed the if (model.vertexNormals.length === 0) model.computeNormals(); check. parseObj pushes a (0, 0, 0) normal for every vertex that has none, so this check could never be true. Also updated the comment below it that said "normals are ready above".
  • src/webgl/loading.js: added a note to the loadModel() reference: if a .obj file has no vertex normals, the model won't react to lights, so call model.computeNormals() after it loads.
  • test/unit/io/loadModel.js: renamed two tests and updated a comment that said normals are "computed" when the OBJ has none. The assertions are unchanged (they check one normal per vertex, which is still true).

Behaviour is unchanged. As mentioned in the issue, computeNormals() on a multi-material model doesn't update model.parts yet; that's left for #9321.

Screenshots of the change:

Not applicable (docs, comments and test names only).

PR Checklist

…uteNormals()

parseObj pushes a (0, 0, 0) normal for every vertex without one, so the vertexNormals.length === 0 check never ran. Remove it, fix the comment and test names that said normals get computed, and add a note to the loadModel() reference about calling computeNormals() when a file has no vn lines.
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.

loadModel(): OBJ files without vn normals render black under lights (normals are all zero)

1 participant