예제 #1
0
        public void EndCommit()
        {
            if (generatedBrushes == null)
            {
                return;
            }
            var bounds = BoundsUtilities.GetBounds(generatedBrushes);

            if (!bounds.IsEmpty())
            {
                var center = bounds.Center - operationGameObject.transform.position;
                GeometryUtility.MoveControlMeshVertices(generatedBrushes, -center);
                SurfaceUtility.TranslateSurfacesInWorldSpace(generatedBrushes, -center);
                ControlMeshUtility.RebuildShapes(generatedBrushes);
                InternalCSGModelManager.Refresh(forceHierarchyUpdate: true);

                operationGameObject.transform.position += center;

                Undo.CollapseUndoOperations(undoGroupIndex);
                Cleanup();

                if (generatedGameObjects != null &&
                    generatedGameObjects.Length > 0)
                {
                    Selection.objects = generatedGameObjects;
                }

                Reset();
            }

            if (shapeCommitted != null)
            {
                shapeCommitted();
            }
        }
예제 #2
0
        private bool GenerateStairs(CSGBrush[] stepBrushes, int totalSteps, float stepLength, float stepHeight, float stairsDepth, float stairsWidth, float stairsHeight, float extraDepth, float extraHeight)
        {
            bool success = true;

            for (int stepIndex = 0; stepIndex < totalSteps; stepIndex++)
            {
                var brush = stepBrushes[stepIndex];
                if (!brush)
                {
                    continue;
                }

                var curStepHeight = Mathf.Min(stairsHeight, (stepIndex == 0) ? (extraHeight + stepHeight) : stepHeight);
                var curStepY      = (stepIndex == 0) ? (stepHeight * stepIndex) : (extraHeight + (stepHeight * stepIndex));

                var extraLength = lengthDirection * (stepLength * stepIndex);
                var heightPos   = heightDirection * curStepY;

                var widthSize  = (widthDirection * stairsWidth);
                var lengthSize = (lengthDirection * stairsDepth) - extraLength;
                var heightSize = (heightDirection * curStepHeight);

                var size     = widthSize + heightSize + lengthSize;
                var position = (totalSteps == 1) ? (heightPos + brushPosition) : heightPos;

                ControlMesh newControlMesh;
                Shape       newShape;
                if (!BrushFactory.CreateCubeControlMesh(out newControlMesh, out newShape, Vector3.zero, size))
                {
                    success = false;
                    if (brush.gameObject.activeSelf)
                    {
                        brush.gameObject.SetActive(false);
                    }
                    continue;
                }

                if (!brush.gameObject.activeSelf)
                {
                    brush.gameObject.SetActive(true);
                }

                brush.Shape                   = newShape;
                brush.ControlMesh             = newControlMesh;
                brush.transform.localPosition = position;
                SurfaceUtility.TranslateSurfacesInWorldSpace(brush, -position);
            }
            return(success);
        }
예제 #3
0
        public static void TranslatePivot(CSGBrush[] brushes, Vector3 offset)
        {
            if (brushes == null ||
                brushes.Length == 0 ||
                offset.sqrMagnitude < MathConstants.ConsideredZero)
            {
                return;
            }

            for (int i = 0; i < brushes.Length; i++)
            {
                brushes[i].transform.position += offset;
            }

            GeometryUtility.MoveControlMeshVertices(brushes, -offset);
            SurfaceUtility.TranslateSurfacesInWorldSpace(brushes, -offset);
            ControlMeshUtility.RebuildShapes(brushes);
        }
예제 #4
0
        public static void SetPivot(CSGBrush brush, Vector3 newCenter)
        {
            if (!brush)
            {
                return;
            }

            var transform  = brush.transform;
            var realCenter = transform.position;
            var difference = newCenter - realCenter;

            if (difference.sqrMagnitude < MathConstants.ConsideredZero)
            {
                return;
            }

            transform.position += difference;

            GeometryUtility.MoveControlMeshVertices(brush, -difference);
            SurfaceUtility.TranslateSurfacesInWorldSpace(brush, -difference);
            ControlMeshUtility.RebuildShape(brush);
        }
예제 #5
0
        private bool GenerateStairs(CSGBrush[] stepBrushes, int totalSteps, float stepLength, float stepHeight, float stepDepth, float stairsDepth, float stairsWidth, float stairsHeight, float extraDepth, float extraHeight, StairsBottom stairsBottom)
        {
            //var currentModel = parentModel ? parentModel : SelectionUtility.LastUsedModel;
            //var modelRotation = Quaternion.Inverse(currentModel.transform.rotation);

            stairsDepth = Math.Max(0, stairsDepth);

            bool success = true;

            for (int stepIndex = 0; stepIndex < totalSteps; stepIndex++)
            {
                var brush = stepBrushes[stepIndex];
                if (!brush)
                {
                    continue;
                }

                float   curStepDepth;
                float   curStepHeight;
                float   curStepY;
                Vector3 extraLength;
                Vector3 lengthPos;

                switch (stairsBottom)
                {
                default:
                case StairsBottom.Filled:
                {
                    curStepHeight = Mathf.Min(stairsHeight, (stepIndex == 0) ? (extraHeight + stepHeight) : stepHeight);
                    curStepY      = (stepIndex == 0) ? (stepHeight * stepIndex) : (extraHeight + (stepHeight * stepIndex));
                    extraLength   = lengthDirection * (stepLength * stepIndex);
                    curStepDepth  = stairsDepth;
                    lengthPos     = Vector3.zero;
                    break;
                }

                case StairsBottom.Steps:
                {
                    curStepHeight = stepHeight;
                    curStepY      = extraHeight + (stepHeight * stepIndex);
                    extraLength   = Vector3.zero;
                    curStepDepth  = (stepIndex == totalSteps - 1) ? (stepDepth + extraDepth) : stepDepth;
                    lengthPos     = (stepIndex == totalSteps - 1) ? Vector3.zero : (lengthDirection * Mathf.Max(0, ((totalSteps - (stepIndex + 1)) * stepDepth) + extraDepth));
                    break;
                }
                }

                var heightPos = heightDirection * curStepY;

                var widthSize  = (widthDirection * stairsWidth);
                var lengthSize = (lengthDirection * curStepDepth) - extraLength;
                var heightSize = (heightDirection * curStepHeight);

                var size     = widthSize + heightSize + lengthSize;
                var position = (totalSteps == 1) ? (heightPos + lengthPos + brushPosition) : (heightPos + lengthPos);

                ControlMesh newControlMesh;
                Shape       newShape;
                if (!BrushFactory.CreateCubeControlMesh(out newControlMesh, out newShape, Vector3.zero, size))
                {
                    success = false;
                    if (brush.gameObject.activeSelf)
                    {
                        brush.gameObject.SetActive(false);
                    }
                    continue;
                }

                if (!brush.gameObject.activeSelf)
                {
                    brush.gameObject.SetActive(true);
                }

                brush.Shape       = newShape;
                brush.ControlMesh = newControlMesh;
                if (totalSteps != 1)
                {
                    brush.transform.localPosition = position;
                }
                //brush.transform.localRotation = Quaternion.identity;
                SurfaceUtility.TranslateSurfacesInWorldSpace(brush, -position);
            }
            return(success);
        }