Get fit to recalculate bounds correctly
This commit is contained in:
parent
68ea61be45
commit
04d4f0f837
1 changed files with 50 additions and 40 deletions
|
|
@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
|
|
||||||
private Vector3 cacheBounds;
|
private Vector3 cacheBounds;
|
||||||
|
|
||||||
private Matrix4X4 cacheParentMatrix;
|
private Matrix4X4 cacheRequestedMatrix = new Matrix4X4();
|
||||||
private Matrix4X4 cacheThisMatrix;
|
private Matrix4X4 cacheThisMatrix;
|
||||||
|
|
||||||
public FitToBoundsObject3D_2()
|
public FitToBoundsObject3D_2()
|
||||||
|
|
@ -111,7 +111,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
{
|
{
|
||||||
if (Children.Count == 2)
|
if (Children.Count == 2)
|
||||||
{
|
{
|
||||||
if (cacheParentMatrix != matrix
|
if (cacheRequestedMatrix != matrix
|
||||||
|| cacheThisMatrix != Matrix
|
|| cacheThisMatrix != Matrix
|
||||||
|| cacheBounds != boundsSize)
|
|| cacheBounds != boundsSize)
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +121,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
cacheAabb = base.GetAxisAlignedBoundingBox(matrix);
|
cacheAabb = base.GetAxisAlignedBoundingBox(matrix);
|
||||||
FitBounds.Visible = false;
|
FitBounds.Visible = false;
|
||||||
}
|
}
|
||||||
cacheParentMatrix = matrix;
|
cacheRequestedMatrix = matrix;
|
||||||
cacheThisMatrix = Matrix;
|
cacheThisMatrix = Matrix;
|
||||||
cacheBounds = boundsSize;
|
cacheBounds = boundsSize;
|
||||||
}
|
}
|
||||||
|
|
@ -147,9 +147,13 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
{
|
{
|
||||||
Rebuild(null);
|
Rebuild(null);
|
||||||
}
|
}
|
||||||
else if(invalidateType.InvalidateType == InvalidateType.Matrix)
|
else if ((invalidateType.InvalidateType == InvalidateType.Properties
|
||||||
|
|| invalidateType.InvalidateType == InvalidateType.Matrix
|
||||||
|
|| invalidateType.InvalidateType == InvalidateType.Mesh
|
||||||
|
|| invalidateType.InvalidateType == InvalidateType.Content))
|
||||||
{
|
{
|
||||||
cacheThisMatrix = Matrix4X4.Identity;
|
cacheThisMatrix = Matrix4X4.Identity;
|
||||||
|
base.OnInvalidate(invalidateType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -162,12 +166,15 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
this.DebugDepth("Rebuild");
|
this.DebugDepth("Rebuild");
|
||||||
using (RebuildLock())
|
using (RebuildLock())
|
||||||
{
|
{
|
||||||
UpdateBoundsItem();
|
|
||||||
|
|
||||||
var aabb = this.GetAxisAlignedBoundingBox();
|
var aabb = this.GetAxisAlignedBoundingBox();
|
||||||
|
|
||||||
AdjustChildSize(null, null);
|
AdjustChildSize(null, null);
|
||||||
|
|
||||||
|
UpdateBoundsItem();
|
||||||
|
|
||||||
|
cacheRequestedMatrix = new Matrix4X4();
|
||||||
|
var after = this.GetAxisAlignedBoundingBox();
|
||||||
|
|
||||||
if (aabb.ZSize > 0)
|
if (aabb.ZSize > 0)
|
||||||
{
|
{
|
||||||
// If the part was already created and at a height, maintain the height.
|
// If the part was already created and at a height, maintain the height.
|
||||||
|
|
@ -180,42 +187,45 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
|
|
||||||
private void AdjustChildSize(object sender, EventArgs e)
|
private void AdjustChildSize(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var aabb = SourceItem.GetAxisAlignedBoundingBox();
|
if (Children.Count > 0)
|
||||||
TransformItem.Matrix = Matrix4X4.Identity;
|
|
||||||
var scale = Vector3.One;
|
|
||||||
if (StretchX)
|
|
||||||
{
|
{
|
||||||
scale.X = SizeX / aabb.XSize;
|
var aabb = SourceItem.GetAxisAlignedBoundingBox();
|
||||||
}
|
TransformItem.Matrix = Matrix4X4.Identity;
|
||||||
if (StretchY)
|
var scale = Vector3.One;
|
||||||
{
|
if (StretchX)
|
||||||
scale.Y = SizeY / aabb.YSize;
|
{
|
||||||
}
|
scale.X = SizeX / aabb.XSize;
|
||||||
if (StretchZ)
|
}
|
||||||
{
|
if (StretchY)
|
||||||
scale.Z = SizeZ / aabb.ZSize;
|
{
|
||||||
}
|
scale.Y = SizeY / aabb.YSize;
|
||||||
|
}
|
||||||
|
if (StretchZ)
|
||||||
|
{
|
||||||
|
scale.Z = SizeZ / aabb.ZSize;
|
||||||
|
}
|
||||||
|
|
||||||
switch (MaintainRatio)
|
switch (MaintainRatio)
|
||||||
{
|
{
|
||||||
case MaintainRatio.None:
|
case MaintainRatio.None:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MaintainRatio.X_Y:
|
case MaintainRatio.X_Y:
|
||||||
var minXy = Math.Min(scale.X, scale.Y);
|
var minXy = Math.Min(scale.X, scale.Y);
|
||||||
scale.X = minXy;
|
scale.X = minXy;
|
||||||
scale.Y = minXy;
|
scale.Y = minXy;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MaintainRatio.X_Y_Z:
|
case MaintainRatio.X_Y_Z:
|
||||||
var minXyz = Math.Min(Math.Min(scale.X, scale.Y), scale.Z);
|
var minXyz = Math.Min(Math.Min(scale.X, scale.Y), scale.Z);
|
||||||
scale.X = minXyz;
|
scale.X = minXyz;
|
||||||
scale.Y = minXyz;
|
scale.Y = minXyz;
|
||||||
scale.Z = minXyz;
|
scale.Z = minXyz;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
TransformItem.Matrix = Object3DExtensions.ApplyAtPosition(TransformItem.Matrix, aabb.Center, Matrix4X4.CreateScale(scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
TransformItem.Matrix = Object3DExtensions.ApplyAtPosition(TransformItem.Matrix, aabb.Center, Matrix4X4.CreateScale(scale));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateBoundsItem()
|
private void UpdateBoundsItem()
|
||||||
|
|
@ -252,7 +262,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
boundsSize.X = value;
|
boundsSize.X = value;
|
||||||
UpdateBoundsItem();
|
Rebuild(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -263,7 +273,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
boundsSize.Y = value;
|
boundsSize.Y = value;
|
||||||
UpdateBoundsItem();
|
Rebuild(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,7 +284,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
boundsSize.Z = value;
|
boundsSize.Z = value;
|
||||||
UpdateBoundsItem();
|
Rebuild(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue