app.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // 别间隔时间(毫秒), 识别服务地址, 认证token
  2. const webAR = new WebAR(1000, 'https://cn1-crs.easyar.com:8443/search', 'I63ooxI48OcR9MseGyf9F3UpVoa4Seio4CtCM1k2kHD59TngdniDdS2FXAx3UWlStF+eUKVvoEJWuU2+bGgpcQ==');
  3. // Threejs简单使用类
  4. const threeHelper = new ThreeHelper();
  5. // 列出并打开设备上的摄像头
  6. document.querySelector('#openCamera').addEventListener('click', function () {
  7. const videoSelect = document.querySelector('#videoDevice');
  8. webAR.listCamera(videoSelect)
  9. .then(msg => {
  10. // 隐藏"打开摄像头"按钮
  11. this.style.display = 'none';
  12. videoSelect.style.display = 'inline-block';
  13. document.querySelector('#start').style.display = 'inline-block';
  14. document.querySelector('#stop').style.display = 'inline-block';
  15. videoSelect.onchange = () => {
  16. webAR.openCamera(JSON.parse(videoSelect.value));
  17. };
  18. // 打开摄像头
  19. // 打开后置摄像头参数: {audio: false, video: {facingMode: {exact: 'environment'}}}
  20. webAR.openCamera(JSON.parse(videoSelect.value))
  21. .then(msg => {
  22. console.info(msg);
  23. }).catch(err => {
  24. console.info(err);
  25. });
  26. })
  27. .catch(err => {
  28. // 没有找到摄像头
  29. console.info(err);
  30. });
  31. });
  32. // 开启识别
  33. document.querySelector('#start').addEventListener('click', () => {
  34. webAR.startRecognize((msg) => {
  35. console.info(msg);
  36. // 可以将 setting 作为meta上传到EasyAR的云识别,使用方法如下
  37. // const setting = JSON.parse(window.atob(msg.target.meta));
  38. const setting = {
  39. model: 'asset/model/trex_v3.fbx',
  40. scale: 0.02,
  41. position: [0, 0, 0]
  42. };
  43. threeHelper.loadObject(setting);
  44. });
  45. }, false);
  46. // 暂停识别
  47. document.querySelector('#stop').addEventListener('click', () => {
  48. webAR.stopRecognize();
  49. }, false);
  50. //# sourceMappingURL=app.js.map