|
|
@@ -1,5 +1,5 @@
|
|
|
-var sceneReadyBehavior = require('../behavior-scene/scene-ready');
|
|
|
-var handleDecodedXML = require('../behavior-scene/util').handleDecodedXML;
|
|
|
+var sceneReadyBehavior = require("../behavior-scene/scene-ready");
|
|
|
+var handleDecodedXML = require("../behavior-scene/util").handleDecodedXML;
|
|
|
var xmlCode = `<xr-scene ar-system="modes:Marker" id="xr-scene" bind:ready="handleReady" bind:arReady="handleARReady" bind:log="handleLog">
|
|
|
<xr-assets bind:progress="handleAssetsProgress" bind:loaded="handleAssetsLoaded">
|
|
|
<xr-asset-material asset-id="ar-anchor" effect="standrand" uniforms="u_baseColorFactor:0 1 0 1"></xr-asset-material>
|
|
|
@@ -24,12 +24,19 @@ var xmlCode = `<xr-scene ar-system="modes:Marker" id="xr-scene
|
|
|
Page({
|
|
|
behaviors: [sceneReadyBehavior],
|
|
|
data: {
|
|
|
- xmlCode: '<div class="codeWrap">' + handleDecodedXML(xmlCode) + '</div>',
|
|
|
- markerImg: 'https://ossxiaoan.4dage.com/hq-eduction-vr/hq-bag.jpg',
|
|
|
+ xmlCode: '<div class="codeWrap">' + handleDecodedXML(xmlCode) + "</div>",
|
|
|
+ markerImg: "https://ossxiaoan.4dage.com/hq-eduction-vr/hq-bag.jpg",
|
|
|
+ markerImg2:
|
|
|
+ "https://houseoss.4dkankan.com/project/hq-eduction-vr/public/1.png",
|
|
|
+ markerImg3:
|
|
|
+ "https://houseoss.4dkankan.com/project/hq-eduction-vr/public/2.png",
|
|
|
+ markerImg4:
|
|
|
+ "https://houseoss.4dkankan.com/project/hq-eduction-vr/public/4.png",
|
|
|
showLoading: true,
|
|
|
- loadingText: '正在初始化相机…',
|
|
|
+ loadingText: "正在初始化相机…",
|
|
|
loadingProgress: 0,
|
|
|
- _wxLoadingText: ''
|
|
|
+ _wxLoadingText: "",
|
|
|
+ showGuide: true,
|
|
|
},
|
|
|
onUnload() {
|
|
|
if (wx.hideLoading) wx.hideLoading();
|
|
|
@@ -40,16 +47,22 @@ Page({
|
|
|
const assetsLoaded = !!detail.assetsLoaded;
|
|
|
const item1Loaded = !!detail.item1Loaded;
|
|
|
const item2Loaded = !!detail.item2Loaded;
|
|
|
- const p = typeof detail.assetsProgress === 'number' ? detail.assetsProgress : 0;
|
|
|
+ const p =
|
|
|
+ typeof detail.assetsProgress === "number" ? detail.assetsProgress : 0;
|
|
|
|
|
|
let loadingText = this.data.loadingText;
|
|
|
- if (!arReady) loadingText = '';
|
|
|
- else if (!assetsLoaded) loadingText = '';
|
|
|
- else if (!item1Loaded || !item2Loaded) loadingText = '';
|
|
|
- else loadingText = '';
|
|
|
+ if (!arReady) loadingText = "";
|
|
|
+ else if (!assetsLoaded) loadingText = "";
|
|
|
+ else if (!item1Loaded || !item2Loaded) loadingText = "";
|
|
|
+ else loadingText = "";
|
|
|
|
|
|
const loadingProgress = Math.max(0, Math.min(100, Math.round(p)));
|
|
|
- const showLoading = !(arReady && assetsLoaded && item1Loaded && item2Loaded);
|
|
|
+ const showLoading = !(
|
|
|
+ arReady &&
|
|
|
+ assetsLoaded &&
|
|
|
+ item1Loaded &&
|
|
|
+ item2Loaded
|
|
|
+ );
|
|
|
|
|
|
this.setData({ showLoading, loadingText, loadingProgress });
|
|
|
|
|
|
@@ -60,22 +73,29 @@ Page({
|
|
|
}
|
|
|
} else {
|
|
|
if (wx.hideLoading) wx.hideLoading();
|
|
|
- if (this.data._wxLoadingText) this.setData({ _wxLoadingText: '' });
|
|
|
+ if (this.data._wxLoadingText) this.setData({ _wxLoadingText: "" });
|
|
|
}
|
|
|
},
|
|
|
- handleChangeMarkerImg: function() {
|
|
|
+ handleARTrackerState(e) {
|
|
|
+ const { isTracking } = e.detail || {};
|
|
|
+ if (isTracking) {
|
|
|
+ // 识别到marker后隐藏guide
|
|
|
+ this.setData({ showGuide: false });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleChangeMarkerImg: function () {
|
|
|
wx.chooseMedia({
|
|
|
count: 1,
|
|
|
- sizeType: ['compressed'],
|
|
|
- mediaType: ['image'],
|
|
|
- sourceType: ['album'],
|
|
|
- success: res => {
|
|
|
+ sizeType: ["compressed"],
|
|
|
+ mediaType: ["image"],
|
|
|
+ sourceType: ["album"],
|
|
|
+ success: (res) => {
|
|
|
const fp = res.tempFiles[0].tempFilePath;
|
|
|
- this.setData({markerImg: fp});
|
|
|
+ this.setData({ markerImg: fp });
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error("[xr-demo]chooseImage failed", err);
|
|
|
},
|
|
|
- fail: err => {
|
|
|
- console.error('[xr-demo]chooseImage failed', err);
|
|
|
- }
|
|
|
});
|
|
|
- }
|
|
|
+ },
|
|
|
});
|