Ejemplo n.º 1
0
        public void DrawSimpleOutlines(Matrix4x4 transformation, ChiselWireframe wireframe, Color color)
        {
            if (wireframe == null ||
                wireframe.Vertices == null ||
                wireframe.Vertices.Length == 0 ||

                (wireframe.VisibleOuterLines == null &&
                 wireframe.InvisibleOuterLines == null &&
                 wireframe.VisibleInnerLines == null &&
                 wireframe.InvisibleInnerLines == null &&
                 wireframe.InvalidLines == null))
            {
                return;
            }

            color.a *= 0.5f;

            var vertices = wireframe.Vertices;
            var indices  = wireframe.VisibleOuterLines;

            if (indices != null &&
                indices.Length > 0 &&
                (indices.Length & 1) == 0)
            {
                zTestLinesManager.DrawLines(transformation, vertices, indices, color, thickness: 0.5f);
            }

            if (indices != null &&
                indices.Length > 0 &&
                (indices.Length & 1) == 0)
            {
                noZTestLinesManager.DrawLines(transformation, vertices, indices, color, thickness: 0.5f, dashSize: GUIConstants.invisibleInnerLineDots);
            }
        }
 // TODO: put somewhere else
 public static ChiselWireframe GetSurfaceWireframe(SurfaceReference surface)
 {
     if (!surfaceOutlineCache.TryGetValue(surface, out ChiselWireframe wireframe))
     {
         wireframe = ChiselWireframe.CreateWireframe(surface.TreeBrush, surface.surfaceID);
         surfaceOutlineCache[surface] = wireframe;
     }
     return(wireframe);
 }
Ejemplo n.º 3
0
        public void DrawOutlines(Matrix4x4 transformation, ChiselWireframe wireframe,
                                 Color outerColor, Color outerOccludedColor,
                                 Color innerColor, Color innerOccludedColor,
                                 float thickness = -1, bool onlyInnerLines = false, bool showInnerLines = true)
        {
            if (wireframe == null ||
                wireframe.Vertices == null ||
                wireframe.Vertices.Length == 0 ||

                (wireframe.VisibleOuterLines == null    //&&
                 //wireframe.InvisibleOuterLines	== null &&
                 //wireframe.VisibleInnerLines	== null &&
                 //wireframe.InvisibleInnerLines	== null &&
                 //wireframe.InvalidLines			== null
                ))
            {
                return;
            }

            if (thickness <= 0)
            {
                thickness = GUIConstants.defaultLineScale;
            }

            if (!onlyInnerLines && wireframe.VisibleOuterLines != null && wireframe.VisibleOuterLines.Length > 0)
            {
                zTestLinesManager.DrawLines(transformation, wireframe.Vertices, wireframe.VisibleOuterLines, outerColor, thickness: thickness);
            }

            //if (showInnerLines && wireframe.VisibleInnerLines != null && wireframe.VisibleInnerLines.Length > 0)
            //    zTestLinesManager.DrawLines(transformation, wireframe.Vertices, wireframe.VisibleInnerLines, innerColor, thickness: thickness);

            //if (!onlyInnerLines && wireframe.InvisibleOuterLines != null && wireframe.InvisibleOuterLines.Length > 0)
            //    zTestLinesManager.DrawLines(transformation, wireframe.Vertices, wireframe.InvisibleOuterLines, outerOccludedColor, dashSize: GUIConstants.invisibleInnerLineDots, thickness: GUIConstants.defaultLineScale);

            if (!onlyInnerLines && wireframe.VisibleOuterLines != null && wireframe.VisibleOuterLines.Length > 0)
            {
                noZTestLinesManager.DrawLines(transformation, wireframe.Vertices, wireframe.VisibleOuterLines, innerOccludedColor, thickness: thickness, dashSize: GUIConstants.invisibleInnerLineDots);
            }

            //if (showInnerLines && wireframe.VisibleInnerLines != null && wireframe.VisibleInnerLines.Length > 0)
            //    noZTestLinesManager.DrawLines(transformation, wireframe.Vertices, wireframe.VisibleInnerLines, innerOccludedColor, thickness: thickness, dashSize: GUIConstants.invisibleInnerLineDots);

            //if (showInnerLines && !onlyInnerLines && wireframe.InvisibleOuterLines != null && wireframe.InvisibleOuterLines.Length > 0)
            //    noZTestLinesManager.DrawLines(transformation, wireframe.Vertices, wireframe.InvisibleOuterLines, outerOccludedColor, dashSize: GUIConstants.invisibleInnerLineDots);

            //if (showInnerLines && wireframe.InvisibleInnerLines != null && wireframe.InvisibleInnerLines.Length > 0)
            //    noZTestLinesManager.DrawLines(transformation, wireframe.Vertices, wireframe.InvisibleInnerLines, innerOccludedColor, dashSize: GUIConstants.invisibleInnerLineDots);

#if TEST_ENABLED
            if (outline.invalidLines != null && outline.invalidLines.Length > 0)
            {
                _noZTestLinesManager.DrawDottedLines(transformation, outline.vertices, outline.invalidLines, Color.red, dashSize: GUIConstants.invalidLineDots);
            }
#endif
        }
Ejemplo n.º 4
0
        public void DrawOutlines(Matrix4x4 transformation, ChiselWireframe wireframe, Color wireframeColor, float thickness = -1, bool onlyInnerLines = false, bool showInnerLines = true)
        {
            Color outerColor = wireframeColor;
            Color innerColor = outerColor;

            innerColor.a *= GUIConstants.innerFactor;

            Color outerOccludedColor = wireframeColor; // * GUIConstants.occludedFactor;
            Color innerOccludedColor = wireframeColor; // * GUIConstants.occludedFactor;

            outerOccludedColor.a *= 0.5f;
            innerOccludedColor.a *= 0.5f * GUIConstants.innerFactor;;

            DrawOutlines(transformation, wireframe, outerColor, outerOccludedColor, innerColor, innerOccludedColor, thickness, onlyInnerLines, showInnerLines);
        }
Ejemplo n.º 5
0
        void UpdateSurfaceWireframe()
        {
            foreach (var pair in surfaceOutlines)
            {
                var wireframe = pair.Value;
                var outline   = pair.Key;
                var surface   = outline.surface;
                var treeBrush = surface.TreeBrush;
                if (wireframe == null)
                {
                    if (treeBrush.Valid &&
                        treeBrush.BrushMesh != BrushMeshInstance.InvalidInstance)
                    {
                        surfaceOutlineFixes[outline] = ChiselWireframe.CreateWireframe(treeBrush, surface.surfaceID);
                    }
                    else
                    {
                        surfaceOutlineFixes[outline] = null;
                    }
                    continue;
                }
                else
                {
                    if (!treeBrush.Valid ||
                        treeBrush.BrushMesh == BrushMeshInstance.InvalidInstance)
                    {
                        surfaceOutlineFixes[outline] = null;
                        continue;
                    }
                }

                if (!wireframe.Dirty)
                {
                    continue;
                }

                wireframe.UpdateWireframe();
            }
            foreach (var pair in surfaceOutlineFixes)
            {
                surfaceOutlines[pair.Key] = pair.Value;
            }
            surfaceOutlineFixes.Clear();
            updateSurfaceLineCache = true;
        }
Ejemplo n.º 6
0
        void UpdateBrushWireframe()
        {
            foreach (var pair in brushOutlines)
            {
                var wireframe = pair.Value;
                var outline   = pair.Key;
                var brush     = outline.brush;
                if (wireframe == null)
                {
                    if (brush.Valid &&
                        brush.BrushMesh != BrushMeshInstance.InvalidInstance)
                    {
                        brushOutlineFixes[outline] = ChiselWireframe.CreateWireframe(brush);
                    }
                    else
                    {
                        brushOutlineFixes[outline] = null;
                    }
                    continue;
                }
                else
                {
                    if (!brush.Valid ||
                        brush.BrushMesh == BrushMeshInstance.InvalidInstance)
                    {
                        brushOutlineFixes[outline] = null;
                        continue;
                    }
                }

                if (!wireframe.Dirty)
                {
                    continue;
                }

                wireframe.UpdateWireframe();
            }
            foreach (var pair in brushOutlineFixes)
            {
                brushOutlines[pair.Key] = pair.Value;
            }
            brushOutlineFixes.Clear();
            updateBrushLineCache = true;
        }
Ejemplo n.º 7
0
        void UpdateSurfaceSelection()
        {
            surfaceOutlines.Clear();
            var selection = ChiselSurfaceSelectionManager.Selection;
            var hovered   = ChiselSurfaceSelectionManager.Hovered;

            if (selection.Count == 0 &&
                hovered.Count == 0)
            {
                surfaceOutlines.Clear();
                surfaceOutlineRenderer.Clear();
            }
            else
            {
                var allSurfaces = new HashSet <SurfaceReference>(selection);
                allSurfaces.AddRange(hovered);
                foreach (var outline in surfaceOutlines.Keys)
                {
                    var surface = outline.surface;
                    if (!allSurfaces.Contains(surface) ||
                        !surface.TreeBrush.Valid ||
                        surface.TreeBrush.BrushMesh == BrushMeshInstance.InvalidInstance)
                    {
                        removedSurfaces.Add(outline);
                    }
                    else
                    {
                        allSurfaces.Remove(surface);
                    }
                }

                if (removedSurfaces.Count > 0)
                {
                    foreach (var outline in removedSurfaces)
                    {
                        surfaceOutlines.Remove(outline);
                    }
                }
                removedSurfaces.Clear();

                foreach (var surface in allSurfaces)
                {
                    var transform = ChiselNodeHierarchyManager.FindModelTransformOfTransform(surface.node.hierarchyItem.Transform);
                    var outline   = new SurfaceOutline(transform, surface);
                    foundSurfaceOutlines.Add(outline);
                }

                foreach (var outline in foundSurfaceOutlines)
                {
                    if (!outline.surface.TreeBrush.Valid ||
                        outline.surface.TreeBrush.BrushMesh == BrushMeshInstance.InvalidInstance)
                    {
                        continue;
                    }

                    var wireframe = ChiselWireframe.CreateWireframe(outline.surface.TreeBrush, outline.surface.surfaceID);
                    surfaceOutlines[outline] = wireframe;
                }
            }
            foundSurfaceOutlines.Clear();
            updateSurfaceWireframe = true;
        }
Ejemplo n.º 8
0
        void UpdateBrushSelection()
        {
            brushDirectlySelected.Clear();
            var objects = Selection.objects;

            if (objects.Length > 0)
            {
                for (int i = 0; i < objects.Length; i++)
                {
                    var          obj        = objects[i];
                    ChiselNode[] nodes      = null;
                    var          gameObject = obj as GameObject;
                    if (!Equals(null, gameObject))
                    {
                        nodes = gameObject.GetComponentsInChildren <ChiselNode>();
                    }
                    else
                    {
                        var behaviour = obj as Behaviour;
                        if (!Equals(null, behaviour))
                        {
                            nodes = behaviour.GetComponents <ChiselNode>();
                        }
                    }

                    if (nodes != null &&
                        nodes.Length > 0)
                    {
                        for (int n = 0; n < nodes.Length; n++)
                        {
                            var node = nodes[n];
                            foundTreeBrushes.Clear();
                            node.GetAllTreeBrushes(foundTreeBrushes, ignoreSynchronizedBrushes: true);
                            if (foundTreeBrushes.Count > 0)
                            {
                                var directSelected = (// if component is directly select
                                    (gameObject == null) ||
                                    // or when the component is part of the selected gameObject
                                    (gameObject == node.gameObject)) &&
                                                     // if we find CSGTreeBrushes directly on this node, but this node
                                                     // can also have child nodes, then we assume the CSGTreeBrushes are generated
                                                     // and we don't want to show those as directly selected
                                                     !node.CanHaveChildNodes;
                                var transform = ChiselNodeHierarchyManager.FindModelTransformOfTransform(node.hierarchyItem.Transform);
                                foreach (var treeBrush in foundTreeBrushes)
                                {
                                    if (directSelected)
                                    {
                                        brushDirectlySelected.Add(treeBrush);
                                    }
                                    var outline = new BrushOutline(transform, treeBrush);
                                    foundBrushOutlines.Add(outline);
                                }
                            }
                        }
                    }
                }
            }

            if (foundTreeBrushes.Count == 0)
            {
                brushOutlines.Clear();
                brushOutlineRenderer.Clear();
            }
            else
            {
                foreach (var outline in brushOutlines.Keys)
                {
                    if (!foundBrushOutlines.Contains(outline) ||
                        !outline.brush.Valid ||
                        outline.brush.BrushMesh == BrushMeshInstance.InvalidInstance)
                    {
                        removedBrushes.Add(outline);
                    }
                }

                if (removedBrushes.Count > 0)
                {
                    foreach (var outline in removedBrushes)
                    {
                        brushOutlines.Remove(outline);
                    }
                }
                removedBrushes.Clear();

                foreach (var outline in foundBrushOutlines)
                {
                    if (!outline.brush.Valid ||
                        outline.brush.BrushMesh == BrushMeshInstance.InvalidInstance)
                    {
                        continue;
                    }

                    var wireframe = ChiselWireframe.CreateWireframe(outline.brush);
                    brushOutlines[outline] = wireframe;
                }
            }

            foundBrushOutlines.Clear();
            updateBrushWireframe = true;
        }