Exemplo n.º 1
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null == view)
            {
                return(IRhinoCommand.result.failure);
            }

            MRhinoViewport             vp = view.ActiveViewport();
            MRhinoDisplayPipeline      dp = view.DisplayPipeline();
            MDisplayPipelineAttributes da = view.DisplayAttributes();

            // Prevent capturing of the frame buffer on every update
            MRhinoDisplayPipeline.EnableFrameBufferCapture(false);
            // Prevent the draw list from updating on every frame
            dp.FreezeDrawing(true);

            int    dir         = 0; // 0 = Right, 1 = Left, 2 = Down, and 3 = Up
            int    frame_count = 100;
            double delta_angle = 5.0 * (Math.PI / 180.0);

            for (int i = 0; i < frame_count; i++)
            {
                switch (dir)
                {
                case 0:
                    vp.LeftRightRotate(delta_angle);
                    break;

                case 1:
                    vp.LeftRightRotate(-delta_angle);
                    break;

                case 2:
                    vp.DownUpRotate(delta_angle);
                    break;

                case 3:
                    vp.DownUpRotate(-delta_angle);
                    break;
                }
                //dp.DrawFrameBuffer(da);
                view.Redraw();
                RhUtil.RhinoApp().Wait(0);
            }

            dp.FreezeDrawing(false);
            MRhinoDisplayPipeline.EnableFrameBufferCapture(true);

            view.Redraw();

            return(IRhinoCommand.result.success);
        }
Exemplo n.º 2
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView rhino_view = RhUtil.RhinoApp().ActiveView();

            if (null == rhino_view)
            {
                return(IRhinoCommand.result.failure);
            }

            On3dmView saved_view = SampleCsSaveView.Instance.PopView();

            if (null == saved_view)
            {
                RhUtil.RhinoApp().Print("No saved views to restore.\n");
                return(IRhinoCommand.result.nothing);
            }

            MRhinoViewport viewport = rhino_view.ActiveViewport();

            int scr_left = 0, scr_right = 0, scr_bottom = 0, scr_top = 0;

            viewport.VP().GetScreenPort(ref scr_left, ref scr_right, ref scr_bottom, ref scr_top);

            On3dmView new_view = new On3dmView(saved_view);

            new_view.m_vp.SetScreenPort(scr_left, scr_right, scr_bottom, scr_top);

            double aspect = 0.0;

            if (new_view.m_vp.GetScreenPortAspect(ref aspect))
            {
                new_view.m_vp.SetFrustumAspect(aspect);
            }

            // Some optional parameters that you might want to control
            // when restoring a saved view
            bool bSavedViewSetsConstructionPlane = true;
            bool bSavedViewSetsProjection        = true;
            bool bSavedViewSetsTraceImage        = true;

            // Keep existing construction plane?
            if (!bSavedViewSetsConstructionPlane)
            {
                new_view.m_cplane = new On3dmConstructionPlane(viewport.ConstructionPlane());
            }

            // Keep existing projection?
            if (!bSavedViewSetsProjection)
            {
                new_view.m_vp.SetProjection(viewport.VP().Projection());
            }

            // Copy parameters from existing view that you might want to keep
            // from current view
            new_view.m_position        = new On3dmViewPosition(viewport.View().m_position);
            new_view.m_trace_image     = new On3dmViewTraceImage(viewport.View().m_trace_image);
            new_view.m_wallpaper_image = new On3dmWallpaperImage(viewport.View().m_wallpaper_image);
            new_view.m_clipping_planes = new ArrayOnClippingPlaneInfo(viewport.View().m_clipping_planes);
            new_view.m_display_mode    = viewport.DisplayMode();
            new_view.m_display_mode_id = viewport.View().m_display_mode_id;

            // Do the view restoration
            viewport.SetView(new_view);

            // Keep existing trace image?
            if (!bSavedViewSetsTraceImage)
            {
                viewport.SetTraceImage(saved_view.m_trace_image);
            }

            // Append the current view onto Rhino's view stack
            viewport.PushViewProjection();

            // Redraw
            rhino_view.Redraw();

            return(IRhinoCommand.result.success);
        }