Use function GetSizeBase64()
This commit is contained in:
parent
4ad1fa85a4
commit
f9a2d89ed2
1 changed files with 7 additions and 13 deletions
20
src/models.c
20
src/models.c
|
@ -3278,16 +3278,7 @@ static int GetSizeBase64(char *input)
|
||||||
|
|
||||||
static unsigned char *DecodeBase64(char *input, int *size)
|
static unsigned char *DecodeBase64(char *input, int *size)
|
||||||
{
|
{
|
||||||
*size = 0;
|
*size = GetSizeBase64(input);
|
||||||
for (int i = 0; input[4*i] != 0; i++)
|
|
||||||
{
|
|
||||||
if (input[4*i + 3] == '=')
|
|
||||||
{
|
|
||||||
if (input[4*i + 2] == '=') *size += 1;
|
|
||||||
else *size += 2;
|
|
||||||
}
|
|
||||||
else *size += 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char *buf = (unsigned char *)RL_MALLOC(*size);
|
unsigned char *buf = (unsigned char *)RL_MALLOC(*size);
|
||||||
for (int i = 0; i < *size/3; i++)
|
for (int i = 0; i < *size/3; i++)
|
||||||
|
@ -3421,7 +3412,7 @@ static Model LoadGLTF(const char *fileName)
|
||||||
|
|
||||||
if (data->materials[i].pbr_metallic_roughness.base_color_texture.texture)
|
if (data->materials[i].pbr_metallic_roughness.base_color_texture.texture)
|
||||||
{
|
{
|
||||||
cgltf_image* img = data->materials[i].pbr_metallic_roughness.base_color_texture.texture->image;
|
cgltf_image *img = data->materials[i].pbr_metallic_roughness.base_color_texture.texture->image;
|
||||||
|
|
||||||
if (img->uri)
|
if (img->uri)
|
||||||
{
|
{
|
||||||
|
@ -3443,9 +3434,11 @@ static Model LoadGLTF(const char *fileName)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
unsigned char *data = DecodeBase64(img->uri+i+1, &size);
|
unsigned char *data = DecodeBase64(img->uri + i + 1, &size);
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
unsigned char *raw = stbi_load_from_memory(data, size, &w, &h, NULL, 4);
|
unsigned char *raw = stbi_load_from_memory(data, size, &w, &h, NULL, 4);
|
||||||
|
|
||||||
Image image = LoadImagePro(raw, w, h, UNCOMPRESSED_R8G8B8A8);
|
Image image = LoadImagePro(raw, w, h, UNCOMPRESSED_R8G8B8A8);
|
||||||
ImageColorTint(&image, tint);
|
ImageColorTint(&image, tint);
|
||||||
texture = LoadTextureFromImage(image);
|
texture = LoadTextureFromImage(image);
|
||||||
|
@ -3474,12 +3467,13 @@ static Model LoadGLTF(const char *fileName)
|
||||||
|
|
||||||
for (int i = 0; i < img->buffer_view->size; i++)
|
for (int i = 0; i < img->buffer_view->size; i++)
|
||||||
{
|
{
|
||||||
data[i] = ((unsigned char*)img->buffer_view->buffer->data)[n];
|
data[i] = ((unsigned char *)img->buffer_view->buffer->data)[n];
|
||||||
n += stride;
|
n += stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
unsigned char *raw = stbi_load_from_memory(data, img->buffer_view->size, &w, &h, NULL, 4);
|
unsigned char *raw = stbi_load_from_memory(data, img->buffer_view->size, &w, &h, NULL, 4);
|
||||||
|
|
||||||
Image image = LoadImagePro(raw, w, h, UNCOMPRESSED_R8G8B8A8);
|
Image image = LoadImagePro(raw, w, h, UNCOMPRESSED_R8G8B8A8);
|
||||||
ImageColorTint(&image, tint);
|
ImageColorTint(&image, tint);
|
||||||
texture = LoadTextureFromImage(image);
|
texture = LoadTextureFromImage(image);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue