多版本兼容
采用编译时代理的方式实现兼容层,不限制 three.js 的版本
仅需几行代码,即可在小程序/小游戏中原样使用 three.js
搭建三维场景。
// index.js 在项目入口根据对应小程序引入并应用适配兼容层
import '@minisheep/mini-program-polyfill-core/wechat-polyfill';
import { adapter } from '@minisheep/three-platform-adapter';
import { wechat } from '@minisheep/three-platform-adapter/wechat';
adapter.useAdapter(wechat).patch('THREEGlobals');
// scene.js
import * as THREE from 'three';
import { adapter } from '@minisheep/three-platform-adapter';
adapter.useCanvas('#canvas').then(({ canvas, requestAnimationFrame }) => {
const renderer = new THREE.WebGLRenderer({ canvas });
// ...
})