public void TestEdit() { var before = GetRandomObjects(_document, 200).OfType<Solid>().ToList(); var after = before.Select(x => x.Clone()).ToList(); var rot = new UnitRotate(40, new Line(new Coordinate(1, 0, -1), new Coordinate(2, -3, 7))); after.ForEach(x => x.Transform(rot, TransformFlags.None)); TestAction(new Edit(before, after)); }
/// <summary> /// Rotate the texture around the texture normal. /// </summary> /// <param name="rotate">The rotation angle in degrees</param> public void SetTextureRotation(decimal rotate) { var rads = DMath.DegreesToRadians(Texture.Rotation - rotate); // Rotate around the texture normal var texNorm = Texture.VAxis.Cross(Texture.UAxis).Normalise(); var transform = new UnitRotate(rads, new Line(Coordinate.Zero, texNorm)); Texture.UAxis = transform.Transform(Texture.UAxis); Texture.VAxis = transform.Transform(Texture.VAxis); Texture.Rotation = rotate; CalculateTextureCoordinates(false); }
public void AlignTextureWithFace(Face face) { // Get reference values for the axes var refU = face.Texture.UAxis; var refV = face.Texture.VAxis; // Reference points in the texture plane to use for shifting later on var refX = face.Texture.UAxis * face.Texture.XShift * face.Texture.XScale; var refY = face.Texture.VAxis * face.Texture.YShift * face.Texture.YScale; // Two non-parallel planes intersect at an edge. We want the textures on this face // to line up with the textures on the provided face. To do this, we rotate the texture // normal on the provided face around the intersection edge to get the new texture axes. // Then we rotate the texture reference point around this edge as well to get the new shift values. // The scale values on both faces will always end up being the same value. // Find the intersection edge vector var intersectionEdge = face.Plane.Normal.Cross(Plane.Normal); // Create a plane using the intersection edge as the normal var intersectionPlane = new Plane(intersectionEdge, 0); // If the planes are parallel, the texture doesn't need any rotation - just different shift values. var intersect = Plane.Intersect(face.Plane, Plane, intersectionPlane); if (intersect != null) { var texNormal = face.Texture.GetNormal(); // Since the intersection plane is perpendicular to both face planes, we can find the angle // between the two planes (the original texture plane and the plane of this face) by projecting // the normals of the planes onto the perpendicular plane and taking the cross product. // Project the two normals onto the perpendicular plane var ptNormal = intersectionPlane.Project(texNormal).Normalise(); var ppNormal = intersectionPlane.Project(Plane.Normal).Normalise(); // Get the angle between the projected normals var dot = Math.Round(ptNormal.Dot(ppNormal), 4); var angle = DMath.Acos(dot); // A.B = cos(angle) // Rotate the texture axis by the angle around the intersection edge var transform = new UnitRotate(angle, new Line(Coordinate.Zero, intersectionEdge)); refU = transform.Transform(refU); refV = transform.Transform(refV); // Rotate the texture reference points as well, but around the intersection line, not the origin refX = transform.Transform(refX + intersect) - intersect; refY = transform.Transform(refY + intersect) - intersect; } // Convert the reference points back to get the final values Texture.Rotation = 0; Texture.UAxis = refU; Texture.VAxis = refV; Texture.XShift = refU.Dot(refX) / face.Texture.XScale; Texture.YShift = refV.Dot(refY) / face.Texture.YScale; Texture.XScale = face.Texture.XScale; Texture.YScale = face.Texture.YScale; CalculateTextureCoordinates(true); }
public void TestEditAction() { var before = GetRandomObjects(_document, 200).OfType<Solid>().ToList(); var rot = new UnitRotate(40, new Line(new Coordinate(1, 0, -1), new Coordinate(2, -3, 7))); TestAction(new Edit(before, (d,x) => x.Transform(rot, TransformFlags.None))); }
public void RotateCounterClockwise() { if (_document.Selection.IsEmpty() || _document.Selection.InFaceSelection) return; var focused = ViewportManager.Viewports.FirstOrDefault(x => x.IsFocused && x is Viewport2D) as Viewport2D; if (focused == null) return; var center = new Box(_document.Selection.GetSelectedObjects().Select(x => x.BoundingBox).Where(x => x != null)).Center; var axis = focused.GetUnusedCoordinate(Coordinate.One); var transform = new UnitRotate(DMath.DegreesToRadians(-90), new Line(center, center + axis)); var selected = _document.Selection.GetSelectedParents(); _document.PerformAction("Transform selection", new Edit(selected, new TransformEditOperation(transform, _document.Map.GetTransformFlags()))); }