123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
- Page({
- behaviors:[sceneReadyBehavior],
- moveTimes: 0,
- data: {
- // 内置
- height: 600,
- heightScale: 0.85,
- showBackBtn: true,
- // 页面
- useScan: true,
- useGLTF: false,
- useVideo1: false,
- useVideo2: false,
- markerList: [],
- // scan 相关
- showMarkerWrap: false,
- markerLeft: -50,
- markerTop: 50,
- markerWidth: 0,
- markerHeight: 0,
- // 全局状态
- dataReady: false,
- // Debug
- debugMsg: 'Defalut Words',
- },
- onLoad( ) {
- this.refreshData();
- },
- resetData() {
- this.setData({
- dataReady: false,
- showMarkerWrap: false,
- markerLeft: -50,
- markerTop: 50,
- markerWidth: 0,
- markerHeight: 0,
- })
- },
- refreshData() {
- this.resetData();
- // 模拟用的数据集合,可以跟进需要切换为后端接口
- const mockDataList = [];
- // 识别框
- if (this.data.useScan) {
- mockDataList.push({
- name: '微信球',
- markerImg: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/wxball.jpg',
- type: 'scan',
- src: '',
- });
- }
- // glTF模型
- if (this.data.useGLTF) {
- mockDataList.push({
- name: '扫描画',
- markerImg: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/portalImage.jpg',
- type: 'gltf',
- src: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/fiesta_tea/scene.gltf',
- });
- }
- // 视频
- if (this.data.useVideo1) {
- mockDataList.push({
- name: '2Dmarker',
- markerImg: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/marker/2dmarker-test.jpg',
- type: 'video',
- src: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/videos/cat.mp4',
- });
- }
- if (this.data.useVideo2) {
- mockDataList.push({
- name: '虎年企鹅',
- markerImg: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/marker/osdmarker-test.jpg',
- type: 'video',
- src: 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo/videos/paris.mp4',
- });
- }
- // 需要使用的marker
- const markerList = []
- let scanIndex = 0
- let videoIndex = 0
- let gltfIndex = 0
- for (let i = 0; i < mockDataList.length; i++) {
- const mockItem = mockDataList[i];
- switch (mockItem.type) {
- case 'scan': // scan
- const scanId = 'scan' + scanIndex
- markerList.push({
- id: scanId,
- name: mockItem.name,
- renderType: mockItem.type,
- markerImage: mockItem.markerImg,
- src: mockItem.src,
- });
- scanIndex++;
- break;
- case 'video': // video
- const videoId = 'video' + videoIndex
- markerList.push({
- id: videoId,
- name: mockItem.name,
- renderType: mockItem.type,
- markerImage: mockItem.markerImg,
- src: mockItem.src,
- });
- videoIndex++;
- break;
- case 'gltf': // gltf
- const gltfId = 'gltf' + gltfIndex
- markerList.push({
- id: gltfId,
- name: mockItem.name,
- renderType: mockItem.type,
- markerImage: mockItem.markerImg,
- src: mockItem.src,
- });
- gltfIndex++;
- break;
- }
- }
- console.log('markerList', markerList);
- this.setData({
- dataReady: true,
- markerList: markerList
- });
- this.setData({
- debugMsg: 'markerList:' + markerList.length
- })
- },
- tapScan() {
- this.setData({
- useScan: !this.data.useScan
- });
- this.refreshData();
- },
- tapGLTF() {
- this.setData({
- useGLTF: !this.data.useGLTF
- });
- this.refreshData();
- },
- tapVideo1() {
- this.setData({
- useVideo1: !this.data.useVideo1
- });
- this.refreshData();
- },
- tapVideo2() {
- this.setData({
- useVideo2: !this.data.useVideo2
- });
- this.refreshData();
- },
- handleTrackerChange(cur) {
- const item = cur.detail;
- this.setData({
- debugMsg: 'handleTrackerChange:' + item.name
- })
- },
- handleTrackerMove(cur) {
- const detail = cur.detail
- const trackerInfo = detail.trackerInfo
-
- this.moveTimes++
- if (detail.type === 'scan') {
- if (detail.active) {
- this.setData({
- showMarkerWrap: true,
- markerLeft: Math.floor((trackerInfo.x) * 100),
- markerTop: Math.floor((trackerInfo.y) * 100) * this.data.heightScale,
- markerWidth: Math.floor(trackerInfo.halfWidth * 2 * this.data.width),
- markerHeight: Math.floor(trackerInfo.halfWidth * 2 * this.data.width / trackerInfo.widthDivideHeight),
- // debugMsg: 'pos:' + trackerInfo.x + '\n' + trackerInfo.y + '\n halfWidth:' + trackerInfo.halfWidth + '\nmoveTimes:' + this.moveTimes
- })
- } else {
- this.setData({
- showMarkerWrap: false,
- })
- }
- }
- },
- });
|