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);

Logo

前往低代码交流专区

更多推荐