loadBufferView loads and returns a byte slice with data from the specified BufferView.
(bvIdx int)
| 1030 | |
| 1031 | // loadBufferView loads and returns a byte slice with data from the specified BufferView. |
| 1032 | func (g *GLTF) loadBufferView(bvIdx int) ([]byte, error) { |
| 1033 | |
| 1034 | // Check if provided buffer view index is valid |
| 1035 | if bvIdx < 0 || bvIdx >= len(g.BufferViews) { |
| 1036 | return nil, fmt.Errorf("invalid buffer view index") |
| 1037 | } |
| 1038 | bvData := g.BufferViews[bvIdx] |
| 1039 | // Return cached if available |
| 1040 | if bvData.cache != nil { |
| 1041 | log.Debug("Fetching BufferView %d (cached)", bvIdx) |
| 1042 | return bvData.cache, nil |
| 1043 | } |
| 1044 | log.Debug("Loading BufferView %d", bvIdx) |
| 1045 | |
| 1046 | // Load buffer view buffer |
| 1047 | buf, err := g.loadBuffer(bvData.Buffer) |
| 1048 | if err != nil { |
| 1049 | return nil, err |
| 1050 | } |
| 1051 | |
| 1052 | // Establish offset |
| 1053 | offset := 0 |
| 1054 | if bvData.ByteOffset != nil { |
| 1055 | offset = *bvData.ByteOffset |
| 1056 | } |
| 1057 | |
| 1058 | // Compute and return offset slice |
| 1059 | bvBytes := buf[offset : offset+bvData.ByteLength] |
| 1060 | |
| 1061 | // Cache buffer view |
| 1062 | g.BufferViews[bvIdx].cache = bvBytes |
| 1063 | |
| 1064 | return bvBytes, nil |
| 1065 | } |
| 1066 | |
| 1067 | // loadBuffer loads and returns the data from the specified GLTF Buffer index |
| 1068 | func (g *GLTF) loadBuffer(bufIdx int) ([]byte, error) { |
no test coverage detected