1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 11:53:53 +00:00

Merge pull request #2547 from Capostrophic/nif2

More minor NIF improvements
This commit is contained in:
Bret Curtis 2019-10-21 21:49:07 +02:00 committed by GitHub
commit f666d796e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 86 deletions

View file

@ -112,7 +112,7 @@ class NiUVController : public Controller
{ {
public: public:
NiUVDataPtr data; NiUVDataPtr data;
int uvSet; unsigned int uvSet;
void read(NIFStream *nif); void read(NIFStream *nif);
void post(NIFFile *nif); void post(NIFFile *nif);

View file

@ -102,12 +102,12 @@ void NiTriStripsData::read(NIFStream *nif)
std::vector<unsigned short> lengths; std::vector<unsigned short> lengths;
nif->getUShorts(lengths, numStrips); nif->getUShorts(lengths, numStrips);
if (!numStrips)
return;
strips.resize(numStrips);
for (int i = 0; i < numStrips; i++) for (int i = 0; i < numStrips; i++)
{ nif->getUShorts(strips[i], lengths[i]);
std::vector<unsigned short> strip;
nif->getUShorts(strip, lengths[i]);
strips.emplace_back(strip);
}
} }
void NiAutoNormalParticlesData::read(NIFStream *nif) void NiAutoNormalParticlesData::read(NIFStream *nif)

View file

@ -18,14 +18,13 @@ void NiTexturingProperty::Texture::read(NIFStream *nif)
if(!inUse) return; if(!inUse) return;
texture.read(nif); texture.read(nif);
clamp = nif->getInt(); clamp = nif->getUInt();
filter = nif->getInt(); nif->skip(4); // Filter mode. Ignoring because global filtering settings are more sensible
uvSet = nif->getInt(); uvSet = nif->getUInt();
// I have no idea, but I think these are actually two // Two PS2-specific shorts.
// PS2-specific shorts (ps2L and ps2K), followed by an unknown nif->skip(4);
// short. nif->skip(2); // Unknown short
nif->skip(6);
} }
void NiTexturingProperty::Texture::post(NIFFile *nif) void NiTexturingProperty::Texture::post(NIFFile *nif)
@ -36,26 +35,25 @@ void NiTexturingProperty::Texture::post(NIFFile *nif)
void NiTexturingProperty::read(NIFStream *nif) void NiTexturingProperty::read(NIFStream *nif)
{ {
Property::read(nif); Property::read(nif);
apply = nif->getInt(); apply = nif->getUInt();
// Unknown, always 7. Probably the number of textures to read unsigned int numTextures = nif->getUInt();
// below
nif->getInt();
textures[0].read(nif); // Base if (!numTextures)
textures[1].read(nif); // Dark return;
textures[2].read(nif); // Detail
textures[3].read(nif); // Gloss (never present) textures.resize(numTextures);
textures[4].read(nif); // Glow for (unsigned int i = 0; i < numTextures; i++)
textures[5].read(nif); // Bump map
if(textures[5].inUse)
{ {
textures[i].read(nif);
// Ignore these at the moment // Ignore these at the moment
/*float lumaScale =*/ nif->getFloat(); if (i == 5 && textures[5].inUse) // Bump map settings
/*float lumaOffset =*/ nif->getFloat(); {
/*const Vector4 *lumaMatrix =*/ nif->getVector4(); /*float lumaScale =*/ nif->getFloat();
/*float lumaOffset =*/ nif->getFloat();
/*const Vector4 *lumaMatrix =*/ nif->getVector4();
}
} }
textures[6].read(nif); // Decal
} }
void NiTexturingProperty::post(NIFFile *nif) void NiTexturingProperty::post(NIFFile *nif)

View file

@ -51,17 +51,10 @@ public:
3 - wrapS wrapT 3 - wrapS wrapT
*/ */
/* Filter:
0 - nearest
1 - bilinear
2 - trilinear
3, 4, 5 - who knows
*/
bool inUse; bool inUse;
NiSourceTexturePtr texture; NiSourceTexturePtr texture;
int clamp, uvSet, filter; unsigned int clamp, uvSet;
short unknown2;
void read(NIFStream *nif); void read(NIFStream *nif);
void post(NIFFile *nif); void post(NIFFile *nif);
@ -74,7 +67,7 @@ public:
3 - hilight // These two are for PS2 only? 3 - hilight // These two are for PS2 only?
4 - hilight2 4 - hilight2
*/ */
int apply; unsigned int apply;
/* /*
* The textures in this list are as follows: * The textures in this list are as follows:
@ -82,7 +75,7 @@ public:
* 0 - Base texture * 0 - Base texture
* 1 - Dark texture * 1 - Dark texture
* 2 - Detail texture * 2 - Detail texture
* 3 - Gloss texture (never used?) * 3 - Gloss texture
* 4 - Glow texture * 4 - Glow texture
* 5 - Bump map texture * 5 - Bump map texture
* 6 - Decal texture * 6 - Decal texture
@ -96,10 +89,9 @@ public:
GlowTexture = 4, GlowTexture = 4,
BumpTexture = 5, BumpTexture = 5,
DecalTexture = 6, DecalTexture = 6,
NumTextures = 7 // Sentry value
}; };
Texture textures[7]; std::vector<Texture> textures;
void read(NIFStream *nif); void read(NIFStream *nif);
void post(NIFFile *nif); void post(NIFFile *nif);

View file

@ -143,31 +143,31 @@ class NiAutoNormalParticlesData;
class NiPalette; class NiPalette;
struct NiParticleModifier; struct NiParticleModifier;
typedef RecordPtrT<Node> NodePtr; using NodePtr = RecordPtrT<Node>;
typedef RecordPtrT<Extra> ExtraPtr; using ExtraPtr = RecordPtrT<Extra>;
typedef RecordPtrT<NiUVData> NiUVDataPtr; using NiUVDataPtr = RecordPtrT<NiUVData>;
typedef RecordPtrT<NiPosData> NiPosDataPtr; using NiPosDataPtr = RecordPtrT<NiPosData>;
typedef RecordPtrT<NiVisData> NiVisDataPtr; using NiVisDataPtr = RecordPtrT<NiVisData>;
typedef RecordPtrT<Controller> ControllerPtr; using ControllerPtr = RecordPtrT<Controller>;
typedef RecordPtrT<Named> NamedPtr; using NamedPtr = RecordPtrT<Named>;
typedef RecordPtrT<NiSkinData> NiSkinDataPtr; using NiSkinDataPtr = RecordPtrT<NiSkinData>;
typedef RecordPtrT<NiMorphData> NiMorphDataPtr; using NiMorphDataPtr = RecordPtrT<NiMorphData>;
typedef RecordPtrT<NiPixelData> NiPixelDataPtr; using NiPixelDataPtr = RecordPtrT<NiPixelData>;
typedef RecordPtrT<NiFloatData> NiFloatDataPtr; using NiFloatDataPtr = RecordPtrT<NiFloatData>;
typedef RecordPtrT<NiColorData> NiColorDataPtr; using NiColorDataPtr = RecordPtrT<NiColorData>;
typedef RecordPtrT<NiKeyframeData> NiKeyframeDataPtr; using NiKeyframeDataPtr = RecordPtrT<NiKeyframeData>;
typedef RecordPtrT<NiTriShapeData> NiTriShapeDataPtr; using NiTriShapeDataPtr = RecordPtrT<NiTriShapeData>;
typedef RecordPtrT<NiTriStripsData> NiTriStripsDataPtr; using NiTriStripsDataPtr = RecordPtrT<NiTriStripsData>;
typedef RecordPtrT<NiSkinInstance> NiSkinInstancePtr; using NiSkinInstancePtr = RecordPtrT<NiSkinInstance>;
typedef RecordPtrT<NiSourceTexture> NiSourceTexturePtr; using NiSourceTexturePtr = RecordPtrT<NiSourceTexture>;
typedef RecordPtrT<NiRotatingParticlesData> NiRotatingParticlesDataPtr; using NiRotatingParticlesDataPtr = RecordPtrT<NiRotatingParticlesData>;
typedef RecordPtrT<NiAutoNormalParticlesData> NiAutoNormalParticlesDataPtr; using NiAutoNormalParticlesDataPtr = RecordPtrT<NiAutoNormalParticlesData>;
typedef RecordPtrT<NiPalette> NiPalettePtr; using NiPalettePtr = RecordPtrT<NiPalette>;
typedef RecordPtrT<NiParticleModifier> NiParticleModifierPtr; using NiParticleModifierPtr = RecordPtrT<NiParticleModifier>;
typedef RecordListT<Node> NodeList; using NodeList = RecordListT<Node>;
typedef RecordListT<Property> PropertyList; using PropertyList = RecordListT<Property>;
typedef RecordListT<NiSourceTexture> NiSourceTextureList; using NiSourceTextureList = RecordListT<NiSourceTexture>;
} // Namespace } // Namespace
#endif #endif

View file

@ -262,7 +262,7 @@ namespace NifOsg
osg::ref_ptr<TextKeyMapHolder> textkeys (new TextKeyMapHolder); 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()) if (nif->getUseSkinning())
{ {
@ -288,7 +288,7 @@ namespace NifOsg
return created; 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; const Nif::PropertyList& props = nifNode->props;
for (size_t i = 0; i <props.length(); ++i) for (size_t i = 0; i <props.length(); ++i)
@ -405,9 +405,8 @@ namespace NifOsg
if (image) if (image)
texture2d->setTextureSize(image->s(), image->t()); texture2d->setTextureSize(image->s(), image->t());
texture2d->setName("envMap"); texture2d->setName("envMap");
unsigned int clamp = static_cast<unsigned int>(textureEffect->clamp); bool wrapT = textureEffect->clamp & 0x1;
int wrapT = (clamp) & 0x1; bool wrapS = (textureEffect->clamp >> 1) & 0x1;
int wrapS = (clamp >> 1) & 0x1;
texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); 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); 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, 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")) if (rootNode != nullptr && Misc::StringUtils::ciEqual(nifNode->name, "Bounding Box"))
return nullptr; return nullptr;
@ -657,7 +656,7 @@ namespace NifOsg
return node; 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) for (Nif::ControllerPtr ctrl = nifNode->controller; !ctrl.empty(); ctrl = ctrl->next)
{ {
@ -666,7 +665,7 @@ 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());
const int uvSet = niuvctrl->uvSet; const unsigned int uvSet = niuvctrl->uvSet;
std::set<int> texUnits; std::set<int> texUnits;
// UVController should work only for textures which use a given UV Set, usually 0. // 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)
@ -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()) if (!vertices.empty())
geometry->setVertexArray(new osg::Vec3Array(vertices.size(), vertices.data())); 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); geometry->setColorArray(new osg::Vec4Array(colors.size(), colors.data()), osg::Array::BIND_PER_VERTEX);
int textureStage = 0; 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; Log(Debug::Verbose) << "Out of bounds UV set " << uvSet << " on shape \"" << name << "\" in " << mFilename;
if (!uvlist.empty()) 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; bool vertexColorsPresent = false;
if (nifNode->recType == Nif::RC_NiTriShape) if (nifNode->recType == Nif::RC_NiTriShape)
@ -1119,7 +1118,7 @@ namespace NifOsg
applyDrawableProperties(parentNode, drawableProps, composite, vertexColorsPresent, animflags, false); 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); assert(nifNode->recType == Nif::RC_NiTriShape || nifNode->recType == Nif::RC_NiTriStrips);
osg::ref_ptr<osg::Drawable> drawable; osg::ref_ptr<osg::Drawable> drawable;
@ -1151,7 +1150,7 @@ namespace NifOsg
parentNode->addChild(drawable); 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; osg::ref_ptr<SceneUtil::MorphGeometry> morphGeom = new SceneUtil::MorphGeometry;
morphGeom->setSourceGeometry(sourceGeometry); morphGeom->setSourceGeometry(sourceGeometry);
@ -1167,7 +1166,7 @@ namespace NifOsg
} }
void handleSkinnedTriShape(const Nif::Node *nifNode, osg::Group *parentNode, SceneUtil::CompositeStateSetUpdater* composite, 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); assert(nifNode->recType == Nif::RC_NiTriShape || nifNode->recType == Nif::RC_NiTriStrips);
osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry); osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry);
@ -1392,7 +1391,7 @@ namespace NifOsg
return image; 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()) 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. // 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) if (texprop->textures[i].inUse)
{ {
@ -1451,14 +1450,13 @@ namespace NifOsg
else else
texture2d = new osg::Texture2D; texture2d = new osg::Texture2D;
unsigned int clamp = static_cast<unsigned int>(tex.clamp); bool wrapT = tex.clamp & 0x1;
int wrapT = (clamp) & 0x1; bool wrapS = (tex.clamp >> 1) & 0x1;
int wrapS = (clamp >> 1) & 0x1;
texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); 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); 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); stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON);
@ -1547,7 +1545,7 @@ namespace NifOsg
} }
void handleProperty(const Nif::Property *property, 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) switch (property->recType)
{ {