(byte[] data)
| 133 | } |
| 134 | |
| 135 | private static Object[] parse(byte[] data) { |
| 136 | if (data == null || data.length < 4) { |
| 137 | throw new IllegalArgumentException("empty glTF data"); |
| 138 | } |
| 139 | String json; |
| 140 | byte[] binChunk; |
| 141 | if (readUInt32(data, 0) == GLB_MAGIC) { |
| 142 | // Binary glTF: 12 byte header then length-prefixed chunks. |
| 143 | String[] jsonHolder = new String[1]; |
| 144 | binChunk = parseGlb(data, jsonHolder); |
| 145 | json = jsonHolder[0]; |
| 146 | } else { |
| 147 | json = utf8(data, 0, data.length); |
| 148 | binChunk = null; |
| 149 | } |
| 150 | try { |
| 151 | Map root = new JSONParser().parseJSON( |
| 152 | new InputStreamReader(new ByteArrayInputStream(utf8Bytes(json)), "UTF-8")); |
| 153 | return new Object[] { root, binChunk }; |
| 154 | } catch (IOException ex) { |
| 155 | throw new RuntimeException("Failed to parse glTF JSON: " + ex.getMessage(), ex); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | private static byte[] parseGlb(byte[] data, String[] jsonHolder) { |
| 160 | long totalLength = readUInt32(data, 8); |
no test coverage detected