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

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

javascript 复制代码
// index.js
Component({
	properties: {
		modelPath: { // vue页面传过来的模型
			type: String,
			value: ''
		}
	},
	data: {},
	methods: {}
})
javascript 复制代码
{ // index.json
	"component": true,
	"renderer": "xr-frame",
	"usingComponents": {}
}
javascript 复制代码
<!-- 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配置

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

3.manifest.json配置

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

4.使用preview.vue

javascript 复制代码
<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().windowWidth
			this.height = uni.getWindowInfo().windowHeight
			const dpi = uni.getWindowInfo().pixelRatio
			this.renderWidth = this.width * dpi
			this.renderHeight = this.height * dpi
		},
		data() {
			return {
				width: 300,
				height: 300,
				renderWidth: 300,
				renderHeight: 300,
				modelPath: ''
			}
		},
		methods: {}
	}
</script>

<style>
</style>

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

相关推荐
仙古.梦回~12 分钟前
uniapp启动页面鉴权页面闪烁问题
uni-app
源码大师1 小时前
一键部署,轻松管理最新课堂知识付费小程序源码系统 带完整的安装代码包以及搭建教程
微信小程序·知识付费小程序·知识付费小程序源码系统·知识付费小程序系统
酷爱码3 小时前
商家团购app微信小程序模板
微信小程序·小程序
枫琳晚9 小时前
微信小程序开发实战课后习题解答————第一章(作业版)
微信小程序·小程序
井眼11 小时前
微信小程序-插槽slot
微信小程序·小程序
迅狐源码工厂14 小时前
选哪个短剧系统源码好:全面评估与决策指南
uni-app·教育电商
泉城清晨的晚风14 小时前
【uniapp】上传附件+Java后端
java·开发语言·uni-app
卿本无忧15 小时前
uniapp H5端使用百度地图
uni-app
恰小面包15 小时前
微信小程序实现双向数据绑定
前端·微信小程序·小程序
2401_8459356816 小时前
Java露营基地预约小程序预约下单系统源码
微信·微信小程序·小程序·微信公众平台·微信开放平台