Prechádzať zdrojové kódy

更新胡迪动画帧逻辑

wangfumin 2 dní pred
rodič
commit
d27bd37c7c

+ 80 - 5
小程序入口_嵌套展示端/components/xr-ar-2dmarker/index.js

@@ -95,6 +95,7 @@ Component({
       this.tigerShouldRun = true;
       this.tigerStartRequested = false;
       this.prepareTigerAudio();
+      this.prepareTigerFrames();
 
       if (!this.data.isStartPlay1) {
         this.setData({
@@ -362,11 +363,12 @@ Component({
       this.tigerFrameStart = 1;
       this.tigerFrameEnd = 460;
       this.tigerFrameCount = 460;
-      const skipFrames = 38;
+      const skipFrames = 29;
       this.tigerPlayedFrames = Math.min(skipFrames, this.tigerFrameCount);
-      this.tigerTextureCacheLimit = 12;
+      this.tigerTextureCacheLimit = 48;
       if (!this.tigerTextureCache) this.tigerTextureCache = new Map();
       if (!this.tigerTextureQueue) this.tigerTextureQueue = [];
+      this.prepareTigerFrames();
 
       this.updateTigerFrame();
       const intervalMs = this.getTigerFrameIntervalMs();
@@ -397,6 +399,73 @@ Component({
       this.tigerTextureCache = null;
       this.tigerTextureQueue = null;
       this.stopTigerAudio();
+      this.stopTigerFramesPreload();
+    },
+    prepareTigerFrames() {
+      if (this.tigerFramesPrepared || this.tigerFramesPreparing) return;
+      this.tigerFramesPreparing = true;
+      this.tigerFramesAbort = false;
+
+      if (!this.tigerFrameTempPaths) this.tigerFrameTempPaths = Object.create(null);
+      if (!this.tigerFrameDownloadTasks) this.tigerFrameDownloadTasks = Object.create(null);
+
+      const startNo = 39;
+      const endNo = 460;
+      const maxConcurrent = 6;
+      let nextNo = startNo;
+      let inFlight = 0;
+
+      const pump = () => {
+        if (this.tigerFramesAbort) return;
+
+        while (inFlight < maxConcurrent && nextNo <= endNo && !this.tigerFramesAbort) {
+          const frameNo = nextNo++;
+          const frameStr = String(frameNo).padStart(3, '0');
+          const assetId = `tigerx-${frameStr}`;
+          if (this.tigerFrameTempPaths[assetId]) continue;
+
+          inFlight += 1;
+          const task = wx.downloadFile({
+            url: `https://ossxiaoan.4dage.com/hq-eduction-vr/tiger/Tigerx_${frameStr}.png`,
+            success: (res) => {
+              if (this.tigerFramesAbort) return;
+              const tempPath = res && res.statusCode === 200 ? res.tempFilePath : '';
+              if (tempPath) this.tigerFrameTempPaths[assetId] = tempPath;
+            },
+            complete: () => {
+              inFlight -= 1;
+              if (this.tigerFrameDownloadTasks) delete this.tigerFrameDownloadTasks[assetId];
+              if (nextNo > endNo && inFlight <= 0) {
+                this.tigerFramesPrepared = true;
+                this.tigerFramesPreparing = false;
+                return;
+              }
+              pump();
+            }
+          });
+          if (task && typeof task.abort === 'function') this.tigerFrameDownloadTasks[assetId] = task;
+        }
+      };
+
+      pump();
+    },
+    stopTigerFramesPreload() {
+      this.tigerFramesAbort = true;
+      this.tigerFramesPrepared = false;
+      this.tigerFramesPreparing = false;
+      if (this.tigerFrameDownloadTasks) {
+        for (const k of Object.keys(this.tigerFrameDownloadTasks)) {
+          const task = this.tigerFrameDownloadTasks[k];
+          if (task && typeof task.abort === 'function') {
+            try {
+              task.abort();
+            } catch (e) {
+            }
+          }
+        }
+      }
+      this.tigerFrameDownloadTasks = null;
+      this.tigerFrameTempPaths = null;
     },
     async updateTigerFrame() {
       if (this.tigerFrameLoading) return;
@@ -439,7 +508,8 @@ Component({
 
         const frameStr = String(frameNo).padStart(3, '0');
         const assetId = `tigerx-${frameStr}`;
-        const src = `https://ossxiaoan.4dage.com/hq-eduction-vr/tiger/Tigerx_${frameStr}.png`;
+        const localSrc = this.tigerFrameTempPaths && this.tigerFrameTempPaths[assetId];
+        const src = localSrc || `https://ossxiaoan.4dage.com/hq-eduction-vr/tiger/Tigerx_${frameStr}.png`;
 
         let texture = this.tigerTextureCache && this.tigerTextureCache.get(assetId);
         if (!texture) {
@@ -577,7 +647,8 @@ Component({
       if (this.tigerAudioStarted) return;
 
       const audioCtx = this.tigerAudioCtx;
-      const startOffsetSec = 2;
+      const requestedOffsetSec = typeof this.tigerAudioStartOffsetSec === 'number' ? this.tigerAudioStartOffsetSec : 2;
+      const startOffsetSec = Math.max(0, Math.min(3, requestedOffsetSec));
       const startNow = () => {
         if (!this.tigerAudioCtx) return;
         if (this.tigerAudioStarted) return;
@@ -587,7 +658,11 @@ Component({
         }
         try {
           const t = Number(audioCtx.currentTime);
-          if (!Number.isFinite(t) || Math.abs(t - startOffsetSec) > 0.2) audioCtx.seek(startOffsetSec);
+          if (startOffsetSec > 0) {
+            if (!Number.isFinite(t) || Math.abs(t - startOffsetSec) > 0.2) audioCtx.seek(startOffsetSec);
+          } else {
+            if (Number.isFinite(t) && t > 0.1) audioCtx.seek(0);
+          }
         } catch (e) {
         }
         try {

+ 1 - 1
小程序入口_嵌套展示端/pages/ar/index.js

@@ -25,7 +25,7 @@ Page({
   behaviors: [sceneReadyBehavior],
   data: {
     xmlCode: '<div class="codeWrap">' + handleDecodedXML(xmlCode) + '</div>',
-    markerImg: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/marker/2dmarker-test.jpg'
+    markerImg: 'https://ossxiaoan.4dage.com/hq-eduction-vr/hq-bag.jpg'
   },
   handleChangeMarkerImg: function() {
     wx.chooseMedia({