Ejemplo n.º 1
0
        public static bool RenderVideo(string dataPath, PartSysSpec spec, string filename)
        {
            var specStr = spec.ToSpec();

            var activeSys = ParticleSystem.FromSpec(specStr);

            return(activeSys.RenderVideo(Color.FromArgb(255, 32, 32, 32), filename));
        }
Ejemplo n.º 2
0
        private void DoRender(IntPtr surface, bool isNewSurface)
        {
            if (DisableRendering)
            {
                return;
            }

            var w = _outputWidth;
            var h = _outputHeight;

            if (w <= 0 || h <= 0)
            {
                return;
            }

            if (_activeSystem == null && ActiveSystem != null)
            {
                _activeSystem = ParticleSystem.FromSpec(ActiveSystem.ToSpec());
            }


            if (_timeSinceLastSimul.HasValue)
            {
                var simulTime = (float)(_lastRender.TotalSeconds - _timeSinceLastSimul.Value.TotalSeconds);
                if (simulTime > 1 / 60.0f)
                {
                    _previewModel?.AdvanceTime(simulTime);

                    if (!_model.Paused)
                    {
                        if (_activeSystem != null)
                        {
                            _activeSystem.Simulate(simulTime);
                            UpdateParticleStatistics();
                        }
                    }
                    _timeSinceLastSimul = _lastRender;
                }
            }
            else
            {
                _timeSinceLastSimul = _lastRender;
            }

            _templeDll.SetRenderTarget(surface);

            _templeDll.Scale = _model.Scale;
            _templeDll.CenterOn(0, 0, 0);

            _previewModel?.Render(TempleDll.Instance);
            _activeSystem?.Render();

            _templeDll.Flush();
        }
Ejemplo n.º 3
0
        private void RenderFrame(object sender, EventArgs e)
        {
            if (DisableRendering)
            {
                return;
            }

            var args = (RenderingEventArgs)e;

            var w = _outputWidth;
            var h = _outputHeight;

            if (w <= 0 || h <= 0)
            {
                return;
            }

            if (Device == null)
            {
                var presentParams = new PresentParameters(w, h)
                {
                    Windowed             = true,
                    SwapEffect           = SwapEffect.Discard,
                    DeviceWindowHandle   = GetDesktopWindow(),
                    PresentationInterval = PresentInterval.Default
                };
                Device = new DeviceEx(new Direct3DEx(),
                                      0,
                                      DeviceType.Hardware,
                                      IntPtr.Zero,
                                      CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve,
                                      presentParams);
            }

            if (_activeSystem == null && ActiveSystem != null)
            {
                _activeSystem = ParticleSystem.FromSpec(Device, DataPath, ActiveSystem.ToSpec());
            }

            if (D3Dimg.IsFrontBufferAvailable && _lastRender != args.RenderingTime)
            {
                if (_renderTargetSurface == null || _renderTargetWidth != w || _renderTargetHeight != h)
                {
                    _renderTargetWidth  = w;
                    _renderTargetHeight = h;

                    _renderTargetSurface?.Dispose();
                    _renderTargetDepth?.Dispose();

                    _renderTargetSurface = Surface.CreateRenderTarget(Device,
                                                                      _renderTargetWidth,
                                                                      _renderTargetHeight,
                                                                      Format.X8R8G8B8,
                                                                      MultisampleType.None,
                                                                      0,
                                                                      false);
                    _renderTargetDepth = Surface.CreateDepthStencil(Device,
                                                                    _renderTargetWidth,
                                                                    _renderTargetHeight,
                                                                    Format.D16,
                                                                    MultisampleType.None,
                                                                    0,
                                                                    true);
                }

                D3Dimg.Lock();

                Device.SetRenderTarget(0, _renderTargetSurface);
                Device.DepthStencilSurface = _renderTargetDepth;

                RenderParticleSystem(w, h, args.RenderingTime);

                D3Dimg.SetBackBuffer(D3DResourceType.IDirect3DSurface9, _renderTargetSurface.NativePointer);
                D3Dimg.AddDirtyRect(new Int32Rect(0, 0, _renderTargetWidth, _renderTargetHeight));
                D3Dimg.Unlock();

                _lastRender = args.RenderingTime;
            }
        }