Esempio n. 1
0
        public static void PasteFiguresAsBin(PlotterController controller)
        {
            if (!Clipboard.ContainsData(CadClipBoard.TypeNameBin))
            {
                return;
            }

            byte[] bin = (byte[])Clipboard.GetData(CadClipBoard.TypeNameBin);

            List <CadFigure> figList = BinToFigList(bin);

            // Pase figures in fig list
            Vector3d pp = controller.LastDownPoint;

            MinMax3D mm3d = CadUtil.GetFigureMinMaxIncludeChild(figList);

            Vector3d d = pp - mm3d.GetMinAsVector();

            CadOpeList opeRoot = new CadOpeList();

            foreach (CadFigure fig in figList)
            {
                PasteFigure(controller, fig, d);
                controller.CurrentLayer.AddFigure(fig);    // 子ObjectはLayerに追加しない

                CadOpe ope = new CadOpeAddFigure(controller.CurrentLayer.ID, fig.ID);
                opeRoot.OpeList.Add(ope);
            }

            controller.HistoryMan.foward(opeRoot);
        }
Esempio n. 2
0
        // With thanks to http://www.turiyaware.com/a-solution-to-unitys-camera-worldtoscreenpoint-causing-ui-elements-to-display-when-object-is-behind-the-camera/
        public static MinMax3D GetScreenRectFromBounds(MeshFilter renderer, Camera mainCamera)
        {
            MinMax3D minMax = new MinMax3D (float.MaxValue, float.MinValue);

            Vector3[] screenBoundsExtents = new Vector3[8];
            var localBounds = renderer.sharedMesh.bounds;
            bool anyPointIsInFrontOfCamera = false;

            for (int i = 0; i < 8; i++) {
                Vector3 localSpaceCorner = localBounds.center + Vector3.Scale (localBounds.extents, cubeCornerOffsets[i]);
                Vector3 worldSpaceCorner = renderer.transform.TransformPoint (localSpaceCorner);
                Vector3 viewportSpaceCorner = mainCamera.WorldToViewportPoint (worldSpaceCorner);

                if (viewportSpaceCorner.z > 0) {
                    anyPointIsInFrontOfCamera = true;
                } else {
                    // If point is behind camera, it gets flipped to the opposite side
                    // So clamp to opposite edge to correct for this
                    viewportSpaceCorner.x = (viewportSpaceCorner.x <= 0.5f) ? 1 : 0;
                    viewportSpaceCorner.y = (viewportSpaceCorner.y <= 0.5f) ? 1 : 0;
                }

                // Update bounds with new corner point
                minMax.AddPoint (viewportSpaceCorner);
            }

            // All points are behind camera so just return empty bounds
            if (!anyPointIsInFrontOfCamera) {
                return new MinMax3D ();
            }

            return minMax;
        }
Esempio n. 3
0
        /// Update the bounding box of the path
        void UpdateBounds()
        {
            if (boundsUpToDate)
            {
                return;
            }

            // Loop through all segments and keep track of the minmax points of all their bounding boxes
            MinMax3D minMax = new MinMax3D();

            for (int i = 0; i < NumSegments; i++)
            {
                Vector3[] p = GetPointsInSegment(i);
                minMax.AddValue(p[0]);
                minMax.AddValue(p[3]);

                List <float> extremePointTimes = PathUtility.ExtremePointTimes(p[0], p[1], p[2], p[3]);
                foreach (float t in extremePointTimes)
                {
                    minMax.AddValue(MathUtility.CubicBezier(p, t));
                }
            }

            boundsUpToDate = true;
            bounds         = new Bounds((minMax.Min + minMax.Max) * .5f, minMax.Max - minMax.Min);
        }
Esempio n. 4
0
        /// Update the bounding box of the path
        public Bounds CalculateBoundsWithTransform(Transform transform)
        {
            // Loop through all segments and keep track of the minmax points of all their bounding boxes
            MinMax3D minMax = new MinMax3D();

            for (int i = 0; i < NumSegments; i++)
            {
                Vector3[] p = GetPointsInSegment(i);
                for (int j = 0; j < p.Length; j++)
                {
                    p[j] = MathUtility.TransformPoint(p[j], transform, space);
                }

                minMax.AddValue(p[0]);
                minMax.AddValue(p[3]);

                List <float> extremePointTimes = PathUtility.ExtremePointTimes(p[0], p[1], p[2], p[3]);
                foreach (float t in extremePointTimes)
                {
                    minMax.AddValue(MathUtility.CubicBezier(p, t));
                }
            }

            return(new Bounds((minMax.Min + minMax.Max) * .5f, minMax.Max - minMax.Min));
        }
Esempio n. 5
0
        public static Bounds CalculateSegmentBounds (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) {
            MinMax3D minMax = new MinMax3D ();
            minMax.AddValue (p0);
            minMax.AddValue (p3);

            List<float> extremePointTimes = ExtremePointTimes (p0,p1,p2,p3);
            foreach (float t in extremePointTimes) {
                minMax.AddValue (CubicBezierUtility.EvaluateCurve (p0, p1, p2, p3, t));
            }

            return new Bounds ((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min);
        }
        public static Bounds CalculateBounds(Vector3[] points)
        {
            MinMax3D minMax = new MinMax3D();

            minMax.AddValue(points[0]);
            minMax.AddValue(points[3]);

            List <float> extremePointTimes = ExtremePointTimes(points[0], points[1], points[2], points[3]);

            foreach (float t in extremePointTimes)
            {
                minMax.AddValue(CubicBezierUtility.EvaluateCurve(points, t));
            }

            return(new Bounds((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min));
        }
Esempio n. 7
0
        public static Bounds CalculateBounds(Vector3[] points)
        {
            Debug.Assert(points.Length == 4, "Incorrect number of points supplied to cubic bezier function (expected 4)");
            MinMax3D minMax = new MinMax3D();

            if (points.Length >= 4)
            {
                minMax.AddValue(points[0]);
                minMax.AddValue(points[3]);

                List <float> extremePointTimes = ExtremePointTimes(points[0], points[1], points[2], points[3]);
                foreach (float t in extremePointTimes)
                {
                    minMax.AddValue(CubicBezierUtility.EvaluateCurve(points, t));
                }
            }

            return(new Bounds((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min));
        }
Esempio n. 8
0
        internal static MinMax3D GetScreenRectFromBounds(MeshFilter renderer, Camera main_camera)
        {
            // With thanks to http://www.turiyaware.com/a-solution-to-unitys-camera-worldtoscreenpoint-causing-ui-elements-to-display-when-object-is-behind-the-camera/

            var min_max = new MinMax3D(min: float.MaxValue, max: float.MinValue);

            var screen_bounds_extents           = new Vector3[8];
            var local_bounds                    = renderer.sharedMesh.bounds;
            var any_point_is_in_front_of_camera = false;

            for (var i = 0; i < 8; i++)
            {
                var local_space_corner = local_bounds.center
                                         + Vector3.Scale(a: local_bounds.extents, b: _cube_corner_offsets[i]);
                var world_space_corner    = renderer.transform.TransformPoint(position: local_space_corner);
                var viewport_space_corner = main_camera.WorldToViewportPoint(position: world_space_corner);

                if (viewport_space_corner.z > 0)
                {
                    any_point_is_in_front_of_camera = true;
                }
                else
                {
                    // If point is behind camera, it gets flipped to the opposite side
                    // So clamp to opposite edge to correct for this
                    viewport_space_corner.x = (viewport_space_corner.x <= 0.5f) ? 1 : 0;
                    viewport_space_corner.y = (viewport_space_corner.y <= 0.5f) ? 1 : 0;
                }

                // Update bounds with new corner point
                min_max.AddPoint(point: viewport_space_corner);
            }

            // All points are behind camera so just return empty bounds
            if (!any_point_is_in_front_of_camera)
            {
                return(new MinMax3D());
            }

            return(min_max);
        }
Esempio n. 9
0
        public static Bounds CalculateBounds(Vector3[] points)
        {
            Debug.Assert(
                points.Length == 4,
                "Incorrect number of points supplied to cubic bezier function. Expected 4, but received " + points.Length);
            var minMax = new MinMax3D();

            if (points.Length >= 4)
            {
                minMax.AddValue(points[0]);
                minMax.AddValue(points[3]);

                var extremePointTimes = ExtremePointTimes(points[0], points[1], points[2], points[3]);
                foreach (var t in extremePointTimes)
                {
                    minMax.AddValue(EvaluateCurve(points, t));
                }
            }

            return(new Bounds((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min));
        }
Esempio n. 10
0
    public static bool BoundsOverlap(MeshFilter nearObject, MeshFilter farObject, Camera camera)
    {
        MinMax3D near = GetScreenRectFromBounds(nearObject, camera);
        MinMax3D far  = GetScreenRectFromBounds(farObject, camera);

        // ensure far object is indeed further away than near object
        if (far.zMax > near.zMin)
        {
            // Doesn't overlap on x axis
            if (far.xMax < near.xMin || far.xMin > near.xMax)
            {
                return(false);
            }
            // Doesn't overlap on y axis
            if (far.yMax < near.yMin || far.yMin > near.yMax)
            {
                return(false);
            }
            // Overlaps
            return(true);
        }
        return(false);
    }