mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 22:09:42 +00:00
Update NIF property loading, second pass
Refactor all remaining NIF properties
This commit is contained in:
parent
080d7d2c13
commit
c551f23667
3 changed files with 257 additions and 275 deletions
|
@ -423,39 +423,104 @@ namespace Nif
|
|||
}
|
||||
}
|
||||
|
||||
void NiAlphaProperty::read(NIFStream* nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
nif->read(mFlags);
|
||||
nif->read(mThreshold);
|
||||
}
|
||||
|
||||
void NiDitherProperty::read(NIFStream* nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
nif->read(mFlags);
|
||||
}
|
||||
|
||||
void NiFogProperty::read(NIFStream* nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
mFlags = nif->getUShort();
|
||||
mFogDepth = nif->getFloat();
|
||||
mColour = nif->getVector3();
|
||||
nif->read(mFlags);
|
||||
nif->read(mFogDepth);
|
||||
nif->read(mColour);
|
||||
}
|
||||
|
||||
void S_MaterialProperty::read(NIFStream* nif)
|
||||
void NiMaterialProperty::read(NIFStream* nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB_OLD)
|
||||
nif->read(mFlags);
|
||||
if (nif->getBethVersion() < 26)
|
||||
{
|
||||
ambient = nif->getVector3();
|
||||
diffuse = nif->getVector3();
|
||||
nif->read(mAmbient);
|
||||
nif->read(mDiffuse);
|
||||
}
|
||||
specular = nif->getVector3();
|
||||
emissive = nif->getVector3();
|
||||
glossiness = nif->getFloat();
|
||||
alpha = nif->getFloat();
|
||||
nif->read(mSpecular);
|
||||
nif->read(mEmissive);
|
||||
nif->read(mGlossiness);
|
||||
nif->read(mAlpha);
|
||||
if (nif->getBethVersion() >= 22)
|
||||
emissiveMult = nif->getFloat();
|
||||
nif->read(mEmissiveMult);
|
||||
}
|
||||
|
||||
void NiShadeProperty::read(NIFStream* nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3)
|
||||
nif->read(mFlags);
|
||||
}
|
||||
|
||||
void NiSpecularProperty::read(NIFStream* nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
mEnable = nif->get<uint16_t>() & 1;
|
||||
}
|
||||
|
||||
void NiStencilProperty::read(NIFStream* nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
|
||||
{
|
||||
if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB_OLD)
|
||||
nif->read(mFlags);
|
||||
mEnabled = nif->get<uint8_t>() != 0;
|
||||
mTestFunction = static_cast<TestFunc>(nif->get<uint32_t>());
|
||||
nif->read(mStencilRef);
|
||||
nif->read(mStencilMask);
|
||||
mFailAction = static_cast<Action>(nif->get<uint32_t>());
|
||||
mZFailAction = static_cast<Action>(nif->get<uint32_t>());
|
||||
mPassAction = static_cast<Action>(nif->get<uint32_t>());
|
||||
mDrawMode = static_cast<DrawMode>(nif->get<uint32_t>());
|
||||
}
|
||||
else
|
||||
{
|
||||
nif->read(mFlags);
|
||||
mEnabled = mFlags & 0x1;
|
||||
mFailAction = static_cast<Action>((mFlags>> 1) & 0x7);
|
||||
mZFailAction = static_cast<Action>((mFlags >> 4) & 0x7);
|
||||
mPassAction = static_cast<Action>((mFlags >> 7) & 0x7);
|
||||
mDrawMode = static_cast<DrawMode>((mFlags >> 10) & 0x3);
|
||||
mTestFunction = static_cast<TestFunc>((mFlags >> 12) & 0x7);
|
||||
nif->read(mStencilRef);
|
||||
nif->read(mStencilMask);
|
||||
}
|
||||
}
|
||||
|
||||
void NiVertexColorProperty::read(NIFStream* nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
mFlags = nif->getUShort();
|
||||
nif->read(mFlags);
|
||||
if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
|
||||
{
|
||||
mVertexMode = static_cast<VertexMode>(nif->getUInt());
|
||||
mLightingMode = static_cast<LightMode>(nif->getUInt());
|
||||
mVertexMode = static_cast<VertexMode>(nif->get<uint32_t>());
|
||||
mLightingMode = static_cast<LightMode>(nif->get<uint32_t>());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -464,36 +529,23 @@ namespace Nif
|
|||
}
|
||||
}
|
||||
|
||||
void S_AlphaProperty::read(NIFStream* nif)
|
||||
void NiWireframeProperty::read(NIFStream* nif)
|
||||
{
|
||||
threshold = nif->getChar();
|
||||
Property::read(nif);
|
||||
|
||||
mEnable = nif->get<uint16_t>() & 1;
|
||||
}
|
||||
|
||||
void S_StencilProperty::read(NIFStream* nif)
|
||||
void NiZBufferProperty::read(NIFStream* nif)
|
||||
{
|
||||
if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
|
||||
{
|
||||
enabled = nif->getChar();
|
||||
compareFunc = nif->getInt();
|
||||
stencilRef = nif->getUInt();
|
||||
stencilMask = nif->getUInt();
|
||||
failAction = nif->getInt();
|
||||
zFailAction = nif->getInt();
|
||||
zPassAction = nif->getInt();
|
||||
drawMode = nif->getInt();
|
||||
}
|
||||
Property::read(nif);
|
||||
|
||||
nif->read(mFlags);
|
||||
if (nif->getVersion() >= NIFStream::generateVersion(4, 1, 0, 12)
|
||||
&& nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
|
||||
nif->read(mTestFunction);
|
||||
else
|
||||
{
|
||||
unsigned short flags = nif->getUShort();
|
||||
enabled = flags & 0x1;
|
||||
failAction = (flags >> 1) & 0x7;
|
||||
zFailAction = (flags >> 4) & 0x7;
|
||||
zPassAction = (flags >> 7) & 0x7;
|
||||
drawMode = (flags >> 10) & 0x3;
|
||||
compareFunc = (flags >> 12) & 0x7;
|
||||
stencilRef = nif->getUInt();
|
||||
stencilMask = nif->getUInt();
|
||||
}
|
||||
mTestFunction = (mFlags >> 2) & 0x7;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
namespace Nif
|
||||
{
|
||||
|
||||
struct Property : public NiObjectNET
|
||||
struct Property : NiObjectNET
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ namespace Nif
|
|||
void read(NIFStream* nif);
|
||||
};
|
||||
|
||||
struct NiTexturingProperty : public Property
|
||||
struct NiTexturingProperty : Property
|
||||
{
|
||||
enum class ApplyMode : uint32_t
|
||||
{
|
||||
|
@ -86,24 +86,11 @@ namespace Nif
|
|||
void post(Reader& nif) override;
|
||||
};
|
||||
|
||||
struct NiFogProperty : public Property
|
||||
{
|
||||
unsigned short mFlags;
|
||||
float mFogDepth;
|
||||
osg::Vec3f mColour;
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
struct NiShadeProperty : public Property
|
||||
struct NiShadeProperty : Property
|
||||
{
|
||||
uint16_t mFlags{ 0u };
|
||||
void read(NIFStream* nif) override
|
||||
{
|
||||
Property::read(nif);
|
||||
if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3)
|
||||
nif->read(mFlags);
|
||||
}
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
enum class BSShaderType : uint32_t
|
||||
|
@ -140,7 +127,7 @@ namespace Nif
|
|||
void read(NIFStream* nif);
|
||||
};
|
||||
|
||||
struct BSShaderProperty : public NiShadeProperty
|
||||
struct BSShaderProperty : NiShadeProperty
|
||||
{
|
||||
uint32_t mType{ 0u }, mShaderFlags1{ 0u }, mShaderFlags2{ 0u };
|
||||
float mEnvMapScale{ 0.f };
|
||||
|
@ -153,16 +140,17 @@ namespace Nif
|
|||
bool decal() const { return mShaderFlags1 & BSSFlag1_Decal; }
|
||||
};
|
||||
|
||||
struct BSShaderLightingProperty : public BSShaderProperty
|
||||
struct BSShaderLightingProperty : BSShaderProperty
|
||||
{
|
||||
unsigned int mClamp{ 0u };
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
|
||||
bool wrapT() const { return mClamp & 1; }
|
||||
bool wrapS() const { return mClamp & 2; }
|
||||
};
|
||||
|
||||
struct BSShaderPPLightingProperty : public BSShaderLightingProperty
|
||||
struct BSShaderPPLightingProperty : BSShaderLightingProperty
|
||||
{
|
||||
BSShaderTextureSetPtr mTextureSet;
|
||||
BSSPRefractionParams mRefraction;
|
||||
|
@ -172,7 +160,7 @@ namespace Nif
|
|||
void post(Reader& nif) override;
|
||||
};
|
||||
|
||||
struct BSShaderNoLightingProperty : public BSShaderLightingProperty
|
||||
struct BSShaderNoLightingProperty : BSShaderLightingProperty
|
||||
{
|
||||
std::string mFilename;
|
||||
osg::Vec4f mFalloffParams;
|
||||
|
@ -258,7 +246,7 @@ namespace Nif
|
|||
void read(NIFStream* nif);
|
||||
};
|
||||
|
||||
struct BSLightingShaderProperty : public BSShaderProperty
|
||||
struct BSLightingShaderProperty : BSShaderProperty
|
||||
{
|
||||
std::vector<uint32_t> mShaderFlags1Hashes, mShaderFlags2Hashes;
|
||||
osg::Vec2f mUVOffset, mUVScale;
|
||||
|
@ -306,7 +294,7 @@ namespace Nif
|
|||
bool treeAnim() const { return mShaderFlags2 & BSLSFlag2_TreeAnim; }
|
||||
};
|
||||
|
||||
struct BSEffectShaderProperty : public BSShaderProperty
|
||||
struct BSEffectShaderProperty : BSShaderProperty
|
||||
{
|
||||
std::vector<uint32_t> mShaderFlags1Hashes, mShaderFlags2Hashes;
|
||||
osg::Vec2f mUVOffset, mUVScale;
|
||||
|
@ -337,95 +325,24 @@ namespace Nif
|
|||
bool treeAnim() const { return mShaderFlags2 & BSLSFlag2_TreeAnim; }
|
||||
};
|
||||
|
||||
struct NiDitherProperty : public Property
|
||||
struct NiAlphaProperty : Property
|
||||
{
|
||||
unsigned short flags;
|
||||
|
||||
void read(NIFStream* nif) override
|
||||
enum Flags
|
||||
{
|
||||
Property::read(nif);
|
||||
Flag_Blending = 0x0001,
|
||||
Flag_Testing = 0x0200,
|
||||
Flag_NoSorter = 0x2000,
|
||||
};
|
||||
|
||||
flags = nif->getUShort();
|
||||
}
|
||||
};
|
||||
uint16_t mFlags;
|
||||
uint8_t mThreshold;
|
||||
|
||||
struct NiZBufferProperty : public Property
|
||||
{
|
||||
unsigned short flags;
|
||||
unsigned int testFunction;
|
||||
void read(NIFStream* nif) override;
|
||||
|
||||
void read(NIFStream* nif) override
|
||||
{
|
||||
Property::read(nif);
|
||||
bool useAlphaBlending() const { return mFlags & Flag_Blending; }
|
||||
bool useAlphaTesting() const { return mFlags & Flag_Testing; }
|
||||
bool noSorter() const { return mFlags & Flag_NoSorter; }
|
||||
|
||||
flags = nif->getUShort();
|
||||
testFunction = (flags >> 2) & 0x7;
|
||||
if (nif->getVersion() >= NIFStream::generateVersion(4, 1, 0, 12)
|
||||
&& nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
|
||||
testFunction = nif->getUInt();
|
||||
}
|
||||
|
||||
bool depthTest() const { return flags & 1; }
|
||||
|
||||
bool depthWrite() const { return flags & 2; }
|
||||
};
|
||||
|
||||
struct NiSpecularProperty : public Property
|
||||
{
|
||||
unsigned short flags;
|
||||
|
||||
void read(NIFStream* nif) override
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
flags = nif->getUShort();
|
||||
}
|
||||
|
||||
bool isEnabled() const { return flags & 1; }
|
||||
};
|
||||
|
||||
struct NiWireframeProperty : public Property
|
||||
{
|
||||
unsigned short flags;
|
||||
|
||||
void read(NIFStream* nif) override
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
flags = nif->getUShort();
|
||||
}
|
||||
|
||||
bool isEnabled() const { return flags & 1; }
|
||||
};
|
||||
|
||||
// The rest are all struct-based
|
||||
template <typename T>
|
||||
struct StructPropT : Property
|
||||
{
|
||||
T data;
|
||||
unsigned short flags;
|
||||
|
||||
void read(NIFStream* nif) override
|
||||
{
|
||||
Property::read(nif);
|
||||
|
||||
flags = nif->getUShort();
|
||||
data.read(nif);
|
||||
}
|
||||
};
|
||||
|
||||
struct S_MaterialProperty
|
||||
{
|
||||
// The vector components are R,G,B
|
||||
osg::Vec3f ambient{ 1.f, 1.f, 1.f }, diffuse{ 1.f, 1.f, 1.f };
|
||||
osg::Vec3f specular, emissive;
|
||||
float glossiness{ 0.f }, alpha{ 0.f }, emissiveMult{ 1.f };
|
||||
|
||||
void read(NIFStream* nif);
|
||||
};
|
||||
|
||||
struct S_AlphaProperty
|
||||
{
|
||||
/*
|
||||
NiAlphaProperty blend modes (glBlendFunc):
|
||||
0000 GL_ONE
|
||||
|
@ -454,125 +371,131 @@ namespace Nif
|
|||
http://niftools.sourceforge.net/doc/nif/NiAlphaProperty.html
|
||||
*/
|
||||
|
||||
// Tested against when certain flags are set (see above.)
|
||||
unsigned char threshold;
|
||||
|
||||
void read(NIFStream* nif);
|
||||
int sourceBlendMode() const { return (mFlags >> 1) & 0xF; }
|
||||
int destinationBlendMode() const { return (mFlags >> 5) & 0xF; }
|
||||
int alphaTestMode() const { return (mFlags >> 10) & 0x7; }
|
||||
};
|
||||
|
||||
/*
|
||||
Docs taken from:
|
||||
http://niftools.sourceforge.net/doc/nif/NiStencilProperty.html
|
||||
*/
|
||||
struct S_StencilProperty
|
||||
struct NiDitherProperty : Property
|
||||
{
|
||||
// Is stencil test enabled?
|
||||
unsigned char enabled;
|
||||
uint16_t mFlags;
|
||||
|
||||
/*
|
||||
0 TEST_NEVER
|
||||
1 TEST_LESS
|
||||
2 TEST_EQUAL
|
||||
3 TEST_LESS_EQUAL
|
||||
4 TEST_GREATER
|
||||
5 TEST_NOT_EQUAL
|
||||
6 TEST_GREATER_EQUAL
|
||||
7 TEST_NEVER (though nifskope comment says TEST_ALWAYS, but ingame it is TEST_NEVER)
|
||||
*/
|
||||
int compareFunc;
|
||||
unsigned stencilRef;
|
||||
unsigned stencilMask;
|
||||
/*
|
||||
Stencil test fail action, depth test fail action and depth test pass action:
|
||||
0 ACTION_KEEP
|
||||
1 ACTION_ZERO
|
||||
2 ACTION_REPLACE
|
||||
3 ACTION_INCREMENT
|
||||
4 ACTION_DECREMENT
|
||||
5 ACTION_INVERT
|
||||
*/
|
||||
int failAction;
|
||||
int zFailAction;
|
||||
int zPassAction;
|
||||
/*
|
||||
Face draw mode:
|
||||
0 DRAW_CCW_OR_BOTH
|
||||
1 DRAW_CCW [default]
|
||||
2 DRAW_CW
|
||||
3 DRAW_BOTH
|
||||
*/
|
||||
int drawMode;
|
||||
|
||||
void read(NIFStream* nif);
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
struct NiAlphaProperty : public StructPropT<S_AlphaProperty>
|
||||
struct NiFogProperty : Property
|
||||
{
|
||||
enum Flags
|
||||
uint16_t mFlags;
|
||||
float mFogDepth;
|
||||
osg::Vec3f mColour;
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
struct NiMaterialProperty : Property
|
||||
{
|
||||
uint16_t mFlags{ 0u };
|
||||
osg::Vec3f mAmbient{ 1.f, 1.f, 1.f };
|
||||
osg::Vec3f mDiffuse{ 1.f, 1.f, 1.f };
|
||||
osg::Vec3f mSpecular;
|
||||
osg::Vec3f mEmissive;
|
||||
float mGlossiness{ 0.f };
|
||||
float mAlpha{ 0.f };
|
||||
float mEmissiveMult{ 1.f };
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
struct NiSpecularProperty : Property
|
||||
{
|
||||
bool mEnable;
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
struct NiStencilProperty : Property
|
||||
{
|
||||
enum class TestFunc : uint32_t
|
||||
{
|
||||
Flag_Blending = 0x0001,
|
||||
Flag_Testing = 0x0200,
|
||||
Flag_NoSorter = 0x2000,
|
||||
Never = 0,
|
||||
Less = 1,
|
||||
Equal = 2,
|
||||
LessEqual = 3,
|
||||
Greater = 4,
|
||||
NotEqual = 5,
|
||||
GreaterEqual = 6,
|
||||
Always = 7,
|
||||
};
|
||||
|
||||
bool useAlphaBlending() const { return flags & Flag_Blending; }
|
||||
bool useAlphaTesting() const { return flags & Flag_Testing; }
|
||||
bool noSorter() const { return flags & Flag_NoSorter; }
|
||||
enum class Action : uint32_t
|
||||
{
|
||||
Keep = 0,
|
||||
Zero = 1,
|
||||
Replace = 2,
|
||||
Increment = 3,
|
||||
Decrement = 4,
|
||||
Invert = 5,
|
||||
};
|
||||
|
||||
int sourceBlendMode() const { return (flags >> 1) & 0xF; }
|
||||
int destinationBlendMode() const { return (flags >> 5) & 0xF; }
|
||||
int alphaTestMode() const { return (flags >> 10) & 0x7; }
|
||||
enum class DrawMode : uint32_t
|
||||
{
|
||||
Default = 0,
|
||||
CounterClockwise = 1,
|
||||
Clockwise = 2,
|
||||
Both = 3,
|
||||
};
|
||||
|
||||
uint16_t mFlags{ 0u };
|
||||
bool mEnabled;
|
||||
TestFunc mTestFunction;
|
||||
uint32_t mStencilRef;
|
||||
uint32_t mStencilMask;
|
||||
Action mFailAction;
|
||||
Action mZFailAction;
|
||||
Action mPassAction;
|
||||
DrawMode mDrawMode;
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
struct NiVertexColorProperty : public Property
|
||||
struct NiVertexColorProperty : Property
|
||||
{
|
||||
enum class VertexMode : unsigned int
|
||||
enum class VertexMode : uint32_t
|
||||
{
|
||||
VertMode_SrcIgnore = 0,
|
||||
VertMode_SrcEmissive = 1,
|
||||
VertMode_SrcAmbDif = 2
|
||||
};
|
||||
|
||||
enum class LightMode : unsigned int
|
||||
enum class LightMode : uint32_t
|
||||
{
|
||||
LightMode_Emissive = 0,
|
||||
LightMode_EmiAmbDif = 1
|
||||
};
|
||||
|
||||
unsigned short mFlags;
|
||||
uint16_t mFlags;
|
||||
VertexMode mVertexMode;
|
||||
LightMode mLightingMode;
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
struct NiStencilProperty : public Property
|
||||
struct NiWireframeProperty : Property
|
||||
{
|
||||
S_StencilProperty data;
|
||||
unsigned short flags{ 0u };
|
||||
bool mEnable;
|
||||
|
||||
void read(NIFStream* nif) override
|
||||
{
|
||||
Property::read(nif);
|
||||
if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB_OLD)
|
||||
flags = nif->getUShort();
|
||||
data.read(nif);
|
||||
}
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
||||
struct NiMaterialProperty : public Property
|
||||
struct NiZBufferProperty : Property
|
||||
{
|
||||
S_MaterialProperty data;
|
||||
unsigned short flags{ 0u };
|
||||
uint16_t mFlags;
|
||||
uint32_t mTestFunction;
|
||||
|
||||
void read(NIFStream* nif) override
|
||||
{
|
||||
Property::read(nif);
|
||||
if (nif->getVersion() >= NIFStream::generateVersion(3, 0, 0, 0)
|
||||
&& nif->getVersion() <= NIFFile::NIFVersion::VER_OB_OLD)
|
||||
flags = nif->getUShort();
|
||||
data.read(nif);
|
||||
}
|
||||
void read(NIFStream* nif) override;
|
||||
|
||||
bool depthTest() const { return mFlags & 1; }
|
||||
bool depthWrite() const { return mFlags & 2; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -412,7 +412,7 @@ namespace NifOsg
|
|||
{
|
||||
const Nif::NiStencilProperty* stencilprop
|
||||
= static_cast<const Nif::NiStencilProperty*>(property.getPtr());
|
||||
if (stencilprop->data.enabled != 0)
|
||||
if (stencilprop->mEnabled)
|
||||
{
|
||||
hasStencilProperty = true;
|
||||
break;
|
||||
|
@ -1616,50 +1616,52 @@ namespace NifOsg
|
|||
}
|
||||
}
|
||||
|
||||
osg::Stencil::Function getStencilFunction(int func)
|
||||
osg::Stencil::Function getStencilFunction(Nif::NiStencilProperty::TestFunc func)
|
||||
{
|
||||
using TestFunc = Nif::NiStencilProperty::TestFunc;
|
||||
switch (func)
|
||||
{
|
||||
case 0:
|
||||
case TestFunc::Never:
|
||||
return osg::Stencil::NEVER;
|
||||
case 1:
|
||||
case TestFunc::Less:
|
||||
return osg::Stencil::LESS;
|
||||
case 2:
|
||||
case TestFunc::Equal:
|
||||
return osg::Stencil::EQUAL;
|
||||
case 3:
|
||||
case TestFunc::LessEqual:
|
||||
return osg::Stencil::LEQUAL;
|
||||
case 4:
|
||||
case TestFunc::Greater:
|
||||
return osg::Stencil::GREATER;
|
||||
case 5:
|
||||
case TestFunc::NotEqual:
|
||||
return osg::Stencil::NOTEQUAL;
|
||||
case 6:
|
||||
case TestFunc::GreaterEqual:
|
||||
return osg::Stencil::GEQUAL;
|
||||
case 7:
|
||||
case TestFunc::Always:
|
||||
return osg::Stencil::ALWAYS;
|
||||
default:
|
||||
Log(Debug::Info) << "Unexpected stencil function: " << func << " in " << mFilename;
|
||||
Log(Debug::Info) << "Unexpected stencil function: " << static_cast<uint32_t>(func) << " in " << mFilename;
|
||||
return osg::Stencil::NEVER;
|
||||
}
|
||||
}
|
||||
|
||||
osg::Stencil::Operation getStencilOperation(int op)
|
||||
osg::Stencil::Operation getStencilOperation(Nif::NiStencilProperty::Action op)
|
||||
{
|
||||
using Action = Nif::NiStencilProperty::Action;
|
||||
switch (op)
|
||||
{
|
||||
case 0:
|
||||
case Action::Keep:
|
||||
return osg::Stencil::KEEP;
|
||||
case 1:
|
||||
case Action::Zero:
|
||||
return osg::Stencil::ZERO;
|
||||
case 2:
|
||||
case Action::Replace:
|
||||
return osg::Stencil::REPLACE;
|
||||
case 3:
|
||||
case Action::Increment:
|
||||
return osg::Stencil::INCR;
|
||||
case 4:
|
||||
case Action::Decrement:
|
||||
return osg::Stencil::DECR;
|
||||
case 5:
|
||||
case Action::Invert:
|
||||
return osg::Stencil::INVERT;
|
||||
default:
|
||||
Log(Debug::Info) << "Unexpected stencil operation: " << op << " in " << mFilename;
|
||||
Log(Debug::Info) << "Unexpected stencil operation: " << static_cast<uint32_t>(op) << " in " << mFilename;
|
||||
return osg::Stencil::KEEP;
|
||||
}
|
||||
}
|
||||
|
@ -2114,14 +2116,17 @@ namespace NifOsg
|
|||
case Nif::RC_NiStencilProperty:
|
||||
{
|
||||
const Nif::NiStencilProperty* stencilprop = static_cast<const Nif::NiStencilProperty*>(property);
|
||||
|
||||
osg::ref_ptr<osg::FrontFace> frontFace = new osg::FrontFace;
|
||||
switch (stencilprop->data.drawMode)
|
||||
using DrawMode = Nif::NiStencilProperty::DrawMode;
|
||||
switch (stencilprop->mDrawMode)
|
||||
{
|
||||
case 2:
|
||||
case DrawMode::Clockwise:
|
||||
frontFace->setMode(osg::FrontFace::CLOCKWISE);
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
case DrawMode::Default:
|
||||
case DrawMode::CounterClockwise:
|
||||
case DrawMode::Both:
|
||||
default:
|
||||
frontFace->setMode(osg::FrontFace::COUNTER_CLOCKWISE);
|
||||
break;
|
||||
|
@ -2130,20 +2135,20 @@ namespace NifOsg
|
|||
|
||||
osg::StateSet* stateset = node->getOrCreateStateSet();
|
||||
stateset->setAttribute(frontFace, osg::StateAttribute::ON);
|
||||
stateset->setMode(GL_CULL_FACE,
|
||||
stencilprop->data.drawMode == 3 ? osg::StateAttribute::OFF : osg::StateAttribute::ON);
|
||||
if (stencilprop->mDrawMode == DrawMode::Both)
|
||||
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
|
||||
else
|
||||
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
||||
|
||||
if (stencilprop->data.enabled != 0)
|
||||
if (stencilprop->mEnabled)
|
||||
{
|
||||
mHasStencilProperty = true;
|
||||
osg::ref_ptr<osg::Stencil> stencil = new osg::Stencil;
|
||||
stencil->setFunction(getStencilFunction(stencilprop->data.compareFunc),
|
||||
stencilprop->data.stencilRef, stencilprop->data.stencilMask);
|
||||
stencil->setStencilFailOperation(getStencilOperation(stencilprop->data.failAction));
|
||||
stencil->setStencilPassAndDepthFailOperation(
|
||||
getStencilOperation(stencilprop->data.zFailAction));
|
||||
stencil->setStencilPassAndDepthPassOperation(
|
||||
getStencilOperation(stencilprop->data.zPassAction));
|
||||
stencil->setFunction(getStencilFunction(stencilprop->mTestFunction),
|
||||
stencilprop->mStencilRef, stencilprop->mStencilMask);
|
||||
stencil->setStencilFailOperation(getStencilOperation(stencilprop->mFailAction));
|
||||
stencil->setStencilPassAndDepthFailOperation(getStencilOperation(stencilprop->mZFailAction));
|
||||
stencil->setStencilPassAndDepthPassOperation(getStencilOperation(stencilprop->mPassAction));
|
||||
stencil = shareAttribute(stencil);
|
||||
|
||||
stateset->setAttributeAndModes(stencil, osg::StateAttribute::ON);
|
||||
|
@ -2155,7 +2160,7 @@ namespace NifOsg
|
|||
const Nif::NiWireframeProperty* wireprop = static_cast<const Nif::NiWireframeProperty*>(property);
|
||||
osg::ref_ptr<osg::PolygonMode> mode = new osg::PolygonMode;
|
||||
mode->setMode(osg::PolygonMode::FRONT_AND_BACK,
|
||||
wireprop->isEnabled() ? osg::PolygonMode::LINE : osg::PolygonMode::FILL);
|
||||
wireprop->mEnable ? osg::PolygonMode::LINE : osg::PolygonMode::FILL);
|
||||
mode = shareAttribute(mode);
|
||||
node->getOrCreateStateSet()->setAttributeAndModes(mode, osg::StateAttribute::ON);
|
||||
break;
|
||||
|
@ -2395,7 +2400,7 @@ namespace NifOsg
|
|||
// Specular property can turn specular lighting off.
|
||||
// FIXME: NiMaterialColorController doesn't care about this.
|
||||
auto specprop = static_cast<const Nif::NiSpecularProperty*>(property);
|
||||
specEnabled = specprop->isEnabled();
|
||||
specEnabled = specprop->mEnable;
|
||||
break;
|
||||
}
|
||||
case Nif::RC_NiMaterialProperty:
|
||||
|
@ -2403,13 +2408,13 @@ namespace NifOsg
|
|||
const Nif::NiMaterialProperty* matprop = static_cast<const Nif::NiMaterialProperty*>(property);
|
||||
|
||||
mat->setDiffuse(
|
||||
osg::Material::FRONT_AND_BACK, osg::Vec4f(matprop->data.diffuse, matprop->data.alpha));
|
||||
mat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(matprop->data.ambient, 1.f));
|
||||
mat->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(matprop->data.emissive, 1.f));
|
||||
emissiveMult = matprop->data.emissiveMult;
|
||||
osg::Material::FRONT_AND_BACK, osg::Vec4f(matprop->mDiffuse, matprop->mAlpha));
|
||||
mat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(matprop->mAmbient, 1.f));
|
||||
mat->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(matprop->mEmissive, 1.f));
|
||||
emissiveMult = matprop->mEmissiveMult;
|
||||
|
||||
mat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(matprop->data.specular, 1.f));
|
||||
mat->setShininess(osg::Material::FRONT_AND_BACK, matprop->data.glossiness);
|
||||
mat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(matprop->mSpecular, 1.f));
|
||||
mat->setShininess(osg::Material::FRONT_AND_BACK, matprop->mGlossiness);
|
||||
|
||||
if (!matprop->mController.empty())
|
||||
{
|
||||
|
@ -2424,29 +2429,31 @@ namespace NifOsg
|
|||
const Nif::NiVertexColorProperty* vertprop
|
||||
= static_cast<const Nif::NiVertexColorProperty*>(property);
|
||||
|
||||
using VertexMode = Nif::NiVertexColorProperty::VertexMode;
|
||||
switch (vertprop->mVertexMode)
|
||||
{
|
||||
case Nif::NiVertexColorProperty::VertexMode::VertMode_SrcIgnore:
|
||||
case VertexMode::VertMode_SrcIgnore:
|
||||
{
|
||||
mat->setColorMode(osg::Material::OFF);
|
||||
break;
|
||||
}
|
||||
case Nif::NiVertexColorProperty::VertexMode::VertMode_SrcEmissive:
|
||||
case VertexMode::VertMode_SrcEmissive:
|
||||
{
|
||||
mat->setColorMode(osg::Material::EMISSION);
|
||||
break;
|
||||
}
|
||||
case Nif::NiVertexColorProperty::VertexMode::VertMode_SrcAmbDif:
|
||||
case VertexMode::VertMode_SrcAmbDif:
|
||||
{
|
||||
lightmode = vertprop->mLightingMode;
|
||||
using LightMode = Nif::NiVertexColorProperty::LightMode;
|
||||
switch (lightmode)
|
||||
{
|
||||
case Nif::NiVertexColorProperty::LightMode::LightMode_Emissive:
|
||||
case LightMode::LightMode_Emissive:
|
||||
{
|
||||
mat->setColorMode(osg::Material::OFF);
|
||||
break;
|
||||
}
|
||||
case Nif::NiVertexColorProperty::LightMode::LightMode_EmiAmbDif:
|
||||
case LightMode::LightMode_EmiAmbDif:
|
||||
default:
|
||||
{
|
||||
mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
|
||||
|
@ -2499,7 +2506,7 @@ namespace NifOsg
|
|||
if (alphaprop->useAlphaTesting())
|
||||
{
|
||||
osg::ref_ptr<osg::AlphaFunc> alphaFunc(new osg::AlphaFunc(
|
||||
getTestMode(alphaprop->alphaTestMode()), alphaprop->data.threshold / 255.f));
|
||||
getTestMode(alphaprop->alphaTestMode()), alphaprop->mThreshold / 255.f));
|
||||
alphaFunc = shareAttribute(alphaFunc);
|
||||
node->getOrCreateStateSet()->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue