Ejemplo n.º 1
0
        //============================================================
        public void LoadResource()
        {
            // 创建数据
            FByteStream vertexs = new FByteStream();

            float[] vertexData = new float[] {
                -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
                1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
            };
            foreach (float value in vertexData)
            {
                vertexs.WriteFloat(value);
            }
            // 输出索引数据
            FByteStream faces = new FByteStream();

            int[] faceData = new int[] {
                0, 1, 2,
                0, 2, 3,
            };
            foreach (int value in faceData)
            {
                faces.WriteInt32(value);
            }
            // 创建顶点流
            _vertexBuffer        = new FDxVertexBuffer();
            _vertexBuffer.Device = _device;
            _vertexBuffer.UploadNormal(6, vertexs.Memory, 0, vertexs.Length);
            // 创建索引流
            _faceBuffer        = new FDxFaceBuffer();
            _faceBuffer.Device = _device;
            _faceBuffer.Upload32(faces.Memory, 0, faces.Length);
        }
Ejemplo n.º 2
0
        //============================================================
        public void Setup()
        {
            //------------------------------------------------------------
            float[] vertexData = new float[] {
                -1, 1, 0, 1, 0, 0,
                1, 1, 0, 1, 1, 0,
                1, -1, 0, 1, 1, 1,
                -1, -1, 0, 1, 0, 1
            };
            FByteStream vertexStream = new FByteStream();

            foreach (float value in vertexData)
            {
                vertexStream.WriteFloat(value);
            }
            // 创建顶点缓冲
            _vertexBuffer        = new FDxVertexBuffer();
            _vertexBuffer.Device = _device;
            _vertexBuffer.Upload5(6, vertexStream.Memory, 0, vertexStream.Length);
            //------------------------------------------------------------
            int[]       faceData   = new int[] { 0, 1, 2, 0, 2, 3 };
            FByteStream faceStream = new FByteStream();

            foreach (int value in faceData)
            {
                faceStream.WriteInt32(value);
            }
            // 创建面缓冲
            _faceBuffer        = new FDxFaceBuffer();
            _faceBuffer.Device = _device;
            _faceBuffer.Upload(faceStream.Memory, 0, faceStream.Length);
        }
Ejemplo n.º 3
0
        //============================================================
        public void LoadResource(FDrGeometry geometry)
        {
            // 创建数据
            int         faceCount = geometry.FaceList.Count;
            FByteStream vertexs   = new FByteStream(4 * 10 * 3 * faceCount);
            FByteStream faces     = new FByteStream(3 * faceCount);

            for (int f = 0; f < faceCount; f++)
            {
                FDrFace face = geometry.FaceList[f];
                for (int n = 0; n < 3; n++)
                {
                    // 输出顶点数据
                    FDrVertex vertex = geometry.VertexList[face.VertexIndex[n]];
                    FDrCoord  coord  = geometry.CoordList[face.CoordIndex[n]];
                    float     coordX = coord.Coord.X;
                    float     coordY = coord.Coord.Y + 1.0f;
                    if (geometry.Channels.Count > 1)
                    {
                        FDrChannelFace channelFace  = geometry.Channels[2].Indexs[face.Index];
                        SFloatPoint3   channelPoint = channelFace.Points[n];
                        coordX = channelPoint.X;
                        coordY = channelPoint.Y;
                    }
                    FDrColor color = geometry.ColorList[face.ColorIndex[n]];
                    vertexs.WriteFloat(vertex.Position.X);
                    vertexs.WriteFloat(vertex.Position.Y);
                    vertexs.WriteFloat(vertex.Position.Z);
                    vertexs.WriteFloat(1.0f);
                    vertexs.WriteFloat(coordX);
                    vertexs.WriteFloat(coordY);
                    vertexs.WriteFloat(color.Color.R);
                    vertexs.WriteFloat(color.Color.G);
                    vertexs.WriteFloat(color.Color.B);
                    vertexs.WriteFloat(1.0f);
                    // 输出索引数据
                    faces.WriteInt32(3 * f + n);
                }
            }
            // 创建顶点流
            _vertexBuffer        = new FDxVertexBuffer();
            _vertexBuffer.Device = _device;
            _vertexBuffer.UploadNormal(10, vertexs.Memory, 0, vertexs.Length);
            // 创建索引流
            _faceBuffer        = new FDxFaceBuffer();
            _faceBuffer.Device = _device;
            _faceBuffer.Upload32(faces.Memory, 0, faces.Length);
        }
Ejemplo n.º 4
0
        //============================================================
        public void LoadResource(FDrGeometry geometry)
        {
            // 创建数据
            int         faceCount = geometry.FaceList.Count;
            FByteStream vertexs   = new FByteStream(4 * 10 * 3 * faceCount);
            FByteStream faces     = new FByteStream(3 * faceCount);

            for (int f = 0; f < faceCount; f++)
            {
                FDrFace face = geometry.FaceList[f];
                for (int n = 0; n < 3; n++)
                {
                    // 输出顶点数据
                    FDrVertex vertex = geometry.VertexList[face.VertexIndex[n]];
                    FDrCoord  coord  = geometry.CoordList[face.CoordIndex[n]];
                    FDrNormal normal = geometry.NormalList[face.NormalIndex[n]];
                    vertexs.WriteFloat(vertex.Position.X);
                    vertexs.WriteFloat(vertex.Position.Y);
                    vertexs.WriteFloat(vertex.Position.Z);
                    vertexs.WriteFloat(1.0f);
                    vertexs.WriteFloat(coord.Coord.X);
                    vertexs.WriteFloat(coord.Coord.Y + 1);
                    vertexs.WriteFloat(normal.Direction.X);
                    vertexs.WriteFloat(normal.Direction.Y);
                    vertexs.WriteFloat(normal.Direction.Z);
                    vertexs.WriteFloat(1.0f);
                    // 输出索引数据
                    faces.WriteInt32(3 * f + n);
                }
            }
            // 创建顶点流
            _vertexBuffer        = new FDxVertexBuffer();
            _vertexBuffer.Device = _device;
            _vertexBuffer.UploadNormal(10, vertexs.Memory, 0, vertexs.Length);
            // 创建索引流
            _faceBuffer        = new FDxFaceBuffer();
            _faceBuffer.Device = _device;
            _faceBuffer.Upload32(faces.Memory, 0, faces.Length);
        }
Ejemplo n.º 5
0
        //============================================================
        // <T>压缩字节数据。</T>
        //
        // @return 字节数据
        //============================================================
        public byte[] CompressBytes()
        {
            byte[] data = null;
            // Deflate压缩
            string compressCd = _compressCd;

            switch (compressCd)
            {
            case ERsCompress.Deflate:
                using (FCompressFile file = new FCompressFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompress(_blockSize);
                    }
                    else
                    {
                        data = file.Compress();
                    }
                }
                break;

            case ERsCompress.Lzma:
                using (FLzmaFile file = new FLzmaFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompress(_blockSize);
                    }
                    else
                    {
                        data = file.Compress();
                    }
                }
                break;

            case ERsCompress.LzmaAlchemy:
                using (FLzmaFile file = new FLzmaFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompressNative(_blockSize);
                    }
                    else
                    {
                        data = file.CompressNative();
                    }
                }
                break;
            }
            // 检查大小,如果压缩后更大,则不压缩数据
            if (data.Length > _length)
            {
                data       = ToArray();
                compressCd = ERsCompress.None;
            }
            // 计算效验码
            _vertifyCode = RByte.ComputeHash32(data, 0, data.Length);
            // 写入文件
            byte[] result = null;
            using (FByteStream stream = new FByteStream()) {
                // 写入信息
                stream.WriteUint8((byte)ERsCompress.Parse(compressCd));
                stream.WriteInt32(_length);
                stream.WriteInt32(_vertifyCode);
                stream.WriteInt32(_blockSize);
                // 写入数据
                if ((ERsCompress.None != compressCd) && (_blockSize > 0))
                {
                    stream.WriteBytes(data, 0, data.Length);
                }
                else
                {
                    stream.WriteInt32(1);
                    stream.WriteInt32(data.Length);
                    stream.WriteBytes(data, 0, data.Length);
                }
                result = stream.ToArray();
            }
            return(result);
        }