From 3aca9c9c7dcc660e7695a64bd1745ecf8c6bb849 Mon Sep 17 00:00:00 2001 From: aap Date: Sat, 19 Dec 2015 15:40:34 +0100 Subject: [PATCH] fixed stuff --- src/anim.cpp | 5 ++--- src/gtaplg.cpp | 2 +- src/mdl.cpp | 22 ++++++++++++++++++---- tools/dffwrite/dffwrite.cpp | 10 ++++++++-- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/anim.cpp b/src/anim.cpp index 10be1b8..1e50c96 100644 --- a/src/anim.cpp +++ b/src/anim.cpp @@ -335,16 +335,15 @@ writeUVAnim(Stream *stream, int32 size, void *object, int32 offset, int32) } } -// TODO: under what circumstance 0? static int32 getSizeUVAnim(void *object, int32 offset, int32) { UVAnim *uvanim = PLUGINOFFSET(UVAnim, object, offset); - int32 size = 12 + 4; + int32 size = 0; for(int32 i = 0; i < 8; i++) if(uvanim->interp[i]) size += 32; - return size; + return size ? size + 12 + 4 : 0; } diff --git a/src/gtaplg.cpp b/src/gtaplg.cpp index c43fa3b..3c54420 100644 --- a/src/gtaplg.cpp +++ b/src/gtaplg.cpp @@ -243,7 +243,7 @@ getSizeBreakableModel(void *object, int32 offset, int32) { Breakable *breakable = *PLUGINOFFSET(Breakable*, object, offset); if(breakable == NULL) - return 4; + return 0; //4; return 56 + breakable->numVertices*(12+8+4) + breakable->numFaces*(6+2) + breakable->numMaterials*(32+32+12); diff --git a/src/mdl.cpp b/src/mdl.cpp index 24a05e5..425c539 100644 --- a/src/mdl.cpp +++ b/src/mdl.cpp @@ -27,7 +27,7 @@ int32 rslPluginOffset; struct RslMesh { float32 bound[4]; // ? - float32 uvOff[2]; // ? + float32 uvScale[2]; uint32 unknown; uint32 dmaOffset; uint16 numTriangles; @@ -50,6 +50,17 @@ struct RslGeometry uint8 *data; }; +float32 +halfFloat(uint16 half) +{ + uint32 f = (uint32)(half & 0x7fff) << 13; + uint32 sgn = (uint32)(half & 0x8000) << 16; + f += 0x38000000; + if(half & 0x7c00 == 0) f = 0; + f |= sgn; + return *(float32*)&f; +} + static uint32 unpackSize(uint32 unpack) { @@ -157,6 +168,9 @@ convertRslMesh(Geometry *g, RslGeometry *rg, Mesh *m, RslMesh *rm) mask |= 0x10000; } + //float uScale = //halfFloat(rm->uvScale[0]); + //float vScale = //halfFloat(rm->uvScale[1]); + int16 *vuVerts = NULL; int8 *vuNorms = NULL; uint8 *vuTex = NULL; @@ -229,8 +243,8 @@ convertRslMesh(Geometry *g, RslGeometry *rg, Mesh *m, RslMesh *rm) v.p[0] = vuVerts[0]/32768.0f*rg->scale[0] + rg->pos[0]; v.p[1] = vuVerts[1]/32768.0f*rg->scale[1] + rg->pos[1]; v.p[2] = vuVerts[2]/32768.0f*rg->scale[2] + rg->pos[2]; - v.t[0] = vuTex[0]/255.0f*rm->uvOff[0]; - v.t[1] = vuTex[1]/255.0f*rm->uvOff[1]; + v.t[0] = vuTex[0]/128.0f*rm->uvScale[0]; + v.t[1] = vuTex[1]/128.0f*rm->uvScale[1]; if(mask & 0x10){ v.n[0] = vuNorms[0]/127.0f; v.n[1] = vuNorms[1]/127.0f; @@ -240,7 +254,7 @@ convertRslMesh(Geometry *g, RslGeometry *rg, Mesh *m, RslMesh *rm) v.c[0] = (vuCols[0] & 0x1f) * 255 / 0x1F; v.c[1] = (vuCols[0]>>5 & 0x1f) * 255 / 0x1F; v.c[2] = (vuCols[0]>>10 & 0x1f) * 255 / 0x1F; - v.c[3] = vuCols[0]&0x80 ? 0xFF : 0; + v.c[3] = vuCols[0]&0x8000 ? 0xFF : 0; } if(mask & 0x10000){ for(int j = 0; j < 4; j++){ diff --git a/tools/dffwrite/dffwrite.cpp b/tools/dffwrite/dffwrite.cpp index 359a86b..e9f852a 100644 --- a/tools/dffwrite/dffwrite.cpp +++ b/tools/dffwrite/dffwrite.cpp @@ -16,8 +16,9 @@ main(int argc, char *argv[]) // rw::version = 0x31000; // rw::build = 0; + rw::version = 0; // rw::version = 0x32000; - rw::version = 0x33002; +// rw::version = 0x33002; rw::platform = PLATFORM_D3D8; // rw::version = 0x30200; @@ -31,6 +32,7 @@ main(int argc, char *argv[]) // rw::StreamFile in; // in.open(argv[1], "rb"); + ChunkHeaderInfo header; if(0){ FILE *cf = fopen(argv[1], "rb"); assert(cf != NULL); @@ -57,7 +59,6 @@ main(int argc, char *argv[]) return 1; } debugFile = argv[1]; - ChunkHeaderInfo header; readChunkHeaderInfo(&in, &header); if(header.type == ID_UVANIMDICT){ UVAnimDictionary *dict = UVAnimDictionary::streamRead(&in); @@ -76,6 +77,11 @@ main(int argc, char *argv[]) for(int32 i = 0; i < c->numAtomics; i++) convertRslGeometry(c->atomicList[i]->geometry); + if(rw::version == 0){ + rw::version = header.version; + rw::build = header.build; + } + // rw::Image::setSearchPath("./;/home/aap/gamedata/ps2/gtavc/MODELS/gta3_archive/txd_extracted/"); /*