46#if !defined(EXTERNAL_CONFIG_FLAGS)
50#if defined(SUPPORT_MODULE_RMODELS)
61#if defined(SUPPORT_FILEFORMAT_OBJ) || defined(SUPPORT_FILEFORMAT_MTL)
62 #define TINYOBJ_MALLOC RL_MALLOC
63 #define TINYOBJ_CALLOC RL_CALLOC
64 #define TINYOBJ_REALLOC RL_REALLOC
65 #define TINYOBJ_FREE RL_FREE
67 #define TINYOBJ_LOADER_C_IMPLEMENTATION
71#if defined(SUPPORT_FILEFORMAT_GLTF)
72 #define CGLTF_MALLOC RL_MALLOC
73 #define CGLTF_FREE RL_FREE
75 #define CGLTF_IMPLEMENTATION
79#if defined(SUPPORT_FILEFORMAT_VOX)
80 #define VOX_MALLOC RL_MALLOC
81 #define VOX_CALLOC RL_CALLOC
82 #define VOX_REALLOC RL_REALLOC
83 #define VOX_FREE RL_FREE
85 #define VOX_LOADER_IMPLEMENTATION
89#if defined(SUPPORT_MESH_GENERATION)
90 #define PAR_MALLOC(T, N) ((T*)RL_MALLOC(N*sizeof(T)))
91 #define PAR_CALLOC(T, N) ((T*)RL_CALLOC(N*sizeof(T), 1))
92 #define PAR_REALLOC(T, BUF, N) ((T*)RL_REALLOC(BUF, sizeof(T)*(N)))
93 #define PAR_FREE RL_FREE
95 #define PAR_SHAPES_IMPLEMENTATION
110#ifndef MAX_MATERIAL_MAPS
111 #define MAX_MATERIAL_MAPS 12
113#ifndef MAX_MESH_VERTEX_BUFFERS
114 #define MAX_MESH_VERTEX_BUFFERS 7
130#if defined(SUPPORT_FILEFORMAT_OBJ)
131static Model LoadOBJ(
const char *fileName);
133#if defined(SUPPORT_FILEFORMAT_IQM)
134static Model LoadIQM(
const char *fileName);
135static ModelAnimation *LoadModelAnimationsIQM(
const char *fileName,
unsigned int *animCount);
137#if defined(SUPPORT_FILEFORMAT_GLTF)
138static Model LoadGLTF(
const char *fileName);
141#if defined(SUPPORT_FILEFORMAT_VOX)
142static Model LoadVOX(
const char *filename);
186 rlRotatef(rotationAngle, rotationAxis.
x, rotationAxis.
y, rotationAxis.
z);
189 for (
int i = 0; i < 360; i += 10)
223 for (
int i = 2; i < pointCount; i++)
227 rlVertex3f(points[i].x, points[i].y, points[i].z);
228 rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z);
229 rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z);
233 rlVertex3f(points[i].x, points[i].y, points[i].z);
234 rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z);
235 rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z);
262 rlVertex3f(x - width/2, y - height/2, z + length/2);
263 rlVertex3f(x + width/2, y - height/2, z + length/2);
264 rlVertex3f(x - width/2, y + height/2, z + length/2);
266 rlVertex3f(x + width/2, y + height/2, z + length/2);
267 rlVertex3f(x - width/2, y + height/2, z + length/2);
268 rlVertex3f(x + width/2, y - height/2, z + length/2);
271 rlVertex3f(x - width/2, y - height/2, z - length/2);
272 rlVertex3f(x - width/2, y + height/2, z - length/2);
273 rlVertex3f(x + width/2, y - height/2, z - length/2);
275 rlVertex3f(x + width/2, y + height/2, z - length/2);
276 rlVertex3f(x + width/2, y - height/2, z - length/2);
277 rlVertex3f(x - width/2, y + height/2, z - length/2);
280 rlVertex3f(x - width/2, y + height/2, z - length/2);
281 rlVertex3f(x - width/2, y + height/2, z + length/2);
282 rlVertex3f(x + width/2, y + height/2, z + length/2);
284 rlVertex3f(x + width/2, y + height/2, z - length/2);
285 rlVertex3f(x - width/2, y + height/2, z - length/2);
286 rlVertex3f(x + width/2, y + height/2, z + length/2);
289 rlVertex3f(x - width/2, y - height/2, z - length/2);
290 rlVertex3f(x + width/2, y - height/2, z + length/2);
291 rlVertex3f(x - width/2, y - height/2, z + length/2);
293 rlVertex3f(x + width/2, y - height/2, z - length/2);
294 rlVertex3f(x + width/2, y - height/2, z + length/2);
295 rlVertex3f(x - width/2, y - height/2, z - length/2);
298 rlVertex3f(x + width/2, y - height/2, z - length/2);
299 rlVertex3f(x + width/2, y + height/2, z - length/2);
300 rlVertex3f(x + width/2, y + height/2, z + length/2);
302 rlVertex3f(x + width/2, y - height/2, z + length/2);
303 rlVertex3f(x + width/2, y - height/2, z - length/2);
304 rlVertex3f(x + width/2, y + height/2, z + length/2);
307 rlVertex3f(x - width/2, y - height/2, z - length/2);
308 rlVertex3f(x - width/2, y + height/2, z + length/2);
309 rlVertex3f(x - width/2, y + height/2, z - length/2);
311 rlVertex3f(x - width/2, y - height/2, z + length/2);
312 rlVertex3f(x - width/2, y + height/2, z + length/2);
313 rlVertex3f(x - width/2, y - height/2, z - length/2);
341 rlVertex3f(x-width/2, y-height/2, z+length/2);
342 rlVertex3f(x+width/2, y-height/2, z+length/2);
345 rlVertex3f(x+width/2, y-height/2, z+length/2);
346 rlVertex3f(x+width/2, y+height/2, z+length/2);
349 rlVertex3f(x+width/2, y+height/2, z+length/2);
350 rlVertex3f(x-width/2, y+height/2, z+length/2);
353 rlVertex3f(x-width/2, y+height/2, z+length/2);
354 rlVertex3f(x-width/2, y-height/2, z+length/2);
358 rlVertex3f(x-width/2, y-height/2, z-length/2);
359 rlVertex3f(x+width/2, y-height/2, z-length/2);
362 rlVertex3f(x+width/2, y-height/2, z-length/2);
363 rlVertex3f(x+width/2, y+height/2, z-length/2);
366 rlVertex3f(x+width/2, y+height/2, z-length/2);
367 rlVertex3f(x-width/2, y+height/2, z-length/2);
370 rlVertex3f(x-width/2, y+height/2, z-length/2);
371 rlVertex3f(x-width/2, y-height/2, z-length/2);
375 rlVertex3f(x-width/2, y+height/2, z+length/2);
376 rlVertex3f(x-width/2, y+height/2, z-length/2);
379 rlVertex3f(x+width/2, y+height/2, z+length/2);
380 rlVertex3f(x+width/2, y+height/2, z-length/2);
384 rlVertex3f(x-width/2, y-height/2, z+length/2);
385 rlVertex3f(x-width/2, y-height/2, z-length/2);
388 rlVertex3f(x+width/2, y-height/2, z+length/2);
389 rlVertex3f(x+width/2, y-height/2, z-length/2);
404 float x = position.
x;
405 float y = position.
y;
406 float z = position.
z;
465 float x = position.
x;
466 float y = position.
y;
467 float z = position.
z;
468 float texWidth = (float)texture.
width;
469 float texHeight = (
float)texture.
height;
481 rlVertex3f(x - width/2, y - height/2, z + length/2);
483 rlVertex3f(x + width/2, y - height/2, z + length/2);
485 rlVertex3f(x + width/2, y + height/2, z + length/2);
487 rlVertex3f(x - width/2, y + height/2, z + length/2);
492 rlVertex3f(x - width/2, y - height/2, z - length/2);
494 rlVertex3f(x - width/2, y + height/2, z - length/2);
496 rlVertex3f(x + width/2, y + height/2, z - length/2);
498 rlVertex3f(x + width/2, y - height/2, z - length/2);
503 rlVertex3f(x - width/2, y + height/2, z - length/2);
505 rlVertex3f(x - width/2, y + height/2, z + length/2);
507 rlVertex3f(x + width/2, y + height/2, z + length/2);
509 rlVertex3f(x + width/2, y + height/2, z - length/2);
514 rlVertex3f(x - width/2, y - height/2, z - length/2);
516 rlVertex3f(x + width/2, y - height/2, z - length/2);
518 rlVertex3f(x + width/2, y - height/2, z + length/2);
520 rlVertex3f(x - width/2, y - height/2, z + length/2);
525 rlVertex3f(x + width/2, y - height/2, z - length/2);
527 rlVertex3f(x + width/2, y + height/2, z - length/2);
529 rlVertex3f(x + width/2, y + height/2, z + length/2);
531 rlVertex3f(x + width/2, y - height/2, z + length/2);
536 rlVertex3f(x - width/2, y - height/2, z - length/2);
538 rlVertex3f(x - width/2, y - height/2, z + length/2);
540 rlVertex3f(x - width/2, y + height/2, z + length/2);
542 rlVertex3f(x - width/2, y + height/2, z - length/2);
558 int numVertex = (rings + 2)*slices*6;
569 for (
int i = 0; i < (rings + 2); i++)
571 for (
int j = 0; j < slices; j++)
574 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*i)),
575 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*i))*cosf(
DEG2RAD*(360.0f*j/slices)));
577 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
578 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(
DEG2RAD*(360.0f*(j + 1)/slices)));
580 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
581 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(
DEG2RAD*(360.0f*j/slices)));
584 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*i)),
585 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*i))*cosf(
DEG2RAD*(360.0f*j/slices)));
587 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i))),
588 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i)))*cosf(
DEG2RAD*(360.0f*(j + 1)/slices)));
590 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
591 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(
DEG2RAD*(360.0f*(j + 1)/slices)));
601 int numVertex = (rings + 2)*slices*6;
612 for (
int i = 0; i < (rings + 2); i++)
614 for (
int j = 0; j < slices; j++)
617 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*i)),
618 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*i))*cosf(
DEG2RAD*(360.0f*j/slices)));
620 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
621 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(
DEG2RAD*(360.0f*(j + 1)/slices)));
624 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
625 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(
DEG2RAD*(360.0f*(j + 1)/slices)));
627 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
628 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(
DEG2RAD*(360.0f*j/slices)));
631 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1))),
632 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*(i + 1)))*cosf(
DEG2RAD*(360.0f*j/slices)));
634 sinf(
DEG2RAD*(270 + (180.0f/(rings + 1))*i)),
635 cosf(
DEG2RAD*(270 + (180.0f/(rings + 1))*i))*cosf(
DEG2RAD*(360.0f*j/slices)));
646 if (sides < 3) sides = 3;
648 int numVertex = sides*6;
660 for (
int i = 0; i < 360; i += 360/sides)
672 for (
int i = 0; i < 360; i += 360/sides)
682 for (
int i = 0; i < 360; i += 360/sides)
691 for (
int i = 0; i < 360; i += 360/sides)
705 if (sides < 3) sides = 3;
707 int numVertex = sides*6;
710 Vector3 direction = { endPos.
x - startPos.
x, endPos.
y - startPos.
y, endPos.
z - startPos.
z };
711 if ((direction.
x == 0) && (direction.
y == 0) && (direction.
z == 0))
return;
717 float baseAngle = (2.0f*
PI)/sides;
722 for (
int i = 0; i < sides; i++) {
724 float s1 = sinf(baseAngle*(i + 0))*startRadius;
725 float c1 = cosf(baseAngle*(i + 0))*startRadius;
726 Vector3 w1 = { startPos.
x + s1*b1.
x + c1*b2.
x, startPos.
y + s1*b1.
y + c1*b2.
y, startPos.
z + s1*b1.
z + c1*b2.
z };
727 float s2 = sinf(baseAngle*(i + 1))*startRadius;
728 float c2 = cosf(baseAngle*(i + 1))*startRadius;
729 Vector3 w2 = { startPos.
x + s2*b1.
x + c2*b2.
x, startPos.
y + s2*b1.
y + c2*b2.
y, startPos.
z + s2*b1.
z + c2*b2.
z };
730 float s3 = sinf(baseAngle*(i + 0))*endRadius;
731 float c3 = cosf(baseAngle*(i + 0))*endRadius;
732 Vector3 w3 = { endPos.
x + s3*b1.
x + c3*b2.
x, endPos.
y + s3*b1.
y + c3*b2.
y, endPos.
z + s3*b1.
z + c3*b2.
z };
733 float s4 = sinf(baseAngle*(i + 1))*endRadius;
734 float c4 = cosf(baseAngle*(i + 1))*endRadius;
735 Vector3 w4 = { endPos.
x + s4*b1.
x + c4*b2.
x, endPos.
y + s4*b1.
y + c4*b2.
y, endPos.
z + s4*b1.
z + c4*b2.
z };
737 if (startRadius > 0) {
764 if (sides < 3) sides = 3;
766 int numVertex = sides*8;
775 for (
int i = 0; i < 360; i += 360/sides)
798 if (sides < 3) sides = 3;
800 int numVertex = sides*6;
803 Vector3 direction = { endPos.
x - startPos.
x, endPos.
y - startPos.
y, endPos.
z - startPos.
z };
804 if ((direction.
x == 0) && (direction.
y == 0) && (direction.
z == 0))
return;
810 float baseAngle = (2.0f*
PI)/sides;
815 for (
int i = 0; i < sides; i++) {
817 float s1 = sinf(baseAngle*(i + 0))*startRadius;
818 float c1 = cosf(baseAngle*(i + 0))*startRadius;
819 Vector3 w1 = { startPos.
x + s1*b1.
x + c1*b2.
x, startPos.
y + s1*b1.
y + c1*b2.
y, startPos.
z + s1*b1.
z + c1*b2.
z };
820 float s2 = sinf(baseAngle*(i + 1))*startRadius;
821 float c2 = cosf(baseAngle*(i + 1))*startRadius;
822 Vector3 w2 = { startPos.
x + s2*b1.
x + c2*b2.
x, startPos.
y + s2*b1.
y + c2*b2.
y, startPos.
z + s2*b1.
z + c2*b2.
z };
823 float s3 = sinf(baseAngle*(i + 0))*endRadius;
824 float c3 = cosf(baseAngle*(i + 0))*endRadius;
825 Vector3 w3 = { endPos.
x + s3*b1.
x + c3*b2.
x, endPos.
y + s3*b1.
y + c3*b2.
y, endPos.
z + s3*b1.
z + c3*b2.
z };
826 float s4 = sinf(baseAngle*(i + 1))*endRadius;
827 float c4 = cosf(baseAngle*(i + 1))*endRadius;
828 Vector3 w4 = { endPos.
x + s4*b1.
x + c4*b2.
x, endPos.
y + s4*b1.
y + c4*b2.
y, endPos.
z + s4*b1.
z + c4*b2.
z };
882 int halfSlices = slices/2;
887 for (
int i = -halfSlices; i <= halfSlices; i++)
904 rlVertex3f((
float)i*spacing, 0.0f, (
float)-halfSlices*spacing);
905 rlVertex3f((
float)i*spacing, 0.0f, (
float)halfSlices*spacing);
907 rlVertex3f((
float)-halfSlices*spacing, 0.0f, (
float)i*spacing);
908 rlVertex3f((
float)halfSlices*spacing, 0.0f, (
float)i*spacing);
918#if defined(SUPPORT_FILEFORMAT_OBJ)
921#if defined(SUPPORT_FILEFORMAT_IQM)
924#if defined(SUPPORT_FILEFORMAT_GLTF)
927#if defined(SUPPORT_FILEFORMAT_VOX)
938#if defined(SUPPORT_MESH_GENERATION)
939 TRACELOG(
LOG_WARNING,
"MESH: [%s] Failed to load mesh data, default to cube mesh", fileName);
953 TRACELOG(
LOG_WARNING,
"MATERIAL: [%s] Failed to load material data, default to white material", fileName);
1012 TRACELOG(
LOG_INFO,
"MODEL: Unloaded model (and meshes) from RAM and VRAM");
1033 TRACELOG(
LOG_INFO,
"MODEL: Unloaded model (but not meshes) from RAM and VRAM");
1046 for (
int i = 1; i < model.
meshCount; i++)
1068 if (mesh->
vaoId > 0)
1086#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
1114 float value[3] = { 1.0f, 1.0f, 1.0f };
1129 float value[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
1144 float value[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
1159 float value[2] = { 0.0f, 0.0f };
1185#if defined(GRAPHICS_API_OPENGL_11)
1186 #define GL_VERTEX_ARRAY 0x8074
1187 #define GL_NORMAL_ARRAY 0x8075
1188 #define GL_COLOR_ARRAY 0x8076
1189 #define GL_TEXTURE_COORD_ARRAY 0x8078
1217#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
1321 if (mesh.
vboId[3] != 0)
1331 float value[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
1359 for (
int eye = 0; eye < eyeCount; eye++)
1363 if (eyeCount == 1) matModelViewProjection =
MatrixMultiply(matModelView, matProjection);
1409#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
1412 unsigned int instancesVboId = 0;
1463 for (
int i = 0; i < instances; i++) instanceTransforms[i] =
MatrixToFloatV(transforms[i]);
1475 for (
unsigned int i = 0; i < 4; i++)
1536 if (mesh.
vboId[3] != 0)
1546 float value[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
1574 for (
int eye = 0; eye < eyeCount; eye++)
1578 if (eyeCount == 1) matModelViewProjection =
MatrixMultiply(matModelView, matProjection);
1647 bool success =
false;
1652 int dataSize = mesh.
vertexCount*(int)strlen(
"v 0000.00f 0000.00f 0000.00f") +
1654 mesh.
vertexCount*(int)strlen(
"vn 0.000f 0.00f 0.00f") +
1655 mesh.
triangleCount*(int)strlen(
"f 00000/00000/00000 00000/00000/00000 00000/00000/00000");
1658 char *txtData = (
char *)
RL_CALLOC(dataSize*2 + 2000,
sizeof(
char));
1661 byteCount += sprintf(txtData + byteCount,
"# //////////////////////////////////////////////////////////////////////////////////\n");
1662 byteCount += sprintf(txtData + byteCount,
"# // //\n");
1663 byteCount += sprintf(txtData + byteCount,
"# // rMeshOBJ exporter v1.0 - Mesh exported as triangle faces and not optimized //\n");
1664 byteCount += sprintf(txtData + byteCount,
"# // //\n");
1665 byteCount += sprintf(txtData + byteCount,
"# // more info and bugs-report: github.com/raysan5/raylib //\n");
1666 byteCount += sprintf(txtData + byteCount,
"# // feedback and support: ray[at]raylib.com //\n");
1667 byteCount += sprintf(txtData + byteCount,
"# // //\n");
1668 byteCount += sprintf(txtData + byteCount,
"# // Copyright (c) 2018-2022 Ramon Santamaria (@raysan5) //\n");
1669 byteCount += sprintf(txtData + byteCount,
"# // //\n");
1670 byteCount += sprintf(txtData + byteCount,
"# //////////////////////////////////////////////////////////////////////////////////\n\n");
1671 byteCount += sprintf(txtData + byteCount,
"# Vertex Count: %i\n", mesh.
vertexCount);
1672 byteCount += sprintf(txtData + byteCount,
"# Triangle Count: %i\n\n", mesh.
triangleCount);
1674 byteCount += sprintf(txtData + byteCount,
"g mesh\n");
1676 for (
int i = 0, v = 0; i < mesh.
vertexCount; i++, v += 3)
1678 byteCount += sprintf(txtData + byteCount,
"v %.2f %.2f %.2f\n", mesh.
vertices[v], mesh.
vertices[v + 1], mesh.
vertices[v + 2]);
1681 for (
int i = 0, v = 0; i < mesh.
vertexCount; i++, v += 2)
1683 byteCount += sprintf(txtData + byteCount,
"vt %.3f %.3f\n", mesh.
texcoords[v], mesh.
texcoords[v + 1]);
1686 for (
int i = 0, v = 0; i < mesh.
vertexCount; i++, v += 3)
1688 byteCount += sprintf(txtData + byteCount,
"vn %.3f %.3f %.3f\n", mesh.
normals[v], mesh.
normals[v + 1], mesh.
normals[v + 2]);
1695 byteCount += sprintf(txtData + byteCount,
"f %i/%i/%i %i/%i/%i %i/%i/%i\n",
1705 byteCount += sprintf(txtData + byteCount,
"f %i/%i/%i %i/%i/%i %i/%i/%i\n", v, v, v, v + 1, v + 1, v + 1, v + 2, v + 2, v + 2);
1709 byteCount += sprintf(txtData + byteCount,
"\n");
1728 unsigned int count = 0;
1732#if defined(SUPPORT_FILEFORMAT_MTL)
1749 if (materials !=
NULL)
1751 for (
unsigned int i = 0; i < count; i++)
1758 *materialCount = count;
1821#if defined(SUPPORT_FILEFORMAT_IQM)
1822 if (
IsFileExtension(fileName,
".iqm")) animations = LoadModelAnimationsIQM(fileName, animCount);
1824#if defined(SUPPORT_FILEFORMAT_GLTF)
1839 for (
int m = 0; m < model.
meshCount; m++)
1844 TRACELOG(
LOG_WARNING,
"MODEL: UpdateModelAnimation Mesh %i has no connection to bones",m);
1848 bool updated =
false;
1852 Vector3 inTranslation = { 0 };
1856 Vector3 outTranslation = { 0 };
1861 int boneCounter = 0;
1862 float boneWeight = 0.0;
1865 for (
int vCounter = 0; vCounter < vValues; vCounter+=3)
1879 for (
int j = 0; j < 4; j++, boneCounter++)
1883 if (boneWeight == 0.0f)
1887 boneId = mesh.
boneIds[boneCounter];
1902 animVertex =
Vector3Add(animVertex, outTranslation);
1916 mesh.
animNormals[vCounter + 1] += animNormal.
y*boneWeight;
1917 mesh.
animNormals[vCounter + 2] += animNormal.
z*boneWeight;
1957 for (
int i = 0; i < model.
boneCount; i++)
1966#if defined(SUPPORT_MESH_GENERATION)
1972 if (sides < 3)
return mesh;
1974 int vertexCount = sides*3;
1979 float d = 0.0f, dStep = 360.0f/sides;
1980 for (
int v = 0; v < vertexCount; v += 3)
1982 vertices[v] = (
Vector3){ 0.0f, 0.0f, 0.0f };
1990 for (
int n = 0; n < vertexCount; n++) normals[n] = (
Vector3){ 0.0f, 1.0f, 0.0f };
1994 for (
int n = 0; n < vertexCount; n++) texcoords[n] = (
Vector2){ 0.0f, 0.0f };
2021 mesh.
normals[3*i + 1] = normals[i].
y;
2022 mesh.
normals[3*i + 2] = normals[i].
z;
2041#define CUSTOM_MESH_GEN_PLANE
2042#if defined(CUSTOM_MESH_GEN_PLANE)
2047 int vertexCount = resX*resZ;
2050 for (
int z = 0; z < resZ; z++)
2053 float zPos = ((float)z/(resZ - 1) - 0.5f)*length;
2054 for (
int x = 0; x < resX; x++)
2057 float xPos = ((float)x/(resX - 1) - 0.5f)*width;
2058 vertices[x + z*resX] = (
Vector3){ xPos, 0.0f, zPos };
2064 for (
int n = 0; n < vertexCount; n++) normals[n] = (
Vector3){ 0.0f, 1.0f, 0.0f };
2068 for (
int v = 0; v < resZ; v++)
2070 for (
int u = 0; u < resX; u++)
2072 texcoords[u + v*resX] = (
Vector2){ (float)u/(resX - 1), (float)v/(resZ - 1) };
2077 int numFaces = (resX - 1)*(resZ - 1);
2078 int *triangles = (
int *)
RL_MALLOC(numFaces*6*
sizeof(
int));
2080 for (
int face = 0; face < numFaces; face++)
2083 int i = face % (resX - 1) + (face/(resZ - 1)*resX);
2085 triangles[t++] = i + resX;
2086 triangles[t++] = i + 1;
2089 triangles[t++] = i + resX;
2090 triangles[t++] = i + resX + 1;
2091 triangles[t++] = i + 1;
2120 mesh.
normals[3*i + 1] = normals[i].
y;
2121 mesh.
normals[3*i + 2] = normals[i].
z;
2174#define CUSTOM_MESH_GEN_CUBE
2175#if defined(CUSTOM_MESH_GEN_CUBE)
2176 float vertices[] = {
2177 -width/2, -height/2, length/2,
2178 width/2, -height/2, length/2,
2179 width/2, height/2, length/2,
2180 -width/2, height/2, length/2,
2181 -width/2, -height/2, -length/2,
2182 -width/2, height/2, -length/2,
2183 width/2, height/2, -length/2,
2184 width/2, -height/2, -length/2,
2185 -width/2, height/2, -length/2,
2186 -width/2, height/2, length/2,
2187 width/2, height/2, length/2,
2188 width/2, height/2, -length/2,
2189 -width/2, -height/2, -length/2,
2190 width/2, -height/2, -length/2,
2191 width/2, -height/2, length/2,
2192 -width/2, -height/2, length/2,
2193 width/2, -height/2, -length/2,
2194 width/2, height/2, -length/2,
2195 width/2, height/2, length/2,
2196 width/2, -height/2, length/2,
2197 -width/2, -height/2, -length/2,
2198 -width/2, -height/2, length/2,
2199 -width/2, height/2, length/2,
2200 -width/2, height/2, -length/2
2203 float texcoords[] = {
2258 memcpy(mesh.
vertices, vertices, 24*3*
sizeof(
float));
2261 memcpy(mesh.
texcoords, texcoords, 24*2*
sizeof(
float));
2264 memcpy(mesh.
normals, normals, 24*3*
sizeof(
float));
2271 for (
int i = 0; i < 36; i += 6)
2274 mesh.
indices[i + 1] = 4*k + 1;
2275 mesh.
indices[i + 2] = 4*k + 2;
2277 mesh.
indices[i + 4] = 4*k + 2;
2278 mesh.
indices[i + 5] = 4*k + 3;
2299 for (
int i = 0; i < 2*cube->
npoints; i++) cube->
tcoords[i] = 0.0f;
2339 if ((rings >= 3) && (slices >= 3))
2381 if ((rings >= 3) && (slices >= 3))
2383 if (radius < 0.0f) radius = 0.0f;
2438 for (
int i = 0; i < 2*capTop->npoints; i++) capTop->tcoords[i] = 0.0f;
2446 for (
int i = 0; i < 2*capBottom->
npoints; i++) capBottom->
tcoords[i] = 0.95f;
2503 for (
int i = 0; i < 2*capBottom->npoints; i++) capBottom->tcoords[i] = 0.95f;
2544 if ((sides >= 3) && (radSeg >= 3))
2546 if (radius > 1.0f) radius = 1.0f;
2547 else if (radius < 0.1f) radius = 0.1f;
2590 if ((sides >= 3) && (radSeg >= 3))
2592 if (radius > 3.0f) radius = 3.0f;
2593 else if (radius < 0.5f) radius = 0.5f;
2633 #define GRAY_VALUE(c) ((c.r+c.g+c.b)/3)
2637 int mapX = heightmap.
width;
2638 int mapZ = heightmap.
height;
2656 int trisCounter = 0;
2658 Vector3 scaleFactor = { size.
x/mapX, size.
y/255.0f, size.
z/mapZ };
2665 for (
int z = 0; z < mapZ-1; z++)
2667 for (
int x = 0; x < mapX-1; x++)
2673 mesh.
vertices[vCounter] = (float)x*scaleFactor.
x;
2675 mesh.
vertices[vCounter + 2] = (float)z*scaleFactor.
z;
2677 mesh.
vertices[vCounter + 3] = (
float)x*scaleFactor.
x;
2679 mesh.
vertices[vCounter + 5] = (
float)(z + 1)*scaleFactor.
z;
2681 mesh.
vertices[vCounter + 6] = (
float)(x + 1)*scaleFactor.
x;
2683 mesh.
vertices[vCounter + 8] = (float)z*scaleFactor.
z;
2694 mesh.
vertices[vCounter + 15] = (
float)(x + 1)*scaleFactor.
x;
2695 mesh.
vertices[vCounter + 16] = (
float)
GRAY_VALUE(pixels[(x + 1) + (z + 1)*mapX])*scaleFactor.
y;
2696 mesh.
vertices[vCounter + 17] = (float)(z + 1)*scaleFactor.
z;
2701 mesh.
texcoords[tcCounter] = (float)x/(mapX - 1);
2702 mesh.
texcoords[tcCounter + 1] = (float)z/(mapZ - 1);
2704 mesh.
texcoords[tcCounter + 2] = (float)x/(mapX - 1);
2705 mesh.
texcoords[tcCounter + 3] = (float)(z + 1)/(mapZ - 1);
2707 mesh.
texcoords[tcCounter + 4] = (float)(x + 1)/(mapX - 1);
2708 mesh.
texcoords[tcCounter + 5] = (float)z/(mapZ - 1);
2716 mesh.
texcoords[tcCounter + 10] = (float)(x + 1)/(mapX - 1);
2717 mesh.
texcoords[tcCounter + 11] = (float)(z + 1)/(mapZ - 1);
2722 for (
int i = 0; i < 18; i += 9)
2739 mesh.
normals[nCounter + i + 1] = vN.
y;
2740 mesh.
normals[nCounter + i + 2] = vN.
z;
2742 mesh.
normals[nCounter + i + 3] = vN.
x;
2743 mesh.
normals[nCounter + i + 4] = vN.
y;
2744 mesh.
normals[nCounter + i + 5] = vN.
z;
2746 mesh.
normals[nCounter + i + 6] = vN.
x;
2747 mesh.
normals[nCounter + i + 7] = vN.
y;
2748 mesh.
normals[nCounter + i + 8] = vN.
z;
2768 #define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a))
2774 int mapWidth = cubicmap.
width;
2775 int mapHeight = cubicmap.
height;
2778 int maxTriangles = cubicmap.
width*cubicmap.
height*12;
2784 float w = cubeSize.
x;
2785 float h = cubeSize.
z;
2786 float h2 = cubeSize.
y;
2793 Vector3 n1 = { 1.0f, 0.0f, 0.0f };
2794 Vector3 n2 = { -1.0f, 0.0f, 0.0f };
2795 Vector3 n3 = { 0.0f, 1.0f, 0.0f };
2796 Vector3 n4 = { 0.0f, -1.0f, 0.0f };
2797 Vector3 n5 = { 0.0f, 0.0f, -1.0f };
2798 Vector3 n6 = { 0.0f, 0.0f, 1.0f };
2801 typedef struct RectangleF {
2808 RectangleF rightTexUV = { 0.0f, 0.0f, 0.5f, 0.5f };
2809 RectangleF leftTexUV = { 0.5f, 0.0f, 0.5f, 0.5f };
2810 RectangleF frontTexUV = { 0.0f, 0.0f, 0.5f, 0.5f };
2811 RectangleF backTexUV = { 0.5f, 0.0f, 0.5f, 0.5f };
2812 RectangleF topTexUV = { 0.0f, 0.5f, 0.5f, 0.5f };
2813 RectangleF bottomTexUV = { 0.5f, 0.5f, 0.5f, 0.5f };
2815 for (
int z = 0; z < mapHeight; ++z)
2817 for (
int x = 0; x < mapWidth; ++x)
2820 Vector3 v1 = { w*(x - 0.5f), h2, h*(z - 0.5f) };
2821 Vector3 v2 = { w*(x - 0.5f), h2, h*(z + 0.5f) };
2822 Vector3 v3 = { w*(x + 0.5f), h2, h*(z + 0.5f) };
2823 Vector3 v4 = { w*(x + 0.5f), h2, h*(z - 0.5f) };
2824 Vector3 v5 = { w*(x + 0.5f), 0, h*(z - 0.5f) };
2825 Vector3 v6 = { w*(x - 0.5f), 0, h*(z - 0.5f) };
2826 Vector3 v7 = { w*(x - 0.5f), 0, h*(z + 0.5f) };
2827 Vector3 v8 = { w*(x + 0.5f), 0, h*(z + 0.5f) };
2837 mapVertices[vCounter] = v1;
2838 mapVertices[vCounter + 1] = v2;
2839 mapVertices[vCounter + 2] = v3;
2840 mapVertices[vCounter + 3] = v1;
2841 mapVertices[vCounter + 4] = v3;
2842 mapVertices[vCounter + 5] = v4;
2845 mapNormals[nCounter] = n3;
2846 mapNormals[nCounter + 1] = n3;
2847 mapNormals[nCounter + 2] = n3;
2848 mapNormals[nCounter + 3] = n3;
2849 mapNormals[nCounter + 4] = n3;
2850 mapNormals[nCounter + 5] = n3;
2853 mapTexcoords[tcCounter] = (
Vector2){ topTexUV.
x, topTexUV.y };
2854 mapTexcoords[tcCounter + 1] = (
Vector2){ topTexUV.
x, topTexUV.y + topTexUV.height };
2855 mapTexcoords[tcCounter + 2] = (
Vector2){ topTexUV.
x + topTexUV.width, topTexUV.y + topTexUV.height };
2856 mapTexcoords[tcCounter + 3] = (
Vector2){ topTexUV.
x, topTexUV.y };
2857 mapTexcoords[tcCounter + 4] = (
Vector2){ topTexUV.
x + topTexUV.width, topTexUV.y + topTexUV.height };
2858 mapTexcoords[tcCounter + 5] = (
Vector2){ topTexUV.
x + topTexUV.width, topTexUV.y };
2862 mapVertices[vCounter] = v6;
2863 mapVertices[vCounter + 1] = v8;
2864 mapVertices[vCounter + 2] = v7;
2865 mapVertices[vCounter + 3] = v6;
2866 mapVertices[vCounter + 4] = v5;
2867 mapVertices[vCounter + 5] = v8;
2870 mapNormals[nCounter] = n4;
2871 mapNormals[nCounter + 1] = n4;
2872 mapNormals[nCounter + 2] = n4;
2873 mapNormals[nCounter + 3] = n4;
2874 mapNormals[nCounter + 4] = n4;
2875 mapNormals[nCounter + 5] = n4;
2878 mapTexcoords[tcCounter] = (
Vector2){ bottomTexUV.
x + bottomTexUV.width, bottomTexUV.y };
2879 mapTexcoords[tcCounter + 1] = (
Vector2){ bottomTexUV.
x, bottomTexUV.y + bottomTexUV.height };
2880 mapTexcoords[tcCounter + 2] = (
Vector2){ bottomTexUV.
x + bottomTexUV.width, bottomTexUV.y + bottomTexUV.height };
2881 mapTexcoords[tcCounter + 3] = (
Vector2){ bottomTexUV.
x + bottomTexUV.width, bottomTexUV.y };
2882 mapTexcoords[tcCounter + 4] = (
Vector2){ bottomTexUV.
x, bottomTexUV.y };
2883 mapTexcoords[tcCounter + 5] = (
Vector2){ bottomTexUV.
x, bottomTexUV.y + bottomTexUV.height };
2891 mapVertices[vCounter] = v2;
2892 mapVertices[vCounter + 1] = v7;
2893 mapVertices[vCounter + 2] = v3;
2894 mapVertices[vCounter + 3] = v3;
2895 mapVertices[vCounter + 4] = v7;
2896 mapVertices[vCounter + 5] = v8;
2899 mapNormals[nCounter] = n6;
2900 mapNormals[nCounter + 1] = n6;
2901 mapNormals[nCounter + 2] = n6;
2902 mapNormals[nCounter + 3] = n6;
2903 mapNormals[nCounter + 4] = n6;
2904 mapNormals[nCounter + 5] = n6;
2907 mapTexcoords[tcCounter] = (
Vector2){ frontTexUV.
x, frontTexUV.y };
2908 mapTexcoords[tcCounter + 1] = (
Vector2){ frontTexUV.
x, frontTexUV.y + frontTexUV.height };
2909 mapTexcoords[tcCounter + 2] = (
Vector2){ frontTexUV.
x + frontTexUV.width, frontTexUV.y };
2910 mapTexcoords[tcCounter + 3] = (
Vector2){ frontTexUV.
x + frontTexUV.width, frontTexUV.y };
2911 mapTexcoords[tcCounter + 4] = (
Vector2){ frontTexUV.
x, frontTexUV.y + frontTexUV.height };
2912 mapTexcoords[tcCounter + 5] = (
Vector2){ frontTexUV.
x + frontTexUV.width, frontTexUV.y + frontTexUV.height };
2921 mapVertices[vCounter] = v1;
2922 mapVertices[vCounter + 1] = v5;
2923 mapVertices[vCounter + 2] = v6;
2924 mapVertices[vCounter + 3] = v1;
2925 mapVertices[vCounter + 4] = v4;
2926 mapVertices[vCounter + 5] = v5;
2929 mapNormals[nCounter] = n5;
2930 mapNormals[nCounter + 1] = n5;
2931 mapNormals[nCounter + 2] = n5;
2932 mapNormals[nCounter + 3] = n5;
2933 mapNormals[nCounter + 4] = n5;
2934 mapNormals[nCounter + 5] = n5;
2937 mapTexcoords[tcCounter] = (
Vector2){ backTexUV.
x + backTexUV.width, backTexUV.y };
2938 mapTexcoords[tcCounter + 1] = (
Vector2){ backTexUV.
x, backTexUV.y + backTexUV.height };
2939 mapTexcoords[tcCounter + 2] = (
Vector2){ backTexUV.
x + backTexUV.width, backTexUV.y + backTexUV.height };
2940 mapTexcoords[tcCounter + 3] = (
Vector2){ backTexUV.
x + backTexUV.width, backTexUV.y };
2941 mapTexcoords[tcCounter + 4] = (
Vector2){ backTexUV.
x, backTexUV.y };
2942 mapTexcoords[tcCounter + 5] = (
Vector2){ backTexUV.
x, backTexUV.y + backTexUV.height };
2951 mapVertices[vCounter] = v3;
2952 mapVertices[vCounter + 1] = v8;
2953 mapVertices[vCounter + 2] = v4;
2954 mapVertices[vCounter + 3] = v4;
2955 mapVertices[vCounter + 4] = v8;
2956 mapVertices[vCounter + 5] = v5;
2959 mapNormals[nCounter] = n1;
2960 mapNormals[nCounter + 1] = n1;
2961 mapNormals[nCounter + 2] = n1;
2962 mapNormals[nCounter + 3] = n1;
2963 mapNormals[nCounter + 4] = n1;
2964 mapNormals[nCounter + 5] = n1;
2967 mapTexcoords[tcCounter] = (
Vector2){ rightTexUV.x, rightTexUV.y };
2968 mapTexcoords[tcCounter + 1] = (
Vector2){ rightTexUV.x, rightTexUV.y + rightTexUV.height };
2969 mapTexcoords[tcCounter + 2] = (
Vector2){ rightTexUV.x + rightTexUV.width, rightTexUV.y };
2970 mapTexcoords[tcCounter + 3] = (
Vector2){ rightTexUV.x + rightTexUV.width, rightTexUV.y };
2971 mapTexcoords[tcCounter + 4] = (
Vector2){ rightTexUV.x, rightTexUV.y + rightTexUV.height };
2972 mapTexcoords[tcCounter + 5] = (
Vector2){ rightTexUV.x + rightTexUV.width, rightTexUV.y + rightTexUV.height };
2981 mapVertices[vCounter] = v1;
2982 mapVertices[vCounter + 1] = v7;
2983 mapVertices[vCounter + 2] = v2;
2984 mapVertices[vCounter + 3] = v1;
2985 mapVertices[vCounter + 4] = v6;
2986 mapVertices[vCounter + 5] = v7;
2989 mapNormals[nCounter] = n2;
2990 mapNormals[nCounter + 1] = n2;
2991 mapNormals[nCounter + 2] = n2;
2992 mapNormals[nCounter + 3] = n2;
2993 mapNormals[nCounter + 4] = n2;
2994 mapNormals[nCounter + 5] = n2;
2997 mapTexcoords[tcCounter] = (
Vector2){ leftTexUV.
x, leftTexUV.y };
2998 mapTexcoords[tcCounter + 1] = (
Vector2){ leftTexUV.
x + leftTexUV.width, leftTexUV.y + leftTexUV.height };
2999 mapTexcoords[tcCounter + 2] = (
Vector2){ leftTexUV.
x + leftTexUV.width, leftTexUV.y };
3000 mapTexcoords[tcCounter + 3] = (
Vector2){ leftTexUV.
x, leftTexUV.y };
3001 mapTexcoords[tcCounter + 4] = (
Vector2){ leftTexUV.
x, leftTexUV.y + leftTexUV.height };
3002 mapTexcoords[tcCounter + 5] = (
Vector2){ leftTexUV.
x + leftTexUV.width, leftTexUV.y + leftTexUV.height };
3010 mapVertices[vCounter] = v1;
3011 mapVertices[vCounter + 1] = v3;
3012 mapVertices[vCounter + 2] = v2;
3013 mapVertices[vCounter + 3] = v1;
3014 mapVertices[vCounter + 4] = v4;
3015 mapVertices[vCounter + 5] = v3;
3018 mapNormals[nCounter] = n4;
3019 mapNormals[nCounter + 1] = n4;
3020 mapNormals[nCounter + 2] = n4;
3021 mapNormals[nCounter + 3] = n4;
3022 mapNormals[nCounter + 4] = n4;
3023 mapNormals[nCounter + 5] = n4;
3026 mapTexcoords[tcCounter] = (
Vector2){ topTexUV.
x, topTexUV.y };
3027 mapTexcoords[tcCounter + 1] = (
Vector2){ topTexUV.
x + topTexUV.width, topTexUV.y + topTexUV.height };
3028 mapTexcoords[tcCounter + 2] = (
Vector2){ topTexUV.
x, topTexUV.y + topTexUV.height };
3029 mapTexcoords[tcCounter + 3] = (
Vector2){ topTexUV.
x, topTexUV.y };
3030 mapTexcoords[tcCounter + 4] = (
Vector2){ topTexUV.
x + topTexUV.width, topTexUV.y };
3031 mapTexcoords[tcCounter + 5] = (
Vector2){ topTexUV.
x + topTexUV.width, topTexUV.y + topTexUV.height };
3035 mapVertices[vCounter] = v6;
3036 mapVertices[vCounter + 1] = v7;
3037 mapVertices[vCounter + 2] = v8;
3038 mapVertices[vCounter + 3] = v6;
3039 mapVertices[vCounter + 4] = v8;
3040 mapVertices[vCounter + 5] = v5;
3043 mapNormals[nCounter] = n3;
3044 mapNormals[nCounter + 1] = n3;
3045 mapNormals[nCounter + 2] = n3;
3046 mapNormals[nCounter + 3] = n3;
3047 mapNormals[nCounter + 4] = n3;
3048 mapNormals[nCounter + 5] = n3;
3051 mapTexcoords[tcCounter] = (
Vector2){ bottomTexUV.
x + bottomTexUV.width, bottomTexUV.y };
3052 mapTexcoords[tcCounter + 1] = (
Vector2){ bottomTexUV.
x + bottomTexUV.width, bottomTexUV.y + bottomTexUV.height };
3053 mapTexcoords[tcCounter + 2] = (
Vector2){ bottomTexUV.
x, bottomTexUV.y + bottomTexUV.height };
3054 mapTexcoords[tcCounter + 3] = (
Vector2){ bottomTexUV.
x + bottomTexUV.width, bottomTexUV.y };
3055 mapTexcoords[tcCounter + 4] = (
Vector2){ bottomTexUV.
x, bottomTexUV.y + bottomTexUV.height };
3056 mapTexcoords[tcCounter + 5] = (
Vector2){ bottomTexUV.
x, bottomTexUV.y };
3074 for (
int i = 0; i < vCounter; i++)
3076 mesh.
vertices[fCounter] = mapVertices[i].
x;
3077 mesh.
vertices[fCounter + 1] = mapVertices[i].
y;
3078 mesh.
vertices[fCounter + 2] = mapVertices[i].
z;
3085 for (
int i = 0; i < nCounter; i++)
3087 mesh.
normals[fCounter] = mapNormals[i].
x;
3088 mesh.
normals[fCounter + 1] = mapNormals[i].
y;
3089 mesh.
normals[fCounter + 2] = mapNormals[i].
z;
3096 for (
int i = 0; i < tcCounter; i++)
3098 mesh.
texcoords[fCounter] = mapTexcoords[i].
x;
3099 mesh.
texcoords[fCounter + 1] = mapTexcoords[i].
y;
3138 box.
min = minVertex;
3139 box.
max = maxVertex;
3171 float x1 = v2.
x - v1.
x;
3172 float y1 = v2.
y - v1.
y;
3173 float z1 = v2.
z - v1.
z;
3174 float x2 = v3.
x - v1.
x;
3175 float y2 = v3.
y - v1.
y;
3176 float z2 = v3.
z - v1.
z;
3178 float s1 = uv2.
x - uv1.
x;
3179 float t1 = uv2.
y - uv1.
y;
3180 float s2 = uv3.
x - uv1.
x;
3181 float t2 = uv3.
y - uv1.
y;
3183 float div = s1*t2 - s2*t1;
3184 float r = (div == 0.0f)? 0.0f : 1.0f/div;
3186 Vector3 sdir = { (t2*x1 - t1*x2)*r, (t2*y1 - t1*y2)*r, (t2*z1 - t1*z2)*r };
3187 Vector3 tdir = { (s1*x2 - s2*x1)*r, (s1*y2 - s2*y1)*r, (s1*z2 - s2*z1)*r };
3205#if defined(COMPUTE_TANGENTS_METHOD_01)
3243 TRACELOG(
LOG_INFO,
"MESH: Tangents data computed and uploaded for provided mesh");
3262 Vector3 vScale = { scale, scale, scale };
3263 Vector3 rotationAxis = { 0.0f, 1.0f, 0.0f };
3265 DrawModelEx(model, position, rotationAxis, 0.0f, vScale, tint);
3282 for (
int i = 0; i < model.
meshCount; i++)
3287 colorTint.
r = (
unsigned char)((((
float)color.
r/255.0f)*((
float)tint.
r/255.0f))*255.0f);
3288 colorTint.
g = (
unsigned char)((((
float)color.
g/255.0f)*((float)tint.
g/255.0f))*255.0f);
3289 colorTint.
b = (
unsigned char)((((
float)color.
b/255.0f)*((
float)tint.
b/255.0f))*255.0f);
3290 colorTint.
a = (
unsigned char)((((
float)color.
a/255.0f)*((
float)tint.
a/255.0f))*255.0f);
3303 DrawModel(model, position, scale, tint);
3313 DrawModelEx(model, position, rotationAxis, rotationAngle, scale, tint);
3330 Vector3 up = { 0.0f, 1.0f, 0.0f };
3356 if (rotation != 0.0f)
3358 float sinRotation = sinf(rotation*
DEG2RAD);
3359 float cosRotation = cosf(rotation*
DEG2RAD);
3362 float rotateAboutX = sizeRatio.
x*origin.
x/2;
3363 float rotateAboutY = sizeRatio.
y*origin.
y/2;
3365 float xtvalue, ytvalue;
3366 float rotatedX, rotatedY;
3370 rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
3371 rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
3376 rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
3377 rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
3382 rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
3383 rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
3388 rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
3389 rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
3396 bottomRight =
Vector3Add(bottomRight, position);
3397 bottomLeft =
Vector3Add(bottomLeft, position);
3443 bool collision =
false;
3467 bool collision =
true;
3471 if ((box1.
max.
y < box2.
min.
y) || (box1.
min.
y > box2.
max.
y)) collision =
false;
3472 if ((box1.
max.
z < box2.
min.
z) || (box1.
min.
z > box2.
max.
z)) collision =
false;
3474 else collision =
false;
3482 bool collision =
false;
3486 if (center.
x < box.
min.
x) dmin += powf(center.
x - box.
min.
x, 2);
3487 else if (center.
x > box.
max.
x) dmin += powf(center.
x - box.
max.
x, 2);
3489 if (center.
y < box.
min.
y) dmin += powf(center.
y - box.
min.
y, 2);
3490 else if (center.
y > box.
max.
y) dmin += powf(center.
y - box.
max.
y, 2);
3492 if (center.
z < box.
min.
z) dmin += powf(center.
z - box.
min.
z, 2);
3493 else if (center.
z > box.
max.
z) dmin += powf(center.
z - box.
max.
z, 2);
3495 if (dmin <= (radius*radius)) collision =
true;
3508 float d = radius*radius - (distance*distance - vector*vector);
3510 collision.
hit = d >= 0.0f;
3513 if (distance < radius)
3515 collision.
distance = vector + sqrtf(d);
3525 collision.
distance = vector - sqrtf(d);
3550 float t[11] = { 0 };
3562 t[6] = (float)fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5]));
3563 t[7] = (float)fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5]));
3565 collision.
hit = !((t[7] < 0) || (t[6] > t[7]));
3608 for (
int i = 0; i < triangleCount; i++)
3615 a = vertdata[mesh.
indices[i*3 + 0]];
3616 b = vertdata[mesh.
indices[i*3 + 1]];
3617 c = vertdata[mesh.
indices[i*3 + 2]];
3621 a = vertdata[i*3 + 0];
3622 b = vertdata[i*3 + 1];
3623 c = vertdata[i*3 + 2];
3635 if ((!collision.
hit) || (collision.
distance > triHitInfo.
distance)) collision = triHitInfo;
3648 #define EPSILON 0.000001f
3654 float det, invDet, u, v, t;
3678 if ((u < 0.0f) || (u > 1.0f))
return collision;
3687 if ((v < 0.0f) || ((u + v) > 1.0f))
return collision;
3694 collision.
hit =
true;
3719#if defined(SUPPORT_FILEFORMAT_OBJ)
3726static Model LoadOBJ(
const char *fileName)
3728 Model model = { 0 };
3732 unsigned int meshCount = 0;
3735 unsigned int materialCount = 0;
3739 if (fileText !=
NULL)
3741 unsigned int dataSize = (
unsigned int)strlen(fileText);
3742 char currentDir[1024] = { 0 };
3745 if (
CHDIR(workingDir) != 0)
3751 int ret =
tinyobj_parse_obj(&attrib, &meshes, &meshCount, &materials, &materialCount, fileText, dataSize, flags);
3754 else TRACELOG(
LOG_INFO,
"MODEL: [%s] OBJ data loaded successfully: %i meshes/%i materials", fileName, meshCount, materialCount);
3759 if (materialCount > 0)
3768 TraceLog(
LOG_INFO,
"MODEL: No materials, putting all meshes in a default material");
3778 if (materialCount > 0)
3780 for (
unsigned int fi = 0; fi < attrib.
num_faces; fi++)
3804 for (
int mi = 0; mi < model.
meshCount; mi++)
3815 for (
unsigned int af = 0; af < attrib.
num_faces; af++)
3818 if (mm == -1) { mm = 0; }
3846 for (
int v = 0; v < 3; v++) { model.
meshes[mm].
normals[vnCount[mm] + v] = attrib.
normals[idx0.
vn_idx*3 + v]; } vnCount[mm] +=3;
3847 for (
int v = 0; v < 3; v++) { model.
meshes[mm].
normals[vnCount[mm] + v] = attrib.
normals[idx1.
vn_idx*3 + v]; } vnCount[mm] +=3;
3848 for (
int v = 0; v < 3; v++) { model.
meshes[mm].
normals[vnCount[mm] + v] = attrib.
normals[idx2.
vn_idx*3 + v]; } vnCount[mm] +=3;
3853 for (
unsigned int m = 0; m < materialCount; m++)
3865 model.
materials[m].
maps[
MATERIAL_MAP_DIFFUSE].
color = (
Color){ (
unsigned char)(materials[m].diffuse[0]*255.0f), (
unsigned char)(materials[m].diffuse[1]*255.0f), (
unsigned char)(materials[m].diffuse[2]*255.0f), 255 };
3869 model.
materials[m].
maps[
MATERIAL_MAP_SPECULAR].
color = (
Color){ (
unsigned char)(materials[m].specular[0]*255.0f), (
unsigned char)(materials[m].specular[1]*255.0f), (
unsigned char)(materials[m].specular[2]*255.0f), 255 };
3876 model.
materials[m].
maps[
MATERIAL_MAP_EMISSION].
color = (
Color){ (
unsigned char)(materials[m].emission[0]*255.0f), (
unsigned char)(materials[m].emission[1]*255.0f), (
unsigned char)(materials[m].emission[2]*255.0f), 255 };
3893 if (
CHDIR(currentDir) != 0)
3903#if defined(SUPPORT_FILEFORMAT_IQM)
3905static Model LoadIQM(
const char *fileName)
3907 #define IQM_MAGIC "INTERQUAKEMODEL"
3908 #define IQM_VERSION 2
3910 #define BONE_NAME_LENGTH 32
3911 #define MESH_NAME_LENGTH 32
3912 #define MATERIAL_NAME_LENGTH 32
3914 unsigned int fileSize = 0;
3915 unsigned char *fileData =
LoadFileData(fileName, &fileSize);
3916 unsigned char *fileDataPtr = fileData;
3920 typedef struct IQMHeader {
3922 unsigned int version;
3923 unsigned int filesize;
3925 unsigned int num_text, ofs_text;
3926 unsigned int num_meshes, ofs_meshes;
3927 unsigned int num_vertexarrays, num_vertexes, ofs_vertexarrays;
3928 unsigned int num_triangles, ofs_triangles, ofs_adjacency;
3929 unsigned int num_joints, ofs_joints;
3930 unsigned int num_poses, ofs_poses;
3931 unsigned int num_anims, ofs_anims;
3932 unsigned int num_frames, num_framechannels, ofs_frames, ofs_bounds;
3933 unsigned int num_comment, ofs_comment;
3934 unsigned int num_extensions, ofs_extensions;
3937 typedef struct IQMMesh {
3939 unsigned int material;
3940 unsigned int first_vertex, num_vertexes;
3941 unsigned int first_triangle, num_triangles;
3944 typedef struct IQMTriangle {
3945 unsigned int vertex[3];
3948 typedef struct IQMJoint {
3951 float translate[3], rotate[4], scale[3];
3954 typedef struct IQMVertexArray {
3957 unsigned int format;
3959 unsigned int offset;
3995 IQM_BLENDINDEXES = 4,
3996 IQM_BLENDWEIGHTS = 5,
4001 Model model = { 0 };
4003 IQMMesh *imesh =
NULL;
4004 IQMTriangle *tri =
NULL;
4005 IQMVertexArray *va =
NULL;
4006 IQMJoint *ijoint =
NULL;
4008 float *vertex =
NULL;
4009 float *normal =
NULL;
4011 char *blendi =
NULL;
4012 unsigned char *blendw =
NULL;
4013 unsigned char *color =
NULL;
4016 if (fileDataPtr ==
NULL)
return model;
4019 IQMHeader *iqmHeader = (IQMHeader *)fileDataPtr;
4029 TRACELOG(
LOG_WARNING,
"MODEL: [%s] IQM file version not supported (%i)", fileName, iqmHeader->version);
4036 imesh =
RL_MALLOC(iqmHeader->num_meshes*
sizeof(IQMMesh));
4039 memcpy(imesh, fileDataPtr + iqmHeader->ofs_meshes, iqmHeader->num_meshes*
sizeof(IQMMesh));
4041 model.
meshCount = iqmHeader->num_meshes;
4051 for (
int i = 0; i < model.
meshCount; i++)
4055 memcpy(name, fileDataPtr + iqmHeader->ofs_text + imesh[i].name,
MESH_NAME_LENGTH*
sizeof(
char));
4059 memcpy(material, fileDataPtr + iqmHeader->ofs_text + imesh[i].material,
MATERIAL_NAME_LENGTH*
sizeof(
char));
4063 TRACELOG(
LOG_DEBUG,
"MODEL: [%s] mesh name (%s), material (%s)", fileName, name, material);
4084 tri =
RL_MALLOC(iqmHeader->num_triangles*
sizeof(IQMTriangle));
4087 memcpy(tri, fileDataPtr + iqmHeader->ofs_triangles, iqmHeader->num_triangles*
sizeof(IQMTriangle));
4089 for (
int m = 0; m < model.
meshCount; m++)
4093 for (
unsigned int i = imesh[m].first_triangle; i < (imesh[m].first_triangle + imesh[m].num_triangles); i++)
4098 model.
meshes[m].
indices[tcounter + 2] = tri[i].vertex[0] - imesh[m].first_vertex;
4099 model.
meshes[m].
indices[tcounter + 1] = tri[i].vertex[1] - imesh[m].first_vertex;
4100 model.
meshes[m].
indices[tcounter] = tri[i].vertex[2] - imesh[m].first_vertex;
4106 va =
RL_MALLOC(iqmHeader->num_vertexarrays*
sizeof(IQMVertexArray));
4109 memcpy(va, fileDataPtr + iqmHeader->ofs_vertexarrays, iqmHeader->num_vertexarrays*
sizeof(IQMVertexArray));
4111 for (
unsigned int i = 0; i < iqmHeader->num_vertexarrays; i++)
4117 vertex =
RL_MALLOC(iqmHeader->num_vertexes*3*
sizeof(
float));
4120 memcpy(vertex, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*3*
sizeof(
float));
4122 for (
unsigned int m = 0; m < iqmHeader->num_meshes; m++)
4125 for (
unsigned int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++)
4135 normal =
RL_MALLOC(iqmHeader->num_vertexes*3*
sizeof(
float));
4138 memcpy(normal, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*3*
sizeof(
float));
4140 for (
unsigned int m = 0; m < iqmHeader->num_meshes; m++)
4143 for (
unsigned int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++)
4153 text =
RL_MALLOC(iqmHeader->num_vertexes*2*
sizeof(
float));
4156 memcpy(text, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*2*
sizeof(
float));
4158 for (
unsigned int m = 0; m < iqmHeader->num_meshes; m++)
4161 for (
unsigned int i = imesh[m].first_vertex*2; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*2; i++)
4168 case IQM_BLENDINDEXES:
4170 blendi =
RL_MALLOC(iqmHeader->num_vertexes*4*
sizeof(
char));
4173 memcpy(blendi, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*
sizeof(
char));
4175 for (
unsigned int m = 0; m < iqmHeader->num_meshes; m++)
4177 int boneCounter = 0;
4178 for (
unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++)
4185 case IQM_BLENDWEIGHTS:
4187 blendw =
RL_MALLOC(iqmHeader->num_vertexes*4*
sizeof(
unsigned char));
4190 memcpy(blendw, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*
sizeof(
unsigned char));
4192 for (
unsigned int m = 0; m < iqmHeader->num_meshes; m++)
4194 int boneCounter = 0;
4195 for (
unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++)
4204 color =
RL_MALLOC(iqmHeader->num_vertexes*4*
sizeof(
unsigned char));
4207 memcpy(color, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*
sizeof(
unsigned char));
4209 for (
unsigned int m = 0; m < iqmHeader->num_meshes; m++)
4214 for (
unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++)
4225 ijoint =
RL_MALLOC(iqmHeader->num_joints*
sizeof(IQMJoint));
4228 memcpy(ijoint, fileDataPtr + iqmHeader->ofs_joints, iqmHeader->num_joints*
sizeof(IQMJoint));
4230 model.
boneCount = iqmHeader->num_joints;
4234 for (
unsigned int i = 0; i < iqmHeader->num_joints; i++)
4258 for (
int i = 0; i < model.
boneCount; i++)
4285static ModelAnimation *LoadModelAnimationsIQM(
const char *fileName,
unsigned int *animCount)
4287 #define IQM_MAGIC "INTERQUAKEMODEL"
4288 #define IQM_VERSION 2
4290 unsigned int fileSize = 0;
4291 unsigned char *fileData =
LoadFileData(fileName, &fileSize);
4292 unsigned char *fileDataPtr = fileData;
4294 typedef struct IQMHeader {
4296 unsigned int version;
4297 unsigned int filesize;
4299 unsigned int num_text, ofs_text;
4300 unsigned int num_meshes, ofs_meshes;
4301 unsigned int num_vertexarrays, num_vertexes, ofs_vertexarrays;
4302 unsigned int num_triangles, ofs_triangles, ofs_adjacency;
4303 unsigned int num_joints, ofs_joints;
4304 unsigned int num_poses, ofs_poses;
4305 unsigned int num_anims, ofs_anims;
4306 unsigned int num_frames, num_framechannels, ofs_frames, ofs_bounds;
4307 unsigned int num_comment, ofs_comment;
4308 unsigned int num_extensions, ofs_extensions;
4311 typedef struct IQMPose {
4314 float channeloffset[10];
4315 float channelscale[10];
4318 typedef struct IQMAnim {
4320 unsigned int first_frame, num_frames;
4326 if (fileDataPtr ==
NULL)
return NULL;
4329 IQMHeader *iqmHeader = (IQMHeader *)fileDataPtr;
4339 TRACELOG(
LOG_WARNING,
"MODEL: [%s] IQM file version not supported (%i)", fileName, iqmHeader->version);
4344 IQMPose *poses =
RL_MALLOC(iqmHeader->num_poses*
sizeof(IQMPose));
4347 memcpy(poses, fileDataPtr + iqmHeader->ofs_poses, iqmHeader->num_poses*
sizeof(IQMPose));
4350 *animCount = iqmHeader->num_anims;
4351 IQMAnim *anim =
RL_MALLOC(iqmHeader->num_anims*
sizeof(IQMAnim));
4354 memcpy(anim, fileDataPtr + iqmHeader->ofs_anims, iqmHeader->num_anims*
sizeof(IQMAnim));
4359 unsigned short *framedata =
RL_MALLOC(iqmHeader->num_frames*iqmHeader->num_framechannels*
sizeof(
unsigned short));
4362 memcpy(framedata, fileDataPtr + iqmHeader->ofs_frames, iqmHeader->num_frames*iqmHeader->num_framechannels*
sizeof(
unsigned short));
4364 for (
unsigned int a = 0; a < iqmHeader->num_anims; a++)
4366 animations[a].
frameCount = anim[a].num_frames;
4367 animations[a].
boneCount = iqmHeader->num_poses;
4372 for (
unsigned int j = 0; j < iqmHeader->num_poses; j++)
4374 strcpy(animations[a].bones[j].name,
"ANIMJOINTNAME");
4378 for (
unsigned int j = 0; j < anim[a].num_frames; j++) animations[a].framePoses[j] =
RL_MALLOC(iqmHeader->num_poses*
sizeof(
Transform));
4380 int dcounter = anim[a].first_frame*iqmHeader->num_framechannels;
4382 for (
unsigned int frame = 0; frame < anim[a].num_frames; frame++)
4384 for (
unsigned int i = 0; i < iqmHeader->num_poses; i++)
4388 if (poses[i].mask & 0x01)
4396 if (poses[i].mask & 0x02)
4404 if (poses[i].mask & 0x04)
4412 if (poses[i].mask & 0x08)
4414 animations[a].
framePoses[frame][i].
rotation.
x += framedata[dcounter]*poses[i].channelscale[3];
4420 if (poses[i].mask & 0x10)
4422 animations[a].
framePoses[frame][i].
rotation.
y += framedata[dcounter]*poses[i].channelscale[4];
4428 if (poses[i].mask & 0x20)
4430 animations[a].
framePoses[frame][i].
rotation.
z += framedata[dcounter]*poses[i].channelscale[5];
4436 if (poses[i].mask & 0x40)
4438 animations[a].
framePoses[frame][i].
rotation.
w += framedata[dcounter]*poses[i].channelscale[6];
4444 if (poses[i].mask & 0x80)
4446 animations[a].
framePoses[frame][i].
scale.
x += framedata[dcounter]*poses[i].channelscale[7];
4452 if (poses[i].mask & 0x100)
4454 animations[a].
framePoses[frame][i].
scale.
y += framedata[dcounter]*poses[i].channelscale[8];
4460 if (poses[i].mask & 0x200)
4462 animations[a].
framePoses[frame][i].
scale.
z += framedata[dcounter]*poses[i].channelscale[9];
4471 for (
unsigned int frame = 0; frame < anim[a].num_frames; frame++)
4473 for (
int i = 0; i < animations[a].
boneCount; i++)
4475 if (animations[a].bones[i].parent >= 0)
4477 animations[a].
framePoses[frame][i].
rotation =
QuaternionMultiply(animations[a].framePoses[frame][animations[a].bones[i].parent].rotation, animations[a].framePoses[frame][i].rotation);
4479 animations[a].
framePoses[frame][i].
translation =
Vector3Add(animations[a].framePoses[frame][i].translation, animations[a].framePoses[frame][animations[a].bones[i].parent].translation);
4480 animations[a].
framePoses[frame][i].
scale =
Vector3Multiply(animations[a].framePoses[frame][i].scale, animations[a].framePoses[frame][animations[a].bones[i].parent].scale);
4497#if defined(SUPPORT_FILEFORMAT_GLTF)
4499static Image LoadImageFromCgltfImage(
cgltf_image *cgltfImage,
const char *texPath)
4501 Image image = { 0 };
4505 if ((strlen(cgltfImage->
uri) > 5) &&
4506 (cgltfImage->
uri[0] ==
'd') &&
4507 (cgltfImage->
uri[1] ==
'a') &&
4508 (cgltfImage->
uri[2] ==
't') &&
4509 (cgltfImage->
uri[3] ==
'a') &&
4510 (cgltfImage->
uri[4] ==
':'))
4516 while ((cgltfImage->
uri[i] !=
',') && (cgltfImage->
uri[i] != 0)) i++;
4521 int base64Size = (int)strlen(cgltfImage->
uri + i + 1);
4522 int outSize = 3*(base64Size/4);
4555 if ((strcmp(cgltfImage->
mime_type,
"image\\/png") == 0) ||
4557 else if ((strcmp(cgltfImage->
mime_type,
"image\\/jpeg") == 0) ||
4568static Model LoadGLTF(
const char *fileName)
4595 #define LOAD_ATTRIBUTE(accesor, numComp, dataType, dstPtr) \
4598 dataType *buffer = (dataType *)accesor->buffer_view->buffer->data + accesor->buffer_view->offset/sizeof(dataType) + accesor->offset/sizeof(dataType); \
4599 for (unsigned int k = 0; k < accesor->count; k++) \
4601 for (int l = 0; l < numComp; l++) \
4603 dstPtr[numComp*k + l] = buffer[n + l];\
4605 n += (int)(accesor->stride/sizeof(dataType));\
4609 Model model = { 0 };
4612 unsigned int dataSize = 0;
4613 unsigned char *fileData =
LoadFileData(fileName, &dataSize);
4615 if (fileData ==
NULL)
return model;
4639 int primitivesCount = 0;
4686 if (imMetallicRoughness.
data !=
NULL)
4746 for (
unsigned int i = 0, meshIndex = 0; i < data->
meshes_count; i++)
4777 else TRACELOG(
LOG_WARNING,
"MODEL: [%s] Vertices attribute data format not supported, use vec3 float", fileName);
4791 else TRACELOG(
LOG_WARNING,
"MODEL: [%s] Normal attribute data format not supported, use vec3 float", fileName);
4805 else TRACELOG(
LOG_WARNING,
"MODEL: [%s] Tangent attribute data format not supported, use vec4 float", fileName);
4821 else TRACELOG(
LOG_WARNING,
"MODEL: [%s] Texcoords attribute data format not supported, use vec2 float", fileName);
4843 unsigned short *temp =
RL_MALLOC(attribute->
count*4*
sizeof(
unsigned short));
4847 for (
int c = 0; c < attribute->
count*4; c++) model.
meshes[meshIndex].
colors[c] = (
unsigned char)(((float)temp[c]/65535.0f)*255.0f);
4861 for (
int c = 0; c < attribute->
count*4; c++) model.
meshes[meshIndex].
colors[c] = (
unsigned char)(temp[c]*255.0f);
4865 else TRACELOG(
LOG_WARNING,
"MODEL: [%s] Color attribute data format not supported", fileName);
4892 unsigned int *temp =
RL_MALLOC(attribute->
count*
sizeof(
unsigned int));
4896 for (
int d = 0; d < attribute->
count; d++) model.
meshes[meshIndex].
indices[d] = (
unsigned short)temp[d];
4898 TRACELOG(
LOG_WARNING,
"MODEL: [%s] Indices data converted from u32 to u16, possible loss of data", fileName);
4902 else TRACELOG(
LOG_WARNING,
"MODEL: [%s] Indices data format not supported, use u16", fileName);
4987#if defined(SUPPORT_FILEFORMAT_VOX)
4989static Model LoadVOX(
const char *fileName)
4991 Model model = { 0 };
4994 int meshescount = 0;
4995 unsigned int fileSize = 0;
4996 unsigned char *fileData =
NULL;
5022 meshescount = 1 + (nbvertices/65536);
5024 TRACELOG(
LOG_INFO,
"MODEL: [%s] VOX data loaded successfully : %i vertices/%i meshes", fileName, nbvertices, meshescount);
5041 int verticesMax = 65532;
5051 for (
int i = 0; i < meshescount; i++)
5054 memset(pmesh, 0,
sizeof(
Mesh));
5057 pmesh->
vertexCount = (int)fmin(verticesMax, verticesRemain);
5061 memcpy(pmesh->
vertices, pvertices, size);
5065 size = voxarray.
indices.
used*
sizeof(
unsigned short);
5067 memcpy(pmesh->
indices, pindices, size);
5074 memcpy(pmesh->
colors, pcolors, size);
5079 verticesRemain -= verticesMax;
5080 pvertices += verticesMax;
5081 pcolors += verticesMax;
@ cgltf_primitive_type_triangles
cgltf_result cgltf_parse(const cgltf_options *options, const void *data, cgltf_size size, cgltf_data **out_data)
void cgltf_free(cgltf_data *data)
@ cgltf_attribute_type_color
@ cgltf_attribute_type_texcoord
@ cgltf_attribute_type_position
@ cgltf_attribute_type_tangent
@ cgltf_attribute_type_normal
cgltf_result cgltf_load_buffer_base64(const cgltf_options *options, cgltf_size size, const char *base64, void **out_data)
cgltf_result cgltf_load_buffers(const cgltf_options *options, cgltf_data *data, const char *gltf_path)
@ cgltf_component_type_r_32f
@ cgltf_component_type_r_8u
@ cgltf_component_type_r_32u
@ cgltf_component_type_r_16u
#define MAX_MATERIAL_MAPS
#define MAX_MESH_VERTEX_BUFFERS
#define GL_TEXTURE_COORD_ARRAY
void par_shapes_merge_and_free(par_shapes_mesh *dst, par_shapes_mesh *src)
par_shapes_mesh * par_shapes_create_parametric_sphere(int slices, int stacks)
par_shapes_mesh * par_shapes_create_cube()
void par_shapes_scale(par_shapes_mesh *, float x, float y, float z)
par_shapes_mesh * par_shapes_create_cone(int slices, int stacks)
void par_shapes_free_mesh(par_shapes_mesh *)
par_shapes_mesh * par_shapes_create_cylinder(int slices, int stacks)
par_shapes_mesh * par_shapes_create_torus(int slices, int stacks, float radius)
par_shapes_mesh * par_shapes_create_plane(int slices, int stacks)
par_shapes_mesh * par_shapes_create_disk(float radius, int slices, float const *center, float const *normal)
par_shapes_mesh * par_shapes_create_trefoil_knot(int slices, int stacks, float radius)
void par_shapes_compute_normals(par_shapes_mesh *m)
void par_shapes_translate(par_shapes_mesh *, float x, float y, float z)
par_shapes_mesh * par_shapes_create_hemisphere(int slices, int stacks)
void par_shapes_rotate(par_shapes_mesh *, float radians, float const *axis)
#define RL_MALLOC(sz)
raudio v1.0 - A simple and easy-to-use audio library based on miniaudio
#define TRACELOG(level,...)
@ SHADER_LOC_MATRIX_MODEL
@ SHADER_LOC_COLOR_DIFFUSE
@ SHADER_LOC_VERTEX_COLOR
@ SHADER_LOC_COLOR_SPECULAR
@ SHADER_LOC_VERTEX_TANGENT
@ SHADER_LOC_MATRIX_PROJECTION
@ SHADER_LOC_VERTEX_TEXCOORD01
@ SHADER_LOC_VERTEX_POSITION
@ SHADER_LOC_VERTEX_TEXCOORD02
@ SHADER_LOC_MATRIX_NORMAL
@ SHADER_LOC_VERTEX_NORMAL
RLAPI const char * TextFormat(const char *text,...)
RLAPI Color * LoadImageColors(Image image)
RLAPI const char * GetWorkingDirectory(void)
RLAPI Texture2D LoadTexture(const char *fileName)
RLAPI void UnloadFileData(unsigned char *data)
@ MATERIAL_MAP_IRRADIANCE
@ PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
RLAPI unsigned char * LoadFileData(const char *fileName, unsigned int *bytesRead)
RLAPI void UnloadShader(Shader shader)
RLAPI void TraceLog(int logLevel, const char *text,...)
RLAPI void UnloadImageColors(Color *colors)
RLAPI Image LoadImage(const char *fileName)
RLAPI bool SaveFileText(const char *fileName, char *text)
#define MATERIAL_MAP_SPECULAR
RLAPI void UnloadImage(Image image)
RLAPI const char * GetDirectoryPath(const char *filePath)
RLAPI void UnloadFileText(char *text)
RLAPI Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize)
#define MATERIAL_MAP_DIFFUSE
RLAPI Texture2D LoadTextureFromImage(Image image)
RLAPI bool IsFileExtension(const char *fileName, const char *ext)
RLAPI char * LoadFileText(const char *fileName)
#define SHADER_LOC_MAP_DIFFUSE
RMAPI Vector3 Vector3Normalize(Vector3 v)
RMAPI Vector3 Vector3Transform(Vector3 v, Matrix mat)
RMAPI Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q)
#define MatrixToFloat(mat)
RMAPI Vector2 Vector2Zero(void)
RMAPI Matrix MatrixRotate(Vector3 axis, float angle)
RMAPI Quaternion QuaternionNormalize(Quaternion q)
RMAPI Quaternion QuaternionInvert(Quaternion q)
RMAPI Vector3 Vector3Min(Vector3 v1, Vector3 v2)
RMAPI Vector3 Vector3Perpendicular(Vector3 v)
RMAPI float Vector3DotProduct(Vector3 v1, Vector3 v2)
RMAPI Matrix MatrixScale(float x, float y, float z)
RMAPI Vector3 Vector3Add(Vector3 v1, Vector3 v2)
RMAPI Matrix MatrixIdentity(void)
RMAPI Vector3 Vector3Subtract(Vector3 v1, Vector3 v2)
RMAPI Matrix MatrixTranslate(float x, float y, float z)
RMAPI Vector3 Vector3Multiply(Vector3 v1, Vector3 v2)
RMAPI float16 MatrixToFloatV(Matrix mat)
RMAPI Vector3 Vector3Negate(Vector3 v)
RMAPI Vector3 Vector3Divide(Vector3 v1, Vector3 v2)
RMAPI Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount)
RMAPI Matrix MatrixInvert(Matrix mat)
RMAPI void Vector3OrthoNormalize(Vector3 *v1, Vector3 *v2)
RMAPI float Vector3Length(const Vector3 v)
RMAPI Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2)
RMAPI Vector3 Vector3Max(Vector3 v1, Vector3 v2)
RMAPI Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2)
RMAPI Vector3 Vector3Scale(Vector3 v, float scalar)
RMAPI Matrix MatrixTranspose(Matrix mat)
RMAPI Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up)
RMAPI Matrix MatrixMultiply(Matrix left, Matrix right)
RLAPI int * rlGetShaderLocsDefault(void)
RLAPI void rlNormal3f(float x, float y, float z)
RLAPI Matrix rlGetMatrixProjection(void)
RLAPI void rlDisableTextureCubemap(void)
RLAPI void rlDisableVertexBuffer(void)
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count)
RLAPI int rlGetFramebufferHeight(void)
RLAPI void rlDrawVertexArray(int offset, int count)
RLAPI bool rlIsStereoRenderEnabled(void)
RLAPI void rlEnableTexture(unsigned int id)
RLAPI unsigned int rlLoadVertexArray(void)
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
RLAPI void rlEnableTextureCubemap(unsigned int id)
RLAPI Matrix rlGetMatrixModelview(void)
RLAPI unsigned int rlLoadVertexBuffer(const void *buffer, int size, bool dynamic)
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances)
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor)
RLAPI void rlDisableTexture(void)
RLAPI unsigned int rlGetShaderIdDefault(void)
RLAPI void rlVertex3f(float x, float y, float z)
RLAPI void rlDisableVertexArray(void)
RLAPI void rlDisableVertexAttribute(unsigned int index)
RLAPI void rlSetUniformMatrix(int locIndex, Matrix mat)
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, const void *pointer)
RLAPI void rlPushMatrix(void)
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, const void *data, int dataSize, int offset)
RLAPI unsigned int rlLoadVertexBufferElement(const void *buffer, int size, bool dynamic)
RLAPI unsigned int rlGetTextureIdDefault(void)
RLAPI void rlSetMatrixModelview(Matrix view)
RLAPI void rlViewport(int x, int y, int width, int height)
RLAPI bool rlEnableVertexArray(unsigned int vaoId)
RLAPI Matrix rlGetMatrixViewOffsetStereo(int eye)
RLAPI void rlScalef(float x, float y, float z)
RLAPI Matrix rlGetMatrixTransform(void)
RLAPI void rlDisableWireMode(void)
RLAPI void rlActiveTextureSlot(int slot)
RLAPI void rlEnableShader(unsigned int id)
RLAPI int rlGetFramebufferWidth(void)
RLAPI void rlMultMatrixf(float *matf)
RLAPI void rlBegin(int mode)
RLAPI void rlDisableVertexBufferElement(void)
RLAPI void rlTexCoord2f(float x, float y)
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances)
RLAPI void rlEnableVertexAttribute(unsigned int index)
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count)
RLAPI void rlColor3f(float x, float y, float z)
RLAPI void rlUnloadVertexArray(unsigned int vaoId)
RLAPI void rlEnableWireMode(void)
RLAPI void rlRotatef(float angle, float x, float y, float z)
RLAPI void rlEnableVertexBuffer(unsigned int id)
RLAPI void rlDisableShader(void)
RLAPI void rlUnloadTexture(unsigned int id)
RLAPI void rlSetMatrixProjection(Matrix proj)
RLAPI void rlPopMatrix(void)
RLAPI void rlSetTexture(unsigned int id)
RLAPI void rlEnableVertexBufferElement(unsigned int id)
RLAPI void rlDrawVertexArrayElements(int offset, int count, const void *buffer)
RLAPI bool rlCheckRenderBatchLimit(int vCount)
RLAPI void rlTranslatef(float x, float y, float z)
RLAPI Matrix rlGetMatrixProjectionStereo(int eye)
RLAPI void rlUnloadVertexBuffer(unsigned int vboId)
Mesh GenMeshSphere(float radius, int rings, int slices)
void UnloadModel(Model model)
void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint)
bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2)
BoundingBox GetModelBoundingBox(Model model)
void UnloadModelKeepMeshes(Model model)
void DrawCubeWires(Vector3 position, float width, float height, float length, Color color)
void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color)
void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color)
void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, int instances)
void UnloadMesh(Mesh mesh)
void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color)
void DrawRay(Ray ray, Color color)
Mesh GenMeshPoly(int sides, float radius)
ModelAnimation * LoadModelAnimations(const char *fileName, unsigned int *animCount)
void GenMeshTangents(Mesh *mesh)
void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color)
RayCollision GetRayCollisionTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3)
void DrawMesh(Mesh mesh, Material material, Matrix transform)
void DrawPlane(Vector3 centerPos, Vector2 size, Color color)
void SetModelMeshMaterial(Model *model, int meshId, int materialId)
void UnloadModelAnimations(ModelAnimation *animations, unsigned int count)
void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color)
bool CheckCollisionSpheres(Vector3 center1, float radius1, Vector3 center2, float radius2)
Model LoadModelFromMesh(Mesh mesh)
BoundingBox GetMeshBoundingBox(Mesh mesh)
#define COLOR_EQUAL(col1, col2)
Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint)
RayCollision GetRayCollisionMesh(Ray ray, Mesh mesh, Matrix transform)
bool CheckCollisionBoxSphere(BoundingBox box, Vector3 center, float radius)
bool IsModelAnimationValid(Model model, ModelAnimation anim)
Mesh GenMeshPlane(float width, float length, int resX, int resZ)
RayCollision GetRayCollisionSphere(Ray ray, Vector3 center, float radius)
void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color)
Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
Mesh GenMeshCylinder(float radius, float height, int slices)
void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float size, Color tint)
void DrawCubeWiresV(Vector3 position, Vector3 size, Color color)
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
Mesh GenMeshHemiSphere(float radius, int rings, int slices)
void DrawCube(Vector3 position, float width, float height, float length, Color color)
Model LoadModel(const char *fileName)
void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color)
Mesh GenMeshCone(float radius, float height, int slices)
void DrawBoundingBox(BoundingBox box, Color color)
void DrawModelWires(Model model, Vector3 position, float scale, Color tint)
Mesh GenMeshCube(float width, float height, float length)
void UploadMesh(Mesh *mesh, bool dynamic)
void UnloadModelAnimation(ModelAnimation anim)
Material LoadMaterialDefault(void)
void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color)
void DrawSphere(Vector3 centerPos, float radius, Color color)
Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
RayCollision GetRayCollisionBox(Ray ray, BoundingBox box)
void UnloadMaterial(Material material)
Material * LoadMaterials(const char *fileName, int *materialCount)
void DrawPoint3D(Vector3 position, Color color)
void UpdateMeshBuffer(Mesh mesh, int index, const void *data, int dataSize, int offset)
RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4)
void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color)
void DrawTriangleStrip3D(Vector3 *points, int pointCount, Color color)
bool ExportMesh(Mesh mesh, const char *fileName)
void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color)
void DrawCubeV(Vector3 position, Vector3 size, Color color)
#define MATERIAL_NAME_LENGTH
void DrawGrid(int slices, float spacing)
void SetMaterialTexture(Material *material, int mapType, Texture2D texture)
#define LOAD_ATTRIBUTE(accesor, numComp, dataType, dstPtr)
void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color)
void GenMeshBinormals(Mesh *mesh)
void DrawModel(Model model, Vector3 position, float scale, Color tint)
cgltf_component_type component_type
cgltf_attribute_type type
cgltf_material * materials
cgltf_size textures_count
cgltf_file_type file_type
cgltf_size materials_count
cgltf_buffer_view * buffer_view
cgltf_pbr_metallic_roughness pbr_metallic_roughness
cgltf_float emissive_factor[3]
cgltf_bool has_pbr_metallic_roughness
cgltf_texture_view emissive_texture
cgltf_texture_view occlusion_texture
cgltf_texture_view normal_texture
cgltf_primitive * primitives
cgltf_size primitives_count
cgltf_size attributes_count
cgltf_attribute * attributes
cgltf_primitive_type type
cgltf_material * material
tinyobj_vertex_index_t * faces
unsigned int num_texcoords
int tinyobj_parse_obj(tinyobj_attrib_t *attrib, tinyobj_shape_t **shapes, unsigned int *num_shapes, tinyobj_material_t **materials, unsigned int *num_materials, const char *buf, unsigned int len, unsigned int flags)
int tinyobj_parse_mtl_file(tinyobj_material_t **materials_out, unsigned int *num_materials_out, const char *filename)
void tinyobj_attrib_free(tinyobj_attrib_t *attrib)
#define TINYOBJ_FLAG_TRIANGULATE
void tinyobj_shapes_free(tinyobj_shape_t *shapes, unsigned int num_shapes)
void tinyobj_materials_free(tinyobj_material_t *materials, unsigned int num_materials)
int Vox_LoadFromMemory(unsigned char *pvoxData, unsigned int voxDataSize, VoxArray3D *pvoxarray)
void Vox_FreeArrays(VoxArray3D *voxarray)