manage.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. var g_ProjectName = window.location.pathname.substring(window.location.pathname.indexOf("/") + 1, window.location.pathname.lastIndexOf("/"))
  2. var s = window.location.href.split('/')
  3. s.pop()
  4. var g_index = null
  5. var g_modeldata = null
  6. var g_weixinTitle = null
  7. var g_Hots = null
  8. var g_HotMeshes = []
  9. var g_HotMeshSize = {
  10. g_HotMeshWidth: 0.3,
  11. g_HotMeshHeight: 0.3
  12. }
  13. //add表示添加,delete表示删除
  14. var g_HotStatus = null
  15. var g_newHot = []//存储新加热点
  16. var g_HotImage = {
  17. "point": "https://super.4dage.com/images/4dagePoint2.png",
  18. "point2": "https://super.4dage.com/images/4dagePoint.png"
  19. }
  20. var g_saveHot = false
  21. var g_TextColor = 0x7777ff
  22. var g_Text = null
  23. var g_TextPlaneMesh = []
  24. var g_TextIconMesh = []
  25. var g_TextIcon = "./images/text.png"
  26. var g_SelectTextIndex = null
  27. var g_TextShow = null
  28. var g_audioPlay = false
  29. var g_background = null
  30. var g_roof = null
  31. var g_data2 = null//加载的data2.js的内容
  32. var g_bgAudio = null//背景音乐
  33. var g_tourAudio = null//导览音乐
  34. var g_play = 1//表示播放图标状态
  35. var g_playAudio = null//当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
  36. var g_currentHot = null//当前打开的热点
  37. //var g_Texture=null;
  38. //var g_ChunknameTexture={}; //chunkname和贴图名称对应
  39. var g_NormalTexture = false
  40. var g_SpecularTexture = false
  41. var g_DirectionalLight = null
  42. var g_snapShotWidth = 200 //截图下载图片的大小
  43. var g_snapShotHeight = 140
  44. //微信分享
  45. var g_weixinObj = {
  46. "title": document.querySelector("head title").innerHTML,
  47. "lineLink": window.location.href,
  48. "imgUrl": "https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg",
  49. "desc": "四维时代提供技术支持",
  50. }
  51. var settings = {
  52. hotClickEvent: {
  53. video: {
  54. playAndPause: true,
  55. examine: false,
  56. openHot: false
  57. },
  58. photo: {
  59. examine: false,
  60. openHot: false
  61. },
  62. shine: {
  63. examine: true,
  64. openHot: true
  65. }
  66. },
  67. //默认的:
  68. teleportTime: 1500, //瞬间过渡的时间
  69. /* flytimeDistanceMultiplier:150,
  70. flyTime:750, */
  71. tourRotTime: 2, //默认停留2秒
  72. //dontExamHot:true
  73. transparentBg: false,
  74. bgImg: null
  75. }
  76. if (window.number == '725' || window.number == '724') {
  77. settings.mobileNavHigh = true
  78. }
  79. //共用函数:
  80. window.common = null
  81. window.MathLight = null
  82. window.math = null
  83. window.easing = null
  84. window.lerp = null
  85. window.transitions = null
  86. window.browser = null
  87. window.momentTourBlackNewType = 0//= number == 'TEST'//true
  88. var dealMap = (map)=>{//使不resize when image is not power of two
  89. map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping
  90. map.minFilter = THREE.LinearFilter
  91. map.magFilter = THREE.LinearFilter
  92. map.generateMipmaps = true
  93. }
  94. var dom = {
  95. getOffset: function(type, element, parent) {
  96. left = (type == "left") ? element.offsetLeft : element.offsetTop
  97. if (!parent) parent = $("body")[0]
  98. while (element = element.offsetParent) {
  99. if (element == parent) break
  100. left += (type == "left") ? element.offsetLeft : element.offsetTop
  101. }
  102. return left
  103. }
  104. }
  105. var getTransformSid = function() {
  106. var name
  107. if (player.mode == 'panorama') {
  108. name = player.currentPano ? player.currentPano.id : 'outside'
  109. } else {
  110. name = 'outside'
  111. }
  112. return name
  113. }
  114. var convertTool = {
  115. getPos2d: function(point, camera, dom) {//获取一个三维坐标对应屏幕中的二维坐标
  116. var camera = camera || player.camera
  117. var dom = dom || player.domElement
  118. var pos = point.clone().project(camera) //比之前hotspot的计算方式写得简单 project用于3转2(求法同shader); unproject用于2转3 :new r.Vector3(e.x, e.y, -1).unproject(this.camera);
  119. var x, y
  120. x = (pos.x + 1) / 2 * dom.clientWidth
  121. y = (1 - (pos.y + 1) / 2) * dom.clientHeight
  122. var inSight = x <= dom.clientWidth && x >= 0 //是否在屏幕中
  123. && y <= dom.clientHeight && y >= 0
  124. return {
  125. pos: new THREE.Vector2(x, y), // 屏幕像素坐标
  126. vector: pos, //(范围 -1 ~ 1)
  127. trueSide: pos.z < 1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  128. inSight: inSight //在屏幕范围内可见
  129. }
  130. },
  131. ifShelter: function(pos3d) {//检测某点在视线中是否被mesh遮挡
  132. var ori = player.position
  133. var dir = pos3d.clone().sub(ori).normalize()
  134. var ray = new THREE.Raycaster(ori, dir) //由外向里 因为模型从内侧是可见的所以从外侧
  135. /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
  136. var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
  137. }else{ */
  138. var o = ray.intersectObjects(player.model.colliders)
  139. //}
  140. var len = pos3d.distanceTo(ori)
  141. if (o && o.length) {
  142. for (var i = 0; i < o.length; i++) {
  143. if (o[i].distance < len) { return true }//有遮挡
  144. }
  145. }
  146. },
  147. /*
  148. 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
  149. 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
  150. */
  151. getPosAtPlane: function(pos, info/* , mouse, camera */) { //pos:与intersectPlane的交点 见笔记
  152. var A = pos
  153. var player = player
  154. var mouse = player.mouse
  155. var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera)
  156. if (info.y != void 0) {//地面线的
  157. var y = info.y
  158. if (player.mode == "floorplan"/* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */) {
  159. //intersectPlane和地面平行,无交点
  160. var x = pos.x, z = pos.z
  161. } else {
  162. if (y < player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */) return null //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
  163. if (O.y == A.y) {console.log('一样??'); return}
  164. if (A.y == y) {console.log('一样2??'); return}
  165. var r = (O.y - y) / (A.y - y)
  166. var x = (r * A.x - O.x) / (r - 1)
  167. var z = (r * A.z - O.z) / (r - 1)
  168. }
  169. } else {//垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
  170. var N = info.normalVec
  171. var P = info.pullPos
  172. if (N.y != 0 ) {console.log('N.y != 0'); return} //仅仅支持垂直于地面的的墙壁,目前都是
  173. if (O.z == A.z) {console.log('O.z==A.z?'); return}
  174. if (N.z != 0 && N.x != 0) {//直接用这个通用的也可以,支持斜线的墙
  175. //console.log('N.z==0 && N.x == 0?');
  176. var c = ( N.x * (A.x - O.x) + N.y * (A.y - O.y) + N.z * (A.z - O.z))
  177. if (c == 0) {console.log("分母为0?? return;"); return}
  178. var t = -((N.x * O.x + N.y * O.y + N.z * O.z) - (P.x * N.x + P.y * N.y + P.z * N.z) ) / c
  179. var x = t * (A.x - O.x) + O.x
  180. var y = t * (A.y - O.y) + O.y
  181. var z = t * (A.z - O.z) + O.z
  182. /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
  183. 求直线L与平面π的交点的坐标。
  184. 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
  185. 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
  186. A(mt+a)+B(nt+b)+C(pt+c)+D=0
  187. 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
  188. 再代入参数方程即得交点的坐标(x,y,z). */
  189. } else if (N.x == 0 ) { //z与pullPos相等
  190. var z = P.z
  191. if (O.y == A.y) {console.log('一样??'); return}
  192. if (A.y == y) {console.log('一样2??'); return}
  193. if (A.z == z) {console.log('一样3??'); return}
  194. var r = (O.z - z) / (A.z - z)
  195. var x = (r * A.x - O.x) / (r - 1)
  196. var y = (r * A.y - O.y) / (r - 1)
  197. } else if (N.z == 0) {//x与pullPos相等
  198. var x = P.x
  199. if (O.y == A.y) {console.log('一样??'); return}
  200. if (A.y == y) {console.log('一样2??'); return}
  201. if (A.x == x) {console.log('一样3??'); return}
  202. var r = (O.x - x) / (A.x - x)
  203. var y = (r * A.y - O.y) / (r - 1)
  204. var z = (r * A.z - O.z) / (r - 1)
  205. }
  206. }
  207. return new THREE.Vector3(x, y, z)
  208. },
  209. getMouseIntersect: function(camera, meshes, mouse) {//获取鼠标和meshes交点
  210. var raycaster = new THREE.Raycaster
  211. camera.updateMatrixWorld()
  212. var origin = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(camera)
  213. , end = new THREE.Vector3(mouse.x, mouse.y, 1).unproject(camera)
  214. var dir = end.sub(origin).normalize()
  215. raycaster.set(origin, dir)
  216. var n = raycaster.intersectObjects(meshes)
  217. if (0 === n.length)
  218. return null
  219. return n[0]
  220. },
  221. ifIntersectChunks: function(A, B, options = {}) {//获取某个线段/射线和meshes的交点
  222. var dir = B.clone().sub(A).normalize()
  223. var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen || 0)
  224. var ray = new THREE.Raycaster(A.clone(), dir, 0, len)
  225. var o = ray.intersectObjects(options.model || player.model.colliders)
  226. if (o && o.length) return o
  227. if (options.throughWidth) { //允许最小宽度,防止穿过极小的缝隙导致撞墙感
  228. var normal = math.getNormal({ points: [{ x: A.x, y: A.z }, { x: B.x, y: B.z }] })//线段法线
  229. normal.multiplyScalar(options.throughWidth)
  230. var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y)
  231. var A2 = A.clone().add(normalVec3)
  232. ray.set(A2, dir)
  233. var o2 = ray.intersectObjects(options.model || player.model.colliders)
  234. ray.set(A.clone().add(normalVec3.negate()), dir)
  235. if (o2 && o2.length) return o2
  236. var o3 = ray.intersectObjects(options.model || player.model.colliders)
  237. if (o3 && o3.length) return o3
  238. }
  239. return null
  240. },
  241. getPosAtSphere: function(pos3d, toPanoPos) {
  242. var dir = pos3d.clone().sub(toPanoPos)
  243. dir.normalize()//然后计算在球中
  244. dir.multiplyScalar(Constants.skyRadius)
  245. dir.add(toPanoPos)
  246. return dir
  247. },
  248. getScaleForConstantSize: function(op = {}) { //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  249. var w
  250. var i = new THREE.Vector3, o = new THREE.Vector3, l = new THREE.Vector3, c = new THREE.Vector3, h = new THREE.Vector3
  251. if (op.width2d) w = op.width2d //如果恒定二维宽度
  252. else {//否则考虑上距离,加一丢丢近大远小的效果
  253. var currentDis, nearBound, farBound
  254. if (op.camera.type == "OrthographicCamera") {
  255. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom
  256. } else {
  257. currentDis = op.position.distanceTo(op.camera.position)
  258. }
  259. w = op.maxSize - ( op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound)
  260. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  261. }
  262. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  263. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  264. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  265. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  266. h.copy(c).unproject(op.camera)//再转成三维坐标,求得tag边缘的位置
  267. var g = h.distanceTo(op.position)//就能得到tag的三维半径
  268. return g //可能NAN 当相机和position重叠时
  269. }
  270. }
  271. //--------------------------------------
  272. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  273. var Manage = function() {
  274. this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  275. this.time = "?" + new Date().getTime()
  276. this.loadAudio()
  277. this.loadWeixin()
  278. }
  279. //动态加载js文件
  280. Manage.prototype.LoadJs = function(_files, succes) {
  281. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  282. var classcodes = []
  283. var FileArray = []
  284. if (typeof _files === "object") {
  285. FileArray = _files
  286. } else {
  287. /*如果文件列表是字符串,则用,切分成数组*/
  288. if (typeof _files === "string") {
  289. FileArray = _files.split(",")
  290. }
  291. }
  292. if (FileArray != null && FileArray.length > 0) {
  293. var LoadedCount = 0
  294. for (var i = 0; i < FileArray.length; i++) {
  295. loadFile(FileArray[i], function() {
  296. LoadedCount++
  297. if (LoadedCount == FileArray.length) {
  298. try {
  299. succes()
  300. }
  301. catch (err) {
  302. console.log("err: 您未定义回调")
  303. }
  304. }
  305. })
  306. }
  307. }
  308. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  309. function loadFile(url, success) {
  310. if (!FileIsExt(classcodes, url)) {
  311. var _ThisType = GetFileType(url)
  312. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0, _ThisType.indexOf("?"))
  313. var fileObj = null
  314. if (ThisType == ".js") {
  315. fileObj = document.createElement('script')
  316. fileObj.src = url
  317. } else if (ThisType == ".css") {
  318. fileObj = document.createElement('link')
  319. fileObj.href = url
  320. fileObj.type = "text/css"
  321. fileObj.rel = "stylesheet"
  322. } else if (ThisType == ".less") {
  323. fileObj = document.createElement('link')
  324. fileObj.href = url
  325. fileObj.type = "text/css"
  326. fileObj.rel = "stylesheet/less"
  327. }
  328. success = success || function() {}
  329. fileObj.onload = fileObj.onreadystatechange = function() {
  330. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  331. success()
  332. classcodes.push(url)
  333. }
  334. }
  335. document.getElementsByTagName('head')[0].appendChild(fileObj)
  336. } else {
  337. success()
  338. }
  339. }
  340. /*获取文件类型,后缀名,小写*/
  341. function GetFileType(url) {
  342. if (url != null && url.length > 0) {
  343. return url.substr(url.lastIndexOf(".")).toLowerCase()
  344. }
  345. return ""
  346. }
  347. /*文件是否已加载*/
  348. function FileIsExt(FileArray, _url) {
  349. if (FileArray != null && FileArray.length > 0) {
  350. var len = FileArray.length
  351. for (var i = 0; i < len; i++) {
  352. if (FileArray[i] == _url) {
  353. return true
  354. }
  355. }
  356. }
  357. return false
  358. }
  359. }
  360. //获取页面url后面的参数
  361. Manage.prototype.number = function(variable) {
  362. var query = window.location.search.substring(1)
  363. var vars = query.split("&")
  364. for (var i = 0; i < vars.length; i++) {
  365. var pair = vars[i].split("=")
  366. if (pair[0] == variable) {return pair[1]}
  367. }
  368. return (false)
  369. }
  370. Manage.prototype.loadWeixin = function() {
  371. var that = this
  372. this.LoadJs(that.weixinURL + that.time, function() { })
  373. }
  374. Manage.prototype.weixinShare = function() {
  375. console.log("weixinShare")
  376. $.ajax({
  377. url: 'https://www.4dage.com/wechat/jssdk/',
  378. type: "post",
  379. data: {
  380. 'url': location.href.split('#')[0]
  381. },
  382. dataType: "jsonp",
  383. jsonpCallback: "success_jsonp",
  384. success: function(data, textStatus) {
  385. console.log("weixinShare success")
  386. console.log(data.appId)
  387. wx.config({
  388. // debug : true,
  389. appId: data.appId,
  390. timestamp: data.timestamp,
  391. nonceStr: data.nonceStr,
  392. signature: data.signature,
  393. jsApiList: [ 'checkJsApi', 'onMenuShareTimeline',
  394. 'onMenuShareAppMessage', 'onMenuShareQQ',
  395. 'onMenuShareWeibo', 'hideMenuItems',
  396. 'showMenuItems', 'hideAllNonBaseMenuItem',
  397. 'showAllNonBaseMenuItem', 'translateVoice',
  398. 'startRecord', 'stopRecord', 'onRecordEnd',
  399. 'playVoice', 'pauseVoice', 'stopVoice',
  400. 'uploadVoice', 'downloadVoice', 'chooseImage',
  401. 'previewImage', 'uploadImage', 'downloadImage',
  402. 'getNetworkType', 'openLocation', 'getLocation',
  403. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  404. 'scanQRCode', 'chooseWXPay',
  405. 'openProductSpecificView', 'addCard', 'chooseCard',
  406. 'openCard' ]
  407. })
  408. },
  409. error: function(XMLHttpRequest, textStatus, errorThrown) {
  410. console.log("jsonp.error:" + textStatus)
  411. }
  412. })
  413. var success_jsonp = function(json) {
  414. console.log(json)
  415. }
  416. wx.ready(function() {
  417. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  418. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  419. //分享到朋友圈
  420. console.log(g_weixinObj)
  421. wx.onMenuShareTimeline({
  422. title: g_weixinObj.title, // 分享标题
  423. link: g_weixinObj.lineLink, // 分享链接
  424. imgUrl: g_weixinObj.imgUrl, // 分享图标
  425. desc: g_weixinObj.desc
  426. })
  427. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  428. wx.onMenuShareAppMessage({
  429. title: g_weixinObj.title, // 分享标题
  430. desc: g_weixinObj.desc, // 分享描述
  431. link: g_weixinObj.lineLink, // 分享链接
  432. imgUrl: g_weixinObj.imgUrl, // 分享图标
  433. type: '', // 分享类型,music、video或link,不填默认为link
  434. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  435. })
  436. wx.onMenuShareWeibo({
  437. title: g_weixinObj.title, // 分享标题
  438. desc: g_weixinObj.desc, // 分享描述
  439. link: g_weixinObj.lineLink, // 分享链接
  440. imgUrl: g_weixinObj.imgUrl, // 分享图标
  441. success: function () {
  442. // 用户确认分享后执行的回调函数
  443. },
  444. cancel: function () {
  445. // 用户取消分享后执行的回调函数
  446. }
  447. })
  448. wx.onMenuShareQZone({
  449. title: g_weixinObj.title, // 分享标题
  450. desc: g_weixinObj.desc, // 分享描述
  451. link: g_weixinObj.lineLink, // 分享链接
  452. imgUrl: g_weixinObj.imgUrl, // 分享图标
  453. success: function () {
  454. // 用户确认分享后执行的回调函数
  455. },
  456. cancel: function () {
  457. // 用户取消分享后执行的回调函数
  458. }
  459. })
  460. wx.onMenuShareQQ({
  461. title: g_weixinObj.title, // 分享标题
  462. desc: g_weixinObj.desc, // 分享描述
  463. link: g_weixinObj.lineLink, // 分享链接
  464. imgUrl: g_weixinObj.imgUrl, // 分享图标
  465. success: function () {
  466. // 用户确认分享后执行的回调函数
  467. },
  468. cancel: function () {
  469. // 用户取消分享后执行的回调函数
  470. }
  471. })
  472. wx.error(function(res) {
  473. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  474. })
  475. })
  476. }
  477. Manage.prototype.dealURL = function(src, type) {
  478. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  479. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  480. if (window.isLocal && settings.localPrefix != void 0) {//本地将线上的前缀替换
  481. var oldPrefix = 'super.4dage.com/' //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  482. var index = src.indexOf(oldPrefix)
  483. if (index > -1) {
  484. var wholeOldPrefix = src.slice(0, index + oldPrefix.length)
  485. return src.replace(wholeOldPrefix, settings.localPrefix)
  486. }
  487. console.error("没有找到合适的本地链接")
  488. return src
  489. } else {
  490. //add https://
  491. var prefix = g_Prefix.replace('https://', '').replace('http://', '')
  492. if (!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)) {
  493. src = 'https://' + src
  494. }
  495. return src
  496. }
  497. }
  498. Manage.prototype.removeSrcPostMark = function(url) {//去除texture.load时自动加上的'?'
  499. var index = url.indexOf('?')
  500. if (index > -1) {
  501. return url.slice(0, index)
  502. } else return url
  503. }
  504. Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"});
  505. var box = $(".resultBox")
  506. var title = o.title || o || i18n.get('保存成功')
  507. box.children().eq(0).html(title)
  508. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  509. var time = o.time || THREE.Math.clamp(title.length * 130, 1300, 5000)
  510. o.time || console.log("showtime " + time)
  511. //实际有一半的时间在渐变透明度
  512. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  513. box.removeClass("animate")//如果之后不久又要showinfo一个的话,先停止前面的animate
  514. setTimeout(function () {
  515. box.css(
  516. {
  517. '-webkit-animation-duration': time + 'ms',
  518. 'animation-duration': time + 'ms'
  519. }
  520. )
  521. if (o.top) {
  522. box.children().css('top', o.top + "%")
  523. } else {
  524. box.children().css('top', '' )
  525. }
  526. box.removeClass("hide")
  527. box.addClass("animate")
  528. if (o.dontInteract) {//遮挡对屏幕的操作
  529. box.css('pointer-events', 'auto')
  530. } else {
  531. box.css('pointer-events', 'none')
  532. }
  533. this.showInfoTimer = setTimeout(function () {
  534. box.removeClass("animate")
  535. box.addClass("hide")
  536. this.showInfoTimer = null
  537. }.bind(this), time + 20)
  538. }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  539. }//like: manage.showInfo({title:'a', top:20})
  540. //公用的函数
  541. function getQueryVariable(variable)
  542. {
  543. var query = window.location.search.substring(1)
  544. var vars = query.split("&")
  545. for (var i = 0; i < vars.length; i++) {
  546. var pair = vars[i].split("=")
  547. if (pair[0] == variable) {return pair[1]}
  548. }
  549. return (false)
  550. }
  551. //隐藏公司Logo
  552. function showLogo() {
  553. $("#myCompany").hide()
  554. $("#loaderCoBrandName").hide()
  555. $("#title-logo").hide()
  556. $(".title-container").css("justify-content", "center")
  557. }
  558. //czj 添加随机的时间
  559. function randomTime() {
  560. return new Date()
  561. }
  562. function matcher(data) {
  563. if (!data || !g_version ) return data
  564. delete data.model.vision_version
  565. var _data = {
  566. files: {
  567. "templates": ["images/images{{number}}/{{filename}}"]
  568. },
  569. model: {
  570. sid: window.number,
  571. camera_start:
  572. data.model.images && data.model.images.length != 0 ?
  573. {
  574. camera: {
  575. zoom: "-1",
  576. quaternion: [
  577. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  578. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  579. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  580. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  581. ]
  582. },
  583. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  584. mode: "0"
  585. }
  586. : ''
  587. },
  588. sid: window.number,
  589. hoticon: {
  590. default: "https://super.4dage.com/images/4dagePoint2.png",
  591. higt: "https://super.4dage.com/images/4dagePoint.png"
  592. },
  593. special: "false",
  594. weixinDesc: ""
  595. }
  596. $.extend(true, data, _data)
  597. return data
  598. }
  599. function hotMatcher(data = {}) {
  600. //if(!data || !g_version) return data;
  601. if (g_version) {
  602. data.tourAudio = data.audio || {}
  603. } else {
  604. data.tourAudio = {}
  605. }
  606. return data
  607. }
  608. var GifTexDeal = {
  609. animateObjects: [],
  610. animateTexs: [],
  611. addAnimation: function(texture, owner, info, id) {
  612. /* if(this.animateObjects.find(e=>
  613. e.texture == texture && !ifSame(info, e.info)
  614. )) */
  615. var animation
  616. var tex = this.animateTexs.find(e=>e.texture == texture)
  617. if (tex) {
  618. animation = tex
  619. } else {
  620. animation = { texture, info }
  621. this.animateTexs.push(animation)
  622. this.setRepeart(animation)
  623. }
  624. var object = {
  625. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  626. owner,
  627. }
  628. this.animateObjects.push(object)
  629. return object
  630. },
  631. remove: function(object) {
  632. var index = this.animateObjects.indexOf(object)
  633. if (index > -1) {
  634. this.animateObjects.splice(index, 1)
  635. if (!this.animateObjects.find(e=>e.animation == object.animation)) {
  636. let i = this.animateTexs.indexOf(object.animation)
  637. this.animateTexs.splice(i, 1)
  638. object.animation.texture.repeat.set(1, 1)
  639. }
  640. this.stop(object)
  641. }
  642. },
  643. setRepeart: function(animation) {
  644. animation.texture.repeat.set(1 / animation.info.cellXcount, 1 / animation.info.cellYcount)
  645. },
  646. start: function(object) {
  647. if (!object || object.started ) return
  648. object.started = true
  649. if (object.animation.started) return
  650. object.animation.started = true
  651. var info = object.animation.info
  652. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  653. if (count <= 1) return
  654. transitions.start( (progress)=>{
  655. var index = Math.floor(count * progress)
  656. var indexX = index % info.cellXcount
  657. var indexY = info.cellYcount - Math.floor(index / info.cellXcount ) - 1 //uv.offset.y是从下到上的
  658. object.animation.texture.offset.x = indexX / info.cellXcount
  659. object.animation.texture.offset.y = indexY / info.cellYcount
  660. //console.log(object.id + " : "+ object.texture.offset.toArray())
  661. }, info.duration * (-1), null, /* ()=>{//done (-1):循环
  662. object.started = false
  663. object.texture.offset.x = 0;
  664. object.texture.offset.y = 0;
  665. this.start(object)
  666. }, */ 0, null, object.id, "gif_" + object.animation.texture.id)
  667. },
  668. stop: function(object) {
  669. if (!object || !object.started) return
  670. object.started = false
  671. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  672. if (this.animateObjects.find(e=>e.animation == object.animation && e.started)) return
  673. transitions.cancelById("gif_" + object.animation.texture.id)
  674. object.animation.texture.offset.set(0, 0)
  675. object.animation.started = false
  676. }
  677. }
  678. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  679. //isSimpleCopy只复制最外层
  680. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  681. if (!copyObj) return copyObj //0 null undefined ''
  682. result = result || {}
  683. if (copyObj instanceof Array) {
  684. /* if (copyObj[0]instanceof Object) {
  685. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  686. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  687. }
  688. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  689. return copyObj.map(e=>{
  690. if (e instanceof Object) {
  691. return CloneObject(e)
  692. } else return e
  693. })
  694. } else {
  695. if (copyObj.clone instanceof Function ) { //解决一部分
  696. return copyObj.clone()
  697. }
  698. }
  699. for (var key in copyObj) {
  700. if (copyObj[key] instanceof Object && !isSimpleCopy)
  701. result[key] = CloneObject(copyObj[key])
  702. else
  703. result[key] = copyObj[key]
  704. //如果是函数类同基本数据,即复制引用
  705. }
  706. return result
  707. }
  708. var ifSame = function(object1, object2) {
  709. if (object1 == object2 ) return true // 0 != undefined , 0 == ''
  710. else if (!object1 || !object2) return false
  711. else if (object1.constructor != object2.constructor) {
  712. return false
  713. } else if (object1 instanceof Array ) {
  714. if (object1.length != object2.length) return false
  715. var _object2 = object2.slice(0)
  716. for (let i = 0; i < object1.length; i++) {
  717. var u = _object2.find(e=>ifSame(object1[i], e))
  718. if (u == void 0 && !_object2.includes(u) && !object1.includes(u)) return false
  719. else {
  720. let index = _object2.indexOf(u)
  721. _object2.splice(index, 1)
  722. }
  723. }
  724. return true
  725. } else if (object1.equals instanceof Function ) {//复杂数据仅支持这种,其他的可能卡住?
  726. return object1.equals(object2)
  727. } else if (typeof object1 == 'number' || typeof object1 == 'string') {
  728. if (isNaN(object1) && isNaN(object2)) return true
  729. else return object1 == object2
  730. } else if (typeof object1 == "object") {
  731. var keys1 = Object.keys(object1)
  732. var keys2 = Object.keys(object2)
  733. if (!ifSame(keys1, keys2)) return false
  734. for (let i in object1) {
  735. var same = ifSame(object1[i], object2[i])
  736. if (!same) return false
  737. }
  738. return true
  739. } else {
  740. console.log('isSame出现例外')
  741. }
  742. }
  743. /* var SoundManager = {//暂不支持同时播放
  744. currentAudio:null,//当前正在播放list中的哪一个
  745. list:[
  746. {
  747. name:"bg",
  748. level : 0,//越大优先级越高
  749. canBeInterrupted : true ,
  750. },
  751. {
  752. name:"boxVideo",
  753. level : 1,
  754. canBeInterrupted : true,
  755. checkIfNeedPlay:function(){
  756. }
  757. },
  758. {
  759. name:"hot",
  760. level : 2,
  761. canBeInterrupted : true
  762. },
  763. {
  764. name:"tour",
  765. level : 3,
  766. canBeInterrupted : true
  767. },
  768. ],
  769. switchPlay:function(){
  770. },
  771. register:function(){
  772. }
  773. }
  774. */
  775. //最好能知道应该播放到的currentTime
  776. var SoundManager = { //暂不支持同时播放
  777. currentAudio: null, //当前正在播放list中的哪一个
  778. enableSound: true, //是否允许有声音
  779. playHistory: [], //被打断的加入播放历史
  780. list: [ ], //同一级别可以互相打断 //暂时不做多级别
  781. play: function(name, src, currentTime) {
  782. // 点击开始自动导览的时候,手动停止背景音乐播放
  783. window.manage.switchBgmState(false)
  784. var object = this.list.find(e=>e.name == name)
  785. if (object) {
  786. if (this.currentAudio) {
  787. this.pause(this.currentAudio.name, false, true)
  788. }
  789. {//将当前要播放的播放历史中清除
  790. let index = this.playHistory.indexOf(object)
  791. if (index > -1) this.playHistory.splice(index, 1)
  792. }
  793. this.currentAudio = object
  794. if (src) {
  795. this.setSrc(name, src)
  796. }
  797. if (currentTime != void 0) {
  798. object.audio.currentTime = currentTime
  799. }
  800. if (object.audio) {
  801. object.audio.load() // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  802. object.audio.play()
  803. object.callback && object.callback(true)
  804. }
  805. Log(name + ' 播放 ' )
  806. }
  807. },
  808. pause: function(name, autoReplayLast, isInterrupt) {//需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  809. var object = this.list.find(e=>e.name == name)
  810. if (object) {
  811. this.currentAudio = null
  812. if (object.audio) {
  813. object.audio.pause()
  814. object.callback && object.callback(false)
  815. Log(name + ' 中断音频 ' + "(" + common.getFileNameFromUrl(object.audio.src) + ')' )
  816. }
  817. if (isInterrupt) {//一般主动调用不需要加这个
  818. this.playHistory.push(object)//如果是被中断的,加入播放历史,等待恢复播放
  819. }
  820. if (autoReplayLast) { //播放之前的音频。它们是被打断过的。
  821. while (this.playHistory.length) {
  822. var last = this.playHistory.pop()
  823. if (last.src && last.canplay(last.audio)) {
  824. this.play(last.name )
  825. }
  826. }
  827. }
  828. }
  829. },
  830. setSrc: function(name, src) {//不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  831. var object = this.list.find(e=>e.name == name)
  832. object.src = src
  833. object.audio.src = src
  834. Log(`${object.name} 设置src: ${src}`)
  835. },
  836. createAudio: function(object = {}) {//name, level, canplay
  837. if (!object.fake) {
  838. object.audio = new Audio()
  839. object.audio.loop = !!object.loop
  840. //object.audio.autoplay = true;
  841. object.audio.addEventListener('ended', ()=>{
  842. if (object.loop) {//循环
  843. Log(`${object.name} 播放完毕,重新播放`)
  844. object.audio.play()
  845. } else {
  846. this.pause(object.name, true)//停止后的后续处理
  847. }
  848. })
  849. object.audio.oncanplaythrough = ()=>{
  850. Log(`${object.name} canplaythrough `)
  851. }
  852. }
  853. this.list.push(object)
  854. },
  855. initAutoPlay: function() { //处理设备自动播放限制
  856. let play = function() {
  857. if (this.currentAudio && this.currentAudio.audio) {
  858. this.currentAudio.audio.play()
  859. Log(`${this.currentAudio.name} 自动播放成功`) //即使设置src在这之后好像也能成功播放
  860. } else {
  861. }
  862. document.removeEventListener("touchstart", play)
  863. document.removeEventListener("click", play)
  864. $('#player')[0].removeEventListener("touchstart", play)
  865. }.bind(this)
  866. document.addEventListener("WeixinJSBridgeReady", play, false)
  867. document.addEventListener("touchstart", play)//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  868. document.addEventListener("click", play)
  869. $('#player')[0].addEventListener("touchstart", play)
  870. }
  871. }
  872. function Log(value, color, fontSize) {
  873. color = color || '#13f'
  874. fontSize = fontSize || 14
  875. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`)
  876. }
  877. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  878. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  879. //box视频都静音,所以暂时不考虑
  880. SoundManager.createAudio({
  881. name: 'bgm',
  882. level: 0,
  883. src: '',
  884. loop: true,
  885. canplay: (audio)=>{
  886. return this.bgmShouldPlay
  887. },
  888. callback: (state)=>{//play或pause时随之触发的函数(即使还没开始播放)
  889. if (state) {
  890. console.log('播放背景音乐')
  891. document.querySelector('#openMusic').style.display = 'none'
  892. document.querySelector('#closeMusic').style.display = 'block'
  893. } else {
  894. console.log('暂停背景音乐')
  895. document.querySelector('#openMusic').style.display = 'block'
  896. document.querySelector('#closeMusic').style.display = 'none'
  897. }
  898. }
  899. })
  900. SoundManager.createAudio({
  901. name: 'tour',
  902. level: 0,
  903. src: '',
  904. loop: false,
  905. canplay: (audio)=>{
  906. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  907. }
  908. })
  909. SoundManager.createAudio({
  910. name: 'hot',
  911. fake: true, //实际上没有audio. 只是为了来停止和续播其他音频
  912. level: 1,
  913. src: '',
  914. loop: false,
  915. canplay: (audio)=>{
  916. }
  917. })
  918. $("#volume").find("a").on("click", ()=> {
  919. if ($("#volume img")[0].src.indexOf("btn_on.png") > -1)
  920. {
  921. this.switchBgmState(true)
  922. }
  923. else if ($("#volume img")[0].src.indexOf("btn_off.png") > -1)
  924. {
  925. this.switchBgmState(false)
  926. }
  927. })
  928. // this.switchBgmState(true);//初始设置允许播放bgm
  929. // SoundManager.initAutoPlay()
  930. }
  931. Manage.prototype.switchBgmState = function(state) {//按钮的状态完全代表是否应该播放bgm,即使还没加载完
  932. this.bgmShouldPlay = state
  933. if (state) {
  934. SoundManager.play('bgm')
  935. } else {
  936. SoundManager.pause('bgm')
  937. }
  938. /* if(!g_bgAudio || !g_bgAudio.src) return;
  939. var played = function(){
  940. console.log('begin play bgm');
  941. g_play = 1;
  942. g_playAudio = g_bgAudio;
  943. g_tourAudio && g_tourAudio.pause()
  944. }
  945. var paused = function(){
  946. g_play = 0;
  947. g_playAudio == g_bgAudio && (g_playAudio = null)
  948. }
  949. if(state ){
  950. g_bgAudio.play();
  951. if(g_bgAudio.paused){
  952. paused()
  953. }else{
  954. played()
  955. return true
  956. }
  957. }else{
  958. g_bgAudio.pause();
  959. paused()
  960. }
  961. g_bgAudio.pauseByHot = false
  962. g_bgAudio.pauseByTour = false */
  963. }
  964. var manage = new Manage()
  965. //兼容一代的場景
  966. //請求地址統一管理
  967. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  968. var g_version = manage.number("version")
  969. g_version === "one" ? g_Prefix = g_onePregix : ''