Changed: Use VSCode auto-formatter.
This commit is contained in:
@@ -72,71 +72,71 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_
|
|||||||
else if (strcmp(lineHeader, "f") == 0)
|
else if (strcmp(lineHeader, "f") == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
int* x;
|
int *x;
|
||||||
fpos_t start;
|
fpos_t start;
|
||||||
fgetpos(file,&start);
|
fgetpos(file, &start);
|
||||||
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n",x,x,x,x,x,x,x,x,x);
|
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", x, x, x, x, x, x, x, x, x);
|
||||||
fsetpos(file,&start);
|
fsetpos(file, &start);
|
||||||
int newerMatches =0;
|
int newerMatches = 0;
|
||||||
|
|
||||||
switch(matches)
|
switch (matches)
|
||||||
{
|
{
|
||||||
/* Vs, VTs and VNs all set */
|
/* Vs, VTs and VNs all set */
|
||||||
case 9:
|
case 9:
|
||||||
|
{
|
||||||
|
fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n",
|
||||||
|
&vertexIndex[0], &coordIndex[0], &normalIndex[0],
|
||||||
|
&vertexIndex[1], &coordIndex[1], &normalIndex[1],
|
||||||
|
&vertexIndex[2], &coordIndex[2], &normalIndex[2]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* Loaded only two digits (V, VT) succesfuly. Not setting VN. */
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n",
|
||||||
|
&vertexIndex[0], &coordIndex[0],
|
||||||
|
&vertexIndex[1], &coordIndex[1],
|
||||||
|
&vertexIndex[2], &coordIndex[2]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* Only V set. Checking for existance of VT or VN. */
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
/* Check for existance of V/// configuration.. */
|
||||||
|
newerMatches = fscanf(file, "%d/// %d/// %d///\n", x, x, x);
|
||||||
|
fsetpos(file, &start);
|
||||||
|
if (newerMatches == 3)
|
||||||
{
|
{
|
||||||
fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n",
|
/* Configuration confirmed. */
|
||||||
&vertexIndex[0], &coordIndex[0], &normalIndex[0],
|
fscanf(file, "%d/// %d/// %d///\n", &vertexIndex[0], &vertexIndex[1], &vertexIndex[2]);
|
||||||
&vertexIndex[1], &coordIndex[1], &normalIndex[1],
|
|
||||||
&vertexIndex[2], &coordIndex[2], &normalIndex[2]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
else
|
||||||
/* Loaded only two digits (V, VT) succesfuly. Not setting VN. */
|
|
||||||
case 2:
|
|
||||||
{
|
{
|
||||||
fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n",
|
/* Failed, checking configuration V//VN */
|
||||||
&vertexIndex[0], &coordIndex[0],
|
newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", x, x, x, x, x, x);
|
||||||
&vertexIndex[1], &coordIndex[1],
|
fsetpos(file, &start);
|
||||||
&vertexIndex[2], &coordIndex[2]);
|
if (newerMatches == 6)
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
/* Only V set. Checking for existance of VT or VN. */
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
/* Check for existance of V/// configuration.. */
|
|
||||||
newerMatches = fscanf(file, "%d/// %d/// %d///\n",x,x,x);
|
|
||||||
fsetpos(file,&start);
|
|
||||||
if(newerMatches==3){
|
|
||||||
/* Configuration confirmed. */
|
|
||||||
fscanf(file, "%d/// %d/// %d///\n",&vertexIndex[0],&vertexIndex[1],&vertexIndex[2]);
|
|
||||||
|
|
||||||
}else
|
|
||||||
{
|
{
|
||||||
/* Failed, checking configuration V//VN */
|
/* Configuration confirmed. */
|
||||||
newerMatches = fscanf(file, "%d//%d %d//%d %d//%d",x,x,x,x,x,x);
|
newerMatches = fscanf(file, "%d//%d %d//%d %d//%d",
|
||||||
fsetpos(file,&start);
|
&vertexIndex[0], &normalIndex[0],
|
||||||
if(newerMatches==6){
|
&vertexIndex[1], &normalIndex[1],
|
||||||
/* Configuration confirmed. */
|
&vertexIndex[2], &normalIndex[2]);
|
||||||
newerMatches = fscanf(file, "%d//%d %d//%d %d//%d",
|
}
|
||||||
&vertexIndex[0], &normalIndex[0],
|
else
|
||||||
&vertexIndex[1], &normalIndex[1],
|
{
|
||||||
&vertexIndex[2], &normalIndex[2]);
|
/*Unknown configuration.*/
|
||||||
}
|
PRINT_ERR("Unknown .obj face for .obj file!");
|
||||||
else{
|
printf("Obj file mentioned: \"%s\"\n", path);
|
||||||
/*Unknown configuration.*/
|
|
||||||
PRINT_ERR("Unknown .obj face for .obj file!");
|
|
||||||
printf("Obj file mentioned: \"%s\"\n",path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
PRINT_ERR("Unknown faces format in .obj file!");
|
|
||||||
printf(" \"%s\"\n",path);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/* if(ferror(file))
|
default:
|
||||||
|
PRINT_ERR("Unknown faces format in .obj file!");
|
||||||
|
printf(" \"%s\"\n", path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* if(ferror(file))
|
||||||
PRINT_ERR("Failed to load .obj file \"%s\".");
|
PRINT_ERR("Failed to load .obj file \"%s\".");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -147,64 +147,61 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_
|
|||||||
//if(fscanf
|
//if(fscanf
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
switch(matches)
|
switch (matches)
|
||||||
{
|
{
|
||||||
case 9:
|
case 9:
|
||||||
|
{
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1);
|
||||||
|
|
||||||
|
o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1);
|
||||||
|
|
||||||
|
o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1);
|
||||||
|
faceI += 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1);
|
||||||
|
|
||||||
|
o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (newerMatches == 3)
|
||||||
|
{
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1);
|
||||||
|
o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1);
|
||||||
|
}
|
||||||
|
else if (newerMatches == 6)
|
||||||
{
|
{
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1);
|
o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1);
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1);
|
o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1);
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1);
|
o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1);
|
||||||
|
|
||||||
o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1);
|
|
||||||
|
|
||||||
o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1);
|
o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1);
|
||||||
o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1);
|
o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1);
|
||||||
o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1);
|
o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1);
|
||||||
faceI += 3;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 2:
|
break;
|
||||||
{
|
}
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1);
|
|
||||||
|
|
||||||
o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
if(newerMatches==3)
|
|
||||||
{
|
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1);
|
|
||||||
}
|
|
||||||
else if(newerMatches==6)
|
|
||||||
{
|
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1);
|
|
||||||
|
|
||||||
o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1);
|
|
||||||
o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
o_result->calculateBoundingBoxes();
|
o_result->calculateBoundingBoxes();
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|||||||
Reference in New Issue
Block a user