1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00

Move NIF record index back to a separate user object

This makes sure it's never erroneously optimized out. NodeIndexHolders don't need to be cloned as their record index is never supposed to be changed.
This commit is contained in:
Capostrophic 2020-07-12 15:34:22 +03:00
parent f93655e803
commit 46825e8a4d
6 changed files with 55 additions and 12 deletions

View file

@ -7,9 +7,8 @@ namespace NifOsg
{
}
MatrixTransform::MatrixTransform(int recordIndex, const Nif::Transformation &trafo)
MatrixTransform::MatrixTransform(const Nif::Transformation &trafo)
: osg::MatrixTransform(trafo.toMatrix())
, mIndex(recordIndex)
, mScale(trafo.scale)
, mRotationScale(trafo.rotation)
{
@ -17,7 +16,6 @@ namespace NifOsg
MatrixTransform::MatrixTransform(const MatrixTransform &copy, const osg::CopyOp &copyop)
: osg::MatrixTransform(copy, copyop)
, mIndex(copy.mIndex)
, mScale(copy.mScale)
, mRotationScale(copy.mRotationScale)
{

View file

@ -12,7 +12,7 @@ namespace NifOsg
{
public:
MatrixTransform();
MatrixTransform(int recordIndex, const Nif::Transformation &trafo);
MatrixTransform(const Nif::Transformation &trafo);
MatrixTransform(const MatrixTransform &copy, const osg::CopyOp &copyop);
META_Node(NifOsg, MatrixTransform)
@ -29,9 +29,6 @@ namespace NifOsg
// Apply the given translation to OSG matrix.
void setTranslation(const osg::Vec3f& translation);
// NIF record index
int mIndex{0};
private:
// Hack: account for Transform differences between OSG and NIFs.
// OSG uses a 4x4 matrix, NIF's use a 3x3 rotationScale, float scale, and vec3 position.

View file

@ -43,6 +43,7 @@
#include <components/sceneutil/morphgeometry.hpp>
#include "matrixtransform.hpp"
#include "nodeindexholder.hpp"
#include "particle.hpp"
namespace
@ -487,7 +488,7 @@ namespace NifOsg
break;
}
if (!node)
node = new NifOsg::MatrixTransform(nifNode->recIndex, nifNode->trafo);
node = new NifOsg::MatrixTransform(nifNode->trafo);
if (nifNode->recType == Nif::RC_NiCollisionSwitch && !(nifNode->flags & Nif::NiNode::Flag_ActiveCollision))
{
@ -522,6 +523,12 @@ namespace NifOsg
if (!rootNode)
rootNode = node;
// The original NIF record index is used for a variety of features:
// - finding the correct emitter node for a particle system
// - establishing connections to the animated collision shapes, which are handled in a separate loader
// - finding a random child NiNode in NiBspArrayController
node->getOrCreateUserDataContainer()->addUserObject(new NodeIndexHolder(nifNode->recIndex));
for (Nif::ExtraPtr e = nifNode->extra; !e.empty(); e = e->next)
{
if(e->recType == Nif::RC_NiTextKeyExtraData && textKeys)

View file

@ -0,0 +1,35 @@
#ifndef OPENMW_COMPONENTS_NIFOSG_NODEINDEXHOLDER_H
#define OPENMW_COMPONENTS_NIFOSG_NODEINDEXHOLDER_H
#include <osg/Object>
namespace NifOsg
{
class NodeIndexHolder : public osg::Object
{
public:
NodeIndexHolder() = default;
NodeIndexHolder(int index)
: mIndex(index)
{
}
NodeIndexHolder(const NodeIndexHolder& copy, const osg::CopyOp& copyop)
: Object(copy, copyop)
, mIndex(copy.mIndex)
{
}
META_Object(NifOsg, NodeIndexHolder)
int getIndex() const { return mIndex; }
private:
// NIF record index
int mIndex{0};
};
}
#endif

View file

@ -11,7 +11,7 @@
#include <components/nif/controlled.hpp>
#include <components/nif/data.hpp>
#include "matrixtransform.hpp"
#include "nodeindexholder.hpp"
namespace NifOsg
{
@ -381,11 +381,16 @@ void FindGroupByRecIndex::apply(osg::Geometry &node)
void FindGroupByRecIndex::applyNode(osg::Node &searchNode)
{
if (NifOsg::MatrixTransform* trans = dynamic_cast<NifOsg::MatrixTransform*>(&searchNode))
if (searchNode.getUserDataContainer() && searchNode.getUserDataContainer()->getNumUserObjects())
{
if (trans->mIndex == mRecIndex)
NodeIndexHolder* holder = dynamic_cast<NodeIndexHolder*>(searchNode.getUserDataContainer()->getUserObject(0));
if (holder && holder->getIndex() == mRecIndex)
{
mFound = trans;
osg::Group* group = searchNode.asGroup();
if (!group)
group = searchNode.getParent(0);
mFound = group;
mFoundPath = getNodePath();
return;
}

View file

@ -143,6 +143,7 @@ void registerSerializers()
"NifOsg::GeomMorpherController",
"NifOsg::UpdateMorphGeometry",
"NifOsg::UVController",
"NifOsg::NodeIndexHolder",
"osgMyGUI::Drawable",
"osg::DrawCallback",
"osgOQ::ClearQueriesCallback",