Ejemplo n.º 1
0
        private Mesh(int index, float[] positions, float[] normals, MeshIndices triangleIndices, float[] textureCoordinates = null, Color?color = null, float[] colors = null, string[] layer = null, string name = null)
        {
            Index            = index;
            Positions        = positions ?? EmptyFloatArray;
            _TriangleIndices = triangleIndices ?? EmptyMeshIndices;

            Normals            = normals ?? EmptyFloatArray;
            TextureCoordinates = textureCoordinates ?? EmptyFloatArray;

            Normals = ValidateAndRegenerateNormals(Positions, Normals, _TriangleIndices.GetIndizes().ToArray());

            Colors = colors;
            Color  = color;
            Layer  = layer;
            Name   = name;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mesh"/> class.
 /// </summary>
 /// <param name="index">The index of the mesh in the <see cref="MeshModelPart"/>..</param>
 /// <param name="positions">The point data array.</param>
 /// <param name="normals">The normal data array.</param>
 /// <param name="triangleIndices">The index array.</param>
 /// <param name="textureCoordinates">The texture coordinate array.</param>
 /// <param name="color">The default color.</param>
 /// <param name="colors">The color data array.</param>
 /// <param name="layer">The layers to which this mesh belongs.</param>
 /// <param name="name">The name.</param>
 public Mesh(int index, float[] positions, float[] normals, int[] triangleIndices, float[] textureCoordinates = null, Color?color = null, float[] colors = null, string[] layer = null, string name = null)
     : this(index, positions, normals, MeshIndices.Create(triangleIndices), textureCoordinates, color, colors, layer, name)
 {
 }
Ejemplo n.º 3
0
        internal static Mesh Read(BinaryReader binaryReader, int index, Version fileVersion)
        {
            float[] positions          = null;
            float[] normals            = null;
            float[] textureCoordinates = null;
            float[] colors             = null;

            MeshIndices indices = null;
            Color?      color   = null;

            string[] layer = null;
            var      name  = string.Empty;

            if (fileVersion >= FileVersion21)
            {
                name = binaryReader.ReadString();
            }

            if (binaryReader.ReadBoolean())
            {
                color = binaryReader.ReadArgbColor();
            }

            if (binaryReader.ReadBoolean())
            {
                positions = fileVersion == FileVersion10
                                        ? binaryReader.ReadDoubleArray(3)
                                        : binaryReader.ReadFloatArray(3);
            }

            if (binaryReader.ReadBoolean())
            {
                normals = fileVersion == FileVersion10
                                        ? binaryReader.ReadDoubleArray(3)
                                        : binaryReader.ReadFloatArray(3);
            }

            if (binaryReader.ReadBoolean())
            {
                indices = binaryReader.ReadIndices(positions?.Length ?? 0);
            }

            if (binaryReader.ReadBoolean())
            {
                layer = new string[binaryReader.ReadInt32()];
                for (var l = 0; l < layer.Length; l++)
                {
                    layer[l] = binaryReader.ReadString();
                }
            }
            if (fileVersion >= FileVersion22 && binaryReader.ReadBoolean())
            {
                textureCoordinates = binaryReader.ReadFloatArray(2);
            }

            if (fileVersion >= FileVersion33 && binaryReader.ReadBoolean())
            {
                colors = binaryReader.ReadFloatArray(4);
            }

            return(new Mesh(index, positions, normals, indices, textureCoordinates, color, colors, layer, name));
        }