MCPcopy
hub / github.com/g3n/engine / bytesToArrayF32

Method bytesToArrayF32

loader/gltf/loader.go:894–921  ·  view source on GitHub ↗

bytesToArrayF32 converts a byte array to ArrayF32.

(data []byte, componentType, count int)

Source from the content-addressed store, hash-verified

892
893// bytesToArrayF32 converts a byte array to ArrayF32.
894func (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.
924func (g *GLTF) loadAccessorU32(ai int, usage string, validTypes []string, validComponentTypes []int) (math32.ArrayU32, error) {

Callers 2

loadAttributesMethod · 0.95
loadAccessorF32Method · 0.95

Calls 2

ArrayF32TypeAlias · 0.92
NewArrayF32Function · 0.92

Tested by

no test coverage detected