【问题标题】:ThreeJS cannot use on <canvas> tag but only on <div> tagThreeJS 不能在 <canvas> 标签上使用,只能在 <div> 标签上使用
【发布时间】:2015-02-14 19:31:45
【问题描述】:

WebGL 新手并尝试了示例代码:http://aerotwist.com/static/tutorials/getting-started-with-three-js/sample.zip

它适用于 div id="container" 标签,但是当我将其更改为 canvas id="container" 时它不起作用。

【问题讨论】:

  • ummm,为什么要把div改成canvas?
  • CanvasRenderer 的后备如何在 div 标签上正常工作。
  • webgl 渲染器和 canvas 渲染器都在 canvas dom 元素中渲染。

标签: three.js


【解决方案1】:

webgl 渲染器和 canvas 渲染器都在 canvas dom 元素中渲染。
您不更改容器 div。

要回退到 CanvasRenderer,您可以使用如下代码:

if (window.WebGLRenderingContext) 
  renderer = new THREE.WebGLRenderer();
else
  renderer = new THREE.CanvasRenderer();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 2022-01-27
    相关资源
    最近更新 更多