loadAccessorBytes returns the base byte array used by an accessor.
(ac Accessor)
| 970 | |
| 971 | // loadAccessorBytes returns the base byte array used by an accessor. |
| 972 | func (g *GLTF) loadAccessorBytes(ac Accessor) ([]byte, error) { |
| 973 | |
| 974 | // Get the Accessor's BufferView |
| 975 | if ac.BufferView == nil { |
| 976 | return nil, fmt.Errorf("accessor.BufferView == nil NOT SUPPORTED YET") // TODO |
| 977 | } |
| 978 | bv := g.BufferViews[*ac.BufferView] |
| 979 | |
| 980 | // Loads data from associated BufferView |
| 981 | data, err := g.loadBufferView(*ac.BufferView) |
| 982 | if err != nil { |
| 983 | return nil, err |
| 984 | } |
| 985 | |
| 986 | // Accessor offset into BufferView |
| 987 | offset := 0 |
| 988 | if ac.ByteOffset != nil { |
| 989 | offset = *ac.ByteOffset |
| 990 | } |
| 991 | data = data[offset:] |
| 992 | |
| 993 | // TODO check if interleaved and de-interleave if necessary? |
| 994 | |
| 995 | // Calculate the size in bytes of a complete attribute |
| 996 | itemSize := TypeSizes[ac.Type] |
| 997 | itemBytes := int(gls.FloatSize) * itemSize |
| 998 | |
| 999 | // If the BufferView stride is equal to the item size, the buffer is not interleaved |
| 1000 | if (bv.ByteStride != nil) && (*bv.ByteStride != itemBytes) { |
| 1001 | // BufferView data is interleaved, de-interleave |
| 1002 | // TODO |
| 1003 | return nil, fmt.Errorf("data is interleaved - not supported for animation yet") |
| 1004 | } |
| 1005 | |
| 1006 | // TODO Sparse accessor |
| 1007 | |
| 1008 | return data, nil |
| 1009 | } |
| 1010 | |
| 1011 | // isInterleaves returns whether the BufferView used by the provided accessor is interleaved. |
| 1012 | func (g *GLTF) isInterleaved(accessor Accessor) bool { |
no test coverage detected