public static void CreateHexagon(VegetationMaskArea mask) { float radius = GetRadius(mask); Vector3[] hexagon = ShapeCreator.CreateHexagon(mask.transform.position, radius); mask.Nodes.Clear(); mask.AddNodesToEnd(hexagon); // center main handle, implicitly updates the mask CenterMainHandle(mask); }
/// <summary> /// Create Biome masks for the specified bounds /// </summary> /// <param name="bounds"></param> private void CreateMasks(Bounds bounds) { float outerRadius = GetOuterRadius(bounds); // bounds for clipping Vector2[] clipPolygon = editor.GetBiomeClipPolygon(bounds); float density = editor.extension.biomeSettings.density; List <Vector3> positions = GetPositions(bounds); foreach (Vector3 position in positions) { // skip randomly if (density != 1 && UnityEngine.Random.Range(0f, 1f) >= density) { continue; } Vector3[] hexagon = ShapeCreator.CreateHexagon(position, outerRadius); // clip, convert to vector2 Vector2[] polygonXY = hexagon.Select(item => new Vector2(item.x, item.z)).ToArray(); Vector2[] clippedPoints = SutherlandHodgman.GetIntersectedPolygon(polygonXY, clipPolygon); if (clippedPoints == null || clippedPoints.Length < 3) { continue; } // convert back to vector3 hexagon = clippedPoints.Select(item => new Vector3(item.x, 0, item.y)).ToArray(); int maskId = editor.GetNextMaskId(); List <Vector3> nodes = hexagon.OfType <Vector3>().ToList(); // apply random shape if requested if (editor.extension.shapeSettings.randomShape) { nodes = ShapeCreator.CreateRandomShape(nodes, // editor.extension.shapeSettings.RandomConvexity, // editor.extension.shapeSettings.keepOriginalPoints, // editor.extension.shapeSettings.RandomPointsCount, // editor.extension.shapeSettings.randomAngle, // editor.extension.shapeSettings.douglasPeuckerReductionTolerance); } CreateBiomeMaskArea("Biome Mask " + maskId, "Mask " + maskId, position, nodes); } }