public Visual3D GetDummyVisual() { BoundingBoxWireFrameVisual3D mesh = new BoundingBoxWireFrameVisual3D(); mesh.BoundingBox = new Rect3D(-0.5, -0.5, -0.5, 1, 1, 1); mesh.Color = DummyColor; return(mesh); }
public void showHideBoundingBox() { if (ShowBoundingBox) { if (_boundingBox == null) { _boundingBox = new BoundingBoxWireFrameVisual3D(); _boundingBox.BoundingBox = this.Content.Bounds; this.Children.Add(_boundingBox); showBoundingBox = false; } } else { this.Children.Remove(_boundingBox); _boundingBox = null; showBoundingBox = true; } }
public void Render(List <GCodeToken> tokens) { var bbox = (DataContext as GrblViewModel).ProgramLimits; double lineThickness = bbox.MaxSize / 1000d; double arrowOffset = lineThickness * 30d; double labelOffset = lineThickness * 50d; ClearViewport(); if (isLatheMode == null) { if ((isLatheMode = model.LatheMode != LatheMode.Disabled) == true) { viewport.ModelUpDirection = new Vector3D(0d, -1d, 0d); if (tool != null) { tool.Normal = new Vector3D(1d, 0d, 0d); } } isDiameterMode = model.LatheMode == LatheMode.Diameter; } bool latheMode = isLatheMode == true; cutCount = 0; point0 = Machine.StartPosition; lastType = MoveType.None; if (tool != null) { tool.Height = Math.Min(6d, lineThickness * 100d); tool.TopRadius = tool.Height / 5d; } #region Canvas adorners if (ShowGrid) { double wh, h, wm = bbox.SizeX % TickSize, w = Math.Ceiling(bbox.SizeX - bbox.SizeX % TickSize + TickSize * 2d); if (model.LatheMode == LatheMode.Disabled) { wh = bbox.SizeY % TickSize; h = Math.Ceiling(bbox.SizeY - bbox.SizeY % TickSize + TickSize * 2d); Machine.Grid = new GridLinesVisual3D() { Center = new Point3D(boffset(bbox.SizeX, bbox.MinX, w, wm) - TickSize, boffset(bbox.SizeY, bbox.MinY, h, wh) - TickSize, 0d), MinorDistance = 2.5d, MajorDistance = TickSize, Width = h, Length = w, Thickness = 0.1d, Fill = AxisBrush }; } else { wh = bbox.SizeZ % TickSize; h = Math.Ceiling(bbox.SizeZ - bbox.SizeZ % TickSize + TickSize * 2d); Machine.Grid = new GridLinesVisual3D() { Center = new Point3D(boffset(bbox.SizeX, bbox.MinX, w, wm) - TickSize, 0d, boffset(bbox.SizeZ, bbox.MinZ, h, wh) - TickSize), MinorDistance = 2.5d, MajorDistance = TickSize, Width = w, Length = h, Thickness = lineThickness, Fill = AxisBrush, LengthDirection = new Vector3D(0d, 0d, 1d), Normal = new Vector3D(0d, 1d, 0d) }; } viewport.Children.Add(Machine.Grid); } if (ShowAxes) { Machine.Axes.Children.Add(new ArrowVisual3D() { Point2 = new Point3D(bbox.SizeX + arrowOffset, 0d, 0d), Diameter = lineThickness * 5, Fill = AxisBrush }); Machine.Axes.Children.Add(new BillboardTextVisual3D() { Text = "X", FontWeight = FontWeights.Bold, Foreground = AxisBrush, Position = new Point3D(bbox.SizeX + labelOffset, 0d, 0d) }); if (bbox.SizeY > 0d) { Machine.Axes.Children.Add(new ArrowVisual3D() { Point2 = new Point3D(0d, bbox.SizeY + arrowOffset, 0d), Diameter = lineThickness * 5d, Fill = AxisBrush }); Machine.Axes.Children.Add(new BillboardTextVisual3D() { Text = "Y", FontWeight = FontWeights.Bold, Foreground = AxisBrush, Position = new Point3D(0d, bbox.SizeY + labelOffset, 0d) }); } if (bbox.SizeZ > 0d) { Machine.Axes.Children.Add(new ArrowVisual3D() { Point1 = latheMode ? new Point3D(0d, 0d, bbox.MaxZ + arrowOffset) : new Point3D(0d, 0d, bbox.MinZ - arrowOffset), Point2 = latheMode ? new Point3D(0d, 0d, bbox.MinZ - arrowOffset) : new Point3D(0d, 0d, bbox.MaxZ + arrowOffset), Diameter = lineThickness * 5d, Fill = AxisBrush, }); Machine.Axes.Children.Add(new BillboardTextVisual3D() { Text = "Z", FontWeight = FontWeights.Bold, Foreground = AxisBrush, Position = new Point3D(0d, 0d, latheMode ? bbox.MinZ - labelOffset : bbox.MaxZ + labelOffset) }); } viewport.Children.Add(Machine.Axes); } if (ShowBoundingBox && bbox.SizeZ > 0d) { Machine.BoundingBox = new BoundingBoxWireFrameVisual3D() { BoundingBox = new Rect3D(bbox.MinX, bbox.MinY, bbox.MinZ, bbox.SizeX, Math.Max(0.001d, bbox.SizeY), bbox.SizeZ), Thickness = 1d, Color = Colors.LightGreen }; viewport.Children.Add(Machine.BoundingBox); } #endregion GCodeEmulator emu = new GCodeEmulator(true); emu.SetStartPosition(Machine.StartPosition); foreach (var cmd in emu.Execute(tokens)) { point0 = cmd.Start; switch (cmd.Token.Command) { case Commands.G0: if (cmd.IsRetract) { AddRetractMove(cmd.End); } else { AddRapidMove(cmd.End); } break; case Commands.G1: AddCutMove(cmd.End); break; case Commands.G2: case Commands.G3: #if DEBUG_ARC_BBOXES var bb = (cmd.Token as GCArc).GetBoundingBox(emu.Plane, point0.ToArray(), emu.DistanceMode == DistanceMode.Incremental); var abb = new BoundingBoxWireFrameVisual3D() { BoundingBox = new Rect3D(bb.Min[0], bb.Min[1], bb.Min[2], bb.Size[0], bb.Size[1], bb.Size[2]), Thickness = .5d, Color = Colors.Blue }; viewport.Children.Add(abb); #endif DrawArc(cmd.Token as GCArc, point0.ToArray(), emu.Plane, emu.DistanceMode == DistanceMode.Incremental); break; case Commands.G5: DrawSpline(cmd.Token as GCSpline, point0.ToArray()); break; } } Machine.RapidLines = rapidPoints; Machine.CutLines = linePoints; Machine.RetractLines = retractPoints; refreshCamera(bbox); }
/// <summary>Creates the plot elements.</summary> /// <remarks>Changes to the bounding box and other parameters will not take effect until this method is called.</remarks> public void CreateElements() { Children.Clear(); Children.Add(new DefaultLights()); string[] labels = AxisLabels.Split(','); if (labels.Length < 3) { labels = new string[] { "X", "Y", "Z" } } ; double bbSize = Math.Max(Math.Max(BoundingBox.SizeX, BoundingBox.SizeY), BoundingBox.SizeZ); double lineThickness = bbSize / 1000; double arrowOffset = lineThickness * 30; labelOffset = lineThickness * 50; minDistanceSquared = MinDistance * MinDistance; if (Elements.HasFlag(EElements.Grid)) { var grid = new GridLinesVisual3D(); grid.Center = new Point3D(BoundingBox.X + 0.5 * BoundingBox.SizeX, BoundingBox.Y + 0.5 * BoundingBox.SizeY, BoundingBox.Z); grid.Length = BoundingBox.SizeX; grid.Width = BoundingBox.SizeY; grid.MinorDistance = TickSize; grid.MajorDistance = bbSize; grid.Thickness = lineThickness; grid.Fill = AxisBrush; Children.Add(grid); } if (Elements.HasFlag(EElements.Axes)) { var arrow = new ArrowVisual3D(); arrow.Point2 = new Point3D((BoundingBox.X + BoundingBox.SizeX) + arrowOffset, 0.0, 0.0); arrow.Diameter = lineThickness * 5; arrow.Fill = AxisBrush; Children.Add(arrow); var label = new BillboardTextVisual3D(); label.Text = labels[0]; label.FontWeight = FontWeights.Bold; label.Foreground = AxisBrush; label.Position = new Point3D((BoundingBox.X + BoundingBox.SizeX) + labelOffset, 0.0, 0.0); Children.Add(label); arrow = new ArrowVisual3D(); arrow.Point2 = new Point3D(0.0, (BoundingBox.Y + BoundingBox.SizeY) + arrowOffset, 0.0); arrow.Diameter = lineThickness * 5; arrow.Fill = AxisBrush; Children.Add(arrow); label = new BillboardTextVisual3D(); label.Text = labels[1]; label.FontWeight = FontWeights.Bold; label.Foreground = AxisBrush; label.Position = new Point3D(0.0, (BoundingBox.Y + BoundingBox.SizeY) + labelOffset, 0.0); Children.Add(label); if (BoundingBox.SizeZ > 0) { arrow = new ArrowVisual3D(); arrow.Point2 = new Point3D(0.0, 0.0, (BoundingBox.Z + BoundingBox.SizeZ) + arrowOffset); arrow.Diameter = lineThickness * 5; arrow.Fill = AxisBrush; Children.Add(arrow); label = new BillboardTextVisual3D(); label.Text = labels[2]; label.FontWeight = FontWeights.Bold; label.Foreground = AxisBrush; label.Position = new Point3D(0.0, 0.0, (BoundingBox.Z + BoundingBox.SizeZ) + labelOffset); Children.Add(label); } } if (Elements.HasFlag(EElements.BoundingBox) && BoundingBox.SizeZ > 0) { var box = new BoundingBoxWireFrameVisual3D(); box.BoundingBox = BoundingBox; box.Thickness = 1; box.Color = AxisBrush.Color; Children.Add(box); } if (Elements.HasFlag(EElements.Marker)) { marker = new TruncatedConeVisual3D(); marker.Height = labelOffset; marker.BaseRadius = 0.0; marker.TopRadius = labelOffset / 5; marker.TopCap = true; marker.Origin = new Point3D(0.0, 0.0, 0.0); marker.Normal = new Vector3D(-1.0, -1.0, 1.0); marker.Fill = MarkerBrush; Children.Add(marker); coords = new BillboardTextVisual3D(); coordinateFormat = string.Format("{{0:F6}}, {{1:F6}}, {{2:F6}}", DecimalPlaces, DecimalPlaces, DecimalPlaces); // "{0:F2}, {1:F2}, {2:F2}" coords.Text = string.Format(coordinateFormat, 0.0, 0.0, 0.0); coords.Foreground = MarkerBrush; coords.Position = new Point3D(-labelOffset, -labelOffset, labelOffset); Children.Add(coords); } else { marker = null; coords = null; } if (trace != null) { foreach (LinesVisual3D p in trace) { Children.Add(p); } path = trace[trace.Count - 1]; } }
public void InitGrid() { int midNum = (int)Math.Ceiling(GridSize / 2d); MapCenter = new Point3D(0d, 0d, 0d); Random ran = new Random(); currentTileX = 0; currentTileY = 0; OSMWorldScale scale = new OSMWorldScale(); double mapCenterNormalizedX = scale.NormalizeX(TileService.xTileOffset); double mapCenterNormalizedY = scale.NormalizeY(TileService.yTileOffset); double maxTiles = Math.Pow(2, mapZoom); double tileNumX = mapCenterNormalizedX * maxTiles; double tileNumY = mapCenterNormalizedY * maxTiles; //X and y are flipped double fracX = tileNumX - Math.Floor(tileNumX); double fracY = tileNumY - Math.Floor(tileNumY); double posFracX = fracX; double posFracY = fracY; if (posFracX <= 0.5) { posFracX += 1; } if (posFracY >= 0.5) { posFracY -= 1; } if (mapZoom == 15 || mapZoom == 12) { posFracY -= 1; } double tileTranslateX = scale.GetTileXTranslateFix(mapCenterNormalizedX, mapZoom, TileSize); //TileSize * fracX; double tileTranslateY = scale.GetTileYTranslateFix(mapCenterNormalizedY, mapZoom, TileSize); //TileSize * fracY; Debug.WriteLine($"TranslateFixes: {tileTranslateX} / {tileTranslateY} TileSize {TileSize}"); Debug.WriteLine($"TranslateFixesWOLessTHanFixes: {TileSize * fracX} / {TileSize * fracY}"); Debug.WriteLine($"TranslateFixesPositive: {posFracX} / {posFracY}"); //double fooTest2 = //double fooTest2 = scale.GetTileXTranslateFix(mapCenterNormalizedX, mapZoom, TileSize); BoundingBoxWireFrameVisual3D box = new BoundingBoxWireFrameVisual3D(); box.Color = Colors.Yellow; double bSize = 1 * TileSize / 32; box.Thickness = 1; box.BoundingBox = new Rect3D((tileTranslateX) - bSize / 2, tileTranslateY - bSize / 2, 0, bSize, bSize, bSize); this.Children.Add(box); BoundingBoxWireFrameVisual3D box2 = new BoundingBoxWireFrameVisual3D(); box2.Color = Colors.LimeGreen; double b2Size = 1 * TileSize / 32; box2.Thickness = 1; box2.BoundingBox = new Rect3D((posFracX * TileSize * -1) - b2Size / 2, (posFracY * TileSize) - b2Size / 2, 0, b2Size, b2Size, b2Size); this.Children.Add(box2); for (int x = 0; x < GridSize; x++) { for (int y = 0; y < GridSize; y++) { int gridPosX = ((x + 1) - midNum); int gridPosY = ((y + 1) - midNum); MapTileVisual tile = new MapTileVisual(); tile.Fill = new SolidColorBrush(Color.FromArgb(255, (byte)ran.Next(30, 255), (byte)ran.Next(32, 255), (byte)ran.Next(28, 255))); TranslateTransform3D position = new TranslateTransform3D(); position.OffsetX = (gridPosX * TileSize) - TileSize / 2; position.OffsetY = (gridPosY * TileSize) - TileSize / 2; if (TranslateOnZoom) { position.OffsetX -= tileTranslateX; position.OffsetY -= tileTranslateY; } tile.Transform = position; tile.Width = TileSize; tile.Length = TileSize; tile.TileX = gridPosX * -1; tile.TileY = gridPosY; tile.TileZoom = MapZoomLevel; this.Children.Add(tile); Tiles.Add(tile); if (TileGenerator != null) { //log.DebugFormat("Requesting Image for x/y/zoom {0} / {1} / {2}", tile.TileX, tile.TileY, mapZoom); TileGenerator.LoadTileImageAsync(tile, tile.TileX, tile.TileY, MapZoomLevel); } else { Aegir.Util.DebugUtil.LogWithLocation("Could not load image, TileGeneratorWas Null"); } tile.UpdateDebugLabels(); } } }