コード例 #1
0
        private void ReadVertexStream(Vector2[] targetArray, int arrayPos, Mesh meshData, VertexLayout.EntryInfo info)
        {
            Mesh.VertexStream stream = meshData.VertexStreams[info.streamIndex];

            for (int i = 0; i < meshData.VertexCount; i++)
            {
                targetArray[i + arrayPos] = ReadVector2(info.offset, stream, i, info.dataType);
            }
        }
コード例 #2
0
        private Vector3 ReadVector3(int offset, Mesh.VertexStream vertexStream, int index, VertexLayout.Entry.DataTypes dataType)
        {
            Vector3 vector3 = new Vector3();

            switch (dataType)
            {
                case VertexLayout.Entry.DataTypes.Float3:
                    vector3.x = BitConverter.ToSingle(vertexStream.Data, (vertexStream.BytesPerVertex * index) + offset + 0);
                    vector3.y = BitConverter.ToSingle(vertexStream.Data, (vertexStream.BytesPerVertex * index) + offset + 4);
                    vector3.z = BitConverter.ToSingle(vertexStream.Data, (vertexStream.BytesPerVertex * index) + offset + 8);
                    break;
                default:
                    throw new InvalidDataException($"Unhandled stream DataType \"{dataType}\"");
            }

            return vector3;
        }
コード例 #3
0
        private Vector2 ReadVector2(int offset, Mesh.VertexStream vertexStream, int index, VertexLayout.Entry.DataTypes dataType)
        {
            Vector2 vector2 = new Vector2();

            switch (dataType)
            {
                case VertexLayout.Entry.DataTypes.Float2:
                    vector2.x = BitConverter.ToSingle(vertexStream.Data, (vertexStream.BytesPerVertex * index) + offset + 0);
                    vector2.y = 1.0f - BitConverter.ToSingle(vertexStream.Data, (vertexStream.BytesPerVertex * index) + offset + 4);
                    break;
                case VertexLayout.Entry.DataTypes.float16_2:
                    vector2.x = Mathf.HalfToFloat(BitConverter.ToUInt16(vertexStream.Data, (vertexStream.BytesPerVertex * index) + offset + 0));
                    vector2.y = 1.0f - Mathf.HalfToFloat(BitConverter.ToUInt16(vertexStream.Data, (vertexStream.BytesPerVertex * index) + offset + 2));
                    break;
                default:
                    throw new InvalidDataException($"Unhandled stream DataType \"{dataType}\"");
            }

            return vector2;
        }