Based on cgltf.h: cgltf_load_buffers(...)
| 1861 | |
| 1862 | // Based on cgltf.h: cgltf_load_buffers(...) |
| 1863 | static cgltf_result ResolveBuffers(const cgltf_options* options, cgltf_data* data, const char* gltf_path) |
| 1864 | { |
| 1865 | if (options == NULL) |
| 1866 | { |
| 1867 | return cgltf_result_invalid_options; |
| 1868 | } |
| 1869 | |
| 1870 | if (data->buffers_count && data->buffers[0].data == NULL && data->buffers[0].uri == NULL && data->bin) |
| 1871 | { |
| 1872 | if (data->bin_size < data->buffers[0].size) |
| 1873 | { |
| 1874 | return cgltf_result_data_too_short; |
| 1875 | } |
| 1876 | |
| 1877 | data->buffers[0].data = (void*)data->bin; |
| 1878 | data->buffers[0].data_free_method = cgltf_data_free_method_none; |
| 1879 | } |
| 1880 | |
| 1881 | for (cgltf_size i = 0; i < data->buffers_count; ++i) |
| 1882 | { |
| 1883 | if (data->buffers[i].data) |
| 1884 | { |
| 1885 | continue; |
| 1886 | } |
| 1887 | |
| 1888 | const char* uri = data->buffers[i].uri; |
| 1889 | |
| 1890 | if (uri == NULL) |
| 1891 | { |
| 1892 | continue; |
| 1893 | } |
| 1894 | |
| 1895 | if (strncmp(uri, "data:", 5) == 0) |
| 1896 | { |
| 1897 | const char* comma = strchr(uri, ','); |
| 1898 | |
| 1899 | if (comma && comma - uri >= 7 && strncmp(comma - 7, ";base64", 7) == 0) |
| 1900 | { |
| 1901 | cgltf_result res = cgltf_load_buffer_base64(options, data->buffers[i].size, comma + 1, &data->buffers[i].data); |
| 1902 | data->buffers[i].data_free_method = cgltf_data_free_method_memory_free; |
| 1903 | |
| 1904 | if (res != cgltf_result_success) |
| 1905 | { |
| 1906 | return res; |
| 1907 | } |
| 1908 | } |
| 1909 | else |
| 1910 | { |
| 1911 | return cgltf_result_unknown_format; |
| 1912 | } |
| 1913 | } |
| 1914 | else if (strstr(uri, "://") == NULL && gltf_path) |
| 1915 | { |
| 1916 | cgltf_result res = cgltf_load_buffer_file(options, data->buffers[i].size, uri, gltf_path, &data->buffers[i].data); |
| 1917 | data->buffers[i].data_free_method = cgltf_data_free_method_file_release; |
| 1918 | |
| 1919 | if (res != cgltf_result_success) |
| 1920 | { |
no test coverage detected