vue项目中安装使用three.js
1, 安装插件npm install three --save2, 在main.js中设置一下,将three.js挂载到vue上:import*asThreefrom"three";Vue.prototype.$THREE=Three;
·
1, 安装插件
npm install three --save
2, vue2.0项目中是这样设置的:在main.js中设置一下,将three.js挂载到vue上:
import Vue from 'vue'
import * as Three from "three";
Vue.prototype.$three = Three;
在vue3.0项目中是这样设置的:
import * as THREE from "three"; //导入threeJs
const app = createApp(App);
app.config.globalProperties.$three = THREE; //挂载到原型
app.mount("#app")
3,页面中使用:
// 1,创建场景对象
this.scene = new this.$three.Scene();
// 创建缓存几何体对象
this.geomery = new this.$three.BufferGeometry();
// 创建环境光对象
this.light = new this.$three.AmbientLight( 0xffffff );
this.scene.add(this.light);
更多推荐
已为社区贡献19条内容
所有评论(0)