与jsdom一起使用WebGLRenderer()时出错

我试图在服务器端渲染一个多维数据集,并能够使用CanvasRenderer,但我想能够使用WebGLRenderer,它应该产生更好的结果。 我已经缩小到这个代码片段:

var jsdom = require('jsdom') , document = jsdom.jsdom('<!doctype html><html><head></head><body></body></html>') , window = document.createWindow() , THREE = require('three'); document.onload = docOnLoad(); function docOnLoad() { console.log("docOnLoad called."); global.document = document; global.window = window; //renderer = new THREE.CanvasRenderer(); //works renderer = new THREE.WebGLRenderer(); renderer.setSize(400, 400); document.body.appendChild(renderer.domElement); } 

当使用WebGLRenderer时,我得到:

 _glExtensionTextureFloat = _gl.getExtension( 'OES_texture_float'); ^ TypeError: Cannot call method 'getExtension' of undefined at initGL (C:\programming\nodejs\node_modules\three\three.js:25870:34) 

当试图debuggingthree.js代码时,console.log(_gl)确实显示_gl是未定义的,并且它的源代码是#25856行,其中:

 _gl = _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes ); 

现在,_canvas的console.log()显示: [Canvas 0x0]

有没有人遇到类似的东西?

通常在您已经从_canvas获得2D上下文时发生。 2D上下文和gl不能从同一个canvas获得。 如果情况并非如此,您是否可以确认是否可以独立成功运行任何其他WebGL示例(来自node.js)?