Пример #1
0
 public void UpdateOrAdd(ImportTaskData d)
 {
     if (assetProcessedWithTasks == null)
     {
         assetProcessedWithTasks = new List <ImportTaskData>();
     }
     for (int i = 0; i < assetProcessedWithTasks.Count; ++i)
     {
         if (assetProcessedWithTasks[i].importDefinitionGUID == d.importDefinitionGUID &&
             assetProcessedWithTasks[i].taskName == d.taskName)
         {
             ImportTaskData p = assetProcessedWithTasks[i];
             p.version = d.version;
             assetProcessedWithTasks[i] = p;
             return;
         }
     }
     assetProcessedWithTasks.Add(d);
 }
Пример #2
0
 public void Import(string fileName, Transform root, bool synchronous = false)
 {
     blocking = synchronous;
     if (synchronous)
     {
         Assimp.AssimpContext ctx = new Assimp.AssimpContext();
         var aScene = ctx.ImportFile(fileName,
                                     Assimp.PostProcessSteps.Triangulate |
                                     Assimp.PostProcessSteps.GenerateNormals |
                                     Assimp.PostProcessSteps.GenerateUVCoords);
         CreateUnityDataFromAssimp(fileName, aScene, root).MoveNext();
         Clear();
         progress = 1.0f;
     }
     else
     {
         unityDataInCoroutineCreated = false;
         ImportTaskData d = new ImportTaskData();
         d.fileName = fileName;
         d.root     = root;
         taskData.Add(d);
     }
 }
Пример #3
0
 public void UpdateProcessing(ImportTaskData d)
 {
     m_ImporterPostprocessorData.UpdateOrAdd(d);
 }
Пример #4
0
        void Update()
        {
            switch (importerState)
            {
            case ImporterState.Ready:
                if (taskData.Count > 0)
                {
                    // Assimp loading
                    ImportTaskData d = taskData[0];
                    currentTask   = Task.Run(async() => await ImportAssimpFile(d.fileName));
                    importerState = ImporterState.Initialized;
                    progress      = 0f;
                }
                break;

            case ImporterState.Initialized:
                if (currentTask.IsCompleted)
                {
                    // Convert assimp structures into unity
                    if (!currentTask.IsFaulted)
                    {
                        var scene = currentTask.Result;
                        if (scene == null)
                        {
                            importerState = ImporterState.Error;
                            break;
                        }
                        ImportTaskData d = taskData[0];
                        StartCoroutine(CreateUnityDataFromAssimp(d.fileName, scene, d.root.transform));
                        importerState = ImporterState.Processing;
                        progress      = 0.5f;
                    }
                    else
                    {
                        importerState = ImporterState.Error;
                    }
                }
                break;

            case ImporterState.Error:
            {
                var tdata = taskData[0];
                taskData.RemoveAt(0);
                currentTask = null;
                Clear();
                importerState = ImporterState.Ready;
                ImportTaskEventArgs args = new ImportTaskEventArgs(null, tdata.fileName, true);
                progress = 1f;
                importEventTask.Invoke(this, args);
            }
            break;

            case ImporterState.Processing:
                if (unityDataInCoroutineCreated)
                {
                    // task done
                    var tdata = taskData[0];
                    taskData.RemoveAt(0);
                    currentTask = null;
                    unityDataInCoroutineCreated = false;
                    Clear();
                    importerState = ImporterState.Ready;

                    Transform           root = tdata.root.transform.GetChild(tdata.root.transform.childCount - 1);
                    ImportTaskEventArgs args = new ImportTaskEventArgs(root, tdata.fileName, false);
                    progress = 1f;
                    importEventTask.Invoke(this, args);
                }
                break;
            }
        }