glTF MAT3 Byte Padding: Read Matrix Columns Before Comparing a Drone Model
Trace an unsigned-byte MAT3 with aligned columns, skip padding, and distinguish the final data boundary from the stride of a matrix sequence.

Check the storage layout before calling a matrix transposed
A diagnostic table for a drone-derived model can show unexpected matrix entries when the reader assumes that nine byte components occupy nine consecutive positions. glTF matrix accessors have column-oriented storage and alignment rules that can insert padding between columns. Before describing the exported values as transposed or corrupted, identify the accessor type, component type, and exact data slice being inspected. A correct comparison begins with the representation actually stored, rather than the arrangement a spreadsheet or a custom array reader happens to prefer.
This tutorial reads a constructed single MAT3 with unsigned-byte components from an already isolated memory slice. It does not open a glTF or GLB file, resolve an accessor graph, or establish the meaning of a matrix in a NiVO model. The small example is a layout witness: it shows which bytes become which row and column entries. It does not apply a coordinate transform, measure an object, or validate whether an application should use that accessor for a particular purpose. The accompanying catalogue photograph is separate product context.
Follow column-major storage and four-byte alignment
The Khronos glTF specification states that matrix accessor data is stored in column-major order and column starts are aligned to four-byte boundaries. For a MAT3 with one-byte components, three components occupy each column and padding separates the next aligned column start. The current specification source lists the full element size as twelve bytes. Thus the column starts in this teaching slice are offsets zero, four, and eight. Reading consecutive triples from offsets zero, three, and six would mix padding and component positions.
The end of the final component is another boundary worth recording. The registry specification allows trailing alignment bytes to be omitted when there is no further data. In the one-matrix exercise, components occupy offsets zero through two, four through six, and eight through ten, so the last component ends at byte eleven, exclusive. A twelve-byte slice may include a trailing pad after that component. This observation does not mean that eleven becomes the stride of a matrix sequence; the aligned layout for successive elements still needs the applicable element and buffer-view rules.

Product context only; this photograph does not depict the constructed examples in this article.
Read a constructed single matrix with explicit padding positions
The input below stores the first column as 1, 2, 3, then a padding byte; the second as 4, 5, 6, then padding; and the third as 7, 8, 9. The function accepts an isolated eleven- or twelve-byte slice for this exact teaching profile and reads only the component positions. It returns rows for a familiar display. The expected result is the three tuples 1, 4, 7; 2, 5, 8; and 3, 6, 9. Those rows are assembled after reading the column layout, not copied from consecutive triples in the buffer.
Run the exercise locally with Python. The padding positions in the constructed input contain zero and are not presented as matrix components. Both the eleven-byte input and a copy with one trailing zero should produce the same rows. No project file is written. This function intentionally does not accept an arbitrary buffer plus guessed offsets, a complete sequence of matrices, signed-byte components, or wider component types. A visible rejection outside this profile is preferable to silently applying the same indices to an accessor whose storage rules differ.
def mat3_unsigned_byte_rows(raw):
if not isinstance(raw, bytes) or len(raw) not in (11, 12):
raise ValueError("Expected one isolated unsigned-byte MAT3 slice, 11 or 12 bytes")
return [tuple(raw[column * 4 + row] for column in range(3)) for row in range(3)]
# Constructed columns with inter-column padding, not a complete glTF asset.
toy = bytes([1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9])
print(mat3_unsigned_byte_rows(toy))
print(mat3_unsigned_byte_rows(toy + b"\x00"))Keep final padding separate from sequence stride
A final byte boundary describes how far a reader must reach to obtain the last component in the isolated example. It is not a general recipe for locating the next matrix. For an actual accessor containing several elements, resolve the effective element size and any declared byteStride before stepping through the buffer view. Skipping directly from the last component to the next byte can misalign the following column. Preserve count, offsets, component type, accessor type, and buffer-view limits together when documenting a real reading calculation.
Do not infer padding positions by searching for zeros. A component can legitimately have a zero value, and a zero in the buffer is not a substitute for the declared layout. The teaching function skips positions three and seven because of the selected column arrangement, not because of their contents. A complete format validator may impose additional requirements that this reader does not assess. Keep the distinction explicit: extracting component positions from a selected profile is different from certifying every property of the surrounding asset or every unused byte.
Separate matrix layout from numerical and geometric meaning
Once the components are associated with their correct row and column positions, other interpretation rules may still apply. Component signedness and any normalized accessor flag need their own handling; this function returns raw unsigned-byte values. It does not normalize integers or convert them into floating-point transform coefficients. Likewise, a MAT3 type does not by itself establish a world reference system, a unit scale, or an intended measurement operation. Identify how the actual model uses the accessor before assigning semantic meaning to a correctly arranged table.
A receiving application may expose a different array convention for display or computation. Compare its documented convention with the stored column-major representation before concluding that the asset has changed. If a project needs an actual transform or geometric comparison, perform it through an appropriate method using the identified data and conventions. The constructed values here were chosen to make row and column placement obvious; they are not a calibrated transform, a sensor orientation, or evidence about the accuracy of a drone-derived model. A readable table remains a diagnostic representation.
Deliver a byte-layout finding that can be reproduced
A useful handoff note identifies the unchanged model package, accessor and buffer view, the selected component type and matrix type, and the offsets used to read the components. Include the actual reader version and a small identified extract if one was examined. State whether the finding concerns column order, padding, stride, or another interpretation boundary. Do not rewrite the original data to match a custom diagnostic that assumed tightly consecutive bytes. Correct the diagnostic, repeat the comparison, and retain the relationship between the earlier and revised findings.
For a NiVO-related model discussion, this method helps separate a storage-layout misunderstanding from a genuine asset discrepancy. Read the aligned columns first, present rows deliberately, and keep the final component boundary distinct from the step between elements. Continue the separate checks for accessor validity, resources, numerical interpretation, model reference, and intended analysis with their own evidence. The result is a specific explanation that another reviewer can reproduce, without treating one successful memory-slice demonstration as proof that an entire model or survey has been validated.



