1.安装
npm install --save threeJs
2.引用three.js
import * as THREE from 'three/build/three.module'
3.根据项目需求引入对应的文件
import {FBXLoader} from 'three/examples/jsm/loaders/FBXLoader'
import {OBJLoader} from 'three/examples/jsm/loaders/OBJLoader'
import {STLLoader} from 'three/examples/jsm/loaders/STLLoader'
import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls'
// import Stats from 'stats-js'
import Stats from 'three/examples/jsm/libs/stats.module'
4.使用(以.fbx模型文件为例)
let _this = this;
var loader = new FBXLoader();
loader.load('文件路径', function ( object) {
//中间进行其他缩放,旋转,设置中心点等等操作
//把模型添加到场景中
_this.scene.add(object);
})
5. stats使用
this.stats = new Stats();
document.getElementById("div").appendChild(this.stats.dom);