Пример #1
0
        public Vector3 GetCenter(CSGPlane plane)
        {
            var vertices2d = GeometryUtility.RotatePlaneTo2D(curve.Points, plane);
            var centroid2d = Centroid(vertices2d);

            return(plane.Project(GeometryUtility.Rotate2DToPlane(new Vector2[] { centroid2d }, plane)[0]));
        }
Пример #2
0
 public void ProjectShapeOnBuildPlane(CSGPlane plane)
 {
     for (int i = 0; i < vertices.Length; i++)
     {
         vertices[i] = plane.Project(vertices[i]);
     }
 }
Пример #3
0
		protected virtual bool StartEditMode(Camera camera)
		{
			if (editMode == EditMode.EditShape ||
				editMode == EditMode.ExtrudeShape)
			{
				return false;
			}

			Undo.RecordObject(this, "Created shape");
			if (GUIUtility.hotControl == shapeId)
			{
				GUIUtility.hotControl = 0;
				GUIUtility.keyboardControl = 0;
				EditorGUIUtility.SetWantsMouseJumping(0);
				EditorGUIUtility.editingTextField = false;
			}
			
			CalculateWorldSpaceTangents(camera);
			brushPosition = buildPlane.Project(ShapeSettings.GetCenter(buildPlane));
			editMode = EditMode.EditShape;

			CSGPlane newPlane = buildPlane;
			ShapeSettings.CalculatePlane(ref newPlane);
			if (newPlane.normal.sqrMagnitude != 0)
				buildPlane = newPlane;

            if (ModelTraits.IsModelEditable(geometryModel))
                SelectionUtility.LastUsedModel = geometryModel;

			UpdateBaseShape();

			//StartExtrudeMode();
			//GrabHeightHandle(ignoreFirstMouseUp: true);
			return true;
		}
Пример #4
0
        public static Vector3 CubeProject(Camera camera, CSGPlane plane, Vector3 pos)
        {
            UpdateGridOrientation(camera);
            var closest_axis = GeometryUtility.SnapToClosestAxis(plane.normal);
            var intersection = plane.LineIntersection(pos, pos + closest_axis);

            if (float.IsNaN(intersection.x) || float.IsInfinity(intersection.x) ||
                float.IsNaN(intersection.y) || float.IsInfinity(intersection.y) ||
                float.IsNaN(intersection.z) || float.IsInfinity(intersection.z))
            {
                // should never happen, but if all else fails just do a projection ..
                intersection = plane.Project(pos);
            }
            return(intersection);
        }
        protected void CenterExtrusionPoints(CSGPlane buildPlane)
        {
            if (!HaveHeight)
            {
                return;
            }

            var center = GetShapeBounds().Center;

            brushPosition = buildPlane.Project(center);
            var height0 = buildPlane.Distance(extrusionPoints[0].Position);
            var height1 = buildPlane.Distance(extrusionPoints[1].Position);

            extrusionPoints[0].Position = brushPosition + (buildPlane.normal * height0);
            extrusionPoints[1].Position = brushPosition + (buildPlane.normal * height1);
        }
Пример #6
0
        public static List <Vector3> FindAllGridEdgesThatTouchPoint(Camera camera, Vector3 point)
        {
            var lines = new List <Vector3>();

            UpdateGridOrientation(camera);
            if (gridOrientation == null)
            {
                return(lines);
            }

            var snapVector = gridOrientation.gridSnapVector;

            var gridPoint        = PointToGridSpace(point);
            var snappedGridPoint = SnapRoundPosition(gridPoint, snapVector);

            var gridPlane = new CSGPlane(CSGGrid.CurrentWorkGridPlane.normal, point);

            if (Math.Abs(gridPoint.x - snappedGridPoint.x) < MathConstants.EqualityEpsilon)
            {
                var lineSize = 10000;
                var pointA   = new Vector3(-lineSize, gridPoint.y, gridPoint.z);
                var pointB   = new Vector3(lineSize, gridPoint.y, gridPoint.z);
                lines.Add(gridPlane.Project(PointFromGridSpace(pointA)));
                lines.Add(gridPlane.Project(PointFromGridSpace(pointB)));
            }

            if (Math.Abs(gridPoint.y - snappedGridPoint.y) < MathConstants.EqualityEpsilon)
            {
                var lineSize = 10000;
                var pointA   = new Vector3(gridPoint.x, -lineSize, gridPoint.z);
                var pointB   = new Vector3(gridPoint.x, lineSize, gridPoint.z);
                lines.Add(gridPlane.Project(PointFromGridSpace(pointA)));
                lines.Add(gridPlane.Project(PointFromGridSpace(pointB)));
            }

            if (Math.Abs(gridPoint.z - snappedGridPoint.z) < MathConstants.EqualityEpsilon)
            {
                var lineSize = 10000;
                var pointA   = new Vector3(gridPoint.x, gridPoint.y, -lineSize);
                var pointB   = new Vector3(gridPoint.x, gridPoint.y, lineSize);
                lines.Add(gridPlane.Project(PointFromGridSpace(pointA)));
                lines.Add(gridPlane.Project(PointFromGridSpace(pointB)));
            }
            return(lines);
        }
Пример #7
0
        public static Vector3 FreeMoveHandle(int id, Vector3 position, Quaternion rotation, float size, DrawCapFunction capFunc = null)
        {
            if (capFunc == null)
            {
                capFunc = PaintUtility.SquareDotCap;
            }
            Vector3   worldPosition = Handles.matrix.MultiplyPoint(position);
            Matrix4x4 origMatrix    = Handles.matrix;

            switch (Event.current.GetTypeForControl(id))
            {
            case EventType.layout:
            {
                Handles.matrix = MathConstants.identityMatrix;
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(worldPosition, size * 1.2f));
                Handles.matrix = origMatrix;
                break;
            }

            case EventType.mouseDown:
            {
                if (GUIUtility.hotControl == 0 &&
                    HandleUtility.nearestControl == id && Event.current.button == 0)
                {
                    GUIUtility.hotControl             = id;
                    GUIUtility.keyboardControl        = id;
                    EditorGUIUtility.editingTextField = false;

                    movePlane = Grid.CurrentGridPlane;
                    movePlane = new CSGPlane(movePlane.normal, position);

                    startMousePosition = Event.current.mousePosition;
//						currentMousePosition = startMousePosition;
//						startPosition = position;

                    Event.current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;
            }

            case EventType.mouseDrag:
            {
                if (GUIUtility.hotControl == id)
                {
                    if (snapFunction == null)
                    {
                        break;
                    }

                    position = snapFunction(startMousePosition, Event.current.mousePosition);
                    if (Camera.current != null && Camera.current.orthographic)
                    {
                        position = movePlane.Project(position);
                    }

                    GUI.changed = true;
                    Event.current.Use();
                }
                break;
            }

            case EventType.mouseUp:
            {
                if (GUIUtility.hotControl == id && Event.current.button == 0)
                {
                    GUIUtility.hotControl             = 0;
                    GUIUtility.keyboardControl        = 0;
                    EditorGUIUtility.editingTextField = false;
                    Event.current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;
            }

            case EventType.repaint:
            {
                bool  isSelected = (id == GUIUtility.keyboardControl) || (id == GUIUtility.hotControl);
                Color temp       = Handles.color;
                if (isSelected)
                {
                    Handles.color = Handles.selectedColor;                             // Why U not work?
                }
                else
                {
                    Handles.color = Color.gray;
                }

                Handles.matrix = MathConstants.identityMatrix;
                capFunc(id, worldPosition, Camera.current.transform.rotation, size);
                Handles.matrix = origMatrix;

                if (isSelected)
                {
                    Handles.color = temp;
                }
                break;
            }
            }
            return(position);
        }