用的是 npm i threejs-miniprogram ,然后直接把里面的 build/index.js 复制出来了。(或者大佬们有没有什么文章推荐一下?找了很久没找到不包含widnow的loader包)
代码如下:
// 引入复制出来的index文件
import {createScopedThreejs} from '../../libs/index.js';
...
// 在 lifetimes 的 ready 里面执行
const qeury = wx.createSelectorQuery();
qeury.select('#c').node().exec(res => {
let canvasId = String(res[0].node.id);
// canvas = THREE.global.registerCanvas(canvasId, res[0].node)
this.setData({
canvasId
})
const THREE = createScopedThreejs(res[0].node);
debugger
scene = new THREE.Scene();
const lightness = new THREE.HemisphereLight(0xffffff, 0x444444);
lightness.position.set(0, 100, 0);
scene.add(lightness);
const shadowLight = new THREE.DirectionalLight(0xffffff);
shadowLight.position.set(0, 20, 10);
scene.add(shadowLight);
const geometry = new THREE.BoxGeometry(50, 50, 50);
const material = new THREE.MeshBasicMaterial({
color: 0x0000ff
});
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
const renderer = new THREE.WebGLRenderer();
wx.getSystemInfo({
success(res) {
renderer.setPixelRatio(res.pixelRatio);
}
})
renderer.setSize(res[0].node.width, res[0].node.height);
})
不知道为什么整个canvas都是黑的,
没事了,render方法没有执行,而且执行顺序可能有点问题
要实现什么功能?