uniapp微信小程序使用xr加載模型的操作方法
1.在根目錄與pages同級(jí)創(chuàng)建如下目錄結(jié)構(gòu)和文件:

// index.js
Component({
properties: {
modelPath: { // vue頁(yè)面?zhèn)鬟^(guò)來(lái)的模型
type: String,
value: ''
}
},
data: {},
methods: {}
}){ // index.json
"component": true,
"renderer": "xr-frame",
"usingComponents": {}
}<!-- index.wxml -->
<!-- 加載靜態(tài)模型 -->
<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": "效果預(yù)覽",
"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().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>不占主包空間(可以忽略)
到此這篇關(guān)于uniapp微信小程序使用xr加載模型的文章就介紹到這了,更多相關(guān)uniapp微信小程序使用xr內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文帶你掌握J(rèn)avaScript中數(shù)組處理方法(含靜態(tài)方法)
這篇文章主要為大家詳細(xì)介紹了JavaScript中數(shù)組處理方法,包含靜態(tài)方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2026-02-02
基于BootStrap Metronic開(kāi)發(fā)框架經(jīng)驗(yàn)小結(jié)【六】對(duì)話框及提示框的處理和優(yōu)化
這篇文章主要介紹了基于BootStrap Metronic開(kāi)發(fā)框架經(jīng)驗(yàn)小結(jié)【六】對(duì)話框及提示框的處理和優(yōu)化的相關(guān)知識(shí),主要對(duì)比說(shuō)明在Bootstrap開(kāi)發(fā)中用到的這些技術(shù)要點(diǎn),對(duì)此文感興趣的朋友一起學(xué)習(xí)吧2016-05-05
JavaScript實(shí)現(xiàn)拖動(dòng)對(duì)話框效果的實(shí)現(xiàn)代碼
這篇文章主要介紹了JavaScript實(shí)現(xiàn)拖動(dòng)對(duì)話框效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
JS實(shí)現(xiàn)的簡(jiǎn)單折疊展開(kāi)動(dòng)畫(huà)效果示例
這篇文章主要介紹了JS實(shí)現(xiàn)的簡(jiǎn)單折疊展開(kāi)動(dòng)畫(huà)效果,可實(shí)現(xiàn)類似百度頁(yè)面分享按鈕一樣的折疊展開(kāi)動(dòng)畫(huà)效果,涉及javascript頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-04-04

