Exemplo n.º 1
0
        ChiselBrushMaterial[] AddSelectedSurfaces(ChiselBrushMaterial[] surfaces)
        {
            if (surfaces == null ||
                surfaces.Length != 1)
            {
                return(surfaces);
            }

            if (ChiselUVMoveTool.IsActive() ||
                ChiselUVRotateTool.IsActive() ||
                ChiselUVScaleTool.IsActive())
            {
                return(surfaces);
            }

            // TODO: implement the ability to query this from the edit mode
            if (!ChiselSurfaceSelectionManager.IsSelected(surfaces[0]))
            {
                return(surfaces);
            }

            var surfaceHashSet = new HashSet <ChiselBrushMaterial>();

            surfaceHashSet.AddRange(ChiselSurfaceSelectionManager.SelectedBrushMaterials);
            surfaceHashSet.AddRange(surfaces);
            return(surfaceHashSet.ToArray());
        }
        void UpdateBrushState()
        {
            if (updateBrushSelection)
            {
                updateBrushSelection = false;
                UpdateBrushSelection();
                updateBrushWireframe = true;
            }
            if (updateBrushWireframe)
            {
                updateBrushWireframe = false;
                UpdateBrushWireframe();
                updateBrushLineCache = true;
            }
            if (updateBrushLineCache)
            {
                updateBrushLineCache = false;
                brushOutlineRenderer.Begin();

                foreach (var pair in brushOutlines)
                {
                    var wireframe = pair.Value;
                    if (wireframe == null)
                    {
                        continue;
                    }

                    var outline = pair.Key;
                    if (!outline.brush.Valid)
                    {
                        continue;
                    }

                    // TODO: simplify this
                    var wireframeValue = pair.Value;
                    var modelTransform = outline.transform;
                    //var brushes		= outline.brush.AllSynchronizedVariants;
                    //var anySelected	= ChiselSyncSelection.IsAnyBrushVariantSelected(brushes);

                    //foreach (var brush in brushes)
                    var brush       = outline.brush;
                    var anySelected = ChiselSyncSelection.IsBrushVariantSelected(brush);
                    {
                        Matrix4x4 transformation;
                        if (modelTransform)
                        {
                            transformation = modelTransform.localToWorldMatrix * brush.NodeToTreeSpaceMatrix;
                        }
                        else
                        {
                            transformation = brush.NodeToTreeSpaceMatrix;
                        }

                        if ((VisualizationMode & VisualizationMode.Outline) == VisualizationMode.Outline)
                        {
                            var directSelect = (ChiselUVMoveTool.IsActive() || ChiselUVRotateTool.IsActive() || ChiselUVScaleTool.IsActive()) &&
                                               ((brush == outline.brush && !anySelected) || (anySelected && ChiselSyncSelection.IsBrushVariantSelected(brush)));

                            // TODO: tweak look of selection, figure out how to do backfaced lighting of edges, for clarity
                            // TODO: support selecting surfaces/edges/points (without showing the entire object selection)
                            if (directSelect)
                            {
                                brushOutlineRenderer.DrawOutlines(transformation, wireframeValue, ColorManager.kSelectedOutlineColor, thickness: 3.0f, onlyInnerLines: false);
                            }
                            else
                            {
                                brushOutlineRenderer.DrawOutlines(transformation, wireframeValue, ColorManager.kUnselectedOutlineColor, thickness: 1.0f, onlyInnerLines: false);// (ChiselEditModeManager.EditMode == CSGEditMode.ShapeEdit));
                            }
                        }

                        if ((VisualizationMode & VisualizationMode.SimpleOutline) == VisualizationMode.SimpleOutline)
                        {
                            brushOutlineRenderer.DrawSimpleOutlines(transformation, wireframeValue, ColorManager.kUnselectedOutlineColor);
                        }
                    }
                }
                brushOutlineRenderer.End();
            }
        }