将THREE注入global
src/global.d.ts
declare let THREE;declare var Hong;declare type ignore = any;interface Window {THREE: typeof THREE;render: (v?: number) => void;renderer: THREE.WebGLRenderer;gui: GUI;onmousewheel: ((e: { wheelDelta: number }) => void) | null;}
interface Document {onmousewheel: ((e: { wheelDelta: number }) => void) | null;
}
初始化全局变量
import * as THREE from "three";export const initGlobalVariable = () => {window.THREE = THREE;
};
初始化
import { initGlobalVariable } from "./GlobalVariable";
initGlobalVariable();
就可以 全局调用 THREE 对象