123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- Component({
- // behaviors: [require('../common/share-behavior').default],
- properties: {
- a: Number,
- },
- data: {
- loaded: false,
- arReady: false,
- isPlay: false,
- },
- lifetimes: {
- async attached() {
- console.log('data', this.data)
- },
- async detached() {
- console.error('detached', this.video)
- this.video && (this.video = null);
- this.animator && (this.animator = null);
- this.setData({
- isPlay: false
- })
- }
- },
- methods: {
- handleReady({
- detail
- }) {
- const xrScene = this.scene = detail.value;
- this.mat = new(wx.getXrFrameSystem().Matrix4)();
- console.log('xr-scene', xrScene)
- this.triggerEvent('ready')
- },
- handleAssetsProgress: function ({
- detail
- }) {
- // console.log('assets progress', detail.value.progress);
- const progress =
- Math.floor(detail.value.progress * 100)
- this.triggerEvent('progress', progress)
- },
- handleAssetsLoaded: function ({
- detail
- }) {
- console.log('assets loaded', detail.value);
- const el = detail.value.target;
- // this.setData({loaded: true});
- this.scene.event.addOnce('touchstart', this.placeNode.bind(this));
- this.triggerEvent('loaded')
- },
- handleARReady: function ({
- detail
- }) {
- console.log('arReady', this.scene.ar.arVersion);
- },
- placeNode(event) {
- const {
- clientX,
- clientY
- } = event.touches[0];
- const {
- frameWidth: width,
- frameHeight: height
- } = this.scene;
- if (clientY / height > 0.8 && clientX / width < 0.2) {
- this.scene.getNodeById('setitem').visible = false;
- this.scene.ar.resetPlane();
- } else {
- console.error('show-gltf')
- this.showAndPlay();
- }
- this.scene.event.addOnce('touchstart', this.placeNode.bind(this));
- },
- handleGLTFLoaded({
- detail
- }) {
- const el = detail.value.target;
- console.error('handleGLTFLoaded')
- const gltf = el.getComponent("gltf");
- const video = this.scene.assets.getAsset("video-texture", "animaV");
- const newMat = this.scene.assets.getAsset("material", "matAnimaV");
- this.video = video
- const animator = el.getComponent("animator");
- this.animator = animator
- console.log('animator', this.animator)
- for (const mesh of gltf.getPrimitivesByNodeName("video")) {
- mesh.material = newMat
- mesh.material.setText
- }
- },
- handleARTrackerState({
- detail
- }) {
- const tracker = detail.value;
- // 获取当前状态和错误信息
- const {
- state,
- errorMessage
- } = tracker;
- console.log('tracker-state', tracker)
- if (state == 2) {
- wx.showToast({
- title: "tracker"
- })
- this.showAndPlay();
- }
- },
- showAndPlay() {
- console.log('showAndPlay')
- if (!this.data.isPlay) {
- this.scene.ar.placeHere('setitem', true);
- this.scene.getNodeById('setitem').visible = true;
- this.setData({
- isPlay: true
- }, () => {
- if (this.video) {
- this.video.play()
- }
- if (this.animator) {
- this.animator.play('Animation')
- }
- })
- }
- }
- }
- })
|