-
Notifications
You must be signed in to change notification settings - Fork 1
Dev Unity
Valentin Noves edited this page Jul 25, 2020
·
3 revisions
Create object
Create a new object on the scene and rename it to "MeshImport"
Add a Mesh Filter
Add mesh filter to the "MeshImport"object
Add a Mesh Renderer
Add mesh Renderer to the "MeshImport"object
Add a Custom Script
Add a custom script and rename it to "MeshImporter"
This is the script that will import/export things from/to to Firebase
[RequireComponent(typeof(MeshFilter))]
public class MeshImporter : MonoBehaviour
{
public static FirebaseFirestore DB;
UnityEngine.Mesh mesh;
Vector3[] vertices;
int[] triangles;
private Rootobject importModel;
Vector3 getPos;
GameObject Main;
List<Vector3> postionElements = new List<Vector3>();
// Start is called before the first frame update
void Start()
{
//Connect to Firebase
DB = FirebaseFirestore.GetInstance(FirebaseApp.DefaultInstance);
FBModelImport();
}
public async void FBModelImport()
{
Rootobject result = new Rootobject();
try
{
DocumentReference docRef = DB.Collection("models").Document("Walls");
var listener = docRef.Listen(snapshot =>
{
if (snapshot.Exists)
{
var st = Newtonsoft.Json.JsonConvert.SerializeObject(snapshot.ToDictionary());
importModel = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(st);
//If the element already exists remove it
var gameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
foreach(GameObject go in gameObjects)
{
if(go.name == importModel._object.name)
{
Destroy(go);
}
}
CreateMaterials.create(importModel.materials);
//Create main Game object
GameObject MainObj = new GameObject(importModel._object.name);
//Create geometries
List<GameObject> createdGeom = Geometries.create(importModel.geometries);
//Create Childrens and assign them to Main Object
ObjChildrens.create(importModel._object.children, MainObj, createdGeom);
Main = MainObj;
postionElements = Utils.currentposition(MainObj);
}
});
}
catch
{
}
}A BIMSOCKet team Original Production