| 253 | |
| 254 | |
| 255 | static float* ReadAccessorFloat(cgltf_accessor* accessor, uint32_t desired_num_components, float default_value, uint32_t* out_count) |
| 256 | { |
| 257 | uint32_t num_components = (uint32_t)cgltf_num_components(accessor->type); |
| 258 | |
| 259 | if (desired_num_components == 0) |
| 260 | desired_num_components = num_components; |
| 261 | |
| 262 | uint32_t source_size = accessor->count * num_components; |
| 263 | uint32_t size = source_size; |
| 264 | if (desired_num_components > num_components) |
| 265 | size = accessor->count * desired_num_components; |
| 266 | |
| 267 | *out_count = size; |
| 268 | float* out = new float[size]; // Now the buffer will fit the max num components |
| 269 | |
| 270 | if (desired_num_components > num_components) |
| 271 | { |
| 272 | float* packed = new float[source_size]; |
| 273 | cgltf_size unpacked = cgltf_accessor_unpack_floats(accessor, packed, source_size); |
| 274 | if (unpacked != source_size) |
| 275 | { |
| 276 | printf("Couldn't read floats!\n"); |
| 277 | delete[] packed; |
| 278 | delete[] out; |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | for (uint32_t i = 0; i < accessor->count; ++i) |
| 283 | { |
| 284 | for (uint32_t j = 0; j < desired_num_components; ++j) |
| 285 | { |
| 286 | out[i * desired_num_components + j] = j < num_components ? packed[i * num_components + j] : default_value; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | delete[] packed; |
| 291 | return out; |
| 292 | } |
| 293 | |
| 294 | cgltf_size unpacked = cgltf_accessor_unpack_floats(accessor, out, source_size); |
| 295 | if (unpacked != source_size) |
| 296 | { |
| 297 | printf("Couldn't read floats!\n"); |
| 298 | delete[] out; |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | return out; |
| 303 | } |
| 304 | |
| 305 | static uint32_t* ReadAccessorUint32ToMem(cgltf_accessor* accessor, uint32_t num_components, uint32_t* out) |
| 306 | { |
no test coverage detected