public.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /**
  2. * 说明:检测菜单项是否已打开
  3. */
  4. function checkBtnActives(arr) {
  5. for (let i = 0; i < arr.length; i++) {
  6. let temp = arr[i];
  7. if ($(temp).hasClass('active')) {
  8. $(temp).removeClass('active');
  9. $(temp).find('.control-menu').removeClass('actives');
  10. }
  11. }
  12. }
  13. /**
  14. * 说明:判断是否全屏
  15. */
  16. function checkFull() {
  17. var isFull =
  18. document.fullscreenElement ||
  19. document.mozFullScreenElement ||
  20. document.webkitFullscreenElement;
  21. //to fix : false || undefined == undefined
  22. if (isFull === undefined) isFull = false;
  23. return isFull;
  24. }
  25. /**
  26. * 说明:创建胶囊
  27. */
  28. function createBox() {
  29. if (box == null) {
  30. box = app.create({
  31. type: 'Thing',
  32. url: 'https://model.3dmomoda.com/models/9CD08ED91F5C4E0ABB6B0833C86F2942/0/gltf/',
  33. position: [0, 0, 0],
  34. angle: 180,
  35. scale: [1.7, 1.7, 1.7],
  36. style: {
  37. color: '#FF0000'
  38. }
  39. });
  40. }
  41. }
  42. /**
  43. * 说明:第一人称行走
  44. */
  45. function enterFps(pos) {
  46. if (fpsCtrl == null) {
  47. app.pauseEvent(THING.EventType.Pick, '*', THING.EventTag.LevelPickOperation);
  48. app.pauseEvent(THING.EventType.KeyUp, null, '空格键切换视角');
  49. app.camera.position = pos; // 起始位置为鼠标点击时的位置
  50. // 添加第一人称行走控件
  51. fpsCtrl = app.addControl(
  52. new THING.WalkControl({ // 参数可以动态修改
  53. walkSpeed: 0.02, // 行走速度
  54. turnSpeed: 0.25, // 右键旋转速度
  55. gravity: 26, // 物体重量
  56. eyeHeight: 1.6, // 人高度
  57. jumpSpeed: 10, // 按空格键 跳跃的速度
  58. enableKeyRotate: false, // 默认不开启键盘控制旋转
  59. useCollision: true, // 默认不开启碰撞检测
  60. useGravity: true, // 默认开启重力
  61. groundObjects: [app.scene], // 把整个场景都添加,可把楼层或其他需要检测的添加进入碰撞体系里 | 默认值 园区地板,如果园区过大,可取消提升性能
  62. collisionObjects: [app.scene] // 把整个场景都添加,可把楼层或其他需要检测的添加进入碰撞体系里 | 默认值 园区地板,如果园区过大,可取消提升性能
  63. })
  64. );
  65. }
  66. }
  67. /**
  68. * 说明:退出第一人称行走
  69. */
  70. function exitFps() {
  71. app.removeControl(fpsCtrl);
  72. fpsCtrl = null;
  73. cameraFly(cameraInitPos[0], cameraInitPos[1]);
  74. // 恢复默认双击事件
  75. app.resumeEvent(THING.EventType.DBLClick, '*', THING.EventTag.LevelEnterOperation);
  76. // 恢复默认点击事件
  77. app.resumeEvent(THING.EventType.Click, '*', THING.EventTag.LevelBackOperation);
  78. // 恢复默认拾取事件
  79. app.resumeEvent(THING.EventType.Pick, '*', THING.EventTag.LevelPickOperation);
  80. // 恢复默认键盘键抬起事件
  81. app.resumeEvent(THING.EventType.KeyUp, null, '空格键切换视角');
  82. $('#moveByFps').removeClass('active');
  83. }
  84. /**
  85. * 说明:开启小地图
  86. */
  87. function createMiniMap() {
  88. if (miniMapCtrl == null) {
  89. // 添加小地图控件
  90. miniMapCtrl = app.addControl(new THING.MiniMapControl({
  91. width: 200,
  92. height: 200,
  93. position: THING.CornerType.LeftBottom,
  94. opacity: 0.8,
  95. scale: 1,
  96. angle: 0,
  97. mousewheel: true,
  98. cameraViewImg: 'http://www.thingjs.com/static/images/minimap1.png',
  99. cameraCenterImg: 'http://www.thingjs.com/static/images/minimap0.png'
  100. }));
  101. $('.minimap').css('border', '1px solid rgba(255, 255, 255, 0.8)');
  102. $('.minimap').css('left', '3px');
  103. $('.minimap').css('bottom', '3px');
  104. } else {
  105. destoryMiniMap();
  106. createMiniMap();
  107. }
  108. }
  109. /**
  110. * 说明:关闭小地图
  111. */
  112. function destoryMiniMap() {
  113. if (miniMapCtrl != null) {
  114. app.removeControl(miniMapCtrl);
  115. miniMapCtrl = null;
  116. }
  117. }
  118. /**
  119. * 说明:全屏显示
  120. */
  121. function fullScreen() {
  122. let el = document.documentElement;
  123. let rfs = el.requestFullScreen || el.webkitRequestFullScreen;
  124. if (typeof rfs != "undefined" && rfs) {
  125. rfs.call(el);
  126. } else if (typeof window.ActiveXObject != "undefined") {
  127. let wscript = new ActiveXObject("WScript.Shell");
  128. if (wscript != null) {
  129. wscript.SendKeys("{F11}");
  130. }
  131. }
  132. }
  133. /**
  134. * 说明:退出全屏
  135. */
  136. function exitFullScreen() {
  137. let el = document;
  138. let cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.exitFullScreen;
  139. if (typeof cfs != "undefined" && cfs) {
  140. cfs.call(el);
  141. } else if (typeof window.ActiveXObject != "undefined") {
  142. let wscript = new ActiveXObject("WScript.Shell");
  143. if (wscript != null) {
  144. wscript.SendKeys("{F11}");
  145. }
  146. }
  147. }
  148. /**
  149. * 说明:摄像机飞行
  150. */
  151. function cameraFly(position, target) {
  152. // 摄像机飞行到某位置
  153. app.camera.flyTo({
  154. 'position': position,
  155. 'target': target,
  156. 'time': 1000,
  157. 'complete': function () {
  158. }
  159. });
  160. }
  161. /**
  162. * 说明:自动旋转
  163. */
  164. function startRotate() {
  165. app.camera.enableRotate = false; // 关闭默认的旋转操作
  166. app.camera.enablePan = false; // 关闭默认的平移操作
  167. app.camera.enableZoom = false; // 关闭默认的缩放操作
  168. // 绕摄像机当前目标点旋转
  169. app.camera.rotateAround({
  170. target: app.camera.target, // 围绕摄像机当前目标点
  171. // object: obj, // 环绕的物体 (object 与 target 的设置互斥)
  172. speed: 4, // 环绕飞行的时间(3min)
  173. yRotateAngle: 360, // 环绕y轴飞行的旋转角度
  174. loopType: THING.LoopType.Repeat // 设置循环类型
  175. });
  176. }
  177. /**
  178. * 说明:停止自动旋转
  179. */
  180. function stopRotate() {
  181. app.camera.enableRotate = true; // 开启默认的旋转操作
  182. app.camera.enablePan = true; // 开启默认的平移操作
  183. app.camera.enableZoom = true; // 开启默认的缩放操作
  184. app.camera.stopRotateAround();
  185. if (rotateTimer) {
  186. clearTimeout(rotateTimer);
  187. rotateTimer = null;
  188. }
  189. }
  190. /**
  191. * 说明:重新开始转动,未进行任何操作5s后开始自动旋转
  192. */
  193. function restarRotate() {
  194. if (fpsCtrl != null || !$('#sceneSetting .control-menu-pane li.autoRotate').hasClass('selected')) {
  195. return;
  196. }
  197. if (rotateTimer == null) {
  198. rotateTimer = setTimeout(function () {
  199. // startRotate();
  200. }, restartTime);
  201. } else {
  202. clearTimeout(rotateTimer);
  203. rotateTimer = null;
  204. restarRotate();
  205. }
  206. }