Made the upArrow a separate class and making it use the InteractionVolume base.
This commit is contained in:
parent
3c9930825b
commit
e08110447d
1 changed files with 43 additions and 33 deletions
|
|
@ -57,6 +57,47 @@ using MatterHackers.VectorMath;
|
||||||
|
|
||||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
{
|
{
|
||||||
|
public class UpArrow3D : InteractionVolume
|
||||||
|
{
|
||||||
|
Mesh upArrow;
|
||||||
|
MeshViewerWidget meshViewerToDrawWith;
|
||||||
|
|
||||||
|
public UpArrow3D(MeshViewerWidget meshViewerToDrawWith)
|
||||||
|
: base(new CylinderShape(3, 12, new SolidMaterial(RGBA_Floats.Red, .5, 0, .4)))
|
||||||
|
{
|
||||||
|
this.meshViewerToDrawWith = meshViewerToDrawWith;
|
||||||
|
string arrowFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "3D Icons", "up_pointer.stl");
|
||||||
|
List<MeshGroup> loadedMeshGroups = MeshFileIo.Load(arrowFile);
|
||||||
|
upArrow = loadedMeshGroups[0].Meshes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawGlContent(EventArgs e)
|
||||||
|
{
|
||||||
|
if (meshViewerToDrawWith.SelectedMeshGroup != null)
|
||||||
|
{
|
||||||
|
AxisAlignedBoundingBox selectedBounds = meshViewerToDrawWith.SelectedMeshGroup.GetAxisAlignedBoundingBox(meshViewerToDrawWith.SelectedMeshGroupTransform.TotalTransform);
|
||||||
|
Vector3 boundsCenter = selectedBounds.Center;
|
||||||
|
Vector3 centerTop = new Vector3(boundsCenter.x, boundsCenter.y, selectedBounds.maxXYZ.z);
|
||||||
|
|
||||||
|
Vector2 centerTopScreenPosition = meshViewerToDrawWith.TrackballTumbleWidget.GetScreenPosition(centerTop);
|
||||||
|
//centerTopScreenPosition = meshViewerToDrawWith.TransformToParentSpace(this, centerTopScreenPosition);
|
||||||
|
|
||||||
|
double scalling = meshViewerToDrawWith.TrackballTumbleWidget.GetWorldUnitsPerScreenPixelAtPosition(centerTop);
|
||||||
|
|
||||||
|
GL.MatrixMode(MatrixMode.Modelview);
|
||||||
|
GL.PushMatrix();
|
||||||
|
GL.Translate(new Vector3(centerTop.x, centerTop.y, centerTop.z + 20 * scalling));
|
||||||
|
GL.Scale(scalling, scalling, scalling);
|
||||||
|
|
||||||
|
RenderMeshToGl.Render(upArrow, RGBA_Bytes.Black, RenderTypes.Shaded);
|
||||||
|
|
||||||
|
GL.PopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
base.DrawGlContent(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public partial class View3DWidget : PartPreview3DWidget
|
public partial class View3DWidget : PartPreview3DWidget
|
||||||
{
|
{
|
||||||
public WindowType windowType { get; set; }
|
public WindowType windowType { get; set; }
|
||||||
|
|
@ -240,38 +281,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
DrawStuffForSelectedPart(graphics2D);
|
DrawStuffForSelectedPart(graphics2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh upArrow;
|
|
||||||
void TrackballTumbleWidget_DrawGlContent(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (SelectedMeshGroup != null)
|
|
||||||
{
|
|
||||||
if (upArrow == null)
|
|
||||||
{
|
|
||||||
string arrowFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "3D Icons", "up_pointer.stl");
|
|
||||||
List<MeshGroup> loadedMeshGroups = MeshFileIo.Load(arrowFile);
|
|
||||||
upArrow = loadedMeshGroups[0].Meshes[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
AxisAlignedBoundingBox selectedBounds = SelectedMeshGroup.GetAxisAlignedBoundingBox(SelectedMeshGroupTransform.TotalTransform);
|
|
||||||
Vector3 boundsCenter = selectedBounds.Center;
|
|
||||||
Vector3 centerTop = new Vector3(boundsCenter.x, boundsCenter.y, selectedBounds.maxXYZ.z);
|
|
||||||
|
|
||||||
Vector2 centerTopScreenPosition = meshViewerWidget.TrackballTumbleWidget.GetScreenPosition(centerTop);
|
|
||||||
centerTopScreenPosition = meshViewerWidget.TransformToParentSpace(this, centerTopScreenPosition);
|
|
||||||
|
|
||||||
double scalling = meshViewerWidget.TrackballTumbleWidget.GetWorldUnitsPerScreenPixelAtPosition(centerTop);
|
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Modelview);
|
|
||||||
GL.PushMatrix();
|
|
||||||
GL.Translate(new Vector3(centerTop.x, centerTop.y, centerTop.z + 20*scalling));
|
|
||||||
GL.Scale(scalling, scalling, scalling);
|
|
||||||
|
|
||||||
RenderMeshToGl.Render(upArrow, RGBA_Bytes.Black, RenderTypes.Shaded);
|
|
||||||
|
|
||||||
GL.PopMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawStuffForSelectedPart(Graphics2D graphics2D)
|
private void DrawStuffForSelectedPart(Graphics2D graphics2D)
|
||||||
{
|
{
|
||||||
if (SelectedMeshGroup != null)
|
if (SelectedMeshGroup != null)
|
||||||
|
|
@ -573,7 +582,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
this.AnchorAll();
|
this.AnchorAll();
|
||||||
|
|
||||||
meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;
|
meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;
|
||||||
meshViewerWidget.TrackballTumbleWidget.DrawGlContent +=TrackballTumbleWidget_DrawGlContent;
|
|
||||||
AddChild(viewControls3D);
|
AddChild(viewControls3D);
|
||||||
|
|
||||||
AddHandlers();
|
AddHandlers();
|
||||||
|
|
@ -628,6 +636,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meshViewerWidget.InteractionVolumes.Add(new UpArrow3D(meshViewerWidget));
|
||||||
|
|
||||||
// make sure the colors are set correctl
|
// make sure the colors are set correctl
|
||||||
ThemeChanged(this, null);
|
ThemeChanged(this, null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue