public Matrix44(Matrix33 rot, Vector3 pos, float scale)
 {
     Matrix44 matrix44_1 = new Matrix44();
     matrix44_1[0][0] = rot[0][0];
     matrix44_1[0][1] = rot[1][0];
     matrix44_1[0][2] = rot[2][0];
     matrix44_1[0][3] = 0.0f;
     matrix44_1[1][0] = rot[0][1];
     matrix44_1[1][1] = rot[1][1];
     matrix44_1[1][2] = rot[2][1];
     matrix44_1[1][3] = 0.0f;
     matrix44_1[2][0] = rot[0][2];
     matrix44_1[2][1] = rot[1][2];
     matrix44_1[2][2] = rot[2][2];
     matrix44_1[2][3] = 0.0f;
     matrix44_1[3][0] = pos[0];
     matrix44_1[3][1] = pos[1];
     matrix44_1[3][2] = pos[2];
     matrix44_1[3][3] = 1f;
     Matrix44 matrix44_2 = new Matrix44();
     matrix44_2[0][0] = scale;
     matrix44_2[0][1] = 0.0f;
     matrix44_2[0][2] = 0.0f;
     matrix44_2[0][3] = 0.0f;
     matrix44_2[1][0] = 0.0f;
     matrix44_2[1][1] = scale;
     matrix44_2[1][2] = 0.0f;
     matrix44_2[1][3] = 0.0f;
     matrix44_2[2][0] = 0.0f;
     matrix44_2[2][1] = 0.0f;
     matrix44_2[2][2] = scale;
     matrix44_2[2][3] = 0.0f;
     matrix44_2[3][0] = 0.0f;
     matrix44_2[3][1] = 0.0f;
     matrix44_2[3][2] = 0.0f;
     matrix44_2[3][3] = 1f;
     Matrix44 matrix44_3 = matrix44_1 * matrix44_2;
     this.m1 = new float[4];
     this.m2 = new float[4];
     this.m3 = new float[4];
     this.m4 = new float[4];
     this.m1[0] = matrix44_3[0][0];
     this.m1[1] = matrix44_3[0][1];
     this.m1[2] = matrix44_3[0][2];
     this.m1[3] = matrix44_3[0][3];
     this.m2[0] = matrix44_3[1][0];
     this.m2[1] = matrix44_3[1][1];
     this.m2[2] = matrix44_3[1][2];
     this.m2[3] = matrix44_3[1][3];
     this.m3[0] = matrix44_3[2][0];
     this.m3[1] = matrix44_3[2][1];
     this.m3[2] = matrix44_3[2][2];
     this.m3[3] = matrix44_3[2][3];
     this.m4[0] = matrix44_3[3][0];
     this.m4[1] = matrix44_3[3][1];
     this.m4[2] = matrix44_3[3][2];
     this.m4[3] = matrix44_3[3][3];
 }
Beispiel #2
0
 public static void WriteMatrix33(BinaryWriter writer, Matrix33 value)
 {
     for (int index1 = 0; index1 < 3; ++index1)
     {
         for (int index2 = 0; index2 < 3; ++index2)
         {
             writer.Write(value[index1][index2]);
         }
     }
 }
        public static Matrix33 operator *(Matrix33 a, Matrix33 b)
        {
            Matrix33 matrix33 = new Matrix33(true);

            for (int index1 = 0; index1 < 3; ++index1)
            {
                for (int index2 = 0; index2 < 3; ++index2)
                {
                    matrix33[index1][index2] = (float)((double)a[index1][0] * (double)b[0][index2] + (double)a[index1][1] * (double)b[1][index2] + (double)a[index1][2] * (double)b[2][index2]);
                }
            }
            return(matrix33);
        }
 public Matrix33(Matrix33 val)
 {
     this.m1 = new float[3];
     this.m2 = new float[3];
     this.m3 = new float[3];
     this.m1[0] = val[0][0];
     this.m1[1] = val[0][1];
     this.m1[2] = val[0][2];
     this.m2[0] = val[1][0];
     this.m2[1] = val[1][1];
     this.m2[2] = val[1][2];
     this.m3[0] = val[2][0];
     this.m3[1] = val[2][1];
     this.m3[2] = val[2][2];
 }
 public Matrix33(Matrix33 val)
 {
     this.m1    = new float[3];
     this.m2    = new float[3];
     this.m3    = new float[3];
     this.m1[0] = val[0][0];
     this.m1[1] = val[0][1];
     this.m1[2] = val[0][2];
     this.m2[0] = val[1][0];
     this.m2[1] = val[1][1];
     this.m2[2] = val[1][2];
     this.m3[0] = val[2][0];
     this.m3[1] = val[2][1];
     this.m3[2] = val[2][2];
 }
Beispiel #6
0
        public Quaternion(Matrix33 m)
        {
            float[] numArray1 = new float[4];
            int[]   numArray2 = new int[3]
            {
                1,
                2,
                0
            };
            float num1 = m[0][0] + m[1][1] + m[2][2];

            if ((double)num1 > 0.0)
            {
                float num2 = (float)Math.Sqrt((double)num1 + 1.0);
                this.w = num2 / 2f;
                float num3 = 0.5f / num2;
                this.x = (m[1][2] - m[2][1]) * num3;
                this.y = (m[2][0] - m[0][2]) * num3;
                this.z = (m[0][1] - m[1][0]) * num3;
            }
            else
            {
                int index1 = 0;
                if ((double)m[1][1] > (double)m[0][0])
                {
                    index1 = 1;
                }
                if ((double)m[2][2] > (double)m[index1][index1])
                {
                    index1 = 2;
                }
                int   index2 = numArray2[index1];
                int   index3 = numArray2[index2];
                float num2   = (float)Math.Sqrt((double)m[index1][index1] - ((double)m[index2][index2] + (double)m[index3][index3]) + 1.0);
                numArray1[index1] = num2 * 0.5f;
                if ((double)num2 != 0.0)
                {
                    num2 = 0.5f / num2;
                }
                numArray1[3]      = (m[index2][index3] - m[index3][index2]) * num2;
                numArray1[index2] = (m[index1][index2] + m[index2][index1]) * num2;
                numArray1[index3] = (m[index1][index3] + m[index3][index1]) * num2;
                this.x            = numArray1[0];
                this.y            = numArray1[1];
                this.z            = numArray1[2];
                this.w            = numArray1[3];
            }
        }
 public NiAVObject()
 {
     if (Game.Mode == "fnv")
     {
         this.flags = (ushort)2062;
         this.flags2 = (ushort)8;
     }
     else
     {
         this.flags = (ushort)14;
         this.flags2 = (ushort)0;
     }
     this.translation = new Vector3(0.0f, 0.0f, 0.0f);
     this.rotation = new Matrix33(true);
     this.scale = 1f;
     this.numProperties = 0U;
     this.properties = new List<int>();
     this.collisionObject = -1;
 }
 public Quaternion(Matrix33 m)
 {
     float[] numArray1 = new float[4];
     int[] numArray2 = new int[3]
       {
     1,
     2,
     0
       };
     float num1 = m[0][0] + m[1][1] + m[2][2];
     if ((double)num1 > 0.0)
     {
         float num2 = (float)Math.Sqrt((double)num1 + 1.0);
         this.w = num2 / 2f;
         float num3 = 0.5f / num2;
         this.x = (m[1][2] - m[2][1]) * num3;
         this.y = (m[2][0] - m[0][2]) * num3;
         this.z = (m[0][1] - m[1][0]) * num3;
     }
     else
     {
         int index1 = 0;
         if ((double)m[1][1] > (double)m[0][0])
             index1 = 1;
         if ((double)m[2][2] > (double)m[index1][index1])
             index1 = 2;
         int index2 = numArray2[index1];
         int index3 = numArray2[index2];
         float num2 = (float)Math.Sqrt((double)m[index1][index1] - ((double)m[index2][index2] + (double)m[index3][index3]) + 1.0);
         numArray1[index1] = num2 * 0.5f;
         if ((double)num2 != 0.0)
             num2 = 0.5f / num2;
         numArray1[3] = (m[index2][index3] - m[index3][index2]) * num2;
         numArray1[index2] = (m[index1][index2] + m[index2][index1]) * num2;
         numArray1[index3] = (m[index1][index3] + m[index3][index1]) * num2;
         this.x = numArray1[0];
         this.y = numArray1[1];
         this.z = numArray1[2];
         this.w = numArray1[3];
     }
 }
 public static Matrix33 operator *(Matrix33 a, Matrix33 b)
 {
     Matrix33 matrix33 = new Matrix33(true);
     for (int index1 = 0; index1 < 3; ++index1)
     {
         for (int index2 = 0; index2 < 3; ++index2)
             matrix33[index1][index2] = (float)((double)a[index1][0] * (double)b[0][index2] + (double)a[index1][1] * (double)b[1][index2] + (double)a[index1][2] * (double)b[2][index2]);
     }
     return matrix33;
 }
Beispiel #10
0
        public Matrix44(Matrix33 rot, Vector3 pos, float scale)
        {
            Matrix44 matrix44_1 = new Matrix44();

            matrix44_1[0][0] = rot[0][0];
            matrix44_1[0][1] = rot[1][0];
            matrix44_1[0][2] = rot[2][0];
            matrix44_1[0][3] = 0.0f;
            matrix44_1[1][0] = rot[0][1];
            matrix44_1[1][1] = rot[1][1];
            matrix44_1[1][2] = rot[2][1];
            matrix44_1[1][3] = 0.0f;
            matrix44_1[2][0] = rot[0][2];
            matrix44_1[2][1] = rot[1][2];
            matrix44_1[2][2] = rot[2][2];
            matrix44_1[2][3] = 0.0f;
            matrix44_1[3][0] = pos[0];
            matrix44_1[3][1] = pos[1];
            matrix44_1[3][2] = pos[2];
            matrix44_1[3][3] = 1f;
            Matrix44 matrix44_2 = new Matrix44();

            matrix44_2[0][0] = scale;
            matrix44_2[0][1] = 0.0f;
            matrix44_2[0][2] = 0.0f;
            matrix44_2[0][3] = 0.0f;
            matrix44_2[1][0] = 0.0f;
            matrix44_2[1][1] = scale;
            matrix44_2[1][2] = 0.0f;
            matrix44_2[1][3] = 0.0f;
            matrix44_2[2][0] = 0.0f;
            matrix44_2[2][1] = 0.0f;
            matrix44_2[2][2] = scale;
            matrix44_2[2][3] = 0.0f;
            matrix44_2[3][0] = 0.0f;
            matrix44_2[3][1] = 0.0f;
            matrix44_2[3][2] = 0.0f;
            matrix44_2[3][3] = 1f;
            Matrix44 matrix44_3 = matrix44_1 * matrix44_2;

            this.m1    = new float[4];
            this.m2    = new float[4];
            this.m3    = new float[4];
            this.m4    = new float[4];
            this.m1[0] = matrix44_3[0][0];
            this.m1[1] = matrix44_3[0][1];
            this.m1[2] = matrix44_3[0][2];
            this.m1[3] = matrix44_3[0][3];
            this.m2[0] = matrix44_3[1][0];
            this.m2[1] = matrix44_3[1][1];
            this.m2[2] = matrix44_3[1][2];
            this.m2[3] = matrix44_3[1][3];
            this.m3[0] = matrix44_3[2][0];
            this.m3[1] = matrix44_3[2][1];
            this.m3[2] = matrix44_3[2][2];
            this.m3[3] = matrix44_3[2][3];
            this.m4[0] = matrix44_3[3][0];
            this.m4[1] = matrix44_3[3][1];
            this.m4[2] = matrix44_3[3][2];
            this.m4[3] = matrix44_3[3][3];
        }
 public static void WriteMatrix33(BinaryWriter writer, Matrix33 value)
 {
     for (int index1 = 0; index1 < 3; ++index1)
     {
         for (int index2 = 0; index2 < 3; ++index2)
             writer.Write(value[index1][index2]);
     }
 }
 public void SetRotation(Matrix33 rot)
 {
     this.rotation = rot;
 }
 public override void Read(NiHeader header, BinaryReader reader)
 {
     base.Read(header, reader);
     this.flags = reader.ReadUInt16();
     if ((header.GetUserVersion() >= 11U) && (header.GetUserVersion2() >= 26U))
         this.flags2 = reader.ReadUInt16();
     this.translation = Utils.ReadVector3(reader);
     this.rotation = Utils.ReadMatrix33(reader);
     this.scale = reader.ReadSingle();
     if ((header.GetVersion() <= 335544325U) || (header.GetUserVersion() <= 11U))
     {
         this.numProperties = reader.ReadUInt32();
         for (int index = 0; (long)index < (long)this.numProperties; ++index)
             this.properties.Add(reader.ReadInt32());
     }
     else
     {
     }
     this.collisionObject = reader.ReadInt32();
 }
 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;
 }