画布渲染取决于不相关的元素吗?

时间:2019-01-16 11:46:03

标签: javascript canvas three.js

我正在尝试营造一个训练神经网络的环境。 首先,我只是制作了一个3d画布,然后将其很好地渲染(代码中为#canvas),然后将其转换为图像。 后来我发现我需要将画布转换为2d才能获得需要输入到AI中的图像数据(根据我得到的here的建议。 我还发现了一个使我两次调用animate()的错误。 奇怪的是,如果我现在尝试删除图像渲染或对animate()的额外调用,则当相机在Chrome中移动时,二维画布将无法渲染,而在IE中将不规则地渲染。知道我该如何解决吗?

我已将代码缩减为基本内容 fiddle,动画循环如下:

function animate(){
requestAnimationFrame( animate );
movement(); 
hudUpdate();
//fps-calculation
newTime = Date.now();   
sumTime += (newTime - oldTime);

if(framesElapsed === 60){
    document.getElementById("fps").innerHTML= 
(Math.floor(600000/sumTime))/10;
    framesElapsed = 0;
    sumTime = 0;
} else {
    framesElapsed+=1;
}

oldTime = newTime;


//Converts the canvas to an image and then draws it on a 2d surface. 
//  CHECKT THIS! Has to be run before renderer.renderer, but will be blank 
if movvement occurs and the segment below is left out.
var image = convertCanvasToImage(drawingSurface);
var AIInputImage = convertImageToCanvas(image);

renderer.render(scene, camera); 




// CHECK THIS! the above conversion stops working while moving unless the 
the line below is present, no idea why..

$("#interim-img").attr("src",drawingSurface.toDataURL("image/png"));

}; 
animate();
animate(); 

编辑:更新了fiddlelink。

0 个答案:

没有答案