diff --git a/src/geometry.cpp b/src/geometry.cpp index 62c8fc9..039149b 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -270,6 +271,45 @@ Geometry::addMorphTargets(int32 n) this->numMorphTargets += n; } +void +Geometry::calculateBoundingSphere(void) +{ + for(int32 i = 0; i < this->numMorphTargets; i++){ + MorphTarget *m = &this->morphTargets[i]; + float32 min[3] = { 1000000.0f, 1000000.0f, 1000000.0f }; + float32 max[3] = { -1000000.0f, -1000000.0f, -1000000.0f }; + float32 *v = m->vertices; + for(int32 j = 0; j < this->numVertices; j++){ + if(v[0] > max[0]) max[0] = v[0]; + if(v[0] < min[0]) min[0] = v[0]; + if(v[1] > max[1]) max[1] = v[1]; + if(v[1] < min[1]) min[1] = v[1]; + if(v[2] > max[2]) max[2] = v[2]; + if(v[2] < min[2]) min[2] = v[2]; + v += 3; + } + m->boundingSphere[0] = (min[0] + max[0])/2.0f; + m->boundingSphere[1] = (min[1] + max[1])/2.0f; + m->boundingSphere[2] = (min[2] + max[2])/2.0f; + max[0] -= m->boundingSphere[0]; + max[1] -= m->boundingSphere[1]; + max[2] -= m->boundingSphere[2]; + m->boundingSphere[3] = sqrt(max[0]*max[0] + max[1]*max[1] + max[2]*max[2]); + } +} + +bool32 +Geometry::hasColoredMaterial(void) +{ + for(int32 i = 0; i < this->numMaterials; i++) + if(this->materialList[i]->color[0] != 255 || + this->materialList[i]->color[1] != 255 || + this->materialList[i]->color[2] != 255 || + this->materialList[i]->color[3] != 255) + return 1; + return 0; +} + void Geometry::allocateData(void) { diff --git a/src/mdl.cpp b/src/mdl.cpp index 425c539..730b377 100644 --- a/src/mdl.cpp +++ b/src/mdl.cpp @@ -56,7 +56,7 @@ halfFloat(uint16 half) uint32 f = (uint32)(half & 0x7fff) << 13; uint32 sgn = (uint32)(half & 0x8000) << 16; f += 0x38000000; - if(half & 0x7c00 == 0) f = 0; + if((half & 0x7c00) == 0) f = 0; f |= sgn; return *(float32*)&f; } @@ -239,7 +239,7 @@ convertRslMesh(Geometry *g, RslGeometry *rg, Mesh *m, RslMesh *rm) while(w[0] == 0) w++; /* Insert Data */ - for(uint32 i = 0; i < nvert; i++){ + for(int32 i = 0; i < nvert; i++){ 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]; @@ -322,7 +322,10 @@ convertRslGeometry(Geometry *g) g->meshHeader->totalIndices += meshes[i].numIndices; g->geoflags = Geometry::TRISTRIP | Geometry::POSITIONS | /* 0x01 ? */ - Geometry::TEXTURED; /* 0x04 ? */ + Geometry::TEXTURED | /* 0x04 ? */ + Geometry::LIGHT; + if(g->hasColoredMaterial()) + g->geoflags |= Geometry::MODULATE; if(rg->flags & 0x2) g->geoflags |= Geometry::NORMALS; if(rg->flags & 0x8) @@ -354,6 +357,7 @@ convertRslGeometry(Geometry *g) skin->findNumWeights(g->numVertices); skin->findUsedBones(g->numVertices); } + g->calculateBoundingSphere(); g->generateTriangles(); } @@ -382,6 +386,10 @@ geometryStreamReadRsl(Stream *stream) for(int32 i = 0; i < g->numMaterials; i++){ assert(findChunk(stream, ID_MATERIAL, NULL, NULL)); g->materialList[i] = Material::streamRead(stream); + // fucked somehow + g->materialList[i]->surfaceProps[0] = 1.0f; + g->materialList[i]->surfaceProps[1] = 1.0f; + g->materialList[i]->surfaceProps[2] = 1.0f; } g->streamReadPlugins(stream); diff --git a/src/rwobjects.h b/src/rwobjects.h index 8967d74..ec6e678 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -335,6 +335,8 @@ struct Geometry : PluginBase, Object bool streamWrite(Stream *stream); uint32 streamGetSize(void); void addMorphTargets(int32 n); + void calculateBoundingSphere(void); + bool32 hasColoredMaterial(void); void allocateData(void); void generateTriangles(int8 *adc = NULL);