# vue-3d-loader
**Repository Path**: gsang/vue-3d-loader
## Basic Information
- **Project Name**: vue-3d-loader
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2025-04-09
- **Last Updated**: 2025-10-20
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# vue-3d-loader
vueJS + threeJS整合的一个3d展示组件。
支持.dae/.fbx/.gltf/.glb/.obj/.ply/.stl/.json,并支持同一个场景导入多个不同3D模型,支持mtl材质以及jpg/png等图片纹理
[](https://www.npmjs.com/package/vue-3d-loader) [](https://www.npmjs.com/package/vue-3d-loader) [](https://www.npmjs.com/package/vue-3d-loader)
[English](./readme.md)
文档:
| 属性名 | 类型 | 默认值 | 值 | 描述 |
|---|---|---|---|---|
| filePath | string | array | - | ```js const filePath = './models/tree.obj' /* or */ const filePath = [ './models/tree.obj', './models/building.obj' ] ``` | 文件路径,支持多个文件一起加载,注意:如果每个文件对应一个材质,需要将材质**mtlPath**设置为数组。图片纹理也一样需要设置**textureImage**为数组 |
| fileType | string | array | - | ```js const fileType = 'obj' /* or */ const fileType = ['obj', 'gltf'] ``` | 文件类型,主要用于无法判断3d模型文件后缀名的url地址,与filePath一起使用,当filePath为数组时,此选项必须为数组 |
| mtlPath | string | array | - | ```js const mltPath = './models/tree.mlt' /* or */ const mltPath = [ './models/tree.mlt', './models/building.mlt' ] ``` | .mtl材质路径,支持多个材质一起加载,设置此参数为数组,必须设置**filePath**为数组 |
| textureImage | string | array | - | ```js const textureImage = './texture/tree.jpg' /* or */ const textureImage = [ './texture/tree.jpg' ,null, './building.png' ] ``` | jpg/png纹理加载,与**filePath**一一对应,为数组时,必须设置**filePath**为数组 |
| width | number | parent element width | 100 | 场景宽度 |
| height | number | parent element height | 100 | 场景高度 |
| position | object | array | {x:0, y:0, z:0} | ```js const position = {x:0, y:0, z:0} // or const position = [ {x:10, y:10, z:10}, {x:50, y:50, z:50} ] ``` | 模型位置坐标,filePath类型为array时可用array |
| rotation | object | array | {x:0, y:0, z:0} | ```js const rotation = {x:0, y:0, z:0} // or const rotation = [ {x: 10, y:20, z:30}, {x: 0, y: 16, z: 20} ] ``` | 模型旋转坐标,filePath类型为array时可用array |
| cameraPosition | object | {x:0, y:0, z:0} | ```js const cameraPosition = {x:0, y:0, z:0} ``` | 摄像机位置坐标 |
| cameraRotation | object | {x:0, y:0, z:0} | ```js const cameraRotation = {x:0, y:0, z:0} ``` | 摄像机旋转坐标 |
| scale | object | array | {x:1, y:1, z:1} | ```js const scale = {x:1, y:2, z:1} // or const scale = [ {x:1, y:2, z:1}, {x:0.5, y:0.5, z:0.5} ] ``` | 模型比例,filePath类型为array时可用array |
| lights | array | [{ type: "AmbientLight", color: 0xaaaaaa, }, { type: "DirectionalLight", position: { x: 1, y: 1, z: 1 }, color: 0xffffff, intensity: 0.8, }] | ```js const lights = [ { type: "AmbientLight", color: "red", }, { type: "DirectionalLight", position: { x: 100, y: 10, z: 100 }, color: "green", intensity: 0.8, }, { type: "PointLight", color: "#000000", position: { x: 200, y: -200, z: 100 }, intensity: 1 }, { type: "HemisphereLight", skyColor: "#00FF00", groundColor: "#000000", position: { x: 200, y: -200, z: 100 } } ] ``` | 灯光为数组,type为 环境光(AmbientLight) | 方向光(DirectionalLight) | 点光(PointLight) | 半球光(HemisphereLight) |
| backgroundColor | number | string | 0xffffff | ```js const bgColor = 0xff00ff /* or */ const bgColor = 'red' /* or */ const bgColor = '#000000' /* or */ const bgColor = 'rgba(0, 0, 0, 0.5)' ``` | 场景背景色 |
| backgroundAlpha | number | 1 | ```js const bgAlpha = 0.5 ``` | 场景背景透明度, 值范围0-1 |
| controlsOptions | object | - | - | 控制参数 [OrbitControls Properties](https://threejs.org/docs/#examples/en/controls/OrbitControls) |
| crossOrigin | string | anonymous | anonymous | use-credentials | 跨域配置 |
| requestHeader | object | anonymous | ```js const headers = { 'Authorization': 'Bearer token' } ``` | 设置请求头 |
| outputEncoding | string | linear | liner 或 sRGB | linear 是 LinearEncoding 线性编码, sRGB 即 sRGBEncoding rgb模式编码(sRGBEncoding能更好的还原材质颜色)。 渲染器的输出编码 [WebGLRenderer OutputEncoding](https://threejs.org/docs/index.html#api/en/renderers/WebGLRenderer.outputEncoding) |
| webGLRendererOptions | object | { antialias: true, alpha: true } | - | WebGLRenderer可选参数 [WebGLRenderer Parameters](https://threejs.org/docs/index.html#api/zh/renderers/WebGLRenderer) |
| showFps | boolean | false | - | 显示FPS等信息 |
| clearScene | boolean | false | - | 清空场景中的内容 |
| parallelLoad | boolean | false | - | 开启/关闭并行加载模型(仅在多模型下有效)**注意:使用此属性后,load进度process事件将不可预测** |
| labels | array | - | ```js const labels = [ { image: "", text: "", textStyle: { fontFamily: "Arial", fontSize: 18, fontWeight: "normal", lineHeight: 1, color: "#ffffff", borderWidth: 8, borderRadius: 4, borderColor: "rgba(0,0,0,1)", backgroundColor: "rgba(0, 0, 0, 1)" }, position: {x:0, y:0, z:0}, scale:{x:1, y:1, z:0}, sid: null } ] ``` | 添加图片/文字标签,设置image则显示图片标签。设置text显示文字标签,文字样式通过textStyle进行设置,样例可以查看[examples/add-label.vue](./src/examples/add-label.vue)文件 |
| autoPlay | boolean | true | - | 播放/停止动画 |
| enableDraco | boolean | false | - | 加载Gltf draco模型需开启draco解密,开启后需要[下载draco解密库](https://github.com/king2088/vue-3d-loader/blob/master/public/assets/draco.7z)放到默认目录assets中,默认目录为assets/draco/gltf/,如需修改默认目录,请查看参数dracoDir。[关于draco请查阅](https://threejs.org/docs/index.html?q=draco#examples/en/loaders/DRACOLoader) |
| dracoDir | string | assets/draco/gltf/ | - | draco解密库默认目录,可自行修改 |
| intersectRecursive | boolean | false | - | 若为true,则同时也会检测所有物体的后代。否则将只会检测对象本身的相交部分。 |
| enableDamping | boolean | false | - | [enableDamping](https://threejs.org/docs/index.html#examples/zh/controls/OrbitControls.enableDamping)设置为true以启用阻尼(惯性),这将给控制器带来重量感。 |
| dampingFactor | number | - | - | enableDamping必须为true,此选项才有效。[dampingFactor](https://threejs.org/docs/index.html#examples/zh/controls/OrbitControls.dampingFactor)用于设置阻尼惯性大小。 |
| verticalCtrl | boolean | object | false | - | 为true,仅能垂直旋转相机。 |
| horizontalCtrl | boolean | object | false | - | 为true,仅能水平旋转相机。 |
| plyMaterial | string | MeshStandardMaterial | - | 值仅有两个 `MeshStandardMaterial` 和 `MeshBasicMaterial`. 用于ply模型. [MeshStandardMaterial相关文档](https://threejs.org/docs/#api/en/materials/MeshStandardMaterial).[MeshBasicMaterial相关文档](https://threejs.org/docs/?q=MeshBasicMaterial#api/en/materials/MeshBasicMaterial) |
| enableAxesHelper | boolean | false | - | 开启并在场景中显示x,y,z轴 |
| axesHelperSize | number | 100 | - | x,y,z轴的尺寸 |
| enableGridHelper | boolean | false | - | 开启并在场景中显示网格 |
| minDistance | float | 0 | - | 你能够将相机向内移动多少,其默认值为0 |
| maxDistance | float | Infinity | - | 你能够将相机向外移动多少,其默认值为Infinity |
| pointLightFollowCamera | boolean | false | - | 开启点光源跟随相机 |