diff --git a/components/nif/nif_file.cpp b/components/nif/nif_file.cpp index 52a37ba5c1..80ea7a0b7f 100644 --- a/components/nif/nif_file.cpp +++ b/components/nif/nif_file.cpp @@ -162,6 +162,15 @@ void NIFFile::parse() r->recName = rec; records[i] = r; r->read(this); + + // Discard tranformations for the root node, otherwise some meshes + // occasionally get wrong orientation. Only for NiNode-s for now, but + // can be expanded if needed. + // This should be rewritten when the method is cleaned up. + if (0 == i && rec == "NiNode") + { + static_cast(r)->trafo = Nif::Transformation::getIdentity(); + } } /* After the data, the nif contains an int N and then a list of N diff --git a/components/nif/nif_types.hpp b/components/nif/nif_types.hpp index 17cec19bcd..ee796cc991 100644 --- a/components/nif/nif_types.hpp +++ b/components/nif/nif_types.hpp @@ -55,10 +55,26 @@ struct Matrix struct Transformation { - Vector pos; - Matrix rotation; - float scale; - Vector velocity; + Vector pos; + Matrix rotation; + float scale; + Vector velocity; + + static const Transformation* getIdentity() + { + static Transformation identity; + static bool iset = false; + if (!iset) + { + identity.scale = 1.0f; + identity.rotation.v[0].array[0] = 1.0f; + identity.rotation.v[1].array[1] = 1.0f; + identity.rotation.v[2].array[2] = 1.0f; + iset = true; + } + + return &identity; + } }; #pragma pack(pop)