// 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);
 }
Beispiel #2
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;
        }
Beispiel #3
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;
        }
Beispiel #4
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;
        }
Beispiel #5
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;
        }