|
@@ -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`实例
|