Buildbot fixes (changed byte types to char; mixed d&c)

This commit is contained in:
mazmazz 2018-12-18 19:31:30 -05:00
parent 3dbda54d3c
commit 6b2f4b5858
5 changed files with 197 additions and 127 deletions

View file

@ -17,7 +17,7 @@
#define NUMVERTEXNORMALS 162
// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and
// Quake 2 normals are indexed. Use avertexnormals[normalindex][x/y/z] and
// you'll have your normals.
float avertexnormals[NUMVERTEXNORMALS][3] = {
{-0.525731f, 0.000000f, 0.850651f},
@ -195,9 +195,9 @@ typedef struct
int numXYZ; // Number of vertices in each frame
int numST; // Number of texture coordinates in each frame.
int numTris; // Number of triangles in each frame
int numGLcmds; // Number of dwords (4 bytes) in the gl command list.
int numGLcmds; // Number of dwords (4 bytes) in the gl command list.
int numFrames; // Number of frames
int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names.
int offsetSkins; // Offset, in bytes from the start of the file, to the list of skin names.
int offsetST; // Offset, in bytes from the start of the file, to the list of texture coordinates
int offsetTris; // Offset, in bytes from the start of the file, to the list of triangles
int offsetFrames; // Offset, in bytes from the start of the file, to the list of frames
@ -236,6 +236,20 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
model_t *retModel = NULL;
md2header_t *header;
size_t fileLen;
int i, j, t;
size_t namelen;
char *texturefilename, *buffer;
const char *texPos;
const float WUNITS = 1.0f;
float dataScale;
md2triangle_t *tris;
md2texcoord_t *texcoords;
md2frame_t *frames;
FILE *f = fopen(fileName, "rb");
if (!f)
@ -243,12 +257,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0);
size_t fileLen;
int i, j;
size_t namelen;
char *texturefilename;
const char *texPos = strchr(fileName, '/');
texPos = strchr(fileName, '/');
if (texPos)
{
@ -274,7 +283,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
fseek(f, 0, SEEK_SET);
// read in file
char *buffer = malloc(fileLen);
buffer = malloc(fileLen);
fread(buffer, fileLen, 1, f);
fclose(f);
@ -284,13 +293,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel->numMeshes = 1; // MD2 only has one mesh
retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0);
retModel->meshes[0].numFrames = header->numFrames;
const float WUNITS = 1.0f;
float dataScale = WUNITS;
dataScale = WUNITS;
// Tris and ST are simple structures that can be straight-copied
md2triangle_t *tris = (md2triangle_t*)&buffer[header->offsetTris];
md2texcoord_t *texcoords = (md2texcoord_t*)&buffer[header->offsetST];
md2frame_t *frames = (md2frame_t*)&buffer[header->offsetFrames];
tris = (md2triangle_t*)&buffer[header->offsetTris];
texcoords = (md2texcoord_t*)&buffer[header->offsetST];
frames = (md2frame_t*)&buffer[header->offsetFrames];
// Read in textures
retModel->numMaterials = header->numSkins;
@ -300,7 +309,6 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0);
int t;
for (t = 0; t < retModel->numMaterials; t++)
{
retModel->materials[t].ambient[0] = 0.8f;
@ -327,6 +335,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
if (!systemSucks)
{
// Check for a normal map...??
Resource::resource_t *res
char openfilename[1024];
char normalMapName[1024];
strcpy(normalMapName, texturefilename);
@ -355,7 +364,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
openfilename[k] = '/';
}
Resource::resource_t *res = Resource::Open(openfilename);
res = Resource::Open(openfilename);
if (res)
{
Resource::Close(res);
@ -368,15 +377,24 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
if (!useFloat) // Decompress to MD3 'tinyframe' space
{
char *ptr = (char*)frames;
md2triangle_t *trisPtr;
unsigned short *indexptr;
float *uvptr;
dataScale = 0.015624f; // 1 / 64.0f
retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0);
retModel->meshes[0].numVertices = header->numXYZ;
retModel->meshes[0].uvs = (float*)Z_Malloc (sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0);
byte *ptr = (byte*)frames;
for (i = 0; i < header->numFrames; i++, ptr += header->framesize)
{
short *vertptr;
char *normptr;
//char *tanptr;
md2frame_t *framePtr = (md2frame_t*)ptr;
md2vertex_t *vertex;
retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short)*3*header->numXYZ, ztag, 0);
retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char)*3*header->numXYZ, ztag, 0);
@ -384,14 +402,14 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
// retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag);
retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0);
short *vertptr = retModel->meshes[0].tinyframes[i].vertices;
char *normptr = retModel->meshes[0].tinyframes[i].normals;
vertptr = retModel->meshes[0].tinyframes[i].vertices;
normptr = retModel->meshes[0].tinyframes[i].normals;
// char *tanptr = retModel->meshes[0].tinyframes[i].tangents;
// tanptr = retModel->meshes[0].tinyframes[i].tangents;
retModel->meshes[0].tinyframes[i].material = &retModel->materials[0];
framePtr++; // Advance to vertex list
md2vertex_t *vertex = (md2vertex_t*)framePtr;
vertex = (md2vertex_t*)framePtr;
framePtr--;
for (j = 0; j < header->numXYZ; j++, vertex++)
{
@ -403,16 +421,16 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
vertptr++;
// Normal
*normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][0] * 127);
*normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][1] * 127);
*normptr++ = (byte)(avertexnormals[vertex->lightNormalIndex][2] * 127);
*normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][0] * 127);
*normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][1] * 127);
*normptr++ = (char)(avertexnormals[vertex->lightNormalIndex][2] * 127);
}
}
// This doesn't need to be done every frame!
md2triangle_t *trisPtr = tris;
unsigned short *indexptr = retModel->meshes[0].indices;
float *uvptr = (float*)retModel->meshes[0].uvs;
trisPtr = tris;
indexptr = retModel->meshes[0].indices;
uvptr = (float*)retModel->meshes[0].uvs;
for (j = 0; j < header->numTris; j++, trisPtr++)
{
*indexptr = trisPtr->meshIndex[0];
@ -432,12 +450,14 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
}
else // Full float loading method
{
md2triangle_t *trisPtr = tris;
float *uvptr = retModel->meshes[0].uvs;
char *ptr = (char*)frames;
retModel->meshes[0].numVertices = header->numTris*3;
retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0);
retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float)*2*retModel->meshes[0].numVertices, ztag, 0);
md2triangle_t *trisPtr = tris;
float *uvptr = retModel->meshes[0].uvs;
for (i = 0; i < retModel->meshes[0].numTriangles; i++, trisPtr++)
{
*uvptr++ = texcoords[trisPtr->stIndex[0]].s / (float)header->skinwidth;
@ -448,23 +468,24 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat)
*uvptr++ = (texcoords[trisPtr->stIndex[2]].t / (float)header->skinheight);
}
byte *ptr = (byte*)frames;
for (i = 0; i < header->numFrames; i++, ptr += header->framesize)
{
md2vertex_t *vertex;
md2frame_t *framePtr = (md2frame_t*)ptr;
float *vertptr, *normptr;
retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag, 0);
retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag, 0);
// if (retModel->materials[0].lightmap)
// retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag);
float *vertptr, *normptr;
normptr = (float*)retModel->meshes[0].frames[i].normals;
vertptr = (float*)retModel->meshes[0].frames[i].vertices;
trisPtr = tris;
retModel->meshes[0].frames[i].material = &retModel->materials[0];
framePtr++; // Advance to vertex list
md2vertex_t *vertex = (md2vertex_t*)framePtr;
vertex = (md2vertex_t*)framePtr;
framePtr--;
for (j = 0; j < header->numTris; j++, trisPtr++)
{

View file

@ -146,31 +146,36 @@ static boolean latlnginit = false;
model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
{
const float WUNITS = 1.0f;
model_t *retModel = NULL;
md3modelHeader *mdh;
long fileLen;
char *buffer;
int surfEnd;
int i, t;
int matCount;
FILE *f;
if (!latlnginit)
{
LatLngInit();
latlnginit = true;
}
const float WUNITS = 1.0f;
model_t *retModel = NULL;
FILE *f = fopen(fileName, "rb");
f = fopen(fileName, "rb");
if (!f)
return NULL;
retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0);
md3modelHeader *mdh;
// find length of file
fseek(f, 0, SEEK_END);
long fileLen = ftell(f);
fileLen = ftell(f);
fseek(f, 0, SEEK_SET);
// read in file
char *buffer = malloc(fileLen);
buffer = malloc(fileLen);
fread(buffer, fileLen, 1, f);
fclose(f);
@ -180,8 +185,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel->numMeshes = mdh->numSurfaces;
retModel->numMaterials = 0;
int surfEnd = 0;
int i;
surfEnd = 0;
for (i = 0; i < mdh->numSurfaces; i++)
{
md3Surface *mdS = (md3Surface*)&buffer[mdh->offsetSurfaces];
@ -196,7 +200,6 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0);
int t;
for (t = 0; t < retModel->numMaterials; t++)
{
retModel->materials[t].ambient[0] = 0.3686f;
@ -221,14 +224,16 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, 0);
int matCount = 0;
matCount = 0;
for (i = 0, surfEnd = 0; i < mdh->numSurfaces; i++)
{
int j;
md3Shader *mdShader;
md3Surface *mdS = (md3Surface*)&buffer[mdh->offsetSurfaces + surfEnd];
surfEnd += mdS->offsetEnd;
md3Shader *mdShader = (md3Shader*)((char*)mdS + mdS->offsetShaders);
int j;
mdShader = (md3Shader*)((char*)mdS + mdS->offsetShaders);
for (j = 0; j < mdS->numShaders; j++, matCount++)
{
size_t len = strlen(mdShader[j].name);
@ -285,11 +290,20 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
if (!useFloat) // 'tinyframe' mode with indices
{
float tempNormal[3];
float *uvptr;
md3TexCoord *mdST;
unsigned short *indexptr;
md3Triangle *mdT;
retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, 0);
retModel->meshes[i].numVertices = mdS->numVerts;
retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, 0);
for (j = 0; j < mdS->numFrames; j++)
{
short *vertptr;
char *normptr;
// char *tanptr;
int k;
md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex)));
retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, 0);
retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, 0);
@ -297,13 +311,12 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
// if (retModel->materials[0].lightmap)
// retModel->meshes[i].tinyframes[j].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag);
retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, 0);
short *vertptr = retModel->meshes[i].tinyframes[j].vertices;
char *normptr = retModel->meshes[i].tinyframes[j].normals;
vertptr = retModel->meshes[i].tinyframes[j].vertices;
normptr = retModel->meshes[i].tinyframes[j].normals;
// char *tanptr = retModel->meshes[i].tinyframes[j].tangents;
// tanptr = retModel->meshes[i].tinyframes[j].tangents;
retModel->meshes[i].tinyframes[j].material = &retModel->materials[i];
int k;
for (k = 0; k < mdS->numVerts; k++)
{
// Vertex
@ -316,17 +329,17 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
// Normal
GetNormalFromLatLong(mdV[k].n, tempNormal);
*normptr = (byte)(tempNormal[0] * 127);
*normptr = (char)(tempNormal[0] * 127);
normptr++;
*normptr = (byte)(tempNormal[2] * 127);
*normptr = (char)(tempNormal[2] * 127);
normptr++;
*normptr = (byte)(tempNormal[1] * 127);
*normptr = (char)(tempNormal[1] * 127);
normptr++;
}
}
float *uvptr = (float*)retModel->meshes[i].uvs;
md3TexCoord *mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST);
uvptr = (float*)retModel->meshes[i].uvs;
mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST);
for (j = 0; j < mdS->numVerts; j++)
{
*uvptr = mdST[j].st[0];
@ -335,8 +348,8 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
uvptr++;
}
unsigned short *indexptr = retModel->meshes[i].indices;
md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles);
indexptr = retModel->meshes[i].indices;
mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles);
for (j = 0; j < mdS->numTriangles; j++, mdT++)
{
// Indices
@ -350,25 +363,31 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
}
else // Traditional full-float loading method
{
retModel->meshes[i].numVertices = mdS->numTriangles * 3;//mdS->numVerts;
float dataScale = 0.015624f * WUNITS;
float tempNormal[3];
md3TexCoord *mdST;
md3Triangle *mdT;
float *uvptr;
int k;
retModel->meshes[i].numVertices = mdS->numTriangles * 3;//mdS->numVerts;
retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, 0);
retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, 0);
for (j = 0; j < mdS->numFrames; j++)
{
float *vertptr;
float *normptr;
md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex)));
retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0);
retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0);
// if (retModel->materials[i].lightmap)
// retModel->meshes[i].frames[j].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag);
float *vertptr = retModel->meshes[i].frames[j].vertices;
float *normptr = retModel->meshes[i].frames[j].normals;
vertptr = retModel->meshes[i].frames[j].vertices;
normptr = retModel->meshes[i].frames[j].normals;
retModel->meshes[i].frames[j].material = &retModel->materials[i];
int k;
md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles);
mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles);
for (k = 0; k < mdS->numTriangles; k++)
{
@ -424,10 +443,9 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat)
}
}
md3TexCoord *mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST);
float *uvptr = (float*)retModel->meshes[i].uvs;
int k;
md3Triangle *mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles);
mdST = (md3TexCoord*)((char*)mdS + mdS->offsetST);
uvptr = (float*)retModel->meshes[i].uvs;
mdT = (md3Triangle*)((char*)mdS + mdS->offsetTriangles);
for (k = 0; k < mdS->numTriangles; k++)
{

View file

@ -27,20 +27,22 @@ vector_t vectorZaxis = { 0.0f, 0.0f, 1.0f };
void VectorRotate(vector_t *rotVec, const vector_t *axisVec, float angle)
{
float ux, uy, uz, vx, vy, vz, wx, wy, wz, sa, ca;
angle = U_Deg2Rad(angle);
// Rotate the point (x,y,z) around the vector (u,v,w)
float ux = axisVec->x * rotVec->x;
float uy = axisVec->x * rotVec->y;
float uz = axisVec->x * rotVec->z;
float vx = axisVec->y * rotVec->x;
float vy = axisVec->y * rotVec->y;
float vz = axisVec->y * rotVec->z;
float wx = axisVec->z * rotVec->x;
float wy = axisVec->z * rotVec->y;
float wz = axisVec->z * rotVec->z;
float sa = sinf(angle);
float ca = cosf(angle);
ux = axisVec->x * rotVec->x;
uy = axisVec->x * rotVec->y;
uz = axisVec->x * rotVec->z;
vx = axisVec->y * rotVec->x;
vy = axisVec->y * rotVec->y;
vz = axisVec->y * rotVec->z;
wx = axisVec->z * rotVec->x;
wy = axisVec->z * rotVec->y;
wz = axisVec->z * rotVec->z;
sa = sinf(angle);
ca = cosf(angle);
rotVec->x = axisVec->x*(ux + vy + wz) + (rotVec->x*(axisVec->y*axisVec->y + axisVec->z*axisVec->z) - axisVec->x*(vy + wz))*ca + (-wy + vz)*sa;
rotVec->y = axisVec->y*(ux + vy + wz) + (rotVec->y*(axisVec->x*axisVec->x + axisVec->z*axisVec->z) - axisVec->y*(ux + wz))*ca + (wx - uz)*sa;
@ -105,7 +107,7 @@ void CreateVBO(mesh_t *mesh, mdlframe_t *frame)
float *tanPtr = frame->tangents;
float *uvPtr = mesh->uvs;
float *lightPtr = mesh->lightuvs;
byte *colorPtr = frame->colors;
char *colorPtr = frame->colors;
int i;
for (i = 0; i < mesh->numTriangles*3; i++)
@ -364,17 +366,22 @@ void GenerateVertexNormals(model_t *model)
int i;
for (i = 0; i < model->numMeshes; i++)
{
int j;
mesh_t *mesh = &model->meshes[i];
if (!mesh->frames)
continue;
int j;
for (j = 0; j < mesh->numFrames; j++)
{
mdlframe_t *frame = &mesh->frames[j];
int memTag = PU_STATIC;
float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, 0);
int k;
float *vertPtr = frame->vertices;
float *oldNormals;
M_Memcpy(newNormals, frame->normals, sizeof(float)*3*mesh->numTriangles*3);
/* if (!systemSucks)
@ -384,20 +391,20 @@ void GenerateVertexNormals(model_t *model)
M_Memcpy(newTangents, frame->tangents, sizeof(float)*3*mesh->numTriangles*3);
}*/
int k;
float *vertPtr = frame->vertices;
for (k = 0; k < mesh->numVertices; k++)
{
float x, y, z;
int vCount = 0;
vector_t normal;
int l;
float *testPtr = frame->vertices;
x = *vertPtr++;
y = *vertPtr++;
z = *vertPtr++;
int vCount = 0;
vector_t normal;
normal.x = normal.y = normal.z = 0;
int l;
float *testPtr = frame->vertices;
for (l = 0; l < mesh->numVertices; l++)
{
float testX, testY, testZ;
@ -433,7 +440,7 @@ void GenerateVertexNormals(model_t *model)
}
}
float *oldNormals = frame->normals;
oldNormals = frame->normals;
frame->normals = newNormals;
Z_Free(oldNormals);
@ -456,7 +463,7 @@ typedef struct materiallist_s
static boolean AddMaterialToList(materiallist_t **head, material_t *material)
{
materiallist_t *node;
materiallist_t *node, *newMatNode;
for (node = *head; node; node = node->next)
{
if (node->material == material)
@ -464,7 +471,7 @@ static boolean AddMaterialToList(materiallist_t **head, material_t *material)
}
// Didn't find it, so add to the list
materiallist_t *newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, 0);
newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, 0);
newMatNode->material = material;
ListAdd(newMatNode, (listitem_t**)head);
return true;
@ -478,12 +485,16 @@ static boolean AddMaterialToList(materiallist_t **head, material_t *material)
//
void Optimize(model_t *model)
{
if (model->numMeshes <= 1)
return; // No need
int numMeshes = 0;
int i;
materiallist_t *matListHead = NULL;
int memTag;
mesh_t *newMeshes;
materiallist_t *node;
if (model->numMeshes <= 1)
return; // No need
for (i = 0; i < model->numMeshes; i++)
{
mesh_t *curMesh = &model->meshes[i];
@ -501,15 +512,18 @@ void Optimize(model_t *model)
numMeshes++;
}
int memTag = PU_STATIC;
mesh_t *newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, 0);
memTag = PU_STATIC;
newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, 0);
i = 0;
materiallist_t *node;
for (node = matListHead; node; node = node->next)
{
material_t *curMat = node->material;
mesh_t *newMesh = &newMeshes[i];
mdlframe_t *curFrame;
int uvCount;
int vertCount;
int colorCount;
// Find all triangles with this material and count them
int numTriangles = 0;
@ -529,20 +543,20 @@ void Optimize(model_t *model)
// if (node->material->lightmap)
// newMesh->lightuvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, 0);
newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, 0);
mdlframe_t *curFrame = &newMesh->frames[0];
curFrame = &newMesh->frames[0];
curFrame->material = curMat;
curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0);
// if (!systemSucks)
// curFrame->tangents = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0);
curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0);
curFrame->colors = (byte*)Z_Malloc(sizeof(byte)*4*numTriangles*3, memTag, 0);
curFrame->colors = (char*)Z_Malloc(sizeof(char)*4*numTriangles*3, memTag, 0);
// Now traverse the meshes of the model, adding in
// vertices/normals/uvs that match the current material
int uvCount = 0;
int vertCount = 0;
int colorCount = 0;
uvCount = 0;
vertCount = 0;
colorCount = 0;
for (j = 0; j < model->numMeshes; j++)
{
mesh_t *curMesh = &model->meshes[j];
@ -551,6 +565,8 @@ void Optimize(model_t *model)
{
float *dest;
float *src;
char *destByte;
char *srcByte;
M_Memcpy(&newMesh->uvs[uvCount],
curMesh->uvs,
@ -587,22 +603,20 @@ void Optimize(model_t *model)
vertCount += 3 * curMesh->numTriangles * 3;
byte *destByte;
byte *srcByte;
destByte = (byte*)newMesh->frames[0].colors;
srcByte = (byte*)curMesh->frames[0].colors;
destByte = (char*)newMesh->frames[0].colors;
srcByte = (char*)curMesh->frames[0].colors;
if (srcByte)
{
M_Memcpy(&destByte[colorCount],
srcByte,
sizeof(byte)*4*curMesh->numTriangles*3);
sizeof(char)*4*curMesh->numTriangles*3);
}
else
{
memset(&destByte[colorCount],
255,
sizeof(byte)*4*curMesh->numTriangles*3);
sizeof(char)*4*curMesh->numTriangles*3);
}
colorCount += 4 * curMesh->numTriangles * 3;
@ -622,21 +636,23 @@ void GeneratePolygonNormals(model_t *model, int ztag)
int i;
for (i = 0; i < model->numMeshes; i++)
{
int j;
mesh_t *mesh = &model->meshes[i];
if (!mesh->frames)
continue;
int j;
for (j = 0; j < mesh->numFrames; j++)
{
int k;
mdlframe_t *frame = &mesh->frames[j];
const float *vertices = frame->vertices;
vector_t *polyNormals;
frame->polyNormals = (vector_t*)Z_Malloc(sizeof(vector_t) * mesh->numTriangles, ztag, 0);
const float *vertices = frame->vertices;
vector_t *polyNormals = frame->polyNormals;
int k;
polyNormals = frame->polyNormals;
for (k = 0; k < mesh->numTriangles; k++)
{
// Vector::Normal(vertices, polyNormals);

View file

@ -38,7 +38,7 @@ typedef struct
float *vertices;
float *normals;
float *tangents;
byte *colors;
char *colors;
unsigned int vboID;
vector_t *polyNormals;
} mdlframe_t;

View file

@ -1924,14 +1924,19 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
GLfloat diffuse[4];
float pol = 0.0f;
scale *= 0.5f;
float scalex = scale, scaley = scale, scalez = scale;
boolean useTinyFrames;
int i;
// Because Otherwise, scaling the screen negatively vertically breaks the lighting
#ifndef KOS_GL_COMPATIBILITY
GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f};
#endif
scale *= 0.5f;
if (duration != 0 && duration != -1 && tics != -1) // don't interpolate if instantaneous or infinite in length
{
UINT32 newtime = (duration - tics); // + 1;
@ -2004,12 +2009,12 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
pglScalef(scalex, scaley, scalez);
boolean useTinyFrames = model->meshes[0].tinyframes != NULL;
useTinyFrames = model->meshes[0].tinyframes != NULL;
if (useTinyFrames)
pglScalef(1 / 64.0f, 1 / 64.0f, 1 / 64.0f);
for (int i = 0; i < model->numMeshes; i++)
for (i = 0; i < model->numMeshes; i++)
{
mesh_t *mesh = &model->meshes[i];
@ -2036,15 +2041,19 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
}
else
{
short *buffer, *vertPtr;
char *normBuffer, *normPtr;
float *uvPtr;
int j = 0;
// Dangit, I soooo want to do this in a GLSL shader...
pglBegin(GL_TRIANGLES);
short *buffer = malloc(mesh->numVertices * sizeof(short));
short *vertPtr = buffer;
char *normBuffer = malloc(mesh->numVertices * sizeof(char));
char *normPtr = normBuffer;
buffer = malloc(mesh->numVertices * sizeof(short));
vertPtr = buffer;
normBuffer = malloc(mesh->numVertices * sizeof(char));
normPtr = normBuffer;
int j = 0;
for (j = 0; j < mesh->numVertices; j++)
{
// Interpolate
@ -2052,7 +2061,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
*normPtr++ = (short)(frame->normals[j] + (pol * (nextframe->normals[j] - frame->normals[j])));
}
float *uvPtr = mesh->uvs;
uvPtr = mesh->uvs;
vertPtr = buffer;
normPtr = normBuffer;
for (j = 0; j < mesh->numTriangles; j++)
@ -2096,15 +2105,21 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
}
else
{
int j = 0;
float *uvPtr;
float *frameVert;
float *frameNormal;
float *nextFrameVert;
float *nextFrameNormal;
// Dangit, I soooo want to do this in a GLSL shader...
pglBegin(GL_TRIANGLES);
int j = 0;
float *uvPtr = mesh->uvs;
float *frameVert = frame->vertices;
float *frameNormal = frame->normals;
float *nextFrameVert = nextframe->vertices;
float *nextFrameNormal = frame->normals;
uvPtr = mesh->uvs;
frameVert = frame->vertices;
frameNormal = frame->normals;
nextFrameVert = nextframe->vertices;
nextFrameNormal = frame->normals;
for (j = 0; j < mesh->numTriangles; j++)
{
// Interpolate