XNA渲染3D视频(固定FPS!) [英] XNA to render 3D video (fixed FPS!)

查看:88
本文介绍了XNA渲染3D视频(固定FPS!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须开发一个应用程序,最后一步是导出由我的软件计算用户输入参数生成的3D动画的视频(或单个帧).

i have to develop an application in wich the final step is to export a video (or a single frame) of a 3D animation generated by my software calculating the user input parameters.

我想为此使用XNA.我需要该软件可以导出FIXED FPS视频(或单独导出视频的所有单帧).实时FPS无关紧要.我不需要以固定的fps在屏幕上查看帧.由于动画可能非常复杂,因此我可以接受该软件是否每帧花费1分钟.

I want to use XNA and for this. i need that the software can export FIXED FPS video (or also all single frames of the video separately). It's not a matter the LIVE FPS. I don't need to view on the screen the frames at a fixed fps. As the animation could be very complex, i could accept if the software take 1 minute for each frame.

重要的是,我可以在渲染时看到框架,而不会跳过任何框架. 例如.如果视频的时长为1分钟,则还必须以24fps的速度导出24帧,如果要花费20秒的时间来渲染每一帧.渲染第一帧后(因此20秒后),它无需在21秒时渲染该帧.它必须渲染帧[第一分钟的2/24]

The important is that i can see the frame while it render and that is not skipped any frame. eg. if the video is 1 minute long, it have to export 24 frames at 24fps also if it will take 20secs to render each frame. After rendered the first frame (so after 20sec) it haven't to render the frame at 21sec. it have to render the frame [2/24 of the first minute]

我怎么能得到这个?

谢谢!

推荐答案

以下是针对XNA 4.0进行此操作的方法,该方法在您的Game类的代码中进行了描述(因为它对我来说很容易):

Here is the method for doing this for XNA 4.0, described in code for your Game class (because it's easy for me):

protected override void Update(GameTime gameTime)
{
    // Do Nothing!
}

void RealUpdate()
{
    const float deltaTime = 1f/60f; // Fixed 60 FPS     
    // Update your scene here
}

RenderTarget2D screenshot;

protected override void LoadContent()
{
    screenshot = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Color, null);
}

protected override void UnloadContent()
{
    screenshot.Dispose();
}

int i = 0;

protected override void Draw(GameTime)
{
    RealUpdate(); // Do the update once before drawing each frame.

    GraphicsDevice.SetRenderTarget(screenshot); // rendering to the render target
    //
    // Render your scene here
    //
    GraphicsDevice.SetRenderTarget(null); // finished with render target

    using(FileStream fs = new FileStream(@"screenshot"+(i++)+@".png", FileMode.OpenOrCreate)
    {
        screenshot.SaveAsPng(fs, width, height); // save render target to disk
    }

    // Optionally you could render your render target to the screen as well so you can see the result!

    if(done)
        Exit();
}

注意:我在编写时没有进行编译或测试-因此可能会出现一个或两个小错误.

Note: I wrote this without compiling or testing - so there might be a minor error or two.

这篇关于XNA渲染3D视频(固定FPS!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆