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;*/ } }
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) => { }); } }
private void Sync(GameObject root, AvrsDeserializer deserializer, List <MAmbiensObject> models) { GameObject gOParent = root; if (root == null) { return; } //Prendo qui la lista di view var currentViewList = this.GetChildrenComponents <VAmbiensObject>(root.transform.GetChildrenUtils().ToList()); //Per ogni modello che viene da revit... for (int i = 0; i < models.Count; i++) { var newModel = models[i]; GameObject go = null; VAmbiensObject currView = null; //...trovo la view corrispondente già instanziata foreach (var instantiatedView in currentViewList) { if (instantiatedView.model.id == newModel.id) { currView = instantiatedView; go = currView.gameObject; } } //Se NON ho trovato currView e quindi non ho trovato la view corrispondente.. if (currView == null) { //... istanzio il gameobject giusto deserializer.sceneController.objectsController.InstantiateViewFromModel(ref newModel, root.transform, (GameObject gO) => { }, (float p) => { }, (string error) => { }); continue; } //Se invece ho trovato il matching tra model da revit e view corrispondente else { //questo non l'ho capito... //currView.model = deserializer.sceneController.objectsController.AddFromExisting(go); // Aggiorno il model della view con quello nuovo //currView.model = newModel; currentViewList.Remove(currView); go.transform.position = newModel.p.V3FromFloatArray(); go.transform.rotation = Quaternion.Euler(newModel.r.V3FromFloatArray()); go.transform.localScale = newModel.s.V3FromFloatArray(); // Refresh Components var bimDatas = go.GetComponents <BimData>(); foreach (var bim in bimDatas) { if (bim == null) { continue; } GameObject.DestroyImmediate(bim); } for (int componentCount = 0; componentCount < newModel.c.Count; componentCount++) { var comp = newModel.c[componentCount]; deserializer.sceneController.componentsController.InstantiateViewFromModel(ref comp, go, null, null, null); } if (currView.model.meshID != -1) { var vMesh = go.GetComponent <VMesh>(); if (vMesh != null && vMesh.model != null) { var newMesh = deserializer.sceneController.scene.assets.meshData.Find(m => m.uniqueMeshID == vMesh.model.uniqueMeshID); if (newMesh != null && !string.IsNullOrEmpty(newMesh.url)) { vMesh.model.url = newMesh.url; if (vMesh.model.url.StartsWith(CScene.tilde)) { vMesh.model.localUrl = vMesh.model.url.Replace(CScene.tilde, deserializer.sceneController.ProjectPath); } if (newMesh.hashChecker != vMesh.model.hashChecker) { //Debug.Log("updating mesh " + newModel.name + " " + vMesh.model.hashChecker + " " + newMesh.hashChecker); vMesh.GetGraphics((MeshFilter f) => { if (f != null) { var meshCollider = vMesh.GetComponent <MeshCollider>(); if (meshCollider != null) { meshCollider.sharedMesh = f.sharedMesh; } } }, (float p) => { }, (string error) => { }); } // Aggiorno il model di vmesh con il nuovo model meshdata vMesh.model = newMesh; } } } } if (newModel.childs.Count > 0) { this.Sync(go, deserializer, newModel.childs); } } //DOPO IL CICLO, se restano dei GO nella lista, vanno cancellati while (currentViewList.Count > 0) { var item = currentViewList[0]; currentViewList.Remove(item); GameObject.DestroyImmediate(item.gameObject); } }
private void SyncScene(GameObject root, ref MScene newSceneModel, ref AvrsDeserializer deserializer) { Sync(root, deserializer, newSceneModel.mObjectWrapper); }