Beispiel #1
0
        public bool BuildTriangles()
        {
            if (!trianglesChanged && !mesh.materials.materialsChanged)
            {
                return(false);
            }
            List <UnityEngine.Material> materials = MaterialUtils.GetMaterials(mesh);

            UnityEngine.Material[] materialArray = MaterialUtils.AssignMaterials(mesh, materials);
            mesh.uMesh.subMeshCount = materials.Count;
            List <Materials.MaterialTriangles> materialTriangles = mesh.materials.GetTriangles();

            for (int i = 0; i < materials.Count; i++)
            {
                mesh.uMesh.SetTriangles(materialTriangles[i].triangles.ToArray(), i);
            }
            Selectable selectable = mesh.GetComponent <Selectable>();

            mesh.materials.materialsChanged = false;
            if (selectable != null)
            {
                UnityEngine.Mesh outlineMesh = new UnityEngine.Mesh();
                outlineMesh.vertices  = mesh.uMesh.vertices;
                outlineMesh.triangles = mesh.triangles.triangles.ToArray();
                outlineMesh.RecalculateNormals();
                selectable.outlineMesh         = outlineMesh;
                selectable.unselectedMaterials = materialArray;
                selectable.UpdateSelectedMaterials();
            }
            else
            {
                // BoxSelectionController mesh only
                mesh.uMesh.triangles = triangles.ToArray();
            }
            trianglesChanged = false;
            return(true);
        }
 public override void OnGrabStart(Transform controller, int controllerIndex)
 {
     base.OnGrabStart(controller, controllerIndex);
     MeshEngine.Mesh mesh = Meshes.GetSelectedMesh();
     mesh.GetComponent <MeshInputController>().OnGrabStart(controller, controllerIndex);
 }
 public static UnityEngine.Material[] AssignMaterials(Mesh mesh, List <UnityEngine.Material> materials)
 {
     UnityEngine.Material[] materialsArray = materials.ToArray();
     mesh.GetComponent <MeshRenderer>().materials = materialsArray;
     return(materialsArray);
 }