private void ParseVertices(PrimitiveData data, byte[] bytes)
        {
            if (data.NumVertices == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(data), "Cannot add vertices when size is unknown.");
            }

            if (bytes.Length < data.NumVertices * Vertex3DNoTex2.Size)
            {
                throw new ArgumentOutOfRangeException($"Tried to read {data.NumVertices} vertices for primitive item \"${data.Name}\" (${data.StorageName}), but only ${bytes.Length} bytes available.");
            }

            if (!(GetValue(data) is Mesh mesh))
            {
                throw new ArgumentException("BiffVertices attribute must sit on a Mesh object.");
            }

            var vertices = new Vertex3DNoTex2[data.NumVertices];

            using (var stream = new MemoryStream(bytes))
                using (var reader = new BinaryReader(stream)) {
                    for (var i = 0; i < data.NumVertices; i++)
                    {
                        vertices[i] = new Vertex3DNoTex2(reader);
                    }
                }
            mesh.Vertices = vertices;
        }
        private void ParseAnimation(PrimitiveData data, byte[] bytes)
        {
            if (data.NumVertices == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(data), "Cannot create animation when size is unknown.");
            }

            if (bytes.Length != data.NumVertices * Mesh.VertData.Size)
            {
                throw new ArgumentOutOfRangeException($"Tried to read {data.NumVertices} vertex animations for primitive item \"${data.Name}\" (${data.StorageName}), but had ${bytes.Length} bytes available.");
            }

            if (!(GetValue(data) is Mesh mesh))
            {
                throw new ArgumentException("BiffAnimationAttribute attribute must sit on a Mesh object.");
            }

            var vertices = new Mesh.VertData[data.NumVertices];

            using (var stream = new MemoryStream(bytes))
                using (var reader = new BinaryReader(stream))
                {
                    for (var i = 0; i < data.NumVertices; i++)
                    {
                        vertices[i] = new Mesh.VertData(reader);
                    }
                }
            mesh.AnimationFrames.Add(vertices);
        }
 private static byte[] SerializeVertices(PrimitiveData data)
 {
     using (var stream = new MemoryStream())
         using (var writer = new BinaryWriter(stream)) {
             for (var i = 0; i < data.NumVertices; i++)
             {
                 data.Mesh.Vertices[i].Write(writer);
             }
             return(stream.ToArray());
         }
 }
 private static byte[] SerializeIndices(PrimitiveData data)
 {
     using (var stream = new MemoryStream())
         using (var writer = new BinaryWriter(stream)) {
             for (var i = 0; i < data.NumIndices; i++)
             {
                 if (data.NumVertices > 65535)
                 {
                     writer.Write((uint)data.Mesh.Indices[i]);
                 }
                 else
                 {
                     writer.Write((ushort)data.Mesh.Indices[i]);
                 }
             }
             return(stream.ToArray());
         }
 }
        private void ParseIndices(PrimitiveData data, byte[] bytes)
        {
            if (data.NumIndices == 0)
            {
                throw new ArgumentOutOfRangeException($"Cannot add indices when size is unknown.");
            }

            if (!(GetValue(data) is Mesh mesh))
            {
                throw new ArgumentException("BiffIndices attribute must sit on a Mesh object.");
            }

            var indices = new int[data.NumIndices];

            using (var stream = new MemoryStream(bytes))
                using (var reader = new BinaryReader(stream)) {
                    for (var i = 0; i < data.NumIndices; i++)
                    {
                        indices[i] = data.NumVertices > 65535 ? (int)reader.ReadUInt32() : reader.ReadUInt16();
                    }
                }
            mesh.Indices = indices;
        }
示例#6
0
 public PrimitiveMeshGenerator(PrimitiveData data)
 {
     _data = data;
 }
示例#7
0
 public PrimitiveHitGenerator(Primitive primitive)
 {
     _primitive = primitive;
     _data      = primitive.Data;
 }