【问题标题】:Trying to add instructions to function in another class (es6)尝试添加指令以在另一个类中运行 (es6)
【发布时间】:2017-07-18 06:07:23
【问题描述】:

我正在使用 video.js 进行一个项目,以显示视频和网页的 3D 渲染。

我已经有了一个调用 WebGL 渲染器的函数,但是这个函数是在另一个我不想修改的插件中定义的。

WebGL 渲染器的功能(这个插件肯定没有错误):

var Canvas = function (baseComponent, THREE, settings = {}) {
    var parent = BaseCanvas(baseComponent, THREE, settings);

    return Util.extend(parent, {
    ...
      render: function(){
                  parent.render.call(this);
                  this.camera.target.x = 500 * Math.sin( this.phi ) * Math.cos( this.theta );
                  this.camera.target.y = 500 * Math.cos( this.phi );
                  this.camera.target.z = 500 * Math.sin( this.phi ) * Math.sin( this.theta );
                  this.camera.lookAt( this.camera.target );

                  if(!this.VRMode){
                      this.renderer.render( this.scene, this.camera );
                  }
              }
    ...
    }
}

所以我创建了另一个插件来创建 CSS3D 渲染器,我的问题是:我想调用 webgl 的渲染函数并添加我的新 CSS3D 渲染函数。我是这样做的:

class css3d {
...

render(){
    this.canvas.render.bind(this);
    this.renderer.render(this.scene, this.canvas.camera)
  }
...
}

我没有错误,但我的 css 渲染器无法正常工作。而且我已经在寻找这样的主题:three.js properly blending css3d and webgl 或这样的主题:https://gist.github.com/leefsmp/38926bf2c379f604f9b5 但仍然无法正常工作。

有人可以帮助我吗?

【问题讨论】:

  • 你说的“但是我的css渲染器不工作”是什么意思?不是叫的吗?它被调用但没有做你想做的事?它被调用了,但原来的render() 代码没有被调用?您是否设置了任何断点并单步执行了调用,以查看它是否按照您的预期执行,以及 this 范围是否符合您的预期?
  • 感谢您的回答,两个函数(使用 webgl 的 render() 和我的函数 render() 都被调用了,但我不知道如何通过调用的调用设置断点。这是我第一次需要使用它。:/
  • 我在函数渲染中使用了调试器,这是由我的实例 css3d 定义的 this.canvas.render 也很好定义。一切看起来都不错,但最终结果不是带有网页的 2000x2000px 正方形(即使页面已加载),它是两个面对面的三角形
  • 您已经很好地描述了您的问题并包含了您的代码,但您未能为我们提供重现问题的方法。

标签: javascript ecmascript-6


【解决方案1】:

最后,我找到了解决方案,我在课堂上创建了一个新的帧动画。所以现在我为每个渲染器(WebGL 和 CSS3D)都有了一个请求动画帧。

结果是这样的,如果有人感兴趣的话:

class css3d{
...

 render(){
        requestAnimationFrame(this.render.bind(this));
        this.renderer.render(this.scene, this.canvas.camera);
 }
...
}

祝您有美好的一天,感谢您的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-28
    • 2019-12-29
    • 2021-12-06
    • 1970-01-01
    • 2014-02-12
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多