当前位置:   article > 正文

three.js如何实现简易3D机房?(二)模型加载的过渡动画_three 加载

three 加载

接上一篇: 

three.js如何实现简易3D机房?(一)基础准备-下:http://t.csdnimg.cn/TTI1P

目录

六、自定义过渡动画

1.过渡动画组件 

2.模型加载时使用


根据模型大小,可以自定义模型加载的过渡动画效果,由于公司和本人设备配置有限,我这个模型才26M,打开都要至少加载一分钟。。。(大家配置高、网速快的当我没说)

六、自定义过渡动画

1.过渡动画组件 

在component/loading.vue文件中

  1. <!--
  2. * @Description: 模型加载过渡动画
  3. * @FilePath: \hk-computerRoom-Security\src\views\home\component\loading.vue
  4. * @Date: 2024-02-02 15:29:56
  5. * @LastEditTime: 2024-02-02 15:55:12
  6. -->
  7. <template>
  8. <div id="loading-mark" v-if="props.loading">
  9. <div class="loading-box">
  10. <div class="loading">
  11. <img src="../../../assets/images/home/threeD/loading.svg" />
  12. <div class="progress-txt">
  13. 当前模型已加载 <b>{{ props.percentage }}</b> %
  14. </div>
  15. <div class="loading-txt">模型文件首次加载时间较长请耐心等待.....</div>
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script setup lang="ts">
  21. const props = defineProps({
  22. percentage: {
  23. type: Number,
  24. default: 0,
  25. },
  26. loading: {
  27. type: Boolean,
  28. default: false,
  29. },
  30. });
  31. </script>
  32. <style scoped lang="scss">
  33. #loading-mark {
  34. position: absolute;
  35. width: 100%;
  36. height: 100%;
  37. z-index: 2000;
  38. top: 0;
  39. right: 0;
  40. bottom: 0;
  41. left: 0;
  42. .loading-box {
  43. width: 100%;
  44. height: 100%;
  45. display: flex;
  46. justify-content: center;
  47. align-items: center;
  48. transition: opacity 0.3s;
  49. background-color: rgb(0 0 0 / 64%);
  50. .loading {
  51. width: 320px;
  52. height: 120px;
  53. text-align: center;
  54. }
  55. .progress-txt {
  56. font-size: 18px;
  57. font-weight: bold;
  58. color: #327cec;
  59. b {
  60. color: #9dadba;
  61. }
  62. }
  63. .loading-txt {
  64. margin-top: 10px;
  65. text-align: center;
  66. font-size: 14px;
  67. color: #327cec;
  68. font-weight: bold;
  69. }
  70. }
  71. }
  72. </style>
2.模型加载时使用

在index.vue中(css代码就不展示了哈)

在模型加载函数中,计算出模型实时加载进度即可,关键代码如下:

完整代码: 

  1. // 导入模型
  2. const importModel = () => {
  3. loader.load(
  4. 'model/room1.glb',
  5. (gltf: any) => {
  6. model = gltf.scene;
  7. model.rotation.set(0, -Math.PI / 12, 0);
  8. model.position.set(0, -5, 0);
  9. model.traverse(function (child: any) {
  10. if (child.isMesh) {
  11. // 1.去掉文字
  12. if (child.name == 'Text') child.visible = false;
  13. // 2.修复设备颜色偏暗的问题
  14. if (child.parent.name.includes('AU')) {
  15. child.frustumCulled = false;
  16. //模型阴影
  17. child.castShadow = true;
  18. //模型自发光
  19. child.material.emissive = child.material.color;
  20. child.material.emissive.setHSL(1, 0, 0.35);
  21. child.material.emissiveMap = child.material.map;
  22. }
  23. }
  24. });
  25. // create3DDialog();
  26. scene.add(model);
  27. },
  28. (xhr: any) => {
  29. // 计算加载进度百分比
  30. state.progress = Math.floor((xhr.loaded / xhr.total) * 100);
  31. if (state.progress == 100) state.loading = false;
  32. },
  33. // 模型加载错误
  34. (error: any) => {
  35. console.log(error, 'error');
  36. }
  37. );
  38. };

接下一篇:

three.js如何实现简易3D机房?(三)显示信息弹框/标签:http://t.csdnimg.cn/sXtjv

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/521364
推荐阅读
相关标签
  

闽ICP备14008679号