|
|
@@ -12,7 +12,10 @@ Component({
|
|
|
adlScale: '0 0 0',
|
|
|
adlPos: '-0.1 -0.5 -0.05',
|
|
|
sunReady: false,
|
|
|
- tigerReady: false
|
|
|
+ tigerReady: false,
|
|
|
+ item1Loaded: false,
|
|
|
+ item2Loaded: false,
|
|
|
+ assetsProgress: 0
|
|
|
},
|
|
|
lifetimes: {
|
|
|
attached() {
|
|
|
@@ -23,23 +26,110 @@ Component({
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ emitLoadState(extra) {
|
|
|
+ const payload = Object.assign({
|
|
|
+ arReady: !!this.data.arReady,
|
|
|
+ assetsLoaded: !!this.data.loaded,
|
|
|
+ item1Loaded: !!this.data.item1Loaded,
|
|
|
+ item2Loaded: !!this.data.item2Loaded,
|
|
|
+ assetsProgress: typeof this.data.assetsProgress === 'number' ? this.data.assetsProgress : 0,
|
|
|
+ }, extra || {});
|
|
|
+ this.triggerEvent('loadState', payload);
|
|
|
+ },
|
|
|
+ pauseSunRotationSoft() {
|
|
|
+ if (this.sunRotationTimer) {
|
|
|
+ clearInterval(this.sunRotationTimer);
|
|
|
+ this.sunRotationTimer = null;
|
|
|
+ }
|
|
|
+ this.sunFrameLoading = false;
|
|
|
+ },
|
|
|
+ pauseTigerSoft() {
|
|
|
+ this.stopTigerAppearWatch();
|
|
|
+ if (this.tigerRotationTimer) {
|
|
|
+ clearInterval(this.tigerRotationTimer);
|
|
|
+ this.tigerRotationTimer = null;
|
|
|
+ }
|
|
|
+ this.tigerFrameLoading = false;
|
|
|
+ this.pauseTigerAudio();
|
|
|
+ },
|
|
|
+ pauseTigerAudio() {
|
|
|
+ if (!this.tigerAudioCtx) return;
|
|
|
+ try {
|
|
|
+ this.tigerAudioCtx.pause();
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ },
|
|
|
+ resumeTigerSoft() {
|
|
|
+ if (!this.tigerShouldRun) return;
|
|
|
+ if (this.tigerCompleted) return;
|
|
|
+ if (!this.tigerMeshes || !this.tigerMeshes.length) return;
|
|
|
+
|
|
|
+ const visibleMeshes = this.getVisibleTigerMeshes();
|
|
|
+ if (visibleMeshes && visibleMeshes.length) this.tigerTargetMeshes = visibleMeshes;
|
|
|
+
|
|
|
+ if (this.tigerAudioCtx) {
|
|
|
+ try {
|
|
|
+ this.tigerAudioCtx.volume = 1;
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ this.tigerAudioCtx.play();
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.tigerRotationTimer) return;
|
|
|
+ const intervalMs = this.getTigerFrameIntervalMs();
|
|
|
+ this.tigerRotationTimer = setInterval(() => this.updateTigerFrame(), intervalMs);
|
|
|
+ },
|
|
|
+ tryStartEntryAnimation() {
|
|
|
+ if (!this._isTracking) return;
|
|
|
+ if (!this.data.loaded) return;
|
|
|
+ if (this.data.isStartPlay1) return;
|
|
|
+ if (!this.animator1 || !this.animator2) return;
|
|
|
+ this.setData({ isStartPlay1: true }, () => {
|
|
|
+ this.playitem1Action();
|
|
|
+ });
|
|
|
+ },
|
|
|
handleReady({
|
|
|
detail
|
|
|
}) {
|
|
|
const xrScene = this.scene = detail.value;
|
|
|
// console.log('xr-scene', xrScene);
|
|
|
+ this.emitLoadState({ sceneReady: true });
|
|
|
},
|
|
|
handleAssetsProgress: function ({
|
|
|
detail
|
|
|
}) {
|
|
|
- // console.log('assets progress', detail.value);
|
|
|
+ const v = detail && detail.value;
|
|
|
+ let progress = 0;
|
|
|
+ if (v && typeof v.progress === 'number') {
|
|
|
+ progress = Math.round(Math.max(0, Math.min(1, v.progress)) * 100);
|
|
|
+ } else if (v && typeof v.loaded === 'number' && typeof v.total === 'number' && v.total > 0) {
|
|
|
+ progress = Math.round(Math.max(0, Math.min(1, v.loaded / v.total)) * 100);
|
|
|
+ }
|
|
|
+
|
|
|
+ const now = Date.now();
|
|
|
+ if (!this._lastProgressEmitAt) this._lastProgressEmitAt = 0;
|
|
|
+ if (!this._lastProgressValue && this._lastProgressValue !== 0) this._lastProgressValue = -1;
|
|
|
+
|
|
|
+ const shouldEmit = (progress === 100) || (progress !== this._lastProgressValue && now - this._lastProgressEmitAt >= 120);
|
|
|
+ if (!shouldEmit) return;
|
|
|
+
|
|
|
+ this._lastProgressEmitAt = now;
|
|
|
+ this._lastProgressValue = progress;
|
|
|
+ this.setData({ assetsProgress: progress }, () => this.emitLoadState());
|
|
|
},
|
|
|
handleAssetsLoaded: function ({
|
|
|
detail
|
|
|
}) {
|
|
|
console.log('assets loaded', detail.value);
|
|
|
this.setData({
|
|
|
- loaded: true
|
|
|
+ loaded: true,
|
|
|
+ assetsProgress: 100
|
|
|
+ }, () => {
|
|
|
+ this.emitLoadState();
|
|
|
+ if (this._pendingPlay || this._isTracking) this.play();
|
|
|
});
|
|
|
},
|
|
|
handleARReady: function ({
|
|
|
@@ -48,6 +138,8 @@ Component({
|
|
|
console.log('arReady');
|
|
|
this.setData({
|
|
|
arReady: true
|
|
|
+ }, () => {
|
|
|
+ this.emitLoadState();
|
|
|
})
|
|
|
},
|
|
|
handleItem1Loaded({ detail }) {
|
|
|
@@ -65,11 +157,20 @@ Component({
|
|
|
this.tigerMeshes = this.resolveTigerMeshesFromBG(gltf);
|
|
|
this.setData({ tigerReady: !!(this.tigerMeshes && this.tigerMeshes.length) });
|
|
|
if (this.tigerShouldRun && this.tigerStartRequested) this.scheduleTigerStart();
|
|
|
+
|
|
|
+ if (!this.data.item1Loaded) {
|
|
|
+ this.setData({ item1Loaded: true }, () => this.emitLoadState());
|
|
|
+ }
|
|
|
+ this.tryStartEntryAnimation();
|
|
|
},
|
|
|
handleItem2Loaded({ detail }) {
|
|
|
const el = detail.value.target;
|
|
|
const animator = el.getComponent("animator");
|
|
|
this.animator2 = animator;
|
|
|
+ if (!this.data.item2Loaded) {
|
|
|
+ this.setData({ item2Loaded: true }, () => this.emitLoadState());
|
|
|
+ }
|
|
|
+ this.tryStartEntryAnimation();
|
|
|
},
|
|
|
handleARTrackerState1({
|
|
|
detail
|
|
|
@@ -82,6 +183,8 @@ Component({
|
|
|
const {
|
|
|
state,
|
|
|
} = tracker;
|
|
|
+ this._lastTrackerState = state;
|
|
|
+ this._isTracking = state == 2;
|
|
|
if (state == 2) {
|
|
|
this.play()
|
|
|
} else {
|
|
|
@@ -89,28 +192,30 @@ Component({
|
|
|
}
|
|
|
},
|
|
|
play() {
|
|
|
- if (!this.data.loaded) return
|
|
|
+ if (!this.data.loaded) {
|
|
|
+ this._pendingPlay = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._pendingPlay = false;
|
|
|
this.sunShouldRun = true;
|
|
|
this.startSunRotation();
|
|
|
this.tigerShouldRun = true;
|
|
|
- this.tigerStartRequested = false;
|
|
|
+ if (!this.data.isStartPlay1) this.tigerStartRequested = false;
|
|
|
this.prepareTigerAudio();
|
|
|
this.prepareTigerFrames();
|
|
|
-
|
|
|
- if (!this.data.isStartPlay1) {
|
|
|
- this.setData({
|
|
|
- isStartPlay1: true
|
|
|
- }, () => {
|
|
|
- this.playitem1Action()
|
|
|
- })
|
|
|
+ this.tryStartEntryAnimation();
|
|
|
+ if (this.tigerHasStarted) {
|
|
|
+ this.resumeTigerSoft();
|
|
|
+ } else if (this.tigerStartRequested) {
|
|
|
+ this.scheduleTigerStart();
|
|
|
}
|
|
|
},
|
|
|
pause() {
|
|
|
this.sunShouldRun = false;
|
|
|
- this.stopSunRotation();
|
|
|
+ this.pauseSunRotationSoft();
|
|
|
this.tigerShouldRun = false;
|
|
|
- this.tigerStartRequested = false;
|
|
|
- this.stopTiger();
|
|
|
+ this._pendingPlay = false;
|
|
|
+ this.pauseTigerSoft();
|
|
|
},
|
|
|
resolveSunMeshesFromBG(gltf) {
|
|
|
if (!gltf || !this.scene) return [];
|
|
|
@@ -360,6 +465,7 @@ Component({
|
|
|
if (this.tigerCompleted) return;
|
|
|
if (this.tigerRotationTimer) return;
|
|
|
|
|
|
+ this.tigerHasStarted = true;
|
|
|
this.tigerFrameStart = 1;
|
|
|
this.tigerFrameEnd = 460;
|
|
|
this.tigerFrameCount = 460;
|
|
|
@@ -390,6 +496,7 @@ Component({
|
|
|
}
|
|
|
this.tigerFrameLoading = false;
|
|
|
this.tigerTargetMeshes = null;
|
|
|
+ this.tigerHasStarted = false;
|
|
|
if (this.scene && this.scene.assets && this.scene.assets.releaseAsset && this.tigerTextureQueue) {
|
|
|
for (const assetId of this.tigerTextureQueue) {
|
|
|
if (assetId === this.tigerLastAssetId) continue;
|