[英]How do I create global variables I can use across my modules?
我将场景从文件sceneSetup.js
导入initFloor1.js
并得到错误 ReferenceError: scene is not defined
找不到此问题的解决方案,无法理解是 javascript 还是 Threejs 的问题
场景设置.js:
export let camera, controls, renderer, labelRenderer, renderer3D, arrow, label, scene;
initFloor1.js:
import * as THREE from 'three';
import { camera, controls, renderer, labelRenderer, renderer3D, arrow, label, scene } from './../sceneSetup.js'
export function initFloor1() {
scene = new THREE.Scene();
我的项目文件夹:
|- src
| |- 3d-scene
| |- sceneSetup.js
| |- Floor1
| |- initFloor1.js
ChrisG建议的解决方案:导出 object 并编辑其值
const globals = {
camera: null,
controls: null,
renderer: null,
labelRenderer: null,
renderer3D: null,
arrow: null,
label: null,
scene: null
};
export { globals };
使用window.variableName
在中心位置声明,然后您可以跨站点访问。
window.camera=null;
window.controls=null;
等等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.