protected void requestMesh2(object sender, IRequestInterface args) // Only works with the v2 server using the v1 API // Meshes are safe because they will be called only once { MeshRequest2 reqObj = args as MeshRequest2; HashSet <int> collectIds = new HashSet <int> (); foreach (Eppy.Tuple <int, int, GameObject, JSONNode> item in reqObj.fragments) { collectIds.Add(item.Item1); } if (collectIds.Count == 1) { collectIds.Add(-1); } string fragIds = string.Join(",", collectIds); reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/mesh/" + reqObj.dbId + "/" + fragIds); //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ()); _mgr.Register(reqObj); }
public override GameObject BuildScene(string name, bool saveToDisk = false) { try { foreach (Eppy.Tuple <int, OpenCTM.Mesh> openctm in _openctm) { OpenCTM.Mesh ctmMesh = openctm.Item2; if (ctmMesh == null || ctmMesh.getVertexCount() == 0 || ctmMesh.getTriangleCount() == 0) { state = SceneLoadingStatus.eCancelled; return(gameObject); } Eppy.Tuple <int, int, GameObject, JSONNode> item = fragments.Single(x => x.Item1 == openctm.Item1); GameObject meshObject = item.Item3; Mesh mesh = new Mesh(); Vector3 [] vertices = MeshRequest2.getAsVector3(ctmMesh.vertices); mesh.vertices = vertices; mesh.triangles = ctmMesh.indices; if (ctmMesh.hasNormals()) { mesh.normals = MeshRequest2.getAsVector3(ctmMesh.normals); } for (int i = 0; i < ctmMesh.getUVCount(); i++) { mesh.SetUVs(i, MeshRequest2.getAsVector2List(ctmMesh.texcoordinates [i].values)); } mesh.RecalculateNormals(); mesh.RecalculateBounds(); MeshFilter filter = meshObject.AddComponent <MeshFilter> (); filter.sharedMesh = mesh; MeshRenderer renderer = meshObject.AddComponent <MeshRenderer> (); renderer.sharedMaterial = ForgeLoaderEngine.GetDefaultMaterial(); if (createCollider) { MeshCollider collider = meshObject.AddComponent <MeshCollider> (); collider.sharedMesh = mesh; } #if UNITY_EDITOR if (saveToDisk) { AssetDatabase.CreateAsset(mesh, ForgeConstants._resourcesPath + this.loader.PROJECTID + "/" + GetName(item.Item1) + ".asset"); //AssetDatabase.SaveAssets () ; //AssetDatabase.Refresh () ; //mesh =AssetDatabase.LoadAssetAtPath<Mesh> (ForgeConstants._resourcesPath + this.loader.PROJECTID + "/" + name + ".asset") ; } #endif // Add our material to the queue loader.GetMgr()._materials.Add(item.Item2); //if ( loader.GetMgr ()._materials.Add (item.Item2) ) { // MaterialRequest req = new MaterialRequest (loader, null, bearer, item.Item2, item.Item4); // req.gameObject = meshObject; // if ( fireRequestCallback != null ) // fireRequestCallback (this, req); //} } base.BuildScene(name, saveToDisk); state = SceneLoadingStatus.eWaitingMaterial; } catch (Exception ex) { Debug.Log(ForgeLoader.GetCurrentMethod() + " " + ex.Message); state = SceneLoadingStatus.eError; } return(gameObject); }