Make lots of objects use the center and height maintainer (for consistency)

This commit is contained in:
Lars Brubaker 2019-01-29 15:13:16 -08:00
parent 77ebe6ab09
commit 6e8b7386c8
22 changed files with 485 additions and 572 deletions

View file

@ -73,59 +73,54 @@ namespace MatterHackers.MatterControl.DesignTools
{
using (RebuildLock())
{
var aabb = this.GetAxisAlignedBoundingBox();
this.Children.Modify(list =>
using (new CenterAndHeightMantainer(this))
{
this.Children.Modify(list =>
{
list.Clear();
});
var brailleLetter = new BrailleObject3D()
{
TextToEncode = Letter.ToString(),
BaseHeight = BaseHeight,
};
brailleLetter.Rebuild(null);
this.Children.Add(brailleLetter);
var brailleLetter = new BrailleObject3D()
{
TextToEncode = Letter.ToString(),
BaseHeight = BaseHeight,
};
brailleLetter.Rebuild(null);
this.Children.Add(brailleLetter);
var textObject = new TextObject3D()
{
PointSize = 46,
Color = Color.LightBlue,
NameToWrite = Letter.ToString(),
Height = BaseHeight
};
var textObject = new TextObject3D()
{
PointSize = 46,
Color = Color.LightBlue,
NameToWrite = Letter.ToString(),
Height = BaseHeight
};
textObject.Invalidate(InvalidateType.Properties);
IObject3D letterObject = new RotateObject3D(textObject, MathHelper.Tau / 4);
letterObject = new AlignObject3D(letterObject, FaceAlign.Bottom | FaceAlign.Front, brailleLetter, FaceAlign.Top | FaceAlign.Front, 0, 0, 3.5);
letterObject = new SetCenterObject3D(letterObject, brailleLetter.GetCenter(), true, false, false);
this.Children.Add(letterObject);
textObject.Invalidate(InvalidateType.Properties);
IObject3D letterObject = new RotateObject3D(textObject, MathHelper.Tau / 4);
letterObject = new AlignObject3D(letterObject, FaceAlign.Bottom | FaceAlign.Front, brailleLetter, FaceAlign.Top | FaceAlign.Front, 0, 0, 3.5);
letterObject = new SetCenterObject3D(letterObject, brailleLetter.GetCenter(), true, false, false);
this.Children.Add(letterObject);
var basePath = new RoundedRect(0, 0, 22, 34, 3)
{
ResolutionScale = 10
};
var basePath = new RoundedRect(0, 0, 22, 34, 3)
{
ResolutionScale = 10
};
IObject3D basePlate = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(basePath, BaseHeight),
Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
};
IObject3D basePlate = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(basePath, BaseHeight),
Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
};
basePlate = new AlignObject3D(basePlate, FaceAlign.Bottom | FaceAlign.Back, brailleLetter, FaceAlign.Bottom | FaceAlign.Back);
basePlate = new SetCenterObject3D(basePlate, brailleLetter.GetCenter(), true, false, false);
this.Children.Add(basePlate);
basePlate = new AlignObject3D(basePlate, FaceAlign.Bottom | FaceAlign.Back, brailleLetter, FaceAlign.Bottom | FaceAlign.Back);
basePlate = new SetCenterObject3D(basePlate, brailleLetter.GetCenter(), true, false, false);
this.Children.Add(basePlate);
IObject3D underline = CubeObject3D.Create(basePlate.XSize(), .2, 1);
underline = new AlignObject3D(underline, FaceAlign.Bottom, brailleLetter, FaceAlign.Top);
underline = new AlignObject3D(underline, FaceAlign.Back | FaceAlign.Left, basePlate, FaceAlign.Front | FaceAlign.Left, 0, .01);
this.Children.Add(underline);
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
IObject3D underline = CubeObject3D.Create(basePlate.XSize(), .2, 1);
underline = new AlignObject3D(underline, FaceAlign.Bottom, brailleLetter, FaceAlign.Top);
underline = new AlignObject3D(underline, FaceAlign.Back | FaceAlign.Left, basePlate, FaceAlign.Front | FaceAlign.Left, 0, .01);
this.Children.Add(underline);
}
}

View file

@ -101,169 +101,164 @@ namespace MatterHackers.MatterControl.DesignTools
{
using (RebuildLock())
{
var aabb = this.GetAxisAlignedBoundingBox();
this.Children.Modify(list =>
using (new CenterAndHeightMantainer(this))
{
this.Children.Modify(list =>
{
list.Clear();
});
var brailleText = TextToEncode;
if (UseGrade2)
{
brailleText = BrailleGrade2.ConvertString(brailleText);
}
var brailleText = TextToEncode;
if (UseGrade2)
{
brailleText = BrailleGrade2.ConvertString(brailleText);
}
double pointSize = 18.5;
double pointsToMm = 0.352778;
IObject3D textObject = new Object3D();
var offest = 0.0;
double pointSize = 18.5;
double pointsToMm = 0.352778;
IObject3D textObject = new Object3D();
var offest = 0.0;
TypeFacePrinter textPrinter;
if (RenderAsBraille)
{
textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(typeFace, pointSize));
}
else
{
textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize));
}
foreach (var letter in brailleText.ToCharArray())
{
IObject3D letterObject;
TypeFacePrinter letterPrinter;
TypeFacePrinter textPrinter;
if (RenderAsBraille)
{
letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(typeFace, pointSize));
var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
// add all the spheres to letterObject
letterObject = new Object3D();
var vertexCount = 0;
var positionSum = Vector2.Zero;
var lastPosition = Vector2.Zero;
// find each dot outline and get it's center and place a sphere there
foreach (var vertex in scalledLetterPrinter.Vertices())
{
switch (vertex.command)
{
case Agg.ShapePath.FlagsAndCommand.Stop:
case Agg.ShapePath.FlagsAndCommand.EndPoly:
case Agg.ShapePath.FlagsAndCommand.FlagClose:
case Agg.ShapePath.FlagsAndCommand.MoveTo:
if (vertexCount > 0)
{
var center = positionSum / vertexCount;
double radius = 1.44 / 2;// (center - lastPosition).Length;
var sphere = new HalfSphereObject3D(radius * 2, 15)
{
Color = Color.LightBlue
};
sphere.Translate(center.X, center.Y);
letterObject.Children.Add(sphere);
}
vertexCount = 0;
positionSum = Vector2.Zero;
break;
case Agg.ShapePath.FlagsAndCommand.Curve3:
case Agg.ShapePath.FlagsAndCommand.Curve4:
case Agg.ShapePath.FlagsAndCommand.LineTo:
vertexCount++;
lastPosition = vertex.position;
positionSum += lastPosition;
break;
}
}
textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(typeFace, pointSize));
}
else
{
letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize));
var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
letterObject = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, 1),
Color = Color.LightBlue
};
textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize));
}
letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0);
textObject.Children.Add(letterObject);
offest += letterPrinter.GetSize(letter.ToString()).X * pointsToMm;
}
// add a plate under the dots
var padding = .9 * pointSize * pointsToMm / 2;
var size = textPrinter.LocalBounds * pointsToMm;
// make the base
var basePath = new VertexStorage();
basePath.MoveTo(0, 0);
basePath.LineTo(size.Width + padding, 0);
basePath.LineTo(size.Width + padding, size.Height + padding);
basePath.LineTo(padding, size.Height + padding);
basePath.LineTo(0, size.Height);
IObject3D basePlate = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(basePath, BaseHeight)
};
basePlate = new AlignObject3D(basePlate, FaceAlign.Top, textObject, FaceAlign.Bottom, 0, 0, .01);
basePlate = new AlignObject3D(basePlate, FaceAlign.Left | FaceAlign.Front,
size.Left - padding / 2,
size.Bottom - padding / 2);
this.Children.Add(basePlate);
basePlate.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4);
// add an optional chain hook
if (AddHook)
{
// x 10 to make it smoother
double edgeWidth = 3;
double height = basePlate.ZSize();
IVertexSource leftSideObject = new RoundedRect(0, 0, height / 2, height, 0)
foreach (var letter in brailleText.ToCharArray())
{
ResolutionScale = 10
IObject3D letterObject;
TypeFacePrinter letterPrinter;
if (RenderAsBraille)
{
letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(typeFace, pointSize));
var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
// add all the spheres to letterObject
letterObject = new Object3D();
var vertexCount = 0;
var positionSum = Vector2.Zero;
var lastPosition = Vector2.Zero;
// find each dot outline and get it's center and place a sphere there
foreach (var vertex in scalledLetterPrinter.Vertices())
{
switch (vertex.command)
{
case Agg.ShapePath.FlagsAndCommand.Stop:
case Agg.ShapePath.FlagsAndCommand.EndPoly:
case Agg.ShapePath.FlagsAndCommand.FlagClose:
case Agg.ShapePath.FlagsAndCommand.MoveTo:
if (vertexCount > 0)
{
var center = positionSum / vertexCount;
double radius = 1.44 / 2;// (center - lastPosition).Length;
var sphere = new HalfSphereObject3D(radius * 2, 15)
{
Color = Color.LightBlue
};
sphere.Translate(center.X, center.Y);
letterObject.Children.Add(sphere);
}
vertexCount = 0;
positionSum = Vector2.Zero;
break;
case Agg.ShapePath.FlagsAndCommand.Curve3:
case Agg.ShapePath.FlagsAndCommand.Curve4:
case Agg.ShapePath.FlagsAndCommand.LineTo:
vertexCount++;
lastPosition = vertex.position;
positionSum += lastPosition;
break;
}
}
}
else
{
letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize));
var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
letterObject = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, 1),
Color = Color.LightBlue
};
}
letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0);
textObject.Children.Add(letterObject);
offest += letterPrinter.GetSize(letter.ToString()).X * pointsToMm;
}
// add a plate under the dots
var padding = .9 * pointSize * pointsToMm / 2;
var size = textPrinter.LocalBounds * pointsToMm;
// make the base
var basePath = new VertexStorage();
basePath.MoveTo(0, 0);
basePath.LineTo(size.Width + padding, 0);
basePath.LineTo(size.Width + padding, size.Height + padding);
basePath.LineTo(padding, size.Height + padding);
basePath.LineTo(0, size.Height);
IObject3D basePlate = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(basePath, BaseHeight)
};
IVertexSource cicleObject = new Ellipse(0, 0, height / 2, height / 2)
basePlate = new AlignObject3D(basePlate, FaceAlign.Top, textObject, FaceAlign.Bottom, 0, 0, .01);
basePlate = new AlignObject3D(basePlate, FaceAlign.Left | FaceAlign.Front,
size.Left - padding / 2,
size.Bottom - padding / 2);
this.Children.Add(basePlate);
basePlate.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4);
// add an optional chain hook
if (AddHook)
{
ResolutionScale = 10
};
// x 10 to make it smoother
double edgeWidth = 3;
double height = basePlate.ZSize();
IVertexSource leftSideObject = new RoundedRect(0, 0, height / 2, height, 0)
{
ResolutionScale = 10
};
cicleObject = new Align2D(cicleObject, Side2D.Left | Side2D.Bottom, leftSideObject, Side2D.Left | Side2D.Bottom, -.01);
IVertexSource holeObject = new Ellipse(0, 0, height / 2 - edgeWidth, height / 2 - edgeWidth)
{
ResolutionScale = 10
};
holeObject = new SetCenter2D(holeObject, cicleObject.GetBounds().Center);
IVertexSource cicleObject = new Ellipse(0, 0, height / 2, height / 2)
{
ResolutionScale = 10
};
IVertexSource hookPath = leftSideObject.Plus(cicleObject);
hookPath = hookPath.Minus(holeObject);
cicleObject = new Align2D(cicleObject, Side2D.Left | Side2D.Bottom, leftSideObject, Side2D.Left | Side2D.Bottom, -.01);
IVertexSource holeObject = new Ellipse(0, 0, height / 2 - edgeWidth, height / 2 - edgeWidth)
{
ResolutionScale = 10
};
holeObject = new SetCenter2D(holeObject, cicleObject.GetBounds().Center);
IObject3D chainHook = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(hookPath, BaseHeight),
Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
};
IVertexSource hookPath = leftSideObject.Plus(cicleObject);
hookPath = hookPath.Minus(holeObject);
chainHook = new AlignObject3D(chainHook, FaceAlign.Left | FaceAlign.Bottom | FaceAlign.Back, basePlate, FaceAlign.Right | FaceAlign.Bottom | FaceAlign.Back, -.01);
IObject3D chainHook = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(hookPath, BaseHeight),
Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
};
this.Children.Add(chainHook);
}
chainHook = new AlignObject3D(chainHook, FaceAlign.Left | FaceAlign.Bottom | FaceAlign.Back, basePlate, FaceAlign.Right | FaceAlign.Bottom | FaceAlign.Back, -.01);
// add the object that is the dots
this.Children.Add(textObject);
textObject.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4);
this.Children.Add(chainHook);
}
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
// add the object that is the dots
this.Children.Add(textObject);
textObject.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4);
}
}

View file

@ -169,14 +169,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
this.DebugDepth("Rebuild");
using (RebuildLock())
{
var aabb = this.GetAxisAlignedBoundingBox();
AdjustChildSize(null, null);
if (aabb.ZSize > 0)
using (new CenterAndHeightMantainer(this))
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
AdjustChildSize(null, null);
}
}

View file

@ -80,20 +80,16 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
using (RebuildLock())
{
var startingAabb = this.GetAxisAlignedBoundingBox();
// remove whatever rotation has been applied (they go in reverse order)
Matrix = Matrix4X4.Identity;
// add the current rotation
Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationX(MathHelper.DegreesToRadians(RotationXDegrees)));
Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationY(MathHelper.DegreesToRadians(RotationYDegrees)));
Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(RotationZDegrees)));
if (startingAabb.ZSize > 0)
using (new CenterAndHeightMantainer(this))
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, startingAabb.MinXYZ.Z);
var startingAabb = this.GetAxisAlignedBoundingBox();
// remove whatever rotation has been applied (they go in reverse order)
Matrix = Matrix4X4.Identity;
// add the current rotation
Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationX(MathHelper.DegreesToRadians(RotationXDegrees)));
Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationY(MathHelper.DegreesToRadians(RotationYDegrees)));
Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(RotationZDegrees)));
}
}

View file

@ -62,26 +62,28 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
{
this.DebugDepth("Rebuild");
var newChildren = new List<IObject3D>();
newChildren.Add(SourceContainer);
var arrayItem = SourceContainer.Children.First();
// add in all the array items
for (int i = 0; i < Math.Max(Count, 1); i++)
using (new CenterAndHeightMantainer(this))
{
var next = arrayItem.Clone();
next.Matrix = arrayItem.Matrix * Matrix4X4.CreateTranslation(Direction.Normal.GetNormal() * Distance * i);
newChildren.Add(next);
var newChildren = new List<IObject3D>();
newChildren.Add(SourceContainer);
var arrayItem = SourceContainer.Children.First();
// add in all the array items
for (int i = 0; i < Math.Max(Count, 1); i++)
{
var next = arrayItem.Clone();
next.Matrix = arrayItem.Matrix * Matrix4X4.CreateTranslation(Direction.Normal.GetNormal() * Distance * i);
newChildren.Add(next);
}
Children.Modify(list =>
{
list.Clear();
list.AddRange(newChildren);
});
}
Children.Modify(list =>
{
list.Clear();
list.AddRange(newChildren);
});
SourceContainer.Visible = false;
rebuildLock.Dispose();
Invalidate(InvalidateType.Children);

View file

@ -98,6 +98,8 @@ namespace MatterHackers.MatterControl.DesignTools
propertyUpdated = true;
}
var originalAabb = this.GetAxisAlignedBoundingBox();
var rebuildLocks = this.RebuilLockAll();
return ApplicationController.Instance.Tasks.Execute(
@ -105,84 +107,87 @@ namespace MatterHackers.MatterControl.DesignTools
null,
(reporter, cancellationToken) =>
{
this.Translate(-rotationOffset);
SourceContainer.Visible = true;
RemoveAllButSource();
// remember the current matrix then clear it so the parts will rotate at the original wrapped position
var currentMatrix = Matrix;
Matrix = Matrix4X4.Identity;
var aabb = SourceContainer.GetAxisAlignedBoundingBox();
if (Diameter == double.MinValue)
using (new CenterAndHeightMantainer(this))
{
// uninitialized set to a reasonable value
Diameter = (int)aabb.XSize;
// TODO: ensure that the editor display value is updated
}
this.Translate(-rotationOffset);
SourceContainer.Visible = true;
RemoveAllButSource();
if (Diameter > 0)
{
var radius = Diameter / 2;
var circumference = MathHelper.Tau * radius;
var rotationCenter = new Vector3(aabb.MinXYZ.X + (aabb.MaxXYZ.X - aabb.MinXYZ.X) * (StartPercent / 100), aabb.MaxXYZ.Y + radius, aabb.Center.Z);
// remember the current matrix then clear it so the parts will rotate at the original wrapped position
var currentMatrix = Matrix;
Matrix = Matrix4X4.Identity;
rotationOffset = rotationCenter;
if (!BendCcw)
var aabb = this.GetAxisAlignedBoundingBox();
if (Diameter == double.MinValue)
{
// fix the stored center so we draw correctly
rotationOffset.Y = aabb.MinXYZ.Y - radius;
// uninitialized set to a reasonable value
Diameter = (int)aabb.XSize;
// TODO: ensure that the editor display value is updated
}
foreach (var sourceItem in SourceContainer.VisibleMeshes())
if (Diameter > 0)
{
var originalMesh = sourceItem.Mesh;
var transformedMesh = originalMesh.Copy(CancellationToken.None);
var itemMatrix = sourceItem.WorldMatrix(SourceContainer);
var radius = Diameter / 2;
var circumference = MathHelper.Tau * radius;
var rotationCenter = new Vector3(aabb.MinXYZ.X + (aabb.MaxXYZ.X - aabb.MinXYZ.X) * (StartPercent / 100), aabb.MaxXYZ.Y + radius, aabb.Center.Z);
rotationOffset = rotationCenter;
if (!BendCcw)
{
// rotate around so it will bend correctly
itemMatrix *= Matrix4X4.CreateTranslation(0, -aabb.MaxXYZ.Y, 0);
itemMatrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 2);
itemMatrix *= Matrix4X4.CreateTranslation(0, aabb.MaxXYZ.Y - aabb.YSize, 0);
// fix the stored center so we draw correctly
rotationOffset.Y = aabb.MinXYZ.Y - radius;
}
var invItemMatrix = itemMatrix.Inverted;
for (int i = 0; i < transformedMesh.Vertices.Count; i++)
foreach (var sourceItem in SourceContainer.VisibleMeshes())
{
var worldPosition = transformedMesh.Vertices[i].Transform((Matrix4X4)itemMatrix);
var originalMesh = sourceItem.Mesh;
var transformedMesh = originalMesh.Copy(CancellationToken.None);
var itemMatrix = sourceItem.WorldMatrix(SourceContainer);
var angleToRotate = ((worldPosition.X - rotationCenter.X) / circumference) * MathHelper.Tau - MathHelper.Tau / 4;
var distanceFromCenter = rotationCenter.Y - worldPosition.Y;
if (!BendCcw)
{
// rotate around so it will bend correctly
itemMatrix *= Matrix4X4.CreateTranslation(0, -aabb.MaxXYZ.Y, 0);
itemMatrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 2);
itemMatrix *= Matrix4X4.CreateTranslation(0, aabb.MaxXYZ.Y - aabb.YSize, 0);
}
var rotatePosition = new Vector3Float(Math.Cos(angleToRotate), Math.Sin(angleToRotate), 0) * distanceFromCenter;
rotatePosition.Z = worldPosition.Z;
var worldWithBend = rotatePosition + new Vector3Float(rotationCenter.X, radius + aabb.MaxXYZ.Y, 0);
var invItemMatrix = itemMatrix.Inverted;
transformedMesh.Vertices[i] = worldWithBend.Transform(invItemMatrix) - new Vector3Float(rotationOffset);
for (int i = 0; i < transformedMesh.Vertices.Count; i++)
{
var worldPosition = transformedMesh.Vertices[i].Transform((Matrix4X4)itemMatrix);
var angleToRotate = ((worldPosition.X - rotationCenter.X) / circumference) * MathHelper.Tau - MathHelper.Tau / 4;
var distanceFromCenter = rotationCenter.Y - worldPosition.Y;
var rotatePosition = new Vector3Float(Math.Cos(angleToRotate), Math.Sin(angleToRotate), 0) * distanceFromCenter;
rotatePosition.Z = worldPosition.Z;
var worldWithBend = rotatePosition + new Vector3Float(rotationCenter.X, radius + aabb.MaxXYZ.Y, 0);
transformedMesh.Vertices[i] = worldWithBend.Transform(invItemMatrix) - new Vector3Float(rotationOffset);
}
transformedMesh.MarkAsChanged();
transformedMesh.CalculateNormals();
var newMesh = new Object3D()
{
Mesh = transformedMesh
};
newMesh.CopyWorldProperties(sourceItem, this, Object3DPropertyFlags.All);
this.Children.Add(newMesh);
}
transformedMesh.MarkAsChanged();
transformedMesh.CalculateNormals();
var newMesh = new Object3D()
{
Mesh = transformedMesh
};
newMesh.CopyWorldProperties(sourceItem, this, Object3DPropertyFlags.All);
this.Children.Add(newMesh);
// set the matrix back
Matrix = currentMatrix;
this.Translate(new Vector3(rotationOffset));
SourceContainer.Visible = false;
rebuildLocks.Dispose();
}
Invalidate(InvalidateType.Children);
}
// set the matrix back
Matrix = currentMatrix;
this.Translate(new Vector3(rotationOffset));
SourceContainer.Visible = false;
rebuildLocks.Dispose();
Invalidate(InvalidateType.Children);
return Task.CompletedTask;
});
}

View file

@ -65,29 +65,28 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
var fitToBounds = new FitToBoundsObject3D_2();
using (fitToBounds.RebuildLock())
{
var aabb = itemToFit.GetAxisAlignedBoundingBox();
var bounds = new Object3D()
using (new CenterAndHeightMantainer(fitToBounds))
{
Visible = false,
Color = new Color(Color.Red, 100),
Mesh = PlatonicSolids.CreateCube()
};
var aabb = fitToBounds.GetAxisAlignedBoundingBox();
var bounds = new Object3D()
{
Visible = false,
Color = new Color(Color.Red, 100),
Mesh = PlatonicSolids.CreateCube()
};
// add all the children
var scaleItem = new Object3D();
fitToBounds.Children.Add(scaleItem);
scaleItem.Children.Add(itemToFit);
fitToBounds.Children.Add(bounds);
// add all the children
var scaleItem = new Object3D();
fitToBounds.Children.Add(scaleItem);
scaleItem.Children.Add(itemToFit);
fitToBounds.Children.Add(bounds);
fitToBounds.boundsSize.X = aabb.XSize;
fitToBounds.boundsSize.Y = aabb.YSize;
fitToBounds.boundsSize.Z = aabb.ZSize;
fitToBounds.Rebuild();
fitToBounds.boundsSize.X = aabb.XSize;
fitToBounds.boundsSize.Y = aabb.YSize;
fitToBounds.boundsSize.Z = aabb.ZSize;
fitToBounds.Rebuild();
var newAabbb = fitToBounds.GetAxisAlignedBoundingBox();
fitToBounds.Translate(aabb.Center - newAabbb.Center);
PlatingHelper.PlaceMeshAtHeight(fitToBounds, aabb.MinXYZ.Z);
}
}
return fitToBounds;
@ -171,23 +170,14 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
this.DebugDepth("Rebuild");
using (RebuildLock())
{
var aabb = this.GetAxisAlignedBoundingBox();
AdjustChildSize(null, null);
UpdateBoundsItem();
cacheRequestedMatrix = new Matrix4X4();
var after = this.GetAxisAlignedBoundingBox();
var newAabbb = this.GetAxisAlignedBoundingBox();
this.Translate(aabb.Center - newAabbb.Center);
if (aabb.ZSize > 0)
using (new CenterAndHeightMantainer(this))
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
AdjustChildSize(null, null);
UpdateBoundsItem();
cacheRequestedMatrix = new Matrix4X4();
var after = this.GetAxisAlignedBoundingBox();
}
}

View file

@ -38,6 +38,7 @@ using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters2D;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
@ -67,22 +68,17 @@ namespace MatterHackers.MatterControl.DesignTools
{
using (RebuildLock())
{
var startingAabb = this.GetAxisAlignedBoundingBox();
var firstChild = this.Children.FirstOrDefault();
// only keep the first object
this.Children.Modify(list =>
using (new CenterAndHeightMantainer(this))
{
list.Clear();
// add back in the sourceContainer
list.Add(firstChild);
});
var firstChild = this.Children.FirstOrDefault();
if (startingAabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, startingAabb.MinXYZ.Z);
// only keep the first object
this.Children.Modify(list =>
{
list.Clear();
// add back in the sourceContainer
list.Add(firstChild);
});
}
}
@ -145,29 +141,24 @@ namespace MatterHackers.MatterControl.DesignTools
null,
(reporter, cancellationToken) =>
{
var startingAabb = this.GetAxisAlignedBoundingBox();
var firstChild = this.Children.FirstOrDefault();
// remove the base mesh we added
this.Children.Modify(list =>
using (new CenterAndHeightMantainer(this))
{
list.Clear();
var firstChild = this.Children.FirstOrDefault();
// remove the base mesh we added
this.Children.Modify(list =>
{
list.Clear();
// add back in the sourceContainer
list.Add(firstChild);
});
});
// and create the base
var vertexSource = this.VertexSource;
// and create the base
var vertexSource = this.VertexSource;
// Convert VertexSource into expected Polygons
Polygons polygonShape = (vertexSource == null) ? null : vertexSource.CreatePolygons();
GenerateBase(polygonShape, firstChild.GetAxisAlignedBoundingBox().MinXYZ.Z);
if (startingAabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, startingAabb.MinXYZ.Z);
// Convert VertexSource into expected Polygons
Polygons polygonShape = (vertexSource == null) ? null : vertexSource.CreatePolygons();
GenerateBase(polygonShape, firstChild.GetAxisAlignedBoundingBox().MinXYZ.Z);
}
rebuildLock.Dispose();
Invalidate(InvalidateType.Children);

View file

@ -36,6 +36,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
@ -87,18 +88,15 @@ namespace MatterHackers.MatterControl.DesignTools
(reporter, cancellationToken) =>
{
Sides = agg_basics.Clamp(Sides, 3, 360, ref changed);
var aabb = this.GetAxisAlignedBoundingBox();
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Diameter / 2, 0);
path.LineTo(0, Height);
Mesh = VertexSourceToMesh.Revolve(path, Sides);
if (aabb.ZSize > 0)
using (new CenterAndHeightMantainer(this))
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Diameter / 2, 0);
path.LineTo(0, Height);
Mesh = VertexSourceToMesh.Revolve(path, Sides);
}
rebuildLock.Dispose();
Invalidate(InvalidateType.Children);

View file

@ -32,6 +32,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.PolygonMesh;
namespace MatterHackers.MatterControl.DesignTools
@ -84,14 +85,9 @@ namespace MatterHackers.MatterControl.DesignTools
this.DebugDepth("Rebuild");
using (RebuildLock())
{
var aabb = this.GetAxisAlignedBoundingBox();
Mesh = PlatonicSolids.CreateCube(Width, Depth, Height);
if (aabb.ZSize > 0)
using (new CenterAndHeightMantainer(this))
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
Mesh = PlatonicSolids.CreateCube(Width, Depth, Height);
}
}

View file

@ -143,33 +143,28 @@ namespace MatterHackers.MatterControl.DesignTools
Height = Math.Max(Height, .001);
Diameter = Math.Max(Diameter, .1);
var aabb = this.GetAxisAlignedBoundingBox();
if (!Advanced)
using (new CenterAndHeightMantainer(this))
{
var path = new VertexStorage();
path.MoveTo(0, -Height / 2);
path.LineTo(Diameter / 2, -Height / 2);
path.LineTo(Diameter / 2, Height / 2);
path.LineTo(0, Height / 2);
if (!Advanced)
{
var path = new VertexStorage();
path.MoveTo(0, -Height / 2);
path.LineTo(Diameter / 2, -Height / 2);
path.LineTo(Diameter / 2, Height / 2);
path.LineTo(0, Height / 2);
Mesh = VertexSourceToMesh.Revolve(path, Sides);
}
else
{
var path = new VertexStorage();
path.MoveTo(0, -Height / 2);
path.LineTo(Diameter / 2, -Height / 2);
path.LineTo(DiameterTop / 2, Height / 2);
path.LineTo(0, Height / 2);
Mesh = VertexSourceToMesh.Revolve(path, Sides);
}
else
{
var path = new VertexStorage();
path.MoveTo(0, -Height / 2);
path.LineTo(Diameter / 2, -Height / 2);
path.LineTo(DiameterTop / 2, Height / 2);
path.LineTo(0, Height / 2);
Mesh = VertexSourceToMesh.Revolve(path, Sides, MathHelper.DegreesToRadians(StartingAngle), MathHelper.DegreesToRadians(EndingAngle));
}
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
Mesh = VertexSourceToMesh.Revolve(path, Sides, MathHelper.DegreesToRadians(StartingAngle), MathHelper.DegreesToRadians(EndingAngle));
}
}
}

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -78,25 +79,20 @@ namespace MatterHackers.MatterControl.DesignTools
using (RebuildLock())
{
Sides = agg_basics.Clamp(Sides, 3, 180, ref changed);
var aabb = this.GetAxisAlignedBoundingBox();
var path = new VertexStorage();
path.MoveTo(Width / 2, 0);
for (int i = 1; i < Sides; i++)
using (new CenterAndHeightMantainer(this))
{
var angle = MathHelper.Tau * i / 2 / (Sides - 1);
path.LineTo(Math.Cos(angle) * Width / 2, Math.Sin(angle) * Width / 2);
}
var path = new VertexStorage();
path.MoveTo(Width / 2, 0);
var mesh = VertexSourceToMesh.Extrude(path, Depth);
mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
Mesh = mesh;
for (int i = 1; i < Sides; i++)
{
var angle = MathHelper.Tau * i / 2 / (Sides - 1);
path.LineTo(Math.Cos(angle) * Width / 2, Math.Sin(angle) * Width / 2);
}
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
var mesh = VertexSourceToMesh.Extrude(path, Depth);
mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
Mesh = mesh;
}
}

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -88,25 +89,21 @@ namespace MatterHackers.MatterControl.DesignTools
LatitudeSides = agg_basics.Clamp(LatitudeSides, 3, 180, ref changed);
LongitudeSides = agg_basics.Clamp(LongitudeSides, 3, 360, ref changed);
var aabb = this.GetAxisAlignedBoundingBox();
var radius = Diameter / 2;
var angleDelta = MathHelper.Tau / 4 / LatitudeSides;
var angle = 0.0;
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
for (int i = 0; i < LatitudeSides; i++)
using (new CenterAndHeightMantainer(this))
{
angle += angleDelta;
var radius = Diameter / 2;
var angleDelta = MathHelper.Tau / 4 / LatitudeSides;
var angle = 0.0;
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
}
for (int i = 0; i < LatitudeSides; i++)
{
angle += angleDelta;
path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
}
Mesh = VertexSourceToMesh.Revolve(path, LongitudeSides);
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
Mesh = VertexSourceToMesh.Revolve(path, LongitudeSides);
}
}

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -76,20 +77,16 @@ namespace MatterHackers.MatterControl.DesignTools
this.DebugDepth("Rebuild");
using (RebuildLock())
{
var aabb = this.GetAxisAlignedBoundingBox();
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Width, 0);
path.LineTo(Width / 2, Height);
var mesh = VertexSourceToMesh.Extrude(path, Depth);
mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
Mesh = mesh;
if (aabb.ZSize > 0)
using (new CenterAndHeightMantainer(this))
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Width, 0);
path.LineTo(Width / 2, Height);
var mesh = VertexSourceToMesh.Extrude(path, Depth);
mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
Mesh = mesh;
}
}

View file

@ -28,11 +28,11 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -75,21 +75,16 @@ namespace MatterHackers.MatterControl.DesignTools
this.DebugDepth("Rebuild");
using (RebuildLock())
{
var aabb = this.GetAxisAlignedBoundingBox();
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Math.Sqrt(2), 0);
path.LineTo(0, Height);
var mesh = VertexSourceToMesh.Revolve(path, 4);
mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width / 2, Depth / 2, 1));
Mesh = mesh;
if (aabb.ZSize > 0)
using (new CenterAndHeightMantainer(this))
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Math.Sqrt(2), 0);
path.LineTo(0, Height);
var mesh = VertexSourceToMesh.Revolve(path, 4);
mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width / 2, Depth / 2, 1));
Mesh = mesh;
}
}

View file

@ -35,6 +35,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
@ -98,33 +99,28 @@ namespace MatterHackers.MatterControl.DesignTools
InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref changed);
Sides = agg_basics.Clamp(Sides, 3, 360, ref changed);
var aabb = this.GetAxisAlignedBoundingBox();
var startingAngle = StartingAngle;
var endingAngle = EndingAngle;
if (!Advanced)
using (new CenterAndHeightMantainer(this))
{
startingAngle = 0;
endingAngle = 360;
}
var startingAngle = StartingAngle;
var endingAngle = EndingAngle;
if (!Advanced)
{
startingAngle = 0;
endingAngle = 360;
}
var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);
var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);
var path = new VertexStorage();
path.MoveTo(OuterDiameter / 2, -Height / 2);
path.LineTo(OuterDiameter / 2, Height / 2);
path.LineTo(innerDiameter / 2, Height / 2);
path.LineTo(innerDiameter / 2, -Height / 2);
path.LineTo(OuterDiameter / 2, -Height / 2);
var path = new VertexStorage();
path.MoveTo(OuterDiameter / 2, -Height / 2);
path.LineTo(OuterDiameter / 2, Height / 2);
path.LineTo(innerDiameter / 2, Height / 2);
path.LineTo(innerDiameter / 2, -Height / 2);
path.LineTo(OuterDiameter / 2, -Height / 2);
var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);
}
}

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -93,40 +94,36 @@ namespace MatterHackers.MatterControl.DesignTools
Sides = agg_basics.Clamp(Sides, 3, 360, ref changed);
LatitudeSides = agg_basics.Clamp(LatitudeSides, 3, 360, ref changed);
var aabb = this.GetAxisAlignedBoundingBox();
var startingAngle = StartingAngle;
var endingAngle = EndingAngle;
var latitudeSides = LatitudeSides;
if (!Advanced)
using (new CenterAndHeightMantainer(this))
{
startingAngle = 0;
endingAngle = 360;
latitudeSides = Sides;
}
var startingAngle = StartingAngle;
var endingAngle = EndingAngle;
var latitudeSides = LatitudeSides;
if (!Advanced)
{
startingAngle = 0;
endingAngle = 360;
latitudeSides = Sides;
}
var path = new VertexStorage();
var angleDelta = MathHelper.Tau / 2 / latitudeSides;
var angle = -MathHelper.Tau / 4;
var radius = Diameter / 2;
path.MoveTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
for (int i = 0; i < latitudeSides; i++)
{
angle += angleDelta;
path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
}
var path = new VertexStorage();
var angleDelta = MathHelper.Tau / 2 / latitudeSides;
var angle = -MathHelper.Tau / 4;
var radius = Diameter / 2;
path.MoveTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
for (int i = 0; i < latitudeSides; i++)
{
angle += angleDelta;
path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
}
var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
var steps = Math.Max(1, (int)(Sides * MathHelper.Tau / Math.Abs(MathHelper.GetDeltaAngle(startAngle, endAngle)) + .5));
Mesh = VertexSourceToMesh.Revolve(path,
steps,
startAngle,
endAngle);
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
var steps = Math.Max(1, (int)(Sides * MathHelper.Tau / Math.Abs(MathHelper.GetDeltaAngle(startAngle, endAngle)) + .5));
Mesh = VertexSourceToMesh.Revolve(path,
steps,
startAngle,
endAngle);
}
}

View file

@ -121,37 +121,32 @@ namespace MatterHackers.MatterControl.DesignTools
null,
(reporter, cancellationToken) =>
{
var aabb = (this).GetAxisAlignedBoundingBox();
this.Children.Modify((List<IObject3D> list) =>
using (new CenterAndHeightMantainer(this))
{
list.Clear();
var offest = 0.0;
double pointsToMm = 0.352778;
foreach (var letter in NameToWrite.ToCharArray())
this.Children.Modify((List<IObject3D> list) =>
{
var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), PointSize))
list.Clear();
var offest = 0.0;
double pointsToMm = 0.352778;
foreach (var letter in NameToWrite.ToCharArray())
{
ResolutionScale = 10
};
var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
IObject3D letterObject = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, Height)
};
var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), PointSize))
{
ResolutionScale = 10
};
var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
IObject3D letterObject = new Object3D()
{
Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, Height)
};
letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0);
list.Add(letterObject);
letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0);
list.Add(letterObject);
offest += letterPrinter.GetSize(letter.ToString()).X * pointsToMm;
}
});
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, (double)aabb.MinXYZ.Z);
offest += letterPrinter.GetSize(letter.ToString()).X * pointsToMm;
}
});
}
rebuildLock.Dispose();

View file

@ -33,6 +33,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
@ -99,32 +100,27 @@ namespace MatterHackers.MatterControl.DesignTools
var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);
var aabb = this.GetAxisAlignedBoundingBox();
var poleRadius = (OuterDiameter / 2 - innerDiameter / 2) / 2;
var toroidRadius = innerDiameter / 2 + poleRadius;
var path = new VertexStorage();
var angleDelta = MathHelper.Tau / ringSides;
var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle);
var ringAngle = ringStartAngle;
var circleCenter = new Vector2(toroidRadius, 0);
path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
for (int i = 0; i < ringSides - 1; i++)
using (new CenterAndHeightMantainer(this))
{
ringAngle += angleDelta;
path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle)));
}
var poleRadius = (OuterDiameter / 2 - innerDiameter / 2) / 2;
var toroidRadius = innerDiameter / 2 + poleRadius;
var path = new VertexStorage();
var angleDelta = MathHelper.Tau / ringSides;
var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle);
var ringAngle = ringStartAngle;
var circleCenter = new Vector2(toroidRadius, 0);
path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
for (int i = 0; i < ringSides - 1; i++)
{
ringAngle += angleDelta;
path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle)));
}
path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);
if (aabb.ZSize > 0)
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);
}
}

View file

@ -77,19 +77,15 @@ namespace MatterHackers.MatterControl.DesignTools
this.DebugDepth("Rebuild");
using (RebuildLock())
{
var aabb = this.GetAxisAlignedBoundingBox();
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Width, 0);
path.LineTo(0, Height);
Mesh = VertexSourceToMesh.Extrude(path, Depth);
Mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
if (aabb.ZSize > 0)
using (new CenterAndHeightMantainer(this))
{
// If the part was already created and at a height, maintain the height.
PlatingHelper.PlaceMeshAtHeight(this, aabb.MinXYZ.Z);
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Width, 0);
path.LineTo(0, Height);
Mesh = VertexSourceToMesh.Extrude(path, Depth);
Mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
}
}

View file

@ -130,16 +130,6 @@ namespace MatterHackers.MatterControl
object3D.Matrix *= Matrix4X4.CreateTranslation(new Vector3(0, 0, -boundsCenter.Z + bounds.ZSize / 2));
}
public static void PlaceMeshAtHeight(IObject3D objectToMove, double zHeight)
{
AxisAlignedBoundingBox bounds = objectToMove.GetAxisAlignedBoundingBox(Matrix4X4.Identity);
if (bounds.MinXYZ.Z != zHeight)
{
objectToMove.Matrix *= Matrix4X4.CreateTranslation(new Vector3(0, 0, zHeight - bounds.MinXYZ.Z));
}
}
/// <summary>
/// Moves the target object to the first non-colliding position, starting from the lower left corner of the bounding box containing all sceneItems
/// </summary>

@ -1 +1 @@
Subproject commit 5a963571ccee4e6ab689ccef63d47499011cdb49
Subproject commit 58d618cc59147699b3cc17684931416481aa2362