Ejemplo n.º 1
0
        public List <MATProject> GetProjects(String path, bool orderByRecent = false)
        {
            List <MATProject> projects = new List <MATProject>();

            foreach (var dir in Directory.GetDirectories(path))
            {
                var directoryInfo = new DirectoryInfo(dir);

                var project = new MATProject(Path.GetFileName(dir), new FileInfo(dir));

                projects.Add(project);

                var files = directoryInfo.GetFiles("*.avrs", SearchOption.AllDirectories).OrderBy(f => f.CreationTime);

                foreach (var file in files)
                {
                    if (file == null)
                    {
                        continue;
                    }

                    var thumbs = Directory.GetFiles(file.DirectoryName, "*.jpg", SearchOption.TopDirectoryOnly);

                    Texture2D thumb = new Texture2D(1, 1);

                    if (thumbs.Length > 0)
                    {
                        if (File.Exists(thumbs[0]))
                        {
                            var bytes = File.ReadAllBytes(thumbs[0]);

                            thumb.LoadImage(bytes);

                            thumb.Apply();
                        }
                        else
                        {
                            UnityEngine.Debug.LogWarning("Project is without thumbnail");
                        }
                    }

                    var view = new Avrs(file.FullName, thumb);

                    view.OnProjectChanged = this.ProjectChanged;

                    var tScene = TempScene.Get(file.FullName);

                    project.views.Add(view);
                }
            }

            projects = projects.OrderByDescending(f => f.fileInfo.LastWriteTime).ToList();

            projects[0].isOpenedInUI = true; // First is always open

            return(projects);
        }
Ejemplo n.º 2
0
        private void CustomUpdate()
        {
            if (RuntimeMeshLoader.IsInstanced())
            {
                RuntimeMeshLoader.Instance.saveMesh = ATSettings.saveMesh;

                RuntimeMeshLoader.Instance.Update();

                this.isCalculateNormalAssigned = false;
            }
            else
            {
                this.isCurrentlyImporting = false;

                if (!this.isCalculateNormalAssigned)
                {
                    foreach (var item in GameObject.FindObjectsOfType <VMesh>())
                    {
                        if (item != null)
                        {
                            if (item.GetComponent <RecalculateNormalsComponent>() == null)
                            {
                                var normalCompoenent = item.gameObject.AddComponent <RecalculateNormalsComponent>();

                                if (ATSettings.setNormalToZero)
                                {
                                    normalCompoenent.RecalculateNormals(0);
                                }
                            }
                        }
                    }
                    this.isCalculateNormalAssigned = true;
                }
            }
            if (RuntimeMeshDataOrderedLoader.IsInstanced())
            {
                RuntimeMeshDataOrderedLoader.Instance.Update();
            }
            if (RuntimeTextureLoader.IsInstanced())
            {
                RuntimeTextureLoader.Instance.Update();
            }
            if (RuntimeJSonLoader.IsInstanced())
            {
                RuntimeJSonLoader.Instance.Update();
            }

            if (this.avrsChanged != null)
            {
                if (this.avrsChanged.isOpened)
                {
                    this.avrsChanged.isImporting = true;
                    Import(this.avrsChanged);
                }
                this.avrsChanged = null;
            }
        }
Ejemplo n.º 3
0
        private void PrepareToSync(Avrs project, MScene newScene, MScene oldScene, AvrsDeserializer deserializer)
        {
            this.Repaint();

            if (oldScene == null || project.root.transform.childCount == 0)
            {
                // Instanzia scena
                deserializer.InstantiateScene(project.root.transform,
                                              (GameObject go) =>
                {
                },
                                              (float p) =>
                {
                },
                                              (string e) =>
                {
                    UnityEngine.Debug.Log("error " + e);
                }
                                              );
            }
            else
            {
                // Sync

                //s.mScene.assets.materialData.Clear();
                _tempScene.mScene.assets.textureData.Clear();
                _tempScene.mScene.assets.meshData.Clear();

                SyncScene(project.root, ref newScene, ref deserializer);

                /*foreach (var vScene in viewsInScene)
                 * {
                 *  if (vScene == null)
                 *      continue;
                 *
                 *  var model = deserializer.sceneController.scene.mObjectWrapper.Find(m => m.id == vScene.model.id);
                 *
                 *  if (model != null)
                 *  {
                 *      model = vScene.model;
                 *  }
                 * }
                 *
                 * _tempScene.mScene = deserializer.sceneController.scene;
                 * _tempScene.currentSceneController = deserializer.sceneController;*/
            }
        }
Ejemplo n.º 4
0
        public void Import(Avrs project)
        {
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());

            if (!string.IsNullOrEmpty(project.projectPath))
            {
                this.isCurrentlyImporting = true;
                _tempScene = TempScene.Get(project.projectPath); // Check if scene already exist

                var deserializer = new AvrsDeserializer();
                deserializer.DeserializeFile(project.projectPath,
                                             (MScene scene) =>
                {
                    EditingInstanceController.Instance.AddSceneController(deserializer.sceneController);

                    new BimDataComponent(deserializer.sceneController);


                    if (project.isOpened)
                    {
                        project.root = GameObject.Find(project.name + "_Root");
                    }

                    if (project.root == null)
                    {
                        project.root = new GameObject(project.name + "_Root");
                    }

                    if (_tempScene == null)
                    {
                        PrepareToSync(project, scene, null, deserializer);

                        _tempScene = TempScene.Create(project.projectPath);

                        _tempScene.Initialize(scene, project.projectPath, deserializer.sceneController);
                    }
                    else
                    {
                        PrepareToSync(project, scene, _tempScene.mScene, deserializer);
                    }
                },
                                             (float p) => { },
                                             (string error) => { });
            }
        }
Ejemplo n.º 5
0
 private void ProjectChanged(Avrs avrsChanged)
 {
     this.avrsChanged = avrsChanged;
 }