From 6bc097be26e71261e0ae1f8b7f9194d3da73cf61 Mon Sep 17 00:00:00 2001 From: Henry de Jongh Date: Sun, 28 Oct 2018 08:29:52 +0100 Subject: [PATCH] Chamfer now assigns materials to new polygons. --- Scripts/Core/PolygonFactory.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Scripts/Core/PolygonFactory.cs b/Scripts/Core/PolygonFactory.cs index 3615272d..680569eb 100644 --- a/Scripts/Core/PolygonFactory.cs +++ b/Scripts/Core/PolygonFactory.cs @@ -546,6 +546,7 @@ internal static bool ChamferPolygons(List polygons, List edges, f { // list of clipping planes. List clippingPlanes = new List(); + List clippingPlaneMaterials = new List(); // iterate through all edges and calculate the clipping planes. for (int e = 0; e < edges.Count; e++) @@ -577,6 +578,9 @@ internal static bool ChamferPolygons(List polygons, List edges, f p2, p1 + (v1 - v2).normalized )); + // find the most likely material we should be using for this chamfer. + // an attempt is made to ignore the default material. + clippingPlaneMaterials.Add(matchingPolygons[0].Material != null ? matchingPolygons[0].Material : matchingPolygons[1].Material); } } @@ -590,6 +594,10 @@ internal static bool ChamferPolygons(List polygons, List edges, f List polygonsBack; if (SplitPolygonsByPlane(resultPolygons, clippingPlanes[i], false, out polygonsFront, out polygonsBack)) resultPolygons = polygonsFront; + // assign the most likely material to the new polygons. + for (int j = 0; j < resultPolygons.Count; j++) + if (resultPolygons[j].Plane.normal.EqualsWithEpsilonLower3(clippingPlanes[i].normal)) + resultPolygons[j].Material = clippingPlaneMaterials[i]; } return true;