private void Rebuild(UndoBuffer undoBuffer) { this.DebugDepth("Rebuild"); this.Children.Modify(list => { IObject3D lastChild = list.First(); list.Clear(); list.Add(lastChild); var offset = Offset; for (int i = 1; i < Count; i++) { var rotateRadians = MathHelper.DegreesToRadians(Rotate); if (ScaleOffset) { offset *= Scale; } var next = lastChild.Clone(); offset = Vector3.Transform(offset, Matrix4X4.CreateRotationZ(rotateRadians)); next.Matrix *= Matrix4X4.CreateTranslation(offset); if (RotatePart) { next.Matrix = next.ApplyAtBoundsCenter(Matrix4X4.CreateRotationZ(rotateRadians)); } next.Matrix = next.ApplyAtBoundsCenter(Matrix4X4.CreateScale(Scale)); list.Add(next); lastChild = next; } }); }
public AlignObject3D(IObject3D item, FaceAlign boundingFacesToAlign, Vector3 positionToAlignTo, string name = "") { AxisAlignedBoundingBox bounds = item.GetAxisAlignedBoundingBox(); if (IsSet(boundingFacesToAlign, FaceAlign.Left, FaceAlign.Right)) { positionToAlignTo.X = positionToAlignTo.X - bounds.minXYZ.X; } if (IsSet(boundingFacesToAlign, FaceAlign.Right, FaceAlign.Left)) { positionToAlignTo.X = positionToAlignTo.X - bounds.minXYZ.X - (bounds.maxXYZ.X - bounds.minXYZ.X); } if (IsSet(boundingFacesToAlign, FaceAlign.Front, FaceAlign.Back)) { positionToAlignTo.Y = positionToAlignTo.Y - bounds.minXYZ.Y; } if (IsSet(boundingFacesToAlign, FaceAlign.Back, FaceAlign.Front)) { positionToAlignTo.Y = positionToAlignTo.Y - bounds.minXYZ.Y - (bounds.maxXYZ.Y - bounds.minXYZ.Y); } if (IsSet(boundingFacesToAlign, FaceAlign.Bottom, FaceAlign.Top)) { positionToAlignTo.Z = positionToAlignTo.Z - bounds.minXYZ.Z; } if (IsSet(boundingFacesToAlign, FaceAlign.Top, FaceAlign.Bottom)) { positionToAlignTo.Z = positionToAlignTo.Z - bounds.minXYZ.Z - (bounds.maxXYZ.Z - bounds.minXYZ.Z); } Matrix *= Matrix4X4.CreateTranslation(positionToAlignTo); Children.Add(item.Clone()); }
public static IObject3D Minus(this IObject3D a, IObject3D b) { var resultsA = a.Clone(); SubtractObject3D.Subtract(resultsA.VisibleMeshes().Select((i) => i).ToList(), b.VisibleMeshes().Select((i) => i).ToList()); return(resultsA); }
public static async void DuplicateItem(this InteractiveScene scene, IObject3D sourceItem = null) { if (sourceItem == null) { if (scene.HasSelection) { sourceItem = scene.SelectedItem; } } if (sourceItem != null) { // Copy selected item IObject3D newItem = await Task.Run(() => { if (sourceItem != null) { if (sourceItem is SelectionGroupObject3D) { // the selection is a group of objects that need to be copied var copyList = sourceItem.Children.ToList(); scene.SelectedItem = null; foreach (var item in copyList) { var clonedItem = item.Clone(); // make the name unique var newName = agg_basics.GetNonCollidingName(item.Name, scene.DescendantsAndSelf().Select((d) => d.Name)); clonedItem.Name = newName; // add it to the scene scene.Children.Add(clonedItem); // add it to the selection scene.AddToSelection(clonedItem); } } else // the selection can be cloned easily { var clonedItem = sourceItem.Clone(); // make the name unique var newName = agg_basics.GetNonCollidingName(sourceItem.Name, scene.DescendantsAndSelf().Select((d) => d.Name)); clonedItem.Name = newName; // More useful if it creates the part in the exact position and then the user can move it. // Consistent with other software as well. LBB 2017-12-02 //PlatingHelper.MoveToOpenPositionRelativeGroup(clonedItem, Scene.Children); return(clonedItem); } } return(null); }); // it might come back null due to threading if (newItem != null) { scene.InsertNewItem(newItem); } } }
public RotateObject3D(IObject3D item, double xRadians = 0, double yRadians = 0, double zRadians = 0, string name = "") { RotationXDegrees = MathHelper.RadiansToDegrees(xRadians); RotationYDegrees = MathHelper.RadiansToDegrees(yRadians); RotationZDegrees = MathHelper.RadiansToDegrees(zRadians); Children.Add(item.Clone()); Rebuild(null); }
public static IObject3D Plus(this IObject3D a, IObject3D b) { var results = new Object3D(); results.Children.Add(a.Clone()); results.Children.Add(b.Clone()); return(results); }
public static IObject3D Minus(this IObject3D a, IObject3D b) { var subtract = new SubtractObject3D(); subtract.Children.Add(a.Clone()); var bClone = b.Clone(); subtract.Children.Add(bClone); subtract.ItemsToSubtract.Add(bClone.ID); subtract.Subtract(); var finalMesh = subtract.VisibleMeshes().First().Mesh; return new Object3D() { Mesh = finalMesh }; }
public SetCenterObject3D(IObject3D item, Vector3 offset, bool onX = true, bool onY = true, bool onZ = true) { var center = item.GetAxisAlignedBoundingBox(Matrix4X4.Identity).Center; Vector3 consideredOffset = Vector3.Zero; // zero out anything we don't want if (onX) { consideredOffset.X = offset.X - center.X; } if (onY) { consideredOffset.Y = offset.Y - center.Y; } if (onZ) { consideredOffset.Z = offset.Z - center.Z; } Matrix = Matrix4X4.CreateTranslation(consideredOffset); Children.Add(item.Clone()); }
/// <summary> /// Union a and b together. This can either return a single item with a mesh on it /// or a group item that has the a and be items as children /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="doMeshCombine"></param> /// <returns></returns> public static IObject3D Plus(this IObject3D a, IObject3D b, bool doMeshCombine = false) { if (doMeshCombine) { var combine = new CombineObject3D_2(); combine.Children.Add(a.Clone()); combine.Children.Add(b.Clone()); combine.Combine(); var finalMesh = combine.VisibleMeshes().First().Mesh; return(new Object3D() { Mesh = finalMesh }); } else { var group = new GroupObject3D(); group.Children.Add(a); group.Children.Add(b); return(group); } }
public static void AddSelectionAsChildren(this IObject3D newParent, InteractiveScene scene, IObject3D selectedItem) { if (selectedItem != null) { List <IObject3D> itemsToReplace; if (selectedItem is SelectionGroupObject3D) { itemsToReplace = selectedItem.Children.ToList(); foreach (var child in itemsToReplace) { newParent.Children.Add(child.Clone()); } } else { itemsToReplace = new List <IObject3D> { selectedItem }; newParent.Children.Add(selectedItem.Clone()); } scene.SelectedItem = null; newParent.MakeNameNonColliding(); scene.UndoBuffer.AddAndDo( new ReplaceCommand( itemsToReplace, new List <IObject3D> { newParent })); SelectModifiedItem(selectedItem, newParent, scene); } }
public static async void DuplicateItem(this ISceneContext sceneContext, double xOffset, IObject3D sourceItem = null) { var scene = sceneContext.Scene; if (sourceItem == null) { var selectedItem = scene.SelectedItem; if (selectedItem != null) { sourceItem = selectedItem; } } if (sourceItem != null) { // Copy selected item IObject3D newItem = await Task.Run(() => { if (sourceItem != null) { if (sourceItem is SelectionGroupObject3D) { // the selection is a group of objects that need to be copied var copyList = sourceItem.Children.ToList(); scene.SelectedItem = null; foreach (var item in copyList) { var clonedItem = item.Clone(); clonedItem.Translate(xOffset); // make the name unique var newName = agg_basics.GetNonCollidingName(item.Name, scene.DescendantsAndSelf().Select((d) => d.Name)); clonedItem.Name = newName; // add it to the scene scene.Children.Add(clonedItem); // add it to the selection scene.AddToSelection(clonedItem); } } else // the selection can be cloned easily { var clonedItem = sourceItem.Clone(); clonedItem.Translate(xOffset); // an empty string is used do denote special name processing for some container types if (!string.IsNullOrWhiteSpace(sourceItem.Name)) { // make the name unique var newName = agg_basics.GetNonCollidingName(sourceItem.Name, scene.DescendantsAndSelf().Select((d) => d.Name)); clonedItem.Name = newName; } // More useful if it creates the part in the exact position and then the user can move it. // Consistent with other software as well. LBB 2017-12-02 // PlatingHelper.MoveToOpenPositionRelativeGroup(clonedItem, Scene.Children); return(clonedItem); } } return(null); }); // it might come back null due to threading if (newItem != null) { sceneContext.InsertNewItem(newItem); } } }
public SetCenterObject3D(IObject3D item, Vector3 position) { Matrix = Matrix4X4.CreateTranslation(position - item.GetCenter()); Children.Add(item.Clone()); }