• uniapp微信小程序使用xr加载模型


    1.在根目录与pages同级创建如下目录结构和文件:

    1. // index.js
    2. Component({
    3. properties: {
    4. modelPath: { // vue页面传过来的模型
    5. type: String,
    6. value: ''
    7. }
    8. },
    9. data: {},
    10. methods: {}
    11. })
    1. { // index.json
    2. "component": true,
    3. "renderer": "xr-frame",
    4. "usingComponents": {}
    5. }
    1. <xr-scene render-system="alpha:true" bind:ready="handleReady">
    2. <xr-node>
    3. <xr-light type="ambient" color="1 1 1" intensity="2" />
    4. <xr-light type="spot" position="3 3 3" color="1 1 1" range="3" intensity="5" />
    5. <xr-assets>
    6. <xr-asset-load type="gltf" asset-id="gltf-model" src="{{modelPath}}"/>
    7. xr-assets>
    8. <xr-gltf scale="0.7 0.7 0.7" node-id="gltf-model" bind:gltf-loaded="handleGLTFLoaded" model="gltf-model">xr-gltf>
    9. xr-node>
    10. <xr-camera id="camera" clear-color="0 0 0 0" position="1 1 2" target="gltf-model" camera-orbit-control/>
    11. xr-scene>

    2.pages.json配置

    1. {
    2. "path": "pages/resource/preview/preview",
    3. "style": {
    4. "navigationBarTitleText": "效果预览",
    5. "enablePullDownRefresh": false,
    6. "navigationBarBackgroundColor": "#73ceda",
    7. "usingComponents": {
    8. "xr-start": "/wxcomponents/xr-start"
    9. },
    10. "disableScroll": true
    11. }
    12. }

    3.manifest.json配置

    1. "mp-weixin": {
    2. "appid": "自己的appid",
    3. "setting": {
    4. "urlCheck": false,
    5. "postcss": true,
    6. "es6": true,
    7. "minified": true,
    8. "ignoreDevUnusedFiles": false,
    9. "ignoreUploadUnusedFiles": false
    10. },
    11. "usingComponents": true,
    12. "lazyCodeLoading": "requiredComponents"
    13. },

    4.使用preview.vue

    1. <script>
    2. export default {
    3. onLoad(option) {
    4. this.modelPath = option.modelPath;
    5. this.width = uni.getWindowInfo().windowWidth
    6. this.height = uni.getWindowInfo().windowHeight
    7. const dpi = uni.getWindowInfo().pixelRatio
    8. this.renderWidth = this.width * dpi
    9. this.renderHeight = this.height * dpi
    10. },
    11. data() {
    12. return {
    13. width: 300,
    14. height: 300,
    15. renderWidth: 300,
    16. renderHeight: 300,
    17. modelPath: ''
    18. }
    19. },
    20. methods: {}
    21. }
    22. script>
    23. <style>
    24. style>

    不占主包空间(可以忽略)

    5.后续出现报错:

    需要在app.json添加一行配置"lazyCodeLoading": "requiredComponents",以下是uniappp中配置

  • 相关阅读:
    Linux计划任务
    泰坦尼克号幸存者数据分析
    [ESP32]:TFLite Micro推理CIFAR10模型
    React 全栈体系(九)
    YOLOv7学习笔记(一)——概述+环境+训练
    【Apache Flink】基于时间和窗口的算子-配置时间特性
    小红书2022上半年品牌营销数据报告
    vue2 el-input-number 千分位显示的支持(不影响v-model的数值取值)
    Flutter:文件与网络操作摘要
    redis工具类
  • 原文地址:https://blog.csdn.net/weixin_46029283/article/details/140043804