mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 06:53:52 +00:00
Merge pull request #2547 from Capostrophic/nif2
More minor NIF improvements
This commit is contained in:
commit
f666d796e9
6 changed files with 74 additions and 86 deletions
|
@ -112,7 +112,7 @@ class NiUVController : public Controller
|
|||
{
|
||||
public:
|
||||
NiUVDataPtr data;
|
||||
int uvSet;
|
||||
unsigned int uvSet;
|
||||
|
||||
void read(NIFStream *nif);
|
||||
void post(NIFFile *nif);
|
||||
|
|
|
@ -102,12 +102,12 @@ void NiTriStripsData::read(NIFStream *nif)
|
|||
std::vector<unsigned short> lengths;
|
||||
nif->getUShorts(lengths, numStrips);
|
||||
|
||||
if (!numStrips)
|
||||
return;
|
||||
|
||||
strips.resize(numStrips);
|
||||
for (int i = 0; i < numStrips; i++)
|
||||
{
|
||||
std::vector<unsigned short> strip;
|
||||
nif->getUShorts(strip, lengths[i]);
|
||||
strips.emplace_back(strip);
|
||||
}
|
||||
nif->getUShorts(strips[i], lengths[i]);
|
||||
}
|
||||
|
||||
void NiAutoNormalParticlesData::read(NIFStream *nif)
|
||||
|
|
|
@ -18,14 +18,13 @@ void NiTexturingProperty::Texture::read(NIFStream *nif)
|
|||
if(!inUse) return;
|
||||
|
||||
texture.read(nif);
|
||||
clamp = nif->getInt();
|
||||
filter = nif->getInt();
|
||||
uvSet = nif->getInt();
|
||||
clamp = nif->getUInt();
|
||||
nif->skip(4); // Filter mode. Ignoring because global filtering settings are more sensible
|
||||
uvSet = nif->getUInt();
|
||||
|
||||
// I have no idea, but I think these are actually two
|
||||
// PS2-specific shorts (ps2L and ps2K), followed by an unknown
|
||||
// short.
|
||||
nif->skip(6);
|
||||
// Two PS2-specific shorts.
|
||||
nif->skip(4);
|
||||
nif->skip(2); // Unknown short
|
||||
}
|
||||
|
||||
void NiTexturingProperty::Texture::post(NIFFile *nif)
|
||||
|
@ -36,26 +35,25 @@ void NiTexturingProperty::Texture::post(NIFFile *nif)
|
|||
void NiTexturingProperty::read(NIFStream *nif)
|
||||
{
|
||||
Property::read(nif);
|
||||
apply = nif->getInt();
|
||||
apply = nif->getUInt();
|
||||
|
||||
// Unknown, always 7. Probably the number of textures to read
|
||||
// below
|
||||
nif->getInt();
|
||||
unsigned int numTextures = nif->getUInt();
|
||||
|
||||
textures[0].read(nif); // Base
|
||||
textures[1].read(nif); // Dark
|
||||
textures[2].read(nif); // Detail
|
||||
textures[3].read(nif); // Gloss (never present)
|
||||
textures[4].read(nif); // Glow
|
||||
textures[5].read(nif); // Bump map
|
||||
if(textures[5].inUse)
|
||||
if (!numTextures)
|
||||
return;
|
||||
|
||||
textures.resize(numTextures);
|
||||
for (unsigned int i = 0; i < numTextures; i++)
|
||||
{
|
||||
textures[i].read(nif);
|
||||
// Ignore these at the moment
|
||||
/*float lumaScale =*/ nif->getFloat();
|
||||
/*float lumaOffset =*/ nif->getFloat();
|
||||
/*const Vector4 *lumaMatrix =*/ nif->getVector4();
|
||||
if (i == 5 && textures[5].inUse) // Bump map settings
|
||||
{
|
||||
/*float lumaScale =*/ nif->getFloat();
|
||||
/*float lumaOffset =*/ nif->getFloat();
|
||||
/*const Vector4 *lumaMatrix =*/ nif->getVector4();
|
||||
}
|
||||
}
|
||||
textures[6].read(nif); // Decal
|
||||
}
|
||||
|
||||
void NiTexturingProperty::post(NIFFile *nif)
|
||||
|
|
|
@ -51,17 +51,10 @@ public:
|
|||
3 - wrapS wrapT
|
||||
*/
|
||||
|
||||
/* Filter:
|
||||
0 - nearest
|
||||
1 - bilinear
|
||||
2 - trilinear
|
||||
3, 4, 5 - who knows
|
||||
*/
|
||||
bool inUse;
|
||||
NiSourceTexturePtr texture;
|
||||
|
||||
int clamp, uvSet, filter;
|
||||
short unknown2;
|
||||
unsigned int clamp, uvSet;
|
||||
|
||||
void read(NIFStream *nif);
|
||||
void post(NIFFile *nif);
|
||||
|
@ -74,7 +67,7 @@ public:
|
|||
3 - hilight // These two are for PS2 only?
|
||||
4 - hilight2
|
||||
*/
|
||||
int apply;
|
||||
unsigned int apply;
|
||||
|
||||
/*
|
||||
* The textures in this list are as follows:
|
||||
|
@ -82,7 +75,7 @@ public:
|
|||
* 0 - Base texture
|
||||
* 1 - Dark texture
|
||||
* 2 - Detail texture
|
||||
* 3 - Gloss texture (never used?)
|
||||
* 3 - Gloss texture
|
||||
* 4 - Glow texture
|
||||
* 5 - Bump map texture
|
||||
* 6 - Decal texture
|
||||
|
@ -96,10 +89,9 @@ public:
|
|||
GlowTexture = 4,
|
||||
BumpTexture = 5,
|
||||
DecalTexture = 6,
|
||||
NumTextures = 7 // Sentry value
|
||||
};
|
||||
|
||||
Texture textures[7];
|
||||
std::vector<Texture> textures;
|
||||
|
||||
void read(NIFStream *nif);
|
||||
void post(NIFFile *nif);
|
||||
|
|
|
@ -143,31 +143,31 @@ class NiAutoNormalParticlesData;
|
|||
class NiPalette;
|
||||
struct NiParticleModifier;
|
||||
|
||||
typedef RecordPtrT<Node> NodePtr;
|
||||
typedef RecordPtrT<Extra> ExtraPtr;
|
||||
typedef RecordPtrT<NiUVData> NiUVDataPtr;
|
||||
typedef RecordPtrT<NiPosData> NiPosDataPtr;
|
||||
typedef RecordPtrT<NiVisData> NiVisDataPtr;
|
||||
typedef RecordPtrT<Controller> ControllerPtr;
|
||||
typedef RecordPtrT<Named> NamedPtr;
|
||||
typedef RecordPtrT<NiSkinData> NiSkinDataPtr;
|
||||
typedef RecordPtrT<NiMorphData> NiMorphDataPtr;
|
||||
typedef RecordPtrT<NiPixelData> NiPixelDataPtr;
|
||||
typedef RecordPtrT<NiFloatData> NiFloatDataPtr;
|
||||
typedef RecordPtrT<NiColorData> NiColorDataPtr;
|
||||
typedef RecordPtrT<NiKeyframeData> NiKeyframeDataPtr;
|
||||
typedef RecordPtrT<NiTriShapeData> NiTriShapeDataPtr;
|
||||
typedef RecordPtrT<NiTriStripsData> NiTriStripsDataPtr;
|
||||
typedef RecordPtrT<NiSkinInstance> NiSkinInstancePtr;
|
||||
typedef RecordPtrT<NiSourceTexture> NiSourceTexturePtr;
|
||||
typedef RecordPtrT<NiRotatingParticlesData> NiRotatingParticlesDataPtr;
|
||||
typedef RecordPtrT<NiAutoNormalParticlesData> NiAutoNormalParticlesDataPtr;
|
||||
typedef RecordPtrT<NiPalette> NiPalettePtr;
|
||||
typedef RecordPtrT<NiParticleModifier> NiParticleModifierPtr;
|
||||
using NodePtr = RecordPtrT<Node>;
|
||||
using ExtraPtr = RecordPtrT<Extra>;
|
||||
using NiUVDataPtr = RecordPtrT<NiUVData>;
|
||||
using NiPosDataPtr = RecordPtrT<NiPosData>;
|
||||
using NiVisDataPtr = RecordPtrT<NiVisData>;
|
||||
using ControllerPtr = RecordPtrT<Controller>;
|
||||
using NamedPtr = RecordPtrT<Named>;
|
||||
using NiSkinDataPtr = RecordPtrT<NiSkinData>;
|
||||
using NiMorphDataPtr = RecordPtrT<NiMorphData>;
|
||||
using NiPixelDataPtr = RecordPtrT<NiPixelData>;
|
||||
using NiFloatDataPtr = RecordPtrT<NiFloatData>;
|
||||
using NiColorDataPtr = RecordPtrT<NiColorData>;
|
||||
using NiKeyframeDataPtr = RecordPtrT<NiKeyframeData>;
|
||||
using NiTriShapeDataPtr = RecordPtrT<NiTriShapeData>;
|
||||
using NiTriStripsDataPtr = RecordPtrT<NiTriStripsData>;
|
||||
using NiSkinInstancePtr = RecordPtrT<NiSkinInstance>;
|
||||
using NiSourceTexturePtr = RecordPtrT<NiSourceTexture>;
|
||||
using NiRotatingParticlesDataPtr = RecordPtrT<NiRotatingParticlesData>;
|
||||
using NiAutoNormalParticlesDataPtr = RecordPtrT<NiAutoNormalParticlesData>;
|
||||
using NiPalettePtr = RecordPtrT<NiPalette>;
|
||||
using NiParticleModifierPtr = RecordPtrT<NiParticleModifier>;
|
||||
|
||||
typedef RecordListT<Node> NodeList;
|
||||
typedef RecordListT<Property> PropertyList;
|
||||
typedef RecordListT<NiSourceTexture> NiSourceTextureList;
|
||||
using NodeList = RecordListT<Node>;
|
||||
using PropertyList = RecordListT<Property>;
|
||||
using NiSourceTextureList = RecordListT<NiSourceTexture>;
|
||||
|
||||
} // Namespace
|
||||
#endif
|
||||
|
|
|
@ -262,7 +262,7 @@ namespace NifOsg
|
|||
|
||||
osg::ref_ptr<TextKeyMapHolder> textkeys (new TextKeyMapHolder);
|
||||
|
||||
osg::ref_ptr<osg::Node> created = handleNode(nifNode, nullptr, imageManager, std::vector<int>(), 0, false, false, false, &textkeys->mTextKeys);
|
||||
osg::ref_ptr<osg::Node> created = handleNode(nifNode, nullptr, imageManager, std::vector<unsigned int>(), 0, false, false, false, &textkeys->mTextKeys);
|
||||
|
||||
if (nif->getUseSkinning())
|
||||
{
|
||||
|
@ -288,7 +288,7 @@ namespace NifOsg
|
|||
return created;
|
||||
}
|
||||
|
||||
void applyNodeProperties(const Nif::Node *nifNode, osg::Node *applyTo, SceneUtil::CompositeStateSetUpdater* composite, Resource::ImageManager* imageManager, std::vector<int>& boundTextures, int animflags)
|
||||
void applyNodeProperties(const Nif::Node *nifNode, osg::Node *applyTo, SceneUtil::CompositeStateSetUpdater* composite, Resource::ImageManager* imageManager, std::vector<unsigned int>& boundTextures, int animflags)
|
||||
{
|
||||
const Nif::PropertyList& props = nifNode->props;
|
||||
for (size_t i = 0; i <props.length(); ++i)
|
||||
|
@ -405,9 +405,8 @@ namespace NifOsg
|
|||
if (image)
|
||||
texture2d->setTextureSize(image->s(), image->t());
|
||||
texture2d->setName("envMap");
|
||||
unsigned int clamp = static_cast<unsigned int>(textureEffect->clamp);
|
||||
int wrapT = (clamp) & 0x1;
|
||||
int wrapS = (clamp >> 1) & 0x1;
|
||||
bool wrapT = textureEffect->clamp & 0x1;
|
||||
bool wrapS = (textureEffect->clamp >> 1) & 0x1;
|
||||
texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
|
||||
texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
|
@ -492,7 +491,7 @@ namespace NifOsg
|
|||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> handleNode(const Nif::Node* nifNode, osg::Group* parentNode, Resource::ImageManager* imageManager,
|
||||
std::vector<int> boundTextures, int animflags, bool skipMeshes, bool hasMarkers, bool isAnimated, TextKeyMap* textKeys, osg::Node* rootNode=nullptr)
|
||||
std::vector<unsigned int> boundTextures, int animflags, bool skipMeshes, bool hasMarkers, bool isAnimated, TextKeyMap* textKeys, osg::Node* rootNode=nullptr)
|
||||
{
|
||||
if (rootNode != nullptr && Misc::StringUtils::ciEqual(nifNode->name, "Bounding Box"))
|
||||
return nullptr;
|
||||
|
@ -657,7 +656,7 @@ namespace NifOsg
|
|||
return node;
|
||||
}
|
||||
|
||||
void handleMeshControllers(const Nif::Node *nifNode, osg::Node* node, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<int> &boundTextures, int animflags)
|
||||
void handleMeshControllers(const Nif::Node *nifNode, osg::Node* node, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int> &boundTextures, int animflags)
|
||||
{
|
||||
for (Nif::ControllerPtr ctrl = nifNode->controller; !ctrl.empty(); ctrl = ctrl->next)
|
||||
{
|
||||
|
@ -666,7 +665,7 @@ namespace NifOsg
|
|||
if (ctrl->recType == Nif::RC_NiUVController)
|
||||
{
|
||||
const Nif::NiUVController *niuvctrl = static_cast<const Nif::NiUVController*>(ctrl.getPtr());
|
||||
const int uvSet = niuvctrl->uvSet;
|
||||
const unsigned int uvSet = niuvctrl->uvSet;
|
||||
std::set<int> texUnits;
|
||||
// UVController should work only for textures which use a given UV Set, usually 0.
|
||||
for (unsigned int i=0; i<boundTextures.size(); ++i)
|
||||
|
@ -1047,7 +1046,7 @@ namespace NifOsg
|
|||
}
|
||||
}
|
||||
|
||||
void triCommonToGeometry(osg::Geometry *geometry, const std::vector<osg::Vec3f>& vertices, const std::vector<osg::Vec3f>& normals, const std::vector<std::vector<osg::Vec2f>>& uvlist, const std::vector<osg::Vec4f>& colors, const std::vector<int>& boundTextures, const std::string& name)
|
||||
void triCommonToGeometry(osg::Geometry *geometry, const std::vector<osg::Vec3f>& vertices, const std::vector<osg::Vec3f>& normals, const std::vector<std::vector<osg::Vec2f>>& uvlist, const std::vector<osg::Vec4f>& colors, const std::vector<unsigned int>& boundTextures, const std::string& name)
|
||||
{
|
||||
if (!vertices.empty())
|
||||
geometry->setVertexArray(new osg::Vec3Array(vertices.size(), vertices.data()));
|
||||
|
@ -1057,9 +1056,9 @@ namespace NifOsg
|
|||
geometry->setColorArray(new osg::Vec4Array(colors.size(), colors.data()), osg::Array::BIND_PER_VERTEX);
|
||||
|
||||
int textureStage = 0;
|
||||
for (const int uvSet : boundTextures)
|
||||
for (const unsigned int uvSet : boundTextures)
|
||||
{
|
||||
if (uvSet >= (int)uvlist.size())
|
||||
if (uvSet >= uvlist.size())
|
||||
{
|
||||
Log(Debug::Verbose) << "Out of bounds UV set " << uvSet << " on shape \"" << name << "\" in " << mFilename;
|
||||
if (!uvlist.empty())
|
||||
|
@ -1072,7 +1071,7 @@ namespace NifOsg
|
|||
}
|
||||
}
|
||||
|
||||
void triShapeToGeometry(const Nif::Node *nifNode, osg::Geometry *geometry, osg::Node* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<int>& boundTextures, int animflags)
|
||||
void triShapeToGeometry(const Nif::Node *nifNode, osg::Geometry *geometry, osg::Node* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures, int animflags)
|
||||
{
|
||||
bool vertexColorsPresent = false;
|
||||
if (nifNode->recType == Nif::RC_NiTriShape)
|
||||
|
@ -1119,7 +1118,7 @@ namespace NifOsg
|
|||
applyDrawableProperties(parentNode, drawableProps, composite, vertexColorsPresent, animflags, false);
|
||||
}
|
||||
|
||||
void handleTriShape(const Nif::Node* nifNode, osg::Group* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<int>& boundTextures, int animflags)
|
||||
void handleTriShape(const Nif::Node* nifNode, osg::Group* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures, int animflags)
|
||||
{
|
||||
assert(nifNode->recType == Nif::RC_NiTriShape || nifNode->recType == Nif::RC_NiTriStrips);
|
||||
osg::ref_ptr<osg::Drawable> drawable;
|
||||
|
@ -1151,7 +1150,7 @@ namespace NifOsg
|
|||
parentNode->addChild(drawable);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Drawable> handleMorphGeometry(const Nif::NiGeomMorpherController* morpher, osg::ref_ptr<osg::Geometry> sourceGeometry, osg::Node* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<int>& boundTextures, int animflags)
|
||||
osg::ref_ptr<osg::Drawable> handleMorphGeometry(const Nif::NiGeomMorpherController* morpher, osg::ref_ptr<osg::Geometry> sourceGeometry, osg::Node* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures, int animflags)
|
||||
{
|
||||
osg::ref_ptr<SceneUtil::MorphGeometry> morphGeom = new SceneUtil::MorphGeometry;
|
||||
morphGeom->setSourceGeometry(sourceGeometry);
|
||||
|
@ -1167,7 +1166,7 @@ namespace NifOsg
|
|||
}
|
||||
|
||||
void handleSkinnedTriShape(const Nif::Node *nifNode, osg::Group *parentNode, SceneUtil::CompositeStateSetUpdater* composite,
|
||||
const std::vector<int>& boundTextures, int animflags)
|
||||
const std::vector<unsigned int>& boundTextures, int animflags)
|
||||
{
|
||||
assert(nifNode->recType == Nif::RC_NiTriShape || nifNode->recType == Nif::RC_NiTriStrips);
|
||||
osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry);
|
||||
|
@ -1392,7 +1391,7 @@ namespace NifOsg
|
|||
return image;
|
||||
}
|
||||
|
||||
void handleTextureProperty(const Nif::NiTexturingProperty* texprop, osg::StateSet* stateset, SceneUtil::CompositeStateSetUpdater* composite, Resource::ImageManager* imageManager, std::vector<int>& boundTextures, int animflags)
|
||||
void handleTextureProperty(const Nif::NiTexturingProperty* texprop, osg::StateSet* stateset, SceneUtil::CompositeStateSetUpdater* composite, Resource::ImageManager* imageManager, std::vector<unsigned int>& boundTextures, int animflags)
|
||||
{
|
||||
if (!boundTextures.empty())
|
||||
{
|
||||
|
@ -1403,7 +1402,7 @@ namespace NifOsg
|
|||
}
|
||||
|
||||
// If this loop is changed such that the base texture isn't guaranteed to end up in texture unit 0, the shadow casting shader will need to be updated accordingly.
|
||||
for (int i=0; i<Nif::NiTexturingProperty::NumTextures; ++i)
|
||||
for (size_t i=0; i<texprop->textures.size(); ++i)
|
||||
{
|
||||
if (texprop->textures[i].inUse)
|
||||
{
|
||||
|
@ -1451,14 +1450,13 @@ namespace NifOsg
|
|||
else
|
||||
texture2d = new osg::Texture2D;
|
||||
|
||||
unsigned int clamp = static_cast<unsigned int>(tex.clamp);
|
||||
int wrapT = (clamp) & 0x1;
|
||||
int wrapS = (clamp >> 1) & 0x1;
|
||||
bool wrapT = tex.clamp & 0x1;
|
||||
bool wrapS = (tex.clamp >> 1) & 0x1;
|
||||
|
||||
texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
|
||||
texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
int texUnit = boundTextures.size();
|
||||
unsigned int texUnit = boundTextures.size();
|
||||
|
||||
stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON);
|
||||
|
||||
|
@ -1547,7 +1545,7 @@ namespace NifOsg
|
|||
}
|
||||
|
||||
void handleProperty(const Nif::Property *property,
|
||||
osg::Node *node, SceneUtil::CompositeStateSetUpdater* composite, Resource::ImageManager* imageManager, std::vector<int>& boundTextures, int animflags)
|
||||
osg::Node *node, SceneUtil::CompositeStateSetUpdater* composite, Resource::ImageManager* imageManager, std::vector<unsigned int>& boundTextures, int animflags)
|
||||
{
|
||||
switch (property->recType)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue