THREE.js static scene, detect when webgl render is

2019-03-06 00:42发布

I am creating a static scene with a lot of objects and I want to save as image after it is rendered. How do I do that in THREE.js r69?

1条回答
戒情不戒烟
2楼-- · 2019-03-06 01:17

Most probably, you are not going in the right direction.

if you have some function like this

function animate() {
    requestAnimationFrame(animate);
    render ();
}

The render is doing it's work all the time.

When you are seeing the scene unfinished, it's because the meshes haven't finished loading, not because the render hasn't finished rendering.

So, you have to listen for some onload event on the models that you are loading, that will depend on the method that you use to load them (and that you don't explain, so I can't help you more)

Given the code in your reply, it isn't clear when you add the mesh to the scene. Anyway, I would try something in the line of

function loaderCallback() {
    mesh = new THREE.Mesh (...
    scene.add (mesh);
    requestAnimationFrame(saveImage);
    render ();
}

the function invoked at requestAnimationFrame should be called when render finishes.

查看更多
登录 后发表回答