unconvert ADC implemented

This commit is contained in:
aap 2015-12-20 13:05:32 +01:00
parent 83d1420dd1
commit 37e1e239f9
9 changed files with 83 additions and 220 deletions

View File

@ -71,14 +71,7 @@ Geometry::~Geometry(void)
delete[] m->normals; delete[] m->normals;
} }
delete[] this->morphTargets; delete[] this->morphTargets;
delete this->meshHeader;
if(this->meshHeader){
// first mesh holds pointer to all indices
delete[] this->meshHeader->mesh[0].indices;
delete[] this->meshHeader->mesh;
delete this->meshHeader;
}
for(int32 i = 0; i < this->numMaterials; i++) for(int32 i = 0; i < this->numMaterials; i++)
this->materialList[i]->decRef(); this->materialList[i]->decRef();
delete[] this->materialList; delete[] this->materialList;

View File

@ -816,37 +816,37 @@ registerCollisionPlugin(void)
using namespace ps2; using namespace ps2;
PipeAttribute saXYZADC = { rw::PipeAttribute saXYZADC = {
"saXYZADC", "saXYZADC",
AT_V4_16 | AT_RW AT_V4_16 | AT_RW
}; };
PipeAttribute saUV = { rw::PipeAttribute saUV = {
"saUV", "saUV",
AT_V2_16 | AT_RW AT_V2_16 | AT_RW
}; };
PipeAttribute saUV2 = { rw::PipeAttribute saUV2 = {
"saUV2", "saUV2",
AT_V4_16 | AT_RW AT_V4_16 | AT_RW
}; };
PipeAttribute saRGBA = { rw::PipeAttribute saRGBA = {
"saRGBA", "saRGBA",
AT_V4_8 | AT_UNSGN | AT_RW AT_V4_8 | AT_UNSGN | AT_RW
}; };
PipeAttribute saRGBA2 = { rw::PipeAttribute saRGBA2 = {
"saRGBA2", "saRGBA2",
AT_V4_16 | AT_UNSGN | AT_RW AT_V4_16 | AT_UNSGN | AT_RW
}; };
PipeAttribute saNormal = { rw::PipeAttribute saNormal = {
"saNormal", "saNormal",
AT_V4_8 | AT_RW AT_V4_8 | AT_RW
}; };
PipeAttribute saWeights = { rw::PipeAttribute saWeights = {
"saWeights", "saWeights",
AT_V4_32 | AT_RW AT_V4_32 | AT_RW
}; };

View File

@ -295,6 +295,13 @@ registerMeshPlugin(void)
Geometry::registerPluginStream(0x50E, readMesh, writeMesh, getSizeMesh); Geometry::registerPluginStream(0x50E, readMesh, writeMesh, getSizeMesh);
} }
MeshHeader::~MeshHeader(void)
{
// first mesh holds pointer to all indices
delete[] this->mesh[0].indices;
delete[] this->mesh;
}
void void
MeshHeader::allocateIndices(void) MeshHeader::allocateIndices(void)
{ {

View File

@ -1217,6 +1217,55 @@ debugadc(Geometry *g, MeshHeader *mh, ADCData *adc)
return n; return n;
} }
// Not optimal but works
void
unconvertADC(Geometry *g)
{
ADCData *adc = PLUGINOFFSET(ADCData, g, adcOffset);
if(!adc->adcFormatted)
return;
int8 *b = adc->adcBits;
MeshHeader *h = new MeshHeader;
h->flags = g->meshHeader->flags; // should be tristrip
h->numMeshes = g->meshHeader->numMeshes;
h->mesh = new Mesh[h->numMeshes];
Mesh *oldm = g->meshHeader->mesh;
Mesh *newm = h->mesh;
h->totalIndices = 0;
for(int32 i = 0; i < h->numMeshes; i++){
newm->material = oldm->material;
newm->numIndices = oldm->numIndices;
for(uint32 j = 0; j < oldm->numIndices; j++)
if(*b++)
newm->numIndices += 2;
h->totalIndices += newm->numIndices;
newm++;
oldm++;
}
h->allocateIndices();
b = adc->adcBits;
oldm = g->meshHeader->mesh;
newm = h->mesh;
for(int32 i = 0; i < h->numMeshes; i++){
int32 n = 0;
for(uint32 j = 0; j < oldm->numIndices; j++){
if(*b++){
newm->indices[n++] = oldm->indices[j-1];
newm->indices[n++] = oldm->indices[j-1];
}
newm->indices[n++] = oldm->indices[j];
}
newm++;
oldm++;
}
delete g->meshHeader;
g->meshHeader = h;
adc->adcFormatted = 0;
delete[] adc->adcBits;
adc->adcBits = 0;
adc->numBits = NULL;
}
void void
allocateADC(Geometry *geo) allocateADC(Geometry *geo)
{ {

View File

@ -291,6 +291,7 @@ struct MeshHeader
Mesh *mesh; // RW has a byte offset here Mesh *mesh; // RW has a byte offset here
void allocateIndices(void); void allocateIndices(void);
~MeshHeader(void);
}; };
struct MorphTarget struct MorphTarget

View File

@ -136,6 +136,7 @@ struct ADCData
extern int32 adcOffset; extern int32 adcOffset;
void registerADCPlugin(void); void registerADCPlugin(void);
void unconvertADC(Geometry *geo);
void allocateADC(Geometry *geo); void allocateADC(Geometry *geo);
// PDS plugin // PDS plugin

View File

@ -180,15 +180,15 @@ initrw(void)
gta::attachPlugins(); gta::attachPlugins();
rw::d3d::registerNativeRaster(); rw::d3d::registerNativeRaster();
// rw::currentTexDictionary = new rw::TexDictionary; rw::currentTexDictionary = new rw::TexDictionary;
// rw::Image::setSearchPath("D:\\rockstargames\\ps2\\gta3\\MODELS\\gta3_archive\\txd_extracted\\;" //rw::Image::setSearchPath("D:\\rockstargames\\ps2\\gta3\\MODELS\\gta3_archive\\txd_extracted\\;"
// "D:\\rockstargames\\ps2\\gtavc\\MODELS\\gta3_archive\\txd_extracted\\;" // "D:\\rockstargames\\ps2\\gtavc\\MODELS\\gta3_archive\\txd_extracted\\;"
// "D:\\rockstargames\\ps2\\gtasa\\models\\gta3_archive\\txd_extracted\\"); // "D:\\rockstargames\\ps2\\gtasa\\models\\gta3_archive\\txd_extracted\\");
rw::platform = rw::PLATFORM_D3D8; rw::platform = rw::PLATFORM_D3D8;
rw::d3d::device = Device; rw::d3d::device = Device;
if(1){ if(0){
char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\admiral.txd"; char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\admiral.txd";
rw::StreamFile in; rw::StreamFile in;
if(in.open(filename, "rb") == NULL){ if(in.open(filename, "rb") == NULL){
@ -208,12 +208,12 @@ initrw(void)
out.close(); out.close();
} }
char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\admiral.dff"; // char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\admiral.dff";
// char *filename = "D:\\rockstargames\\pc\\gta3\\models\\gta3_archive\\kuruma.dff"; // char *filename = "D:\\rockstargames\\pc\\gta3\\models\\gta3_archive\\kuruma.dff";
// char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\player.dff"; // char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\player.dff";
// char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\od_newscafe_dy.dff"; // char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\od_newscafe_dy.dff";
// char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\admiral.dff"; // char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\admiral.dff";
// char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\lae2_roads89.dff"; char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\lae2_roads89.dff";
// char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\casinoblock41_nt.dff"; // char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\casinoblock41_nt.dff";
// char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\cutscene_archive\\csremington92.dff"; // char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\cutscene_archive\\csremington92.dff";
// char *filename = "C:\\gtasa\\test\\hanger.dff"; // char *filename = "C:\\gtasa\\test\\hanger.dff";
@ -232,6 +232,8 @@ initrw(void)
for(int i = 0; i < clump->numAtomics; i++){ for(int i = 0; i < clump->numAtomics; i++){
rw::Atomic *a = clump->atomicList[i]; rw::Atomic *a = clump->atomicList[i];
if(a->pipeline && a->pipeline->platform == rw::PLATFORM_PS2)
a->pipeline = NULL;
a->getPipeline()->instance(a); a->getPipeline()->instance(a);
} }
if(rw::platform == rw::PLATFORM_D3D8) if(rw::platform == rw::PLATFORM_D3D8)

View File

@ -11,125 +11,6 @@
using namespace std; using namespace std;
using namespace rw; using namespace rw;
struct bone {
int32 id;
char *name;
char *newName;
};
bone idMapVC[] = {
{ 0, "Root", NULL },
{ 1, "Pelvis", NULL },
{ 2, "Spine", NULL },
{ 3, "Spine1", NULL },
{ 4, "Neck", NULL },
{ 5, "Head", NULL },
{ 31, "Bip01 L Clavicle", NULL },
{ 32, "L UpperArm", NULL },
{ 33, "L Forearm", NULL },
{ 34, "L Hand", NULL },
{ 35, "L Finger", NULL },
{ 21, "Bip01 R Clavicle", NULL },
{ 22, "R UpperArm", NULL },
{ 23, "R Forearm", NULL },
{ 24, "R Hand", NULL },
{ 25, "R Finger", NULL },
{ 41, "L Thigh", NULL },
{ 42, "L Calf", NULL },
{ 43, "L Foot", NULL },
{ 2000, "L Toe0", NULL },
{ 51, "R Thigh", NULL },
{ 52, "R Calf", NULL },
{ 53, "R Foot", NULL },
{ 2001, "R Toe0", NULL },
};
bone csIdMapVC[] = {
{ 0, "Root", NULL },
{ 1, "Pelvis", NULL },
{ 2, "Spine", NULL },
{ 3, "Spine1", NULL },
{ 4, "Neck", NULL },
{ 5, "Head", NULL },
{ 2000, "HeadNub", "Bip01 HeadNub" },
{ 5006, "llid", NULL },
{ 5005, "rlid", NULL },
{ 5001, "rbrow1", NULL },
{ 5002, "rbrow2", NULL },
{ 5004, "lbrow1", NULL },
{ 5003, "lbrow2", NULL },
{ 5008, "lcheek", NULL },
{ 5015, "rcorner", NULL },
{ 5016, "lcorner", NULL },
{ 5017, "jaw1", NULL },
{ 5018, "jaw2", NULL },
{ 5019, "llip", NULL },
{ 5020, "llip01", NULL },
{ 5012, "ltlip1", NULL },
{ 5013, "ltlip2", NULL },
{ 5014, "ltlip3", NULL },
{ 5009, "rtlip1", NULL },
{ 5010, "rtlip2", NULL },
{ 5011, "rtlip3", NULL },
{ 5007, "rcheek", NULL },
{ 5021, "reye", NULL },
{ 5022, "leye", NULL },
{ 31, "L Clavicle", "Bip01 L Clavicle" },
{ 32, "L UpperArm", NULL },
{ 33, "L Forearm", NULL },
{ 34, "L Hand", NULL },
{ 35, "L Finger0", "L Finger" },
{ 36, "L Finger01", "Root L Finger01" },
{ 2001, "L Finger0Nub", "Bip01 L Finger0Nub" },
{ 21, "R Clavicle", "Bip01 R Clavicle" },
{ 22, "R UpperArm", NULL },
{ 23, "R Forearm", NULL },
{ 24, "R Hand", NULL },
{ 25, "R Finger0", "R Finger" },
{ 26, "R Finger01", "Root R Finger01" },
{ 2002, "R Finger0Nub", "Bip01 R Finger0Nub" },
{ 41, "L Thigh", NULL },
{ 42, "L Calf", NULL },
{ 43, "L Foot", NULL },
{ 2003, "L Toe0", NULL },
{ 2004, "L Toe0Nub", "Bip01 L Toe0Nub" },
{ 51, "R Thigh", NULL },
{ 52, "R Calf", NULL },
{ 53, "R Foot", NULL },
{ 2005, "R Toe0", NULL },
{ 2006, "R Toe0Nub", "Bip01 R Toe0Nub" },
};
//int
//strcmpci(const char *s, const char *t)
//{
// while(*s && *t && tolower(*s) == tolower(*t)){
// s++;
// t++;
// }
// return *s-*t;
//}
//Frame*
//assignIdCB(Frame *f, void *p)
//{
// HAnimData *hanim = PLUGINOFFSET(HAnimData, f, hAnimOffset);
// char *name = PLUGINOFFSET(char, f, gta::nodeNameOffset);
// HAnimHierarchy *hier = (HAnimHierarchy*)p;
// bone *map = hier->numNodes == 24 ? idMapVC : csIdMapVC;
// for(int32 i = 0; i < hier->numNodes; i++){
// if(strcmpci(name, map[i].name) == 0){
// if(map[i].newName)
// strncpy(name, map[i].newName, 24);
// //printf("%x %d %s\n", hanim->id, hanim->id, name);
// //hanim->id = map[i].id;
// break;
// }
// }
// f->forAllChildren(assignIdCB, hier);
// return f;
//}
Frame* Frame*
findHierCB(Frame *f, void *p) findHierCB(Frame *f, void *p)
{ {
@ -151,82 +32,16 @@ getHierarchy(Clump *c)
} }
void void
assignNodeIDs(Clump *c) fixLcsHier(HAnimHierarchy *hier)
{ {
HAnimHierarchy *hier = getHierarchy(c); hier->maxInterpKeyFrameSize = findAnimInterpolatorInfo(1)->keyFrameSize;
if(hier == NULL)
return;
// if(hier == NULL || (hier->numNodes != 24 && hier->numNodes != 53))
// return;
// bone *map = hier->numNodes == 24 ? idMapVC : csIdMapVC;
for(int32 i = 0; i < hier->numNodes; i++){ for(int32 i = 0; i < hier->numNodes; i++){
// printf("%x %x %d\n", hier->nodeInfo[i].index, hier->nodeInfo[i].id, hier->nodeInfo[i].id);
int32 id = hier->nodeInfo[i].id; int32 id = hier->nodeInfo[i].id;
if(id == 255) hier->nodeInfo[i].id = -1; if(id == 255) hier->nodeInfo[i].id = -1;
else if(id > 0x80) hier->nodeInfo[i].id |= 0x1300; else if(id > 0x80) hier->nodeInfo[i].id |= 0x1300;
// hier->nodeInfo[i].id = map[hier->nodeInfo[i].index].id;
} }
// assignIdCB((Frame*)c->parent, hier);
} }
//void
//mirrorFrameHier(Frame *f)
//{
// if(f->next){
// Frame *n = f->next;
// Frame *p = (Frame*)f->parent;
// f->removeChild();
// mirrorFrameHier(n);
// p->addChild(f);
// }
// if(f->child)
// mirrorFrameHier(f->child);
//}
//void
//generateInvBoneMats(Atomic *a)
//{
// float32 rootInv[16], tmp[16];
// HAnimHierarchy *h = getHierarchy(a->clump);
// Frame *root = h->parentFrame;
// root->updateLTM();
// matrixInvert(rootInv, root->ltm);
// Skin *skin = *PLUGINOFFSET(Skin*, a->geometry, skinGlobals.offset);
// assert(skin->numBones == h->numNodes);
// for(int32 i = 0; i < h->numNodes; i++){
// //assert(h->nodeInfo[i].frame);
// if(h->nodeInfo[i].frame == NULL){
// printf("warning: no node for node %d/%d\n", i, h->nodeInfo[i].id);
// continue;
// }
// h->nodeInfo[i].frame->updateLTM();
// float32 *m = &skin->inverseMatrices[i*16];
// matrixMult(tmp, rootInv, h->nodeInfo[i].frame->ltm);
// matrixInvert(m, tmp);
// }
//}
//Frame*
//findFrameById(Frame *f, int32 id)
//{
// if(f == NULL)
// return NULL;
// HAnimData *hanim = PLUGINOFFSET(HAnimData, f, hAnimOffset);
// if(hanim->id == id)
// return f;
// Frame *ff = findFrameById(f->next, id);
// if(ff) return ff;
// return findFrameById(f->child, id);
//}
//void
//attachFrames(Clump *c)
//{
// HAnimHierarchy *h = getHierarchy(c);
// for(int32 i = 0; i < h->numNodes; i++)
// h->nodeInfo[i].frame = findFrameById(h->parentFrame, h->nodeInfo[i].id);
//}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -298,19 +113,13 @@ main(int argc, char *argv[])
if(lcs){ if(lcs){
HAnimHierarchy *hier = getHierarchy(c); HAnimHierarchy *hier = getHierarchy(c);
if(hier){ if(hier)
hier->maxInterpKeyFrameSize = findAnimInterpolatorInfo(1)->keyFrameSize; fixLcsHier(hier);
//mirrorFrameHier((Frame*)c->parent);
assignNodeIDs(c);
}
//attachFrames(c);
for(int32 i = 0; i < c->numAtomics; i++){ for(int32 i = 0; i < c->numAtomics; i++){
Skin *skin = *PLUGINOFFSET(Skin*, c->atomicList[i]->geometry, skinGlobals.offset); Skin *skin = *PLUGINOFFSET(Skin*, c->atomicList[i]->geometry, skinGlobals.offset);
convertRslGeometry(c->atomicList[i]->geometry); convertRslGeometry(c->atomicList[i]->geometry);
if(skin){ if(skin)
c->atomicList[i]->pipeline = skinGlobals.pipelines[rw::platform]; c->atomicList[i]->pipeline = skinGlobals.pipelines[rw::platform];
//generateInvBoneMats(c->atomicList[i]);
}
} }
} }

View File

@ -84,9 +84,10 @@ main(int argc, char *argv[])
for(int32 i = 0; i < c->numAtomics; i++){ for(int32 i = 0; i < c->numAtomics; i++){
Atomic *a = c->atomicList[i]; Atomic *a = c->atomicList[i];
ObjPipeline *p = a->getPipeline(); ObjPipeline *p = a->getPipeline();
if(uninstance) if(uninstance){
p->uninstance(a); p->uninstance(a);
else ps2::unconvertADC(a->geometry);
}else
p->instance(a); p->instance(a);
} }