public static int WorldMaterialIndex(this IObject3D child, IObject3D rootOverride = null, bool includingRoot = true)
        {
            var lastMaterialIndexFound = -1;

            foreach (var item in child.AncestorsAndSelf())
            {
                if (!includingRoot &&
                    item == rootOverride)
                {
                    // exit before the root item is included
                    break;
                }

                if (item.MaterialIndex != -1)
                {
                    // use collection as the color for all recursive children
                    lastMaterialIndexFound = item.MaterialIndex;
                }

                // If the root override has been matched, break and return latest
                if (item == rootOverride)
                {
                    break;
                }
            }

            // If we don't find a color (-1) return 0
            return(lastMaterialIndexFound);
        }
        public static PrintOutputTypes WorldOutputType(this IObject3D child, IObject3D rootOverride = null, bool includingRoot = true)
        {
            var lastOutputTypeFound = PrintOutputTypes.Default;

            foreach (var item in child.AncestorsAndSelf())
            {
                if (!includingRoot &&
                    item == rootOverride)
                {
                    // exit before the root item is included
                    break;
                }

                if (item.OutputType != PrintOutputTypes.Default)
                {
                    // use collection as the color for all recursive children
                    lastOutputTypeFound = item.OutputType;
                }

                // If the root override has been matched, break and return latest
                if (item == rootOverride)
                {
                    break;
                }
            }

            return(lastOutputTypeFound);
        }
        public static bool WorldVisible(this IObject3D child, IObject3D rootOverride = null, bool includingRoot = true)
        {
            foreach (var item in child.AncestorsAndSelf())
            {
                if (!includingRoot &&
                    item == rootOverride)
                {
                    // exit before the root item is included
                    break;
                }

                if (!item.Visible)
                {
                    return(false);
                }

                // If the root override has been matched, break and return latest
                if (item == rootOverride)
                {
                    break;
                }
            }

            return(true);
        }
Beispiel #4
0
        public static Color WorldColor(this IObject3D child, IObject3D rootOverride = null, bool includingRoot = true)
        {
            var lastColorFound = Color.White;

            foreach (var item in child.AncestorsAndSelf())
            {
                if (!includingRoot &&
                    item == rootOverride)
                {
                    // exit before the root item is included
                    break;
                }

                // if we find a color it overrides our current color so set it
                if (item.Color.Alpha0To255 != 0)
                {
                    lastColorFound = item.Color;
                }

                // If the root override has been matched, break and return latest
                if (item == rootOverride)
                {
                    break;
                }
            }

            return(lastColorFound);
        }
Beispiel #5
0
        private Color GetItemColor(IObject3D item, IObject3D selectedItem)
        {
            Color drawColor = item.WorldColor();

            if (item.WorldOutputType() == PrintOutputTypes.Support)
            {
                drawColor = new Color(Color.Yellow, 120);
            }
            else if (item.WorldOutputType() == PrintOutputTypes.WipeTower)
            {
                drawColor = new Color(Color.Cyan, 120);
            }

            // If there is a printer - check if the object is within the bed volume (has no AABB outside the bed volume)
            if (sceneContext.Printer != null)
            {
                if (!sceneContext.Printer.InsideBuildVolume(item))
                {
                    drawColor = new Color(drawColor, 65);
                }
            }

            // check if we should be rendering materials (this overrides the other colors)
            if (sceneContext.ViewState.RenderType == RenderTypes.Materials)
            {
                drawColor = MaterialRendering.Color(item.WorldMaterialIndex());
            }

            if (drawColor.alpha != 255 &&
                item is Object3D item3D)
            {
                item3D.EnsureTransparentSorting();
            }

            if (selectedItem is ISelectableChildContainer selectableChildContainer)
            {
                if (item.AncestorsAndSelf().Any(i => selectableChildContainer.SelectedChildren.Contains(i.ID)))
                {
                    drawColor = new Color(drawColor, 200);
                }
            }

            if (!sceneContext.ViewState.ModelView)
            {
                if (modelRenderStyle == ModelRenderStyle.WireframeAndSolid)
                {
                    drawColor = gCodeMeshColor;
                }
                else if (modelRenderStyle == ModelRenderStyle.Wireframe)
                {
                    drawColor = new Color(gCodeMeshColor, 1);
                }
                else if (modelRenderStyle == ModelRenderStyle.None)
                {
                    drawColor = Color.Transparent;
                }
            }

            return(drawColor);
        }
        public static Matrix4X4 WorldMatrix(this IObject3D child, IObject3D rootOverride = null)
        {
            var matrix = Matrix4X4.Identity;

            foreach (var item in child.AncestorsAndSelf())
            {
                matrix *= item.Matrix;
                if (item == rootOverride)
                {
                    break;
                }
            }

            return(matrix);
        }
        public static Color WorldColor(this IObject3D child, IObject3D rootOverride = null, bool includingRoot = true, bool checkOutputType = false)
        {
            var lastColorFound = Color.White;

            foreach (var item in child.AncestorsAndSelf())
            {
                if (!includingRoot &&
                    item == rootOverride)
                {
                    // exit before the root item is included
                    break;
                }

                // if we find a color it overrides our current color so set it
                if (item.Color.Alpha0To255 != 0)
                {
                    lastColorFound = item.Color;
                }

                if (checkOutputType)
                {
                    if (item.WorldOutputType() == PrintOutputTypes.Support)
                    {
                        lastColorFound = new Color(Color.Yellow, 120);
                    }
                    else if (item.WorldOutputType() == PrintOutputTypes.WipeTower)
                    {
                        lastColorFound = new Color(Color.Cyan, 120);
                    }
                    else if (item.WorldOutputType() == PrintOutputTypes.Fuzzy)
                    {
                        lastColorFound = new Color(108, 209, 98, 120);
                    }
                    else if (item.WorldOutputType() == PrintOutputTypes.Hole)
                    {
                        lastColorFound = Color.DarkGray.WithAlpha(120);
                    }
                }

                // If the root override has been matched, break and return latest
                if (item == rootOverride)
                {
                    break;
                }
            }

            return(lastColorFound);
        }
        public static bool WorldPrintable(this IObject3D child, IObject3D rootOverride = null)
        {
            foreach (var item in child.AncestorsAndSelf())
            {
                if (!item.Printable)
                {
                    return(false);
                }

                // If the root override has been matched, break and return latest
                if (item == rootOverride)
                {
                    break;
                }
            }

            return(true);
        }
        public static bool WorldPersistable(this IObject3D child, IObject3D rootOverride = null)
        {
            foreach (var item in child.AncestorsAndSelf())
            {
                // if we find a color it overrides our current color so set it
                if (!item.Persistable)
                {
                    return(false);
                }

                // If the root override has been matched, break and return latest
                if (item == rootOverride)
                {
                    break;
                }
            }

            return(true);
        }
        public static Matrix4X4 WorldMatrix(this IObject3D child, IObject3D rootOverride = null, bool includingRoot = true)
        {
            var matrix = Matrix4X4.Identity;

            foreach (var item in child.AncestorsAndSelf())
            {
                if (!includingRoot &&
                    item == rootOverride)
                {
                    // exit before the root item is included
                    break;
                }

                matrix *= item.Matrix;
                if (item == rootOverride)
                {
                    break;
                }
            }

            return(matrix);
        }
Beispiel #11
0
        private Color GetItemColor(IObject3D item, IObject3D selectedItem)
        {
            Color drawColor = item.WorldColor();

            if (item.WorldOutputType() == PrintOutputTypes.Support)
            {
                drawColor = new Color(Color.Yellow, 120);
            }
            else if (item.WorldOutputType() == PrintOutputTypes.WipeTower)
            {
                drawColor = new Color(Color.Cyan, 120);
            }
            else if (sceneContext.ViewState.RenderType == RenderTypes.Materials)
            {
                // check if we should be rendering materials (this overrides the other colors)
                drawColor = MaterialRendering.Color(item.WorldMaterialIndex());
            }

            if (sceneContext.Printer is PrinterConfig printer)
            {
                if (printer.InsideBuildVolume(item))
                {
                    if (printer.Settings.Helpers.HotendCount() > 1)
                    {
                        var materialIndex = item.WorldMaterialIndex();
                        if (materialIndex == -1)
                        {
                            materialIndex = 0;
                        }

                        bool isWipeTower = item?.OutputType == PrintOutputTypes.WipeTower;

                        // Determine if the given item is outside the bounds of the given extruder
                        if (materialIndex < printer.Settings.ToolBounds.Length ||
                            isWipeTower)
                        {
                            var itemAABB   = item.WorldAxisAlignedBoundingBox();
                            var itemBounds = new RectangleDouble(new Vector2(itemAABB.MinXYZ), new Vector2(itemAABB.MaxXYZ));

                            var activeHotends = new HashSet <int>(new[] { materialIndex });

                            if (isWipeTower)
                            {
                                activeHotends.Add(0);
                                activeHotends.Add(1);
                            }

                            // Validate against active hotends
                            foreach (var hotendIndex in activeHotends)
                            {
                                var hotendBounds = printer.Settings.ToolBounds[hotendIndex];
                                if (!hotendBounds.Contains(itemBounds))
                                {
                                    // Draw in red outside of the bounds for the hotend
                                    drawColor = Color.Red.WithAlpha(90);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Outside of printer build volume
                    drawColor = new Color(drawColor, 65);
                }
            }

            if (drawColor.alpha != 255 &&
                item is Object3D item3D)
            {
                item3D.EnsureTransparentSorting();
            }

            if (selectedItem is ISelectableChildContainer selectableChildContainer)
            {
                if (item.AncestorsAndSelf().Any(i => selectableChildContainer.SelectedChildren.Contains(i.ID)))
                {
                    drawColor = new Color(drawColor, 200);
                }
            }

            if (!sceneContext.ViewState.ModelView)
            {
                if (modelRenderStyle == ModelRenderStyle.WireframeAndSolid)
                {
                    drawColor = gCodeMeshColor;
                }
                else if (modelRenderStyle == ModelRenderStyle.Wireframe)
                {
                    drawColor = new Color(gCodeMeshColor, 1);
                }
                else if (modelRenderStyle == ModelRenderStyle.None)
                {
                    drawColor = Color.Transparent;
                }
            }

            return(drawColor);
        }