public override void OnInspectorGUI()
 {
     aux = (MeshArray)target;
     if (GUILayout.Button("Update"))
     {
         Quaternion rot = aux.transform.rotation;
         aux.transform.rotation = Quaternion.identity;
         aux.UpdateArray();
         aux.transform.rotation = rot;
         EditorUtility.SetDirty(aux);
     }
     base.OnInspectorGUI();
 }
 public void SetMesh(Dictionary <long[], MeshArray> mesh_dict)
 {
     foreach (KeyValuePair <long[], MeshArray> entry in mesh_dict)
     {
         long[]    index     = entry.Key;
         MeshArray meshArray = entry.Value;
         Mesh      mesh      = meshArray.GetMesh();
         // If there is no existing game object for the block, create one.
         if (!gameobject_dict.ContainsKey(index))
         {
             GameObject meshObject = new GameObject(index.ToString());
             meshObject.transform.parent           = meshParent.transform;
             meshObject.transform.localPosition    = new Vector3(0, 0, 0);
             meshObject.transform.localEulerAngles = new Vector3(0, 0, 0);
             meshObject.transform.localScale       = new Vector3(1, 1, 1);
             MeshFilter   meshFilter   = meshObject.AddComponent <MeshFilter>();
             MeshRenderer meshRenderer = meshObject.AddComponent <MeshRenderer>();
             //meshRenderer.sharedMaterial = new Material(Shader.Find("Particles/Standard Unlit"));
             meshRenderer.sharedMaterial = material;
             gameobject_dict.Add(index, meshObject);
         }
         gameobject_dict[index].GetComponent <MeshFilter>().mesh = mesh;
     }
 }
    /// <summary>
    /// Generates a dictionary of MeshArrays specified by the message.
    /// </summary>
    /// <param name="meshMsg">Voxblox Mesh message to generate Meshes with.</param>
    /// <returns>A dictionary of MeshArrays.</returns>
    public Dictionary <long[], MeshArray> generateMesh(MeshMsg meshMsg)
    {
        Dictionary <Int64[], MeshArray> generated_mesh_dict = new Dictionary <long[], MeshArray>(new LongArrayEqualityComparer());
        /// The length of one block. Also the scaling factor of the coordinates.
        float scale_factor = meshMsg.GetBlockEdgeLength();

        /// List of all the mesh blocks.
        MeshBlockMsg[] mesh_blocks = meshMsg.GetMeshBlocks();
        /// Iterate through each mesh block generating and updating meshes for each.
        for (int i = 0; i < mesh_blocks.Length; i++)
        {
            /// index of the mesh block.
            Int64[] index = mesh_blocks[i].GetIndex();

            ushort[] x = mesh_blocks[i].GetX();
            ushort[] y = mesh_blocks[i].GetY();
            ushort[] z = mesh_blocks[i].GetZ();

            // Create a list of vertices and their corresponding colors.
            List <Vector3> newVertices = new List <Vector3>();
            List <Color>   newColors   = new List <Color>();

            // update indicies, converting from block index to global position transforms.
            for (int j = 0; j < x.Length; j++)
            {
                float zv = ((float)z[j] / 32768.0f + index[2]) * scale_factor;
                float xv = ((float)x[j] / 32768.0f + index[0]) * scale_factor;
                float yv = ((float)y[j] / 32768.0f + index[1]) * scale_factor;
                if (flipYZ)
                {
                    newVertices.Add(new Vector3(xv, zv, yv));
                }
                else
                {
                    newVertices.Add(new Vector3(xv, yv, zv));
                }
            }
            // update colors
            byte[] r = mesh_blocks[i].GetR();
            byte[] g = mesh_blocks[i].GetG();
            byte[] b = mesh_blocks[i].GetB();

            for (int j = 0; j < r.Length; j++)
            {
                newColors.Add(new Color32(r[j], g[j], b[j], alpha));
            }

            // Vertices come in triples each corresponding to one face.
            int[] newTriangles = new int[newVertices.Count / 3 * 3];
            for (int j = 0; j < newTriangles.Length; j++)
            {
                newTriangles[j] = j;
            }

            // correct for inverted mesh. By reversing the lists, the normal vectors point the right direction.
            newVertices.Reverse();
            newColors.Reverse();

            generated_mesh_dict[index] = new MeshArray(newVertices.ToArray(), newTriangles, newColors.ToArray());
        }
        return(generated_mesh_dict);
    }