mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Refactor NiUVController
This commit is contained in:
parent
b0dfd74562
commit
ca85820431
@ -287,15 +287,15 @@ namespace Nif
|
|||||||
{
|
{
|
||||||
Controller::read(nif);
|
Controller::read(nif);
|
||||||
|
|
||||||
uvSet = nif->getUShort();
|
nif->read(mUvSet);
|
||||||
data.read(nif);
|
mData.read(nif);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NiUVController::post(Reader& nif)
|
void NiUVController::post(Reader& nif)
|
||||||
{
|
{
|
||||||
Controller::post(nif);
|
Controller::post(nif);
|
||||||
|
|
||||||
data.post(nif);
|
mData.post(nif);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NiKeyframeController::read(NIFStream* nif)
|
void NiKeyframeController::read(NIFStream* nif)
|
||||||
|
@ -213,8 +213,8 @@ namespace Nif
|
|||||||
|
|
||||||
struct NiUVController : public Controller
|
struct NiUVController : public Controller
|
||||||
{
|
{
|
||||||
NiUVDataPtr data;
|
NiUVDataPtr mData;
|
||||||
unsigned int uvSet;
|
uint16_t mUvSet;
|
||||||
|
|
||||||
void read(NIFStream* nif) override;
|
void read(NIFStream* nif) override;
|
||||||
void post(Reader& nif) override;
|
void post(Reader& nif) override;
|
||||||
|
@ -255,9 +255,7 @@ namespace NifOsg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UVController::UVController() {}
|
UVController::UVController(const Nif::NiUVData* data, const std::set<unsigned int>& textureUnits)
|
||||||
|
|
||||||
UVController::UVController(const Nif::NiUVData* data, const std::set<int>& textureUnits)
|
|
||||||
: mUTrans(data->mKeyList[0], 0.f)
|
: mUTrans(data->mKeyList[0], 0.f)
|
||||||
, mVTrans(data->mKeyList[1], 0.f)
|
, mVTrans(data->mKeyList[1], 0.f)
|
||||||
, mUScale(data->mKeyList[2], 1.f)
|
, mUScale(data->mKeyList[2], 1.f)
|
||||||
@ -281,8 +279,8 @@ namespace NifOsg
|
|||||||
void UVController::setDefaults(osg::StateSet* stateset)
|
void UVController::setDefaults(osg::StateSet* stateset)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::TexMat> texMat(new osg::TexMat);
|
osg::ref_ptr<osg::TexMat> texMat(new osg::TexMat);
|
||||||
for (std::set<int>::const_iterator it = mTextureUnits.begin(); it != mTextureUnits.end(); ++it)
|
for (unsigned int unit : mTextureUnits)
|
||||||
stateset->setTextureAttributeAndModes(*it, texMat, osg::StateAttribute::ON);
|
stateset->setTextureAttributeAndModes(unit, texMat, osg::StateAttribute::ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UVController::apply(osg::StateSet* stateset, osg::NodeVisitor* nv)
|
void UVController::apply(osg::StateSet* stateset, osg::NodeVisitor* nv)
|
||||||
|
@ -262,9 +262,9 @@ namespace NifOsg
|
|||||||
class UVController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller
|
class UVController : public SceneUtil::StateSetUpdater, public SceneUtil::Controller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UVController();
|
UVController() = default;
|
||||||
UVController(const UVController&, const osg::CopyOp&);
|
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)
|
META_Object(NifOsg, UVController)
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ namespace NifOsg
|
|||||||
FloatInterpolator mVTrans;
|
FloatInterpolator mVTrans;
|
||||||
FloatInterpolator mUScale;
|
FloatInterpolator mUScale;
|
||||||
FloatInterpolator mVScale;
|
FloatInterpolator mVScale;
|
||||||
std::set<int> mTextureUnits;
|
std::set<unsigned int> mTextureUnits;
|
||||||
};
|
};
|
||||||
|
|
||||||
class VisController : public SceneUtil::NodeCallback<VisController>, public SceneUtil::Controller
|
class VisController : public SceneUtil::NodeCallback<VisController>, public SceneUtil::Controller
|
||||||
|
@ -865,18 +865,17 @@ namespace NifOsg
|
|||||||
if (ctrl->recType == Nif::RC_NiUVController)
|
if (ctrl->recType == Nif::RC_NiUVController)
|
||||||
{
|
{
|
||||||
const Nif::NiUVController* niuvctrl = static_cast<const Nif::NiUVController*>(ctrl.getPtr());
|
const Nif::NiUVController* niuvctrl = static_cast<const Nif::NiUVController*>(ctrl.getPtr());
|
||||||
if (niuvctrl->data.empty())
|
if (niuvctrl->mData.empty())
|
||||||
continue;
|
continue;
|
||||||
const unsigned int uvSet = niuvctrl->uvSet;
|
std::set<unsigned int> texUnits;
|
||||||
std::set<int> texUnits;
|
// UVController should only work for textures which use the given UV Set.
|
||||||
// UVController should work only for textures which use a given UV Set, usually 0.
|
|
||||||
for (unsigned int i = 0; i < boundTextures.size(); ++i)
|
for (unsigned int i = 0; i < boundTextures.size(); ++i)
|
||||||
{
|
{
|
||||||
if (boundTextures[i] == uvSet)
|
if (boundTextures[i] == niuvctrl->mUvSet)
|
||||||
texUnits.insert(i);
|
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);
|
setupController(niuvctrl, uvctrl, animflags);
|
||||||
composite->addController(uvctrl);
|
composite->addController(uvctrl);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user