예제 #1
0
        public void RemoveExisting()
        {
            scene.SelectedItem = null;
            var existingSupports = scene.Descendants().Where(i => i.GetType() == typeof(GeneratedSupportObject3D));

            scene.UndoBuffer.AddAndDo(new DeleteCommand(scene, existingSupports.ToList()));
        }
예제 #2
0
        public void RemoveExisting()
        {
            var selectedItem = scene.SelectedItem;
            var bedBounds    = new RectangleDouble(Vector2.NegativeInfinity, Vector2.PositiveInfinity);

            if (selectedItem != null)
            {
                var aabb = selectedItem.GetAxisAlignedBoundingBox();
                bedBounds = new RectangleDouble(new Vector2(aabb.MinXYZ), new Vector2(aabb.MaxXYZ));
            }

            using (new SelectionMaintainer(scene))
            {
                var existingSupports = scene.Descendants().Where(i =>
                {
                    if (i.GetType() == typeof(GeneratedSupportObject3D))
                    {
                        // we have a support, check if it is within the bounds of the selected object
                        var xyCenter = new Vector2(i.GetAxisAlignedBoundingBox().Center);
                        if (bedBounds.Contains(xyCenter))
                        {
                            return(true);
                        }
                    }

                    return(false);
                });

                scene.UndoBuffer.AddAndDo(new DeleteCommand(scene, existingSupports.ToList()));
            }
        }
예제 #3
0
        private void DrawGlContent(DrawEventArgs e)
        {
            var gcodeOptions = sceneContext.RendererOptions;

            if (gcodeOptions.GCodeModelView)
            {
                modelRenderStyle = ModelRenderStyle.WireframeAndSolid;
            }
            else
            {
                modelRenderStyle = ModelRenderStyle.None;
            }

            foreach (var drawable in drawables.Where(d => d.DrawStage == DrawStage.First))
            {
                if (drawable.Enabled)
                {
                    drawable.Draw(this, e, Matrix4X4.Identity, this.World);
                }
            }

            GLHelper.SetGlContext(this.World, renderSource.TransformToScreenSpace(renderSource.LocalBounds), lighting);

            foreach (var drawable in drawables.Where(d => d.DrawStage == DrawStage.OpaqueContent))
            {
                if (drawable.Enabled)
                {
                    drawable.Draw(this, e, Matrix4X4.Identity, this.World);
                }
            }

            // Draw solid objects, extract transparent
            var transparentMeshes = new List <Object3DView>();

            var selectedItem = scene.SelectedItem;

            editorDrawItems.Clear();
            editorDrawItems.Add(selectedItem);

            foreach (var item in scene.Children)
            {
                if (item.Visible)
                {
                    DrawObject(item, transparentMeshes, e);
                }
            }

            foreach (var item in scene.Descendants().Where(i => i is IAlwaysEditorDraw))
            {
                editorDrawItems.Add(item);
            }

            if (sceneContext.Printer?.Connection?.serialPort is PrinterEmulator.Emulator emulator)
            {
                void NozzlePositionChanged(object s, EventArgs e2)
                {
                    // limit max number of updates per second to 10
                    if (UiThread.CurrentTimerMs > lastEmulatorDrawMs + 100)
                    {
                        UiThread.RunOnIdle(Invalidate);
                        // set it to now
                        lastEmulatorDrawMs = UiThread.CurrentTimerMs;
                    }
                }

                var matrix = Matrix4X4.CreateTranslation(emulator.CurrentPosition + new Vector3(.5, .5, 5));
                GLHelper.Render(emulatorNozzleMesh,
                                MaterialRendering.Color(sceneContext.Printer, emulator.ExtruderIndex),
                                matrix,
                                RenderTypes.Shaded,
                                matrix * World.ModelviewMatrix);

                if (!emulatorHooked)
                {
                    emulator.DestinationChanged += NozzlePositionChanged;
                    emulatorHooked = true;
                }

                Closed += (s, e3) => emulator.DestinationChanged -= NozzlePositionChanged;
            }

            transparentMeshes.Sort(BackToFrontXY);

            var bedNormalInViewSpace  = Vector3Ex.TransformNormal(Vector3.UnitZ, World.ModelviewMatrix).GetNormal();
            var pointOnBedInViewSpace = Vector3Ex.Transform(new Vector3(10, 10, 0), World.ModelviewMatrix);
            var lookingDownOnBed      = Vector3Ex.Dot(bedNormalInViewSpace, pointOnBedInViewSpace) < 0;

            floorDrawable.LookingDownOnBed = lookingDownOnBed;

            if (lookingDownOnBed)
            {
                floorDrawable.Draw(this, e, Matrix4X4.Identity, this.World);
            }

            var wireColor = Color.Transparent;

            switch (modelRenderStyle)
            {
            case ModelRenderStyle.Wireframe:
                wireColor = darkWireframe;
                break;

            case ModelRenderStyle.WireframeAndSolid:
                wireColor = lightWireframe;
                break;
            }

            // Draw transparent objects
            foreach (var item in transparentMeshes)
            {
                GL.Enable(EnableCap.Lighting);

                var object3D = item.Object3D;
                GLHelper.Render(
                    object3D.Mesh,
                    item.Color,
                    object3D.WorldMatrix(),
                    RenderTypes.Outlines,
                    object3D.WorldMatrix() * World.ModelviewMatrix,
                    wireColor,
                    allowBspRendering: transparentMeshes.Count < 1000);
            }

            if (!lookingDownOnBed)
            {
                floorDrawable.Draw(this, e, Matrix4X4.Identity, this.World);
            }

            // Draw the editor items in the same scope as the 3D Controls
            foreach (var item in editorDrawItems)
            {
                // Invoke existing IEditorDraw when iterating items
                if (item is ISelectedEditorDraw editorDraw)
                {
                    editorDraw.DrawEditor(this, transparentMeshes, e);
                }
            }

            DrawObject3DControlVolumes(e);

            foreach (var drawable in drawables.Where(d => d.DrawStage == DrawStage.TransparentContent))
            {
                if (drawable.Enabled)
                {
                    drawable.Draw(this, e, Matrix4X4.Identity, this.World);
                }
            }

            GLHelper.UnsetGlContext();

            // Invoke DrawStage.Last item drawables
            foreach (var item in scene.Children)
            {
                // HACK: Consider how shared code in DrawObject can be reused to prevent duplicate execution
                bool isSelected = selectedItem != null &&
                                  selectedItem.DescendantsAndSelf().Any((i) => i == item);

                foreach (var itemDrawable in itemDrawables.Where(d => d.DrawStage == DrawStage.Last && d.Enabled))
                {
                    itemDrawable.Draw(this, item, isSelected, e, Matrix4X4.Identity, this.World);
                }
            }

            // Invoke DrawStage.Last scene drawables
            foreach (var drawable in drawables.Where(d => d.DrawStage == DrawStage.Last))
            {
                if (drawable.Enabled)
                {
                    drawable.Draw(this, e, Matrix4X4.Identity, this.World);
                }
            }
        }