Merge branch 'particles' into 'master'

Make NIF particle node handling more generic

See merge request OpenMW/openmw!425
pull/593/head
psi29a 4 years ago
commit 2c6e8eb195

@ -184,7 +184,7 @@ void NiLinesData::read(NIFStream *nif)
} }
} }
void NiAutoNormalParticlesData::read(NIFStream *nif) void NiParticlesData::read(NIFStream *nif)
{ {
NiGeometryData::read(nif); NiGeometryData::read(nif);
@ -216,7 +216,7 @@ void NiAutoNormalParticlesData::read(NIFStream *nif)
void NiRotatingParticlesData::read(NIFStream *nif) void NiRotatingParticlesData::read(NIFStream *nif)
{ {
NiAutoNormalParticlesData::read(nif); NiParticlesData::read(nif);
if (nif->getVersion() <= NIFStream::generateVersion(4,2,2,0) && nif->getBoolean()) if (nif->getVersion() <= NIFStream::generateVersion(4,2,2,0) && nif->getBoolean())
nif->getQuaternions(rotations, vertices.size()); nif->getQuaternions(rotations, vertices.size());

@ -70,7 +70,7 @@ struct NiLinesData : public NiGeometryData
void read(NIFStream *nif) override; void read(NIFStream *nif) override;
}; };
class NiAutoNormalParticlesData : public NiGeometryData class NiParticlesData : public NiGeometryData
{ {
public: public:
int numParticles{0}; int numParticles{0};
@ -84,7 +84,7 @@ public:
void read(NIFStream *nif) override; void read(NIFStream *nif) override;
}; };
class NiRotatingParticlesData : public NiAutoNormalParticlesData class NiRotatingParticlesData : public NiParticlesData
{ {
public: public:
void read(NIFStream *nif) override; void read(NIFStream *nif) override;

@ -47,8 +47,9 @@ static std::map<std::string,RecordFactoryEntry> makeFactory()
factory["NiTriShape"] = {&construct <NiTriShape> , RC_NiTriShape }; factory["NiTriShape"] = {&construct <NiTriShape> , RC_NiTriShape };
factory["NiTriStrips"] = {&construct <NiTriStrips> , RC_NiTriStrips }; factory["NiTriStrips"] = {&construct <NiTriStrips> , RC_NiTriStrips };
factory["NiLines"] = {&construct <NiLines> , RC_NiLines }; factory["NiLines"] = {&construct <NiLines> , RC_NiLines };
factory["NiRotatingParticles"] = {&construct <NiRotatingParticles> , RC_NiRotatingParticles }; factory["NiParticles"] = {&construct <NiParticles> , RC_NiParticles };
factory["NiAutoNormalParticles"] = {&construct <NiAutoNormalParticles> , RC_NiAutoNormalParticles }; factory["NiRotatingParticles"] = {&construct <NiParticles> , RC_NiParticles };
factory["NiAutoNormalParticles"] = {&construct <NiParticles> , RC_NiParticles };
factory["NiCamera"] = {&construct <NiCamera> , RC_NiCamera }; factory["NiCamera"] = {&construct <NiCamera> , RC_NiCamera };
factory["RootCollisionNode"] = {&construct <NiNode> , RC_RootCollisionNode }; factory["RootCollisionNode"] = {&construct <NiNode> , RC_RootCollisionNode };
factory["NiTexturingProperty"] = {&construct <NiTexturingProperty> , RC_NiTexturingProperty }; factory["NiTexturingProperty"] = {&construct <NiTexturingProperty> , RC_NiTexturingProperty };
@ -99,8 +100,9 @@ static std::map<std::string,RecordFactoryEntry> makeFactory()
factory["NiSkinData"] = {&construct <NiSkinData> , RC_NiSkinData }; factory["NiSkinData"] = {&construct <NiSkinData> , RC_NiSkinData };
factory["NiUVData"] = {&construct <NiUVData> , RC_NiUVData }; factory["NiUVData"] = {&construct <NiUVData> , RC_NiUVData };
factory["NiPosData"] = {&construct <NiPosData> , RC_NiPosData }; factory["NiPosData"] = {&construct <NiPosData> , RC_NiPosData };
factory["NiRotatingParticlesData"] = {&construct <NiRotatingParticlesData> , RC_NiRotatingParticlesData }; factory["NiParticlesData"] = {&construct <NiParticlesData> , RC_NiParticlesData };
factory["NiAutoNormalParticlesData"] = {&construct <NiAutoNormalParticlesData> , RC_NiAutoNormalParticlesData }; factory["NiRotatingParticlesData"] = {&construct <NiRotatingParticlesData> , RC_NiParticlesData };
factory["NiAutoNormalParticlesData"] = {&construct <NiParticlesData> , RC_NiParticlesData };
factory["NiSequenceStreamHelper"] = {&construct <NiSequenceStreamHelper> , RC_NiSequenceStreamHelper }; factory["NiSequenceStreamHelper"] = {&construct <NiSequenceStreamHelper> , RC_NiSequenceStreamHelper };
factory["NiSourceTexture"] = {&construct <NiSourceTexture> , RC_NiSourceTexture }; factory["NiSourceTexture"] = {&construct <NiSourceTexture> , RC_NiSourceTexture };
factory["NiSkinInstance"] = {&construct <NiSkinInstance> , RC_NiSkinInstance }; factory["NiSkinInstance"] = {&construct <NiSkinInstance> , RC_NiSkinInstance };

@ -401,39 +401,22 @@ struct NiCamera : Node
} }
}; };
struct NiAutoNormalParticles : Node struct NiParticles : NiGeometry
{ {
NiAutoNormalParticlesDataPtr data; NiParticlesDataPtr data;
void read(NIFStream *nif) override void read(NIFStream *nif) override
{ {
Node::read(nif); Node::read(nif);
data.read(nif); data.read(nif);
nif->getInt(); // -1 skin.read(nif);
} materialData.read(nif);
void post(NIFFile *nif) override
{
Node::post(nif);
data.post(nif);
}
};
struct NiRotatingParticles : Node
{
NiRotatingParticlesDataPtr data;
void read(NIFStream *nif) override
{
Node::read(nif);
data.read(nif);
nif->getInt(); // -1
} }
void post(NIFFile *nif) override void post(NIFFile *nif) override
{ {
Node::post(nif); Node::post(nif);
data.post(nif); data.post(nif);
skin.post(nif);
} }
}; };

@ -44,8 +44,7 @@ enum RecordType
RC_NiTriShape, RC_NiTriShape,
RC_NiTriStrips, RC_NiTriStrips,
RC_NiLines, RC_NiLines,
RC_NiRotatingParticles, RC_NiParticles,
RC_NiAutoNormalParticles,
RC_NiBSParticleNode, RC_NiBSParticleNode,
RC_NiCamera, RC_NiCamera,
RC_NiTexturingProperty, RC_NiTexturingProperty,
@ -94,7 +93,7 @@ enum RecordType
RC_NiUVData, RC_NiUVData,
RC_NiPosData, RC_NiPosData,
RC_NiRotatingParticlesData, RC_NiRotatingParticlesData,
RC_NiAutoNormalParticlesData, RC_NiParticlesData,
RC_NiSequenceStreamHelper, RC_NiSequenceStreamHelper,
RC_NiSourceTexture, RC_NiSourceTexture,
RC_NiSkinInstance, RC_NiSkinInstance,
@ -119,7 +118,7 @@ enum RecordType
RC_NiFloatInterpolator, RC_NiFloatInterpolator,
RC_NiPoint3Interpolator, RC_NiPoint3Interpolator,
RC_NiBoolInterpolator, RC_NiBoolInterpolator,
RC_NiTransformInterpolator, RC_NiTransformInterpolator
}; };
/// Base class for all records /// Base class for all records

@ -138,8 +138,7 @@ class NiTriShapeData;
class NiTriStripsData; class NiTriStripsData;
class NiSkinInstance; class NiSkinInstance;
class NiSourceTexture; class NiSourceTexture;
class NiRotatingParticlesData; class NiParticlesData;
class NiAutoNormalParticlesData;
class NiPalette; class NiPalette;
struct NiParticleModifier; struct NiParticleModifier;
struct NiLinesData; struct NiLinesData;
@ -167,8 +166,7 @@ using NiTriStripsDataPtr = RecordPtrT<NiTriStripsData>;
using NiLinesDataPtr = RecordPtrT<NiLinesData>; using NiLinesDataPtr = RecordPtrT<NiLinesData>;
using NiSkinInstancePtr = RecordPtrT<NiSkinInstance>; using NiSkinInstancePtr = RecordPtrT<NiSkinInstance>;
using NiSourceTexturePtr = RecordPtrT<NiSourceTexture>; using NiSourceTexturePtr = RecordPtrT<NiSourceTexture>;
using NiRotatingParticlesDataPtr = RecordPtrT<NiRotatingParticlesData>; using NiParticlesDataPtr = RecordPtrT<NiParticlesData>;
using NiAutoNormalParticlesDataPtr = RecordPtrT<NiAutoNormalParticlesData>;
using NiPalettePtr = RecordPtrT<NiPalette>; using NiPalettePtr = RecordPtrT<NiPalette>;
using NiParticleModifierPtr = RecordPtrT<NiParticleModifier>; using NiParticleModifierPtr = RecordPtrT<NiParticleModifier>;
using NiBoolDataPtr = RecordPtrT<NiBoolData>; using NiBoolDataPtr = RecordPtrT<NiBoolData>;

@ -638,7 +638,7 @@ namespace NifOsg
} }
} }
if(nifNode->recType == Nif::RC_NiAutoNormalParticles || nifNode->recType == Nif::RC_NiRotatingParticles) if (nifNode->recType == Nif::RC_NiParticles)
handleParticleSystem(nifNode, node, composite, animflags); handleParticleSystem(nifNode, node, composite, animflags);
if (composite->getNumControllers() > 0) if (composite->getNumControllers() > 0)
@ -946,14 +946,12 @@ namespace NifOsg
// Load the initial state of the particle system, i.e. the initial particles and their positions, velocity and colors. // Load the initial state of the particle system, i.e. the initial particles and their positions, velocity and colors.
void handleParticleInitialState(const Nif::Node* nifNode, osgParticle::ParticleSystem* partsys, const Nif::NiParticleSystemController* partctrl) void handleParticleInitialState(const Nif::Node* nifNode, osgParticle::ParticleSystem* partsys, const Nif::NiParticleSystemController* partctrl)
{ {
const Nif::NiAutoNormalParticlesData *particledata = nullptr; const auto particleNode = static_cast<const Nif::NiParticles*>(nifNode);
if(nifNode->recType == Nif::RC_NiAutoNormalParticles) if (particleNode->data.empty())
particledata = static_cast<const Nif::NiAutoNormalParticles*>(nifNode)->data.getPtr();
else if(nifNode->recType == Nif::RC_NiRotatingParticles)
particledata = static_cast<const Nif::NiRotatingParticles*>(nifNode)->data.getPtr();
else
return; return;
const Nif::NiParticlesData* particledata = particleNode->data.getPtr();
osg::BoundingBox box; osg::BoundingBox box;
int i=0; int i=0;

Loading…
Cancel
Save