コード例 #1
0
 public QuadTree(NiTriShapeData data, int quadLevel)
 {
     this.sampleSize = Game.sampleSize;
     // water
     if (data.GetBSNumUVSets() == 0)
     {
         this.sampleSize = 1;
         this.isLand = false;
     }
     else
     {
         isLand = true;
     }
     this.vertices = data.GetVertices();
     this.boundingBox = new BBox();
     this.boundingBox.Set(float.MaxValue, float.MinValue, float.MaxValue, float.MinValue, float.MaxValue, float.MinValue);
     this.segments = new QuadTreeLeaf[(int)(this.sampleSize * quadLevel * this.sampleSize * quadLevel)];
     for (int index = 0; index < (this.sampleSize * quadLevel) * (this.sampleSize * quadLevel); index++)
     {
         this.segments[index] = this.CreateSegment(index, quadLevel, data.GetTriangles(), data.GetVertices());
         boundingBox.GrowByBox(this.segments[index].boundingBox);
     }
     QuadTreeLeaf quadTreeLeaf = new QuadTreeLeaf();
     List<Triangle> triangles = data.GetTriangles();
     quadTreeLeaf.boundingBox.GrowByBox(boundingBox);
     quadTreeLeaf.triangles = triangles;
     this.entirequad = quadTreeLeaf;
 }
コード例 #2
0
 public void GrowByBox(BBox boundingBox)
 {
     if (boundingBox.px1 < this.px1)
     {
         this.px1 = boundingBox.px1;
     }
     if (boundingBox.px2 > this.px2)
     {
         this.px2 = boundingBox.px2;
     }
     if (boundingBox.py1 < this.py1)
     {
         this.py1 = boundingBox.py1;
     }
     if (boundingBox.py2 > this.py2)
     {
         this.py2 = boundingBox.py2;
     }
     if (boundingBox.pz1 < this.pz1)
     {
         this.pz1 = boundingBox.pz1;
     }
     if (boundingBox.pz2 > this.pz2)
     {
         this.pz2 = boundingBox.pz2;
     }
 }
コード例 #3
0
 public ShapeDesc()
 {
     this.shape       = (NiTriShape)null;
     this.data        = (NiTriShapeData)null;
     this.textures    = new string[2];
     this.boundingBox = new BBox();
     // relative x, y for segment
     this.x        = new float();
     this.y        = new float();
     this.segments = new List <SegmentDesc>();
 }
コード例 #4
0
 public ShapeDesc()
 {
     this.shape = (NiTriShape)null;
     this.data = (NiTriShapeData)null;
     this.textures = new string[2];
     this.boundingBox = new BBox();
     // relative x, y for segment
     this.x = new float();
     this.y = new float();
     this.segments = new List<SegmentDesc>();
 }
コード例 #5
0
ファイル: QuadDesc.cs プロジェクト: longde123/xLODGen
 public QuadDesc(bool val)
 {
     this.x                         = 0;
     this.y                         = 0;
     this.statics                   = new List <StaticDesc>();
     this.terrainQuadTree           = new QuadTree();
     this.waterQuadTree             = new QuadTree();
     this.hasTerrainVertices        = false;
     this.boundingBox               = new BBox();
     this.outValues                 = new OutDesc();
     this.outValues.totalTriCount   = 0;
     this.outValues.reducedTriCount = 0;
     this.textureBlockIndex         = new Dictionary <string, int>();
     this.textureBlockIndexPassThru = new Dictionary <string, int>();
     this.dataBlockIndex            = new Dictionary <string, int>();
     this.shaderBlockIndex          = new Dictionary <string, int>();
 }
コード例 #6
0
 public ShapeDesc()
 {
     this.name                = "";
     this.staticName          = "";
     this.staticModel         = "";
     this.geometry            = null;
     this.shaderType          = "";
     this.effectShader        = null;
     this.lightingShader      = null;
     this.texturingProperty   = null;
     this.materialProperty    = null;
     this.sourceTextureBase   = null;
     this.sourceTextureDetail = null;
     this.sourceTextureGlow   = null;
     this.sourceTextureBump   = null;
     this.shaderHash          = "";
     this.shapeHash           = "";
     this.material            = "";
     this.textures            = new string[10] {
         "", "", "", "", "", "", "", "", "", ""
     };
     this.textures[0]      = "textures\\default.dds";
     this.textures[1]      = "textures\\default_n.dds";
     this.isPassThru       = false;
     this.isGroup          = false;
     this.isHighDetail     = false;
     this.hasVertexColor   = false;
     this.allWhite         = false;
     this.isDoubleSided    = false;
     this.isAlpha          = false;
     this.isDecal          = false;
     this.enableParent     = 0;
     this.TextureClampMode = 0;
     this.boundingBox      = new BBox();
     this.x           = new float();
     this.y           = new float();
     this.segments    = new List <SegmentDesc>();
     this.translation = new Vector3(0f, 0f, 0f);
     this.rotation    = new Matrix33(true);
     this.scale       = 1f;
 }
コード例 #7
0
 public ShapeDesc(ShapeDesc shapeDesc)
 {
     this.name                = shapeDesc.name;
     this.staticName          = shapeDesc.name;
     this.staticModel         = shapeDesc.name;
     this.geometry            = null;
     this.shaderType          = shapeDesc.shaderType;
     this.effectShader        = shapeDesc.effectShader;
     this.lightingShader      = shapeDesc.lightingShader;
     this.texturingProperty   = shapeDesc.texturingProperty;
     this.materialProperty    = shapeDesc.materialProperty;
     this.sourceTextureBase   = shapeDesc.sourceTextureBase;
     this.sourceTextureDetail = shapeDesc.sourceTextureDetail;
     this.sourceTextureGlow   = shapeDesc.sourceTextureGlow;
     this.sourceTextureBump   = shapeDesc.sourceTextureBump;
     this.shaderHash          = shapeDesc.shaderHash;
     this.shapeHash           = shapeDesc.shapeHash;
     this.material            = shapeDesc.material;
     this.textures            = shapeDesc.textures;
     this.isPassThru          = shapeDesc.isPassThru;
     this.isGroup             = shapeDesc.isGroup;
     this.isHighDetail        = shapeDesc.isHighDetail;
     this.hasVertexColor      = shapeDesc.hasVertexColor;
     this.allWhite            = shapeDesc.allWhite;
     this.isDoubleSided       = shapeDesc.isDoubleSided;
     this.isAlpha             = shapeDesc.isAlpha;
     this.isDecal             = shapeDesc.isDecal;
     this.enableParent        = shapeDesc.enableParent;
     this.TextureClampMode    = shapeDesc.TextureClampMode;
     this.boundingBox         = new BBox();
     this.x           = shapeDesc.x;
     this.y           = shapeDesc.y;
     this.segments    = new List <SegmentDesc>();
     this.translation = shapeDesc.translation;
     this.rotation    = shapeDesc.rotation;
     this.scale       = shapeDesc.scale;
 }
コード例 #8
0
        public ShapeDesc(String gameDir, NiFile file, NiTriBasedGeom geom, StaticDesc stat, int quadIndex, StringList PassThruMeshList, bool skyblivionTexPath, bool useOptimizer, bool fixTangents, bool useDecalFlag, bool terrain, bool verbose, LogFile logFile)
        {
            this.name = "";
            if (geom.GetNameIndex() != -1)
            {
                this.name = file.GetStringAtIndex(geom.GetNameIndex());
            }
            else
            {
                this.name = geom.GetName();
            }
            if (this.name == null)
            {
                this.name = "";
            }
            this.staticName = stat.staticName;
            if (stat.staticModels != null && quadIndex < stat.staticModels.Count())
            {
                this.staticModel = stat.staticModels[quadIndex].ToLower(CultureInfo.InvariantCulture);
            }
            else
            {
                this.staticModel = "";
            }
            this.geometry            = null;
            this.shaderType          = "";
            this.effectShader        = null;
            this.lightingShader      = null;
            this.texturingProperty   = null;
            this.materialProperty    = null;
            this.sourceTextureBase   = null;
            this.sourceTextureDetail = null;
            this.sourceTextureGlow   = null;
            this.sourceTextureBump   = null;
            this.shaderHash          = "";
            this.shapeHash           = "";
            if (stat.materialName != null)
            {
                this.material = stat.materialName;
            }
            else
            {
                this.material = "";
            }
            if (quadIndex != 0 && this.material.ToLower().Contains("largeref"))
            {
                this.material = Regex.Replace(this.material, "-largeref", "", RegexOptions.IgnoreCase);
            }
            this.textures = new string[10] {
                "", "", "", "", "", "", "", "", "", ""
            };
            this.textures[0] = "textures\\default.dds";
            this.textures[1] = "textures\\default_n.dds";

            if (this.name == "LODGenPassThru" || this.material.ToLower(CultureInfo.InvariantCulture) == "passthru" || (PassThruMeshList != null && staticModel != "" && PassThruMeshList.Any(staticModel.Contains)))
            {
                this.isPassThru = true;
                this.material   = "passthru";
            }
            else
            {
                this.isPassThru = false;
            }
            if ((stat.staticFlags & 1) == 1)
            {
                this.isGroup = true;
            }
            this.isHighDetail     = false;
            this.hasVertexColor   = false;
            this.allWhite         = false;
            this.isDoubleSided    = false;
            this.isAlpha          = false;
            this.isDecal          = false;
            this.enableParent     = 0;
            this.TextureClampMode = 0;
            this.boundingBox      = new BBox();
            this.x           = new float();
            this.y           = new float();
            this.segments    = new List <SegmentDesc>();
            this.translation = new Vector3(stat.x, stat.y, stat.z);

            this.scale = stat.scale;

            Matrix33 matrix33_1 = new Matrix33(true);
            Matrix33 matrix33_2 = new Matrix33(true);
            Matrix33 matrix33_3 = new Matrix33(true);

            matrix33_1.SetRotationX(Utils.ToRadians(-stat.rotX));
            matrix33_2.SetRotationY(Utils.ToRadians(-stat.rotY));
            matrix33_3.SetRotationZ(Utils.ToRadians(-stat.rotZ));
            this.rotation = new Matrix33(true) * matrix33_1 * matrix33_2 * matrix33_3;

            try
            {
                if (geom.GetClassName() == "NiTriStrips")
                {
                    int index = geom.GetData();
                    if (index == -1)
                    {
                        geometry = new Geometry();
                    }
                    else
                    {
                        geometry = new Geometry(new NiTriShapeData((NiTriStripsData)file.GetBlockAtIndex(index)));
                    }
                    List <int> extradatalist = geom.GetExtraData();
                    if (extradatalist.Count == 1)
                    {
                        NiBinaryExtraData extradata = (NiBinaryExtraData)file.GetBlockAtIndex(extradatalist[0]);
                        this.geometry.SetTangents(extradata.GetTangents());
                        this.geometry.SetBitangents(extradata.GetBitangents());
                    }
                }
                else
                {
                    int index = geom.GetData();
                    if (index == -1)
                    {
                        geometry = new Geometry();
                    }
                    else
                    {
                        if (file.GetBlockAtIndex(index).IsDerivedType("BSTriShape"))
                        {
                            BSTriShape bsts = (BSTriShape)file.GetBlockAtIndex(index);
                            geometry = bsts.GetGeom();
                        }
                        else
                        {
                            geometry = new Geometry((NiTriShapeData)file.GetBlockAtIndex(index));
                        }
                    }
                }
            }
            catch
            {
                logFile.WriteLog("Skipping non supported data " + this.staticModel + " " + this.name);
                geometry = new Geometry();
                return;
            }

            if (terrain)
            {
                return;
            }

            if (geometry.uvcoords.Count == 0)
            {
                logFile.WriteLog("Skipping no UV " + this.staticModel + " " + this.name);
                geometry = new Geometry();
                return;
            }

            if (geometry.HasVertexColors())
            {
                this.allWhite = true;
                List <Color4> vertexColors = geometry.GetVertexColors();
                for (int index = 0; index < vertexColors.Count; index++)
                {
                    float r = vertexColors[index][0];
                    float g = vertexColors[index][1];
                    float b = vertexColors[index][2];
                    float a = vertexColors[index][3];
                    if (r < 0.9f || b < 0.9f || g < 0.9f)
                    {
                        this.allWhite = false;
                    }
                    if (this.isPassThru && Game.Mode != "merge5")
                    {
                        // if neither LOD flag is set, alpha is used on/off at 0.5f, nobody wants that
                        // HD snow shader uses alpha for something else
                        a = 1f;
                    }
                    vertexColors[index] = new Color4(r, g, b, a);
                }
                if (this.allWhite)
                {
                    geometry.SetVertexColors(new List <Color4>());
                }
                else if (this.isPassThru && Game.Mode != "merge5")
                {
                    geometry.SetVertexColors(vertexColors);
                }
            }
            this.hasVertexColor = geometry.HasVertexColors();
            try
            {
                this.shapeHash = Utils.GetHash(Utils.ObjectToByteArray(geometry.vertices));
            }
            catch
            {
                logFile.WriteLog("Can not get hash for vertices in " + this.staticModel + " block " + this.name);
                logFile.Close();
                System.Environment.Exit(3003);
            }
            if ((file.GetVersion() > 335544325U) && (file.GetUserVersion() > 11U))
            {
                for (int index = 0; index < 2; index++)
                {
                    if (geom.GetBSProperty(index) != -1)
                    {
                        string type = file.GetBlockAtIndex(geom.GetBSProperty(index)).GetClassName().ToLower(CultureInfo.InvariantCulture);
                        if (type == "nialphaproperty")
                        {
                            if (Game.Mode == "fo4" || Game.Mode == "merge5")
                            {
                                this.isAlpha = true;
                                NiAlphaProperty alphaProperty = (NiAlphaProperty)file.GetBlockAtIndex(geom.GetBSProperty(index));
                                this.alphaThreshold = alphaProperty.GetThreshold();
                            }
                        }
                        else if (type == "bseffectshaderproperty")
                        {
                            this.shaderType = type;
                            BSEffectShaderProperty shader = (BSEffectShaderProperty)file.GetBlockAtIndex(geom.GetBSProperty(index));
                            this.textures[0] = shader.GetSourceTexture().ToLower(CultureInfo.InvariantCulture);
                            // disable non supported flags
                            if (Game.Mode != "merge5")
                            {
                                shader.SetShaderFlags1(shader.GetShaderFlags1() & 3724541045);
                                shader.SetShaderFlags2(shader.GetShaderFlags2() & 3758063615);
                            }
                            shader.SetSourceTexture("");
                            this.effectShader = shader;
                            if (this.hasVertexColor)
                            {
                                shader.SetShaderFlags2(shader.GetShaderFlags2() | 32);
                            }
                            else
                            {
                                shader.SetShaderFlags2(shader.GetShaderFlags2() & 4294967263);
                            }
                            this.isDoubleSided    = (shader.GetShaderFlags2() & 16) == 16;
                            this.TextureClampMode = shader.GetTextureClampMode();
                            shader.SetTextureClampMode(3);
                            try
                            {
                                this.shaderHash = Utils.GetHash(Utils.ObjectToByteArray(shader));
                            }
                            catch
                            {
                                logFile.WriteLog("Can not get hash for shader in " + this.staticModel + " block " + this.name);
                                logFile.Close();
                                System.Environment.Exit(3004);
                            }
                        }
                        else if (type == "bslightingshaderproperty")
                        {
                            this.shaderType = type;
                            BSLightingShaderProperty shader = (BSLightingShaderProperty)file.GetBlockAtIndex(geom.GetBSProperty(index));
                            // disable non supported flags
                            if (Game.Mode != "merge5")
                            {
                                //enviroment shader
                                if (shader.GetShaderType() == 1)
                                {
                                    if ((shader.GetShaderFlags2() & 64) == 64)
                                    {
                                        //glow shader
                                        shader.SetShaderType(2);
                                    }
                                    shader.SetShaderType(0);
                                }
                                //3695270121
                                shader.SetShaderFlags1(shader.GetShaderFlags1() & 3724541045);
                                shader.SetShaderFlags2(shader.GetShaderFlags2() & 3758063615);
                            }
                            this.TextureClampMode = shader.GetTextureClampMode();
                            shader.SetTextureClampMode(3);
                            this.isDoubleSided = (shader.GetShaderFlags2() & 16) == 16;
                            if ((Game.Mode == "tes5" || Game.Mode == "sse") && useDecalFlag && !this.isPassThru && ((shader.GetShaderFlags1() & 67108864) == 67108864 || (shader.GetShaderFlags1() & 134217728) == 134217728))
                            {
                                this.isDecal = true;
                                // SLSF1_Decal
                                shader.SetShaderFlags1(shader.GetShaderFlags1() | 67108864);
                                // SLSF1_Dynamic_Decal
                                shader.SetShaderFlags1(shader.GetShaderFlags1() | 134217728);
                                // SLSF2_No_Fade
                                shader.SetShaderFlags2(shader.GetShaderFlags2() | 8);
                            }
                            if (this.hasVertexColor)
                            {
                                shader.SetShaderFlags2(shader.GetShaderFlags2() | 32);
                            }
                            else
                            {
                                shader.SetShaderFlags2(shader.GetShaderFlags2() & 4294967263);
                            }
                            // no specular flag -> reset specular strength, color, glossiness
                            //if ((shader.GetShaderFlags1() & 1) == 0 || shader.GetSpecularStrength() == 0f || (shader.GetGlossiness() == 80f && shader.GetSpecularColor() == new Color3(0f, 0f, 0f) && shader.GetSpecularStrength() == 1f))
                            //{
                            shader.SetShaderFlags1(shader.GetShaderFlags1() & 4294967294);
                            shader.SetGlossiness(80f);
                            shader.SetSpecularColor(new Color3(0f, 0f, 0f));
                            shader.SetSpecularStrength(1f);
                            //}
                            // no soft/rim/back/effect lighting -> reset effect lighting 1 and 2
                            if ((shader.GetShaderFlags2() & 1308622848) == 0 || (shader.GetLightingEffect1() < 0.1f && shader.GetLightingEffect2() < 0.1f))
                            {
                                shader.SetShaderFlags2(shader.GetShaderFlags2() & 2986344447);
                                shader.SetLightingEffect1(0f);
                                shader.SetLightingEffect2(0f);
                            }
                            // no own emit -> reset own emit, emissive color, muliplier
                            if ((shader.GetShaderFlags1() & 4194304) == 0 || (shader.GetEmissiveColor()[0] < 0.1f && shader.GetEmissiveColor()[1] < 0.1f && shader.GetEmissiveColor()[2] < 0.1f) || shader.GetEmissiveMultiple() == 0f)
                            {
                                shader.SetShaderFlags1(shader.GetShaderFlags1() & 4290772991);
                                shader.SetEmissiveColor(new Color3(0f, 0f, 0f));
                                shader.SetEmissiveMultiple(1f);
                            }
                            this.backlightPower = shader.GetBacklightPower();
                            if (shader.GetTextureSet() != -1 && this.textures[0] == "textures\\default.dds")
                            {
                                BSShaderTextureSet shaderTextureSet = (BSShaderTextureSet)file.GetBlockAtIndex(shader.GetTextureSet());
                                for (int index2 = 0; index2 < shaderTextureSet.GetNumTextures(); ++index2)
                                {
                                    this.textures[index2] = shaderTextureSet.GetTexture(index2).ToLower(CultureInfo.InvariantCulture);
                                }
                            }
                            shader.SetTextureSet(-1);
                            //BGSM takes priority and overwrite everything in nif
                            if (shader.GetNameIndex() != -1)
                            {
                                string bgsmFileName = file.GetStringAtIndex(shader.GetNameIndex()).ToLower(CultureInfo.InvariantCulture);
                                if (bgsmFileName.Contains(".bgsm"))
                                {
                                    int i = bgsmFileName.IndexOf("\\data\\");
                                    if (i > 0)
                                    {
                                        i           += 6;
                                        bgsmFileName = bgsmFileName.Substring(i, bgsmFileName.Length - i);
                                    }
                                    if (stat.materialSwap.ContainsKey(bgsmFileName))
                                    {
                                        bgsmFileName = stat.materialSwap[bgsmFileName];
                                    }
                                    BGSMFile bgsmdata = new BGSMFile();
                                    bgsmdata.Read(gameDir, bgsmFileName, logFile);
                                    if (bgsmdata.textures[0] != "")
                                    {
                                        this.textures[0]      = "textures\\" + bgsmdata.textures[0];
                                        this.textures[1]      = "textures\\" + bgsmdata.textures[1];
                                        this.textures[7]      = "textures\\" + bgsmdata.textures[2];
                                        this.TextureClampMode = bgsmdata.textureClampMode;
                                        shader.SetTextureClampMode(this.TextureClampMode);
                                        this.isAlpha       = Convert.ToBoolean(bgsmdata.alphaFlag);
                                        this.isDoubleSided = Convert.ToBoolean(bgsmdata.doubleSided);
                                        shader.SetShaderFlags2(shader.GetShaderFlags2() | 16);
                                        this.alphaThreshold = bgsmdata.alphaThreshold;
                                        this.backlightPower = bgsmdata.backlightPower;
                                        shader.SetBacklightPower(this.backlightPower);
                                    }
                                }
                            }
                            try
                            {
                                this.shaderHash = Utils.GetHash(Utils.ObjectToByteArray(shader));
                            }
                            catch
                            {
                                logFile.WriteLog("Can not get hash for shader in " + this.staticModel + " block " + this.name);
                                logFile.Close();
                                System.Environment.Exit(3005);
                            }
                            this.lightingShader = shader;
                        }
                        else
                        {
                            if (this.shaderType == "")
                            {
                                this.shaderType = type;
                            }
                        }
                    }
                }
            }
            else
            {
                this.shaderType = "none";
                for (int index = 0; index < geom.GetNumProperties(); ++index)
                {
                    NiProperty niProperty = (NiProperty)file.GetBlockAtIndex(geom.GetProperty(index));
                    string     type       = niProperty.GetClassName().ToLower(CultureInfo.InvariantCulture);
                    if (niProperty.GetType() == typeof(BSShaderPPLightingProperty))
                    {
                        BSShaderPPLightingProperty shader           = (BSShaderPPLightingProperty)file.GetBlockAtIndex(geom.GetProperty(index));
                        BSShaderTextureSet         shaderTextureSet = (BSShaderTextureSet)file.GetBlockAtIndex(shader.GetTextureSet());
                        for (int index2 = 0; index2 < shaderTextureSet.GetNumTextures(); ++index2)
                        {
                            this.textures[index2] = shaderTextureSet.GetTexture(index2).ToLower(CultureInfo.InvariantCulture);
                        }
                        //this.hasVertexColor = (shader.GetShaderFlags2() & 32) == 32;
                        //this.isDoubleSided = (shader.GetShaderFlags2() & 16) == 16;
                        //this.TextureClampMode = shader.GetTextureClampMode();
                        this.shaderType = type;
                        break;
                    }
                    if (niProperty.GetType() == typeof(NiMaterialProperty))
                    {
                        this.materialProperty = (NiMaterialProperty)niProperty;
                        this.hasVertexColor   = this.geometry.HasVertexColors();
                    }
                    if (niProperty.GetType() == typeof(NiTexturingProperty))
                    {
                        this.texturingProperty = (NiTexturingProperty)niProperty;
                        string str1 = "textures\\defaultdiffuse.dds";
                        string str2 = "textures\\default_n.dds";
                        if (this.texturingProperty != null)
                        {
                            TexDesc baseTexture = this.texturingProperty.GetBaseTexture();
                            if (this.texturingProperty.HasBaseTexture() && this.texturingProperty.GetBaseTexture().source != -1)
                            {
                                this.sourceTextureBase = (NiSourceTexture)file.GetBlockAtIndex(this.texturingProperty.GetBaseTexture().source);
                                str1 = this.sourceTextureBase.GetFileName().ToLower(CultureInfo.InvariantCulture);
                            }
                            if (this.texturingProperty.HasDarkTexture() && this.texturingProperty.GetDarkTexture().source != -1)
                            {
                                if (verbose)
                                {
                                    logFile.WriteLog("dark texture " + this.staticName);
                                }
                            }
                            if (this.texturingProperty.HasDetailTexture() && this.texturingProperty.GetDetailTexture().source != -1)
                            {
                                if (verbose)
                                {
                                    logFile.WriteLog("detail texture " + this.staticName);
                                }
                                this.sourceTextureDetail = (NiSourceTexture)file.GetBlockAtIndex(this.texturingProperty.GetDetailTexture().source);
                                str1 = this.sourceTextureDetail.GetFileName().ToLower(CultureInfo.InvariantCulture);
                            }
                            if (this.texturingProperty.HasGlossTexture() && this.texturingProperty.GetGlossTexture().source != -1)
                            {
                                if (verbose)
                                {
                                    logFile.WriteLog("gloss texture " + this.staticName);
                                }
                            }
                            if (this.texturingProperty.HasGlowTexture() && this.texturingProperty.GetGlowTexture().source != -1)
                            {
                                if (verbose)
                                {
                                    logFile.WriteLog("glow texture " + this.staticName);
                                }
                                this.sourceTextureGlow = (NiSourceTexture)file.GetBlockAtIndex(this.texturingProperty.GetGlowTexture().source);
                            }
                            if (this.texturingProperty.HasBumpMapTexture() && this.texturingProperty.GetBumpMapTexture().source != -1)
                            {
                                if (verbose)
                                {
                                    logFile.WriteLog("bump texture " + this.staticName);
                                }
                                this.sourceTextureBump = (NiSourceTexture)file.GetBlockAtIndex(this.texturingProperty.GetBumpMapTexture().source);
                            }
                            if (this.texturingProperty.HasDecalTexture0() && this.texturingProperty.GetDecalTexture0().source != -1)
                            {
                                if (verbose)
                                {
                                    logFile.WriteLog("decal texture " + this.staticName);
                                }
                            }
                            str2 = Utils.GetNormalTextureName(str1);
                            if (skyblivionTexPath && !str1.Contains("textures\\tes4"))
                            {
                                str1 = str1.ToLower().Replace("textures", "textures\\tes4");
                                str2 = str2.ToLower().Replace("textures", "textures\\tes4");
                            }
                        }
                        this.textures[0] = str1.ToLower(CultureInfo.InvariantCulture);
                        this.textures[1] = str2.ToLower(CultureInfo.InvariantCulture);
                        if (this.texturingProperty.HasBaseTexture())
                        {
                            this.TextureClampMode = this.texturingProperty.GetBaseTexture().clampMode;
                        }
                        this.shaderType = type;
                        break;
                    }
                }
            }

            for (int index = 0; index < this.textures.Length; index++)
            {
                this.textures[index] = this.textures[index].Trim();
                if (this.textures[index].Contains(".dds") && !this.textures[index].Contains("textures\\"))
                {
                    this.textures[index] = Path.Combine("textures\\", this.textures[index]);
                }
            }

            if (((Game.Mode == "convert4" || Game.Mode == "convert5") && useOptimizer && AtlasList.Contains(this.textures[0])) || this.textures[0] == "textures\\grid.dds")
            {
                string texture = this.textures[0];
                geometry      = geometry.ReUV(this, texture, logFile, verbose);
                this.textures = new string[10] {
                    "", "", "", "", "", "", "", "", "", ""
                };
                this.textures[0] = AtlasList.Get(texture).AtlasTexture;
                this.textures[1] = AtlasList.Get(texture).AtlasTextureN;
                if (this.textures[2] != "")
                {
                    this.textures[2] = AtlasList.Get(texture).AtlasTexture;
                }
                if (Game.Mode == "fo4")
                {
                    this.textures[7] = AtlasList.Get(texture).AtlasTextureS;
                }
                this.TextureClampMode = 0U;
                this.isHighDetail     = false;
            }
            else if ((Game.Mode == "convert4" || Game.Mode == "convert5") && useOptimizer && verbose)
            {
                logFile.WriteLog(this.staticModel + " " + this.name + " " + this.textures[0] + " not in atlas file");
            }
            if (!geometry.HasNormals())
            {
                geometry.FaceNormals();
                geometry.SmoothNormals(60f, 0.001f);
            }
            if (fixTangents && !geometry.HasTangents())
            {
                geometry.UpdateTangents(fixTangents);
            }
        }
コード例 #9
0
 public void ShrinkByBox(BBox boundingBox)
 {
     if (boundingBox.px1 > this.px1)
     {
         this.px1 = boundingBox.px1;
     }
     if (boundingBox.px2 < this.px2)
     {
         this.px2 = boundingBox.px2;
     }
     if (boundingBox.py1 > this.py1)
     {
         this.py1 = boundingBox.py1;
     }
     if (boundingBox.py2 < this.py2)
     {
         this.py2 = boundingBox.py2;
     }
     if (boundingBox.pz1 > this.pz1)
     {
         this.pz1 = boundingBox.pz1;
     }
     if (boundingBox.pz2 < this.pz2)
     {
         this.pz2 = boundingBox.pz2;
     }
 }
コード例 #10
0
 private QuadTreeLeaf CreateSegment(int segmentnumber, int quadLevel, List<Triangle> triangles, List<Vector3> vertices)
 {
     quadLevel = (int)(this.sampleSize * quadLevel);
     QuadTreeLeaf quadTreeLeaf = new QuadTreeLeaf();
     List<Triangle> triangles1 = new List<Triangle>();
     int segmentx = segmentnumber / quadLevel;
     int segmenty = segmentnumber - (segmentx * quadLevel);
     quadTreeLeaf.boundingBox.Set(float.MaxValue, float.MinValue, float.MaxValue, float.MinValue, float.MaxValue, float.MinValue);
     BBox bbox = new BBox();
     bbox.Set((float)segmentx / quadLevel * 4096, ((float)segmentx + 1) / quadLevel * 4096, (float)segmenty / quadLevel * 4096, ((float)segmenty + 1) / quadLevel * 4096, 0f, 0f);
     for (int index = 0; index < triangles.Count; index++)
     {
         BBox tbox = new BBox(float.MaxValue, float.MinValue, float.MaxValue, float.MinValue, float.MaxValue, float.MinValue);
         for (int index2 = 0; index2 < 3; index2++)
         {
             Vector3 vertex = vertices[triangles[index][index2]];
             tbox.GrowByVertex(vertex);
         }
         if (tbox.px2 >= bbox.px1 && tbox.px1 <= bbox.px2 && tbox.py2 >= bbox.py1 && tbox.py1 <= bbox.py2)
         {
             triangles1.Add(triangles[index]);
             quadTreeLeaf.boundingBox.GrowByBox(tbox);
         }
     }
     quadTreeLeaf.triangles = triangles1;
     return quadTreeLeaf;
 }
コード例 #11
0
 private bool LoadTerrainQuad(QuadDesc quad, out QuadTree qt, out QuadTree waterQt, out BBox boundingBox)
 {
     bool flag = false;
     string str = "";
     if (Game.Mode == "fnv")
     {
         str = "meshes\\landscape\\lod\\" + this.worldspaceName + "\\" + this.worldspaceName + ".Level" + this.quadLevel.ToString() + ".X" + quad.x.ToString() + ".Y" + quad.y.ToString() + ".nif";
     }
     else
     {
         str = "meshes\\terrain\\" + this.worldspaceName + "\\" + this.worldspaceName + "." + this.quadLevel.ToString() + "." + quad.x.ToString() + "." + quad.y.ToString() + ".btr";
     }
     boundingBox = new BBox();
     qt = (QuadTree)null;
     waterQt = (QuadTree)null;
     if (!File.Exists(this.gameDir + str) && !BSAArchive.FileExists(str))
     {
         if (this.verbose)
         {
             this.logFile.WriteLog("terrain file not found " + str);
         }
     }
     else
     {
         //Console.WriteLine("Doing " + str);
         //logFile.WriteLog("Doing " + str);
         NiFile niFile = new NiFile();
         niFile.Read(this.gameDir, str, logFile);
         BSMultiBoundNode bsMultiBoundNode1 = (BSMultiBoundNode)niFile.GetBlockAtIndex(0);
         if (bsMultiBoundNode1 != null && bsMultiBoundNode1.GetNumChildren() > 0U)
         {
             BSMultiBound bsMultiBound1 = (BSMultiBound)niFile.GetBlockAtIndex(bsMultiBoundNode1.GetMultiBound());
             BSMultiBoundAABB bsMultiBoundAabb1 = bsMultiBound1 != null ? (BSMultiBoundAABB)niFile.GetBlockAtIndex(bsMultiBound1.GetData()) : (BSMultiBoundAABB)null;
             if (bsMultiBound1 != null && bsMultiBoundAabb1 != null)
             {
                 NiTriShape niTriShape = (NiTriShape)niFile.GetBlockAtIndex(bsMultiBoundNode1.GetChildAtIndex(0));
                 if (niTriShape != null)
                 {
                     NiTriShapeData data = (NiTriShapeData)niFile.GetBlockAtIndex(niTriShape.GetData());
                     Vector3 vector3_1 = bsMultiBoundAabb1.GetPosition() / 4;
                     Vector3 vector3_2 = bsMultiBoundAabb1.GetExtent() / 4;
                     boundingBox.Set(vector3_1[0] - vector3_2[0], vector3_1[0] + vector3_2[0], vector3_1[1] - vector3_2[1], vector3_1[1] + vector3_2[1], vector3_1[2] - vector3_2[2], vector3_1[2] + vector3_2[2]);
                     List<Vector3> vertices = data.GetVertices();
                     if (Game.Mode == "fnv")
                     {
                         for (int index = 0; index < vertices.Count; index++)
                         {
                             vertices[index] = vertices[index] / quadLevel;
                         }
                     }
                     List<Triangle> triangles = data.GetTriangles();
                     for (int index = 0; index < triangles.Count; index++)
                     {
                         Vector3 vertA = vertices[triangles[index][0]];
                         Vector3 vertB = vertices[triangles[index][1]];
                         Vector3 vertC = vertices[triangles[index][2]];
                         if ((vertA[0] == 0 && vertB[0] == 0 && vertC[0] == 0) || (vertA[0] == 4096 && vertB[0] == 4096 && vertC[0] == 4096) || (vertA[1] == 0 && vertB[1] == 0 && vertC[1] == 0) || (vertA[1] == 4096 && vertB[1] == 4096 && vertC[1] == 4096))
                         {
                             triangles.RemoveAt(index);
                             --index;
                         }
                     }
                     data.SetVertices(vertices);
                     data.SetTriangles(triangles);
                     qt = new QuadTree(data, quadLevel);
                     if (qt != null)
                         flag = true;
                 }
             }
             if (Game.Mode != "fnv" && this.removeUnderwaterFaces && bsMultiBoundNode1.GetNumChildren() > 1U)
             {
                 BSMultiBoundNode bsMultiBoundNode2 = (BSMultiBoundNode)niFile.GetBlockAtIndex(bsMultiBoundNode1.GetChildAtIndex(1));
                 if (bsMultiBoundNode2 != null)
                 {
                     BSMultiBound bsMultiBound2 = (BSMultiBound)niFile.GetBlockAtIndex(bsMultiBoundNode2.GetMultiBound());
                     BSMultiBoundAABB bsMultiBoundAabb2 = (BSMultiBoundAABB)niFile.GetBlockAtIndex(bsMultiBound2.GetData());
                     NiTriShapeData datacombined = new NiTriShapeData();
                     ushort numVertices = 0;
                     for (int index = 0; index < bsMultiBoundNode2.GetNumChildren(); index++)
                     {
                         NiObject blockAtIndex = niFile.GetBlockAtIndex(bsMultiBoundNode2.GetChildAtIndex(index));
                         if (blockAtIndex != null)
                         {
                             NiTriShapeData data;
                             if (blockAtIndex.GetClassName() == "BSSegmentedTriShape")
                             {
                                 BSSegmentedTriShape segmentedTriShape = (BSSegmentedTriShape)blockAtIndex;
                                 data = (NiTriShapeData)niFile.GetBlockAtIndex(segmentedTriShape.GetData());
                             }
                             else
                             {
                                 NiTriShape niTriShape = (NiTriShape)blockAtIndex;
                                 data = (NiTriShapeData)niFile.GetBlockAtIndex(niTriShape.GetData());
                             }
                             if (index == 0)
                             {
                                 datacombined = data;
                                 numVertices += data.GetNumVertices();
                             }
                             else
                             {
                                 datacombined.AppendVertices(data.GetVertices());
                                 List<Triangle> triangles = new List<Triangle>(data.GetTriangles());
                                 for (int index2 = 0; index2 < triangles.Count; ++index2)
                                 {
                                     triangles[index2][0] += numVertices;
                                     triangles[index2][1] += numVertices;
                                     triangles[index2][2] += numVertices;
                                 }
                                 datacombined.AppendTriangles(triangles);
                                 numVertices += data.GetNumVertices();
                             }
                         }
                     }
                     Vector3 vector3_1 = bsMultiBoundAabb2.GetPosition() / 4;
                     Vector3 vector3_2 = bsMultiBoundAabb2.GetExtent() / 4;
                     BBox boundingBox1 = new BBox(vector3_1[0] - vector3_2[0], vector3_1[0] + vector3_2[0], vector3_1[1] - vector3_2[1], vector3_1[1] + vector3_2[1], vector3_1[2] - vector3_2[2], vector3_1[2] + vector3_2[2]);
                     waterQt = new QuadTree(datacombined, quadLevel);
                 }
             }
         }
     }
     return flag;
 }
コード例 #12
0
 private void GenerateMultibound(NiFile file, BSMultiBoundNode node, QuadDesc curQuad, BBox bb)
 {
     if ((Game.Mode != "fnv") || (Game.Mode == "fnv" && node.GetMultiBound() == -1))
     {
         BSMultiBound bsMultiBound = new BSMultiBound();
         node.SetMultiBound(file.AddBlock((NiObject)bsMultiBound));
         BSMultiBoundAABB bsMultiBoundAabb = new BSMultiBoundAABB();
         bsMultiBound.SetData(file.AddBlock((NiObject)bsMultiBoundAabb));
         float num1 = (float)curQuad.x * 4096f;
         float num2 = (float)curQuad.y * 4096f;
         bsMultiBoundAabb.SetPosition(new Vector3((float)(((double)num1 + (double)bb.px1 + ((double)num1 + (double)bb.px2)) / 2.0), (float)(((double)num2 + (double)bb.py1 + ((double)num2 + (double)bb.py2)) / 2.0), (float)(((double)bb.pz1 + (double)bb.pz2) / 2.0)));
         bsMultiBoundAabb.SetExtent(new Vector3((float)(((double)bb.px2 - (double)bb.px1) / 2.0), (float)(((double)bb.py2 - (double)bb.py1) / 2.0), (float)(((double)bb.pz2 - (double)bb.pz1) / 2.0)));
     }
 }
コード例 #13
0
 private ShapeDesc TransformShape(QuadDesc quad, StaticDesc stat, NiFile file, NiTriBasedGeom geom, Matrix44 parentTransform, float parentScale)
 {
     BBox bbox = new BBox(float.MaxValue, float.MinValue, float.MaxValue, float.MinValue, float.MaxValue, float.MinValue);
     ShapeDesc shape1 = new ShapeDesc();
     NiTriShape shape2;
     NiTriShapeData data = new NiTriShapeData();
     //Console.WriteLine("Reading block #" + geom.GetData());
     if (geom.GetClassName() == "NiTriStrips")
     {
         shape2 = new NiTriShape(geom);
         data = new NiTriShapeData((NiTriStripsData)file.GetBlockAtIndex(geom.GetData()));
     }
     else if (geom.GetClassName() == "BSLODTriShape")
     {
         shape2 = new NiTriShape(geom);
         data = (NiTriShapeData)file.GetBlockAtIndex(geom.GetData());
     }
     else
     {
         shape2 = new NiTriShape(geom);
         data = (NiTriShapeData)file.GetBlockAtIndex(geom.GetData());
     }
     if (verbose && !data.HasVertexColors() && ((this.GetShaderFlags2(file, shape2) & 32) == 32))
     {
         if (!stat.staticModels[this.quadIndex].Contains("glacierrubbletrim0"))
         {
             logFile.WriteLog("Vertex Colors Flag, but no vertex colors in " + stat.staticModels[this.quadIndex]);
         }
     }
     if (((int)data.GetBSNumUVSets() & 1) == 0)
         return shape1;
     float _x = stat.x - (float)quad.x * 4096f;
     float _y = stat.y - (float)quad.y * 4096f;
     Matrix33 matrix33_1 = new Matrix33(true);
     Matrix33 matrix33_2 = new Matrix33(true);
     Matrix33 matrix33_3 = new Matrix33(true);
     matrix33_1.SetRotationX(Utils.ToRadians(-stat.rotX));
     matrix33_2.SetRotationY(Utils.ToRadians(-stat.rotY));
     matrix33_3.SetRotationZ(Utils.ToRadians(-stat.rotZ));
     Matrix44 matrix44 = new Matrix44(new Matrix33(true) * matrix33_1 * matrix33_2 * matrix33_3, new Vector3(_x, _y, stat.z), 1f);
     List<Vector3> vertices = new List<Vector3>(data.GetVertices());
     List<Vector3> normals = new List<Vector3>(data.GetNormals());
     List<Vector3> tangents = new List<Vector3>(data.GetTangents());
     List<Vector3> bitangents = new List<Vector3>(data.GetBitangents());
     // generate tangents independent of fix tangents setting
     bool newtangents = false;
     bool newbitangents = false;
     if (this.generateTangents && data.HasNormals())
     {
         if (tangents.Count == 0)
         {
             newtangents = true;
             for (int index = 0; index < vertices.Count; ++index)
                 tangents.Add(new Vector3(0.0f, 0.0f, 0.0f));
         }
         if (bitangents.Count == 0)
         {
             newbitangents = true;
             for (int index = 0; index < vertices.Count; ++index)
                 bitangents.Add(new Vector3(0.0f, 0.0f, 0.0f));
         }
     }
     for (int index = 0; index < vertices.Count; ++index)
     {
         vertices[index] *= shape2.GetScale() * parentScale;
         vertices[index] *= shape2.GetTransform() * parentTransform;
         vertices[index] *= stat.scale;
         vertices[index] *= matrix44;
         if (data.HasNormals())
         {
             normals[index] *= parentTransform.RemoveTranslation() * shape2.GetTransform().RemoveTranslation();
             normals[index] *= matrix44.RemoveTranslation();
             // adjust tangents as well
             if (tangents.Count != 0)
             {
                 tangents[index] *= parentTransform.RemoveTranslation() * shape2.GetTransform().RemoveTranslation();
                 tangents[index] *= matrix44.RemoveTranslation();
             }
             // adjust bitangents as well
             if (bitangents.Count != 0)
             {
                 bitangents[index] *= parentTransform.RemoveTranslation() * shape2.GetTransform().RemoveTranslation();
                 bitangents[index] *= matrix44.RemoveTranslation();
             }
             // fix tangents when they were newly generated
             if (newtangents || newbitangents || this.fixTangents)
             {
                 Vector3 vector3_1 = Vector3.Cross(normals[index], new Vector3(0.0f, 0.0f, 1f));
                 Vector3 vector3_2 = Vector3.Cross(normals[index], new Vector3(0.0f, 1f, 0.0f));
                 if (newtangents)
                 {
                     tangents[index] = (double)vector3_1.Length > (double)vector3_2.Length ? vector3_1 : vector3_2;
                     tangents[index].Normalize();
                 }
                 if (newbitangents)
                 {
                     bitangents[index] = Vector3.Cross(normals[index], tangents[index]);
                     bitangents[index].Normalize();
                 }
             }
         }
         bbox.GrowByVertex(vertices[index]);
         vertices[index] /= (float)this.quadLevel;
     }
     data.SetVertices(vertices);
     if (data.HasNormals())
     {
         data.SetNormals(normals);
         data.SetHasTangents(false);
     }
     data.SetCenter(new Vector3((float)(((double)bbox.px1 + (double)bbox.px2) / 2.0), (float)(((double)bbox.py1 + (double)bbox.py2) / 2.0), (float)(((double)bbox.pz1 + (double)bbox.pz2) / 2.0)) / (float)this.quadLevel);
     data.SetRadius(this.CalcRadius(data));
     data.SetConsistencyFlags((ushort)0);
     data.SetKeepFlags((byte)51);
     data.SetSkyrimMaterial(0U);
     shape1.shape = shape2;
     shape1.data = data;
     // relative x, y for segment
     shape1.x = _x;
     shape1.y = _y;
     shape1.boundingBox = bbox;
     //Console.WriteLine(stat.staticName + " 2 " + stat.refID + " " + file + " " + shape2.GetName() + " ");
     shape1.textures = this.GetMeshTextures(file, shape2);
     shape1.material = stat.materialName;
     shape1.isHighDetail = false;
     if (useHDFlag)
     {
         if ((stat.refFlags & 131072) == 131072)
         {
             if (HDMeshList.Any(stat.staticModels[this.quadIndex].ToLower().Contains))
             {
                 shape1.isHighDetail = true;
             }
             else if (notHDMeshList.Any(stat.staticModels[this.quadIndex].ToLower().Contains))
             {
                 shape1.isHighDetail = false;
             }
             else
             {
                 shape1.isHighDetail = true;
             }
         }
     }
     // Shader Flags 2 SLSF2_Double_Sided
     shape1.isDoubleSided = (this.GetShaderFlags2(file, shape2) & 16) == 16;
     // clamp mode for atlas
     shape1.TextureClampMode = this.GetTextureClampMode(file, shape2);
     /*if ((this.GetShaderFlags1(file, shape2) & 1) == 1)
     {
         //logFile.WriteLog("Specular" + stat.staticModels[this.quadIndex]);
     }*/
     if (AtlasList.Contains(shape1.textures[0]))
     {
         if (this.UVAtlas(data, shape1.textures[0], stat))
         {
             string[] strArray = new string[2];
             strArray[0] = AtlasList.Get(shape1.textures[0]).AtlasTexture;
             strArray[1] = AtlasList.Get(shape1.textures[0]).AtlasTextureN;
             shape1.textures = strArray;
             shape1.TextureClampMode = 0U;
             shape1.isHighDetail = false;
         }
     }
     else
     {
         if (useOptimizer && quadLevel != 4 && shape1.textures[0].ToLower().Contains("mountainslab01"))
         {
             string[] strArray = new string[2];
             strArray[0] = "textures\\landscape\\mountains\\mountainslab02.dds";
             strArray[1] = "textures\\landscape\\mountains\\mountainslab02_n.dds";
             shape1.textures = strArray;
         }
         if (notHDTextureList.Any(shape1.textures[0].Contains))
         {
             if (this.verbose)
             {
                 logFile.WriteLog("No atlas for " + shape1.textures[0] + " in " + stat.staticModels[this.quadIndex]);
             }
         }
         else
         {
             if (!useHDFlag)
             {
                 shape1.isHighDetail = true;
             }
         }
     }
     if (notHDTextureList.Any(shape1.textures[0].Contains))
     {
         shape1.isHighDetail = false;
     }
     if (HDTextureList.Any(shape1.textures[0].Contains))
     {
         shape1.isHighDetail = true;
     }
     if (shape1.textures[0].Contains("dyndolod\\lod"))
     {
         shape1.TextureClampMode = 0U;
         shape1.isHighDetail = false;
     }
     if (!this.generateVertexColors || (this.quadLevel != 4 && !shape1.isHighDetail))
     {
         data.SetHasVertexColors(false);
         shape1.hasVertexColor = false;
     }
     if (this.generateTangents)
     {
         //shape1.material.Length != 0
         if (!useOptimizer || (useOptimizer && (this.quadLevel == 4 || shape1.isHighDetail)))
         {
             data.SetTangents(tangents);
             data.SetBitangents(bitangents);
         }
     }
     if (this.removeUnseenFaces && quad.hasTerrainVertices)
     {
         this.RemoveUnseenFaces(quad, data, shape1);
         if ((int)data.GetNumTriangles() == 0)
             return (ShapeDesc)null;
     }
     else
     {
         quad.outValues.totalTriCount += data.GetNumTriangles();
         quad.outValues.reducedTriCount += data.GetNumTriangles();
     }
     this.GenerateSegments(quad, ref shape1);
     return shape1;
 }