From d7bd5e76ca86c4ca5f468d39eaecb588e2680e82 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Tue, 23 Apr 2024 23:40:14 +0300 Subject: [PATCH] Move wrapping flag handling to relevant properties --- components/bgsm/file.hpp | 3 +++ components/nif/property.hpp | 6 ++++++ components/nifosg/nifloader.cpp | 22 ++++++++-------------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/components/bgsm/file.hpp b/components/bgsm/file.hpp index d3fb189256..2fe831e918 100644 --- a/components/bgsm/file.hpp +++ b/components/bgsm/file.hpp @@ -51,6 +51,9 @@ namespace Bgsm MaterialFile() = default; virtual void read(BGSMStream& stream); virtual ~MaterialFile() = default; + + bool wrapT() const { return mClamp & 1; } + bool wrapS() const { return mClamp & 2; } }; struct BGSMFile : MaterialFile diff --git a/components/nif/property.hpp b/components/nif/property.hpp index fbc7e8294c..f8798003d3 100644 --- a/components/nif/property.hpp +++ b/components/nif/property.hpp @@ -338,6 +338,9 @@ namespace Nif void read(NIFStream* nif) override; void post(Reader& nif) override; + bool wrapT() const { return mClamp & 1; } + bool wrapS() const { return mClamp & 2; } + bool doubleSided() const { return mShaderFlags2 & BSLSFlag2_DoubleSided; } bool treeAnim() const { return mShaderFlags2 & BSLSFlag2_TreeAnim; } }; @@ -366,6 +369,9 @@ namespace Nif void read(NIFStream* nif) override; + bool wrapT() const { return mClamp & 1; } + bool wrapS() const { return mClamp & 2; } + bool useFalloff() const { return mShaderFlags1 & BSLSFlag1_Falloff; } bool softEffect() const { return mShaderFlags1 & BSLSFlag1_SoftEffect; } bool doubleSided() const { return mShaderFlags2 & BSLSFlag2_DoubleSided; } diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 05a8378c11..0f338aa633 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -2176,8 +2176,8 @@ namespace NifOsg Bgsm::MaterialFilePtr material, osg::StateSet* stateset, std::vector& boundTextures) { const unsigned int uvSet = 0; - const bool wrapS = (material->mClamp >> 1) & 0x1; - const bool wrapT = material->mClamp & 0x1; + const bool wrapS = material->wrapS(); + const bool wrapT = material->wrapT(); if (material->mShaderType == Bgsm::ShaderType::Lighting) { const Bgsm::BGSMFile* bgsm = static_cast(material.get()); @@ -2486,11 +2486,9 @@ namespace NifOsg node->setUserValue("shaderRequired", shaderRequired); osg::StateSet* stateset = node->getOrCreateStateSet(); clearBoundTextures(stateset, boundTextures); - const bool wrapS = (texprop->mClamp >> 1) & 0x1; - const bool wrapT = texprop->mClamp & 0x1; if (!texprop->mTextureSet.empty()) - handleTextureSet( - texprop->mTextureSet.getPtr(), wrapS, wrapT, node->getName(), stateset, boundTextures); + handleTextureSet(texprop->mTextureSet.getPtr(), texprop->wrapS(), texprop->wrapT(), + node->getName(), stateset, boundTextures); handleTextureControllers(texprop, composite, stateset, animflags); if (texprop->refraction()) SceneUtil::setupDistortion(*node, texprop->mRefraction.mStrength); @@ -2534,11 +2532,9 @@ namespace NifOsg handleShaderMaterialNodeProperties(material, stateset, boundTextures); break; } - const bool wrapS = (texprop->mClamp >> 1) & 0x1; - const bool wrapT = texprop->mClamp & 0x1; if (!texprop->mTextureSet.empty()) - handleTextureSet( - texprop->mTextureSet.getPtr(), wrapS, wrapT, node->getName(), stateset, boundTextures); + handleTextureSet(texprop->mTextureSet.getPtr(), texprop->wrapS(), texprop->wrapT(), + node->getName(), stateset, boundTextures); handleTextureControllers(texprop, composite, stateset, animflags); if (texprop->doubleSided()) stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); @@ -2566,11 +2562,9 @@ namespace NifOsg if (!texprop->mSourceTexture.empty()) { const unsigned int uvSet = 0; - const bool wrapS = (texprop->mClamp >> 1) & 0x1; - const bool wrapT = texprop->mClamp & 0x1; unsigned int texUnit = boundTextures.size(); - attachExternalTexture( - "diffuseMap", texprop->mSourceTexture, wrapS, wrapT, uvSet, stateset, boundTextures); + attachExternalTexture("diffuseMap", texprop->mSourceTexture, texprop->wrapS(), texprop->wrapT(), + uvSet, stateset, boundTextures); { osg::ref_ptr texMat(new osg::TexMat); // This handles 20.2.0.7 UV settings like 4.0.0.2 UV settings (see NifOsg::UVController)