Exemplo n.º 1
0
        private void Extract(string inputFilePath, string outputFolderPath, CancellationToken token)
        {
            using (var fc = new FileCleaner())
            {
                var idsFilePath = Path.GetTempFileName();
                fc.AddFile(idsFilePath);

                if (token.IsCancellationRequested)
                {
                    return;
                }
                if (ExtractShell(_ExtractShellCLI, inputFilePath, idsFilePath, token))
                {
                    //如果抽壳成功,则从原始模型中把外壳提取出来另存
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    using (var doc = SvfDocument.LoadFrom(inputFilePath))
                    {
                        if (token.IsCancellationRequested)
                        {
                            return;
                        }
                        doc.Extract(idsFilePath, outputFolderPath, token);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ConvertSvfToGltf(string svfFilePath, string gltfFilePath, bool allowExtractShell, GltfOption options, CancellationToken token)
        {
            using (var fc = new FileCleaner())
            {
                #region 抽取外壳

                if (allowExtractShell)
                {
                    var idsFilePath = Path.GetTempFileName();
                    fc.AddFile(idsFilePath);

                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    if (ExtractShell(_ExtractShellCLI, svfFilePath, idsFilePath, token))
                    {
                        //如果抽壳成功,则从原始模型中把外壳提取出来

                        var tempFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                        FileSystemUtility.CreateDirectory(tempFolder);
                        fc.AddFolder(tempFolder);

                        if (token.IsCancellationRequested)
                        {
                            return;
                        }
                        using (var doc = SvfDocument.LoadFrom(svfFilePath))
                        {
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            if (doc.Extract(idsFilePath, tempFolder, token))
                            {
                                svfFilePath = tempFolder;   //将 Svf -> glTF 的输入源替换成已经抽壳的模型
                            }
                        }
                    }
                }

                #endregion

                if (token.IsCancellationRequested)
                {
                    return;
                }
                GltfExtension.ConvertToGltf(svfFilePath, gltfFilePath, options, token);
            }
        }