微信小程序中使用threejs-miniprogram - 【安装】

  1. 通过npm安装
  • 在项目目录下,shift+鼠标右键,打开PowerShell,输入npm i threejs-miniprogram,执行安装;
  • 安装完成后,会出现node_modules目录,查看是否已经存在了threejs-miniprogram文件,内容如下:
    在这里插入图片描述
  1. 微信小程序开发者工具中构建npm
  • 小程序工具栏,【工具】→ “构建npm”,即可完成npm构建,如下图:
    在这里插入图片描述
  1. 导入小程序适配版本的Three.js
import {
    
    createScopedThreejs} from 'threejs-miniprogram'

Page({
    
    
  onReady() {
    
    
    wx.createSelectorQuery()
      .select('#webgl')
      .node()
      .exec((res) => {
    
    
        const canvas = res[0].node
        // 创建一个与 canvas 绑定的 three.js
        const THREE = createScopedThreejs(canvas)
        // 传递并使用 THREE 变量
      })
  }
})

猜你喜欢

转载自blog.csdn.net/qq_29517595/article/details/130085009