当前位置: 首页 > news >正文

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

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

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

2.pages.json配置

{"path": "pages/resource/preview/preview","style": {"navigationBarTitleText": "效果预览","enablePullDownRefresh": false,"navigationBarBackgroundColor": "#73ceda","usingComponents": {"xr-start": "/wxcomponents/xr-start"},"disableScroll": true}}

3.manifest.json配置

"mp-weixin": {"appid": "自己的appid","setting": {"urlCheck": false,"postcss": true,"es6": true,"minified": true,"ignoreDevUnusedFiles": false,"ignoreUploadUnusedFiles": false},"usingComponents": true,"lazyCodeLoading": "requiredComponents"},

4.使用preview.vue

<template><view style="display: flex;flex-direction: column;"><xr-start :modelPath="modelPath" id="main-frame" disable-scroll :width="renderWidth" :height="renderHeight":style="'width:'+width+'px;height:'+height+'px;'"></xr-start></view>
</template><script>export default {onLoad(option) {this.modelPath = option.modelPath;this.width = uni.getWindowInfo().windowWidththis.height = uni.getWindowInfo().windowHeightconst dpi = uni.getWindowInfo().pixelRatiothis.renderWidth = this.width * dpithis.renderHeight = this.height * dpi},data() {return {width: 300,height: 300,renderWidth: 300,renderHeight: 300,modelPath: ''}},methods: {}}
</script><style>
</style>

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

http://www.lryc.cn/news/389459.html

相关文章:

  • 机器人运动范围检测 c++
  • kettle从入门到精通 第七十四课 ETL之kettle kettle调用https接口教程,忽略SSL校验
  • C++轻量级 线程间异步消息架构(向曾经工作的ROSA-RB以及共事的DOPRA的老兄弟们致敬)
  • Kotlin中的类
  • VSCode中常用的快捷键
  • 代码随想录-Day45
  • Rust Eq 和 PartialEq
  • 思考如何学习一门编程语言?
  • 顺序串算法库构建
  • [论文阅读笔记33] Matching Anything by Segmenting Anything (CVPR2024 highlight)
  • 阿里Nacos下载、安装(保姆篇)
  • 四、golang基础之defer
  • 机器人----四元素
  • IBM Spectrum LSF Application Center 提供单一界面来管理应用程序、用户、资源和数据
  • 如何选择品牌推广公司?哪家好?收费标准及评价!
  • JDeveloper 12C 官网下载教程
  • 中英双语介绍美国的州:印第安纳州(Indiana)
  • Flink实现准确和高效流处理的关键问题
  • isidentifier()方法——判断字符串是否为合法的Python标识符或变量名
  • 天猫商品列表数据接口(Tmall.item_search)
  • React+TS前台项目实战(二十一)-- Search业务组件封装实现全局搜索
  • SEO与AI的结合:如何用ChatGPT生成符合搜索引擎优化的内容
  • 【信息系统项目管理师知识点速记】组织通用管理:知识管理
  • CM-UNet: Hybrid CNN-Mamba UNet for Remote Sensing Image Semantic Segmentation
  • DP:子序列问题
  • Spring Data与多数据源配置
  • 【前端vue3】TypeScrip-类型推论和类型别名
  • javaEE——Servlet
  • Kotlin扩展函数(also apply run let)和with函数
  • C语言笔记27 •单链表介绍•