1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241 |
- var _musicMaxWeight = 8//M
- function reData(data,type) {
- return JSON.stringify(data) == type ? null : data
- }
- //新编辑界面
- var EditTools = function (n) {
- //main2018 里面的主要对象
- this.n = n;
- //当前状态
- this.atPanel = null;
- //场景信息
- this.sceneInformation = new SceneInformation();
- //热点
- this.hotpoint = new Hotpoint();
- //导览
- this.editGuide = new EditGuide();
- //音乐
- this.editMiuse = new EditMiuse();
- //初始化界面
- this.init();
- }
- EditTools.prototype.init = function () {
- this.hotpoint.init(this.n);
- var that = this;
- this.saveAll();
- this.active();
- //请求数据someData.js
- $.ajax(g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(), { dataType: "json" })
- .done(function (data) {
- //创建导览
- that.editMiuse.init(data);
- //请求完someData.js 之后再请求data2.js
- data2(data, that.sceneInformation.init);
- })
- //请求热点数据 data2.js
- function data2(data, callback) {
- $.ajax(g_Prefix + "data/" + window.number + "/data2.js" + "?" + Date.now(), { dataType: "json" })
- .done(function (data2) {
- callback(data, data2);
- // fyz 初始化导览需要两部分数据, 其中data2为data.js中的数据
- that.editGuide.init(data, data2);
- }).fail(
- callback(data, data2)
- )
- }
- $("body").on("click", function () {
- $(".DelConfirm").removeClass("active");
- })
- }
- //点击的时候激活状态
- EditTools.prototype.active = function () {
- var that = this;
- var confirmSnap = $(".confirmSnap.innerBtn");
- var snapshotGui = $(".snapshotGui.overlayGui");
- $('.toolBottom .toolLeft li').click(function () {
- var name = $(this).data("name");
- $('.toolLeft li[data-name=' + name + ']').addClass("active").siblings().removeClass("active");
- $('.toolRight .' + name).removeClass("hide").siblings().addClass("hide");
- if(name == that.atPanel)return;
-
- console.log(`atPanel ${that.atPanel} name ${name}`)
- switch(that.atPanel){//退出
- case "panoVisible":
- permitTranMode(true)
- panoVisiSet.finishSetPanoVisible()
- break;
- case "screen":
- confirmSnap.addClass("hide").removeClass("unable");
- snapshotGui.hide();
- break;
- case "overlay":
- EditOverlay.leave()
- break;
- case "hotpoint":
- $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click()
- break;
- }
- switch(name){
- case "panoVisible":
- var enter = function(){
- if(player.modeTran.split('-')[1] != "floorplan"){
- setTimeout(panoVisiSet.beginSetPanoVisible.bind(panoVisiSet), 300)//提前一点出现
- }
- player.flyToMode("floorplan", panoVisiSet.beginSetPanoVisible.bind(panoVisiSet));
- }
- $(".toolLeft").addClass("unable")
- permitTranMode(false)
- if(!player.modeTran){
- player.afterCModeFuc = ()=>{
- enter()
- }
- }else enter()
- break;
- case "screen":
- confirmSnap.removeClass("hide");
- $('#camera-start').text("点此设置为初始画面")
- snapshotGui.show();
- if(player.modeTran.split("-")[1] != "panorama")$(".confirmSnap").addClass("unable")
- break;
- case "overlay":
- EditOverlay.enter()
- break;
- }
-
- that.atPanel = name;
-
-
- /* if(name != "hotpoint"){
- $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click()
- } */
-
- })
- //滚动阻止事件
- $(".toolRight div.content").on("mousewheel", function (event) {
- event.stopPropagation()
- });
- // 输入框阻止事件
- $('.toolRight').on('keydown', function (ev) {
- ev.stopPropagation();
- })
- }
- //保存按钮
- EditTools.prototype.saveAll = function () {
- var that = this;
- $('#save').on('click', function () {
- $(".edit-loading").removeClass("hide");
- //导览的数据
- var guides = Array.from($('.tourList ul li')).map(function (dom) {
- return dom.data
- })
- var hots = {}
- // 热点数据
- Array.from($('.spotList ul li')).forEach(function (dom) {
-
- if(dom.infoAttribute){
- delete dom.infoAttribute.position;
- delete dom.infoAttribute.quaternion;
- }
- hots[dom.hotAttribute.belongHot.sid] = {
- position: {
- x: dom.hotAttribute.position.x,
- y: dom.hotAttribute.position.y,
- z: dom.hotAttribute.position.z
- },
- rotation: {
- x: dom.hotAttribute.rotation.x,
- y: dom.hotAttribute.rotation.y,
- z: dom.hotAttribute.rotation.z
- },
- infoAttribute: dom.infoAttribute
- }
- })
- var info = {
- name: $('#pjtName').val(),
- summary: $('#info-summary').val(),
- weixinDesc:$('#weixin-summary').val(),
- backgroundMusic: $('#query-bgm').attr('href'),
- hoticon: JSON.parse($(".hotStyle-item li.active").attr("data-val")),
- camera_start: $('#camera-start')[0].data,
- loadlogo: $("#loadlogo").is(':checked'),
- special: $("#g_specialScene").is(':checked'),
- vision_version: $("#twoData").is(':checked') ? "1.1.562.17209" : false,
-
- /************************************** 方奕卓 场景可配置项 ******************************************/
- hotImageScale: $("#hotImgScale").is(':checked'), // 热点图片可放大
- hideFloorMarker: $("#hideFloorMarker").is(':checked'), // 地面标记
- hideMouseMarker: $("#hideMouseMarker").is(':checked'), // 鼠标标记
- floorMarkerColor: $('#floorMarkerColor').val(), // 地面/导览标志颜色
- mouseMarkerColor: $('#mouseMarkerColor').val(), // 鼠标标志颜色
- momentTour: $('#tourSwitch input').is(':checked') ? 'black' : 'walk', // 导览瞬间过渡
- showHotListSta: $('#hotListSwitch input').is(':checked'), // 开启热点列表
- hotIconScale: $('#hotIconScale input').val(), // 热点缩放
- supportsVR: $('#VRSwitch input').is(':checked'), // 开启VR功能
- }
-
- var overlayInfo = []
- player.overlayGroup.children.forEach((overlay)=>{
- var info = EditOverlay.getSavingInfo(overlay)
- if(info)overlayInfo.push(info);
- })
-
- $.ajax({
- method: 'POST',
- headers:{
- 'Content-Type':'application/json',
- token:token
- },
- dataType:'json',
- contentType:'application/json',
- url: ceshi + '/manage/scene/edit',
- data: JSON.stringify({
- sceneCode:number,
- hots: reData(hots,'{}') ,
- name: number,
- guides: reData(guides,'[]'),
- info: info,
- tourAudio: reData(that.editGuide.tourAudio,'{}'),
- overlays: reData(overlayInfo,'[]')
- }),
- success: function (data) {
- if (data.code === 0) {
- location.reload()
- }
- if (data.code === 5001) {
- alert('请重新登录')
- localStorage.dcj_token = ''
- location.reload()
- }
- }
-
- })
- });
- }
- //场景信息编辑
- var SceneInformation = function () {
- }
- SceneInformation.prototype.init = function (data, data2) {
- var $options = $('.hotStyle-item li');
- var $loadlogo = $("#loadlogo");
- var $hotImageScale = $("#hotImgScale");
- var $hideFloorMarker = $("#hideFloorMarker");
- var $hideMouseMarker = $("#hideMouseMarker");
- var $g_specialScene = $("#g_specialScene");
- var $twoData = $("#twoData");
- /*******************方奕卓 其他项需要用到data来初始化, 故一并放到这里 ******************/
- let momentTour = $('#tourSwitch input'); // 导览瞬间过渡开关
- let hotListSwitch = $('#hotListSwitch input'); // 热点列表开关
- let hotIconScale = $('#hotIconScale input'); // 热点图标缩放
- let VRSwitch = $('#VRSwitch input'); // VR功能开启
- /***********************************************************************************/
- $(".model-title2").text(data.name);
- $('#pjtName').val(data.name);
- $('#info-summary').val(data.summary);
- //if (data2) $('#weixin-summary').val(data2.weixinDesc);
- $('#weixin-summary').val(data.weixinDesc);
- for (var i = 0; i < $options.length; i++) {
- if ($options.eq(i).attr('data-val') === JSON.stringify(data.hoticon)) {
- $options.eq(i).addClass("active").siblings().removeClass("active");
- }
- }
- $('#camera-start')[0].data = data.camera_start;
- $(".shotImg.innerBtn").on("click",()=>{
- var EntryInfo = $('#camera-start')[0].data
- if(EntryInfo){
- var to = player.model.panos.get(EntryInfo.pano.uuid);
- var q = new THREE.Quaternion().fromArray(EntryInfo.camera.quaternion);
- var lookAtPoint = new THREE.Vector3(0, 0, -1).applyQuaternion(q).add(to.position);
- player.flyToPano({ pano: to, lookAtPoint: lookAtPoint })
- }
- })
-
- /*************方奕卓 其他项的初始化操作 ************/
- initColorElem(data);
- addListener(); // 给其他元素绑定事件
- if (data.momentTour === 'black') {
- momentTour.prop('checked', true);
- }
- if (data.showHotListSta && data.showHotListSta != "false") {
- hotListSwitch.prop('checked', true);
- }
- if (data.hotIconScale && parseFloat(data.hotIconScale) <= 1.5 && parseFloat(data.hotIconScale) >= 0.3) {
- hotIconScale.val(parseFloat(data.hotIconScale));
- }
- if (data.supportsVR) {
- VRSwitch.prop('checked', true);
- }
- /************************************************/
- //隐藏公司logo
- if (data.loadlogo) {
- $loadlogo[0].checked = true
- showLogo();
- }
- // 热点图片放大
- if (data.hotImageScale && data.hotImageScale != "false") {
- $hotImageScale[0].checked = true
- }
- // 隐藏地面标记
- if (data.hideFloorMarker && data.hideFloorMarker != "false") {
- $hideFloorMarker[0].checked = true
- }
- // 隐藏鼠标标记
- if (data.hideMouseMarker && data.hideMouseMarker != "false") {
- $hideMouseMarker[0].checked = true
- }
- //特殊大场景
- if (data.special === "true" || data.special) {
- $g_specialScene[0].checked = true
- }
- //启动二代的数据
- if (data.vision_version === "1.1.562.17209" || data.vision_version) {
- $twoData[0].checked = true
- }
- }
- /**
- * 初始化颜色选择的html元素
- * @param {*} data
- * @param {*} elem
- */
- function initColorElem(data, elem) {
- let $floorMarkerColor = $('#floorMarkerColor');
- let $mouseMarkerColor = $('#mouseMarkerColor');
- let $floorMarkerColorTex = $('#floorMarkerColorTex');
- let $mouseMarkerColorTex = $('#mouseMarkerColorTex');
- var colorRe = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
- // 判断data中是否有存在的颜色值, 否则设置默认值
- data.floorMarkerColor ? $floorMarkerColor.val(data.floorMarkerColor) : $floorMarkerColor.val('#4bcdfc');
- data.mouseMarkerColor ? $mouseMarkerColor.val(data.mouseMarkerColor) : $mouseMarkerColor.val('#4bcdfc');
- // 事件监听
- $floorMarkerColor.on('change', function (e) {
- $('#floorMarkerColorTex').attr('placeholder', e.target.value)
-
- })
- $floorMarkerColorTex.on('blur keydown', function (e) {
- (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $floorMarkerColor, this);
- })
- $mouseMarkerColor.on('change', function (e) {
- $('#mouseMarkerColorTex').attr('placeholder', e.target.value)
-
- })
- $mouseMarkerColorTex.on('blur keydown', function (e) {
- (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $mouseMarkerColor, this);
- })
- // 设置颜色值
- function setColor(e, colorElem, inputElem) {
- var isColor = colorRe.test(e.target.value);
- isColor && colorElem.val(e.target.value);
- // isColor ? colorElem.val(e.target.value): (inputElem.placeholder = colorElem.val());
- }
- }
- function addListener() {
- }
- //设置初始界面
- function getSeft(seft) {
- $('#camera-start').on('click', function () {
-
-
- if(panoVisiSet.setPanoVisible){
- return panoVisiSet.savePanoVisibles()
- }
-
- // 这部分内容需要配合main_2018.js中来进行修改
- var snap = JSON.parse("{" + seft.getSnapAngleInfo() + "}")
- this.data = {
- camera :{
- position : snap.metadata.camera_position,
- quaternion : snap.metadata.camera_quaternion // 相机朝向
- },
- pano:{
- uuid : snap.metadata.scan_id // 起始点位的id
- }
- }
- var ev = document.createEvent("MouseEvent");//点击截取视图
- g_snapShotWidth = 240;
- g_snapShotHeight = 118;
- window.screenSta = 'startScreen';
- ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
-
-
- ev.__callback = (imgData, info)=>{
- uploadImg(imgData, (rs)=>{
- if (rs.code === 0) {
- $(".shotImg.innerBtn").css("background-image", "url(" + rs.data + ")")
- this.data.thumbImg = rs.data;
- }
- })
-
- }
-
- window.dispatchEvent(ev);
- });
-
-
-
- }
- //热点编辑
- var Hotpoint = function () {
- this.spotList = $(".spotList");
- this.hotpointDetail = $("#hotpointDetail"); // fyz 导览编辑页面同样采取热点编辑的样式, 这里确保只查找到热点编辑
- }
- Hotpoint.prototype.init = function (n) {
- this.active();
- this.addmedia(); // 添加多媒体
- this.addMusic(); // 添加音乐
- this.addModel(); // 添加模型
- this.addwebPack(); // 添加外链
- this.saveHot(); // 保存热点
- var that = this;
- let hotIconScale = $('#hotIconScale');
- //点击添加热点按钮
- $('#addHotSpots').on("click", function () {//点击添加热点
- g_HotStatus = g_HotStatus === "add" ? null : "add";
- $("#player").css("cursor", "cell");
- });
- //点击热点列表弹出按钮
- this.spotList.on("click", function (e) {
- var target = $(e.target);
- if (target.hasClass("del")) {
- e.stopPropagation();
- target.siblings(".DelConfirm").addClass("active");
- that.spotList.find("i").text(that.spotList.find("ul li").length);
- } else {
- if (target.hasClass("DelConfirm")) {
- e.stopPropagation();
- that.remHot(target, n);
- } else {
- //点击热点列表弹出编辑热点窗口
- if (target.hasClass("title") || target.hasClass("icon")) {
- that.editHot(target)
- }
- }
- }
- });
- //点击热点编辑窗口右上角的关闭按钮
- this.hotpointDetail.find("a.close, button.cancel").on("click", function () {
- var spot_id = that.hotpointDetail.attr("data-id");
-
- var info = that.hotpointDetail[0].targetDOM.infoAttribute;
- if(info){
- var hot = player.model.hots[spot_id];
- info.position && hot.mesh.position.copy(info.position)
- info.quaternion && hot.mesh.quaternion.copy(info.quaternion)
- }
- that.hotpointDetail.addClass("atRight");
- transformControls.detach()
- });
-
- //遍历热点 初始话加载热点数据
- for (var i = 0; i < g_HotMeshes.length; i++) {
- this.spotList.children("ul").append(this.addHotList(g_HotMeshes[i], i));
- }
- this.spotList.find("i").text(g_HotMeshes.length);
- // 初始话的时候把热点信息添加到对应的热点中
- $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
- .then(function (infos) {
- that.infos = infos ;
- Object.keys(infos).forEach(function (key) {
- //sxm增加热点列表可读性,方便查看删除操作等
- that.spotList.find("ul li[data-spid=" + key + "]")[0] && (that.spotList.find("ul li[data-spid=" + key + "]")[0].infoAttribute = infos[key])&& (that.spotList.find("ul li[data-spid=" + key + "] .title").html(infos[key].title));
-
- })
- })
- }
- /**
- * 显示编辑热点的窗口和初始化热点窗口的数据
- */
- Hotpoint.prototype.editHot = function (target) {
- this.hotpointDetail.removeClass("atRight");
- $("#hotpointDetail .audio.mediaUpload").find("input").val(''); // 点击编辑导览清空上一次文件
- var playIcon = '139.159.225.37:85/images/play.png';
- var $layout = $("#hotpointDetail")[0];
- $layout.targetDOM = target.closest("li")[0];//closest匹配选择器的第一个祖先元素
- //编辑时将热点列表唯一标识带入,以便后期保存使用识别
- var li_id = $($layout.targetDOM).attr("data-spid");
-
-
- this.hotpointDetail.attr("data-id",li_id);
- var info = $layout.targetDOM.infoAttribute || {}
- transformControls.transCtlChangeMode("translate")
-
-
-
-
- // 参数初始化
- info.title = info.title || '';
- info.content = info.content || '';
- info.iframe = info.iframe || [];
- info.model = info.model || [];
- info.images = info.images || [];
- info.video = info.video || [];
-
-
- try{
- transformControls.attach(player.model.hots[li_id].mesh)
- player.model.hots[li_id].examine(player,{dontOpen:true})//add
-
- info.position = player.model.hots[li_id].mesh.position.clone()
- info.quaternion = player.model.hots[li_id].mesh.quaternion.clone()
- }catch(e){}
-
- initStyle(player.model.hots[li_id])
- var iframesHTML = info.iframe.map(function (iframe) {
- return this.inputList("请填写网页链接", iframe)
- }.bind(this))
- var modulesHTML = info.model.map(function (module) {
- return this.inputList("请填写网页链接", module)
- }.bind(this))
- var imagesHTML = info.images.map(function (image) {
- return '<div><a class=" result success"><span></span><img src="' + image + '"></a></div>'
- })
- var videosHTML = info.video.map(function (ly) {
- var imgDom = (!ly.img || ly.img === "undefined") ? '' : 'success';
- var imgUrl = (!ly.img || ly.img === "undefined") ? playIcon : ly.img;
- return '<div><a class=" result success"><span></span><img class="play-video" videoURL="' + ly.url + '" src="' + imgUrl + '"></a ><span class="upload-thum ' + imgDom + ' result" attr-thum="' + ly.img + '">上传封面<i><input type="file"></i></span></div>'
- })
- this.hotpointDetail.find(".name > input").val(info.title);
- this.hotpointDetail.find(".editText").val(info.content);
- this.hotpointDetail.find(".photo .list").html(imagesHTML);
- this.hotpointDetail.find(".video .list").html(videosHTML);
- this.hotpointDetail.find(".model .list").html(modulesHTML);
- this.hotpointDetail.find(".webPage .list").html(iframesHTML);
- let bgName = info.bgName || '热点背景音乐';
- if (info.backgroundMusic) {
- this.hotpointDetail.find(".audio .playBox").removeClass("hide");
- this.hotpointDetail.find("#upload-hotBgm").attr('data-hotBgm', info.backgroundMusic)
- this.hotpointDetail.find(".audio .playBox a").attr("href", info.backgroundMusic);
- this.hotpointDetail.find('#hotBgName')[0].innerHTML = bgName;
- this.hotpointDetail.find(".audio .submit").text("替换");
- } else {
- this.hotpointDetail.find(".audio .playBox").addClass("hide");
- this.hotpointDetail.find("#upload-hotBgm").removeAttr('data-hotBgm') // 没有背景音乐,则移除该属性, 避免其他热点的干扰
- }
- $layout.targetDOM.infoAttribute = info
- }
- //添加图片和视频
- Hotpoint.prototype.addmedia = function () {
- // 视频预览控制
- var $videoLayout = $('.fun-view-video')
- $videoLayout.find('span').on('click', function () {
- $videoLayout.hide();
- $videoLayout.find('video').attr('src', '')[0].pause()
- });
- // 图片加载回调
- function imageSuccess(file) {
- if (!/image\/\w+/.test(file.type)) {
- alert("文件必须为图片!");
- return false;
- }
- if (!restrictedSize(file, 2)) {
- return false;
- }
- var img = new Image()
- img.src = URL.createObjectURL(file);
- return img
- }
- // 视频加载回调
- function videoSuccess(file, $elayout) {
- if (!/video\/\w+/.test(file.type)) {
- alert("视频必须为map4格式!");
- return false;
- }
- $elayout.append('<span class="upload-thum">上传封面<i><input type="file"></i></span>')
- return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) + '">'
- }
- // 视频封面回调
- function thumSuccess(file, $elayout, $seft) {
- if (!/image\/\w+/.test(file.type)) {
- alert("文件必须为图片!");
- return false;
- }
- if (!restrictedSize(file, 2)) {
- return false;
- }
- $seft.closest('div').find('img').attr('src', URL.createObjectURL(file));
- }
- // 图片与视频加载
- function fileHandle() {
- var $seft = $(this)
- var $layout = $seft.closest("li");
- var type = $seft.parent().attr('data-type');
- var file = this.files[0];
- var $din = $(document.createElement('div'));
- var fnc = type === 'photo' ? imageSuccess :
- type === 'video' ? videoSuccess : thumSuccess
- var $dom = fnc(file, $din, $seft)
- if (type === 'photo' || type === 'video') {
- if (!$dom) return $seft.val('');
- var $addLayout = $(document.createElement('a'));
- var $addInput = $('<input type="file">')
- var $close = $(document.createElement('span'));
- $addInput[0].files = this.files;
- $addLayout.append($addInput)
- $addLayout.append($close);
- $addLayout.append($dom);
- $addLayout.addClass("result");
- $din.prepend($addLayout);
- $layout.find('.edit-fun-images').append($din);
- }
- };
- // 图片与视频加载
- $('.upload, .edit-fun-images').on('change', function (ev) {
- if (ev.target.tagName.toUpperCase() === 'INPUT') {
- fileHandle.call(ev.target)
- }
-
- })
- $('.edit-fun-images').on('click', function (ev) {
- var $tag = $(ev.target)
- var tagName = ev.target.tagName.toUpperCase()
- if (tagName === 'SPAN') {
- var $resf = $(ev.target)
- $resf.parent().parent().remove()
- } else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
- $videoLayout
- .css('display', 'flex')
- .find('video')
- .attr('src', $tag.attr('videoURL'))[0]
- .play()
- }
- })
- }
- //========================xzw=======================更改热点样式图
- var currStyle; //当前选择的模式 默认or用户自定义
- var currentHotStyleImg = []; //当前编辑状态下添加的图, 每次开始编辑热点时更新
- var editStyleImgIndex = 0; //当前正在编辑第几张图
- var uploadInput = $('<input type="file" style="display:none" accept="image/*"></input>');
- $("#hotpointDetail .style .MenuOptions li").on("click",(e)=>{//热点页面内样式切换
- currStyle = $(e.target).attr("index")
- if(currStyle == "default"){
- $("#userUploadStyle").addClass("hide")
- }else{
- $("#userUploadStyle").removeClass("hide")
- }
- $("#hotpointDetail .style .MenuOptions li").removeClass("chosen");
- $(e.target).addClass("chosen")
- })
- $('#userUploadStyle li').on('click',(e)=>{
- var index = $(e.currentTarget).index();
- if(e.target.classList.contains("del")){//删除图片
- if(currentHotStyleImg.length == 2 && index == 0){//删除第一个 且有第二个的话
- setImgContent(0,currentHotStyleImg[1].src);
- setImgContent(1,null);
- currentHotStyleImg = [currentHotStyleImg[1]]
- }else{
- setImgContent(index,null);
- currentHotStyleImg.pop()
- if(currentHotStyleImg.length == 0){
- $('#userUploadStyle li').eq(1).addClass("hide");
- }
- }
- }else{//添加图片
- uploadInput.click()
- editStyleImgIndex = index;
- }
-
- })
- uploadInput.on("change", (e)=>{
- inputMedia({
- enableTypes:[ "photo"],
- photoDone:(resultImg)=>{
- currentHotStyleImg[editStyleImgIndex] = resultImg;
- setImgContent(editStyleImgIndex, resultImg.src)
-
- if(editStyleImgIndex == 0) $('#userUploadStyle li').eq(1).removeClass("hide");
- resultImg.needSave = true
- }
- }, "photo", e);
- })
- var setImgContent = function(index, src){
- var li = $('#userUploadStyle li').eq(index)
- var div = li.find('>div');
- if(src){
- li.addClass("uploaded")
- div.css("background-image",`url(${src})`)
- }else{
- li.removeClass("uploaded")
- div.css("background-image",'')
- }
- }
- var initStyle = function(hot){//每次开始编辑热点时更新列表UI 和 currentHotStyleImg
- if(!hot.styleTex) hot.styleTex = [];
-
- $('#userUploadStyle li>div').css("background-image","");
- $('#userUploadStyle li').removeClass("uploaded")
- currentHotStyleImg = hot.styleTex.slice(0);
-
- if(hot.styleTex.length){
- $("#hotpointDetail .style .MenuOptions li").eq(1).click();
- hot.styleTex.forEach((img,index)=>{
- setImgContent(index, img.src)
- })
- $('#userUploadStyle li').eq(1).removeClass("hide")
-
- }else{
- $("#hotpointDetail .style .MenuOptions li").eq(0).click()
- $('#userUploadStyle li').eq(1).addClass("hide")
- }
- }
- //=====================================================
- //选择热点的样式
- Hotpoint.prototype.active = function () {
- $(".hotStyle-item li").on('click', function () {
- $(this).addClass('active').siblings().removeClass('active');
- })
- }
- //当前处于的状态,比如是否是添加热点的状态
- Hotpoint.prototype.state = function (that, Hot) {
- if (g_HotStatus === "add") {
- //console.log(Hot)
- this.addHot(that, Hot, function () {
- this.addHotList(g_HotMeshes, g_HotMeshes.length - 1);
- this.spotList.find("i").text(this.spotList.find("ul li").length);
- });
- }
- }
- //删除热点
- Hotpoint.prototype.remHot = function (that, thisScene) {
- var hotId = that.closest("li").attr("data-spid");
- for (var i = 0; i < g_HotMeshes.length; i++) {
- if (g_HotMeshes[i].belongHot.sid === hotId) {
- //在场景中删除这个热点模型
- thisScene.scene.remove(g_HotMeshes[i]);
- g_HotMeshes[i].visible = false;
- //如果热点数据中有这个热点数据就删除
- //g_HotMeshes.splice(i, 1);
- }
- }
- that.closest("li").remove();
- this.spotList.find(".hotNum").text(this.spotList.find("ul li").length);
- console.log("删除成功:" + hotId);
- }
- //添加热点模型
- Hotpoint.prototype.addHot = function (that, Hot, fn) {
- if (!window.hotIntersect) return; // 没有正确的热点位置, return
- var position = hotIntersect.point.toArray();
-
- //var sid = g_HotMeshes.length > 0 ? "sprite_" + (parseInt(g_HotMeshes[g_HotMeshes.length - 1].name.substring(7)) + 1) : "sprite_" + g_HotMeshes.length;//这么写出bug了。因为当前热点名字不是按照从小到大
- var sid = getRandomSid()
- var hot = new Hot(sid, { position: position, rotation: [0,0,0], size: 1.05 }, that.model);
- that.model.hots[sid] = hot;
-
- if(player.getMouseDirection().angleTo(window.hotIntersect.face.normal) < Math.PI/2) {
- hot.mesh.lookAt(window.hotIntersect.face.normal.clone().negate().add(hotIntersect.point));
- hot.mesh.position.add(window.hotIntersect.face.normal.clone().negate().multiplyScalar(0.01))//avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
- }else{
- hot.mesh.lookAt(window.hotIntersect.face.normal.clone().add(hotIntersect.point));
- hot.mesh.position.add(window.hotIntersect.face.normal.clone().multiplyScalar(0.01))
- }
- g_HotStatus = false;
- that.mouseCouldBeClickToMove = false;
- $("#player").css("cursor", "");
- //添加完热点之后的回调函数
- if (g_HotMeshes && g_newHot.length === g_newHot.length++) {
- var thisScene = that;
- fn && fn.call(this, thisScene);
- }
- }
- //创建热点列表的dom
- Hotpoint.prototype.createDom = function (data, index) {
- var _index = +index + 1;
- return "<li data-spid=" + data.name + " id=ggg_s" + index + ">" +
- "<div class=icon></div>" +
- "<div class=number title=热点>" + _index + "</div>" +
- "<div class=title title=热点></div>" +
- "<div class=DelConfirm>确定删除</div>" +
- "<div class=del></div>" +
- "</li>";
- }
- //添加热点列表
- Hotpoint.prototype.addHotList = function (data, index) {
- if (!data) return;
- this.spotList.children("ul").append(this.createDom(data, index));
- //保存热点信息到热点dom元素中
- var spotList = $(".spotList ul").children("#ggg_s" + index);
- spotList[0].hotAttribute = g_HotMeshes[index];
- spotList.attr('data-spid', g_HotMeshes[index].belongHot.sid);
- }
- //添加热点音乐
- Hotpoint.prototype.addMusic = function () {
- var mediaUpload = $("#hotpointDetail .audio.mediaUpload");
- mediaUpload.find("input").on("change", function () {
- var file = this.files[0];
- mediaUpload.find(".innerBtn").text("替换");
- mediaUpload.find(".playBox").removeClass("hide");
- mediaUpload.find(".title").text(file.name);
- mediaUpload.find('#query-bgm').attr('href', URL.createObjectURL(file));
- });
- //删除音乐
- mediaUpload.on("click", ".delete", function () {
- mediaUpload.find('#query-bgm').attr('href', "");
- mediaUpload.find(".playBox").addClass("hide");
- mediaUpload.find(".innerBtn").text("上传");
- mediaUpload.find("input").val("").removeAttr("data-hotbgm");
- })
- }
- //添加热点模型列表dom
- Hotpoint.prototype.inputList = function (text, val) {
- var _val = '';
- if (arguments[1]) {
- _val = 'value=' + val;
- }
- return '<div class="link"> <input class="text" type="text" placeholder=' + text + ' spellcheck="false" ' + _val + ' > </div>'
- }
- //添加热点模型
- Hotpoint.prototype.addModel = function () {
- var text = this.inputList("请填写模型链接");
- this.hotpointDetail.find(".model .add").on('click', function () {
- $(this).closest(".model").find(".list").append(text)
- });
- this.hotpointDetail.find(".model .delete").on('click', function () {
- $(this).closest(".model").find(".list > div:last").remove();
- });
- }
- //添加网页链接
- Hotpoint.prototype.addwebPack = function () {
- var text = this.inputList("请填写网页链接", "");
- this.hotpointDetail.find(".webPage .add").on('click', function () {
- $(this).closest(".webPage").find(".list").append(text)
- });
- this.hotpointDetail.find(".webPage .delete").on('click', function () {
- $(this).closest(".webPage").find(".list > div:last").remove();
- });
- }
- // 保存热点信息
- Hotpoint.prototype.saveHot = function () {
- var $layout = $(".edit-loading");
- var hotpointDetail = this.hotpointDetail;
- var spotList = this.spotList ;
- hotpointDetail.find(".tail .submit").on('click', function () {
- //获取唯一标识
- var spot_id = hotpointDetail.attr("data-id");
- var spot = spotList.find("li[data-spid="+spot_id+"]");
- var hot = player.model.hots[spot_id];
- //显示loading
- $layout.removeClass('hide');
- var args = {};
- //热点标题
- var $title = hotpointDetail.find(".info input");
- //热点内容
- var $content = hotpointDetail.find(".info textarea");
- //热点图片
- var $images = hotpointDetail.find(".photo .edit-fun-images a.result");
- //热点视频
- var $videos = hotpointDetail.find(".video .edit-fun-images a.result");
- //热点视频的图片
- var $thums = hotpointDetail.find(".video .edit-fun-images .upload-thum");
- //热点模型
- var $modules = hotpointDetail.find(".model input");
- //热点内嵌网页
- var $iframes = hotpointDetail.find(".webPage input");
- //热点音乐
- var $miusc = hotpointDetail.find("#upload-hotBgm");
- let $bgName = hotpointDetail.find('.title');
- new Promise(function (resolve, reject) {
- //获取热点图片所有的路径
- upload($images, 'images', resolve)
- }).then(function (imgUrls) {
- args.images = imgUrls
- //获取热点视频所有的路径
- return new Promise(function (resolve, reject) {
- upload($videos, 'images', resolve)
- })
- }).then(function (videoUrls) {
- args.video = videoUrls
- //获取热点视频图片所有的路径
- return new Promise(function (resolve, reject) {
- upload($thums, 'images', resolve)
- })
- }).then(function (thums) {
- args.video = args.video.map(function (video, index) {
- return {
- url: video,
- img: thums[index]
- }
- })
- }).then(function () {
- //获取热点音乐所有的路径
- //console.log($miusc)
- if ($miusc[0].files.length > 0) {
- return new Promise(function (resolve) {
- upload($miusc, 'miusc', function (res) {
- resolve(res[0])
- })
- })
- } else {
- return $miusc.attr('data-hotBgm')
- }
- }).then(function (src) {
- args.backgroundMusic = src
- args.bgName = $bgName[0].innerHTML;
- }).then(function(){//上传style图片
- var a = $.Deferred();
- var doneNum = 0;
- if(currStyle == "user" && currentHotStyleImg.length){
- currentHotStyleImg.forEach((img)=>{
- if(img.needSave)
- uploadImg(img.base64Src, function(rs){
- if(rs.code == 0){
- img.needSave = false;
- img.saveURL = rs.data;
- if(++doneNum >= currentHotStyleImg.length){
- a.resolve();
- }
- }else{
- alert("样式图上传失败");
- a.reject();
- }
- })
- else if(++doneNum >= currentHotStyleImg.length){
- a.resolve();
- }
- })
- return a.promise()
- }else return a.resolve()
-
- }).then(()=>{ //获取style图的信息
-
- args.styleImg = [];
- if(currStyle == "user" ){
- currentHotStyleImg.forEach((img)=>{
- args.styleImg.push(img.saveURL || img.src)
- })
- hot.styleTex = currentHotStyleImg.slice(0)
- }else{
- hot.styleTex = [];
- }
- hot.changeTex(); //更新材质
- }).then(function () {
- //获取热点标题、内容、内嵌网页、模型网页。
- args.title = $title.val()
- args.content = $content.val()
- var iframes = []
- for (var i = 0; i < $iframes.length; i++) {
- var iframe = $iframes.eq(i).val()
- iframe && iframes.push(iframe)
- }
- args.iframe = iframes
- var modules = []
- for (var i = 0; i < $modules.length; i++) {
- var module = $modules.eq(i).val()
- module && modules.push(module)
- }
- args.model = modules
-
-
- args.position = hot.mesh.position.clone()
- args.quaternion = hot.mesh.quaternion.clone()
- return args
- }).then(function (args) {
- console.log(args);
- //把获取的所有信息都保存在对应热点的dom元素里面
- hotpointDetail[0].targetDOM.infoAttribute = args;
- $layout.addClass('hide');
- hotpointDetail.addClass("atRight");
- spot.find(".title").html(args.title);
- transformControls.detach()
- })
- })
- }
- //背景音乐
- var EditMiuse = function () {
- this.mediaUpload = $(".music .audio.mediaUpload");
- this.success = function (text, url) {
- this.mediaUpload.find(".innerBtn").text("替换");
- this.mediaUpload.find(".playBox").removeClass("hide");
- this.mediaUpload.find(".title").text(text);
- this.mediaUpload.find('#query-bgm').attr('href', url)
- };
- this.delete = function () {
- this.mediaUpload.find('#query-bgm').attr('href', "");
- this.mediaUpload.find(".playBox").addClass("hide");
- this.mediaUpload.find(".innerBtn").text("上传");
- this.mediaUpload.find("input").val("");
- };
- var that = this;
- $('#upload-bgm').on('change', function (e) {
- var file = this.files[0];
- uploadMiuse(file, function (rs, file) {
- if (rs.code === 0) {
- that.success(file.name, rs.data)
- }
- })
- e.target.value = null
- });
- //删除音乐
- this.mediaUpload.on("click", ".delete", function () {
- that.delete();
- })
- }
- EditMiuse.prototype.init = function (data) {
- if (!data.backgroundMusic) return;
- this.success("backgound", data.backgroundMusic);
- }
- //导览编辑
- var EditGuide = function () {
- this.$list = $('#guide-list')
- this.tourDetail = $('#tourEdit'); // 导览编辑
- this.targetTourPoint = null; // fyz 记录当前编辑的导览点
- // fyz 导览音乐队列
- this.tourAudio = {};
- }
- /**
- * @author fyz 2019.07.31
- * @description 新增参数data2, 表示data2.js中的数据
- */
- EditGuide.prototype.init = function (data, data2) {
- this.createDom(data, data2);
- this.addTourMusic(); // 添加导览音乐
- this.tourAudio = data2.tourAudio || {};
- var that = this;
- //点击添加导览
- $('.addTour .innerBtn').on("click", function () {//点击截取视图
- addTour(this);
- }.bind(this));
- // 重新录制导览
- $('#renewTourBtn').on("click", function () {//点击截取视图
- addTour(this, true);
- }.bind(this));
- // 确认并保存导览信息
- $('#tourSubmit').on("click", function () {//点击截取视图
- this.saveGuide();
- }.bind(this));
- function addTour(that, renew) {
- var ev = document.createEvent("MouseEvent");//"MouseEvent"
- ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
- g_snapShotWidth = 200;
- g_snapShotHeight = 140;
- window.screenSta = 'tour'; // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
- ev.__callback = function (imgData, info) {
- that.uploadGuide(imgData, info, renew, that.targetTourPoint)
- }.bind(that);
- window.dispatchEvent(ev);
- }
- // fyz 点击导览名字, 对导览进行详细编辑
- $('.tourList ul').on('click', function (ev) {
- var $seft = $(ev.target)
- if ($seft.attr('data-oper') === 'tour-text') {
- that.editGuideData($seft);
- }
- if ($seft.attr('data-oper') === 'tour-delete') {
- var choice = confirm("你确定删除吗?"); // 删除导览
- if (choice) {
- $seft.closest('li').remove();
- reIndexTourList()
- }
- else {
- return false
- }
- }
- }).on("change", function (ev) {
- this.inputDone(ev)
- ev.target.value = null
- }.bind(this))
- $('.tourList ul input').on('blur', function (ev) {
- this.inputDone(ev)
- }.bind(this)).on('keydown', function (ev) {
- ev.stopPropagation()
- })
- //点击导览编辑窗口右上角的关闭按钮
- this.tourDetail.find("a.close, button.cancel").on("click", function () {
- that.targetTourPoint[0].musicSta = true; // 取消操作, 重置状态
- that.tourDetail.addClass("atRight");
- });
- /*fyz 导览列表拖拽以改变导览点的顺序 */
- let tourListNode = document.querySelector('#tourListWrap');
- let draging = null;
- tourListNode.ondragstart = function (event) {
- event.dataTransfer.setData("te", event.target.innerText); //不能使用text,firefox会打开新tab
- draging = event.target;
- }
- tourListNode.ondragover = function (event) { // 拖拽完毕
- event.preventDefault();
- let target = event.target.parentNode.parentNode;
- let dragingIndex = draging.querySelector('#index');
- let targetIndex = target.querySelector('#index');
- // 判断dragover是否发生在LI元素上
- if (target.nodeName === 'LI' && target !== draging) {
- var targetRect = target.getBoundingClientRect();
- var dragingRect = draging.getBoundingClientRect();
- if (target && target.animated) {
- return;
- }
- let ulElem = target.parentNode; // 寻找到 ul节点
- if (getIndex(draging) < getIndex(target)) {
- dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0]; // 交换两个节点的序号
- ulElem.insertBefore(draging, target.nextSibling);
- } else {
- dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
- ulElem.insertBefore(draging, target);
- }
- _animate(dragingRect, draging);
- _animate(targetRect, target);
- reIndexTourList()
- }
- }
- }
- function reIndexTourList(){
- Array.from($(".tourList ul li")).forEach((li,index)=>{
- $(li).find("div:first-child span").text(index+1);
- })
- }
- /**
- * @author fyz 编辑导览数据
- * @param {any} target 所点击的导览点
- */
- EditGuide.prototype.editGuideData = function (target) {
- this.targetTourPoint = target; // 记录当前编辑的导览点
- var that = this;
- $('#tourEdit').removeClass('atRight'); // 显示导览编辑的工具栏
- document.querySelector('#tourName input').value = target.context.textContent; // 显示已有的导览名字
- $("#tourEdit .audio.mediaUpload").find("input").val(''); // 点击编辑导览清空上一次文件
- target[0].musicSta = true;
- // 判断当前点是否有导览音频
- var audio = this.tourAudio[target.closest('li')[0].data.sid];
- var musicUrl = audio ? audio.music : null;
- if (musicUrl) { // 判断改导览点是否已经已有音乐
- var musicName = audio.name || '导览音频.mp3' // 获取音频的文件名
- this.tourDetail.find(".audio .playBox").removeClass("hide");
- this.tourDetail.find("#upload-hotBgm").attr('data-hotBgm', musicUrl)
- this.tourDetail.find(".audio .playBox a").attr("href", "//" + musicUrl);
- this.tourDetail.find(".audio .submit").text("替换");
- this.tourDetail.find("#tourMusicName").text(musicName);
- } else {
- this.tourDetail.find(".audio .playBox").addClass("hide");
- this.tourDetail.find(".audio .submit").text("上传");
- }
- }
- /**
- * @author fyz 保存导览数据
- */
- EditGuide.prototype.saveGuide = function () {
- var $layout = $(".edit-loading");
- $layout.removeClass('hide');
- var that = this;
- var tourDetail = this.tourDetail;
- var tourName = tourDetail.find('#tourNameInput').val() || this.targetTourPoint.context.innerText;
- var curTourPoint = this.targetTourPoint.context.closest('li');
- this.targetTourPoint.text(tourName); // 输入框未输入数据则保留原来的值
- curTourPoint.data.name = tourName;
- // 导览音乐
- var tourAudio = this.tourDetail.find('#uploadTourBgm');
- var tourName = this.tourDetail.find("#tourMusicName").text(); // 记录音频名称
- var sid = curTourPoint.data.sid;
- // 判断当前编辑的导览点位是否已上传音乐
- if (tourAudio[0].files.length > 0 && this.targetTourPoint[0].musicSta) { // 已添加导览音乐
- new Promise(function (resolve, reject) {
- uploadMiuse(tourAudio[0].files[0], function (res) {
- resolve(res.data);
- })
- }).then(function (src) {
- var audio = new Audio();
- audio.src = src;
- audio.onloadedmetadata = function () {
- // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
- var srcArr = src.split('/');
- srcArr[0] = '';
- src = srcArr.join('/');
- that.tourAudio[sid] = {
- "name": tourName,
- "music": '/' + src,
- "time": Math.round(audio.duration * 1000 + 1000)
- }
- $layout.addClass('hide');
- $('#tourEdit').addClass('atRight'); // 显示导览编辑的工具栏
- }
- })
- } else if (!this.targetTourPoint[0].musicSta) { // 删除导览音乐, 将数据重置
- this.tourAudio[sid] = {
- "music": "",
- "time": 0
- }
- $layout.addClass('hide');
- $('#tourEdit').addClass('atRight'); // 显示导览编辑的工具栏
- } else { // 未添加导览音乐
- $layout.addClass('hide');
- $('#tourEdit').addClass('atRight'); // 显示导览编辑的工具栏
- }
- }
- //添加导览音乐
- EditGuide.prototype.addTourMusic = function () {
- var mediaUpload = $("#tourEdit .audio.mediaUpload");
- var that = this;
- mediaUpload.find("input").on("change", function () {
- var file = this.files[0];
- mediaUpload.find(".innerBtn").text("替换");
- mediaUpload.find(".playBox").removeClass("hide");
- mediaUpload.find(".title").text(file.name);
- mediaUpload.find('#query-bgm').attr('href', URL.createObjectURL(file));
- that.targetTourPoint[0].musicSta = true;
- });
- mediaUpload.find("input").on("click", function () {
- mediaUpload
- });
- //删除音乐
- mediaUpload.on("click", ".delete", function () {
- mediaUpload.find('#query-bgm').attr('href', "");
- mediaUpload.find(".playBox").addClass("hide");
- mediaUpload.find(".innerBtn").text("上传");
- mediaUpload.find("input").val("").removeAttr("data-hotbgm");
- that.targetTourPoint[0].musicSta = false;
- })
- }
- /**
- * @author fyz 2019.07.31
- * @description 新增参数data2
- * @param {object} data someData.js中的模型数据
- * @param {object} data2 data2.js中的导览和热点数据
- */
- EditGuide.prototype.createDom = function (data, data2) {
- var $lis = [];
- var that = this;
- var tourAudio = data2.tourAudio || {};
- data.model.images.forEach(function (i, index) {
- if (i.thumbnail_signed_src) {
- var $li = $(that.dom(index+1, i.name, i.thumbnail_signed_src));
- $li[0].data = i
- // 挂载当前导览点对应的音频链接
- if (i.sid in tourAudio && tourAudio[i.sid].music && tourAudio[i.sid].music !== '') {
- $li[0].musicUrl = tourAudio[i.sid].music;
- }
- $lis.push($li)
- }
- })
- $(".tourList > ul").append($lis)
- }
- EditGuide.prototype.dom = function (index, title, img) {
- return '<li draggable="true">' +
- '<div>' +
- '<span id="index">' + index + '</span>' +
- '<div class="line"></div>' +
- '</div>' +
- '<div>' +
- '<span class="guide-name" data-oper=tour-text>' + title + '</span>' +
- '<input maxlength="14" class="hide" data-oper=tour-input>' +
- '</div>' +
- '<div class="preview" >' +
- '<div id="tourBg" style="background-image: url(' + img + ');" data-oper=tour-delete>' +
- '</div>' +
- '</div>' +
- '</li >';
- }
- /**
- * @author fyz
- * @param target 当前导览点的父级li元素
- */
- EditGuide.prototype.inputDone = function (ev, target) {
- var $seft = $(ev.target)
- if ($seft.attr('data-oper') === 'tour-input') {
- // $seft.addClass('hide') // fyz 现有的实现方式不隐藏输入框
- var name = target.siblings('span').context.innerText;
- $seft.text($seft.val() || name); // fyz 如果未输入数据, 则保留原来的导览名字
- //更改导览横向列表的名字:
- target.siblings('span').context.innerText = $seft.val() || name;
- target.closest('li')[0].data.name = $seft.val() || name;
- }
- }
- /**
- * @author fyz 2019.07.31
- * @description uploadGuide方法新增参数renew状态码, 表示是否重新录制当前导览, 新增targetTourPoint, 记录当前的导览点元素
- */
- EditGuide.prototype.uploadGuide = function (urlData, guide, renew, target) {
- var that = this;
- uploadImg(urlData, function (rs) {
- if (rs.code === 0) {
- var editGuide = new EditGuide();
- var sid = rs.data.substring(rs.data.lastIndexOf('/') + 1, rs.data.lastIndexOf('.'));
- var thumbnail_signed_src = rs.data;
- var args = JSON.parse("{" + guide + "}");
-
- args.sid = sid;
- args.name = sid;
- args.thumbnail_signed_src = thumbnail_signed_src;
- args.metadata = JSON.stringify({
- camera_mode: args.metadata.camera_mode,
- camera_position: {
- x: args.metadata.camera_position[0],
- y: args.metadata.camera_position[1],
- z: args.metadata.camera_position[2]
- },
- camera_quaternion: {
- x: args.metadata.camera_quaternion[0],
- y: args.metadata.camera_quaternion[1],
- z: args.metadata.camera_quaternion[2],
- w: args.metadata.camera_quaternion[3]
- },
- ortho_zoom: args.metadata.ortho_zoom,
- scan_id: args.metadata.scan_id || "outside", //这个"outside"不能随便改成别的
- /* final_angle: 110,
- is_ortho: false, */
- zoom: args.metadata.zoom // fyz zoom是内部计算的zoomLevel, 乘以系数1.06才是实际缩放倍数
- })
- if (renew && target) { // 重新录制导览
- var oldId = target.closest('li')[0].data.sid;
- that.tourAudio[args.sid] = that.tourAudio[oldId]; // 新生成的id指向以前的导览音频
- delete that.tourAudio[oldId]; // 删除导览音频中的旧导览id
- target.closest('li')[0].data = args; // 更新数据
- target.closest('li').find('#tourBg')[0].style.backgroundImage = 'url(' + args.thumbnail_signed_src + ')';
- args.name = $('#tourEdit').find('#tourNameInput').val()//target.text(args.name); // 更新导览列表中的导览名称 //不改名字
- //$('#tourEdit').find('#tourNameInput').val(args.name); // 修改输入框内容
- } else {
- var index = $(".tourList ul li").length + 1;
- var $li = $(editGuide.dom(index, args.name, args.thumbnail_signed_src));
- $li[0].data = args;
- $(".tourList ul").append($li);
- }
- }
- })
- }
- /* -- 以下是一些公用的方法 -- */
- //限制大小
- var restrictedSize = function (file, _size) {
- //限制大小不大于8m
- var fileSize = 0;
- var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
- if (isIE && !file) {
- var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
- var _file = fileSystem.GetFile(filepath);
- fileSize = _file.Size;
- } else {
- fileSize = file.size;
- }
- var size = fileSize / 1024;
- var RSize = _size * 1024;
- if (size > RSize) {
- alert("文件不能大于" + _size + "M");
- return false;
- }
- if (size <= 0) {
- alert("文件大小不能为0M!");
- return false;
- }
- return true
- }
- //上传音乐
- var uploadMiuse = function (file, callback) {
- if (!/audio\/\w+/.test(file.type)) {
- alert("文件必须为音乐!");
- return false;
- }
- //限制大小不大于8m
- if (!restrictedSize(file, _musicMaxWeight)) {
- return false
- }
- uploadFile(file, 'audio', callback);
- }
- $(".toolRight .music .itemTitle span").text(`背景音乐 (<${_musicMaxWeight}M)`)
- //上传图片
- function uploadImg(urlData, callback) {
- //console.log('urlData',urlData);
- var bytes = window.atob(urlData.split(',')[1]); //去掉url的头,并转换为byte
- //处理异常,将ascii码小于0的转换为大于0
- var ab = new ArrayBuffer(bytes.length);
- var ia = new Uint8Array(ab);
- for (var i = 0; i < bytes.length; i++) {
- ia[i] = bytes.charCodeAt(i);
- }
- var blob = new Blob([ab], { type: 'image/jpeg', });
- uploadFile(blob, 'hot/images', callback);
- }
- //上传文件
- function uploadFile(file, type, callback) {
- $(".edit-loading").removeClass("hide");
- var formData = new FormData()
- formData.append('name', number)
- formData.append('dir', type)
- formData.append('random', true)
- formData.append('file', file, getRandomSid()+".jpg")
-
- /*
- var blob = dataURLtoBlob(fileObj.file);
- form.append("file", blob, fileObj.name);
- } else {
- if (fileObj.isBlob) {
- console.log('上传的文件:' + fileObj.name)
- form.append("file", fileObj.file, fileObj.name);
- } else {
- var file = fileObj.file;
- form.append("file", file, fileObj.name);
- } */
- $.ajax({
- url: ceshi + '/manage/scene/upload/'+number,
- data: formData,
- headers:{
- token:token
- },
- dataType: 'json',
- type: 'POST',
- cache: false,//上传文件无需缓存
- processData: false,//用于对data参数进行序列化处理 这里必须false
- contentType: false, //必须
- success: function (rs) {
- if (rs.code === 5001) {
- alert('请重新登录')
- localStorage.dcj_token = ''
- location.reload()
- }
- callback(rs, file);
- $(".edit-loading").addClass("hide");
- }
- })
- }
- function _animate(prevRect, target) {
- var ms = 300;
- if (ms) {
- var currentRect = target.getBoundingClientRect();
- if (prevRect.nodeType === 1) {
- prevRect = prevRect.getBoundingClientRect();
- }
- _css(target, 'transition', 'none');
- _css(target, 'transform', 'translate3d(' +
- (prevRect.left - currentRect.left) + 'px,' +
- (prevRect.top - currentRect.top) + 'px,0)'
- );
- target.offsetWidth; // 触发重绘
- //放在timeout里面也可以
- // setTimeout(function() {
- // _css(target, 'transition', 'all ' + ms + 'ms');
- // _css(target, 'transform', 'translate3d(0,0,0)');
- // }, 0);
- _css(target, 'transition', 'all ' + ms + 'ms');
- _css(target, 'transform', 'translate3d(0,0,0)');
- clearTimeout(target.animated);
- target.animated = setTimeout(function () {
- _css(target, 'transition', '');
- _css(target, 'transform', '');
- target.animated = false;
- }, ms);
- }
- }
- //给元素添加style
- function _css(el, prop, val) {
- var style = el && el.style;
- if (style) {
- if (val === void 0) {
- if (document.defaultView && document.defaultView.getComputedStyle) {
- val = document.defaultView.getComputedStyle(el, '');
- } else if (el.currentStyle) {
- val = el.currentStyle;
- }
- return prop === void 0 ? val : val[prop];
- } else {
- if (!(prop in style)) {
- prop = '-webkit-' + prop;
- }
- style[prop] = val + (typeof val === 'string' ? '' : 'px');
- }
- }
- }
- function upload($files, type, cb) {
- var length = $files.length
- var rcount = 0
- var result = []
- Array.from($files).forEach(function (dFile) {
- //a 标签的success 是用来判断是否是已经上传过的文件
- //attr-thum 属性是视频的图片
- //videoURL 是判断是否有视频
- var $file = $(dFile)
- var $image = $file.find('img')
- if ($file.hasClass('success')) {
- if ($file.attr('attr-thum')) {
- result.push($file.attr('attr-thum'))
- } else if ($image.attr('videoURL')) {
- result.push($image.attr('videoURL'))
- } else {
- result.push($image.attr('src'))
- }
- return success(++rcount);
- } else {
- switch ($file[0].localName) {
- case "input":
- dFile = $file[0]
- break;
- case "span":
- dFile = $file.find('input')[0];
- break;
- case "a":
- dFile = $file.find('input')[0];
- break;
- default:
- dFile = $file.closest("li").find('.upload input')[0];
- break;
- }
- // dFile = $file[0].localName === "input" ? $file[0] : $file[0].localName === "span" ? $file.find('input')[0] : $file.closest("li").find('.upload input')[0];
- }
- var file = (dFile.files && dFile.files[0]) || '';
- if (!file) return success(++rcount);
- uploadFile(file, 'hot/' + type, function (rs) {
- if (rs.code === 0) {
- result.push(rs.data)
- };
- success(++rcount);
- })
- })
- //判断当前队列元素是否处理成功
- function success() {
- if (rcount === length) {
- cb(result)
- }
- }
- success()
- }
- function getIndex(el) {
- let index = 0;
- if (!el || !el.parentNode) {
- return -1;
- }
- while (el && (el = el.previousElementSibling)) {
- index++;
- }
- return index;
- }
- dataURLtoBlob = function (dataurl) {//将base64转换blob
- var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
- bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
- while (n--) {
- u8arr[n] = bstr.charCodeAt(n);
- }
- return new Blob([u8arr], { type: mime });
- };
- //=========================
- var eachMaxWeights = {//大小限制
- "photo": 10,
- "video": 50,//20,
- "audio": 10//5
- }
- var supportTypes = {//支持后缀
- "photo": ["jpg", "png", "jpeg", "bmp", "gif"],
- "audio": ["mp3", "aac", "ogg", "wav"/* , "m4a" */],
- "video": ["mp4", "mov" /* ,"webm", "rmvb", "wmv" */] //ios:mov
- }
- function getExt(name) { //后缀
- if (name.indexOf('.') > -1) {
- var a = name.split(".");
- return a.pop();
- } else {
- return '';
- }
- }
- function detectType(fileName) { //检测文件后缀类型
- console.log("名:" + fileName)
- var ext = getExt(fileName);
- console.log("后缀:" + ext)
- //不一定所有浏览器都可以
- var type;
- //仅能根据后缀判断类型,尽管后缀可能被修改。 其他方法如file.type和base64开头的字符串均是根据后缀。
- for (var i in supportTypes) {
- if (supportTypes[i].indexOf(ext.toLowerCase()) > -1) {
- type = i;
- break;
- }
- }
- if (type) {
- return type;
- } else {
- return false;
- }
- }
- //手机上的相片会不会太大?
- var detectWeights = function (file, type) {
- //检测大小
- var size = file.size / 1024 / 1024; console.log("weight" + size)
- var over;
- if (size > eachMaxWeights[type]) {
- over = Math.ceil(size * 100) / 100;
- }
- return over;
- }
- var exitUpload = function (input) {
- $('.waiting').removeClass('showloading');
- input.value = "";
- }
- var inputMedia = function (options, type, e) {
-
- var input = e.target;
- if (!window.FileReader) {
- alert('您的浏览器不支持上传文件');
- exitUpload(input);
- return;
- } else if (e.target.files.length === 0) {/* exitUpload(input); */return; }
- $('.waiting').addClass('showloading');
- var file = e.target.files[0];
- var elemType = type;
-
- var inputType = detectType(file.name);
-
- var chType = {
- "photo": '图片',
- "video": '视频',
- "audio": '音乐'
- }
-
- var overWeight = detectWeights(file, inputType);
-
- if(elemType){//有指定其中一种类型
- if(inputType != elemType){
- alert("您选择的不是浏览器支持的"+ chType[elemType] + '文件,请重新选择');
- exitUpload(e.target);
-
- return;
- }
- }else{
- if(!options.enableTypes.includes(inputType)){
- var text = "";
- options.enableTypes.forEach((type,index)=>{text += ((index!=0 ? " / ":"") + chType[elemType])})
- alert("您选择的不是浏览器支持的"+ text + '文件,请重新选择');
-
- exitUpload(e.target);
- return;
- }
- }
-
-
- if (overWeight) {
- alert(`文件过大(${overWeight}兆),不能大于${ eachMaxWeights[inputType]} 兆`)
- exitUpload(e.target);
- return;
- }
- var loadError = function () {
- exitUpload(e.target);
- alert(`文件出错, 无法加载此${chType[inputType]}文件。 文件可能损坏,或者浏览器不支持,或者后缀与文件不匹配。建议在IE以外的浏览器上传`)
- }
- deal();
- function deal(fi) {
- console.log('开始deal文件')
- var reader = new FileReader();
- //reader.name = file.name;
- file = fi || file;
- reader.readAsDataURL(file);
- reader.onload = function (evt) {
- var blob = dataURLtoBlob(evt.target.result);
- var blobSrc = window.URL.createObjectURL(blob);
- if (inputType == "photo") {
- /* EXIF.getData(file, function () {
- //获取相片旋转
- EXIF.getAllTags(this);
- var orient = EXIF.getTag(this, 'Orientation');
- var img = new Image();
- img.src = evt.target.result;
- img.onload = function (e) { //这时img才有宽高,才能赋予texture宽高
- var smallerImg = CompressImg(e.target, {
- weight: blob.size,
- maxWeight: 0.5 * 1024 * 1024,
- maxSize: 1480
- });
- //最大500k
- smallerImg.onload = function () {
- var f = function (resultImg) {//处理结束回调
- options.photoDone(resultImg)
- $('.waiting').removeClass('showloading');
- }
- Rotate(smallerImg, orient, f)
- window.URL.revokeObjectURL(blobSrc);
- }
- }
- .bind(this)
- img.onerror = loadError;
- }); */
- var img = new Image();
- img.src = blobSrc;
- img.base64Src = evt.target.result;
- img.onload = function (e) {
- options.photoDone(img)
- $('.waiting').removeClass('showloading');
-
- }
- } else if (inputType == "video") {
- var video = $('<video controls="controls" x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>')[0]
- video.setAttribute("crossOrigin", 'Anonymous')//要在src设置好前解决跨域
- $(video).on('contextmenu', function () { return false; });//禁止右键点击出现选项(尤其是下载选项)
-
- $(video).attr('src', blobSrc); //华为无法使用blobSrc,否则加载不出来
- //$(video).attr('src', evt.target.result);
- video.base64Src = evt.target.result;
-
- var hasload = false;
- var error = false;
-
- var up = function () {
- if (hasload) return;
-
- hasload = true;
- options.videoDone(file, video)
- $('.waiting').removeClass('showloading');
- }
- video.addEventListener('loadeddata', function (e) {
- up()
- })
- //video.onerror = loadError;
- video.onerror = function (e) {
- console.log('error')
- error = true;
-
- loadError();//将mp4改成mov后缀会error
- }
- } else if (inputType == "audio") {
- //林俊波 new Howl For IE&Safari:
- var sound = new Howl({
- src: [blobSrc],
- format: ["mp3"]
- });
- // Clear listener after first call.
- sound.once('load', function () {
- console.log('loaded sound')
- sound.unload()
-
- console.log("audio.onloadeddata");
- var audio = new Audio;
- audio.controls = "controls";
- audio.src = blobSrc;
- audio.base64Src = evt.target.result;
- options.audioDone(file, audio)
-
- $('.waiting').removeClass('showloading');
- //}
- });
- sound.once('loaderror', function () {
- loadError.apply(this, arguments)
- console.log('loaderror sound')
- });
- // Fires when the sound finishes playing.
- sound.on('end', function () {
- console.log('Finished sound');
- });
- }
- }
- }
- e.target.value = ""; //更改value会触发change
- }.bind(player)
-
-
-
-
-
-
-
-
- //滑动条控件
- var SlideBar = function (o) {
- var scope = this;
- this.name = o.name;
- this.value = o.value; //初始值
- this.min = o.min != void 0 ? o.min : 0;
- this.max = this.oriMax = o.max != void 0 ? o.max : 100;
- this.noValue = o.noValue; //是否数值输入
- this.precision = o.precision;//精度 保留几位小数
- var div = $('<div><div class="Main"><div class="scrollBar"><div class="scroll_Track"></div><div class="scroll_Thumb"></div></div>' + (o.noValue ? '' : '<div class="BarTxt"><input class="scrollBarTxt"></div></div>'))
- div.addClass('slider')
- if(o.unitStr){
- div.find(".BarTxt").append($('<span>'+ o.unitStr +'</span>'));
- }
-
- o.root.append(div);
- this.line = $(".scrollBar", div);
- this.knot = $(".scroll_Thumb", div);
- o.noValue || (this.textArea = $(".scrollBarTxt", div));
- this.track = $(".scroll_Track", div);
- this.unitStr = o.unitStr;//unitStr是单位字符串,比如角度的°。不能是数字
- this.onchange = o.onchange;
- this.percent = null;
- this.dragStart = false;
- this.offsetToBody = null;
- this.getOffset();
- this.checkError();
- this.percent = this.getPercent();
- o.noValue || this.displayValue();
- this.moveKnot();
- this.knotWidth = 0;
- this.lineWidth = 0;
- //this.waitValue;//等待要触发事件的值,防止崩溃
- this.avoidCrash = o.avoidCrash;
- this.realMax = !this.noValue ? o.realMax : null;//如果传入realMax,代表可以通过输入数字修改最大值范围,最大值不可以超过realMax。
-
- this.scrollUnit = (scope.max - scope.min) * 0.001;
- if(this.precision != void 0){
- var prec = Math.pow(10,-this.precision);
- this.scrollUnit < prec && (this.scrollUnit = prec);
- }else{//默认化为整数
- this.scrollUnit < 1 && (this.scrollUnit = 1);
- }
-
-
- this.dragStartEvent = o.dragStartEvent;
- this.line.on( "mousedown touchstart", function (event) {
- scope.dragStart = true;
- scope.dragChange(event);
- if(scope.dragStartEvent)scope.dragStartEvent()
- //if(o.avoidCrash && isMobile)scope.dealInterval();
- });
-
- !window.isMobile && this.line.on( "mousewheel DOMMouseScroll wheel", function (event) {
- event.preventDefault();
- var v = event.originalEvent.deltaY>0 ? -scope.scrollUnit : scope.scrollUnit;
- scope.setValue(scope.value + v);
- });
-
-
- this.dragEndEvent = o.dragEndEvent;
- var stop = function(){
- if (scope.dragStart) {
- scope.dragStart = false;
- if(scope.dragEndEvent)scope.dragEndEvent()
- }
- }
-
- $(document).on("mouseup touchend",stop)
- /* isMobile || */$("#player").on("mouseup",stop)
-
- var lastChangeTime = 0;
- $(document).on("mousemove touchmove",function(){
- if (scope.dragStart) {
- /* if(isMobile && o.avoidCrash){
- scope.lastDragEvent = event;
- }else */scope.dragChange(event);
-
- }
- })
-
- o.noValue || this.textArea.on("change", function () {
- var v = parseFloat(scope.textArea.val());
- if (v != v)//NaN
- return;
- scope.setValueFromOutside(v);
- });
- }
- SlideBar.prototype.dealInterval = function(){
- this.interval = setInterval(function(){
- this.lastDragEvent && this.dragChange(this.lastDragEvent);
- this.lastDragEvent = null
- if(!this.dragStart) clearInterval(this.interval)
- }.bind(this),90)
- }
-
- SlideBar.prototype.changeLimit = function (o) {
- if(o.min) this.min = o.min;
- if(o.max) this.max = o.max;
- }
- SlideBar.prototype.getOffset = function () { //为了检测鼠标位置需要获得相对body的offset
- var left = this.line[0].offsetLeft;
- var element = this.line[0];
- while (element = element.offsetParent) {
- left += element.offsetLeft;
- }
- this.offsetToBody = (left == 0) ? (this.offsetToBody || 0) : left;
- //如果left为0,很可能是它不可见,那么最好使用旧的offsetToBody
- }
- SlideBar.prototype.InitOffset = function () {
- //如果一开始scroller没有显示,要在显示时获取一下offset
- this.getOffset();
- this.getWidth();
- this.moveKnot();
- }
- SlideBar.prototype.checkError = function () {
- if (this.min >= this.max) {
- console.log("scrollbar值有误 " + name);
- return;
- }
- }
- SlideBar.prototype.getPercent = function () {
- return (this.value - this.min) / (this.max - this.min);
- }
- SlideBar.prototype.displayValue = function (value) {
- //this.textArea.val(this.value + (this.unitStr ? " " + this.unitStr : ""));
- if(value != void 0)this.value = value;
- this.textArea.val(this.value)
-
- }
- SlideBar.prototype.getWidth = function () {
- this.knotWidth = this.knot.width();
- this.lineWidth = this.line.width() - this.knotWidth
-
- }
- SlideBar.prototype.moveKnot = function () {
- //this.getWidth();
- var width = this.percent * this.lineWidth;
- this.knot.css('left',width + "px")
- if (this.track)this.track.css('width', (width + this.knotWidth / 2) + "px")
-
- }
-
- SlideBar.prototype.bind = function (f) {
- this.onchange = f;
- }
- SlideBar.prototype.setValue = function (v, noEvent, changeMax) {//设置数值并改变knot位置 noEvent为true的话就可以不触发回调函数,仅仅改变显示
- //if(this.value==v)return; //因为换选材质需要执行后面onchange才会带动preview的改变,所以这里一样还是执行,而拉动滑动条的部分值不变就不执行
-
- if(this.precision != void 0){
- this.value = parseFloat(v.toFixed(this.precision))
- }else{//默认化为整数
- this.value = Math.round(v);
- }
- if(changeMax && this.realMax!=void 0){
- if(this.value>this.oriMax){
- this.value = Math.min(this.value, this.realMax);
- this.changeLimit({max:this.value})
- }else{
- this.changeLimit({max:this.oriMax})
- }
- }
-
- this.percent = this.getPercent();
-
- var makeit = true;
- if (this.onchange && !noEvent ){
- var result = this.onchange(this.value); //如果执行的函数不允许这个值,就不能变
- if(result === false){
- makeit = false;
- }
- }
-
- if(makeit){
- this.moveKnot();
- //console.log("SlideBarV-"+this.name + " : "+this.value)
- this.noValue || this.displayValue();
- }
-
-
- }
- SlideBar.prototype.dragChange = function (event) {//拖动时触发 计算数值
- //this.getWidth();
- //if(!this.offsetToBody || isNaN(this.offsetToBody)this.getOffset();
- if (event.clientX != void 0) {
- this.percent = (event.clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
- } else {
- if(event.touches != void 0){
- this.percent = (event.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
- }
- else this.percent = (event.originalEvent.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
- }
- if (this.percent < 0)
- this.percent = 0;
- else if (this.percent > 1)
- this.percent = 1;
- //var v = this.percent * this.max;
- var v = this.percent * (this.max - this.min) + this.min;
- //var v = Math.round(this.percent * this.max * 10)/10; //精度为0.1
- if (this.value == v)
- return;
- this.setValue(v);
- }
- SlideBar.prototype.setValueFromOutside = function (v) { //外面的事件触发的
- if (this.line.width() == 0)
- return;
- //不可见就不执行。
- //v = Math.round(v*10)/10;
- if(this.realMax!=void 0){
- v = THREE.Math.clamp(v, this.min, this.realMax);
- if(v>this.max)this.changeLimit({max:v});
- }else v = THREE.Math.clamp(v, this.min, this.max);
- this.setValue(v);
- }
-
- //-----------------------------------------------------
-
-
-
-
-
-
- var LineDraw = {
-
- createLine: function (posArr, o) {
- var e = new THREE.BufferGeometry
- , p = new Float32Array(6);
- e.addAttribute("position", new THREE.BufferAttribute(p, 3));
- //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
- var p = e.attributes.position.array;
- for (var i = 0; i < 2; i++) {
- p[i * 3] = posArr[i].x;
- p[i * 3 + 1] = posArr[i].y;
- p[i * 3 + 2] = posArr[i].z;
- }
- var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
- linewidth: o.width || 1,
- //windows无效。 似乎mac/ios上粗细有效 ?
- color: o.color || defaultColor,
- transparent: o.dontAlwaysSeen ? false : true,
- depthTest: o.dontAlwaysSeen ? true : false
- })
- var line = new THREE.Line(e, mat);
- line.renderOrder = o.renderOrder || 4
- //同tagStem; //如果不加高,可能会部分被model遮住
- return line;
- }
- }
-
-
- var toPrecision = function(e, t) {
- function i(e, t) {
- var i = Math.pow(10, t);
- return Math.round(e * i) / i
- }
- if (e instanceof Array) {
- for (var n = 0; n < e.length; n++)
- e[n] = i(e[n], t);
- return e
- }
- return i(e, t)
- }
- var transformControls;
- var initTransformCtl = function(THREE){
-
- TransformControls.init(THREE)
- TransformControls.prototype.transCtlChangeMode = function(mode){
- //if(!this.editing)return;
- if(mode && this.mode != mode){
- this.mode = mode;
- $(".MenuOptions[name='transform'] li").removeClass("chosen");
- $(".MenuOptions[name='transform'] li[index='"+ mode +"']").addClass("chosen");
- }
- },
-
-
-
- transformControls = new TransformControls( player.camera, player.domElement, {
- player:player,
- dontHideWhenFaceCamera:true,
- scaleAxis:["x","y"], //隐藏了z轴。虽然参数没用上
- NoScaleZ:true//整体缩放时只缩放xy轴。
- });
- transformControls.setSize(1.5)
- player.model.add(transformControls)
-
-
- $(".MenuOptions[name='transform'] li").on("click",(e)=>{
- transformControls.transCtlChangeMode($(e.target).attr("index"))
- })
-
-
- }
- var EditOverlay = {
- editing: false,
- overlayMaxCount: 10,
- scroller:{
- videoDepth : new SlideBar({
- root: $('#videoDepth').eq(0),
- value: settings.overlay.depth * 100,
- min: 0 * 100,
- max: 1 * 100,
- name: "videoDepth",
- unitStr:"cm",
- avoidCrash:true,
- onchange:function (s) {
- if(s == 0){
- EditOverlay.editPlane.addBox(false)
- }else{
- EditOverlay.editPlane.addBox(true)
- EditOverlay.editPlane.scale.z = s/100 / settings.overlay.depth ;
- }
- },
- dragEndEvent:function(){
-
- }
- })
- },
- init: function(THREE){
- var mat = new THREE.MeshBasicMaterial({wireframe:true, opacity:0.5, color:"#57e4f3", transparent:true})
- var wireframeModel = this.wireframeModel = new THREE.Object3D; wireframeModel.name = 'wireframeModel'
- player.model.chunks.forEach((mesh)=>{
- var chunk = mesh.clone();
- chunk.material = mat;
- wireframeModel.add(chunk)
- })
- wireframeModel.visible = false
- player.model.add(wireframeModel)
- //------------------------------
-
- $('.overlay .addBtn button').on("click",this.beginToAddPlane.bind(this))
- $("#overlayProp a.close").on("click",()=>{this.closeOverlayPanel("cancel")})
-
- $("#overlayProp button.submit").on("click",(e)=>{
- this.SaveOverlay()
- })
- $("#overlayProp button.delete").on("click",(e)=>{
- this.DeleteOverlay();
- })
-
- $('#overlayUpload [name="useImgRatio"] button').on("click", this.useImgRatio.bind(this));
-
-
-
- var uploadInput = $('<input type="file" style="display:none" accept="video/*"></input>');
- $('#overlayUpload [name="upload"] button').on('click',()=>{
- uploadInput.click()
- })
-
- uploadInput.on("change", (e)=>{
- inputMedia({
- enableTypes:[/* "photo", */"video"],
- videoDone:(file, video)=>{
- var plane = this.editPlane.plane
- $(video).css('width','100%')
- $(video).css('height','100%')
- plane.material.map = new THREE.VideoTexture( video );
- plane.material.map.image.play();
- plane.material.map.minFilter = THREE.LinearFilter;
-
- this.editPlane.overlayType = "video";
- $('#overlayUpload .preview video').remove();
- //$('#overlayUpload .preview').css('background-image',"").append($(video));
- video.autoplay = true;
- video.loop = true;
- video.volume = 0
- video.muted = true
- this.useImgRatio() //自适应比例
- this.editPlane.file = file;
- plane.material.opacity = 1;
- plane.material.color = new THREE.Color(1,1,1)
- plane.material.needsUpdate = true;
-
-
- }
- }, "video", e);
- })
-
- player.overlayGroup.children.forEach((overlay)=>{
- this.getOverlayInfo(overlay)
- this.addToList(overlay)
- })
- },
- enter : function(){
- this.editing = true;
- this.wireframeModel.visible = true;
- },
- leave : function(){
- if(!this.editing)return;
- this.editing = false
- $("#overlayProp a.close").click();
- this.endAddPlane();
- this.wireframeModel.visible = false;
- },
- beginToAddPlane: function(){
- player.reticule.visible = false;
- this.objCursorType = 'overlay';
- player.currentCursor = 'url(images/edit/box_video.png), auto'
- $('#player').css('cursor', player.currentCursor)
- $('.overlay .addBtn button').addClass("unable")//可以加多个视频时的按钮
-
- },
- endAddPlane : function(){
- this.objCursorType = null;
- player.currentCursor = '';
- $('#player').css('cursor','')
- $('.overlay .addBtn button').removeClass("unable")
- player.reticule.visible = true
- },
-
-
- addPlane : function(o){
- var pos = o.intersect.point;
- var overlay = new Overlay({sid:new Date().getTime()+""})
- overlay.position.copy(pos);
- if(player.getMouseDirection().angleTo(o.intersect.face.normal) < Math.PI/2) {
- overlay.lookAt(o.intersect.face.normal.clone().negate().add(pos));
- overlay.position.add(o.intersect.face.normal.clone().negate().multiplyScalar(0.01))//avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
- }else{
- overlay.lookAt(o.intersect.face.normal.clone().add(pos));
- overlay.position.add(o.intersect.face.normal.clone().multiplyScalar(0.01))
- }
- overlay.isNew = true
- player.clickOverlay(overlay)
- transformControls.transCtlChangeMode("translate")
- this.addToList(overlay)
-
- },
-
-
-
- updateOverlayScaleDisplay : function(){
- var overlay = this.editPlane;
- var maxWidth = 193, maxHeight = maxWidth//maxWidth/2;
- var ratioW = Math.abs(overlay.width) / maxWidth;
- var ratioH = Math.abs(overlay.height) / maxHeight;
- var ratio = 1/Math.max(ratioW,ratioH);//缩放比例
- var w = Math.round(Math.abs(overlay.width)*ratio)
- var h = Math.round(Math.abs(overlay.height)*ratio)
- $('#overlayUpload .preview').css({
- "width": w + 'px',
- "height": h + 'px',
- });
- $('#overlayUpload .preview [attr-type="width"]').text(toPrecision(overlay.width, 2))
- $('#overlayUpload .preview [attr-type="height"]').text(toPrecision(overlay.height, 2))
-
- }
- ,
- updateOverlayPanel : function(overlay){
- this.editPlane = overlay;
- var plane = overlay.plane
- var src = plane.material.map && plane.material.map.image.src;
- $('#overlayUpload .preview video').remove();
- if(overlay.overlayType == "video"){
- var video = plane.material.map.image
- $('#overlayUpload .preview').css('background-image',"").append(video);
- }else{
- $('#overlayUpload .preview').css({
- 'background-image': src ? ("url(" + src + ")") : ""
- })
- }
- if(overlay.overlayType){
- $('#overlayUpload [name="useImgRatio"]').removeClass("hide")
- $('#overlayUpload .preview').addClass('uploaded')
- }else{
- $('#overlayUpload [name="useImgRatio"]').addClass("hide")
- $('#overlayUpload .preview').removeClass('uploaded')
- }
-
- this.updateOverlayScaleDisplay()
-
-
- if(overlay.hasBox){
- this.scroller.videoDepth.setValue(overlay.scale.z * settings.overlay.depth * 100,true)
- }else{
- this.scroller.videoDepth.setValue(0,true)
- }
- setTimeout(()=>{
- this.scroller.videoDepth.InitOffset()
- },201)
- }
- ,
-
-
-
- closeOverlayPanel : function(type){
- if(!this.editPlane)return;
-
- if(type == 'cancel'){
- if(!this.editPlane.isNew && !this.editPlane.needDelete)this.editPlane.setFromInfo(this.editPlane.info) //this.setOverlayFromInfo(this.editPlane, this.editPlane.info);//恢复
- else this.disposeOverlay(this.editPlane); //删除
- }
-
- this.editPlane = null;
- transformControls.detach()
- $("#overlayProp").addClass("atRight");
- //if(player.model.overlayPlanes.length < this.overlayMaxCount) this.beginToAddPlane()
-
- }
- ,
- useImgRatio : function(o){
- var plane = this.editPlane.plane;
- if(!plane.material.map)return;
- var img = plane.material.map.image;
- var mintranRatio = 200;//default is 200 , 防止图片太小时在墙上依旧很大
- var width = this.editPlane.overlayType == "video" ? img.videoWidth : img.width;
- var height = this.editPlane.overlayType == "video" ? img.videoHeight : img.height;
-
- if(o == "suitSize"){
- var boundWidth = Math.min(Math.max(width,height)/mintranRatio, 1)
- if(width > height){
- var w = boundWidth;
- var h = boundWidth * height / width
- }else{
- var h = boundWidth;
- var w = boundWidth * width / height;
- }
- }else{
- //假设不变总面积
- var k = Math.sqrt(Math.abs(this.editPlane.width * this.editPlane.height) / (width * height))
- var w = k * width * (this.editPlane.width<0?-1:1);
- var h = k * height * (this.editPlane.height<0?-1:1);
-
- }
-
- this.editPlane.scale.setX(w/settings.overlay.width)
- this.editPlane.scale.setY(h/settings.overlay.height)
- this.editPlane.width = w;
- this.editPlane.height = h;
-
- this.updateOverlayPanel(this.editPlane)
- },
-
-
-
- getOverlayInfo : function(overlay){
- //2 编辑前, 从当前状态获取info
- var plane = overlay.plane;
- overlay.info = {
- width: overlay.width,
- height: overlay.height,
- depth: settings.overlay.depth * overlay.scale.z,
- pos: overlay.position.clone(),
- qua: overlay.quaternion.clone(),
- media: plane.material.map.image,
- file: overlay.file,
- type: overlay.overlayType,
- hasBox: overlay.hasBox
- }
- }
- ,
-
-
- getSavingInfo : function(overlay){
-
-
- if(!overlay.file && (!overlay.plane.material.map ||!overlay.plane.material.map.image)){
- return;
- }
-
- var info = {
- width: toPrecision(overlay.width, 4),
- height: toPrecision(overlay.height, 4),
- depth: toPrecision(settings.overlay.depth * overlay.scale.z, 4),
- pos: toPrecision(overlay.position.toArray(),4),
- qua: toPrecision(overlay.quaternion.toArray(),4),
- sid: overlay.sid,
- hasBox: overlay.hasBox ? 1 : 0,
- media: [overlay.overlayType],
-
- file: overlay.fileSrc || overlay.plane.material.map.image.src
- }
-
- return info
-
- },
-
-
-
-
- SaveOverlay : function(){
- var overlay = this.editPlane;
- if(!overlay.file && (!overlay.plane.material.map ||!overlay.plane.material.map.image)){
- alert("请上传视频");return;
- }
-
- var saveInfo = ()=>{
- //overlay.savingInfo = JSON.stringify(info)//准备写入的info
- //saveDone:
- overlay.isNew = false;
-
-
- this.getOverlayInfo(overlay);
-
- this.closeOverlayPanel()
-
- $('.waiting').removeClass('showloading');
-
-
- }
- if(!overlay.info || overlay.file != overlay.info.file){
- $('.waiting').addClass('showloading');
- uploadFile(overlay.file, 'overlay', function (rs) {
- if (rs.code === 0) {
- overlay.fileSrc = rs.data;
- saveInfo()
- };
- } )
-
- }else saveInfo();
-
-
- }
- ,
-
-
- disposeOverlay : function(overlay){
- var plane = overlay.plane
- if(overlay == player.hoveringPlane){
- player.hoverOverlay(null,"soon");
- }
- if(plane.material.map){//删除视频src
- //overlay.info && common.destroyBlob(overlay.info.media.src)
- //common.destroyBlob(plane.material.map.image.src)
- }
- plane.material.dispose();
- overlay.parent.remove(overlay);
- this.removeFromList(overlay)
-
- //this.beginToAddPlane()
-
- }
- ,
- DeleteOverlay : function(){
- var overlay = this.editPlane;
-
- if(!overlay.isNew){
- if(confirm("确定删除该视频?")){
- overlay.needDelete = true;
- $("#overlayProp a.close").click()//this.closeOverlayPanel()
- }
- }else{//刚创建时的删除按钮等同于取消按钮
- $("#overlayProp a.close").click()//this.closeOverlayPanel()
- }
- }
- ,
- addToList : function(overlay){
- var li = $(`<li><div class="icon"></div><div class="title">${overlay.sid}</div></li>`)
- $(".overlayList ul").append(li);
- li.on("click",()=>{
- player.clickOverlay(overlay)
- })
- overlay.domLi = li;
- },
- removeFromList : function(overlay){
- overlay.domLi.remove();
-
- }
-
-
- }
- //----------------漫游可见性---------------------------------
-
- var panoVisiSet = {
-
-
- setPanoVisible : false,
- //漫游可见性
-
- panoVLines : {},//线条
- panoVTemp:null, //修改后还没保存的临时数据
- //热点可见性
- $confirmSnap : $("#camera-start"),
- colors:{green: "#00c8ae"},
- init : function(){
- this.meshGroup = new THREE.Object3D; this.meshGroup.name = "setVisible-group"
- player.model.add(this.meshGroup)
- },
- beginSetPanoVisible : function () {
- if (this.setPanoVisible ) return;
- $(".toolLeft").removeClass("unable")
- this.setPanoVisible = true;
- this.panoVTemp = {};
-
- this.SetOnePanoVisible(player.currentPano)//先设置currentPano
-
-
- this.$confirmSnap.text('保存当前设置').removeClass("hide")
-
- //objects.tagManager.hideAllTags();
-
-
- this.updateFootIconSize()//更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
- },
- SetOnePanoVisible : function (pano) { //点击某个pano后就对该pano点进行设置
- if (this.panoVsetting == pano) return;
- //if (this.panoVsetting) saveLastPanoVi(this.panoVsetting);
- this.panoVsetting = pano; //记录正在修改的
- this.delVisibleLines(); //删除线
- this.showFootIcons(pano, true);
- this.createPanoVisiLines(pano); //创线
-
-
-
-
- },
- saveLastPanoVi : function () { //保存刚设置过的pano
- var change = [];
- for (var r in this.panoVLines) {
- var line = this.panoVLines[r];
- if (line.name.indexOf("new") > -1 && line.visible) { //新设置为visible且没有取消
- change.push({
- type: "add",
- id: r
- })
- } else if (line.name.indexOf("new") == -1 && !line.visible) { //旧的且已经取消
- change.push({
- type: "sub",
- id: r
- })
- }
- }
- if (change.length) { //添加双向的neighbour:
- var self = this.searchNeib(this.panoVsetting.id)
- //var seeMarkers_self = self.seeMarkers;
- var neighbourUUIDs_self = self.neighbourUUIDs
- var neighbourPanos_self = self.neighbourPanos;
- for (var i = 0; i < change.length; i++) {
- var other = this.searchNeib(change[i].id)
- //var seeMarkers = other.seeMarkers;
- var neighbourUUIDs = other.neighbourUUIDs;
- var neighbourPanos = other.neighbourPanos;
- if (change[i].type == "add") {
- //seeMarkers.push(this.panoVsetting.id);
- neighbourUUIDs.push(this.panoVsetting.id);
- neighbourPanos[this.panoVsetting.id] = true;
- //seeMarkers_self.push(change[i].id);
- neighbourUUIDs_self.push(change[i].id);
- neighbourPanos_self[change[i].id] = true;
- } else {
- //var index = seeMarkers.indexOf(this.panoVsetting.id);
- //index > -1 && seeMarkers.splice(index, 1);
- var index = neighbourUUIDs.indexOf(this.panoVsetting.id);
- index > -1 && neighbourUUIDs.splice(index, 1);
- neighbourPanos[this.panoVsetting.id] = false;
- //var index = seeMarkers_self.indexOf(change[i].id);
- //index > -1 && seeMarkers_self.splice(index, 1);
- var index = neighbourUUIDs_self.indexOf(change[i].id);
- index > -1 && neighbourUUIDs_self.splice(index, 1);
- neighbourPanos_self[change[i].id] = false;
- }
- this.panoVTemp[change[i].id] = { //后面两个是作为保存到后台的数据存储,临时需要用到的是第一个
- neighbourPanos: neighbourPanos,
- //seeMarkers: seeMarkers,
- neighbourUUIDs: neighbourUUIDs
- }
- }
- this.panoVTemp[this.panoVsetting.id] = {//加上自己
- neighbourPanos: neighbourPanos_self,
- //seeMarkers: seeMarkers_self,
- neighbourUUIDs: neighbourUUIDs_self
- }
-
- }
- },
- pauseSetPanoVisible : function (type) { //暂停 因为点击了保存设置 但没有退出设置
- if (!this.setPanoVisible) return;
- if(type == "unsaved"){//中途点击pano从而停止一个热点的设置
- this.saveLastPanoVi();
- }else{
- this.panoVTemp = {}; //清空数据
- }
- this.delVisibleLines();
- this.showFootIcons();//清空选择
- var lastPanoSetting = this.panoVsetting;
- this.panoVsetting = null;
- lastPanoSetting && this.changeFIconState2(lastPanoSetting.footIcon, this.checkHasNeighbor(lastPanoSetting))//这句要放在this.panoVsetting = null后。 根据可见性更改透明度
-
-
- },
- //按理说改变了neighbourPano,tag的初始visible也要改。但是这样还要考虑已经改过的tag。。很麻烦
- finishSetPanoVisible : function () { //结束 退出这个设置
- if (!this.setPanoVisible)
- return; //否则会加多个侦听
- this.setPanoVisible = false;
- this.hideFootIcons();
- this.delVisibleLines();
-
- //objects.tagManager.showAllTags();
- this.recoverAllState2();
- this.panoVsetting = null;
- this.panoVTemp = {};
- player.flyoutType = null
- this.$confirmSnap.addClass("hide")
-
- },
-
- recoverAllState2 : function(){//为了热点可视恢复成pano全部可见
- for (var i = 0; i < this.footIcons.length; i++) {
- this.footIcons[i].material.uniforms.opacity.value = 1;
- this.footIcons[i].material.uniforms.map.value = footTex1;
- }
- },
-
- afterSavePanoVisibles : function(){ //实施:
-
- var panos = player.model.panos;
- for (var i in this.panoVTemp) {
- var pano = panos.index[i];
- //pano.seeMarkers = this.panoVTemp[i].seeMarkers;
- pano.neighbourUUIDs = this.panoVTemp[i].neighbourUUIDs;
- pano.neighbourPanos = this.panoVTemp[i].neighbourPanos;
-
-
- }
- if(!this.checkHasNeighbor(player.currentPano)){//currentPano变为孤立点 就要换一个防止飞入
- var list = panos.sortByScore([pano=>{return this.checkHasNeighbor(pano)}],
- [function(pano){return -pano.position.distanceTo(player.currentPano.position)}])
- if(list && list.length){
- player.currentPano = list[0].pano;//找最近的一非孤立点
- //this.noPanoHasNeighbor = false; //更新状态
- }else{
- //this.noPanoHasNeighbor = true; //更新状态
- }
- }else{
- //this.noPanoHasNeighbor = false; //更新状态
- }
-
-
-
-
-
-
- //dataDeal.done();
- //暂时:
- this.pauseSetPanoVisible()
-
-
-
- this.updateFootIconSize()//更新一下center大小 写在最后
-
- },
- //最佳推荐操作顺序: 先设置pano可见性 再创建热点 这样热点的visible正确些,否则之后再设置热点可见性会改更多
- savePanoVisibles : function () { //保存
- if (this.panoVsetting) this.saveLastPanoVi(this.panoVsetting); //获取最后设置的那个热点的改动
- var PanoData = [];
- for (var i in this.panoVTemp) {
- PanoData.push({//希望算法部不会更改index排序,或者更改后能将visible信息一并更改
- panoID: i,
- //visibles: this.turnToPanoIndex(this.panoVTemp[i].seeMarkers),
- visibles3: this.turnToPanoIndex(this.panoVTemp[i].neighbourUUIDs)
- })
- }
-
-
- if (PanoData.length == 0) {//没改变
- alert("保存成功")
- return;
- }
-
- /* this.afterSavePanoVisibles()
- alert("保存成功")
- console.log(JSON.stringify(PanoData)) */
-
-
- $.ajax({
- method: 'POST',
- url: ceshi + '/manage/scene/roamViable',
- headers:{
- 'Content-Type':'application/json',
- token:token
- },
- contentType:'application/json',
- data: JSON.stringify({
- data: JSON.stringify(PanoData),
- sceneCode: window.number
- }),
- success: (data)=>{
- if (data.code === 0) {
- this.afterSavePanoVisibles()
- alert("保存漫游可行成功")
- }else alert("保存漫游可行失败")
- if (data.code === 5001) {
- alert('请重新登录')
- localStorage.dcj_token = ''
- location.reload()
- }
- },
- fail:function(){
- alert("保存漫游可行失败")
- }
- })
-
-
-
- /* var o = {
- name_t: "panoVisible",
- f: this.pauseSetPanoVisible,
- url: Config.prefixEditProPCApi+"/saveLinkPano",
- dialog: i18n.get('设置'),
- data: { data: JSON.stringify(PanoData) }
- }
-
- var dataDeal = uploadsSaving.saveFucforPC(o);
- dataDeal.group[0] = function () {
- //实施:
- for (var i in player.panoVTemp) {
- var pano = player.model.panos.index[i];
- pano.seeMarkers = player.panoVTemp[i].seeMarkers;
- pano.neighbourUUIDs = player.panoVTemp[i].neighbourUUIDs;
- pano.neighbourPanos = player.panoVTemp[i].neighbourPanos;
- }
- if(!player.model.checkHasNeighbor(player.currentPano)){//currentPano变为孤立点 就要换一个防止飞入
- var list = player.model.panos.sortByScore([function(pano){return player.model.checkHasNeighbor(pano)}],
- [function(pano){return -pano.position.distanceTo(player.currentPano.position)}])
- if(list && list.length){
- player.currentPano = list[0].pano;//找最近的一非孤立点
- player.model.noPanoHasNeighbor = false; //更新状态
- }else{
- player.model.noPanoHasNeighbor = true; //更新状态
- }
- }else{
- player.model.noPanoHasNeighbor = false; //更新状态
- }
-
- dataDeal.done();
- player.model.updateFootIconSize(player.cameraControls.activeControl)//更新一下center大小 写在最后
- } */
- },
- searchNeib : function (panoId) {//寻找某pano的相关neighbour 可能是修改过的
- var panos = player.model.panos;
- var o = {};
- if (this.panoVTemp[panoId]) {
- //o.seeMarkers = this.panoVTemp[panoId].seeMarkers;
- o.neighbourUUIDs = this.panoVTemp[panoId].neighbourUUIDs;
- o.neighbourPanos = this.panoVTemp[panoId].neighbourPanos;
- } else {
- //o.seeMarkers = panos.index[panoId].seeMarkers.slice(0);
- o.neighbourUUIDs = panos.index[panoId].neighbourUUIDs.slice(0);
- o.neighbourPanos = CloneObject(panos.index[panoId].neighbourPanos);
- }
- return o;
- },
- turnToPanoIndex : function (panoArr) {
- var panos = player.model.panos;
- var array = [];
- for (var i = 0; i < panoArr.length; i++) {
- var pano = panos.index[panoArr[i]];
- var index = panos.list.indexOf(pano)
- array.push(index);
- }
- return array;
- },
-
- setDisplay : function(state){
- var panos = player.model.panos;
- if(state){
- player.model.panos.forEach((pano)=>{
- if(pano.hasVideo){
- pano.marker.visible = false;
- pano.flagSpot.disc.visible = false;
- pano.flagSpot.markGroup.hide();
- }
- })
- player.model.cadFloorPlane.changeCadVisible(false)
- }else{
- player.model.panos.forEach((pano)=>{
- if(pano.hasVideo){
- pano.marker.visible = true;
- pano.flagSpot.disc.visible = true;
- pano.flagSpot.markGroup.show();
- }
- })
- player.model.cadFloorPlane.changeCadVisible(null,{autoJudge:true})
- }
-
- player.defaultRoomLabels.forEach(function(label){ label.update()})
- player.path.currentPanoMarker.mesh.visible = !state;
- objects.overlayManager.group.visible = !state;
- player.reticule.visible = !state;
-
-
- },
-
-
- delVisibleLines : function () {
- //xzw add 所有线都删除
- for (var i in this.tagsVLines) {
- this.tagsVLines[i].geometry.dispose();
- this.tagsVLines[i].material.dispose();
- this.meshGroup.remove(this.tagsVLines[i]);
- delete this.tagsVLines[i];
- }
- for (var i in this.panoVLines) {
- this.panoVLines[i].geometry.dispose();
- this.panoVLines[i].material.dispose();
- this.meshGroup.remove(this.panoVLines[i]);
- delete this.panoVLines[i];
- }
- },
- //--------panoVisible
- createPanoVisiLines : function (pano) {
- // pano可见性线条
- var neighbours = this.panoVTemp[pano.id] && this.panoVTemp[pano.id].neighbourPanos || pano.neighbourPanos;
- for (var r in neighbours) {
- if (neighbours[r] && r != pano.id) {
- this.createPanoSingleLine(pano, "old", r)
- }
- }
- },
- createPanoSingleLine : function (pano, type, id) {//pano是中心
- var panos = player.model.panos;
- var p2 = panos.index[id].floorPosition.clone()/* .sub(player.model.position) */
- var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */, p2], {
- color: this.colors.green
- });
- this.meshGroup.add(line);
- line.name = "PanoVL-" + type + "-" + id;
- this.panoVLines[id] = line;
- this.changeFIconState(panos.index[id].footIcon, "linked")
- },
-
- dealPanoVisible : function (id) { //外部调用
- var panos = player.model.panos;
- if (this.panoVsetting) {
- if (id == this.panoVsetting.id) {//关闭当前pano设置
- this.pauseSetPanoVisible('unsaved')
- }else{
- var link;//结果是否连接
- if(this.panoVLines[id]){
- this.panoVLines[id].visible = !this.panoVLines[id].visible;
- link = this.panoVLines[id].visible;
- this.changeFIconState(panos.index[id].footIcon, this.panoVLines[id].visible?"linked":false)
- }else{
- this.createPanoSingleLine(this.panoVsetting, "new", id)
- link = true;
- }
- if(link){//如果连接上了,直接判断该点是可见的(有附近点),(不能通过checkHasNeighbor来判断,因为新增的线条可能不在它的neighbour中
- this.changeFIconState2(panos.index[id].footIcon, true)
- this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, true)
- }else{//否则需要checkHasNeighbor
- this.changeFIconState2(panos.index[id].footIcon, this.checkHasNeighbor(panos.index[id]))
- this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, this.checkHasNeighbor(this.panoVsetting))
- }
- }
- }else {//点击开始设置要设置的pano
- this.SetOnePanoVisible(panos.index[id])
- }
- this.updateFootIconSize()
-
- },
-
-
- showFootIcons : function (pano, isPanovisible) {
- if (!this.footIcons) {
- footTex1 = Texture.load("images/edit/End_128.png"); //Store.FootIcon);
- footTex2 = Texture.load("images/edit/End_unable_128.png"); //Store.FootIcon_unable);
- this.footIcons = [];
- var scale = 0.4;
- scale *= 40 / Math.sqrt(Math.min($("#player").width(), $("#player").height()));//屏幕越小,放得越大
- scale = THREE.Math.clamp(scale, 0.3, 0.7)
- //console.log("scale"+scale)
- var geo = new THREE.PlaneGeometry(scale, scale, 1, 1)
- var panos = player.model.panos;
- for (var r in panos.index) {
- var t = THREE.UniformsUtils.clone(shaders.waypoint.uniforms);
- t.map.value = footTex1
- t.color.value.set("#ffffff");
- var mat = new THREE.RawShaderMaterial({
- vertexShader: shaders.waypoint.vertexShader,
- fragmentShader: shaders.waypoint.fragmentShader,
- uniforms: t,
- side: THREE.DoubleSide,
- transparent: !0,
- depthWrite: !1,
- depthTest: false,
- name: "footIcon"
- })
- var foot = new THREE.Mesh(geo, mat)
- foot.position.copy(panos.index[r].floorPosition.clone()/* .sub(player.model.position) */)
- foot.lookAt(foot.position.clone().add(new THREE.Vector3(0, 1, 0)));
- foot.name = panos.index[r].id;
- foot.visible = false;
- foot.renderOrder = 6,
- panos.index[r].footIcon = foot;
- this.meshGroup.add(foot);
- this.footIcons.push(foot)
- }
- }
- for (var i = 0; i < this.footIcons.length; i++) {
- this.footIcons[i].visible = true;
- this.changeFIconState(this.footIcons[i], false)
- var panos = player.model.panos;
- if(isPanovisible){
- this.changeFIconState2(this.footIcons[i], this.checkHasNeighbor(panos.index[this.footIcons[i].name], "showFoot"))
- }
-
-
- if (pano && (this.footIcons[i].name == pano.id)) {
- //pano为中心 或者 currentPano 所以放大一点
- this.footIcons[i].oriScale = new THREE.Vector3(1.5, 1.5, 1.5)
- if (isPanovisible) {
- //currentPano特殊些:
- this.changeFIconState(this.footIcons[i], "center")
- //this.footIcons[i].Unclick = true;//不让点击和hover
- }
- } else {
- this.footIcons[i].oriScale = new THREE.Vector3(1, 1, 1)
- }
- }
- },
- checkHasNeighbor : function(pano, state){ //检查当前状态pano点是否有可通行点
- var neighbours = this.panoVTemp && this.panoVTemp[pano.id] ? this.panoVTemp[pano.id].neighbourPanos : pano.neighbourPanos;
-
- if(state != "showFoot" && pano == this.panoVsetting){//是中心点的话。state == "showFoot"代表是showFootIcon时, 这时候线还没创建,无法用线判断中心点有几个相邻点,直接用neighbourPanos
- for(var i in this.panoVLines){
- if(this.panoVLines[i].visible){
- return true; //有一条线即可
- }
- }
- return;
- }
-
- for(var i in neighbours ){
- if(i == pano.id)continue;
- if(neighbours[i]){
- if(this.panoVsetting && this.panoVsetting.id == i && this.panoVLines[pano.id] && !this.panoVLines[pano.id].visible) continue;
- return true;
- }
- }
- return false;
- },
- /* ifAllPanoNoNeighbor : function(){//检查是否全是孤立点
- var panos = player.model.panos;
- for(var i in panos.index){
- if(this.checkHasNeighbor(panos.index[i])){
- return false;
- }
- }
- this.noPanoHasNeighbor = true;
- return true;//是全部没有neighbour
- }, */
- changeFIconState : function (footIcon, state) {
- var color = state == "linked" ? this.colors.green :(state == "center" ? /* "#d7f244" */ "#d5f12e": "#ffffff") ;
- footIcon.material.uniforms.color.value.set(color)
- },
- changeFIconState2 : function(footIcon, state){//是可见点还是不可见点
- if(state){
- footIcon.material.uniforms.map.value = footTex1;
- if(this.panoVsetting){
- if(this.panoVsetting.id != footIcon.name){
- footIcon.material.uniforms.opacity.value = 1;
- }else{
- //this.changeVisiBtnState(true)
- }
- }
- }else{//不可见
- footIcon.material.uniforms.map.value = footTex2;
- if(!this.panoVsetting || this.panoVsetting.id != footIcon.name){//非中心点时
- footIcon.material.uniforms.opacity.value = 0.5;
- }else{//变为中心点时
- footIcon.material.uniforms.opacity.value = 1;
- //this.changeVisiBtnState(false)
- }
- }
- },
-
-
- hideFootIcons : function () {
- if (!this.footIcons) return;
- for (var i = 0; i < this.footIcons.length; i++) {
- this.footIcons[i].visible = false;
- }
- },
- updateFootIconSize : function () {//根据相机位置 改变footIcon大小,使在范围内看到的热点大小一致,防止太小点击不到
- if (!this.footIcons) return;
- var s = player.cameraControls.controls.floorplan.absoluteScale * 2.8;
- s = THREE.Math.clamp(s, 0.5, 1.4);
- this.footIcons.forEach(function (f) {
- try{
-
-
- f.scale.copy(f.oriScale).multiplyScalar(s);
-
-
- }catch(e){console.log(e)}
- })
- }
-
- }
- function permitTranMode(state){
- state ? $(".pinBottom.left").removeClass('hide') : $(".pinBottom.left").addClass('hide');
- }
- CloneObject = function (copyObj, result, isSimpleCopy) {//isSimpleCopy只复制最外层
- //复制json result的可能:普通数字或字符串、普通数组、复杂对象
- result = result || {};
- if (copyObj instanceof Array) {
- if (copyObj[0] instanceof Object) {
- //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
- console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
- }
- return copyObj.slice(0);
- //如果是数组,直接复制返回(排除数组内是object
- }
- for (var key in copyObj) {
- if (copyObj[key] instanceof Object && !isSimpleCopy)
- result[key] = CloneObject(copyObj[key]);
- else
- result[key] = copyObj[key];
- //如果是函数类同基本数据,即复制引用
- }
- return result;
- };
- function randomWord(randomFlag, min, max) {//随机字符串
- var str = "",
- range = min,
- arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
- if (randomFlag) { // 随机长度
- range = Math.round(Math.random() * (max - min)) + min;
- }
- for (var i = 0; i < range; i++) {
- var pos = Math.round(Math.random() * (arr.length - 1));
- str += arr[pos];
- }
- return str;
- }
- function getRandomSid() {//5-7位随机字符串 + 6位时间 为热点准备
- var pre = randomWord(true, 5, 7);
- var post = new Date().getTime() + "";
- var len = post.length;
- post = post.substring(len - 8, len - 5) + post.substring(len - 3, len)//其实还是有可能重复的....
- return pre + post;
- }
-
-
- //})();
|