示例#1
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            using (var session = LicenseConfig.Create())
            {
                if (session.IsValid == false)
                {
                    LicenseConfig.ShowDialog(session, this);
                    return;
                }

                using (new ProgressHelper(this, @"Convert Svf Model To glTF/glb ..."))
                {
                    try
                    {
                        var sw = Stopwatch.StartNew();

                        var svfFilePath  = txtInputFilePath.Text;
                        var gltfFilePath = txtOutputFilePath.Text;

                        var options = new GltfOption
                        {
                            AllowDracoMeshCompression = true,
                            AllowNodeExtraData        = true,
                            AllowTextureTransform     = false,
                            GenerateHtml = true
                        };

                        //是否需要做抽壳处理
                        var allowExtractShell = cbExtractShell.Checked;

                        ConvertSvfToGltf(svfFilePath, gltfFilePath, allowExtractShell, options, CancellationToken.None);

                        ProgressHelper.Close();
                        var message = $@"Convert Model Success! (duration: {sw.Elapsed})";
                        MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        ProgressHelper.Close();
                        MessageBox.Show(this, ex.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
示例#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);
            }
        }