public override bool ExecConduit(ref MRhinoDisplayPipeline dp, uint nChannel, ref bool bTerminate)
        {
            if (nChannel == MSupportChannels.SC_DRAWOBJECT)
            {
                if (null != m_pChannelAttrs.m_pObject)
                {
                    if (m_pChannelAttrs.m_pObject.m_runtime_object_serial_number == m_runtime_object_serial_number)
                    {
                        if (null == m_mesh_face_colors)
                        {
                            IRhinoMeshObject mesh_object = MRhinoMeshObject.ConstCast(m_pChannelAttrs.m_pObject);
                            if (null != mesh_object)
                            {
                                int mesh_face_count = mesh_object.Mesh().FaceCount();
                                m_mesh_face_colors = new ArrayOnColor(mesh_face_count);
                                for (int i = 0; i < mesh_face_count; i++)
                                {
                                    OnColor color = new OnColor(m_random.Next(0, 255), m_random.Next(0, 255), m_random.Next(0, 255));
                                    m_mesh_face_colors.Append(color);
                                }
                            }
                        }

                        if (null != m_mesh_face_colors)
                        {
                            m_pChannelAttrs.m_bDrawObject = false;

                            MDisplayPipelineAttributes da = new MDisplayPipelineAttributes();
                            da.m_bShadeSurface = true;
                            da.m_pMaterial.m_FrontMaterial.SetTransparency(0.0);
                            da.m_pMaterial.m_BackMaterial.SetTransparency(0.0);
                            da.m_pMaterial.m_FrontMaterial.m_bFlatShaded = true;
                            da.m_pMaterial.m_BackMaterial.m_bFlatShaded  = true;

                            dp.EnableDepthWriting(true);

                            if (da.m_bCullBackfaces)
                            {
                                dp.PushCullFaceMode(1);
                            }

                            for (int i = 0; i < m_mesh_face_colors.Count(); i++)
                            {
                                da.m_pMaterial.m_FrontMaterial.m_diffuse = m_mesh_face_colors[i];
                                da.m_pMaterial.m_BackMaterial.m_diffuse  = m_mesh_face_colors[i];
                                dp.DrawFace(m_pChannelAttrs.m_pObject, i, da);
                            }

                            if (da.m_bCullBackfaces)
                            {
                                dp.PopCullFaceMode();
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemple #2
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);
        }
        ///<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 (view == null)
            return IRhinoCommand.result.nothing;

              MRhinoGetOption go = new MRhinoGetOption();
              go.SetCommandPrompt("Capture Method");
              go.SetCommandPromptDefault("ViewCapture");
              int viewcap = go.AddCommandOption(new MRhinoCommandOptionName("ViewCapture"));
              int screencap = go.AddCommandOption(new MRhinoCommandOptionName("ScreenCapture"));
              go.GetOption();
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              System.Drawing.Bitmap bmp = null;

              if (go.Option().m_option_index == viewcap)
              {
            MRhinoDisplayPipeline pipeline = view.DisplayPipeline();
            int left = 0, right = 0, bot = 0, top = 0;
            view.MainViewport().VP().GetScreenPort(ref left, ref right, ref bot, ref top);
            int w = right - left;
            int h = bot - top;
            bmp = new System.Drawing.Bitmap(w, h);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            MDisplayPipelineAttributes attr = new MDisplayPipelineAttributes(pipeline.DisplayAttrs());
            bool rc = pipeline.DrawToDC(g, w, h, attr);
            g.Dispose();
            if (!rc)
              bmp = null;
              }
              else
              {
            bmp = new System.Drawing.Bitmap(1, 1);
            bool rc = view.ScreenCaptureToBitmap(ref bmp, true, false);
            if (!rc)
              bmp = null;
              }

              if (bmp != null)
              {
            string mydir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
            string path = System.IO.Path.Combine(mydir, "capture.png");
            bmp.Save(path);
            return IRhinoCommand.result.success;
              }

              return IRhinoCommand.result.failure;
        }
        public override bool ExecConduit(ref MRhinoDisplayPipeline dp, uint nChannel, ref bool bTerminate)
        {
            if (nChannel == MSupportChannels.SC_DRAWOBJECT)
              {
            if (null != m_pChannelAttrs.m_pObject)
            {
              if (m_pChannelAttrs.m_pObject.m_runtime_object_serial_number == m_runtime_object_serial_number)
              {
            if (null == m_mesh_face_colors)
            {
              IRhinoMeshObject mesh_object = MRhinoMeshObject.ConstCast(m_pChannelAttrs.m_pObject);
              if (null != mesh_object)
              {
                int mesh_face_count = mesh_object.Mesh().FaceCount();
                m_mesh_face_colors = new ArrayOnColor(mesh_face_count);
                for (int i = 0; i < mesh_face_count; i++)
                {
                  OnColor color = new OnColor(m_random.Next(0, 255), m_random.Next(0, 255), m_random.Next(0, 255));
                  m_mesh_face_colors.Append(color);
                }
              }
            }

            if (null != m_mesh_face_colors)
            {
              m_pChannelAttrs.m_bDrawObject = false;

              MDisplayPipelineAttributes da = new MDisplayPipelineAttributes();
              da.m_bShadeSurface = true;
              da.m_pMaterial.m_FrontMaterial.SetTransparency(0.0);
              da.m_pMaterial.m_BackMaterial.SetTransparency(0.0);
              da.m_pMaterial.m_FrontMaterial.m_bFlatShaded = true;
              da.m_pMaterial.m_BackMaterial.m_bFlatShaded = true;

              dp.EnableDepthWriting(true);

              if (da.m_bCullBackfaces)
                dp.PushCullFaceMode(1);

              for (int i = 0; i < m_mesh_face_colors.Count(); i++)
              {
                da.m_pMaterial.m_FrontMaterial.m_diffuse = m_mesh_face_colors[i];
                da.m_pMaterial.m_BackMaterial.m_diffuse = m_mesh_face_colors[i];
                dp.DrawFace(m_pChannelAttrs.m_pObject, i, da);
              }

              if (da.m_bCullBackfaces)
                dp.PopCullFaceMode();
            }
              }
            }
              }
              return true;
        }
Exemple #5
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 (view == null)
            {
                return(IRhinoCommand.result.nothing);
            }

            MRhinoGetOption go = new MRhinoGetOption();

            go.SetCommandPrompt("Capture Method");
            go.SetCommandPromptDefault("ViewCapture");
            int viewcap   = go.AddCommandOption(new MRhinoCommandOptionName("ViewCapture"));
            int screencap = go.AddCommandOption(new MRhinoCommandOptionName("ScreenCapture"));

            go.GetOption();
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            System.Drawing.Bitmap bmp = null;

            if (go.Option().m_option_index == viewcap)
            {
                MRhinoDisplayPipeline pipeline = view.DisplayPipeline();
                int left = 0, right = 0, bot = 0, top = 0;
                view.MainViewport().VP().GetScreenPort(ref left, ref right, ref bot, ref top);
                int w = right - left;
                int h = bot - top;
                bmp = new System.Drawing.Bitmap(w, h);
                System.Drawing.Graphics    g    = System.Drawing.Graphics.FromImage(bmp);
                MDisplayPipelineAttributes attr = new MDisplayPipelineAttributes(pipeline.DisplayAttrs());
                bool rc = pipeline.DrawToDC(g, w, h, attr);
                g.Dispose();
                if (!rc)
                {
                    bmp = null;
                }
            }
            else
            {
                bmp = new System.Drawing.Bitmap(1, 1);
                bool rc = view.ScreenCaptureToBitmap(ref bmp, true, false);
                if (!rc)
                {
                    bmp = null;
                }
            }

            if (bmp != null)
            {
                string mydir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
                string path  = System.IO.Path.Combine(mydir, "capture.png");
                bmp.Save(path);
                return(IRhinoCommand.result.success);
            }

            return(IRhinoCommand.result.failure);
        }