123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- // components/ar-tracker/ar-tracker.ts
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- },
- /**
- * 组件的方法列表
- */
- methods: {
- handleReady({
- detail
- }) {
- const xrScene = this.scene = detail.value;
- this.mat = new(wx.getXrFrameSystem().Matrix4)();
- console.log('xr-scene', xrScene)
- this.triggerEvent('ready')
- },
- handleARReady() {
- console.log('handleARReady')
- },
- handleAssetsProgress: function ({
- detail
- }) {
- const progress =
- Math.floor(detail.value.progress * 100)
- console.log('progress', progress)
- this.triggerEvent('progress', progress)
- },
- handleAssetsLoaded({
- detail
- }) {
- console.log('assets loaded', detail.value);
- this.triggerEvent('loaded')
- },
- handleItem1Loaded({
- detail
- }) {
- const el = detail.value.target;
- console.warn('item1 load')
- const gltf = el.getComponent("gltf");
- 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 = () => {}
- const animator = el.getComponent("animator");
- this.animator1 = animator
- console.log('animator', this.animator)
- for (const mesh of gltf.getPrimitivesByNodeName("video")) {
- mesh.material = newMat
- }
- },
- handleItem2Loaded() {
- },
- handleItem3Loaded() {
- },
- play(type) {
- if (type === 1) {
- this.scene.getNodeById('setitem1').visible = true;
- if (this.video1) {
- this.video1.play()
- }
- if (this.animator1) {
- this.animator1.play('Animation')
- }
- }
- },
- handleARTrackerState({
- detail
- }) {
- // 事件的值即为`ARTracker`实例
- const tracker = detail.value;
- // 获取当前状态和错误信息
- const {
- state,
- errorMessage
- } = tracker;
- if (state == 2) {
- wx.showToast({
- title: '1',
- })
- this.play(1)
- }
- },
- handleARTrackerState1({
- detail
- }) {
- // 事件的值即为`ARTracker`实例
- const tracker = detail.value;
- // 获取当前状态和错误信息
- const {
- state,
- errorMessage
- } = tracker;
- if (state == 2) {
- }
- },
- handleARTrackerState2({
- detail
- }) {
- // 事件的值即为`ARTracker`实例
- const tracker = detail.value;
- // 获取当前状态和错误信息
- const {
- state,
- errorMessage
- } = tracker;
- if (state == 2) {}
- }
- }
- })
|