【问题标题】:dividing function to a separate file将函数拆分为单独的文件
【发布时间】:2020-01-12 08:23:16
【问题描述】:

我正在使用 Three.js 构建一个允许用户调整输入的应用程序。我想将 userGUI 函数移动到一个单独的文件中,但必须在 startAnimationLoop 函数中调用它才能渲染动画。

Dat.Gui(我希望这部分放在单独的文件中)

   userGUI = () => {
   this.gui = new dat.GUI();
   var controls = function() {
   this.RotationSpeed = 0.005;
}
  this.title = new controls();
  this.gui.add(this.title, 'RotationSpeed', 0.005, 0.1);
  }

requestAnimationFrame()

  startAnimationLoop = () => {
    const tableBoard = this.scene.getObjectByName('tableSurface');
    tableBoard.rotation.y += this.title.RotationSpeed; //This is where i use the value from the GUI
    this.renderer.render(this.scene, this.camera);
    this.requestID = window.requestAnimationFrame(this.startAnimationLoop);
  };

关于如何将 userGUI 部分移动到单独的文件中并仍然像我在 startAnimationLoop 函数的第三行中那样调用它的任何建议?

【问题讨论】:

  • 你的应用环境是什么?您使用的是 es6 模块还是脚本标签?你是在像 Vue 这样的框架中构建的吗?

标签: reactjs three.js dat.gui


【解决方案1】:

gui.js

userGUI = () => {
...
}

export const gui = new userGUI()

main.js

import { gui } from 'gui.js'

startAnimationLoop = () => {
...
    tableBoard.rotation.y += gui.title.RotationSpeed;
...
};

【讨论】:

    猜你喜欢
    • 2022-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 2018-06-24
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    相关资源
    最近更新 更多