manage.js 38 KB

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