Use vectors for ShapeData properties

actorid
Chris Robinson 13 years ago
parent ecdd4ee23f
commit 9436ca4b0c

@ -96,7 +96,9 @@ public:
class ShapeData : public Record
{
public:
std::vector<float> vertices, normals, colors, uvlist;
std::vector<Ogre::Vector3> vertices, normals;
std::vector<Ogre::Vector4> colors;
std::vector< std::vector<Ogre::Vector2> > uvlist;
Ogre::Vector3 center;
float radius;
@ -105,16 +107,16 @@ public:
int verts = nif->getUShort();
if(nif->getInt())
nif->getFloats(vertices, verts*3);
nif->getVector3s(vertices, verts);
if(nif->getInt())
nif->getFloats(normals, verts*3);
nif->getVector3s(normals, verts);
center = nif->getVector3();
radius = nif->getFloat();
if(nif->getInt())
nif->getFloats(colors, verts*4);
nif->getVector4s(colors, verts);
// Only the first 6 bits are used as a count. I think the rest are
// flags of some sort.
@ -122,7 +124,11 @@ public:
uvs &= 0x3f;
if(nif->getInt())
nif->getFloats(uvlist, uvs*verts*2);
{
uvlist.resize(uvs);
for(int i = 0;i < uvs;i++)
nif->getVector2s(uvlist[i], verts);
}
}
};

@ -26,6 +26,7 @@
#include <OgreResourceGroupManager.h>
#include <OgreDataStream.h>
#include <OgreVector2.h>
#include <OgreVector3.h>
#include <OgreVector4.h>
#include <OgreMatrix3.h>
@ -142,6 +143,13 @@ public:
unsigned short getUShort() { return read_le16(); }
int getInt() { return read_le32(); }
float getFloat() { return read_le32f(); }
Ogre::Vector2 getVector2()
{
float a[2];
for(size_t i = 0;i < 2;i++)
a[i] = getFloat();
return Ogre::Vector2(a);
}
Ogre::Vector3 getVector3()
{
float a[3];
@ -208,6 +216,24 @@ public:
for(size_t i = 0;i < vec.size();i++)
vec[i] = getFloat();
}
void getVector2s(std::vector<Ogre::Vector2> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector2();
}
void getVector3s(std::vector<Ogre::Vector3> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector3();
}
void getVector4s(std::vector<Ogre::Vector4> &vec, size_t size)
{
vec.resize(size);
for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector4();
}
};

@ -271,19 +271,16 @@ void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags
Nif::NiTriShapeData *data = shape->data.getPtr();
float* vertices = &data->vertices[0];
short* triangles = &data->triangles[0];
const std::vector<Ogre::Vector3> &vertices = data->vertices;
const Ogre::Matrix3 &rot = shape->trafo.rotation;
const Ogre::Vector3 &pos = shape->trafo.pos;
float scale = shape->trafo.scale;
for(unsigned int i=0; i < data->triangles.size(); i = i+3)
float scale = shape->trafo.scale * parentScale;
short* triangles = &data->triangles[0];
for(size_t i = 0;i < data->triangles.size();i+=3)
{
Ogre::Vector3 b1(vertices[triangles[i+0]*3]*parentScale,vertices[triangles[i+0]*3+1]*parentScale,vertices[triangles[i+0]*3+2]*parentScale);
Ogre::Vector3 b2(vertices[triangles[i+1]*3]*parentScale,vertices[triangles[i+1]*3+1]*parentScale,vertices[triangles[i+1]*3+2]*parentScale);
Ogre::Vector3 b3(vertices[triangles[i+2]*3]*parentScale,vertices[triangles[i+2]*3+1]*parentScale,vertices[triangles[i+2]*3+2]*parentScale);
b1 = pos + rot*b1*scale;
b2 = pos + rot*b2*scale;
b3 = pos + rot*b3*scale;
Ogre::Vector3 b1 = pos + rot*vertices[triangles[i+0]]*scale;
Ogre::Vector3 b2 = pos + rot*vertices[triangles[i+1]]*scale;
Ogre::Vector3 b3 = pos + rot*vertices[triangles[i+2]]*scale;
mTriMesh->addTriangle(btVector3(b1.x,b1.y,b1.z),btVector3(b2.x,b2.y,b2.z),btVector3(b3.x,b3.y,b3.z));
}
}

Loading…
Cancel
Save