mirror of
https://github.com/ZDoom/Raze.git
synced 2025-01-18 22:51:50 +00:00
- removed dead Polymer handling in model code.
This commit is contained in:
parent
4b44e6e392
commit
fbdc6c7a6c
2 changed files with 1 additions and 267 deletions
|
@ -1035,7 +1035,6 @@ static int32_t defsparser(scriptfile *script)
|
|||
if (scriptfile_getdouble(script,&scale)) break;
|
||||
if (scriptfile_getnumber(script,&shadeoffs)) break;
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
lastmodelid = md_loadmodel(modelfn);
|
||||
if (EDUKE32_PREDICT_FALSE(lastmodelid < 0))
|
||||
{
|
||||
|
@ -1043,11 +1042,7 @@ static int32_t defsparser(scriptfile *script)
|
|||
break;
|
||||
}
|
||||
md_setmisc(lastmodelid,(float)scale, shadeoffs,0.0,0.0,0);
|
||||
# ifdef POLYMER
|
||||
if (glrendmode == REND_POLYMER)
|
||||
md3postload_polymer((md3model_t *)models[lastmodelid]);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
modelskin = lastmodelskin = 0;
|
||||
seenframe = 0;
|
||||
}
|
||||
|
@ -1666,7 +1661,6 @@ static int32_t defsparser(scriptfile *script)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (EDUKE32_PREDICT_FALSE(!model_ok))
|
||||
{
|
||||
if (lastmodelid >= 0)
|
||||
|
@ -1679,32 +1673,6 @@ static int32_t defsparser(scriptfile *script)
|
|||
}
|
||||
|
||||
md_setmisc(lastmodelid,(float)scale,shadeoffs,(float)mzadd,(float)myoffset,flags);
|
||||
|
||||
// thin out the loaded model by throwing away unused frames
|
||||
// FIXME: CURRENTLY DISABLED: interpolation may access frames we consider 'unused'?
|
||||
# if 0
|
||||
if (models[lastmodelid]->mdnum==3 && ((md3model_t *)models[lastmodelid])->numframes <= 1024)
|
||||
{
|
||||
# ifdef DEBUG_MODEL_MEM
|
||||
md3model_t *m = (md3model_t *)models[lastmodelid];
|
||||
int32_t i, onumframes;
|
||||
onumframes = m->numframes;
|
||||
i =
|
||||
# endif
|
||||
md_thinoutmodel(lastmodelid, usedframebitmap);
|
||||
# ifdef DEBUG_MODEL_MEM
|
||||
if (i>=0 && i<onumframes)
|
||||
Printf("used %d/%d frames: %s\n", i, onumframes, modelfn);
|
||||
else if (i<0)
|
||||
Printf("md_thinoutmodel returned %d: %s\n", i, modelfn);
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
|
||||
if (glrendmode == REND_POLYMER)
|
||||
md3postload_polymer((md3model_t *)models[lastmodelid]);
|
||||
#endif
|
||||
|
||||
modelskin = lastmodelskin = 0;
|
||||
seenframe = 0;
|
||||
|
||||
|
|
|
@ -1191,240 +1191,6 @@ static void md3postload_common(md3model_t *m)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef POLYMER
|
||||
// pre-check success of conversion since it must not fail later.
|
||||
// keep in sync with md3postload_polymer!
|
||||
static int md3postload_polymer_check(md3model_t *m)
|
||||
{
|
||||
ssize_t surfi, trii;
|
||||
md3surf_t *s;
|
||||
|
||||
surfi = 0;
|
||||
while (surfi < m->head.numsurfs)
|
||||
{
|
||||
s = &m->head.surfs[surfi];
|
||||
|
||||
uint32_t const numverts = s->numverts;
|
||||
|
||||
trii = 0;
|
||||
while (trii < s->numtris)
|
||||
{
|
||||
uint32_t const * const u = (uint32_t const *)s->tris[trii].i;
|
||||
|
||||
// let the vertices know they're being referenced by a triangle
|
||||
if (u[0] >= numverts || u[1] >= numverts || u[2] >= numverts)
|
||||
{
|
||||
// corrupt model
|
||||
Printf("%s: Triangle index out of bounds!\n", m->head.nam);
|
||||
return 1;
|
||||
}
|
||||
|
||||
++trii;
|
||||
}
|
||||
|
||||
++surfi;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Precalculated cos/sin arrays.
|
||||
static float g_mdcos[256], g_mdsin[256];
|
||||
static int32_t mdtrig_init = 0;
|
||||
|
||||
static void init_mdtrig_arrays(void)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
float ang = i * (2.f * fPI) * (1.f/255.f);
|
||||
g_mdcos[i] = cosf(ang);
|
||||
g_mdsin[i] = sinf(ang);
|
||||
}
|
||||
|
||||
mdtrig_init = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int md3postload_polymer(md3model_t *m)
|
||||
{
|
||||
#ifdef POLYMER
|
||||
int framei, surfi, verti, trii;
|
||||
float vec1[5], vec2[5], mat[9], r;
|
||||
|
||||
// POLYMER_MD_PROCESS_CHECK
|
||||
if (m->head.surfs[0].geometry)
|
||||
return -1; // already postprocessed
|
||||
|
||||
if (!mdtrig_init)
|
||||
init_mdtrig_arrays();
|
||||
|
||||
// let's also repack the geometry to more usable formats
|
||||
|
||||
surfi = 0;
|
||||
while (surfi < m->head.numsurfs)
|
||||
{
|
||||
handleevents();
|
||||
|
||||
md3surf_t *const s = &m->head.surfs[surfi];
|
||||
#ifdef DEBUG_MODEL_MEM
|
||||
i = (m->head.numframes * s->numverts * sizeof(float) * 15);
|
||||
if (i > 1<<20)
|
||||
Printf("size %d (%d fr, %d v): md %s surf %d/%d\n", i, m->head.numframes, s->numverts,
|
||||
m->head.nam, surfi, m->head.numsurfs);
|
||||
#endif
|
||||
s->geometry = (float *)Xcalloc(m->head.numframes * s->numverts * 15, sizeof(float));
|
||||
|
||||
if (s->numverts > tribufverts)
|
||||
{
|
||||
tribuf = (int32_t *) Xrealloc(tribuf, s->numverts * sizeof(int32_t));
|
||||
tribufverts = s->numverts;
|
||||
}
|
||||
|
||||
Bmemset(tribuf, 0, s->numverts * sizeof(int32_t));
|
||||
|
||||
verti = 0;
|
||||
while (verti < (m->head.numframes * s->numverts))
|
||||
{
|
||||
md3xyzn_t const & xyzn = s->xyzn[verti];
|
||||
|
||||
// normal extraction from packed spherical coordinates
|
||||
// FIXME: swapping lat and lng because of npherno's compiler
|
||||
uint8_t lat = xyzn.nlng;
|
||||
uint8_t lng = xyzn.nlat;
|
||||
size_t verti15 = (size_t)verti * 15;
|
||||
|
||||
s->geometry[verti15 + 0] = xyzn.x;
|
||||
s->geometry[verti15 + 1] = xyzn.y;
|
||||
s->geometry[verti15 + 2] = xyzn.z;
|
||||
|
||||
s->geometry[verti15 + 3] = g_mdcos[lat] * g_mdsin[lng];
|
||||
s->geometry[verti15 + 4] = g_mdsin[lat] * g_mdsin[lng];
|
||||
s->geometry[verti15 + 5] = g_mdcos[lng];
|
||||
|
||||
++verti;
|
||||
}
|
||||
|
||||
uint32_t numverts = s->numverts;
|
||||
|
||||
trii = 0;
|
||||
while (trii < s->numtris)
|
||||
{
|
||||
int32_t const * const i = s->tris[trii].i;
|
||||
uint32_t const * const u = (uint32_t const *)i;
|
||||
|
||||
// let the vertices know they're being referenced by a triangle
|
||||
if (u[0] >= numverts ||u[1] >= numverts || u[2] >= numverts)
|
||||
{
|
||||
// corrupt model
|
||||
return 0;
|
||||
}
|
||||
tribuf[u[0]]++;
|
||||
tribuf[u[1]]++;
|
||||
tribuf[u[2]]++;
|
||||
|
||||
uint32_t const tris15[] = { u[0] * 15, u[1] * 15, u[2] * 15 };
|
||||
|
||||
|
||||
framei = 0;
|
||||
while (framei < m->head.numframes)
|
||||
{
|
||||
const uint32_t verti15 = framei * s->numverts * 15;
|
||||
|
||||
vec1[0] = s->geometry[verti15 + tris15[1]] - s->geometry[verti15 + tris15[0]];
|
||||
vec1[1] = s->geometry[verti15 + tris15[1] + 1] - s->geometry[verti15 + tris15[0] + 1];
|
||||
vec1[2] = s->geometry[verti15 + tris15[1] + 2] - s->geometry[verti15 + tris15[0] + 2];
|
||||
vec1[3] = s->uv[u[1]].u - s->uv[u[0]].u;
|
||||
vec1[4] = s->uv[u[1]].v - s->uv[u[0]].v;
|
||||
|
||||
vec2[0] = s->geometry[verti15 + tris15[2]] - s->geometry[verti15 + tris15[1]];
|
||||
vec2[1] = s->geometry[verti15 + tris15[2] + 1] - s->geometry[verti15 + tris15[1] + 1];
|
||||
vec2[2] = s->geometry[verti15 + tris15[2] + 2] - s->geometry[verti15 + tris15[1] + 2];
|
||||
vec2[3] = s->uv[u[2]].u - s->uv[u[1]].u;
|
||||
vec2[4] = s->uv[u[2]].v - s->uv[u[1]].v;
|
||||
|
||||
r = (vec1[3] * vec2[4] - vec2[3] * vec1[4]);
|
||||
if (r != 0.0f)
|
||||
{
|
||||
r = 1.f/r;
|
||||
|
||||
// tangent
|
||||
mat[0] = (vec2[4] * vec1[0] - vec1[4] * vec2[0]) * r;
|
||||
mat[1] = (vec2[4] * vec1[1] - vec1[4] * vec2[1]) * r;
|
||||
mat[2] = (vec2[4] * vec1[2] - vec1[4] * vec2[2]) * r;
|
||||
|
||||
normalize(&mat[0]);
|
||||
|
||||
// bitangent
|
||||
mat[3] = (vec1[3] * vec2[0] - vec2[3] * vec1[0]) * r;
|
||||
mat[4] = (vec1[3] * vec2[1] - vec2[3] * vec1[1]) * r;
|
||||
mat[5] = (vec1[3] * vec2[2] - vec2[3] * vec1[2]) * r;
|
||||
|
||||
normalize(&mat[3]);
|
||||
}
|
||||
else
|
||||
Bmemset(mat, 0, sizeof(float) * 6);
|
||||
|
||||
// T and B are shared for the three vertices in that triangle
|
||||
size_t const offs = (framei * numverts * 15) + 6;
|
||||
size_t j = 0;
|
||||
do
|
||||
{
|
||||
size_t const offsi = offs + j;
|
||||
s->geometry[offsi + tris15[0]] += mat[j];
|
||||
s->geometry[offsi + tris15[1]] += mat[j];
|
||||
s->geometry[offsi + tris15[2]] += mat[j];
|
||||
}
|
||||
while (++j < 6);
|
||||
|
||||
++framei;
|
||||
}
|
||||
|
||||
++trii;
|
||||
}
|
||||
|
||||
// now that we accumulated the TBNs, average and invert them for each vertex
|
||||
int verti_end = m->head.numframes * s->numverts;
|
||||
|
||||
verti = 0;
|
||||
while (verti < verti_end)
|
||||
{
|
||||
const int32_t curnumtris = tribuf[verti % s->numverts];
|
||||
uint32_t const verti15 = verti * 15;
|
||||
|
||||
if (curnumtris > 0)
|
||||
{
|
||||
const float rfcurnumtris = 1.f/(float)curnumtris;
|
||||
size_t i = 6;
|
||||
do
|
||||
s->geometry[i + verti15] *= rfcurnumtris;
|
||||
while (++i < 12);
|
||||
}
|
||||
#ifdef DEBUG_MODEL_MEM
|
||||
else if (verti == verti%s->numverts)
|
||||
{
|
||||
Printf("%s: vert %d is unused\n", m->head.nam, verti);
|
||||
}
|
||||
#endif
|
||||
// copy N over
|
||||
Bmemcpy(&s->geometry[verti15 + 12], &s->geometry[verti15 + 3], sizeof(float) * 3);
|
||||
invertmatrix(&s->geometry[verti15 + 6], mat);
|
||||
Bmemcpy(&s->geometry[verti15 + 6], mat, sizeof(float) * 9);
|
||||
|
||||
++verti;
|
||||
}
|
||||
|
||||
++surfi;
|
||||
}
|
||||
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(m);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void md3_vox_calcmat_common(tspriteptr_t tspr, const vec3f_t *a0, float f, float mat[16])
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue