Exemplo n.º 1
0
        private Mesh NiTriShapeDataToMesh(NiTriShapeData data)
        {
            // vertex positions
            var vertices = new Vector3[data.Vertices.Length];

            for (var i = 0; i < vertices.Length; i++)
            {
                vertices[i] = NifUtils.NifPointToUnityPoint(data.Vertices[i]);
            }
            // vertex normals
            Vector3[] normals = null;
            if (data.HasNormals)
            {
                normals = new Vector3[vertices.Length];
                for (var i = 0; i < normals.Length; i++)
                {
                    normals[i] = NifUtils.NifVectorToUnityVector(data.Normals[i]);
                }
            }
            // vertex UV coordinates
            Vector2[] UVs = null;
            if (data.HasUV)
            {
                UVs = new Vector2[vertices.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[data.NumTrianglePoints];

            for (var i = 0; i < data.Triangles.Length; i++)
            {
                var baseI = 3 * i;
                // Reverse triangle winding order.
                triangles[baseI]     = data.Triangles[i].v1;
                triangles[baseI + 1] = data.Triangles[i].v3;
                triangles[baseI + 2] = data.Triangles[i].v2;
            }

            // Create the mesh.
            var mesh = new Mesh
            {
                vertices  = vertices,
                normals   = normals,
                uv        = UVs,
                triangles = triangles
            };

            if (!data.HasNormals)
            {
                mesh.RecalculateNormals();
            }
            mesh.RecalculateBounds();
            return(mesh);
        }
Exemplo n.º 2
0
 private 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;
 }