Exemplo n.º 1
0
        public static async Task <FitToBoundsObject3D_3> Create(IObject3D itemToFit)
        {
            var fitToBounds = new FitToBoundsObject3D_3();

            using (fitToBounds.RebuildLock())
            {
                var startingAabb = itemToFit.GetAxisAlignedBoundingBox();
                itemToFit.Translate(-startingAabb.Center);

                // add the fit item
                var scaleItem = new Object3D();
                fitToBounds.Children.Add(scaleItem);
                scaleItem.Children.Add(itemToFit);

                // create an object that just represents the bounds in the scene
                var fitBounds = new Object3D()
                {
                    Visible = false,
                    Color   = new Color(Color.Red, 100),
                    Mesh    = PlatonicSolids.CreateCube()
                };
                // add the item that holds the bounds
                fitToBounds.Children.Add(fitBounds);

                fitToBounds.Width  = startingAabb.XSize;
                fitToBounds.Depth  = startingAabb.YSize;
                fitToBounds.Height = startingAabb.ZSize;
                await fitToBounds.Rebuild();

                var finalAabb = fitToBounds.GetAxisAlignedBoundingBox();
                fitToBounds.Translate(startingAabb.Center - finalAabb.Center);
            }

            return(fitToBounds);
        }
Exemplo n.º 2
0
        public void CreatesAndLinksAmfsForUnsavedMeshes()
        {
            AssetObject3D.AssetManager = new AssetManager();

            var scene = new InteractiveScene();

            scene.Children.Add(new Object3D
            {
                Mesh = PlatonicSolids.CreateCube(20, 20, 20)
            });

            string tempPath = GetSceneTempPath();
            string filePath = Path.Combine(tempPath, "some.mcx");

            Object3D.AssetsPath = Path.Combine(tempPath, "Assets");

            scene.Save(filePath);

            Assert.IsTrue(File.Exists(filePath));

            IObject3D loadedItem = Object3D.Load(filePath, CancellationToken.None);

            Assert.IsTrue(loadedItem.Children.Count == 1);

            IObject3D meshItem = loadedItem.Children.First();

            Assert.IsTrue(!string.IsNullOrEmpty(meshItem.MeshPath));

            Assert.IsTrue(File.Exists(Path.Combine(tempPath, "Assets", meshItem.MeshPath)));
            Assert.IsNotNull(meshItem.Mesh);
            Assert.IsTrue(meshItem.Mesh.Faces.Count > 0);
        }
        public static FitToBoundsObject3D_2 Create(IObject3D itemToFit)
        {
            var fitToBounds = new FitToBoundsObject3D_2();
            var aabb        = itemToFit.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);

            fitToBounds.SizeX = aabb.XSize;
            fitToBounds.SizeY = aabb.YSize;
            fitToBounds.SizeZ = aabb.ZSize;

            return(fitToBounds);
        }
Exemplo n.º 4
0
        public void SubtractIcosahedronsWorks()
        {
            Vector3 centering = new Vector3(100, 100, 20);
            Mesh    meshA     = PlatonicSolids.CreateIcosahedron(35);

            meshA.Translate(centering);
            Mesh meshB = PlatonicSolids.CreateIcosahedron(35);

            Vector3   finalTransform = new Vector3(105.240172225344, 92.9716306394062, 18.4619570261172);
            Vector3   rotCurrent     = new Vector3(4.56890223673623, -2.67874102322035, 1.02768848238523);
            Vector3   scaleCurrent   = new Vector3(1.07853517569753, 0.964980885267323, 1.09290934544604);
            Matrix4X4 transformB     = Matrix4X4.CreateScale(scaleCurrent) * Matrix4X4.CreateRotation(rotCurrent) * Matrix4X4.CreateTranslation(finalTransform);

            meshB.Transform(transformB);

            Mesh result = CsgOperations.Subtract(meshA, meshB);

            AxisAlignedBoundingBox a_aabb         = meshA.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox b_aabb         = meshB.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox intersect_aabb = result.GetAxisAlignedBoundingBox();

            Assert.IsTrue(a_aabb.XSize == 40 && a_aabb.YSize == 40 && a_aabb.ZSize == 40);
            Assert.IsTrue(intersect_aabb.XSize == 40 && intersect_aabb.YSize == 40 && intersect_aabb.ZSize == 40);

            // Todo: turn this on
            //Assert.IsTrue(result.IsManifold());
        }
        private static IObject3D CreateCalibrationObject(PrinterConfig printer)
        {
            var printObject = new Object3D();

            var layerHeight = printer.Settings.GetValue <double>(SettingsKey.layer_height);
            var baseSize    = 20;
            var inset       = 2.5;
            // add a base
            var mesh = PlatonicSolids.CreateCube(baseSize, baseSize, CalibrationObjectHeight(printer) - layerHeight);

            mesh.Translate(0, 0, mesh.GetAxisAlignedBoundingBox().ZSize / 2);
            printObject.Children.Add(new Object3D()
            {
                Mesh = mesh
            });

            // add a middle part where we will probe to find the height and the edges of
            mesh = PlatonicSolids.CreateCube(baseSize - inset, baseSize - inset, CalibrationObjectHeight(printer));
            mesh.Translate(0, 0, mesh.GetAxisAlignedBoundingBox().ZSize / 2);
            printObject.Children.Add(new Object3D()
            {
                Mesh = mesh
            });

            return(printObject);
        }
        public static async Task <FitToCylinderObject3D> Create(IObject3D itemToFit)
        {
            var fitToBounds = new FitToCylinderObject3D();

            using (fitToBounds.RebuildLock())
            {
                using (new CenterAndHeightMantainer(itemToFit))
                {
                    var aabb   = itemToFit.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);

                    fitToBounds.Diameter     = Math.Sqrt(aabb.XSize * aabb.XSize + aabb.YSize * aabb.YSize);
                    fitToBounds.boundsSize.Z = aabb.ZSize;

                    fitToBounds.SizeZ = aabb.ZSize;

                    await fitToBounds.Rebuild();
                }
            }

            return(fitToBounds);
        }
Exemplo n.º 7
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            var width         = Width.ClampIfNotCalculated(this, MinEdgeSize, 1000000, ref valuesChanged);
            var depth         = Depth.ClampIfNotCalculated(this, MinEdgeSize, 1000000, ref valuesChanged);
            var height        = Height.ClampIfNotCalculated(this, MinEdgeSize, 1000000, ref valuesChanged);
            var roundSegments = RoundSegments.ClampIfNotCalculated(this, 1, 90, ref valuesChanged);
            var roundRadius   = Radius.ClampIfNotCalculated(this, 0, Math.Min(width, Math.Min(depth, height)) / 2, ref valuesChanged);

            Invalidate(InvalidateType.DisplayValues);

            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    if (Round)
                    {
                        Mesh = RoundedCornerBox.Create(roundSegments, new Vector3(width, depth, height), roundRadius);
                    }
                    else
                    {
                        Mesh = PlatonicSolids.CreateCube(Width.Value(this), Depth.Value(this), Height.Value(this));
                    }
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 8
0
        public void AmfFilesSaveObjectProperties()
        {
            AssetObject3D.AssetManager = new AssetManager();

            var scene = new InteractiveScene();

            scene.Children.Add(new Object3D
            {
                Mesh          = PlatonicSolids.CreateCube(20, 20, 20),
                Name          = "test1",
                OutputType    = PrintOutputTypes.Support,
                Color         = Color.Red,
                MaterialIndex = 2,
            });

            scene.Children.Add(new Object3D
            {
                Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                Name   = "test2",
                Matrix = Matrix4X4.CreateTranslation(30, 0, 0)
            });

            string tempPath = GetSceneTempPath();

            Object3D.AssetsPath = Path.Combine(tempPath, "Assets");

            string filePath = Path.Combine(tempPath, "exportTest.amf");

            scene.SetSelection(scene.Children.ToList());
            AmfDocument.Save(scene.SelectedItem, filePath);

            Assert.IsTrue(File.Exists(filePath));

            IObject3D loadedItem = Object3D.Load(filePath, CancellationToken.None);

            Assert.IsTrue(loadedItem.Children.Count == 2);

            IObject3D item1 = loadedItem.Children.Last();

            Assert.AreEqual("test1", item1.Name);
            Assert.AreEqual(PrintOutputTypes.Support, item1.OutputType);
            Assert.AreEqual(2, item1.MaterialIndex);
            Assert.AreEqual(Color.Red, item1.Color);
            Assert.AreEqual(12, item1.Mesh.Faces.Count);
            var aabb1 = item1.GetAxisAlignedBoundingBox();

            Assert.True(new AxisAlignedBoundingBox(-10, -10, -10, 10, 10, 10).Equals(aabb1, .001));

            IObject3D item2 = loadedItem.Children.First();

            Assert.AreEqual("test2", item2.Name);
            Assert.AreEqual(Color.White, item2.Color);
            Assert.AreEqual(12, item2.Mesh.Faces.Count);
            var aabb2 = item2.GetAxisAlignedBoundingBox();

            Assert.True(new AxisAlignedBoundingBox(20, -10, -10, 40, 10, 10).Equals(aabb2, .001));
        }
        public override Task Rebuild()
        {
            using (new CenterAndHeightMaintainer(this))
            {
                this.Mesh = PlatonicSolids.CreateCube(20, 20, 20);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 10
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            var rebuildLock = RebuildLock();

            return(Task.Run(() =>
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    bool valuesChanged = false;
                    var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
                    var nameToWrite = NameToWrite.Value(this);
                    if (string.IsNullOrWhiteSpace(nameToWrite))
                    {
                        Mesh = PlatonicSolids.CreateCube(20, 10, height);
                    }
                    else
                    {
                        Mesh = null;
                        this.Children.Modify(list =>
                        {
                            list.Clear();

                            var offest = 0.0;
                            double pointsToMm = 0.352778;

                            foreach (var letter in nameToWrite.ToCharArray())
                            {
                                var style = new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), PointSize.Value(this));
                                var letterPrinter = new TypeFacePrinter(letter.ToString(), style)
                                {
                                    ResolutionScale = 10
                                };
                                var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));

                                list.Add(new Object3D()
                                {
                                    Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height.Value(this)),
                                    Matrix = Matrix4X4.CreateTranslation(offest, 0, 0),
                                    Name = letter.ToString()
                                });

                                offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                            }
                        });
                    }
                }

                UiThread.RunOnIdle(() =>
                {
                    rebuildLock.Dispose();
                    Invalidate(InvalidateType.DisplayValues);
                    Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                });
            }));
        }
Exemplo n.º 11
0
        private Mesh GetNormalShadowMesh()
        {
            if (normalShadowMesh == null)
            {
                normalShadowMesh = PlatonicSolids.CreateCube(1, 1, .1);
            }

            return(normalShadowMesh);
        }
Exemplo n.º 12
0
        public ScaleMatrixEdgeControl(IObject3DControlContext context, int edgeIndex)
            : base(context)
        {
            theme = MatterControl.AppContext.Theme;

            xValueDisplayInfo = new InlineEditControl()
            {
                ForceHide        = ForceHideScale,
                GetDisplayString = (value) => "{0:0.0}".FormatWith(value),
            };

            xValueDisplayInfo.EditComplete += EditComplete;

            xValueDisplayInfo.VisibleChanged += (s, e) =>
            {
                if (!xValueDisplayInfo.Visible)
                {
                    hadClickOnControl = false;
                }
            };

            yValueDisplayInfo = new InlineEditControl()
            {
                ForceHide        = ForceHideScale,
                GetDisplayString = (value) => "{0:0.0}".FormatWith(value)
            };

            yValueDisplayInfo.EditComplete += EditComplete;

            yValueDisplayInfo.VisibleChanged += (s, e) =>
            {
                if (!yValueDisplayInfo.Visible)
                {
                    hadClickOnControl = false;
                }
            };

            if (edgeIndex % 2 == 1)
            {
                Object3DControlContext.GuiSurface.AddChild(xValueDisplayInfo);
            }
            else
            {
                Object3DControlContext.GuiSurface.AddChild(yValueDisplayInfo);
            }

            this.edgeIndex = edgeIndex;

            DrawOnTop = true;

            minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize);

            CollisionVolume = minXminYMesh.CreateBVHData();

            Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw;
        }
Exemplo n.º 13
0
        public async Task <IObject3D> CreateItem(ILibraryItem item, Action <double, string> reporter)
        {
            const double DefaultSizeMm = 40;

            return(await Task.Run(async() =>
            {
                if (imageBuffer != null)
                {
                    // Build an ImageBuffer from some svg content
                    double scaleMmPerPixels = Math.Min(DefaultSizeMm / imageBuffer.Width, DefaultSizeMm / imageBuffer.Height);

                    // Create texture mesh
                    double width = scaleMmPerPixels * imageBuffer.Width;
                    double height = scaleMmPerPixels * imageBuffer.Height;

                    Mesh textureMesh = PlatonicSolids.CreateCube(width, height, 0.2);
                    textureMesh.PlaceTextureOnFaces(0, imageBuffer);

                    string assetPath = null;

                    if (item is ILibraryAssetStream assetStream)
                    {
                        assetPath = assetStream.AssetPath;

                        if (string.IsNullOrWhiteSpace(assetPath))
                        {
                            using (var streamAndLength = await assetStream.GetStream(null))
                            {
                                string assetID = AssetObject3D.AssetManager.StoreStream(streamAndLength.Stream, ".svg");
                                assetPath = assetID;
                            }
                        }
                    }

                    var svgObject = new SvgObject3D()
                    {
                        DString = "",                         // How to acquire?
                        SvgPath = assetPath
                    };

                    svgObject.Children.Add(new Object3D()
                    {
                        Mesh = textureMesh
                    });

                    await svgObject.Rebuild();

                    return svgObject;
                }
                else
                {
                    return null;
                }
            }));
        }
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            tabScale = 3;

            // by default we don't want tab with to be greater than 10 mm
            if (TabWidth > 10)
            {
                tabScale = 1;
            }
            else if (TabWidth > 5)
            {
                tabScale = 2;
            }

            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    this.Children.Modify((list) =>
                    {
                        list.Clear();
                    });

                    var calibrateX = GetTab(true);
                    this.Children.Add(calibrateX);
                    var calibrateY = GetTab(false);
                    this.Children.Add(calibrateY);
                    // add in the corner connector
                    this.Children.Add(new Object3D()
                    {
                        Mesh   = PlatonicSolids.CreateCube(),
                        Matrix = Matrix4X4.CreateTranslation(-1 / 2.0, 1 / 2.0, 1 / 2.0) * Matrix4X4.CreateScale(TabDepth, TabDepth, BaseHeight),
                        Color  = Color.LightBlue
                    });

                    if (WipeTowerSize > 0)
                    {
                        // add in the wipe tower
                        this.Children.Add(new Object3D()
                        {
                            Mesh   = new CylinderObject3D(1, 1, 50).Mesh,
                            Matrix = Matrix4X4.CreateTranslation(1 / 2.0, 1 / 2.0, 1 / 2.0)
                                     * Matrix4X4.CreateScale(WipeTowerSize, WipeTowerSize, BaseHeight + Layers * ChangingHeight)
                                     * Matrix4X4.CreateTranslation(TabDepth * 1, TabDepth * 2, 0),
                            OutputType = PrintOutputTypes.WipeTower
                        });
                    }
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
 public TracedPositionObject3DControl(IObject3DControlContext context, IObject3D owner, Func <Vector3> getPosition, Action <Vector3> setPosition)
 {
     this.theme       = ApplicationController.Instance.Theme;
     this.context     = context;
     this.getPosition = getPosition;
     this.setPosition = setPosition;
     this.shape       = PlatonicSolids.CreateCube();
     this.shape       = SphereObject3D.CreateSphere(1, 15, 10);
     collisionVolume  = shape.CreateBVHData();
     this.owner       = owner;
 }
Exemplo n.º 16
0
        public void Draw(GuiWidget sender, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world)
        {
            Mesh xAxis = PlatonicSolids.CreateCube(big, small, small);

            GLHelper.Render(xAxis, Color.Red);
            Mesh yAxis = PlatonicSolids.CreateCube(small, big, small);

            GLHelper.Render(yAxis, Color.Green);
            Mesh zAxis = PlatonicSolids.CreateCube(small, small, big);

            GLHelper.Render(zAxis, Color.Blue);
        }
Exemplo n.º 17
0
        public PolygonMesh.Mesh CsgToMeshRecursive(BoxPrimitive objectToProcess)
        {
            if (objectToProcess.CreateCentered)
            {
                //objectToProcess.Size;
            }
            else
            {
            }

            return(PlatonicSolids.CreateCube(objectToProcess.Size));
        }
Exemplo n.º 18
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            var rebuildLock = RebuildLock();

            return(ApplicationController.Instance.Tasks.Execute(
                       "Generating Text Meshes".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    if (string.IsNullOrWhiteSpace(NameToWrite))
                    {
                        Mesh = PlatonicSolids.CreateCube(20, 10, Height);
                    }
                    else
                    {
                        Mesh = null;
                        this.Children.Modify(list =>
                        {
                            list.Clear();

                            var offest = 0.0;
                            double pointsToMm = 0.352778;

                            foreach (var letter in this.NameToWrite.ToCharArray())
                            {
                                var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), this.PointSize))
                                {
                                    ResolutionScale = 10
                                };
                                var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));

                                list.Add(new Object3D()
                                {
                                    Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height),
                                    Matrix = Matrix4X4.CreateTranslation(offest, 0, 0),
                                    Name = letter.ToString()
                                });

                                offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                            }
                        });
                    }
                }

                rebuildLock.Dispose();
                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                return Task.CompletedTask;
            }));
        }
Exemplo n.º 19
0
        private void trackballTumbleWidget_DrawGlContent(object sender, EventArgs e)
        {
            for (int groupIndex = 0; groupIndex < MeshGroups.Count; groupIndex++)
            {
                MeshGroup meshGroupToRender = MeshGroups[groupIndex];

                int part = 0;
                foreach (Mesh meshToRender in meshGroupToRender.Meshes)
                {
                    MeshMaterialData meshData  = MeshMaterialData.Get(meshToRender);
                    RGBA_Bytes       drawColor = GetMaterialColor(meshData.MaterialIndex);
                    if (meshGroupToRender == SelectedMeshGroup)
                    {
                        drawColor = GetSelectedMaterialColor(meshData.MaterialIndex);
                    }

                    RenderMeshToGl.Render(meshToRender, drawColor, MeshGroupTransforms[groupIndex].TotalTransform, RenderType);
                    part++;
                }
            }

            foreach (InteractionVolume interactionVolume in interactionVolumes)
            {
                interactionVolume.DrawGlContent(e);
            }

            // we don't want to render the bed or bulid volume before we load a model.
            if (MeshGroups.Count > 0 || AllowBedRenderingWhenEmpty)
            {
                if (RenderBed)
                {
                    RenderMeshToGl.Render(printerBed, this.BedColor);
                }

                if (buildVolume != null && RenderBuildVolume)
                {
                    RenderMeshToGl.Render(buildVolume, this.BuildVolumeColor);
                }

                if (false)                 // this is code to draw a small axis indicator
                {
                    double big   = 10;
                    double small = 1;
                    Mesh   xAxis = PlatonicSolids.CreateCube(big, small, small);
                    RenderMeshToGl.Render(xAxis, RGBA_Bytes.Red);
                    Mesh yAxis = PlatonicSolids.CreateCube(small, big, small);
                    RenderMeshToGl.Render(yAxis, RGBA_Bytes.Green);
                    Mesh zAxis = PlatonicSolids.CreateCube(small, small, big);
                    RenderMeshToGl.Render(zAxis, RGBA_Bytes.Blue);
                }
            }
        }
Exemplo n.º 20
0
        public override void DrawGlContent(EventArgs e)
        {
            if (MeshViewerToDrawWith.SelectedMeshGroup != null)
            {
                // draw the bounds on the bed
                AxisAlignedBoundingBox selectedBounds = MeshViewerToDrawWith.GetBoundsForSelection();

                Mesh bottomBounds = PlatonicSolids.CreateCube(selectedBounds.XSize, selectedBounds.YSize, .1);
                RenderMeshToGl.Render(bottomBounds, new RGBA_Bytes(22, 80, 220, 30), TotalTransform, RenderTypes.Shaded);
            }

            base.DrawGlContent(e);
        }
Exemplo n.º 21
0
        public void UnionExactlyOnWorks()
        {
            Mesh meshA = PlatonicSolids.CreateCube(40, 40, 40);
            Mesh meshB = PlatonicSolids.CreateCube(40, 40, 40);

            Mesh meshToAdd = CsgOperations.Union(meshA, meshB);

            AxisAlignedBoundingBox a_aabb         = meshA.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox b_aabb         = meshB.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox intersect_aabb = meshToAdd.GetAxisAlignedBoundingBox();

            Assert.IsTrue(a_aabb.XSize == 40 && a_aabb.YSize == 40 && a_aabb.ZSize == 40);
            Assert.IsTrue(intersect_aabb.XSize == 40 && intersect_aabb.YSize == 40 && intersect_aabb.ZSize == 40);
        }
Exemplo n.º 22
0
        public ScaleCornerControl(IInteractionVolumeContext context, int cornerIndex)
            : base(context)
        {
            theme = MatterControl.AppContext.Theme;

            xValueDisplayInfo = new InlineEditControl()
            {
                ForceHide        = ForceHideScale,
                GetDisplayString = (value) => "{0:0.0}mm".FormatWith(value),
            };

            xValueDisplayInfo.EditComplete += EditComplete;

            xValueDisplayInfo.VisibleChanged += (s, e) =>
            {
                if (!xValueDisplayInfo.Visible)
                {
                    HadClickOnControl = false;
                }
            };

            yValueDisplayInfo = new InlineEditControl()
            {
                ForceHide        = ForceHideScale,
                GetDisplayString = (value) => "{0:0.0}mm".FormatWith(value)
            };

            yValueDisplayInfo.EditComplete += EditComplete;

            yValueDisplayInfo.VisibleChanged += (s, e) =>
            {
                if (!yValueDisplayInfo.Visible)
                {
                    HadClickOnControl = false;
                }
            };

            InteractionContext.GuiSurface.AddChild(xValueDisplayInfo);
            InteractionContext.GuiSurface.AddChild(yValueDisplayInfo);

            this.quadrantIndex = cornerIndex;

            DrawOnTop = true;

            minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize);

            CollisionVolume = minXminYMesh.CreateBVHData();

            InteractionContext.GuiSurface.AfterDraw += InteractionLayer_AfterDraw;
        }
        public override void OnDraw(Graphics2D graphics2D)
        {
            base.OnDraw(graphics2D);

            this.SetGlContext();

            foreach (var object3D in Scene.Children)
            {
                DrawObject(object3D, false);
            }

            if (RenderBed)
            {
                GLHelper.Render(printerBed, this.BedColor);
            }

            if (buildVolume != null && RenderBuildVolume)
            {
                GLHelper.Render(buildVolume, this.BuildVolumeColor);
            }

            // we don't want to render the bed or build volume before we load a model.
            if (Scene.HasChildren() || AllowBedRenderingWhenEmpty)
            {
                if (false)                 // this is code to draw a small axis indicator
                {
                    double big   = 10;
                    double small = 1;
                    Mesh   xAxis = PlatonicSolids.CreateCube(big, small, small);
                    GLHelper.Render(xAxis, Color.Red);
                    Mesh yAxis = PlatonicSolids.CreateCube(small, big, small);
                    GLHelper.Render(yAxis, Color.Green);
                    Mesh zAxis = PlatonicSolids.CreateCube(small, small, big);
                    GLHelper.Render(zAxis, Color.Blue);
                }
            }

            DrawInteractionVolumes();

            //if (!SuppressUiVolumes)
            {
                foreach (InteractionVolume interactionVolume in interactionVolumes)
                {
                    interactionVolume.Draw2DContent(graphics2D);
                }
            }

            this.UnsetGlContext();
        }
Exemplo n.º 24
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    Mesh = PlatonicSolids.CreateCube(Width, Depth, Height);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 25
0
        public void UnionExactlyOnWorks()
        {
            Mesh meshA = PlatonicSolids.CreateCube(40, 40, 40);
            Mesh meshB = PlatonicSolids.CreateCube(40, 40, 40);

            Mesh result = CsgOperations.Union(meshA, meshB);

            AxisAlignedBoundingBox a_aabb         = meshA.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox b_aabb         = meshB.GetAxisAlignedBoundingBox();
            AxisAlignedBoundingBox intersect_aabb = result.GetAxisAlignedBoundingBox();

            Assert.IsTrue(a_aabb.XSize == 40 && a_aabb.YSize == 40 && a_aabb.ZSize == 40);
            Assert.IsTrue(intersect_aabb.XSize == 40 && intersect_aabb.YSize == 40 && intersect_aabb.ZSize == 40);

            // Todo: turn this on
            //Assert.IsTrue(result.IsManifold());
        }
Exemplo n.º 26
0
        private void AddSupportColumn(IObject3D holder, double gridX, double gridY, double bottomZ, double topZ)
        {
            if (topZ - bottomZ < .01)
            {
                // less than 10 micros high, don't ad it
                return;
            }
            var support = new GeneratedSupportObject3D()
            {
                Mesh = PlatonicSolids.CreateCube(1, 1, 1)
            };

            support.Matrix = Matrix4X4.CreateScale(PillarSize - reduceAmount, PillarSize - reduceAmount, topZ - bottomZ)
                             * Matrix4X4.CreateTranslation(gridX, gridY, bottomZ + (topZ - bottomZ) / 2);

            holder.Children.Add(support);
        }
Exemplo n.º 27
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                Mesh = PlatonicSolids.CreateCube(Width, Depth, Height);

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
Exemplo n.º 28
0
        public void EnsureSimpleCubeIntersection()
        {
            // the intersection of 2 cubes
            {
                Mesh meshA = PlatonicSolids.CreateCube(new Vector3(10, 10, 10));

                meshA.Translate(new Vector3(-2, -2, -2));
                Mesh meshB = PlatonicSolids.CreateCube(new Vector3(10, 10, 10));
                meshB.Translate(new Vector3(2, 2, 2));

                Mesh result = CsgOperations.Intersect(meshA, meshB);

                AxisAlignedBoundingBox a_aabb         = meshA.GetAxisAlignedBoundingBox();
                AxisAlignedBoundingBox b_aabb         = meshB.GetAxisAlignedBoundingBox();
                AxisAlignedBoundingBox intersect_aabb = result.GetAxisAlignedBoundingBox();

                Assert.IsTrue(a_aabb.XSize == 10 && a_aabb.YSize == 10 && a_aabb.ZSize == 10);
                Assert.IsTrue(intersect_aabb.XSize == 6 && intersect_aabb.YSize == 6 && intersect_aabb.ZSize == 6);

                // Todo: turn this on
                //Assert.IsTrue(result.IsManifold());
            }

            // the intersection of 2 cubes that miss eachother
            {
                Mesh meshA = PlatonicSolids.CreateCube(new Vector3(10, 10, 10));

                meshA.Translate(new Vector3(-5, -5, -5));
                Mesh meshB = PlatonicSolids.CreateCube(new Vector3(10, 10, 10));
                meshB.Translate(new Vector3(5, 5, 5));

                Mesh result = CsgOperations.Intersect(meshA, meshB);

                AxisAlignedBoundingBox a_aabb         = meshA.GetAxisAlignedBoundingBox();
                AxisAlignedBoundingBox b_aabb         = meshB.GetAxisAlignedBoundingBox();
                AxisAlignedBoundingBox intersect_aabb = result.GetAxisAlignedBoundingBox();

                Assert.IsTrue(a_aabb.XSize == 10 && a_aabb.YSize == 10 && a_aabb.ZSize == 10);
                Assert.IsTrue(intersect_aabb.XSize == 0 && intersect_aabb.YSize == 0 && intersect_aabb.ZSize == 0);

                // Todo: turn this on
                //Assert.IsTrue(result.IsManifold());
            }
        }
Exemplo n.º 29
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            using (RebuildLock())
            {
                using (new CenterAndHeightMantainer(this))
                {
                    this.Children.Modify((list) =>
                    {
                        list.Clear();
                    });

                    var calibrateX = GetTab(true);
                    this.Children.Add(calibrateX);
                    var calibrateY = GetTab(false);
                    this.Children.Add(calibrateY);
                    // add in the corner connecter
                    this.Children.Add(new Object3D()
                    {
                        Mesh   = PlatonicSolids.CreateCube(),
                        Matrix = Matrix4X4.CreateTranslation(-1 / 2.0, 1 / 2.0, 1 / 2.0) * Matrix4X4.CreateScale(TabDepth, TabDepth, ChangeHeight),
                        Color  = Color.LightBlue
                    });

                    if (WipeTowerSize > 0)
                    {
                        // add in the wipe tower
                        this.Children.Add(new Object3D()
                        {
                            Mesh   = PlatonicSolids.CreateCube(),
                            Matrix = Matrix4X4.CreateTranslation(1 / 2.0, 1 / 2.0, 1 / 2.0)
                                     * Matrix4X4.CreateScale(WipeTowerSize, WipeTowerSize, ChangeHeight * 2)
                                     * Matrix4X4.CreateTranslation(TabDepth * 1, TabDepth * 2, 0),
                            OutputType = PrintOutputTypes.WipeTower
                        });
                    }
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 30
0
        private void CreateUnderline(List <MeshGroup> meshesList, List <ScaleRotateTranslate> meshTransforms, List <PlatingMeshGroupData> platingDataList)
        {
            if (meshesList.Count > 0)
            {
                AxisAlignedBoundingBox bounds = meshesList[0].GetAxisAlignedBoundingBox(meshTransforms[0].TotalTransform);
                for (int i = 1; i < meshesList.Count; i++)
                {
                    bounds = AxisAlignedBoundingBox.Union(bounds, meshesList[i].GetAxisAlignedBoundingBox(meshTransforms[i].TotalTransform));
                }

                double xSize          = bounds.XSize;
                double ySize          = sizeScrollBar.Value * 3;
                double zSize          = bounds.ZSize / 3;
                Mesh   connectionLine = PlatonicSolids.CreateCube(xSize, ySize, zSize);
                meshesList.Add(new MeshGroup(connectionLine));
                platingDataList.Add(new PlatingMeshGroupData());
                meshTransforms.Add(ScaleRotateTranslate.CreateTranslation((bounds.maxXYZ.x + bounds.minXYZ.x) / 2, bounds.minXYZ.y + ySize / 2 - ySize * 1 / 3, zSize / 2));
                PlatingHelper.CreateITraceableForMeshGroup(platingDataList, meshesList, meshesList.Count - 1, null);
            }
        }