bytesToArrayF32 converts a byte array to ArrayF32.
(data []byte, componentType, count int)
| 892 | |
| 893 | // bytesToArrayF32 converts a byte array to ArrayF32. |
| 894 | func (g *GLTF) bytesToArrayF32(data []byte, componentType, count int) (math32.ArrayF32, error) { |
| 895 | |
| 896 | // If component is UNSIGNED_INT nothing to do |
| 897 | if componentType == UNSIGNED_INT { |
| 898 | arr := (*[1 << 30]float32)(unsafe.Pointer(&data[0]))[:count] |
| 899 | return math32.ArrayF32(arr), nil |
| 900 | } |
| 901 | |
| 902 | // Converts UNSIGNED_SHORT or SHORT to UNSIGNED_INT |
| 903 | if componentType == UNSIGNED_SHORT || componentType == SHORT { |
| 904 | out := math32.NewArrayF32(count, count) |
| 905 | for i := 0; i < count; i++ { |
| 906 | out[i] = float32(data[i*2]) + float32(data[i*2+1])*256 |
| 907 | } |
| 908 | return out, nil |
| 909 | } |
| 910 | |
| 911 | // Converts UNSIGNED_BYTE or BYTE to UNSIGNED_INT |
| 912 | if componentType == UNSIGNED_BYTE || componentType == BYTE { |
| 913 | out := math32.NewArrayF32(count, count) |
| 914 | for i := 0; i < count; i++ { |
| 915 | out[i] = float32(data[i]) |
| 916 | } |
| 917 | return out, nil |
| 918 | } |
| 919 | |
| 920 | return (*[1 << 30]float32)(unsafe.Pointer(&data[0]))[:count], nil |
| 921 | } |
| 922 | |
| 923 | // loadAccessorU32 loads data from the specified accessor and performs validation of the Type and ComponentType. |
| 924 | func (g *GLTF) loadAccessorU32(ai int, usage string, validTypes []string, validComponentTypes []int) (math32.ArrayU32, error) { |
no test coverage detected