Introduce NiGeometry abstraction

pull/578/head
Capostrophic 5 years ago
parent 019c843589
commit b665fed8f2

@ -31,7 +31,7 @@ void NiSkinInstance::post(NIFFile *nif)
} }
} }
void ShapeData::read(NIFStream *nif) void NiGeometryData::read(NIFStream *nif)
{ {
int verts = nif->getUShort(); int verts = nif->getUShort();
@ -69,7 +69,7 @@ void ShapeData::read(NIFStream *nif)
void NiTriShapeData::read(NIFStream *nif) void NiTriShapeData::read(NIFStream *nif)
{ {
ShapeData::read(nif); NiGeometryData::read(nif);
/*int tris =*/ nif->getUShort(); /*int tris =*/ nif->getUShort();
@ -92,7 +92,7 @@ void NiTriShapeData::read(NIFStream *nif)
void NiTriStripsData::read(NIFStream *nif) void NiTriStripsData::read(NIFStream *nif)
{ {
ShapeData::read(nif); NiGeometryData::read(nif);
// Every strip with n points defines n-2 triangles, so this should be unnecessary. // Every strip with n points defines n-2 triangles, so this should be unnecessary.
/*int tris =*/ nif->getUShort(); /*int tris =*/ nif->getUShort();
@ -112,7 +112,7 @@ void NiTriStripsData::read(NIFStream *nif)
void NiAutoNormalParticlesData::read(NIFStream *nif) void NiAutoNormalParticlesData::read(NIFStream *nif)
{ {
ShapeData::read(nif); NiGeometryData::read(nif);
// Should always match the number of vertices // Should always match the number of vertices
numParticles = nif->getUShort(); numParticles = nif->getUShort();

@ -32,7 +32,7 @@ namespace Nif
{ {
// Common ancestor for several data classes // Common ancestor for several data classes
class ShapeData : public Record class NiGeometryData : public Record
{ {
public: public:
std::vector<osg::Vec3f> vertices, normals; std::vector<osg::Vec3f> vertices, normals;
@ -44,7 +44,7 @@ public:
void read(NIFStream *nif); void read(NIFStream *nif);
}; };
class NiTriShapeData : public ShapeData class NiTriShapeData : public NiGeometryData
{ {
public: public:
// Triangles, three vertex indices per triangle // Triangles, three vertex indices per triangle
@ -53,7 +53,7 @@ public:
void read(NIFStream *nif); void read(NIFStream *nif);
}; };
class NiTriStripsData : public ShapeData class NiTriStripsData : public NiGeometryData
{ {
public: public:
// Triangle strips, series of vertex indices. // Triangle strips, series of vertex indices.
@ -62,7 +62,7 @@ public:
void read(NIFStream *nif); void read(NIFStream *nif);
}; };
class NiAutoNormalParticlesData : public ShapeData class NiAutoNormalParticlesData : public NiGeometryData
{ {
public: public:
int numParticles; int numParticles;

@ -128,7 +128,12 @@ struct NiNode : Node
} }
}; };
struct NiTriShape : Node struct NiGeometry : Node
{
NiSkinInstancePtr skin;
};
struct NiTriShape : NiGeometry
{ {
/* Possible flags: /* Possible flags:
0x40 - mesh has no vertex normals ? 0x40 - mesh has no vertex normals ?
@ -138,7 +143,6 @@ struct NiTriShape : Node
*/ */
NiTriShapeDataPtr data; NiTriShapeDataPtr data;
NiSkinInstancePtr skin;
void read(NIFStream *nif) void read(NIFStream *nif)
{ {
@ -157,10 +161,9 @@ struct NiTriShape : Node
} }
}; };
struct NiTriStrips : Node struct NiTriStrips : NiGeometry
{ {
NiTriStripsDataPtr data; NiTriStripsDataPtr data;
NiSkinInstancePtr skin;
void read(NIFStream *nif) void read(NIFStream *nif)
{ {

@ -649,11 +649,7 @@ namespace NifOsg
const bool isMarker = hasMarkers && !nodeName.compare(0, markerName.size(), markerName); const bool isMarker = hasMarkers && !nodeName.compare(0, markerName.size(), markerName);
if (!isMarker && nodeName.compare(0, shadowName.size(), shadowName) && nodeName.compare(0, shadowName2.size(), shadowName2)) if (!isMarker && nodeName.compare(0, shadowName.size(), shadowName) && nodeName.compare(0, shadowName2.size(), shadowName2))
{ {
Nif::NiSkinInstancePtr skin; Nif::NiSkinInstancePtr skin = static_cast<const Nif::NiGeometry*>(nifNode)->skin;
if (nifNode->recType == Nif::RC_NiTriShape)
skin = static_cast<const Nif::NiTriShape*>(nifNode)->skin;
else // if (nifNode->recType == Nif::RC_NiTriStrips)
skin = static_cast<const Nif::NiTriStrips*>(nifNode)->skin;
if (skin.empty()) if (skin.empty())
handleTriShape(nifNode, node, composite, boundTextures, animflags); handleTriShape(nifNode, node, composite, boundTextures, animflags);
@ -1294,12 +1290,7 @@ namespace NifOsg
// Assign bone weights // Assign bone weights
osg::ref_ptr<SceneUtil::RigGeometry::InfluenceMap> map (new SceneUtil::RigGeometry::InfluenceMap); osg::ref_ptr<SceneUtil::RigGeometry::InfluenceMap> map (new SceneUtil::RigGeometry::InfluenceMap);
Nif::NiSkinInstancePtr skinPtr; const Nif::NiSkinInstance *skin = static_cast<const Nif::NiGeometry*>(nifNode)->skin.getPtr();
if (nifNode->recType == Nif::RC_NiTriShape)
skinPtr = static_cast<const Nif::NiTriShape*>(nifNode)->skin;
else
skinPtr = static_cast<const Nif::NiTriStrips*>(nifNode)->skin;
const Nif::NiSkinInstance *skin = skinPtr.getPtr();
const Nif::NiSkinData *data = skin->data.getPtr(); const Nif::NiSkinData *data = skin->data.getPtr();
const Nif::NodeList &bones = skin->bones; const Nif::NodeList &bones = skin->bones;
for(size_t i = 0;i < bones.length();i++) for(size_t i = 0;i < bones.length();i++)

Loading…
Cancel
Save