public void Attach(PolyMesh center, PolyMesh brush, int cornerCount) { //var center = PolyMesh.CreateGreatRhombicosidodecahedron(1.0); //var brush = PolyMesh.CreateDodecahedron(1.0); // Get brushPolygon Polygon brushPolygon = null; foreach (var polygon in brush.Geometry.Polygons) { if (polygon.Corners.Count == cornerCount) { brushPolygon = polygon; break; } } if (brushPolygon == null) { return; } List <Polygon> processPolygons = new List <Polygon>(); foreach (var centerPolygon in center.Geometry.Polygons) { if (centerPolygon.Corners.Count != cornerCount) { continue; } processPolygons.Add(centerPolygon); } foreach (var centerPolygon in processPolygons) { ReferenceFrame brushFrame = MakePolygonReference(brush.Geometry, brushPolygon); ReferenceFrame centerFrame = MakePolygonReference(center.Geometry, centerPolygon); var cloner = new CloneGeometryOperation(brush.Geometry, null); float scale = centerFrame.Scale / brushFrame.Scale; var newGeometry = cloner.Destination; var scaleTransform = Matrix4.CreateScale(scale); var clonedPolygon = cloner.polygonOldToNew[brushPolygon]; if (scale != 1.0f) { newGeometry.Transform(scaleTransform); brushFrame.Transform(scaleTransform); } centerFrame.Normal *= -1.0f; // Flip target normal.. Matrix4 centerTransform = centerFrame.GetTransform(); Matrix4 brushTransform = brushFrame.GetTransform(); Matrix4 inverseBrush = Matrix4.Invert(brushTransform); Matrix4 align = centerTransform * inverseBrush; newGeometry.Transform(align); //center.Geometry.MergeFast(newGeometry, centerPolygon, clonedPolygon); center.Geometry.Merge(newGeometry); } center.Geometry.ComputePolygonNormals(); center.Geometry.ComputePolygonCentroids(); center.Geometry.ComputeCornerNormals(2.0f * (float)Math.PI); center.BuildMeshFromGeometry(); }