Ejemplo n.º 1
0
        /// <summary>
        /// Implement the render entry point.
        ///
        /// Rhino data is prepared for further conversion in RenderEngine.
        /// </summary>
        /// <param name="doc">Rhino document for which the render command was given</param>
        /// <param name="mode">mode</param>
        /// <param name="fastPreview">True for fast preview.</param>
        /// <returns></returns>
        protected override Result Render(RhinoDoc doc, RunMode mode, bool fastPreview)
        {
            //AsyncRenderContext a_rc = new RhinoCycles.ModalRenderEngine(doc, Id);
            ModalRenderEngine engine = new ModalRenderEngine(doc, Id);

            var renderSize = Rhino.Render.RenderPipeline.RenderSize(doc);

            var pipe = new RhinoCycles.RenderPipeline(doc, mode, this, engine);

            engine.RenderWindow             = pipe.GetRenderWindow(true);
            engine.RenderDimension          = renderSize;
            engine.Database.RenderDimension = renderSize;

            engine.SetFloatTextureAsByteTexture(false);

            engine.CreateWorld();             // has to be done on main thread, so lets do this just before starting render session

            /* since we're an asynchronous renderer plugin we start the render process
             * here, but, apart from data conversion and pumping, we fall right through
             * without a complete render result.
             */
            var rc = pipe.Render();

            if (Rhino.Render.RenderPipeline.RenderReturnCode.Ok != rc)
            {
                RhinoApp.WriteLine("Rendering failed:" + rc.ToString());
                return(Result.Failure);
            }

            return(Result.Success);
        }
Ejemplo n.º 2
0
        public override bool StartRenderer(int w, int h, RhinoDoc doc, ViewInfo rhinoView, ViewportInfo viewportInfo, bool forCapture, RenderWindow renderWindow)
        {
            _started     = true;
            _forCapture  = forCapture;
            _useFastDraw = UseFastDraw();
            if (forCapture)
            {
                SetUseDrawOpenGl(false);
                _useFastDraw = UseFastDraw();
                var mre = new ModalRenderEngine(doc, PlugIn.IdFromName("RhinoCycles"), rhinoView, viewportInfo, Dpa);
                mre.SetCallbackForCapture();

                _cycles = null;
                _modal  = mre;

                var rs = new Size(w, h);

                mre.RenderWindow = renderWindow;

                mre.RenderDimension          = rs;
                mre.Database.RenderDimension = rs;

                mre.StatusTextUpdated += Mre_StatusTextUpdated;

                mre.Database.LinearWorkflowChanged += DatabaseLinearWorkflowChanged;

                mre.CreateWorld();                 // has to be done on main thread, so lets do this just before starting render session

                _modalThread = new Thread(RenderOffscreen)
                {
                    Name = $"Cycles offscreen viewport rendering with ModalRenderEngine {_serial}"
                };
                _modalThread.Start(mre);

                return(true);
            }
            _fadeInMs = RcCore.It.EngineSettings.FadeInMs;

            _frameAvailable = false;
            _sameView       = false;

            _cycles = new ViewportRenderEngine(doc.RuntimeSerialNumber, PlugIn.IdFromName("RhinoCycles"), rhinoView, Dpa);

            _cycles.StatusTextUpdated              += CyclesStatusTextUpdated; // render engine tells us status texts for the hud
            _cycles.RenderStarted                  += CyclesRenderStarted;     // render engine tells us when it actually is rendering
            _cycles.StartSynchronizing             += CyclesStartSynchronizing;
            _cycles.Synchronized                   += CyclesSynchronized;
            _cycles.PassRendered                   += CyclesPassRendered;
            _cycles.Database.LinearWorkflowChanged += DatabaseLinearWorkflowChanged;
            _cycles.UploadProgress                 += _cycles_UploadProgress;

            ViewportSettingsChanged += _cycles.ViewportSettingsChangedHandler;
            _cycles.CurrentViewportSettingsRequested += _cycles_CurrentViewportSettingsRequested;
            var renderSize = Rhino.Render.RenderPipeline.RenderSize(doc);

            _cycles.RenderWindow    = renderWindow;
            _cycles.RenderDimension = renderSize;

            _maxSamples = RcCore.It.EngineSettings.Samples;

            _startTime = DateTime.UtcNow;      // use _startTime to time CreateWorld
            _cycles.CreateWorld();             // has to be done on main thread, so lets do this just before starting render session

            var createWorldDuration = DateTime.UtcNow - _startTime;

            RhinoApp.OutputDebugString($"CreateWorld({RcCore.It.EngineSettings.FlushAtEndOfCreateWorld}): {createWorldDuration.Ticks} ticks ({createWorldDuration.TotalMilliseconds} ms)\n");

            _startTime = DateTime.UtcNow;
            _lastTime  = _startTime;
            if (_useFastDraw)
            {
                _sw = new Thread(TimerForAlpha)
                {
                    Name = "Cycles RenderedViewport Alpha Thread"
                };
                _sw.Start();
            }
            _cycles.StartRenderThread(_cycles.Renderer, $"A cool Cycles viewport rendering thread {_serial}");

            return(true);
        }