private static void conformSelection(ProceduralObject obj, List <int> editingVertexIndex, Vertex[] buffer, bool andNetBuildings) { obj.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.vertices, buffer); var bounds = new Bounds(ProceduralUtils.VertexWorldPosition(buffer.First(v => v.Index == editingVertexIndex[0]).Position, obj), Vector3.zero); var vertices = buffer.Where(v => (editingVertexIndex.Contains(v.Index) || (v.IsDependent && editingVertexIndex.Contains(v.DependencyIndex)))); foreach (Vertex v in vertices) { bounds.Encapsulate(ProceduralUtils.VertexWorldPosition(v.Position, obj)); } Vector3 bottomPoint = bounds.center; bottomPoint.y -= bounds.extents.y; var boundsOffset = new Vector3(0, bounds.size.y, 0); foreach (Vertex v in vertices) { var worldPos = ProceduralUtils.VertexWorldPosition(v, obj); var yDiff = worldPos.y - bottomPoint.y; worldPos = ProceduralUtils.NearestGroundPointVertical(worldPos + boundsOffset, andNetBuildings); worldPos.y += yDiff; v.Position = Quaternion.Inverse(obj.m_rotation) * (worldPos - obj.m_position); if (obj.isPloppableAsphalt) { v.Position = v.Position.RevertPloppableAsphaltPosition(); } } obj.historyEditionBuffer.ConfirmNewStep(buffer); }
public static void SnapEachToGround(ProceduralObject obj, List <int> editingVertexIndex, Vertex[] buffer) { obj.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.vertices, buffer); var vertices = buffer.Where(v => (editingVertexIndex.Contains(v.Index) || (v.IsDependent && editingVertexIndex.Contains(v.DependencyIndex)))); foreach (Vertex v in vertices) { var worldPos = ProceduralUtils.NearestGroundPointVertical(ProceduralUtils.VertexWorldPosition(v, obj)); v.Position = Quaternion.Inverse(obj.m_rotation) * (worldPos - obj.m_position); if (obj.isPloppableAsphalt) { v.Position = v.Position.RevertPloppableAsphaltPosition(); } } obj.historyEditionBuffer.ConfirmNewStep(buffer); }