|
|
|
@ -2640,7 +2640,7 @@ Mesh GenMeshPoly(int sides, float radius)
|
|
|
|
int vertexCount = sides*3;
|
|
|
|
int vertexCount = sides*3;
|
|
|
|
|
|
|
|
|
|
|
|
// Vertices definition
|
|
|
|
// Vertices definition
|
|
|
|
Vector3 *vertices = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3));
|
|
|
|
Vector3 *vertices = (Vector3 *)RL_CALLOC(vertexCount, sizeof(Vector3));
|
|
|
|
|
|
|
|
|
|
|
|
float d = 0.0f, dStep = 360.0f/sides;
|
|
|
|
float d = 0.0f, dStep = 360.0f/sides;
|
|
|
|
for (int v = 0; v < vertexCount - 2; v += 3)
|
|
|
|
for (int v = 0; v < vertexCount - 2; v += 3)
|
|
|
|
@ -2652,18 +2652,18 @@ Mesh GenMeshPoly(int sides, float radius)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Normals definition
|
|
|
|
// Normals definition
|
|
|
|
Vector3 *normals = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3));
|
|
|
|
Vector3 *normals = (Vector3 *)RL_CALLOC(vertexCount, sizeof(Vector3));
|
|
|
|
for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up;
|
|
|
|
for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up;
|
|
|
|
|
|
|
|
|
|
|
|
// TexCoords definition
|
|
|
|
// TexCoords definition
|
|
|
|
Vector2 *texcoords = (Vector2 *)RL_MALLOC(vertexCount*sizeof(Vector2));
|
|
|
|
Vector2 *texcoords = (Vector2 *)RL_CALLOC(vertexCount, sizeof(Vector2));
|
|
|
|
for (int n = 0; n < vertexCount; n++) texcoords[n] = (Vector2){ 0.0f, 0.0f };
|
|
|
|
for (int n = 0; n < vertexCount; n++) texcoords[n] = (Vector2){ 0.0f, 0.0f };
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = vertexCount;
|
|
|
|
mesh.vertexCount = vertexCount;
|
|
|
|
mesh.triangleCount = sides;
|
|
|
|
mesh.triangleCount = sides;
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Mesh vertices position array
|
|
|
|
// Mesh vertices position array
|
|
|
|
for (int i = 0; i < mesh.vertexCount; i++)
|
|
|
|
for (int i = 0; i < mesh.vertexCount; i++)
|
|
|
|
@ -2712,7 +2712,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
|
|
|
|
// Vertices definition
|
|
|
|
// Vertices definition
|
|
|
|
int vertexCount = resX*resZ; // vertices get reused for the faces
|
|
|
|
int vertexCount = resX*resZ; // vertices get reused for the faces
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 *vertices = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3));
|
|
|
|
Vector3 *vertices = (Vector3 *)RL_CALLOC(vertexCount, sizeof(Vector3));
|
|
|
|
for (int z = 0; z < resZ; z++)
|
|
|
|
for (int z = 0; z < resZ; z++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// [-length/2, length/2]
|
|
|
|
// [-length/2, length/2]
|
|
|
|
@ -2726,11 +2726,11 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Normals definition
|
|
|
|
// Normals definition
|
|
|
|
Vector3 *normals = (Vector3 *)RL_MALLOC(vertexCount*sizeof(Vector3));
|
|
|
|
Vector3 *normals = (Vector3 *)RL_CALLOC(vertexCount, sizeof(Vector3));
|
|
|
|
for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up;
|
|
|
|
for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up;
|
|
|
|
|
|
|
|
|
|
|
|
// TexCoords definition
|
|
|
|
// TexCoords definition
|
|
|
|
Vector2 *texcoords = (Vector2 *)RL_MALLOC(vertexCount*sizeof(Vector2));
|
|
|
|
Vector2 *texcoords = (Vector2 *)RL_CALLOC(vertexCount, sizeof(Vector2));
|
|
|
|
for (int v = 0; v < resZ; v++)
|
|
|
|
for (int v = 0; v < resZ; v++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int u = 0; u < resX; u++)
|
|
|
|
for (int u = 0; u < resX; u++)
|
|
|
|
@ -2741,7 +2741,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
|
|
|
|
|
|
|
|
|
|
|
|
// Triangles definition (indices)
|
|
|
|
// Triangles definition (indices)
|
|
|
|
int numFaces = (resX - 1)*(resZ - 1);
|
|
|
|
int numFaces = (resX - 1)*(resZ - 1);
|
|
|
|
int *triangles = (int *)RL_MALLOC(numFaces*6*sizeof(int));
|
|
|
|
int *triangles = (int *)RL_CALLOC(numFaces*6, sizeof(int));
|
|
|
|
int t = 0;
|
|
|
|
int t = 0;
|
|
|
|
for (int face = 0; face < numFaces; face++)
|
|
|
|
for (int face = 0; face < numFaces; face++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -2759,10 +2759,10 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = vertexCount;
|
|
|
|
mesh.vertexCount = vertexCount;
|
|
|
|
mesh.triangleCount = numFaces*2;
|
|
|
|
mesh.triangleCount = numFaces*2;
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
|
|
|
mesh.indices = (unsigned short *)RL_MALLOC(mesh.triangleCount*3*sizeof(unsigned short));
|
|
|
|
mesh.indices = (unsigned short *)RL_CALLOC(mesh.triangleCount*3, sizeof(unsigned short));
|
|
|
|
|
|
|
|
|
|
|
|
// Mesh vertices position array
|
|
|
|
// Mesh vertices position array
|
|
|
|
for (int i = 0; i < mesh.vertexCount; i++)
|
|
|
|
for (int i = 0; i < mesh.vertexCount; i++)
|
|
|
|
@ -2802,9 +2802,9 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ)
|
|
|
|
par_shapes_rotate(plane, -PI/2.0f, (float[]){ 1, 0, 0 });
|
|
|
|
par_shapes_rotate(plane, -PI/2.0f, (float[]){ 1, 0, 0 });
|
|
|
|
par_shapes_translate(plane, -width/2, 0.0f, length/2);
|
|
|
|
par_shapes_translate(plane, -width/2, 0.0f, length/2);
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(plane->ntriangles*3*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(plane->ntriangles*3*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(plane->ntriangles*3*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(plane->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(plane->ntriangles*3*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = plane->ntriangles*3;
|
|
|
|
mesh.vertexCount = plane->ntriangles*3;
|
|
|
|
mesh.triangleCount = plane->ntriangles;
|
|
|
|
mesh.triangleCount = plane->ntriangles;
|
|
|
|
@ -2920,16 +2920,16 @@ Mesh GenMeshCube(float width, float height, float length)
|
|
|
|
-1.0f, 0.0f, 0.0f
|
|
|
|
-1.0f, 0.0f, 0.0f
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(24*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(24*3, sizeof(float));
|
|
|
|
memcpy(mesh.vertices, vertices, 24*3*sizeof(float));
|
|
|
|
memcpy(mesh.vertices, vertices, 24*3*sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(24*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(24*2, sizeof(float));
|
|
|
|
memcpy(mesh.texcoords, texcoords, 24*2*sizeof(float));
|
|
|
|
memcpy(mesh.texcoords, texcoords, 24*2*sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.normals = (float *)RL_MALLOC(24*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(24*3, sizeof(float));
|
|
|
|
memcpy(mesh.normals, normals, 24*3*sizeof(float));
|
|
|
|
memcpy(mesh.normals, normals, 24*3*sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.indices = (unsigned short *)RL_MALLOC(36*sizeof(unsigned short));
|
|
|
|
mesh.indices = (unsigned short *)RL_CALLOC(36, sizeof(unsigned short));
|
|
|
|
|
|
|
|
|
|
|
|
int k = 0;
|
|
|
|
int k = 0;
|
|
|
|
|
|
|
|
|
|
|
|
@ -2967,9 +2967,9 @@ par_shapes_mesh *par_shapes_create_icosahedron(); // 20 sides polyhedron
|
|
|
|
par_shapes_translate(cube, -width/2, 0.0f, -length/2);
|
|
|
|
par_shapes_translate(cube, -width/2, 0.0f, -length/2);
|
|
|
|
par_shapes_compute_normals(cube);
|
|
|
|
par_shapes_compute_normals(cube);
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(cube->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(cube->ntriangles*3*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(cube->ntriangles*3*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(cube->ntriangles*3*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(cube->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(cube->ntriangles*3*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = cube->ntriangles*3;
|
|
|
|
mesh.vertexCount = cube->ntriangles*3;
|
|
|
|
mesh.triangleCount = cube->ntriangles;
|
|
|
|
mesh.triangleCount = cube->ntriangles;
|
|
|
|
@ -3009,9 +3009,9 @@ Mesh GenMeshSphere(float radius, int rings, int slices)
|
|
|
|
par_shapes_scale(sphere, radius, radius, radius);
|
|
|
|
par_shapes_scale(sphere, radius, radius, radius);
|
|
|
|
// NOTE: Soft normals are computed internally
|
|
|
|
// NOTE: Soft normals are computed internally
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(sphere->ntriangles*3*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(sphere->ntriangles*3*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(sphere->ntriangles*3*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(sphere->ntriangles*3*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = sphere->ntriangles*3;
|
|
|
|
mesh.vertexCount = sphere->ntriangles*3;
|
|
|
|
mesh.triangleCount = sphere->ntriangles;
|
|
|
|
mesh.triangleCount = sphere->ntriangles;
|
|
|
|
@ -3053,9 +3053,9 @@ Mesh GenMeshHemiSphere(float radius, int rings, int slices)
|
|
|
|
par_shapes_scale(sphere, radius, radius, radius);
|
|
|
|
par_shapes_scale(sphere, radius, radius, radius);
|
|
|
|
// NOTE: Soft normals are computed internally
|
|
|
|
// NOTE: Soft normals are computed internally
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(sphere->ntriangles*3*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(sphere->ntriangles*3*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(sphere->ntriangles*3*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(sphere->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(sphere->ntriangles*3*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = sphere->ntriangles*3;
|
|
|
|
mesh.vertexCount = sphere->ntriangles*3;
|
|
|
|
mesh.triangleCount = sphere->ntriangles;
|
|
|
|
mesh.triangleCount = sphere->ntriangles;
|
|
|
|
@ -3117,9 +3117,9 @@ Mesh GenMeshCylinder(float radius, float height, int slices)
|
|
|
|
par_shapes_merge_and_free(cylinder, capTop);
|
|
|
|
par_shapes_merge_and_free(cylinder, capTop);
|
|
|
|
par_shapes_merge_and_free(cylinder, capBottom);
|
|
|
|
par_shapes_merge_and_free(cylinder, capBottom);
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(cylinder->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(cylinder->ntriangles*3*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(cylinder->ntriangles*3*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(cylinder->ntriangles*3*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(cylinder->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(cylinder->ntriangles*3*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = cylinder->ntriangles*3;
|
|
|
|
mesh.vertexCount = cylinder->ntriangles*3;
|
|
|
|
mesh.triangleCount = cylinder->ntriangles;
|
|
|
|
mesh.triangleCount = cylinder->ntriangles;
|
|
|
|
@ -3172,9 +3172,9 @@ Mesh GenMeshCone(float radius, float height, int slices)
|
|
|
|
|
|
|
|
|
|
|
|
par_shapes_merge_and_free(cone, capBottom);
|
|
|
|
par_shapes_merge_and_free(cone, capBottom);
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(cone->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(cone->ntriangles*3*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(cone->ntriangles*3*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(cone->ntriangles*3*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(cone->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(cone->ntriangles*3*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = cone->ntriangles*3;
|
|
|
|
mesh.vertexCount = cone->ntriangles*3;
|
|
|
|
mesh.triangleCount = cone->ntriangles;
|
|
|
|
mesh.triangleCount = cone->ntriangles;
|
|
|
|
@ -3220,9 +3220,9 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
|
|
|
|
par_shapes_mesh *torus = par_shapes_create_torus(radSeg, sides, radius);
|
|
|
|
par_shapes_mesh *torus = par_shapes_create_torus(radSeg, sides, radius);
|
|
|
|
par_shapes_scale(torus, size/2, size/2, size/2);
|
|
|
|
par_shapes_scale(torus, size/2, size/2, size/2);
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(torus->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(torus->ntriangles*3*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(torus->ntriangles*3*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(torus->ntriangles*3*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(torus->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(torus->ntriangles*3*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = torus->ntriangles*3;
|
|
|
|
mesh.vertexCount = torus->ntriangles*3;
|
|
|
|
mesh.triangleCount = torus->ntriangles;
|
|
|
|
mesh.triangleCount = torus->ntriangles;
|
|
|
|
@ -3264,9 +3264,9 @@ Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
|
|
|
|
par_shapes_mesh *knot = par_shapes_create_trefoil_knot(radSeg, sides, radius);
|
|
|
|
par_shapes_mesh *knot = par_shapes_create_trefoil_knot(radSeg, sides, radius);
|
|
|
|
par_shapes_scale(knot, size, size, size);
|
|
|
|
par_shapes_scale(knot, size, size, size);
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(knot->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(knot->ntriangles*3*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(knot->ntriangles*3*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(knot->ntriangles*3*2, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(knot->ntriangles*3*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(knot->ntriangles*3*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = knot->ntriangles*3;
|
|
|
|
mesh.vertexCount = knot->ntriangles*3;
|
|
|
|
mesh.triangleCount = knot->ntriangles;
|
|
|
|
mesh.triangleCount = knot->ntriangles;
|
|
|
|
@ -3313,9 +3313,9 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertexCount = mesh.triangleCount*3;
|
|
|
|
mesh.vertexCount = mesh.triangleCount*3;
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
|
|
|
|
mesh.colors = NULL;
|
|
|
|
mesh.colors = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int vCounter = 0; // Used to count vertices float by float
|
|
|
|
int vCounter = 0; // Used to count vertices float by float
|
|
|
|
@ -3448,9 +3448,9 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
|
|
|
float h = cubeSize.z;
|
|
|
|
float h = cubeSize.z;
|
|
|
|
float h2 = cubeSize.y;
|
|
|
|
float h2 = cubeSize.y;
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 *mapVertices = (Vector3 *)RL_MALLOC(maxTriangles*3*sizeof(Vector3));
|
|
|
|
Vector3 *mapVertices = (Vector3 *)RL_CALLOC(maxTriangles*3, sizeof(Vector3));
|
|
|
|
Vector2 *mapTexcoords = (Vector2 *)RL_MALLOC(maxTriangles*3*sizeof(Vector2));
|
|
|
|
Vector2 *mapTexcoords = (Vector2 *)RL_CALLOC(maxTriangles*3, sizeof(Vector2));
|
|
|
|
Vector3 *mapNormals = (Vector3 *)RL_MALLOC(maxTriangles*3*sizeof(Vector3));
|
|
|
|
Vector3 *mapNormals = (Vector3 *)RL_CALLOC(maxTriangles*3, sizeof(Vector3));
|
|
|
|
|
|
|
|
|
|
|
|
// Define the 6 normals of the cube, combined accordingly later
|
|
|
|
// Define the 6 normals of the cube, combined accordingly later
|
|
|
|
Vector3 n1 = { 1.0f, 0.0f, 0.0f };
|
|
|
|
Vector3 n1 = { 1.0f, 0.0f, 0.0f };
|
|
|
|
@ -3727,9 +3727,9 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
|
|
|
mesh.vertexCount = vCounter;
|
|
|
|
mesh.vertexCount = vCounter;
|
|
|
|
mesh.triangleCount = vCounter/3;
|
|
|
|
mesh.triangleCount = vCounter/3;
|
|
|
|
|
|
|
|
|
|
|
|
mesh.vertices = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
|
|
|
|
mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_MALLOC(mesh.vertexCount*3*sizeof(float));
|
|
|
|
mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
|
|
|
|
mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float));
|
|
|
|
mesh.colors = NULL;
|
|
|
|
mesh.colors = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int fCounter = 0;
|
|
|
|
int fCounter = 0;
|
|
|
|
@ -3816,11 +3816,11 @@ void GenMeshTangents(Mesh *mesh)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Allocate or reallocate tangents data
|
|
|
|
// Allocate or reallocate tangents data
|
|
|
|
if (mesh->tangents == NULL) mesh->tangents = (float *)RL_MALLOC(mesh->vertexCount*4*sizeof(float));
|
|
|
|
if (mesh->tangents == NULL) mesh->tangents = (float *)RL_CALLOC(mesh->vertexCount*4, sizeof(float));
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RL_FREE(mesh->tangents);
|
|
|
|
RL_FREE(mesh->tangents);
|
|
|
|
mesh->tangents = (float *)RL_MALLOC(mesh->vertexCount*4*sizeof(float));
|
|
|
|
mesh->tangents = (float *)RL_CALLOC(mesh->vertexCount*4, sizeof(float));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Allocate temporary arrays for tangents calculation
|
|
|
|
// Allocate temporary arrays for tangents calculation
|
|
|
|
@ -4874,7 +4874,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
//fileDataPtr += sizeof(IQMHeader); // Move file data pointer
|
|
|
|
//fileDataPtr += sizeof(IQMHeader); // Move file data pointer
|
|
|
|
|
|
|
|
|
|
|
|
// Meshes data processing
|
|
|
|
// Meshes data processing
|
|
|
|
imesh = (IQMMesh *)RL_MALLOC(iqmHeader->num_meshes*sizeof(IQMMesh));
|
|
|
|
imesh = (IQMMesh *)RL_CALLOC(iqmHeader->num_meshes, sizeof(IQMMesh));
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_meshes, SEEK_SET);
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_meshes, SEEK_SET);
|
|
|
|
//fread(imesh, sizeof(IQMMesh)*iqmHeader->num_meshes, 1, iqmFile);
|
|
|
|
//fread(imesh, sizeof(IQMMesh)*iqmHeader->num_meshes, 1, iqmFile);
|
|
|
|
memcpy(imesh, fileDataPtr + iqmHeader->ofs_meshes, iqmHeader->num_meshes*sizeof(IQMMesh));
|
|
|
|
memcpy(imesh, fileDataPtr + iqmHeader->ofs_meshes, iqmHeader->num_meshes*sizeof(IQMMesh));
|
|
|
|
@ -4920,7 +4920,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Triangles data processing
|
|
|
|
// Triangles data processing
|
|
|
|
tri = (IQMTriangle *)RL_MALLOC(iqmHeader->num_triangles*sizeof(IQMTriangle));
|
|
|
|
tri = (IQMTriangle *)RL_CALLOC(iqmHeader->num_triangles, sizeof(IQMTriangle));
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_triangles, SEEK_SET);
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_triangles, SEEK_SET);
|
|
|
|
//fread(tri, sizeof(IQMTriangle), iqmHeader->num_triangles, iqmFile);
|
|
|
|
//fread(tri, sizeof(IQMTriangle), iqmHeader->num_triangles, iqmFile);
|
|
|
|
memcpy(tri, fileDataPtr + iqmHeader->ofs_triangles, iqmHeader->num_triangles*sizeof(IQMTriangle));
|
|
|
|
memcpy(tri, fileDataPtr + iqmHeader->ofs_triangles, iqmHeader->num_triangles*sizeof(IQMTriangle));
|
|
|
|
@ -4942,7 +4942,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Vertex arrays data processing
|
|
|
|
// Vertex arrays data processing
|
|
|
|
va = (IQMVertexArray *)RL_MALLOC(iqmHeader->num_vertexarrays*sizeof(IQMVertexArray));
|
|
|
|
va = (IQMVertexArray *)RL_CALLOC(iqmHeader->num_vertexarrays, sizeof(IQMVertexArray));
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_vertexarrays, SEEK_SET);
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_vertexarrays, SEEK_SET);
|
|
|
|
//fread(va, sizeof(IQMVertexArray), iqmHeader->num_vertexarrays, iqmFile);
|
|
|
|
//fread(va, sizeof(IQMVertexArray), iqmHeader->num_vertexarrays, iqmFile);
|
|
|
|
memcpy(va, fileDataPtr + iqmHeader->ofs_vertexarrays, iqmHeader->num_vertexarrays*sizeof(IQMVertexArray));
|
|
|
|
memcpy(va, fileDataPtr + iqmHeader->ofs_vertexarrays, iqmHeader->num_vertexarrays*sizeof(IQMVertexArray));
|
|
|
|
@ -4953,7 +4953,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case IQM_POSITION:
|
|
|
|
case IQM_POSITION:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
vertex = (float *)RL_MALLOC(iqmHeader->num_vertexes*3*sizeof(float));
|
|
|
|
vertex = (float *)RL_CALLOC(iqmHeader->num_vertexes*3, sizeof(float));
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fread(vertex, iqmHeader->num_vertexes*3*sizeof(float), 1, iqmFile);
|
|
|
|
//fread(vertex, iqmHeader->num_vertexes*3*sizeof(float), 1, iqmFile);
|
|
|
|
memcpy(vertex, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*3*sizeof(float));
|
|
|
|
memcpy(vertex, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*3*sizeof(float));
|
|
|
|
@ -4971,7 +4971,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
case IQM_NORMAL:
|
|
|
|
case IQM_NORMAL:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
normal = (float *)RL_MALLOC(iqmHeader->num_vertexes*3*sizeof(float));
|
|
|
|
normal = (float *)RL_CALLOC(iqmHeader->num_vertexes*3, sizeof(float));
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fread(normal, iqmHeader->num_vertexes*3*sizeof(float), 1, iqmFile);
|
|
|
|
//fread(normal, iqmHeader->num_vertexes*3*sizeof(float), 1, iqmFile);
|
|
|
|
memcpy(normal, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*3*sizeof(float));
|
|
|
|
memcpy(normal, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*3*sizeof(float));
|
|
|
|
@ -4989,7 +4989,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
case IQM_TEXCOORD:
|
|
|
|
case IQM_TEXCOORD:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = (float *)RL_MALLOC(iqmHeader->num_vertexes*2*sizeof(float));
|
|
|
|
text = (float *)RL_CALLOC(iqmHeader->num_vertexes*2, sizeof(float));
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fread(text, iqmHeader->num_vertexes*2*sizeof(float), 1, iqmFile);
|
|
|
|
//fread(text, iqmHeader->num_vertexes*2*sizeof(float), 1, iqmFile);
|
|
|
|
memcpy(text, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*2*sizeof(float));
|
|
|
|
memcpy(text, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*2*sizeof(float));
|
|
|
|
@ -5006,7 +5006,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
case IQM_BLENDINDEXES:
|
|
|
|
case IQM_BLENDINDEXES:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
blendi = (char *)RL_MALLOC(iqmHeader->num_vertexes*4*sizeof(char));
|
|
|
|
blendi = (char *)RL_CALLOC(iqmHeader->num_vertexes*4, sizeof(char));
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fread(blendi, iqmHeader->num_vertexes*4*sizeof(char), 1, iqmFile);
|
|
|
|
//fread(blendi, iqmHeader->num_vertexes*4*sizeof(char), 1, iqmFile);
|
|
|
|
memcpy(blendi, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(char));
|
|
|
|
memcpy(blendi, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(char));
|
|
|
|
@ -5023,7 +5023,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
case IQM_BLENDWEIGHTS:
|
|
|
|
case IQM_BLENDWEIGHTS:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
blendw = (unsigned char *)RL_MALLOC(iqmHeader->num_vertexes*4*sizeof(unsigned char));
|
|
|
|
blendw = (unsigned char *)RL_CALLOC(iqmHeader->num_vertexes*4, sizeof(unsigned char));
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fread(blendw, iqmHeader->num_vertexes*4*sizeof(unsigned char), 1, iqmFile);
|
|
|
|
//fread(blendw, iqmHeader->num_vertexes*4*sizeof(unsigned char), 1, iqmFile);
|
|
|
|
memcpy(blendw, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(unsigned char));
|
|
|
|
memcpy(blendw, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(unsigned char));
|
|
|
|
@ -5040,7 +5040,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
case IQM_COLOR:
|
|
|
|
case IQM_COLOR:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
color = (unsigned char *)RL_MALLOC(iqmHeader->num_vertexes*4*sizeof(unsigned char));
|
|
|
|
color = (unsigned char *)RL_CALLOC(iqmHeader->num_vertexes*4, sizeof(unsigned char));
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fseek(iqmFile, va[a].offset, SEEK_SET);
|
|
|
|
//fread(blendw, iqmHeader->num_vertexes*4*sizeof(unsigned char), 1, iqmFile);
|
|
|
|
//fread(blendw, iqmHeader->num_vertexes*4*sizeof(unsigned char), 1, iqmFile);
|
|
|
|
memcpy(color, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(unsigned char));
|
|
|
|
memcpy(color, fileDataPtr + va[i].offset, iqmHeader->num_vertexes*4*sizeof(unsigned char));
|
|
|
|
@ -5061,7 +5061,7 @@ static Model LoadIQM(const char *fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Bones (joints) data processing
|
|
|
|
// Bones (joints) data processing
|
|
|
|
ijoint = (IQMJoint *)RL_MALLOC(iqmHeader->num_joints*sizeof(IQMJoint));
|
|
|
|
ijoint = (IQMJoint *)RL_CALLOC(iqmHeader->num_joints, sizeof(IQMJoint));
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_joints, SEEK_SET);
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_joints, SEEK_SET);
|
|
|
|
//fread(ijoint, sizeof(IQMJoint), iqmHeader->num_joints, iqmFile);
|
|
|
|
//fread(ijoint, sizeof(IQMJoint), iqmHeader->num_joints, iqmFile);
|
|
|
|
memcpy(ijoint, fileDataPtr + iqmHeader->ofs_joints, iqmHeader->num_joints*sizeof(IQMJoint));
|
|
|
|
memcpy(ijoint, fileDataPtr + iqmHeader->ofs_joints, iqmHeader->num_joints*sizeof(IQMJoint));
|
|
|
|
@ -5184,14 +5184,14 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, int *animCou
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get bones data
|
|
|
|
// Get bones data
|
|
|
|
IQMPose *poses = (IQMPose *)RL_MALLOC(iqmHeader->num_poses*sizeof(IQMPose));
|
|
|
|
IQMPose *poses = (IQMPose *)RL_CALLOC(iqmHeader->num_poses, sizeof(IQMPose));
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_poses, SEEK_SET);
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_poses, SEEK_SET);
|
|
|
|
//fread(poses, sizeof(IQMPose), iqmHeader->num_poses, iqmFile);
|
|
|
|
//fread(poses, sizeof(IQMPose), iqmHeader->num_poses, iqmFile);
|
|
|
|
memcpy(poses, fileDataPtr + iqmHeader->ofs_poses, iqmHeader->num_poses*sizeof(IQMPose));
|
|
|
|
memcpy(poses, fileDataPtr + iqmHeader->ofs_poses, iqmHeader->num_poses*sizeof(IQMPose));
|
|
|
|
|
|
|
|
|
|
|
|
// Get animations data
|
|
|
|
// Get animations data
|
|
|
|
*animCount = iqmHeader->num_anims;
|
|
|
|
*animCount = iqmHeader->num_anims;
|
|
|
|
IQMAnim *anim = (IQMAnim *)RL_MALLOC(iqmHeader->num_anims*sizeof(IQMAnim));
|
|
|
|
IQMAnim *anim = (IQMAnim *)RL_CALLOC(iqmHeader->num_anims, sizeof(IQMAnim));
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_anims, SEEK_SET);
|
|
|
|
//fseek(iqmFile, iqmHeader->ofs_anims, SEEK_SET);
|
|
|
|
//fread(anim, sizeof(IQMAnim), iqmHeader->num_anims, iqmFile);
|
|
|
|
//fread(anim, sizeof(IQMAnim), iqmHeader->num_anims, iqmFile);
|
|
|
|
memcpy(anim, fileDataPtr + iqmHeader->ofs_anims, iqmHeader->num_anims*sizeof(IQMAnim));
|
|
|
|
memcpy(anim, fileDataPtr + iqmHeader->ofs_anims, iqmHeader->num_anims*sizeof(IQMAnim));
|
|
|
|
@ -5231,7 +5231,7 @@ static ModelAnimation *LoadModelAnimationsIQM(const char *fileName, int *animCou
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int j = 0; j < anim[a].num_frames; j++)
|
|
|
|
for (unsigned int j = 0; j < anim[a].num_frames; j++)
|
|
|
|
animations[a].keyframePoses[j] = (Transform *)RL_MALLOC(iqmHeader->num_poses*sizeof(Transform));
|
|
|
|
animations[a].keyframePoses[j] = (Transform *)RL_CALLOC(iqmHeader->num_poses, sizeof(Transform));
|
|
|
|
|
|
|
|
|
|
|
|
int dcounter = anim[a].first_frame*iqmHeader->num_framechannels;
|
|
|
|
int dcounter = anim[a].first_frame*iqmHeader->num_framechannels;
|
|
|
|
|
|
|
|
|
|
|
|
@ -5424,7 +5424,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((cgltfImage->buffer_view != NULL) && (cgltfImage->buffer_view->buffer->data != NULL)) // Check if image is provided as data buffer
|
|
|
|
else if ((cgltfImage->buffer_view != NULL) && (cgltfImage->buffer_view->buffer->data != NULL)) // Check if image is provided as data buffer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned char *data = (unsigned char *)RL_MALLOC(cgltfImage->buffer_view->size);
|
|
|
|
unsigned char *data = (unsigned char *)RL_CALLOC(cgltfImage->buffer_view->size, sizeof(unsigned char));
|
|
|
|
int offset = (int)cgltfImage->buffer_view->offset;
|
|
|
|
int offset = (int)cgltfImage->buffer_view->offset;
|
|
|
|
int stride = (int)cgltfImage->buffer_view->stride? (int)cgltfImage->buffer_view->stride : 1;
|
|
|
|
int stride = (int)cgltfImage->buffer_view->stride? (int)cgltfImage->buffer_view->stride : 1;
|
|
|
|
|
|
|
|
|
|
|
|
@ -5647,8 +5647,8 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
Image imMetallic = { 0 };
|
|
|
|
Image imMetallic = { 0 };
|
|
|
|
Image imRoughness = { 0 };
|
|
|
|
Image imRoughness = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
imMetallic.data = RL_MALLOC(imMetallicRoughness.width*imMetallicRoughness.height);
|
|
|
|
imMetallic.data = RL_CALLOC(imMetallicRoughness.width*imMetallicRoughness.height, 1);
|
|
|
|
imRoughness.data = RL_MALLOC(imMetallicRoughness.width*imMetallicRoughness.height);
|
|
|
|
imRoughness.data = RL_CALLOC(imMetallicRoughness.width*imMetallicRoughness.height, 1);
|
|
|
|
|
|
|
|
|
|
|
|
imMetallic.width = imRoughness.width = imMetallicRoughness.width;
|
|
|
|
imMetallic.width = imRoughness.width = imMetallicRoughness.width;
|
|
|
|
imMetallic.height = imRoughness.height = imMetallicRoughness.height;
|
|
|
|
imMetallic.height = imRoughness.height = imMetallicRoughness.height;
|
|
|
|
@ -5782,7 +5782,7 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh vertices to copy glTF attribute data
|
|
|
|
// Init raylib mesh vertices to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].vertexCount = (int)attribute->count;
|
|
|
|
model.meshes[meshIndex].vertexCount = (int)attribute->count;
|
|
|
|
model.meshes[meshIndex].vertices = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
|
|
|
|
model.meshes[meshIndex].vertices = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load 3 components of float data type into mesh.vertices
|
|
|
|
// Load 3 components of float data type into mesh.vertices
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, float, model.meshes[meshIndex].vertices)
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, float, model.meshes[meshIndex].vertices)
|
|
|
|
@ -5801,10 +5801,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh vertices to copy glTF attribute data
|
|
|
|
// Init raylib mesh vertices to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].vertexCount = (int)attribute->count;
|
|
|
|
model.meshes[meshIndex].vertexCount = (int)attribute->count;
|
|
|
|
model.meshes[meshIndex].vertices = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
|
|
|
|
model.meshes[meshIndex].vertices = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*3*sizeof(unsigned short));
|
|
|
|
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*3, sizeof(unsigned short));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, unsigned short, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, unsigned short, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib vertex data type (float) the matrix will scale it to the correct size as a float
|
|
|
|
// Convert data to raylib vertex data type (float) the matrix will scale it to the correct size as a float
|
|
|
|
@ -5826,10 +5826,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh vertices to copy glTF attribute data
|
|
|
|
// Init raylib mesh vertices to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].vertexCount = (int)attribute->count;
|
|
|
|
model.meshes[meshIndex].vertexCount = (int)attribute->count;
|
|
|
|
model.meshes[meshIndex].vertices = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
|
|
|
|
model.meshes[meshIndex].vertices = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
short *temp = (short *)RL_MALLOC(attribute->count*3*sizeof(short));
|
|
|
|
short *temp = (short *)RL_CALLOC(attribute->count*3, sizeof(short));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, short, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, short, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib vertex data type (float) the matrix will scale it to the correct size as a float
|
|
|
|
// Convert data to raylib vertex data type (float) the matrix will scale it to the correct size as a float
|
|
|
|
@ -5860,7 +5860,7 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_32f))
|
|
|
|
if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_32f))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh normals to copy glTF attribute data
|
|
|
|
// Init raylib mesh normals to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
|
|
|
|
model.meshes[meshIndex].normals = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load 3 components of float data type into mesh.normals
|
|
|
|
// Load 3 components of float data type into mesh.normals
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, float, model.meshes[meshIndex].normals)
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, float, model.meshes[meshIndex].normals)
|
|
|
|
@ -5878,10 +5878,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_16))
|
|
|
|
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_16))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh normals to copy glTF attribute data
|
|
|
|
// Init raylib mesh normals to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
|
|
|
|
model.meshes[meshIndex].normals = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
short *temp = (short *)RL_MALLOC(attribute->count*3*sizeof(short));
|
|
|
|
short *temp = (short *)RL_CALLOC(attribute->count*3, sizeof(short));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, short, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, short, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib normal data type (float)
|
|
|
|
// Convert data to raylib normal data type (float)
|
|
|
|
@ -5902,10 +5902,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_8u))
|
|
|
|
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_8u))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh normals to copy glTF attribute data
|
|
|
|
// Init raylib mesh normals to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
|
|
|
|
model.meshes[meshIndex].normals = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*3*sizeof(unsigned char));
|
|
|
|
unsigned char *temp = (unsigned char *)RL_CALLOC(attribute->count*3, sizeof(unsigned char));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, unsigned char, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, unsigned char, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib normal data type (float)
|
|
|
|
// Convert data to raylib normal data type (float)
|
|
|
|
@ -5926,10 +5926,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_8))
|
|
|
|
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_8))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh normals to copy glTF attribute data
|
|
|
|
// Init raylib mesh normals to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
|
|
|
|
model.meshes[meshIndex].normals = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
char *temp = (char *)RL_MALLOC(attribute->count*3*sizeof(char));
|
|
|
|
char *temp = (char *)RL_CALLOC(attribute->count*3, sizeof(char));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, char, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, char, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib normal data type (float)
|
|
|
|
// Convert data to raylib normal data type (float)
|
|
|
|
@ -5960,7 +5960,7 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
if ((attribute->type == cgltf_type_vec4) && (attribute->component_type == cgltf_component_type_r_32f))
|
|
|
|
if ((attribute->type == cgltf_type_vec4) && (attribute->component_type == cgltf_component_type_r_32f))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh tangent to copy glTF attribute data
|
|
|
|
// Init raylib mesh tangent to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].tangents = (float *)RL_MALLOC(attribute->count*4*sizeof(float));
|
|
|
|
model.meshes[meshIndex].tangents = (float *)RL_CALLOC(attribute->count*4, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load 4 components of float data type into mesh.tangents
|
|
|
|
// Load 4 components of float data type into mesh.tangents
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, float, model.meshes[meshIndex].tangents)
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, float, model.meshes[meshIndex].tangents)
|
|
|
|
@ -5990,7 +5990,7 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
if (attribute->component_type == cgltf_component_type_r_32f) // vec2, float
|
|
|
|
if (attribute->component_type == cgltf_component_type_r_32f) // vec2, float
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data
|
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data
|
|
|
|
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
|
|
|
|
texcoordPtr = (float *)RL_CALLOC(attribute->count*2, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load 3 components of float data type into mesh.texcoords
|
|
|
|
// Load 3 components of float data type into mesh.texcoords
|
|
|
|
LOAD_ATTRIBUTE(attribute, 2, float, texcoordPtr)
|
|
|
|
LOAD_ATTRIBUTE(attribute, 2, float, texcoordPtr)
|
|
|
|
@ -5998,10 +5998,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_8u) // vec2, u8n
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_8u) // vec2, u8n
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data
|
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data
|
|
|
|
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
|
|
|
|
texcoordPtr = (float *)RL_CALLOC(attribute->count*2, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*2*sizeof(unsigned char));
|
|
|
|
unsigned char *temp = (unsigned char *)RL_CALLOC(attribute->count*2, sizeof(unsigned char));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 2, unsigned char, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 2, unsigned char, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib texcoord data type (float)
|
|
|
|
// Convert data to raylib texcoord data type (float)
|
|
|
|
@ -6012,10 +6012,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_16u) // vec2, u16n
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_16u) // vec2, u16n
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data
|
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data
|
|
|
|
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
|
|
|
|
texcoordPtr = (float *)RL_CALLOC(attribute->count*2, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*2*sizeof(unsigned short));
|
|
|
|
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*2, sizeof(unsigned short));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 2, unsigned short, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 2, unsigned short, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib texcoord data type (float)
|
|
|
|
// Convert data to raylib texcoord data type (float)
|
|
|
|
@ -6050,10 +6050,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
if (attribute->component_type == cgltf_component_type_r_8u)
|
|
|
|
if (attribute->component_type == cgltf_component_type_r_8u)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*3*sizeof(unsigned char));
|
|
|
|
unsigned char *temp = (unsigned char *)RL_CALLOC(attribute->count*3, sizeof(unsigned char));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, unsigned char, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, unsigned char, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib color data type (4 bytes)
|
|
|
|
// Convert data to raylib color data type (4 bytes)
|
|
|
|
@ -6070,10 +6070,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_16u)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_16u)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*3*sizeof(unsigned short));
|
|
|
|
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*3, sizeof(unsigned short));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, unsigned short, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, unsigned short, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib color data type (4 bytes)
|
|
|
|
// Convert data to raylib color data type (4 bytes)
|
|
|
|
@ -6090,10 +6090,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_32f)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_32f)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
float *temp = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
|
|
|
|
float *temp = (float *)RL_CALLOC(attribute->count*3, sizeof(float));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, float, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 3, float, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib color data type (4 bytes)
|
|
|
|
// Convert data to raylib color data type (4 bytes)
|
|
|
|
@ -6114,7 +6114,7 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
if (attribute->component_type == cgltf_component_type_r_8u)
|
|
|
|
if (attribute->component_type == cgltf_component_type_r_8u)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
|
|
|
|
|
|
|
|
|
|
|
|
// Load 4 components of unsigned char data type into mesh.colors
|
|
|
|
// Load 4 components of unsigned char data type into mesh.colors
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, unsigned char, model.meshes[meshIndex].colors)
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, unsigned char, model.meshes[meshIndex].colors)
|
|
|
|
@ -6122,10 +6122,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_16u)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_16u)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*4*sizeof(unsigned short));
|
|
|
|
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*4, sizeof(unsigned short));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib color data type (4 bytes)
|
|
|
|
// Convert data to raylib color data type (4 bytes)
|
|
|
|
@ -6136,10 +6136,10 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_32f)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_32f)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
// Init raylib mesh color to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
|
|
|
|
model.meshes[meshIndex].colors = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
float *temp = (float *)RL_MALLOC(attribute->count*4*sizeof(float));
|
|
|
|
float *temp = (float *)RL_CALLOC(attribute->count*4, sizeof(float));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, float, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, float, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib color data type (4 bytes), color data must be normalized
|
|
|
|
// Convert data to raylib color data type (4 bytes), color data must be normalized
|
|
|
|
@ -6169,7 +6169,7 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
if (attribute->component_type == cgltf_component_type_r_16u)
|
|
|
|
if (attribute->component_type == cgltf_component_type_r_16u)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh indices to copy glTF attribute data
|
|
|
|
// Init raylib mesh indices to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].indices = (unsigned short *)RL_MALLOC(attribute->count*sizeof(unsigned short));
|
|
|
|
model.meshes[meshIndex].indices = (unsigned short *)RL_CALLOC(attribute->count, sizeof(unsigned short));
|
|
|
|
|
|
|
|
|
|
|
|
// Load unsigned short data type into mesh.indices
|
|
|
|
// Load unsigned short data type into mesh.indices
|
|
|
|
LOAD_ATTRIBUTE(attribute, 1, unsigned short, model.meshes[meshIndex].indices)
|
|
|
|
LOAD_ATTRIBUTE(attribute, 1, unsigned short, model.meshes[meshIndex].indices)
|
|
|
|
@ -6177,14 +6177,14 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_8u)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_8u)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh indices to copy glTF attribute data
|
|
|
|
// Init raylib mesh indices to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].indices = (unsigned short *)RL_MALLOC(attribute->count*sizeof(unsigned short));
|
|
|
|
model.meshes[meshIndex].indices = (unsigned short *)RL_CALLOC(attribute->count, sizeof(unsigned short));
|
|
|
|
LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned char, model.meshes[meshIndex].indices, unsigned short)
|
|
|
|
LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned char, model.meshes[meshIndex].indices, unsigned short)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_32u)
|
|
|
|
else if (attribute->component_type == cgltf_component_type_r_32u)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Init raylib mesh indices to copy glTF attribute data
|
|
|
|
// Init raylib mesh indices to copy glTF attribute data
|
|
|
|
model.meshes[meshIndex].indices = (unsigned short *)RL_MALLOC(attribute->count*sizeof(unsigned short));
|
|
|
|
model.meshes[meshIndex].indices = (unsigned short *)RL_CALLOC(attribute->count, sizeof(unsigned short));
|
|
|
|
LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned int, model.meshes[meshIndex].indices, unsigned short);
|
|
|
|
LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned int, model.meshes[meshIndex].indices, unsigned short);
|
|
|
|
|
|
|
|
|
|
|
|
TRACELOG(LOG_WARNING, "MODEL: [%s] Indices data converted from u32 to u16, possible loss of data", fileName);
|
|
|
|
TRACELOG(LOG_WARNING, "MODEL: [%s] Indices data converted from u32 to u16, possible loss of data", fileName);
|
|
|
|
@ -6350,7 +6350,7 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
model.meshes[meshIndex].boneWeights = (float *)RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(float));
|
|
|
|
model.meshes[meshIndex].boneWeights = (float *)RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*4*sizeof(unsigned char));
|
|
|
|
unsigned char *temp = (unsigned char *)RL_CALLOC(attribute->count*4, sizeof(unsigned char));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, unsigned char, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, unsigned char, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib bone weight data type (4 bytes)
|
|
|
|
// Convert data to raylib bone weight data type (4 bytes)
|
|
|
|
@ -6364,7 +6364,7 @@ static Model LoadGLTF(const char *fileName)
|
|
|
|
model.meshes[meshIndex].boneWeights = (float *)RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(float));
|
|
|
|
model.meshes[meshIndex].boneWeights = (float *)RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type
|
|
|
|
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*4*sizeof(unsigned short));
|
|
|
|
unsigned short *temp = (unsigned short *)RL_CALLOC(attribute->count*4, sizeof(unsigned short));
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp);
|
|
|
|
LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert data to raylib bone weight data type
|
|
|
|
// Convert data to raylib bone weight data type
|
|
|
|
@ -6642,7 +6642,7 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
|
|
|
|
// store bone offsets on dummy parent nodes rather than on the
|
|
|
|
// store bone offsets on dummy parent nodes rather than on the
|
|
|
|
// joints themselves. Depends only on the skin, not the animation.
|
|
|
|
// joints themselves. Depends only on the skin, not the animation.
|
|
|
|
int jointCount = (int)skin.joints_count;
|
|
|
|
int jointCount = (int)skin.joints_count;
|
|
|
|
Matrix *extOffset = (Matrix *)RL_MALLOC(jointCount*sizeof(Matrix));
|
|
|
|
Matrix *extOffset = (Matrix *)RL_CALLOC(jointCount, sizeof(Matrix));
|
|
|
|
|
|
|
|
|
|
|
|
if (extOffset == NULL)
|
|
|
|
if (extOffset == NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -6721,28 +6721,15 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
|
|
|
|
|
|
|
|
|
|
|
|
if (animData.channels[j].sampler->interpolation != cgltf_interpolation_type_max_enum)
|
|
|
|
if (animData.channels[j].sampler->interpolation != cgltf_interpolation_type_max_enum)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (channel.target_path == cgltf_animation_path_type_translation)
|
|
|
|
if (channel.target_path == cgltf_animation_path_type_translation) boneChannels[boneIndex].translate = &animData.channels[j];
|
|
|
|
{
|
|
|
|
else if (channel.target_path == cgltf_animation_path_type_rotation) boneChannels[boneIndex].rotate = &animData.channels[j];
|
|
|
|
boneChannels[boneIndex].translate = &animData.channels[j];
|
|
|
|
else if (channel.target_path == cgltf_animation_path_type_scale) boneChannels[boneIndex].scale = &animData.channels[j];
|
|
|
|
}
|
|
|
|
else TRACELOG(LOG_WARNING, "MODEL: [%s] Unsupported target_path on channel %d's sampler for animation %d. Skipping.", fileName, j, a);
|
|
|
|
else if (channel.target_path == cgltf_animation_path_type_rotation)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
boneChannels[boneIndex].rotate = &animData.channels[j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (channel.target_path == cgltf_animation_path_type_scale)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
boneChannels[boneIndex].scale = &animData.channels[j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TRACELOG(LOG_WARNING, "MODEL: [%s] Unsupported target_path on channel %d's sampler for animation %d. Skipping.", fileName, j, a);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else TRACELOG(LOG_WARNING, "MODEL: [%s] Invalid interpolation curve encountered for GLTF animation.", fileName);
|
|
|
|
else TRACELOG(LOG_WARNING, "MODEL: [%s] Invalid interpolation curve encountered for GLTF animation.", fileName);
|
|
|
|
|
|
|
|
|
|
|
|
float time = 0.0f;
|
|
|
|
float time = 0.0f;
|
|
|
|
cgltf_bool result = cgltf_accessor_read_float(channel.sampler->input, channel.sampler->input->count - 1, &time, 1);
|
|
|
|
result = cgltf_accessor_read_float(channel.sampler->input, channel.sampler->input->count - 1, &time, 1);
|
|
|
|
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to load input time", fileName);
|
|
|
|
TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to load input time", fileName);
|
|
|
|
@ -6894,8 +6881,6 @@ static Model LoadVOX(const char *fileName)
|
|
|
|
|
|
|
|
|
|
|
|
unsigned short *pindices = voxarray.indices.array; // 5461*6*6 = 196596 indices max per mesh
|
|
|
|
unsigned short *pindices = voxarray.indices.array; // 5461*6*6 = 196596 indices max per mesh
|
|
|
|
|
|
|
|
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < meshescount; i++)
|
|
|
|
for (int i = 0; i < meshescount; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Mesh *pmesh = &model.meshes[i];
|
|
|
|
Mesh *pmesh = &model.meshes[i];
|
|
|
|
@ -6904,25 +6889,22 @@ static Model LoadVOX(const char *fileName)
|
|
|
|
// Copy vertices
|
|
|
|
// Copy vertices
|
|
|
|
pmesh->vertexCount = (int)fmin(verticesMax, verticesRemain);
|
|
|
|
pmesh->vertexCount = (int)fmin(verticesMax, verticesRemain);
|
|
|
|
|
|
|
|
|
|
|
|
size = pmesh->vertexCount*sizeof(float)*3;
|
|
|
|
pmesh->vertices = (float *)RL_CALLOC(pmesh->vertexCount*3, sizeof(float));
|
|
|
|
pmesh->vertices = (float *)RL_MALLOC(size);
|
|
|
|
memcpy(pmesh->vertices, pvertices, pmesh->vertexCount*3*sizeof(float));
|
|
|
|
memcpy(pmesh->vertices, pvertices, size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy normals
|
|
|
|
// Copy normals
|
|
|
|
pmesh->normals = (float *)RL_MALLOC(size);
|
|
|
|
pmesh->normals = (float *)RL_CALLOC(pmesh->vertexCount*3, sizeof(float));
|
|
|
|
memcpy(pmesh->normals, pnormals, size);
|
|
|
|
memcpy(pmesh->normals, pnormals, pmesh->vertexCount*3*sizeof(float));
|
|
|
|
|
|
|
|
|
|
|
|
// Copy indices
|
|
|
|
// Copy indices
|
|
|
|
size = voxarray.indices.used*sizeof(unsigned short);
|
|
|
|
pmesh->indices = (unsigned short *)RL_CALLOC(voxarray.indices.used, sizeof(unsigned short));
|
|
|
|
pmesh->indices = (unsigned short *)RL_MALLOC(size);
|
|
|
|
memcpy(pmesh->indices, pindices, voxarray.indices.used*sizeof(unsigned short));
|
|
|
|
memcpy(pmesh->indices, pindices, size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pmesh->triangleCount = (pmesh->vertexCount/4)*2;
|
|
|
|
pmesh->triangleCount = (pmesh->vertexCount/4)*2;
|
|
|
|
|
|
|
|
|
|
|
|
// Copy colors
|
|
|
|
// Copy colors
|
|
|
|
size = pmesh->vertexCount*sizeof(Color);
|
|
|
|
pmesh->colors = (unsigned char *)RL_CALLOC(pmesh->vertexCount*4, sizeof(unsigned char));
|
|
|
|
pmesh->colors = (unsigned char *)RL_MALLOC(size);
|
|
|
|
memcpy(pmesh->colors, pcolors, pmesh->vertexCount*4*sizeof(unsigned char));
|
|
|
|
memcpy(pmesh->colors, pcolors, size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// First material index
|
|
|
|
// First material index
|
|
|
|
model.meshMaterial[i] = 0;
|
|
|
|
model.meshMaterial[i] = 0;
|
|
|
|
|