mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-26 07:35:40 +00:00
double up polys for two sided polys, fixes some diffuse lighting problems
This commit is contained in:
parent
ddf3d5213d
commit
e295ad6868
|
@ -842,36 +842,24 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data)
|
||||||
int numTriangles = ph.NumTrianglesTotal();
|
int numTriangles = ph.NumTrianglesTotal();
|
||||||
|
|
||||||
// Cache all polygons
|
// Cache all polygons
|
||||||
while (!done)
|
do {
|
||||||
{
|
|
||||||
R3DPoly p; // current polygon
|
R3DPoly p; // current polygon
|
||||||
GLfloat uvScale;
|
GLfloat uvScale;
|
||||||
int i, j;
|
int i, j;
|
||||||
bool validPoly = true;
|
|
||||||
|
|
||||||
ph = data;
|
|
||||||
|
|
||||||
if (ph.header[6] == 0) {
|
if (ph.header[6] == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ph.header[0] & 0x100) && (ph.header[0] & 0x200)) { // assuming these two bits mean z and colour writes are disabled
|
if (ph.Disabled() || !numPolys && (ph.NumSharedVerts() != 0)) {
|
||||||
validPoly = false;
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if (!numPolys && (ph.NumSharedVerts() != 0)) { // sharing vertices, but we haven't started the model yet
|
|
||||||
printf("incomplete data\n");
|
|
||||||
validPoly = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set current header pointer (header is 7 words)
|
|
||||||
data += 7; // data will now point to first vertex
|
|
||||||
|
|
||||||
// create a hash value based on poly attributes -todo add more attributes
|
// create a hash value based on poly attributes -todo add more attributes
|
||||||
auto hash = ph.Hash();
|
auto hash = ph.Hash();
|
||||||
|
|
||||||
if (hash != lastHash && validPoly) {
|
if (hash != lastHash) {
|
||||||
|
|
||||||
if (sMap.count(hash) == 0) {
|
if (sMap.count(hash) == 0) {
|
||||||
|
|
||||||
|
@ -883,7 +871,7 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data)
|
||||||
currentMesh->polys.reserve(numTriangles);
|
currentMesh->polys.reserve(numTriangles);
|
||||||
|
|
||||||
//copy attributes
|
//copy attributes
|
||||||
currentMesh->doubleSided = ph.DoubleSided();
|
currentMesh->doubleSided = false; // we will double up polys
|
||||||
currentMesh->textured = ph.TexEnabled();
|
currentMesh->textured = ph.TexEnabled();
|
||||||
currentMesh->alphaTest = ph.AlphaTest();
|
currentMesh->alphaTest = ph.AlphaTest();
|
||||||
currentMesh->textureAlpha = ph.TextureAlpha();
|
currentMesh->textureAlpha = ph.TextureAlpha();
|
||||||
|
@ -912,9 +900,7 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data)
|
||||||
currentMesh = &sMap[hash];
|
currentMesh = &sMap[hash];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validPoly) {
|
lastHash = hash;
|
||||||
lastHash = hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtain basic polygon parameters
|
// Obtain basic polygon parameters
|
||||||
done = ph.LastPoly();
|
done = ph.LastPoly();
|
||||||
|
@ -970,14 +956,16 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data)
|
||||||
p.v[i].normal[2] = p.faceNormal[2];
|
p.v[i].normal[2] = p.faceNormal[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UINT32* vData = ph.StartOfData(); // vertex data starts here
|
||||||
|
|
||||||
// remaining vertices are new and defined here
|
// remaining vertices are new and defined here
|
||||||
for (; j < p.number; j++)
|
for (; j < p.number; j++)
|
||||||
{
|
{
|
||||||
// Fetch vertices
|
// Fetch vertices
|
||||||
UINT32 ix = data[0];
|
UINT32 ix = vData[0];
|
||||||
UINT32 iy = data[1];
|
UINT32 iy = vData[1];
|
||||||
UINT32 iz = data[2];
|
UINT32 iz = vData[2];
|
||||||
UINT32 it = data[3];
|
UINT32 it = vData[3];
|
||||||
|
|
||||||
// Decode vertices
|
// Decode vertices
|
||||||
p.v[j].pos[0] = (GLfloat)(((INT32)ix) >> 8) * m_vertexFactor;
|
p.v[j].pos[0] = (GLfloat)(((INT32)ix) >> 8) * m_vertexFactor;
|
||||||
|
@ -1008,14 +996,14 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data)
|
||||||
float texU, texV = 0;
|
float texU, texV = 0;
|
||||||
|
|
||||||
// tex coords
|
// tex coords
|
||||||
if (validPoly && currentMesh->textured) {
|
if (currentMesh->textured) {
|
||||||
Texture::GetCoordinates(currentMesh->width, currentMesh->height, (UINT16)(it >> 16), (UINT16)(it & 0xFFFF), uvScale, texU, texV);
|
Texture::GetCoordinates(currentMesh->width, currentMesh->height, (UINT16)(it >> 16), (UINT16)(it & 0xFFFF), uvScale, texU, texV);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.v[j].texcoords[0] = texU;
|
p.v[j].texcoords[0] = texU;
|
||||||
p.v[j].texcoords[1] = texV;
|
p.v[j].texcoords[1] = texV;
|
||||||
|
|
||||||
data += 4;
|
vData += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we need to modify the texture coordinates
|
// check if we need to modify the texture coordinates
|
||||||
|
@ -1036,17 +1024,31 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy current vertices into previous vertex array
|
// check if we need double up vertices for two sided lighting
|
||||||
for (i = 0; i < 4 && validPoly; i++) {
|
if (ph.DoubleSided()) {
|
||||||
prev[i] = p.v[i];
|
|
||||||
|
R3DPoly tempP = p;
|
||||||
|
|
||||||
|
// flip normals
|
||||||
|
V3::inverse(tempP.faceNormal);
|
||||||
|
|
||||||
|
for (int i = 0; i < tempP.number; i++) {
|
||||||
|
V3::inverse(tempP.v[i].normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyVertexData(tempP, currentMesh->polys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy this polygon into the model buffer
|
// Copy this polygon into the model buffer
|
||||||
if (validPoly) {
|
CopyVertexData(p, currentMesh->polys);
|
||||||
CopyVertexData(p, currentMesh->polys);
|
numPolys++;
|
||||||
numPolys++;
|
|
||||||
|
// Copy current vertices into previous vertex array
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
prev[i] = p.v[i];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
} while (ph.NextPoly());
|
||||||
|
|
||||||
//sorted the data, now copy to main data structures
|
//sorted the data, now copy to main data structures
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ int PolyHeader::PolyNumber()
|
||||||
|
|
||||||
bool PolyHeader::Disabled()
|
bool PolyHeader::Disabled()
|
||||||
{
|
{
|
||||||
if ((header[0] & 0x100) && (header[0] & 0x200)) { // assuming these two bits mean z and colour writes are disabled
|
if ((header[0] & 0x100) && (header[0] & 0x200)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ public:
|
||||||
float SpecularValue();
|
float SpecularValue();
|
||||||
bool Clockwise();
|
bool Clockwise();
|
||||||
int PolyNumber();
|
int PolyNumber();
|
||||||
bool Disabled(); // z & colour disabled
|
bool Disabled();
|
||||||
int NumVerts();
|
int NumVerts();
|
||||||
int NumSharedVerts();
|
int NumSharedVerts();
|
||||||
bool SharedVertex(int vertex);
|
bool SharedVertex(int vertex);
|
||||||
|
|
Loading…
Reference in a new issue