mirror of
https://github.com/aap/librw.git
synced 2025-04-20 00:27:15 +01:00
more fixes
This commit is contained in:
parent
3aca9c9c7d
commit
b7ec874b25
@ -2,6 +2,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
@ -270,6 +271,45 @@ Geometry::addMorphTargets(int32 n)
|
|||||||
this->numMorphTargets += 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
|
void
|
||||||
Geometry::allocateData(void)
|
Geometry::allocateData(void)
|
||||||
{
|
{
|
||||||
|
14
src/mdl.cpp
14
src/mdl.cpp
@ -56,7 +56,7 @@ halfFloat(uint16 half)
|
|||||||
uint32 f = (uint32)(half & 0x7fff) << 13;
|
uint32 f = (uint32)(half & 0x7fff) << 13;
|
||||||
uint32 sgn = (uint32)(half & 0x8000) << 16;
|
uint32 sgn = (uint32)(half & 0x8000) << 16;
|
||||||
f += 0x38000000;
|
f += 0x38000000;
|
||||||
if(half & 0x7c00 == 0) f = 0;
|
if((half & 0x7c00) == 0) f = 0;
|
||||||
f |= sgn;
|
f |= sgn;
|
||||||
return *(float32*)&f;
|
return *(float32*)&f;
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ convertRslMesh(Geometry *g, RslGeometry *rg, Mesh *m, RslMesh *rm)
|
|||||||
while(w[0] == 0) w++;
|
while(w[0] == 0) w++;
|
||||||
|
|
||||||
/* Insert Data */
|
/* 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[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[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.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->meshHeader->totalIndices += meshes[i].numIndices;
|
||||||
g->geoflags = Geometry::TRISTRIP |
|
g->geoflags = Geometry::TRISTRIP |
|
||||||
Geometry::POSITIONS | /* 0x01 ? */
|
Geometry::POSITIONS | /* 0x01 ? */
|
||||||
Geometry::TEXTURED; /* 0x04 ? */
|
Geometry::TEXTURED | /* 0x04 ? */
|
||||||
|
Geometry::LIGHT;
|
||||||
|
if(g->hasColoredMaterial())
|
||||||
|
g->geoflags |= Geometry::MODULATE;
|
||||||
if(rg->flags & 0x2)
|
if(rg->flags & 0x2)
|
||||||
g->geoflags |= Geometry::NORMALS;
|
g->geoflags |= Geometry::NORMALS;
|
||||||
if(rg->flags & 0x8)
|
if(rg->flags & 0x8)
|
||||||
@ -354,6 +357,7 @@ convertRslGeometry(Geometry *g)
|
|||||||
skin->findNumWeights(g->numVertices);
|
skin->findNumWeights(g->numVertices);
|
||||||
skin->findUsedBones(g->numVertices);
|
skin->findUsedBones(g->numVertices);
|
||||||
}
|
}
|
||||||
|
g->calculateBoundingSphere();
|
||||||
g->generateTriangles();
|
g->generateTriangles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,6 +386,10 @@ geometryStreamReadRsl(Stream *stream)
|
|||||||
for(int32 i = 0; i < g->numMaterials; i++){
|
for(int32 i = 0; i < g->numMaterials; i++){
|
||||||
assert(findChunk(stream, ID_MATERIAL, NULL, NULL));
|
assert(findChunk(stream, ID_MATERIAL, NULL, NULL));
|
||||||
g->materialList[i] = Material::streamRead(stream);
|
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);
|
g->streamReadPlugins(stream);
|
||||||
|
@ -335,6 +335,8 @@ struct Geometry : PluginBase<Geometry>, Object
|
|||||||
bool streamWrite(Stream *stream);
|
bool streamWrite(Stream *stream);
|
||||||
uint32 streamGetSize(void);
|
uint32 streamGetSize(void);
|
||||||
void addMorphTargets(int32 n);
|
void addMorphTargets(int32 n);
|
||||||
|
void calculateBoundingSphere(void);
|
||||||
|
bool32 hasColoredMaterial(void);
|
||||||
void allocateData(void);
|
void allocateData(void);
|
||||||
void generateTriangles(int8 *adc = NULL);
|
void generateTriangles(int8 *adc = NULL);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user