vue-3d-loader

vue-3d-loader - npm

GitHub - king2088/vue-3d-loader: VueJS and threeJS 3d viewer

是对 vue-3d-model 的改进,降低Threejs使用难度

# 默认安装 "vue-3d-loader": "^1.3.4", 只支持vue2
npm i vue-3d-loader
# vue3 需要安装2版本,vite只建立在vue3之上的,因此vite也是需要安装2版本
npm i vue-3d-loader@2.2.1 --save 
<template>
  <div class="player-container">
    <!--1和2版本都是 @load-->
    <vue3dLoader style="height: 100vh;" :showFps="false" :scale="scale" :rotation="rotation" :lights="lights" filePath="https://basin.csceccloud.net:9000/tomcat/fbx/yushuihy.FBX"
      :backgroundAlpha="0" @load="onLoad"></vue3dLoader>
    <!-- <vue3dLoader style="height: 100vh;" :showFps="false" :scale="scale" :rotation="rotation" :lights="lights" filePath="https://basin.csceccloud.net:9000/tomcat/fbx/panjiduanmian.glb"
      :backgroundAlpha="0" @load="onLoad"></vue3dLoader> -->
  </div>
</template>

<script>
import { vue3dLoader } from "vue-3d-loader";

export default {
  components: {
    vue3dLoader
  },
  data() {
    return {
      scale: { x: 1.5, y: 1.5, z: 1.3 },
      rotation: {
        x: 0,
        y: 0,
        z: 0,
      },
      //3d模型灯光
      lights: [
        {
          type: 'HemisphereLight',
          position: { x: 2, y: 2, z: 2 },
          skyColor: 0xffffff,
          intensity: 2,
        },
        {
          type: 'DirectionalLight',
          position: { x: 2, y: 2, z: 2 },
          color: 0xffffff,
          intensity: 2,
        }
      ],
    }
  },
  methods: {
    onLoad() {
      console.log('模型加载完成')
      this.rotate();
    },
    rotate() {
      requestAnimationFrame(this.rotate);//实现自动旋转效果
      this.rotation.y += 0.001;
    },
  }
}
</script>

<style>
html,
body {
  padding: 0;
  margin: 0;
  overflow: hidden;
}

.player-container {
  width: 100vw;
  height: 100vh;
  background-color: black;
}
</style>

模型放在服务器的tomcat中,跨域配置参见这篇文章:

vue-3d-model-CSDN博客

相关推荐

  1. Vue】1-3、Webpack 中的 loader

    2024-02-02 23:00:01       30 阅读
  2. Vue2 Echarts 3D饼图

    2024-02-02 23:00:01       31 阅读
  3. vue-loader是如何工作的?

    2024-02-02 23:00:01       29 阅读
  4. vue-template-loader 是如何工作的?

    2024-02-02 23:00:01       35 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-02 23:00:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-02 23:00:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-02 23:00:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-02 23:00:01       20 阅读

热门阅读

  1. uniapp uni.redirectTo() 跳转失效

    2024-02-02 23:00:01       36 阅读
  2. Centos7环境安装PHP8

    2024-02-02 23:00:01       35 阅读
  3. PHP面试题

    2024-02-02 23:00:01       34 阅读
  4. 2款网络监控系统软件,你更喜欢哪款?

    2024-02-02 23:00:01       33 阅读
  5. 速盾:服务器接入免备案CDN节点的好处有哪些

    2024-02-02 23:00:01       33 阅读
  6. 用于Web导出excel

    2024-02-02 23:00:01       29 阅读
  7. 关于后端异步+前端进度条的简单实现

    2024-02-02 23:00:01       30 阅读
  8. Three.js PBR 物理渲染

    2024-02-02 23:00:01       35 阅读
  9. this.$set()用法,强制刷新,新删改查

    2024-02-02 23:00:01       33 阅读
  10. JVM 内存配置参数积累

    2024-02-02 23:00:01       29 阅读
  11. vue + element 页面滚动计算百分比 + 节流函数

    2024-02-02 23:00:01       27 阅读
  12. 11.29 校招 实习 内推 面经

    2024-02-02 23:00:01       35 阅读