import { createScopedThreejs } from 'threejs-miniprogram'
import registerOrbit from "../libs/orbit"
let canvas;
let THREE;
let camera, scene, renderer;
let controls;
function init (canvasDom) {
const info = wx.getSystemInfoSync();
const width = info.windowWidth;
const height = info.windowHeight;
const devicePixelRatio = info.pixelRatio;
canvas = canvasDom;
THREE = createScopedThreejs(canvas);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(100, width / height, 1, 1000);
camera.position.set(16, 25, 16);
camera.lookAt(new THREE.Vector3(0, 2, 0));
renderer = new THREE.WebGLRenderer({ canvas, alpha: true });
renderer.setPixelRatio(devicePixelRatio);
renderer.setSize(width, height);
const { OrbitControls } = registerOrbit(THREE)
controls = new OrbitControls( camera, renderer.domElement );
controls.update()
}
function render () {
controls.update()
renderer.render(scene, camera);
}
function createUI () {
let geometry = new THREE.BoxGeometry(10, 10, 10);
let material = new THREE.MeshBasicMaterial({ color: 0x999999});
let cube = new THREE.Mesh(geometry, material);
scene.add(cube);
render()
}
function createEnv(canvasDom) {
init(canvasDom)
createUI()
}
module.exports = {
createEnv,
}
-----
const cameraBusiness = require('../../utils/cameraBusiness.js')
Page({
data: {
},
onReady() {
console.log('onReady')
wx.createSelectorQuery()
.select('#canvas')
.node()
.exec(res => {
cameraBusiness.createEnv(res[0].node)
})
},
});
--------
<canvas
id="canvas"
class="canvas"
type="webgl"
disable-scroll="true">
</canvas>
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。