Esempio n. 1
0
            public void Init(CSGCylinder generator)
            {
                this.generator  = generator;
                bottomDiameterX = generator.BottomDiameterX;
                bottomDiameterZ = generator.IsEllipsoid ? generator.BottomDiameterZ : generator.BottomDiameterX;

                topDiameterX = generator.TopDiameterX;
                topDiameterZ = generator.IsEllipsoid ? generator.TopDiameterZ : generator.TopDiameterX;

                rotate        = Quaternion.AngleAxis(generator.Rotation, Vector3.up);
                topXVector    = rotate * Vector3.right * topDiameterX * 0.5f;
                topZVector    = rotate * Vector3.forward * topDiameterZ * 0.5f;
                bottomXVector = rotate * Vector3.right * bottomDiameterX * 0.5f;
                bottomZVector = rotate * Vector3.forward * bottomDiameterZ * 0.5f;
                topHeight     = Vector3.up * generator.TopHeight;
                bottomHeight  = Vector3.up * generator.BottomHeight;
                normal        = Vector3.up;

                if (!generator.IsEllipsoid)
                {
                    bottomZVector = bottomZVector.normalized * bottomXVector.magnitude;
                    topZVector    = topZVector.normalized * topXVector.magnitude;
                }

                prevBottomXVector = bottomXVector;
                prevBottomZVector = bottomZVector;
                prevTopXVector    = topXVector;
                prevTopZVector    = topZVector;

                topPoint    = topHeight;
                bottomPoint = bottomHeight;

                vertices = new Vector3[generator.Sides * 2];
            }
        public void OnSceneGUI(SceneView sceneView, Rect dragArea)
        {
            Bounds    bounds;
            CSGModel  modelBeneathCursor;
            Matrix4x4 transformation;
            float     height;

            var flags = (isSymmetrical ? BoxExtrusionFlags.IsSymmetricalXZ : BoxExtrusionFlags.None) |
                        (generateFromCenterXZ ? BoxExtrusionFlags.GenerateFromCenterXZ : BoxExtrusionFlags.None);

            switch (BoxExtrusionHandle.Do(dragArea, out bounds, out height, out modelBeneathCursor, out transformation, flags, Axis.Y))
            {
            case BoxExtrusionState.Create:
            {
                cylinder = BrushMeshAssetFactory.Create <CSGCylinder>("Cylinder",
                                                                      BrushMeshAssetFactory.GetModelForNode(modelBeneathCursor),
                                                                      transformation);
                cylinder.definition.Reset();
                cylinder.Operation       = forceOperation ?? CSGOperationType.Additive;
                cylinder.IsEllipsoid     = !isSymmetrical;
                cylinder.Type            = cylinderType;
                cylinder.Height          = height;
                cylinder.Sides           = sides;
                cylinder.BottomDiameterX = bounds.size[(int)Axis.X];
                cylinder.Height          = height;
                cylinder.BottomDiameterZ = bounds.size[(int)Axis.Z];
                cylinder.UpdateGenerator();
                break;
            }

            case BoxExtrusionState.Modified:
            {
                cylinder.Operation = forceOperation ??
                                     ((height < 0 && modelBeneathCursor) ?
                                      CSGOperationType.Subtractive :
                                      CSGOperationType.Additive);
                cylinder.BottomDiameterX = bounds.size[(int)Axis.X];
                cylinder.Height          = height;
                cylinder.BottomDiameterZ = bounds.size[(int)Axis.Z];
                break;
            }

            case BoxExtrusionState.Commit:
            {
                UnityEditor.Selection.activeGameObject = cylinder.gameObject;
                CSGEditModeManager.EditMode            = CSGEditMode.ShapeEdit;
                Reset();
                break;
            }

            case BoxExtrusionState.Cancel:
            {
                Reset();
                Undo.RevertAllInCurrentGroup();
                EditorGUIUtility.ExitGUI();
                break;
            }

            case BoxExtrusionState.BoxMode:
            case BoxExtrusionState.SquareMode:      { CSGOutlineRenderer.VisualizationMode = VisualizationMode.SimpleOutline; break; }

            case BoxExtrusionState.HoverMode:       { CSGOutlineRenderer.VisualizationMode = VisualizationMode.Outline; break; }
            }

            HandleRendering.RenderCylinder(transformation, bounds, (cylinder) ? cylinder.Sides : sides);
        }