Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Polygon reduction script

Discussion in 'Assets and Asset Store' started by meshonline, Jul 27, 2014.

  1. meshonline

    meshonline

    Joined:
    Feb 7, 2014
    Posts:
    121
    Hi,

    I want to share the polygon reduction script, you may use this script to simplify your mesh from within Unity's editor, it supports both Unity Pro and Unity Free.

    Simply save the code as 'MantisLODEditorOnline.cs' and place it in the 'Editor' subdirectory, enjoy it.

    Need a guide? You may read the guide from http://www.mesh-online.net/guide.html.

    Code (CSharp):
    1. /*--------------------------------------------------------
    2.   MantisLODEditorOnline.cs
    3.  
    4.   Created by MINGFEN WANG on 13-12-26.
    5.   Copyright (c) 2013 MINGFEN WANG. All rights reserved.
    6.   http://www.mesh-online.net/
    7. --------------------------------------------------------*/
    8. using UnityEngine;
    9. using UnityEditor;
    10. using System;
    11. using System.Collections;
    12. using System.Runtime.InteropServices;
    13. using System.Text;
    14.  
    15. namespace MantisLODEditorOnline {
    16.     class Mantis_Mesh {
    17.         public Mesh mesh;
    18.         public string uuid;
    19.         public int[][] origin_triangles;
    20.         public int[] out_triangles;
    21.         public int out_count;
    22.         public Mantis_Mesh() {
    23.             uuid = null;
    24.             out_count = 0;
    25.         }
    26.     }
    27.  
    28.     [CustomEditor(typeof(GameObject))]
    29.     class MantisLODEditorOnline: Editor {
    30.         private int origin_face_number = 0;
    31.         private int face_number = 0;
    32.         private float quality = 100.0f;
    33.         private float save_quality = 100.0f;
    34.         private bool protect_boundary = true;
    35.         private bool save_protect_boundary = true;
    36.         private Mantis_Mesh[] Mantis_Meshes = null;
    37.         private bool show_title = true;
    38.         private bool show_help = true;
    39.         private bool save_show_help = true;
    40.         private string www_result = null;
    41.         private int state = 0;
    42.         private int tag_when_update = 0;
    43.         private float start_time = 0.0f;
    44.         private WWW www = null;
    45.         private static string server_name = "www.mesh-online.net";
    46.  
    47.         public override void OnInspectorGUI() {
    48.             if(target) {
    49.                 if(Mantis_Meshes != null) {
    50.                     show_title = EditorGUILayout.Foldout(show_title, "Mantis LOD Editor - Online Version");
    51.                     if(show_title) {
    52.                         // A decent style.  Light grey text inside a border.
    53.                         GUIStyle helpStyle = new GUIStyle(GUI.skin.box);
    54.                         helpStyle.wordWrap = true;
    55.                         helpStyle.alignment = TextAnchor.UpperLeft;
    56.                         show_help = EditorGUILayout.Foldout(show_help, show_help?"Hide Help":"Show Help");
    57.                         GUI.enabled = (state == 0);
    58.                         if(GUILayout.Button("Upload Mesh Data", GUILayout.ExpandWidth(true), GUILayout.ExpandWidth(true))) {
    59.                             // when idle
    60.                             if (state == 0) {
    61.                                 // reset quality
    62.                                 quality = 100.0f;
    63.                                 start_update(101);
    64.                             }
    65.                         }
    66.                         GUI.enabled = true;
    67.                         if(show_help) {
    68.                             GUILayout.Label(
    69.                                 "When Clicked, necessory mesh data will be uploaded to server, the server will cache your data for 24 hours, so you need not upload your data frequently. But if you have restarted Unity, your data might mismatch the cache on the server side, if this happens, you have to upload your data again."
    70.                                 , helpStyle
    71.                                 , GUILayout.ExpandWidth(true));
    72.                         }
    73.                         GUI.enabled = (state == 0);
    74.                         // save current mesh as a lod version of asset
    75.                         if(GUILayout.Button("Save Current Mesh", GUILayout.ExpandWidth(true), GUILayout.ExpandWidth(true))) {
    76.                             foreach (Mantis_Mesh child in Mantis_Meshes) {
    77.                                 // clone the mesh
    78.                                 Mesh new_mesh = (Mesh)Instantiate(child.mesh);
    79.                                 // remove unused vertices
    80.                                 shrink_mesh(new_mesh);
    81.                                 string filePath = EditorUtility.SaveFilePanelInProject (
    82.                                     "Save Current Mesh",
    83.                                     new_mesh.name + "_Quality_" + quality.ToString() + ".asset",
    84.                                     "asset",
    85.                                     "Choose a file location"
    86.                                     );
    87.                                 if(filePath!="") {
    88.                                     AssetDatabase.CreateAsset(new_mesh, filePath);
    89.                                     AssetDatabase.SaveAssets();
    90.                                     AssetDatabase.Refresh();
    91.                                 }
    92.                             }
    93.                         }
    94.                         GUI.enabled = true;
    95.                         if(show_help) {
    96.                             GUILayout.Label(
    97.                                 "When Clicked, save the meshes of current quality as LOD files."
    98.                                 , helpStyle
    99.                                 , GUILayout.ExpandWidth(true));
    100.                         }
    101.                         GUI.enabled = (state == 0);
    102.                         protect_boundary = EditorGUILayout.Toggle ("Protect Boundary", protect_boundary);
    103.                         GUI.enabled = true;
    104.                         if(show_help) {
    105.                             GUILayout.Label(
    106.                                 "When checked, all open boundaries will be protected; Otherwise, some smooth parts of open boundaries will be smartly merged. Both way, uv boundaries and material boundaries will be protected."
    107.                                 , helpStyle
    108.                                 , GUILayout.ExpandWidth(true));
    109.                         }
    110.                         EditorGUILayout.LabelField("Triangles", face_number.ToString() + "/" + origin_face_number.ToString());
    111.                         if(show_help) {
    112.                             GUILayout.Label(
    113.                                 "Display current triangle number and total triangle number."
    114.                                 , helpStyle
    115.                                 , GUILayout.ExpandWidth(true));
    116.                         }
    117.                         GUI.enabled = (state == 0);
    118.                         quality = EditorGUILayout.Slider ("Quality", quality, 0.0f, 100.0f);
    119.                         GUI.enabled = true;
    120.                         if(show_help) {
    121.                             GUILayout.Label(
    122.                                 "Drag to change the quality, the mesh will change just in time, be patient to wait for the completion of online operation."
    123.                                 , helpStyle
    124.                                 , GUILayout.ExpandWidth(true));
    125.                         }
    126.                         if(state != 0) {
    127.                             EditorGUILayout.LabelField("Time Elapse", (Time.realtimeSinceStartup - start_time).ToString("#0.0"));
    128.                         }
    129.                         if(www_result != null) {
    130.                             GUILayout.Label(
    131.                                 www_result
    132.                                 , helpStyle
    133.                                 , GUILayout.ExpandWidth(true));
    134.                         }
    135.                         if (GUI.changed) {
    136.                             if(save_show_help != show_help) {
    137.                                 string filename = "mantis_not_show_help";
    138.                                 if(show_help) {
    139.                                     if(System.IO.File.Exists(filename)) System.IO.File.Delete(filename);
    140.                                 } else {
    141.                                     if(!System.IO.File.Exists(filename)) System.IO.File.Create(filename);
    142.                                 }
    143.                                 save_show_help = show_help;
    144.                             }
    145.                             if(save_protect_boundary != protect_boundary) {
    146.                                 quality = 100.0f;
    147.                                 save_protect_boundary = protect_boundary;
    148.                             }
    149.                             if(save_quality != quality) {
    150.                                 // when idle
    151.                                 if (state == 0) {
    152.                                     start_update(1);
    153.                                 }
    154.                             }
    155.                         }
    156.                     }
    157.                 }
    158.             }
    159.         }
    160.         private void start_update(int one_state) {
    161.             state = one_state;
    162.             tag_when_update = 0;
    163.             start_time = Time.realtimeSinceStartup;
    164.             EditorApplication.update += Update;
    165.         }
    166.         private void end_update() {
    167.             state = 0;
    168.             tag_when_update = 0;
    169.             start_time = 0.0f;
    170.             EditorApplication.update -= Update;
    171.         }
    172.         private void shrink_mesh(Mesh mesh) {
    173.             // get all origin data
    174.             Vector3[] origin_vertices = mesh.vertices;
    175.             Vector3[] vertices = null;
    176.             if(origin_vertices != null && origin_vertices.Length > 0) vertices = new Vector3[origin_vertices.Length];
    177.             BoneWeight[] origin_boneWeights = mesh.boneWeights;
    178.             BoneWeight[] boneWeights = null;
    179.             if(origin_boneWeights != null && origin_boneWeights.Length > 0) boneWeights = new BoneWeight[origin_boneWeights.Length];
    180.             Color[] origin_colors = mesh.colors;
    181.             Color[] colors = null;
    182.             if(origin_colors != null && origin_colors.Length > 0) colors = new Color[origin_colors.Length];
    183.             Color32[] origin_colors32 = mesh.colors32;
    184.             Color32[] colors32 = null;
    185.             if(origin_colors32 != null && origin_colors32.Length > 0) colors32 = new Color32[origin_colors32.Length];
    186.             Vector4[] origin_tangents = mesh.tangents;
    187.             Vector4[] tangents = null;
    188.             if(origin_tangents != null && origin_tangents.Length > 0) tangents = new Vector4[origin_tangents.Length];
    189.             Vector2[] origin_uv = mesh.uv;
    190.             Vector2[] uv = null;
    191.             if(origin_uv != null && origin_uv.Length > 0) uv = new Vector2[origin_uv.Length];
    192.             Vector2[] origin_uv2 = mesh.uv2;
    193.             Vector2[] uv2 = null;
    194.             if(origin_uv2 != null && origin_uv2.Length > 0) uv2 = new Vector2[origin_uv2.Length];
    195.             int[][] origin_triangles = new int[mesh.subMeshCount][];
    196.             for (int i=0; i<mesh.subMeshCount; i++) {
    197.                 origin_triangles[i] = mesh.GetTriangles(i);
    198.             }
    199.             //     make permutation
    200.             Hashtable imap = new Hashtable ();
    201.             int vertex_count = 0;
    202.             for (int i=0; i<mesh.subMeshCount; i++) {
    203.                 int[] triangles = mesh.GetTriangles(i);
    204.                 for(int j=0; j<triangles.Length; j += 3) {
    205.                     if(!imap.Contains(triangles[j])) {
    206.                         if(vertices != null) vertices[vertex_count] = origin_vertices[triangles[j]];
    207.                         if(boneWeights != null) boneWeights[vertex_count] = origin_boneWeights[triangles[j]];
    208.                         if(colors != null) colors[vertex_count] = origin_colors[triangles[j]];
    209.                         if(colors32 != null) colors32[vertex_count] = origin_colors32[triangles[j]];
    210.                         if(tangents != null) tangents[vertex_count] = origin_tangents[triangles[j]];
    211.                         if(uv != null) uv[vertex_count] = origin_uv[triangles[j]];
    212.                         if(uv2 != null) uv2[vertex_count] = origin_uv2[triangles[j]];
    213.                         imap.Add(triangles[j], vertex_count);
    214.                         vertex_count++;
    215.                     }
    216.                     if(!imap.Contains(triangles[j+1])) {
    217.                         if(vertices != null) vertices[vertex_count] = origin_vertices[triangles[j+1]];
    218.                         if(boneWeights != null) boneWeights[vertex_count] = origin_boneWeights[triangles[j+1]];
    219.                         if(colors != null) colors[vertex_count] = origin_colors[triangles[j+1]];
    220.                         if(colors32 != null) colors32[vertex_count] = origin_colors32[triangles[j+1]];
    221.                         if(tangents != null) tangents[vertex_count] = origin_tangents[triangles[j+1]];
    222.                         if(uv != null) uv[vertex_count] = origin_uv[triangles[j+1]];
    223.                         if(uv2 != null) uv2[vertex_count] = origin_uv2[triangles[j+1]];
    224.                         imap.Add(triangles[j+1], vertex_count);
    225.                         vertex_count++;
    226.                     }
    227.                     if(!imap.Contains(triangles[j+2])) {
    228.                         if(vertices != null) vertices[vertex_count] = origin_vertices[triangles[j+2]];
    229.                         if(boneWeights != null) boneWeights[vertex_count] = origin_boneWeights[triangles[j+2]];
    230.                         if(colors != null) colors[vertex_count] = origin_colors[triangles[j+2]];
    231.                         if(colors32 != null) colors32[vertex_count] = origin_colors32[triangles[j+2]];
    232.                         if(tangents != null) tangents[vertex_count] = origin_tangents[triangles[j+2]];
    233.                         if(uv != null) uv[vertex_count] = origin_uv[triangles[j+2]];
    234.                         if(uv2 != null) uv2[vertex_count] = origin_uv2[triangles[j+2]];
    235.                         imap.Add(triangles[j+2], vertex_count);
    236.                         vertex_count++;
    237.                     }
    238.                 }
    239.             }
    240.             // set data back to mesh
    241.             mesh.Clear (false);
    242.             if (vertices != null) {
    243.                 Vector3[] new_vertices = new Vector3[vertex_count];
    244.                 Array.Copy(vertices, new_vertices, vertex_count);
    245.                 mesh.vertices = new_vertices;
    246.             }
    247.             if (boneWeights != null) {
    248.                 BoneWeight[] new_boneWeights = new BoneWeight[vertex_count];
    249.                 Array.Copy(boneWeights, new_boneWeights, vertex_count);
    250.                 mesh.boneWeights = new_boneWeights;
    251.             }
    252.             if (colors != null) {
    253.                 Color[] new_colors = new Color[vertex_count];
    254.                 Array.Copy(colors, new_colors, vertex_count);
    255.                 mesh.colors = new_colors;
    256.             }
    257.             if (colors32 != null) {
    258.                 Color32[] new_colors32 = new Color32[vertex_count];
    259.                 Array.Copy(colors32, new_colors32, vertex_count);
    260.                 mesh.colors32 = new_colors32;
    261.             }
    262.             if (tangents != null) {
    263.                 Vector4[] new_tangents = new Vector4[vertex_count];
    264.                 Array.Copy(tangents, new_tangents, vertex_count);
    265.                 mesh.tangents = new_tangents;
    266.             }
    267.             if (uv != null) {
    268.                 Vector2[] new_uv = new Vector2[vertex_count];
    269.                 Array.Copy(uv, new_uv, vertex_count);
    270.                 mesh.uv = new_uv;
    271.             }
    272.             if (uv2 != null) {
    273.                 Vector2[] new_uv2 = new Vector2[vertex_count];
    274.                 Array.Copy(uv2, new_uv2, vertex_count);
    275.                 mesh.uv2 = new_uv2;
    276.             }
    277.             mesh.subMeshCount = origin_triangles.Length;
    278.             for (int i=0; i<mesh.subMeshCount; i++) {
    279.                 int[] new_triangles = new int[origin_triangles[i].Length];
    280.                 for(int j=0; j<new_triangles.Length; j += 3) {
    281.                     new_triangles[j] = (int)imap[origin_triangles[i][j]];
    282.                     new_triangles[j+1] = (int)imap[origin_triangles[i][j+1]];
    283.                     new_triangles[j+2] = (int)imap[origin_triangles[i][j+2]];
    284.                 }
    285.                 mesh.SetTriangles(new_triangles, i);
    286.             }
    287.             // refresh normals and bounds
    288.             mesh.RecalculateNormals();
    289.             mesh.RecalculateBounds();
    290.         }
    291.         private void get_all_meshes() {
    292.             Component[] allFilters = (Component[])((GameObject)target).GetComponentsInChildren (typeof(MeshFilter));
    293.             Component[] allRenderers = (Component[])((GameObject)target).GetComponentsInChildren (typeof(SkinnedMeshRenderer));
    294.             int mesh_count = allFilters.Length + allRenderers.Length;
    295.             if (mesh_count > 0) {
    296.                 Mantis_Meshes = new Mantis_Mesh[mesh_count];
    297.                 int counter = 0;
    298.                 foreach (Component child in allFilters) {
    299.                     Mantis_Meshes[counter] = new Mantis_Mesh();
    300.                     Mantis_Meshes[counter].mesh = ((MeshFilter)child).sharedMesh;
    301.                     counter++;
    302.                 }
    303.                 foreach (Component child in allRenderers) {
    304.                     Mantis_Meshes[counter] = new Mantis_Mesh();
    305.                     Mantis_Meshes[counter].mesh = ((SkinnedMeshRenderer)child).sharedMesh;
    306.                     counter++;
    307.                 }
    308.             }
    309.         }
    310.         void Awake() {
    311.             init_all();
    312.         }
    313.         void init_all() {
    314.             if (Mantis_Meshes == null) {
    315.                 if(target) {
    316.                     get_all_meshes();
    317.                     if (Mantis_Meshes != null) {
    318.                         face_number = 0;
    319.                         foreach (Mantis_Mesh child in Mantis_Meshes) {
    320.                             int triangle_number = child.mesh.triangles.Length;
    321.                             child.origin_triangles = new int[child.mesh.subMeshCount][];
    322.                             // out data is large than origin data
    323.                             child.out_triangles = new int[triangle_number*2];
    324.                             for(int i=0; i<child.mesh.subMeshCount; i++) {
    325.                                 int[] sub_triangles = child.mesh.GetTriangles(i);
    326.                                 face_number += sub_triangles.Length/3;
    327.                                 // save origin triangle list
    328.                                 child.origin_triangles[i] = new int[sub_triangles.Length];
    329.                                 Array.Copy(sub_triangles, child.origin_triangles[i], sub_triangles.Length);
    330.                             }
    331.                             // load cached uuid
    332.                             string filename = "mantis_uuid_" + child.mesh.GetInstanceID().ToString();
    333.                             if(System.IO.File.Exists(filename)) {
    334.                                 child.uuid = System.IO.File.ReadAllText(filename);
    335.                             } else {
    336.                                 child.uuid = null;
    337.                             }
    338.                         }
    339.                         origin_face_number = face_number;
    340.                         string filename2 = "mantis_not_show_help";
    341.                         if(System.IO.File.Exists(filename2)) {
    342.                             show_help = false;
    343.                             save_show_help = false;
    344.                         } else {
    345.                             show_help = true;
    346.                             save_show_help = true;
    347.                         }
    348.                     }
    349.                 }
    350.             }
    351.         }
    352.         void Update() {
    353.             // we cannot use nice yield method in Editor class, I have to write ugly code:(
    354.             switch(state) {
    355.             case 1: download_stage_1(); break;
    356.             case 2: download_stage_2(); break;
    357.             case 3: download_stage_3(); break;
    358.             case 101: upload_stage_1(); break;
    359.             case 102: upload_stage_2(); break;
    360.             }
    361.             // show time elapse label in main thread
    362.             Repaint();
    363.         }
    364.         private void download_stage_1() {
    365.             face_number = 0;
    366.             state = 2;
    367.         }
    368.         private void download_stage_2() {
    369.             Mantis_Mesh child = Mantis_Meshes[tag_when_update];
    370.             // get triangle list by quality value
    371.             if(child.uuid != null) {
    372.                 get_triangle_list(child.uuid, quality, child.out_triangles, ref child.out_count);
    373.                 state = 3;
    374.             } else {
    375.                 www_result = "You need to upload your mesh.";
    376.                 end_update();
    377.             }
    378.         }
    379.         private void download_stage_3() {
    380.             if(www.isDone) {
    381.                 if(!String.IsNullOrEmpty(www.error)) {
    382.                     www_result = "Error with network: " + www.error;
    383.                     end_update();
    384.                 } else {
    385.                     string ret = www.text;
    386.                     if(ret[0] == '[' && ret[ret.Length-2] == ']') {
    387.                         ret = ret.Substring(1, ret.Length-3);
    388.                         string[] triangle_array = ret.Split(new char[]{' '});
    389.                         Mantis_Mesh child = Mantis_Meshes[tag_when_update];
    390.                         for(int i=0; i<triangle_array.Length; i++) {
    391.                             child.out_triangles[i] = int.Parse(triangle_array[i]);
    392.                         }
    393.                         child.out_count = triangle_array.Length;
    394.                         if(child.out_count > 0) {
    395.                             int counter = 0;
    396.                             int mat = 0;
    397.                             while(counter < child.out_count) {
    398.                                 int len = child.out_triangles[counter];
    399.                                 counter++;
    400.                                 if(len > 0) {
    401.                                     int[] new_triangles = new int[len];
    402.                                     Array.Copy(child.out_triangles, counter, new_triangles, 0, len);
    403.                                     child.mesh.SetTriangles(new_triangles, mat);
    404.                                     counter += len;
    405.                                 } else {
    406.                                     child.mesh.SetTriangles(null, mat);
    407.                                 }
    408.                                 mat++;
    409.                             }
    410.                             face_number += child.mesh.triangles.Length/3;
    411.                             // refresh normals and bounds
    412.                             child.mesh.RecalculateNormals();
    413.                             child.mesh.RecalculateBounds();
    414.                             EditorUtility.SetDirty (target);
    415.                         }
    416.                      
    417.                         tag_when_update++;
    418.                         if(tag_when_update < Mantis_Meshes.Length) {
    419.                             // loop to stage 2
    420.                             state = 2;
    421.                         } else {
    422.                             // finish
    423.                             save_quality = quality;
    424.                             end_update();
    425.                         }
    426.                     } else {
    427.                         www_result = www.text;
    428.                         end_update();
    429.                     }
    430.                 }
    431.             }
    432.         }
    433.      
    434.         private void upload_stage_1() {
    435.             Mantis_Mesh child = Mantis_Meshes[tag_when_update];
    436.             int triangle_number = child.mesh.triangles.Length;
    437.             Vector3[] vertices = child.mesh.vertices;
    438.             // in data is large than origin data
    439.             int[] triangles = new int[triangle_number*2];
    440.             // we need uv data to protect uv boundary
    441.             Vector2[] uvs = child.mesh.uv;
    442.             int counter = 0;
    443.             for(int i=0; i<child.mesh.subMeshCount; i++) {
    444.                 int[] sub_triangles = child.mesh.GetTriangles(i);
    445.                 triangles[counter] = sub_triangles.Length;
    446.                 counter++;
    447.                 Array.Copy(sub_triangles, 0, triangles, counter, sub_triangles.Length);
    448.                 counter += sub_triangles.Length;
    449.             }
    450.          
    451.             // upload data
    452.             upload_data(vertices, vertices.Length, triangles, counter, uvs, uvs.Length);
    453.             state = 102;
    454.         }
    455.         private void upload_stage_2() {
    456.             if(www.isDone) {
    457.                 if(!String.IsNullOrEmpty(www.error)) {
    458.                     www_result = "Error with network: " + www.error;
    459.                     end_update();
    460.                 } else {
    461.                     string ret = www.text;
    462.                     if(ret[0] == '[' && ret[ret.Length-2] == ']') {
    463.                         ret = ret.Substring(1, ret.Length-3);
    464.                         Mantis_Mesh child = Mantis_Meshes[tag_when_update];
    465.                         child.uuid = ret;
    466.                         // save uuid to file
    467.                         string filename = "mantis_uuid_" + child.mesh.GetInstanceID().ToString();
    468.                         System.IO.File.WriteAllText(filename, child.uuid);
    469.                      
    470.                         tag_when_update++;
    471.                         if(tag_when_update < Mantis_Meshes.Length) {
    472.                             // loop to stage 1
    473.                             state = 101;
    474.                         } else {
    475.                             // finish
    476.                             www_result = "Upload success.";
    477.                             end_update();
    478.                         }
    479.                     } else {
    480.                         www_result = www.text;
    481.                         end_update();
    482.                     }
    483.                 }
    484.             }
    485.         }
    486.         private void upload_data(Vector3[] vertex_array, int vertex_count, int[] triangle_array, int triangle_count, Vector2[] uv_array, int uv_count) {
    487.             WWWForm form = new WWWForm();
    488.             StringBuilder vertex_array_string = new StringBuilder();
    489.             StringBuilder triangle_array_string = new StringBuilder();
    490.             StringBuilder uv_array_string = new StringBuilder();
    491.             for(int i=0; i<vertex_count; i++) {
    492.                 vertex_array_string.Append(vertex_array[i].x.ToString("G6"));
    493.                 vertex_array_string.Append(" ");
    494.                 vertex_array_string.Append(vertex_array[i].y.ToString("G6"));
    495.                 vertex_array_string.Append(" ");
    496.                 vertex_array_string.Append(vertex_array[i].z.ToString("G6"));
    497.                 ;
    498.                 if(i+1 != vertex_count) vertex_array_string.Append(" ");
    499.             }
    500.             for(int i=0; i<triangle_count; i++) {
    501.                 triangle_array_string.Append(triangle_array[i].ToString());
    502.                 if(i+1 != triangle_count) triangle_array_string.Append(" ");
    503.             }
    504.             for(int i=0; i<uv_count; i++) {
    505.                 uv_array_string.Append(uv_array[i].x.ToString("G6"));
    506.                 uv_array_string.Append(" ");
    507.                 uv_array_string.Append(uv_array[i].y.ToString("G6"));
    508.                 if(i+1 != uv_count) uv_array_string.Append(" ");
    509.             }
    510.             form.AddField("vertex_array", vertex_array_string.ToString());
    511.             form.AddField("vertex_count", vertex_count.ToString());
    512.             form.AddField("triangle_array", triangle_array_string.ToString());
    513.             form.AddField("triangle_count", triangle_count.ToString());
    514.             form.AddField("uv_array", uv_array_string.ToString());
    515.             form.AddField("uv_count", uv_count.ToString());
    516.          
    517.             www = new WWW("http://" + server_name + "/cgi-bin/upload.cgi", form);
    518.             www_result = null;
    519.         }
    520.         private void get_triangle_list(string uuid, float goal, int[] triangles, ref int triangle_count) {
    521.             WWWForm form = new WWWForm();
    522.             form.AddField("uuid", uuid);
    523.             form.AddField("goal", goal.ToString());
    524.             form.AddField("protect_boundary", protect_boundary?"1":"0");
    525.             www = new WWW("http://" + server_name + "/cgi-bin/download.cgi", form);
    526.             www_result = null;
    527.         }
    528.         private void clean_all() {
    529.             // restore triangle list
    530.             if (Mantis_Meshes != null) {
    531.                 if(target) {
    532.                     foreach (Mantis_Mesh child in Mantis_Meshes) {
    533.                         if(child.uuid != null) {
    534.                             for(int i=0; i<child.mesh.subMeshCount; i++) {
    535.                                 child.mesh.SetTriangles(child.origin_triangles[i], i);
    536.                             }
    537.                             child.mesh.RecalculateNormals();
    538.                             child.mesh.RecalculateBounds();
    539.                             child.uuid = null;
    540.                         }
    541.                     }
    542.                 }
    543.                 Mantis_Meshes = null;
    544.             }
    545.         }
    546.         public void OnDisable() {
    547.             clean_all();
    548.         }
    549.         public void OnDestroy() {
    550.             clean_all ();
    551.         }
    552.     }
    553. }
    554.  
     
    Last edited: Jul 27, 2014
    domkia likes this.
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    This belongs in show off I believe? Maybe assets?
     
  3. meshonline

    meshonline

    Joined:
    Feb 7, 2014
    Posts:
    121
    Yes, it is asset, but it is also a piece of script.
     
    Last edited: Jul 27, 2014
  4. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Yes, I'm saying you posted in the wrong forum.