Ejemplo n.º 1
0
 public void SetCallback(OnProgressHandler onProgress, OnErrorHandler onError, OnSuccHandler onSucc, OnURLRedirectHandler onRedirect)
 {
     m_onProgressHandler = onProgress;
     m_onErrorHandler    = onError;
     m_onSuccHandler     = onSucc;
     m_onRedirectHandler = onRedirect;
 }
Ejemplo n.º 2
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            double plannedSpeed = Math.Round(realTimeLength * 1.0 / totalLength, 2);

            long downloadSpeed = realTimeLength - lastlLength;

            lastlLength = realTimeLength;

            timeCost++;

            OnProgressHandler?.Invoke(fileName, timeCost, plannedSpeed, downloadSpeed);
        }
Ejemplo n.º 3
0
        private static byte[] GetVoxFromVoxelData(VoxelData data, OnProgressHandler onProgress)
        {
            if (!data)
            {
                return(null);
            }
            List <byte> voxByte = new List <byte>();

            byte[] mainChrunk = WriteMain(data, onProgress);
            voxByte.AddRange(Encoding.Default.GetBytes("VOX "));
            voxByte.AddRange(GetBytes(data.Version));
            voxByte.AddRange(Encoding.Default.GetBytes("MAIN"));
            voxByte.AddRange(GetBytes(0));
            voxByte.AddRange(GetBytes(mainChrunk.Length));
            voxByte.AddRange(mainChrunk);
            return(voxByte.ToArray());
        }
Ejemplo n.º 4
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            double plannedSpeed = Math.Round(realTimeLength * 1.0 / totalLength, 2);

            if (plannedSpeed == double.NaN)
            {
                //Stop();
                return;
            }

            long downloadSpeed = realTimeLength - lastlLength;

            lastlLength = realTimeLength;

            timeCost++;

            OnProgressHandler?.Invoke(timeCost, plannedSpeed, downloadSpeed);
        }
Ejemplo n.º 5
0
    public bool DownLoadFile(string url, string saveFile, OnProgressHandler onProgress, OnErrorHandler onError, OnSuccHandler onSucc, OnURLRedirectHandler onRedirect)
    {
        bool hasTask = m_httpWorker != null;

        m_downLoadContent = null;

        m_onProgressHandler = onProgress;
        m_onErrorHandler    = onError;
        m_onSuccHandler     = onSucc;
        m_onRedirectHandler = onRedirect;

        m_fileName   = saveFile;
        m_httpWorker = new HttpClientHelper(saveFile, url, ++m_workerSerNum);
        m_loopCheckHelper.SetActive(true);

        m_httpWorker.SetCallback(new OnProgressHandler(this.OnProgress), new OnErrorHandler(this.OnError), new OnSuccHandler(this.OnSucc),
                                 new OnURLRedirectHandler(this.OnReidrect));
        m_httpWorker.Start();

        return(hasTask);
    }
Ejemplo n.º 6
0
        private static byte[] WriteMain(VoxelData data, OnProgressHandler onProgress)
        {
            const float STEP_COUNT = 5f;

            List <byte> bytes = new List <byte>();

            if (data.Voxels.Count > 1)
            {
                // PACK
                //bytes.AddRange(WritePack(data));
            }

            for (int i = 0; i < data.Voxels.Count; i++)
            {
                if (onProgress != null)
                {
                    onProgress.Invoke((i + 1) / STEP_COUNT / data.Voxels.Count);
                }

                // SIZE
                bytes.AddRange(WriteSize(data.Voxels[i]));
                // XYZI
                bytes.AddRange(WriteVoxels(data.Voxels[i]));
            }

            // RGBA
            if (onProgress != null)
            {
                onProgress.Invoke((2 / STEP_COUNT));
            }

            bytes.AddRange(WritePalette(data.Palette));


            // TGS
            var tgsList = new SortedList <int, byte[]>();

            if (onProgress != null)
            {
                onProgress.Invoke(3 / STEP_COUNT);
            }

            // nTRN
            foreach (var t in data.Transforms)
            {
                tgsList.Add(t.Key, WriteTransform(t.Key, t.Value));
            }

            // nGRP
            foreach (var g in data.Groups)
            {
                tgsList.Add(g.Key, WriteGroup(g.Key, g.Value));
            }

            // nSHP
            foreach (var s in data.Shapes)
            {
                tgsList.Add(s.Key, WriteShape(s.Key, s.Value));
            }

            for (int i = 0; i < tgsList.Keys.Count; i++)
            {
                bytes.AddRange(tgsList[tgsList.Keys[i]]);
            }

            if (onProgress != null)
            {
                onProgress.Invoke(4 / STEP_COUNT);
            }
            // MATL
            for (int i = 0; i < data.Materials.Count; i++)
            {
                bytes.AddRange(WriteMaterial(data.Materials[i]));
            }

            if (onProgress != null)
            {
                onProgress.Invoke(5 / STEP_COUNT);
            }
            // RIGG
            foreach (var r in data.Rigs)
            {
                bytes.AddRange(WriteRig(r.Key, r.Value));
            }

            return(bytes.ToArray());
        }
Ejemplo n.º 7
0
        private static VoxelData GetVoxelDataFromVox(byte[] voxBytes, OnProgressHandler onProgress)
        {
            VoxelData data = new VoxelData();

            if (!CheckID(voxBytes, "VOX "))
            {
                Debug.LogError("Error with Magic Number. The file is not a vox file.");
                return(null);
            }

            using (MemoryStream ms = new MemoryStream(voxBytes)) {
                using (BinaryReader br = new BinaryReader(ms)) {
                    // VOX_
                    br.ReadInt32();

                    // VERSION
                    data.Version = System.BitConverter.ToInt32(br.ReadBytes(4), 0);

                    // MAIN
                    byte[] chunkId          = br.ReadBytes(4);
                    int    mainChunkSize    = br.ReadInt32();
                    int    mainChildrenSize = br.ReadInt32();
                    br.ReadBytes(mainChunkSize);
                    if (!CheckID(chunkId, "MAIN"))
                    {
                        Debug.LogError("Error with Main Chunk ID");
                        return(null);
                    }

                    // Containt
                    int     readSize = 0;
                    Vector3 tempSize = new Vector3();

                    while (readSize < mainChildrenSize)
                    {
                        string id = GetID(br.ReadBytes(4));
                        readSize += 4;

                        switch (id)
                        {
                        case "PACK":
                            readSize += ReadPackChunk(br);
                            break;

                        case "SIZE":
                            readSize += ReadSizeChunk(br, out tempSize);
                            break;

                        case "XYZI":
                            int[,,] tempVoxels = new int[(int)tempSize.x, (int)tempSize.y, (int)tempSize.z];
                            readSize          += ReadVoxelChunk(br, ref tempVoxels);
                            data.Voxels.Add(tempVoxels);
                            break;

                        case "RGBA":
                            readSize += ReadPalattee(br, ref data.Palette);
                            break;

                        case "nTRN":
                            readSize += ReadTransform(br, ref data);
                            break;

                        case "nGRP":
                            readSize += ReadGroup(br, ref data);
                            break;

                        case "nSHP":
                            readSize += ReadShape(br, ref data);
                            break;

                        case "MATL":
                            readSize += ReadMaterial(br, ref data);
                            break;

                        case "RIGG":
                            readSize += ReadRig(br, ref data, 0);
                            break;

                        case "_RIG":
                            readSize += ReadRig(br, ref data, VoxelData.RigData.CURRENT_VERSION);
                            break;

                        default:
                            int chunkSize    = br.ReadInt32();
                            int childrenSize = br.ReadInt32();
                            br.ReadBytes(chunkSize + childrenSize);
                            readSize += chunkSize + childrenSize + 4 + 4;
                            break;
                        }
                    }

                    if (onProgress != null)
                    {
                        onProgress.Invoke((float)readSize / mainChildrenSize);
                    }

                    // Add Default Node if No Node
                    if (data.Transforms.Count == 0)
                    {
                        data.ResetToDefaultNode();
                    }
                }
            }
            return(data);
        }
Ejemplo n.º 8
0
 public static byte[] GetVoxelByte(VoxelData data, bool isVox, OnProgressHandler onProgress = null)
 {
     return(isVox ? GetVoxFromVoxelData(data, onProgress) : GetQbFromVoxelData(data));
 }
Ejemplo n.º 9
0
 public static VoxelData GetVoxelData(byte[] voxelBytes, bool isVox, OnProgressHandler onProgress = null)
 {
     return(isVox ? GetVoxelDataFromVox(voxelBytes, onProgress) : GetVoxelDataFromQb(voxelBytes));
 }
Ejemplo n.º 10
0
 public OnProgressHandlerListener(OnProgressHandler handler)
 {
     _handler = handler;
 }