Exemplo n.º 1
0
        //slow
        private async System.Threading.Tasks.Task <MutiFilesImportOption> PreImport(string[] fileNames, string absSavePath)
        {
            MutiFilesImportOption mutiFilesImportOption = new MutiFilesImportOption();

            for (int i = 0; i < fileNames.Length; i++)
            {
                CGfxFileImportOption fileImportOption = await PreImport(fileNames[i], absSavePath);

                if (fileImportOption != null)
                {
                    mutiFilesImportOption.FileImportOptions.Add(fileImportOption);
                }
            }
            return(mutiFilesImportOption);
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task ImportMutiFiles(string[] fileNames, string absSavePath, MutiFilesImportOption mutiFilesImportOption)
        {
            var   per            = 1.0f / fileNames.Length;
            float currentPercent = 0;

            OnAssetImportMessageDumping?.Invoke(this, "", "", AssetImportMessageType.AMT_Import, 0, "ImportStart", 0);
            for (int i = 0; i < fileNames.Length; ++i)
            {
                if (IsCancle)
                {
                    return;
                }
                var fileName = fileNames[i];
                OnAssetImportMessageDumping?.Invoke(this, "", "", AssetImportMessageType.AMT_Import, 0, "ImportStart: " + fileName, currentPercent);
                CGfxFileImportOption fileImportOption = new CGfxFileImportOption();
                var fBXImporter = new FBX.CGfxFBXImporter();
                var result      = await fBXImporter.PreImport(fileName, fileImportOption);

                if (result)
                {
                    mFileImportOptions.Add(fileName, fileImportOption);
                    fileImportOption.BuildOptionsDictionary();
                    mFBXImporters.Add(fileName, fBXImporter);
                    fileImportOption.InitializeSavePath(absSavePath);

                    fileImportOption.ImportMesh       = mutiFilesImportOption.ImportMesh;
                    fileImportOption.ImportAnimation  = mutiFilesImportOption.ImportAnimation;
                    fileImportOption.ConvertSceneUnit = mutiFilesImportOption.ConvertSceneUnit;
                    fileImportOption.Scale            = mutiFilesImportOption.Scale;

                    var assetFile = new CGfxAsset_File();
                    assetFile.FileOption = mFileImportOptions[fileName];
                    using (var it = assetFile.FileOption.ObjectOptions.GetEnumerator())
                    {
                        while (it.MoveNext())
                        {
                            if (IsCancle)
                            {
                                return;
                            }
                            var hash        = it.Current.Key;
                            var assetOption = it.Current.Value;
                            if (!assetOption.IsImport)
                            {
                                continue;
                            }
                            if (assetOption.AssetType == ImportAssetType.IAT_Mesh)
                            {
                                var meshOP = assetOption as CGfxMeshImportOption;
                                meshOP.Skeleton = mutiFilesImportOption.Skeleton;
                            }
                            if (assetOption.AssetType == ImportAssetType.IAT_Animation)
                            {
                                var animOP = assetOption as CGfxAnimationImportOption;
                                animOP.Skeleton = mutiFilesImportOption.Skeleton;
                            }
                            var creater = CGfxAssetCreater.CreateAssetCreater(assetOption);
                            creater.OnCreaterAssetImportMessageDumping += MutiFiles_OnCreaterAssetImportMessageDumping;
                            if (!creater.CheckIfNeedImport())
                            {
                                creater.OnCreaterAssetImportMessageDumping -= MutiFiles_OnCreaterAssetImportMessageDumping;
                                continue;
                            }
                            assetFile.AddCreaters(hash, creater);
                        }
                    }
                    await mFBXImporters[fileName].Import(assetFile);
                    await assetFile.SaveAsset();

                    currentPercent += per;
                    OnAssetImportMessageDumping?.Invoke(this, "", "", AssetImportMessageType.AMT_Import, 0, "ImportDone: " + fileName, currentPercent);
                    OnAssetImportMessageDumping?.Invoke(this, "", "", AssetImportMessageType.AMT_Save, 0, "ImportDone: " + fileName, 0.0f);
                }
            }
            //await CEngine.Instance.EventPoster.AwaitMTS_Foreach(fileNames.Length,async (idx, smp) =>
            //{
            //    var fileName = fileNames[idx];
            //    OnAssetImportMessageDumping?.Invoke(this, "", "", AssetImportMessageType.AMT_Import, "ImportStart: " + fileName, currentPercent);
            //    CGfxFileImportOption fileImportOption = new CGfxFileImportOption();
            //    var fBXImporter = new FBX.CGfxFBXImporter();
            //    var result = await fBXImporter.PreImport(fileName, fileImportOption);
            //    if (result)
            //    {
            //        mFileImportOptions.Add(fileName, fileImportOption);
            //        fileImportOption.BuildOptionsDictionary();
            //        mFBXImporters.Add(fileName, fBXImporter);
            //        fileImportOption.InitializeSavePath(absSavePath);

            //        fileImportOption.ImportMesh = mutiFilesImportOption.ImportMesh;
            //        fileImportOption.ImportAnimation = mutiFilesImportOption.ImportAnimation;
            //        fileImportOption.ConvertSceneUnit = mutiFilesImportOption.ConvertSceneUnit;
            //        fileImportOption.Scale = mutiFilesImportOption.Scale;

            //        var assetFile = new CGfxAsset_File();
            //        assetFile.FileOption = mFileImportOptions[fileName];
            //        using (var it = assetFile.FileOption.ObjectOptions.GetEnumerator())
            //        {
            //            while (it.MoveNext())
            //            {
            //                var hash = it.Current.Key;
            //                var assetOption = it.Current.Value;
            //                if (!assetOption.IsImport)
            //                    continue;
            //                var creater = CGfxAssetCreater.CreateAssetCreater(assetOption);
            //                assetFile.AddCreaters(hash, creater);
            //            }
            //        }
            //        await mFBXImporters[fileName].Import(assetFile);
            //        await assetFile.SaveAsset();
            //        currentPercent += per;
            //        OnAssetImportMessageDumping?.Invoke(this, "", "", AssetImportMessageType.AMT_Import, "ImportDone: " + fileName, currentPercent);
            //    }
            //});
        }