Beispiel #1
0
        //void ApplyNiAVObject(NiAVObject niAVObject, GameObject obj)
        //{
        //    obj.transform.position = NifUtils.NifPointToUnityPoint(niAVObject.Translation);
        //    obj.transform.rotation = NifUtils.NifRotationMatrixToUnityQuaternion(niAVObject.Rotation);
        //    obj.transform.localScale = niAVObject.Scale * Vector3.one;
        //}

        Mesh MeshLodDataToMesh(SiMeshLod data)
        {
            // vertex positions
            var vertices = new Vector3[data.Vertices.Length];

            for (var i = 0; i < vertices.Length; i++)
            {
                vertices[i] = data.Vertices[i].ToUnityVector(ConvertUtils.MeterInUnits);
            }
            var hasNormals = false;
            var faces      = data.Faces;

            // vertex normals
            Vector3[] normals = null;
            if (hasNormals) // has normals
            {
                //normals = new Vector3[faces.Length];
                //for (var i = 0; i < normals.Length; i++)
                //    normals[i] = data.Faces[i].NormalVector.ToUnityVector();
            }
            // vertex UV coordinates
            Vector2[] UVs = null;
            if (true) // has uv
            {
                //UVs = new Vector2[faces.Length];
                //for (var i = 0; i < UVs.Length; i++)
                //{
                //    var NiTexCoord = data.UVSets[0, i];
                //    UVs[i] = new Vector2(NiTexCoord.u, NiTexCoord.v);
                //}
            }
            // triangle vertex indices
            var triangles = new int[faces.Length];

            for (var i = 0; i < faces.Length; i++)
            {
                var baseI = 3 * i;
                // Reverse triangle winding order.
                triangles[baseI]     = (int)faces[i].Points[0].Point;
                triangles[baseI + 1] = (int)faces[i].Points[1].Point;
                triangles[baseI + 2] = (int)faces[i].Points[2].Point;
            }
            // Create the mesh.
            var mesh = new Mesh
            {
                vertices  = vertices,
                normals   = normals,
                uv        = UVs,
                triangles = triangles
            };

            if (!hasNormals)
            {
                mesh.RecalculateNormals();
            }
            mesh.RecalculateBounds();
            return(mesh);
        }
Beispiel #2
0
 public SiMesh(GenericReader r)
 {
     LimbId       = r.ReadUInt32();
     ParentId     = r.ReadUInt32();
     ScaleX       = r.ReadUInt32();
     ScaleY       = r.ReadUInt32();
     ScaleZ       = r.ReadUInt32();
     Position     = r.ReadVector3();
     OrientationW = r.ReadSingle();
     OrientationX = r.ReadSingle();
     OrientationY = r.ReadSingle();
     OrientationZ = r.ReadSingle();
     Lod          = new SiMeshLod(r);
 }
Beispiel #3
0
        MaterialProps MeshLodDataToMaterialProperties(SiMeshLod data)
        {
            // Create the material properties.
            var mp = new MaterialProps();
            var tp = new MaterialTextures();

            foreach (var material in data.Materials)
            {
                if (tp.MainFilePath == null)
                {
                    tp.MainFilePath = material.Texture;
                }
            }
            mp.Textures = tp;
            return(mp);
        }