gemer 1 سال پیش
والد
کامیت
8abb57431d

+ 72 - 16
miniprogram/components/ar-tracker/ar-tracker.js

@@ -12,7 +12,8 @@ Component({
    * 组件的初始数据
    */
   data: {
-
+    loaded: false,
+    isStartPlay1: false,
   },
 
   /**
@@ -45,6 +46,9 @@ Component({
     }) {
       console.log('assets loaded', detail.value);
       this.triggerEvent('loaded')
+      this.setData({
+        loaded: true
+      })
 
     },
     handleItem1Loaded({
@@ -56,34 +60,84 @@ Component({
       const video = this.scene.assets.getAsset("video-texture", "item1-v");
       const newMat = this.scene.assets.getAsset("material", "item1-m");
       this.video1 = video
-      this.video1.onEnd = () => {}
+      // this.video1.onEnd = () => {}
       const animator = el.getComponent("animator");
       this.animator1 = animator
-      console.log('animator', this.animator)
+      console.warn('animator1', this.animator1)
       for (const mesh of gltf.getPrimitivesByNodeName("video")) {
         mesh.material = newMat
       }
 
     },
-    handleItem2Loaded() {
-
+    handleItem2Loaded({
+      detail
+    }) {
+      const el = detail.value.target;
+      console.warn('item2 load')
+      const gltf = el.getComponent("gltf");
+      const video = this.scene.assets.getAsset("video-texture", "item2-v");
+      const newMat = this.scene.assets.getAsset("material", "item2-m");
+      this.video2 = video
+      for (const mesh of gltf.getPrimitivesByNodeName("video")) {
+        mesh.material = newMat
+      }
     },
-    handleItem3Loaded() {
-
+    handleItem3Loaded({
+      detail
+    }) {
+      const el = detail.value.target;
+      console.warn('item3 load')
+      const gltf = el.getComponent("gltf");
+      const animator = el.getComponent("animator");
+      this.animator3 = animator
+      console.warn('animator3', this.animator3)
     },
     play(type) {
+      if (this.data.loaded) {
+        if (type === 1) {
+          console.warn('play 1')
+          if (this.video1) {
+            this.data.isStartPlay1 ? this.video1.resume() : this.video1.play()
+          }
+          if (this.animator1) {
+            this.data.isStartPlay1 ? this.animator1.resume('Animation') : this.animator1.play('Animation')
+          }
+          this.setData({
+            isStartPlay1: true
+          })
+        }
+        if (type === 2) {
+          console.warn('play 2')
+          if (this.video2) {
+            this.data.isStartPlay2 ? this.video2.resume() : this.video2.play()
+          }
+          this.setData({
+            isStartPlay2: true
+          })
+        }
+      }
+
+    },
+
+    pause(type) {
       if (type === 1) {
-        this.scene.getNodeById('setitem1').visible = true;
+        console.warn('pause 1')
         if (this.video1) {
-          this.video1.play()
+          this.video1.pause()
         }
         if (this.animator1) {
-          this.animator1.play('Animation')
+          this.animator1.pause('Animation')
+        }
+      }
+      if (type === 2) {
+        console.warn('pause 2')
+        if (this.video2) {
+          this.video2.pause()
         }
       }
     },
 
-    handleARTrackerState({
+    handleARTrackerState1({
       detail
     }) {
       // 事件的值即为`ARTracker`实例
@@ -94,13 +148,12 @@ Component({
         errorMessage
       } = tracker;
       if (state == 2) {
-        wx.showToast({
-          title: '1',
-        })
         this.play(1)
+      } else {
+        this.data.isStartPlay1 && this.pause(1)
       }
     },
-    handleARTrackerState1({
+    handleARTrackerState2({
       detail
     }) {
       // 事件的值即为`ARTracker`实例
@@ -111,10 +164,13 @@ Component({
         errorMessage
       } = tracker;
       if (state == 2) {
+        this.play(2);
+      } else {
+        this.pause(2);
 
       }
     },
-    handleARTrackerState2({
+    handleARTrackerState3({
       detail
     }) {
       // 事件的值即为`ARTracker`实例

+ 14 - 6
miniprogram/components/ar-tracker/ar-tracker.wxml

@@ -17,20 +17,28 @@
   <xr-env env-data="xr-frame-team-workspace-day" />
 
   <xr-node>
-    <xr-ar-tracker id="ar-tracker-1" mode="Marker" src="https://houseoss.4dkankan.com/mini-ar-test/AR/1/marker.png" bind:ar-tracker-state="handleARTrackerState">
+    <xr-ar-tracker id="ar-tracker-1" mode="Marker" src="https://houseoss.4dkankan.com/mini-ar-test/AR/1/marker.png" bind:ar-tracker-state="handleARTrackerState1">
+      <xr-gltf model="item1" scale="5 5 5" rotation="270 0 0" bind:gltf-loaded="handleItem1Loaded"></xr-gltf>
     </xr-ar-tracker>
-    <xr-ar-tracker id="ar-tracker-2" mode="Marker" src="https://houseoss.4dkankan.com/mini-ar-test/AR/2/marker.png" bind:ar-tracker-state="handleARTrackerState1">
+    <xr-ar-tracker id="ar-tracker-2" mode="Marker" src="https://houseoss.4dkankan.com/mini-ar-test/AR/2/marker.png" bind:ar-tracker-state="handleARTrackerState2">
+      <xr-gltf model="item2" scale="0.08 0.08 0.08" rotation="0 -90 90" bind:gltf-loaded="handleItem2Loaded"></xr-gltf>
+
     </xr-ar-tracker>
-    <xr-ar-tracker id="ar-tracker-3" mode="Marker" src="https://houseoss.4dkankan.com/mini-ar-test/AR/3/marker.png" bind:ar-tracker-state="handleARTrackerState2">
+    <xr-ar-tracker id="ar-tracker-3" mode="Marker" src="https://houseoss.4dkankan.com/mini-ar-test/AR/3/marker.png" bind:ar-tracker-state="handleARTrackerState3">
+      <xr-gltf model="item3" scale="5 5 5" rotation="270 0 0" bind:gltf-loaded="handleItem3Loaded"></xr-gltf>
     </xr-ar-tracker>
 
     <!-- <xr-camera id="camera" node-id="camera" position="1 1 1" clear-color="0.925 0.925 0.925 1" far="2000" background="ar" is-ar-camera></xr-camera> -->
-    <xr-camera id="camera" node-id="camera" clear-color="0.925 0.925 0.925 1" background="ar" is-ar-camera></xr-camera>
+    <!-- 
+    <xr-camera id="camera1" node-id="camera1" clear-color="0.925 0.925 0.925 1" background="ar" target="item1-wrpper" camera-orbit-control=""></xr-camera> -->
+
+    <xr-camera id="camera" position="1 1 1" node-id="camera" clear-color="0.925 0.925 0.925 1" background="ar" is-ar-camera></xr-camera>
+
   </xr-node>
 
-  <xr-node node-id="setitem1" visible="false">
+  <!-- <xr-node node-id="setitem1" visible="false">
     <xr-gltf model="item1" scale="0.5 0.5 0.5" rotation="0 0 0" bind:gltf-loaded="handleItem1Loaded"></xr-gltf>
-  </xr-node>
+  </xr-node> -->
   <xr-node node-id="lights">
     <xr-light type="ambient" color="1 1 1" intensity="2" />
     <xr-light type="directional" rotation="90 60 0" color="1 1 1" intensity="1" />

+ 0 - 5
miniprogram/components/xr-ar-vio-marker-2/index.js

@@ -84,11 +84,6 @@ Component({
       for (const mesh of gltf.getPrimitivesByNodeName("video")) {
         mesh.material = newMat
       }
-      if (this.data.fromScan) {
-        console.log('fromScan', this.data.fromScan);
-        this.scene.ar.resetPlane();
-        this.showAndPlay();
-      }
     },
     handleARTrackerState({
       detail

+ 38 - 38
project.config.json

@@ -1,39 +1,39 @@
-{
-  "description": "项目配置文件",
-  "miniprogramRoot": "miniprogram/",
-  "compileType": "miniprogram",
-  "setting": {
-    "useCompilerPlugins": [
-      "typescript"
-    ],
-    "babelSetting": {
-      "ignore": [],
-      "disablePlugins": [],
-      "outputPath": ""
-    },
-    "coverView": false,
-    "postcss": false,
-    "minified": false,
-    "enhance": true,
-    "showShadowRootInWxmlPanel": false,
-    "packNpmRelationList": [],
-    "ignoreUploadUnusedFiles": true,
-    "compileHotReLoad": false,
-    "skylineRenderEnable": true,
-    "es6": true
-  },
-  "simulatorType": "wechat",
-  "simulatorPluginLibVersion": {},
-  "condition": {},
-  "srcMiniprogramRoot": "miniprogram/",
-  "editorSetting": {
-    "tabIndent": "insertSpaces",
-    "tabSize": 2
-  },
-  "libVersion": "trial",
-  "packOptions": {
-    "ignore": [],
-    "include": []
-  },
-  "appid": "wxd55ee54235e90359"
+{
+  "description": "项目配置文件",
+  "miniprogramRoot": "miniprogram/",
+  "compileType": "miniprogram",
+  "setting": {
+    "useCompilerPlugins": [
+      "typescript"
+    ],
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
+    },
+    "coverView": false,
+    "postcss": false,
+    "minified": false,
+    "enhance": true,
+    "showShadowRootInWxmlPanel": false,
+    "packNpmRelationList": [],
+    "ignoreUploadUnusedFiles": true,
+    "compileHotReLoad": false,
+    "skylineRenderEnable": true,
+    "es6": true
+  },
+  "simulatorType": "wechat",
+  "simulatorPluginLibVersion": {},
+  "condition": {},
+  "srcMiniprogramRoot": "miniprogram/",
+  "editorSetting": {
+    "tabIndent": "insertSpaces",
+    "tabSize": 2
+  },
+  "libVersion": "trial",
+  "packOptions": {
+    "ignore": [],
+    "include": []
+  },
+  "appid": "wxd55ee54235e90359"
 }

+ 21 - 21
project.private.config.json

@@ -1,22 +1,22 @@
-{
-  "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
-  "projectname": "mini-ar-demo",
-  "setting": {
-    "compileHotReLoad": true,
-    "skylineRenderEnable": true
-  },
-  "libVersion": "3.4.1",
-  "condition": {
-    "miniprogram": {
-      "list": [
-        {
-          "name": "pages/dunhuang/dunhuang",
-          "pathName": "pages/dunhuang/dunhuang",
-          "query": "fromScan=1",
-          "launchMode": "default",
-          "scene": null
-        }
-      ]
-    }
-  }
+{
+  "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
+  "projectname": "mini-ar-demo",
+  "setting": {
+    "compileHotReLoad": true,
+    "skylineRenderEnable": true
+  },
+  "libVersion": "3.4.1",
+  "condition": {
+    "miniprogram": {
+      "list": [
+        {
+          "name": "pages/dunhuang/dunhuang",
+          "pathName": "pages/dunhuang/dunhuang",
+          "query": "fromScan=1",
+          "launchMode": "default",
+          "scene": null
+        }
+      ]
+    }
+  }
 }