Exemplo n.º 1
0
 public SurfaceReference(ChiselNode node, int descriptionIndex, CSGTreeBrush brush, int surfaceIndex)
 {
     this.node             = node as ChiselGeneratorComponent;
     this.brush            = brush;
     this.descriptionIndex = descriptionIndex;
     this.surfaceIndex     = surfaceIndex;
 }
Exemplo n.º 2
0
        public static Bounds CalculateBounds(ChiselGeneratorComponent generator)
        {
            if (!generator.TopTreeNode.Valid)
            {
                return(ChiselHierarchyItem.EmptyBounds);
            }

            var modelMatrix = ChiselNodeHierarchyManager.FindModelTransformMatrixOfTransform(generator.hierarchyItem.Transform);
            var minMax      = new ChiselAABB {
            };
            var boundsCount = 0;

            s_FoundBrushes.Clear();
            ChiselGeneratedComponentManager.GetAllTreeBrushes(generator, s_FoundBrushes);
            foreach (var brush in s_FoundBrushes)
            {
                if (!brush.Valid)
                {
                    continue;
                }

                var transformation = modelMatrix * (Matrix4x4)brush.NodeToTreeSpaceMatrix;
                var childBounds    = brush.Bounds;
                var size           = childBounds.Max - childBounds.Min;
                var magnitude      = math.lengthsq(size);
                if (float.IsInfinity(magnitude) ||
                    float.IsNaN(magnitude))
                {
                    var center   = ((float4)transformation.GetColumn(3)).xyz;
                    var halfSize = size * 0.5f;
                    childBounds = new ChiselAABB {
                        Min = center - halfSize, Max = center + halfSize
                    };
                }
                if (magnitude != 0)
                {
                    if (boundsCount == 0)
                    {
                        minMax = childBounds;
                    }
                    else
                    {
                        minMax.Encapsulate(childBounds);
                    }
                    boundsCount++;
                }
            }
            if (boundsCount == 0)
            {
                return(ChiselHierarchyItem.EmptyBounds);
            }
            var bounds = new Bounds();

            bounds.SetMinMax(minMax.Min, minMax.Max);
            return(bounds);
        }
Exemplo n.º 3
0
        // Get all brushes directly contained by this CSGNode (not its children)
        public static void GetAllTreeBrushes(ChiselGeneratorComponent component, HashSet <CSGTreeBrush> foundBrushes)
        {
            if (foundBrushes == null ||
                !component.TopTreeNode.Valid)
            {
                return;
            }

            var brush = (CSGTreeBrush)component.TopTreeNode;

            if (brush.Valid)
            {
                foundBrushes.Add(brush);
            }
            else
            {
                var nodes = new List <CSGTreeNode>();
                nodes.Add(component.TopTreeNode);
                while (nodes.Count > 0)
                {
                    var lastIndex = nodes.Count - 1;
                    var current   = nodes[lastIndex];
                    nodes.RemoveAt(lastIndex);
                    var nodeType = current.Type;
                    if (nodeType == CSGNodeType.Brush)
                    {
                        brush = (CSGTreeBrush)current;
                        foundBrushes.Add(brush);
                    }
                    else
                    {
                        for (int i = current.Count - 1; i >= 0; i--)
                        {
                            nodes.Add(current[i]);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static VisibilityState UpdateVisibility(UnityEditor.SceneVisibilityManager instance, ChiselGeneratorComponent generator)
        {
            var resultState    = VisibilityState.Unknown;
            var visible        = !instance.IsHidden(generator.gameObject);
            var pickingEnabled = !instance.IsPickingDisabled(generator.gameObject);
            var topNode        = generator.TopTreeNode;

            if (topNode.Valid)
            {
                topNode.Visible        = visible;
                topNode.PickingEnabled = pickingEnabled;

                if (visible)
                {
                    resultState |= VisibilityState.AllVisible;
                }
                else
                {
                    resultState |= VisibilityState.AllInvisible;
                }
            }
            return(resultState);
        }