-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Guarantee typed array compatible byte alignment #167
Comments
Good catch, so the 2 actions to do are:
Anything else ? |
No, just those two items. |
Will the converter be updated in dev-2? |
yes, that's an easy one. |
Very nice. 👍 |
on dev-2 |
on master now. |
Re-opening for the spec. |
@tparisi here is text for the draft 1.0 spec: Accessor Attribute SizeThe following tables can be used to compute the size of an accessor's attribute type.
The size of an accessor's attribute type, in bytes, is For example: "accessor_1": {
"bufferView": "bufferView_1",
"byteOffset": 7032,
"byteStride": 12,
"componentType": 5126, // FLOAT
"count": 586,
"type": "VEC3"
} In this accessor, the BufferView and Accessor Byte AlignmentThe offset of an Implementation Note: This allows a runtime to efficiently create a single arraybuffer from a glTF Consider the following example: "bufferView_1": {
"buffer": "buffer_1",
"byteLength": 17136,
"byteOffset": 620,
"target": 34963
},
"accessor_1": {
"bufferView": "bufferView_1",
"byteOffset": 4608,
"byteStride": 0,
"componentType": 5123, // UNSIGNED_SHORT
"count": 5232,
"type": "SCALAR"
} The size of the accessor attribute type is two bytes (the @tfili can you confirm that the converter ensures an accessor's |
It looks like there is code in there for that. Since it always outputs floats except for indices, it just verifies the indices are 4-byte aligned. |
Thanks! @tparisi you can close this when you update the spec. |
Fixed in 88b5f24 |
This is a serious (but easy to fix) issue that we need to consider ASAP.
We want a glTF implementation to be able to create a single arraybuffer from a glTF
buffer
and then use the glTFbufferView
andaccessor
(CC #161) to create a typed array view (e.g.,Float32Array
) into that arraybuffer without copying it. However, to do so, the byte offset of the typed array view must be a multiple of the size of the type (e.g.,4
forFloat32Array
). For homogenous arraybuffers where every element is the same type, this, of course, just works, but for heterogeneous arraybuffers, it does not work in the general case.The glTF spec needs to guarantee this byte alignment and the converter needs to add the required padding, which will only have a trivial impact on the total size.
JSON example
Say we have this buffer view:
which is then referenced from this animation parameter
In order to make a typed array for
translation
, we want to write code likeFor this code to work,
bufferView_393.byteOffset + translation.byteOffset
must be division by4
(which it is in this case).The text was updated successfully, but these errors were encountered: