public static void KtaneDoubleOhArrange([ToolDouble("Center X?")] double centerX, [ToolDouble("Center Z?")] double centerZ, [ToolDouble("Radius?")] double radius, [ToolDouble("Bézier factor?")] double f) { // big (4 buttons) //var center = new Pt(-0.25, 0.15, 0.1); //var radius = .6; //var f = .2; // small (submit button) //var center = new Pt(.5, .15, .45); //var radius = .275; //var f = .05; // custom var center = new Pt(centerX, .15, centerZ); var bézierSteps = 72 / 4 + 1; var b1 = bézier(center + new Pt(-radius, 0, 0), center + new Pt(-radius, 0, f), center + new Pt(-f, 0, radius), center + new Pt(0, 0, radius), bézierSteps); var b2 = bézier(center + new Pt(0, 0, radius), center + new Pt(f, 0, radius), center + new Pt(radius, 0, f), center + new Pt(radius, 0, 0), bézierSteps); var b3 = bézier(center + new Pt(radius, 0, 0), center + new Pt(radius, 0, -f), center + new Pt(f, 0, -radius), center + new Pt(0, 0, -radius), bézierSteps); var b4 = bézier(center + new Pt(0, 0, -radius), center + new Pt(-f, 0, -radius), center + new Pt(-radius, 0, -f), center + new Pt(-radius, 0, 0), bézierSteps); var bs = b1.Skip(1).Concat(b2.Skip(1)).Concat(b3.Skip(1)).Concat(b4.Skip(1)).ToArray(); Program.Settings.Execute(new MoveVertices(Ut.NewArray(Program.Settings.SelectedVertices.Count, i => Tuple.Create(Program.Settings.SelectedVertices[i], bs[i])))); }
public static void KtaneTheBulbRotation() { var axisEnd = new Pt(-0.42426406871192862, 0.150511, -0.32426406871192848); var axisStart = new Pt(0.4242640687119284, 0.150511, -0.32426406871192859); var tilt = 30; // angle in degrees Program.Settings.Execute(new MoveVertices( Program.Settings.SelectedVertices .Select(p => Tuple.Create(p, p.Rotate(axisStart, axisEnd, tilt))) .ToArray())); }
public static void ArrangeInCircle( //[ToolDouble("Radius of the circle?")] double radius, //[ToolDouble("Offset angle? (0 = first vertex is right of the center; vertices go clockwise)")] double offsetAngle ) { var center = new Pt(-0.7, 0.150511, 0.66); var radius = .12 + .03; var offsetAngle = -90; //var center = new Pt(-0.54, 0.150511, 0.588); //var radius = .12 + .03; //var offsetAngle = 90; Program.Settings.Execute(new MoveVertices(Ut.NewArray(Program.Settings.SelectedVertices.Count, i => Tuple.Create( Program.Settings.SelectedVertices[i], new Pt(center.X + radius * cs(i * 360 / Program.Settings.SelectedVertices.Count + offsetAngle), center.Y, center.Z + radius * sn(i * 360 / Program.Settings.SelectedVertices.Count + offsetAngle)))))); }
public static void SortSelection( [ToolBool( "• Which direction?", "Clockwise", "Counter-clockwise")] bool cw) { var midPt = new Pt( Program.Settings.SelectedVertices.Sum(p => p.X) / Program.Settings.SelectedVertices.Count, Program.Settings.SelectedVertices.Sum(p => p.Y) / Program.Settings.SelectedVertices.Count, Program.Settings.SelectedVertices.Sum(p => p.Z) / Program.Settings.SelectedVertices.Count); Program.Settings.SelectedVertices.Sort((p1, p2) => { var atan1 = Math.Atan2(p1.Z - midPt.Z, p1.X - midPt.X); var atan2 = Math.Atan2(p2.Z - midPt.Z, p2.X - midPt.X); return(atan1.CompareTo(atan2) * (cw ? -1 : 1)); }); }
public override void Redo() { Pt location = default(Pt); foreach (var tup in _affectedFaces) { var list = tup.Item1.Vertices.ToList(); foreach (var index in tup.Item2.OrderByDescending(ix => ix)) { list.Insert(index + 1, new VertexInfo( (location = (list[index].Location + list[(index + 1) % list.Count].Location) / 2), (list[index].Texture + list[(index + 1) % list.Count].Texture) / 2, (list[index].Normal + list[(index + 1) % list.Count].Normal) / 2)); } tup.Item1.Vertices = list.ToArray(); } Program.Settings.SelectedVertices = new List <Pt> { location }; }
private static IEnumerable <Pt> bézier(Pt start, Pt control1, Pt control2, Pt end, int steps) { return(Enumerable.Range(0, steps) .Select(i => (double)i / (steps - 1)) .Select(t => pow(1 - t, 3) * start + 3 * pow(1 - t, 2) * t * control1 + 3 * (1 - t) * t * t * control2 + pow(t, 3) * end)); }
private static Pt round(Pt input) => new Pt(Math.Round(input.X), Math.Round(input.Y), Math.Round(input.Z));
public VertexInfo(Pt location, PointD?texture, Pt?normal) { Location = location; Texture = texture; Normal = normal; }