Improving twist object
fixed draw normals and added it
This commit is contained in:
parent
a9577e9a35
commit
ca24a67706
5 changed files with 77 additions and 26 deletions
|
|
@ -822,7 +822,7 @@ namespace MatterHackers.MatterControl
|
||||||
var curve = new TwistObject3D();
|
var curve = new TwistObject3D();
|
||||||
curve.WrapSelectedItemAndSelect(sceneContext.Scene);
|
curve.WrapSelectedItemAndSelect(sceneContext.Scene);
|
||||||
},
|
},
|
||||||
Icon = AggContext.StaticData.LoadIcon("curve.png", 16, 16, theme.InvertIcons),
|
Icon = AggContext.StaticData.LoadIcon("twist.png", 16, 16, theme.InvertIcons),
|
||||||
IsEnabled = (scene) => scene.SelectedItem != null,
|
IsEnabled = (scene) => scene.SelectedItem != null,
|
||||||
},
|
},
|
||||||
new SceneSelectionOperation()
|
new SceneSelectionOperation()
|
||||||
|
|
|
||||||
|
|
@ -55,17 +55,28 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
Name = "Twist".Localize();
|
Name = "Twist".Localize();
|
||||||
}
|
}
|
||||||
|
|
||||||
[DisplayName("Twist Right")]
|
[Description("The angle to rotate the top of the part")]
|
||||||
public bool TwistCw { get; set; } = true;
|
|
||||||
|
|
||||||
public double Angle { get; set; } = double.MaxValue;
|
public double Angle { get; set; } = double.MaxValue;
|
||||||
|
|
||||||
public Vector2 RotationOffset { get; set; }
|
|
||||||
|
|
||||||
[Range(3, 360, ErrorMessage = "Value for {0} must be between {1} and {2}.")]
|
[Range(3, 360, ErrorMessage = "Value for {0} must be between {1} and {2}.")]
|
||||||
[Description("Ensures the rotated part has a minimum number of sides per complete rotation")]
|
[Description("Ensures the rotated part has a minimum number of sides per complete rotation")]
|
||||||
public double MinCutsPerRotation { get; set; } = 30;
|
public double MinCutsPerRotation { get; set; } = 30;
|
||||||
|
|
||||||
|
[DisplayName("Twist Right")]
|
||||||
|
public bool TwistCw { get; set; } = true;
|
||||||
|
|
||||||
|
public bool Advanced { get; set; }
|
||||||
|
|
||||||
|
public Easing.EaseType EasingType { get; set; } = Easing.EaseType.Linear;
|
||||||
|
|
||||||
|
public Easing.EaseOption EasingOption { get; set; } = Easing.EaseOption.In;
|
||||||
|
|
||||||
|
public double EndHeightPercent { get; set; } = 100;
|
||||||
|
|
||||||
|
public double StartHeightPercent { get; set; } = 0;
|
||||||
|
|
||||||
|
[Description("Allows for the repositioning of the rotation origin")]
|
||||||
|
public Vector2 RotationOffset { get; set; }
|
||||||
|
|
||||||
public void DrawEditor(InteractionLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e, ref bool suppressNormalDraw)
|
public void DrawEditor(InteractionLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e, ref bool suppressNormalDraw)
|
||||||
{
|
{
|
||||||
|
|
@ -104,6 +115,18 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
valuesChanged = true;
|
valuesChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (EndHeightPercent < 1 || EndHeightPercent > 100)
|
||||||
|
{
|
||||||
|
EndHeightPercent = Math.Min(100, Math.Max(1, EndHeightPercent));
|
||||||
|
valuesChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StartHeightPercent < 0 || StartHeightPercent > EndHeightPercent - 1)
|
||||||
|
{
|
||||||
|
StartHeightPercent = Math.Min(EndHeightPercent - 1, Math.Max(0, StartHeightPercent));
|
||||||
|
valuesChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
var rebuildLocks = this.RebuilLockAll();
|
var rebuildLocks = this.RebuilLockAll();
|
||||||
|
|
||||||
return ApplicationController.Instance.Tasks.Execute(
|
return ApplicationController.Instance.Tasks.Execute(
|
||||||
|
|
@ -113,14 +136,21 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
var sourceAabb = this.SourceContainer.GetAxisAlignedBoundingBox();
|
var sourceAabb = this.SourceContainer.GetAxisAlignedBoundingBox();
|
||||||
|
|
||||||
double numberOfCuts = MinCutsPerRotation * (Angle / 360.0);
|
var bottom = sourceAabb.MinXYZ.Z;
|
||||||
double cutSize = sourceAabb.XSize / numberOfCuts;
|
var top = sourceAabb.ZSize * EndHeightPercent / 100.0;
|
||||||
double cutPosition = sourceAabb.MinXYZ.Z + cutSize;
|
var size = sourceAabb.ZSize;
|
||||||
var cuts = new List<double>();
|
if (Advanced)
|
||||||
for (int i = 0; i < numberOfCuts; i++)
|
|
||||||
{
|
{
|
||||||
cuts.Add(cutPosition);
|
bottom += sourceAabb.ZSize * StartHeightPercent / 100.0;
|
||||||
cutPosition += cutSize;
|
size = top - bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
double numberOfCuts = MinCutsPerRotation * (Angle / 360.0);
|
||||||
|
double cutSize = size / numberOfCuts;
|
||||||
|
var cuts = new List<double>();
|
||||||
|
for (int i = 0; i < numberOfCuts + 1; i++)
|
||||||
|
{
|
||||||
|
cuts.Add(bottom - cutSize + i * size / numberOfCuts);
|
||||||
}
|
}
|
||||||
|
|
||||||
var rotationCenter = new Vector2(sourceAabb.Center) + RotationOffset;
|
var rotationCenter = new Vector2(sourceAabb.Center) + RotationOffset;
|
||||||
|
|
@ -143,7 +173,27 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
var position = transformedMesh.Vertices[i];
|
var position = transformedMesh.Vertices[i];
|
||||||
|
|
||||||
var angleToRotate = ((position.Z - sourceAabb.MinXYZ.Z) / sourceAabb.ZSize) * Angle / 360.0 * MathHelper.Tau;
|
var ratio = (position.Z - bottom) / size;
|
||||||
|
|
||||||
|
if (Advanced)
|
||||||
|
{
|
||||||
|
if (position.Z < bottom)
|
||||||
|
{
|
||||||
|
ratio = 0;
|
||||||
|
}
|
||||||
|
else if (position.Z > top)
|
||||||
|
{
|
||||||
|
ratio = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ratio = (position.Z - bottom) / size;
|
||||||
|
ratio = Easing.Specify(EasingType, EasingOption, ratio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var angleToRotate = ratio * Angle / 360.0 * MathHelper.Tau;
|
||||||
|
|
||||||
if (!TwistCw)
|
if (!TwistCw)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ of the authors and should not be interpreted as representing official policies,
|
||||||
either expressed or implied, of the FreeBSD Project.
|
either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using MatterHackers.Agg;
|
||||||
using System.Drawing;
|
|
||||||
using MatterHackers.Agg.UI;
|
using MatterHackers.Agg.UI;
|
||||||
using MatterHackers.DataConverters3D;
|
using MatterHackers.DataConverters3D;
|
||||||
using MatterHackers.RenderOpenGl;
|
using MatterHackers.RenderOpenGl;
|
||||||
|
|
@ -57,8 +56,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
|
|
||||||
public void Draw(GuiWidget sender, IObject3D item, bool isSelected, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world)
|
public void Draw(GuiWidget sender, IObject3D item, bool isSelected, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
|
||||||
#if false
|
|
||||||
if (item.Mesh?.Faces.Count <= 0)
|
if (item.Mesh?.Faces.Count <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
@ -71,24 +68,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
foreach (var face in mesh.Faces)
|
foreach (var face in mesh.Faces)
|
||||||
{
|
{
|
||||||
int vertexCount = 0;
|
int vertexCount = 0;
|
||||||
Vector3 faceCenter = Vector3.Zero;
|
Vector3Float faceCenter = Vector3Float.Zero;
|
||||||
foreach (var v in new[] { face.v0, face.v1, face.v2 })
|
foreach (var v in new[] { face.v0, face.v1, face.v2 })
|
||||||
{
|
{
|
||||||
var vertex = mesh.Vertices[v];
|
var vertex = mesh.Vertices[v];
|
||||||
|
|
||||||
faceCenter += vertex.Position;
|
faceCenter += vertex;
|
||||||
vertexCount++;
|
vertexCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
faceCenter /= vertexCount;
|
faceCenter /= vertexCount;
|
||||||
|
|
||||||
var matrix = item.WorldMatrix();
|
var matrix = item.WorldMatrix();
|
||||||
|
|
||||||
var transformed1 = Vector3Ex.Transform(faceCenter, matrix);
|
var transformed1 = faceCenter.Transform(matrix);
|
||||||
var normal = Vector3Ex.TransformNormal(face.Normal, matrix).GetNormal();
|
var normal = face.normal.TransformNormal(matrix).GetNormal();
|
||||||
|
|
||||||
world.Render3DLineNoPrep(frustum, transformed1, transformed1 + normal, Color.Red, 2);
|
world.Render3DLineNoPrep(frustum, transformed1, transformed1 + normal, Color.Red, 2);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
new AxisIndicatorDrawable(),
|
new AxisIndicatorDrawable(),
|
||||||
new SceneTraceDataDrawable(sceneContext),
|
new SceneTraceDataDrawable(sceneContext),
|
||||||
new AABBDrawable(sceneContext),
|
new AABBDrawable(sceneContext),
|
||||||
new LevelingDataDrawable(sceneContext)
|
new LevelingDataDrawable(sceneContext),
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
itemDrawables.AddRange(new IDrawableItem[]
|
itemDrawables.AddRange(new IDrawableItem[]
|
||||||
|
|
@ -92,7 +92,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
});
|
});
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
itemDrawables.Add(new InspectedItemDrawable(sceneContext));
|
itemDrawables.AddRange(new IDrawableItem[]
|
||||||
|
{
|
||||||
|
new InspectedItemDrawable(sceneContext),
|
||||||
|
new NormalsDrawable(sceneContext)
|
||||||
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
base.OnLoad(args);
|
base.OnLoad(args);
|
||||||
|
|
|
||||||
BIN
StaticData/Icons/twist.png
Normal file
BIN
StaticData/Icons/twist.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1 KiB |
Loading…
Add table
Add a link
Reference in a new issue