Three.js: glTF loader not implementing "normalized" data on accessors?

Created on 24 Oct 2017  路  10Comments  路  Source: mrdoob/three.js

Description of the problem

I'm creating some glTF files, and there aren't many glTF importers yet, so it's possible I may simply be creating my files incorrectly. But I think the Three.js glTF loader isn't handling normalized data for vertex colors correctly.

Here is a file that I'm trying to load in three.js:
http://www.user00.com/threejsnotnormalized.js

In it, I'm creating a GLB with a triangle where the vertex colors at the corners are:
0xFF0000FF, 0xFF0100FF, 0xFF000032

The colors are stored as 8-bit unsigned bytes.

The result I'm seeing is below:

threejsnotnormalized

It looks like the 0x01 in the green channel of the 2nd point is being converted to a 1.0 instead of 1.0/255. I see other consistencies when using the vertex colors 0xFF0000FF, 0xFFFF00FF, 0xFF0000FF that are consistent with 0xFF being interpreted as 255 instead of as 1.0.

I think that when I set {"normalized":true} for the accessors, then the data should be normalized, but it seems that three.js isn't doing that.

You can edit for small-test.
http://jsfiddle.net/akmcv7Lh/ (current revision)
http://jsfiddle.net/hw9rcLL8/ (dev)

Three.js version
  • [x] Dev
  • [ ] r87
  • [ ] ...
Browser
  • [ ] All of them
  • [x] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [] All of them
  • [x] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)

Haswell integrated graphics

Most helpful comment

Thanks for reporting.

GLTFLoader doesn't support accessor.normalized yet.
We should let it support.

https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#accessornormalized

Update: I'm working on it...

All 10 comments

Thanks for reporting.

GLTFLoader doesn't support accessor.normalized yet.
We should let it support.

https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#accessornormalized

Update: I'm working on it...

Thanks @takahirox! Let me know if I should take a look at anything also. :)

Almost done in the local branch.
But I don't have any accessor.normalized file and can't test well enough other than threejsnotnormalized.js.
Any other accessor.normalized files?

Not that I'm aware of. That might be a good request for the https://github.com/bghgary/glTF-Asset-Generator project.

Here is the working repository

~https://github.com/takahirox/three.js/blob/GLTFLoaderAccessorNormalized/examples/js/loaders/GLTFLoader.js#L1475-L1574~

Seems it's working for threejsnotnormalized.js but is not tested well enough yet.

I only just saw this but there is an optional normalized argument to THREE.BufferAttribute: https://threejs.org/docs/#api/core/BufferAttribute, which passes into WebGL vertexAttribPointer() call.

Oops, I wasn't aware of that. I'll look into it later...

And also I had missed Related WebGL functions: vertexAttribPointer() normalized parameter in glTF accessor specification...

Nice! That seems more convenient yes 馃槃

That might be a good request for the https://github.com/bghgary/glTF-Asset-Generator project.

Yup. And requesting to https://github.com/KhronosGroup/glTF-Sample-Models seems also nice.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donmccurdy picture donmccurdy  路  3Comments

filharvey picture filharvey  路  3Comments

Bandit picture Bandit  路  3Comments

boyravikumar picture boyravikumar  路  3Comments

yqrashawn picture yqrashawn  路  3Comments