From a0355c9b897281d0bfea48bec9d490724ecabd96 Mon Sep 17 00:00:00 2001 From: SulfurNitride Date: Sun, 12 Apr 2026 17:54:45 -0500 Subject: Add NIF previewer plugin with Linux-specific fixes Vendored from github.com/Parapets/mo2-preview_nif and adapted for Linux: - BSA texture resolution via MO2 virtual tree with case-insensitive fallback walk (Linux FS is case-sensitive; NIFs reference textures with arbitrary case against files on disk) - Process-wide cached BSA candidate list, keyed by profile path, priority-sorted, filtering disabled mods - Path backslash normalization before loose-file lookup - Polygon offset on SLSF1_Decal-flagged shapes to break z-ties with coincident base meshes (road decals, moss overlays) - Opaque framebuffer via glColorMask alpha lock so alpha-blended shapes can't bleed the dialog background through the preview area - QMouseEvent::globalPosition().toPoint() for Qt6 compatibility Preview dialog behavior (organizercore.cpp): - Switch previewFile and previewFileWithAlternatives from stack-allocated exec() to heap + ApplicationModal + show() + WA_DeleteOnClose. - Parent passed as nullptr so preview lifetime is decoupled from the stack-allocated ModInfoDialog that spawns it. Nested exec() inside the enclosing dialog's exec() was softlocking on close. Co-Authored-By: Claude Opus 4.6 (1M context) --- libs/preview_nif/src/OpenGLShape.h | 105 +++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 libs/preview_nif/src/OpenGLShape.h (limited to 'libs/preview_nif/src/OpenGLShape.h') diff --git a/libs/preview_nif/src/OpenGLShape.h b/libs/preview_nif/src/OpenGLShape.h new file mode 100644 index 0000000..b53e96d --- /dev/null +++ b/libs/preview_nif/src/OpenGLShape.h @@ -0,0 +1,105 @@ +#pragma once + +#include "ShaderManager.h" +#include "TextureManager.h" + +#include +#include + +#include +#include +#include +#include +#include + +enum TextureSlot +{ + BaseMap = 0, + NormalMap = 1, + GlowMap = 2, + LightMask = 2, + HeightMap = 3, + DetailMask = 3, + EnvironmentMap = 4, + EnvironmentMask = 5, + TintMask = 6, + InnerMap = 6, + BacklightMap = 7, + SpecularMap = 7, +}; + +struct OpenGLShape +{ +public: + OpenGLShape( + nifly::NifFile* nifFile, + nifly::NiShape* niShape, + TextureManager* textureManager); + + void destroy(); + void setupShaders(QOpenGLShaderProgram* program); + + static QVector2D convertVector2(nifly::Vector2 vector); + static QVector3D convertVector3(nifly::Vector3 vector); + static QColor convertColor(nifly::Color4 color); + static QMatrix4x4 convertTransform(nifly::MatTransform transform); + + ShaderManager::ShaderType shaderType = ShaderManager::SKDefault; + + QOpenGLVertexArrayObject* vertexArray = nullptr; + + QOpenGLBuffer* vertexBuffers[ATTRIB_COUNT] { nullptr }; + + QOpenGLBuffer* indexBuffer = nullptr; + GLsizei elements = 0; + + std::array textures { nullptr }; + + QMatrix4x4 modelMatrix; + QVector3D specColor{ 1.0f, 1.0f, 1.0f }; + float specStrength = 1.0f ; + float specGlossiness = 1.0f; + float fresnelPower; + + float paletteScale; + + bool hasGlowMap = false; + QColor glowColor = QColorConstants::White; + float glowMult = 1.0f; + + float alpha = 1.0f; + QVector3D tintColor{ 1.0f, 1.0f, 1.0f }; + + QVector2D uvScale{ 1.0f, 1.0f }; + QVector2D uvOffset{ 0.0f, 0.0f }; + + bool hasEmit = false; + bool hasSoftlight = false; + bool hasBacklight = false; + bool hasRimlight = false; + bool hasTintColor = false; + bool hasWeaponBlood = false; + + bool doubleSided = false; + float softlight = 0.3f; + float backlightPower = 0.0f; + float rimPower = 2.0f; + float subsurfaceRolloff; + float envReflection = 1.0f; + + QVector2D innerScale; + float innerThickness; + float outerRefraction; + float outerReflection; + + bool zBufferWrite = true; + bool zBufferTest = true; + bool isDecal = false; + + bool alphaBlendEnable = false; + GLenum srcBlendMode = GL_ONE; + GLenum dstBlendMode = GL_ONE; + bool alphaTestEnable = false; + GLenum alphaTestMode = GL_GREATER; + float alphaThreshold = 0.0f; +}; -- cgit v1.3.1