private void upload_stage_1() { Mantis_Mesh child = Mantis_Meshes[tag_when_update]; int triangle_number = child.mesh.triangles.Length; Vector3[] vertices = child.mesh.vertices; // in data is large than origin data int[] triangles = new int[triangle_number * 2]; // we need normal data to protect normal boundary Vector3[] normals = child.mesh.normals; // we need color data to protect color boundary Color[] colors = child.mesh.colors; // we need uv data to protect uv boundary Vector2[] uvs = child.mesh.uv; int counter = 0; for (int i = 0; i < child.mesh.subMeshCount; i++) { int[] sub_triangles = child.mesh.GetTriangles(i); triangles[counter] = sub_triangles.Length; counter++; Array.Copy(sub_triangles, 0, triangles, counter, sub_triangles.Length); counter += sub_triangles.Length; } // upload data upload_data(vertices, vertices.Length, triangles, counter, normals, normals.Length, colors, colors.Length, uvs, uvs.Length); state = 102; }
private void download_stage_2() { Mantis_Mesh child = Mantis_Meshes[tag_when_update]; // get triangle list by quality value if (child.uuid != null) { get_triangle_list(child.uuid, quality, child.out_triangles, ref child.out_count); state = 3; } else { www_result = "You need to upload your mesh."; end_update(); } }
private void upload_stage_2() { if (www.isDone) { #if UNITY_2017_1_OR_NEWER if (www.isNetworkError || www.isHttpError) { #else if (www.isError) { #endif www_result = "Error with network: " + www.error; end_update(); } else { string ret = www.downloadHandler.text; if (ret[0] == '[' && ret[ret.Length - 2] == ']') { ret = ret.Substring(1, ret.Length - 3); Mantis_Mesh child = Mantis_Meshes[tag_when_update]; child.uuid = ret; // save uuid to file string filename = "mantis_uuid_" + child.mesh.GetInstanceID().ToString(); System.IO.File.WriteAllText(filename, child.uuid); tag_when_update++; if (tag_when_update < Mantis_Meshes.Length) { // loop to stage 1 state = 101; } else { // finish www_result = "Upload success."; end_update(); } } else { www_result = www.downloadHandler.text; end_update(); } } } }
private void upload_stage_2() { if (www.isDone) { if (!String.IsNullOrEmpty(www.error)) { www_result = "Error with network: " + www.error; end_update(); } else { string ret = www.text; if (ret[0] == '[' && ret[ret.Length - 2] == ']') { ret = ret.Substring(1, ret.Length - 3); Mantis_Mesh child = Mantis_Meshes[tag_when_update]; child.uuid = ret; // save uuid to file string filename = "mantis_uuid_" + child.mesh.GetInstanceID().ToString(); System.IO.File.WriteAllText(filename, child.uuid); tag_when_update++; if (tag_when_update < Mantis_Meshes.Length) { // loop to stage 1 state = 101; } else { // finish www_result = "Upload success."; end_update(); } } else { www_result = www.text; end_update(); } } } }
private void get_all_meshes() { Component[] allFilters = (Component[])((Component)target).gameObject.GetComponentsInChildren(typeof(MeshFilter)); Component[] allRenderers = (Component[])((Component)target).gameObject.GetComponentsInChildren(typeof(SkinnedMeshRenderer)); int mesh_count = allFilters.Length + allRenderers.Length; if (mesh_count > 0) { Mantis_Meshes = new Mantis_Mesh[mesh_count]; int counter = 0; foreach (Component child in allFilters) { Mantis_Meshes[counter] = new Mantis_Mesh(); Mantis_Meshes[counter].mesh = ((MeshFilter)child).sharedMesh; counter++; } foreach (Component child in allRenderers) { Mantis_Meshes[counter] = new Mantis_Mesh(); Mantis_Meshes[counter].mesh = ((SkinnedMeshRenderer)child).sharedMesh; counter++; } } }
private void download_stage_3() { if (www.isDone) { #if UNITY_2017_1_OR_NEWER if (www.isNetworkError || www.isHttpError) { #else if (www.isError) { #endif www_result = "Error with network: " + www.error; end_update(); } else { string ret = www.downloadHandler.text; if (ret[0] == '[' && ret[ret.Length - 2] == ']') { ret = ret.Substring(1, ret.Length - 3); string[] triangle_array = ret.Split(new char[] { ' ' }); Mantis_Mesh child = Mantis_Meshes[tag_when_update]; for (int i = 0; i < triangle_array.Length; i++) { child.out_triangles[i] = int.Parse(triangle_array[i]); } child.out_count = triangle_array.Length; if (child.out_count > 0) { int counter = 0; int mat = 0; while (counter < child.out_count) { int len = child.out_triangles[counter]; counter++; if (len > 0) { int[] new_triangles = new int[len]; Array.Copy(child.out_triangles, counter, new_triangles, 0, len); child.mesh.SetTriangles(new_triangles, mat); counter += len; } else { child.mesh.SetTriangles((int[])null, mat); } mat++; } face_number += child.mesh.triangles.Length / 3; // refresh normals and bounds child.mesh.RecalculateNormals(); child.mesh.RecalculateBounds(); EditorUtility.SetDirty(target); } tag_when_update++; if (tag_when_update < Mantis_Meshes.Length) { // loop to stage 2 state = 2; } else { // finish save_quality = quality; end_update(); } } else { www_result = www.downloadHandler.text; end_update(); } } } }