Refactor NiUVController

macos_ci_fix
Alexei Kotov 1 year ago
parent b0dfd74562
commit ca85820431

@ -287,15 +287,15 @@ namespace Nif
{
Controller::read(nif);
uvSet = nif->getUShort();
data.read(nif);
nif->read(mUvSet);
mData.read(nif);
}
void NiUVController::post(Reader& nif)
{
Controller::post(nif);
data.post(nif);
mData.post(nif);
}
void NiKeyframeController::read(NIFStream* nif)

@ -213,8 +213,8 @@ namespace Nif
struct NiUVController : public Controller
{
NiUVDataPtr data;
unsigned int uvSet;
NiUVDataPtr mData;
uint16_t mUvSet;
void read(NIFStream* nif) override;
void post(Reader& nif) override;

@ -255,9 +255,7 @@ namespace NifOsg
}
}
UVController::UVController() {}
UVController::UVController(const Nif::NiUVData* data, const std::set<int>& textureUnits)
UVController::UVController(const Nif::NiUVData* data, const std::set<unsigned int>& textureUnits)
: mUTrans(data->mKeyList[0], 0.f)
, mVTrans(data->mKeyList[1], 0.f)
, mUScale(data->mKeyList[2], 1.f)
@ -281,8 +279,8 @@ namespace NifOsg
void UVController::setDefaults(osg::StateSet* stateset)
{
osg::ref_ptr<osg::TexMat> texMat(new osg::TexMat);
for (std::set<int>::const_iterator it = mTextureUnits.begin(); it != mTextureUnits.end(); ++it)
stateset->setTextureAttributeAndModes(*it, texMat, osg::StateAttribute::ON);
for (unsigned int unit : mTextureUnits)
stateset->setTextureAttributeAndModes(unit, texMat, osg::StateAttribute::ON);
}
void UVController::apply(osg::StateSet* stateset, osg::NodeVisitor* nv)

@ -262,9 +262,9 @@ namespace NifOsg
class UVController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller
{
public:
UVController();
UVController() = default;
UVController(const UVController&, const osg::CopyOp&);
UVController(const Nif::NiUVData* data, const std::set<int>& textureUnits);
UVController(const Nif::NiUVData* data, const std::set<unsigned int>& textureUnits);
META_Object(NifOsg, UVController)
@ -276,7 +276,7 @@ namespace NifOsg
FloatInterpolator mVTrans;
FloatInterpolator mUScale;
FloatInterpolator mVScale;
std::set<int> mTextureUnits;
std::set<unsigned int> mTextureUnits;
};
class VisController : public SceneUtil::NodeCallback<VisController>, public SceneUtil::Controller

@ -865,18 +865,17 @@ namespace NifOsg
if (ctrl->recType == Nif::RC_NiUVController)
{
const Nif::NiUVController* niuvctrl = static_cast<const Nif::NiUVController*>(ctrl.getPtr());
if (niuvctrl->data.empty())
if (niuvctrl->mData.empty())
continue;
const unsigned int uvSet = niuvctrl->uvSet;
std::set<int> texUnits;
// UVController should work only for textures which use a given UV Set, usually 0.
std::set<unsigned int> texUnits;
// UVController should only work for textures which use the given UV Set.
for (unsigned int i = 0; i < boundTextures.size(); ++i)
{
if (boundTextures[i] == uvSet)
if (boundTextures[i] == niuvctrl->mUvSet)
texUnits.insert(i);
}
osg::ref_ptr<UVController> uvctrl = new UVController(niuvctrl->data.getPtr(), texUnits);
osg::ref_ptr<UVController> uvctrl = new UVController(niuvctrl->mData.getPtr(), texUnits);
setupController(niuvctrl, uvctrl, animflags);
composite->addController(uvctrl);
}

Loading…
Cancel
Save