edit.js 182 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354
  1. /* var ceshi = '';
  2. // var ceshi = 'http://192.168.0.135:8105';
  3. // var ceshi = 'http://47.107.252.54:8105';
  4. // var token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInJvbGUiOm51bGwsIm1hbmFnZXIiOm51bGwsImlkIjoxLCJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNTk2NzAxNjAyLCJpYXQiOjE1OTY2MTUyMDIsImp0aSI6Ijk0YjA5YTg1LWViY2ItNDE1Yy04OGVmLWU0MDM1M2UzYmIxYyJ9.Uzi95n0kYXp7bdpY77MdLtTpPL_Fq-jn0tE7gjg6AzA"
  5. var token = window.localStorage.dcj_token
  6. */
  7. var _musicMaxWeight = 8
  8. //M
  9. var cmp = getQueryVariable('cmp') || ''
  10. var _hotNum = 0
  11. function reData(data, type) {
  12. return JSON.stringify(data) == type ? null : data
  13. }
  14. //新编辑界面
  15. var EditTools = function(n) {
  16. //main2018 里面的主要对象
  17. this.n = n;
  18. //当前状态
  19. this.atPanel = null;
  20. //场景信息
  21. this.sceneInformation = new SceneInformation();
  22. //热点
  23. this.hotpoint = new Hotpoint();
  24. //导览
  25. this.editGuide = new EditGuide();
  26. //音乐
  27. this.editMiuse = new EditMiuse();
  28. //初始化界面
  29. //this.init();
  30. this.data = {}
  31. }
  32. EditTools.prototype.loadDone = function(name, data){
  33. this.data[name] = data
  34. if('data' in this.data && 'data2' in this.data){
  35. this.init();
  36. }
  37. }
  38. EditTools.prototype.init = function() {
  39. this.hotpoint.init(/* this.n */);
  40. var that = this;
  41. this.initSaveAll();
  42. this.active();
  43. if(player.mode != 'panorama'){
  44. $(".toolLeft li[data-name=panoVisible]").addClass('unable')
  45. player.once("pano.chosen",()=>{
  46. $(".toolLeft li[data-name=panoVisible]").removeClass('unable')
  47. })
  48. }
  49. that.hotpoint.initTexSelect( this.data.data2.hots);
  50. //创建导览
  51. that.editMiuse.init(this.data.data);
  52. that.sceneInformation.init(this.data.data, this.data.data2)
  53. // fyz 初始化导览需要两部分数据, 其中data2为data.js中的数据
  54. that.editGuide.init(this.data.data, this.data.data2);
  55. $("body").on("click", function() {
  56. $(".DelConfirm").removeClass("active");
  57. })
  58. $(" .MenuOptions li").on("click", (e)=>{
  59. var $elem = $(e.target);
  60. $elem.closest('.MenuOptions').find('li').removeClass("chosen");
  61. $elem.addClass("chosen");
  62. })
  63. }
  64. //点击的时候激活状态
  65. EditTools.prototype.active = function() {
  66. var that = this;
  67. var confirmSnap = $(".confirmSnap.innerBtn");
  68. var snapshotGui = $(".snapshotGui.overlayGui");
  69. $('.toolBottom .toolLeft li').click(function() {
  70. var name = $(this).data("name");
  71. $('.toolLeft li[data-name=' + name + ']').addClass("active").siblings().removeClass("active");
  72. $('.toolRight .' + name).removeClass("hide").siblings().addClass("hide");
  73. if (name == that.atPanel)
  74. return;
  75. console.log(`atPanel ${that.atPanel} name ${name}`)
  76. switch (that.atPanel) {
  77. //退出
  78. case "panoVisible":
  79. VisiSet.finishSetPanoVisible()
  80. break;
  81. case "panoLog":
  82. VisiSet.finishSetPanoLog()
  83. break;
  84. case "screen":
  85. confirmSnap.addClass("hide").removeClass("unable");
  86. snapshotGui.hide();
  87. break;
  88. case "overlay":
  89. EditOverlay.leave()
  90. break;
  91. case "hotpoint":
  92. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click();
  93. VisiSet.finishSetTagVisible()
  94. break;
  95. }
  96. switch (name) {
  97. case "panoVisible":
  98. $(".toolLeft").addClass("unable")
  99. VisiSet.enterSet(VisiSet.beginSetPanoVisible.bind(VisiSet))
  100. break;
  101. case "panoLog":
  102. $(".toolLeft").addClass("unable")
  103. VisiSet.enterSet(VisiSet.beginSetPanoLog.bind(VisiSet))
  104. break;
  105. case "screen":
  106. confirmSnap.removeClass("hide");
  107. $('#camera-start').text("点此设置为初始画面")
  108. snapshotGui.show();
  109. if (player.modeTran.split("-")[1] != "panorama")
  110. $(".confirmSnap").addClass("unable")
  111. break;
  112. case "overlay":
  113. EditOverlay.enter()
  114. break;
  115. }
  116. that.atPanel = name;
  117. /* if(name != "hotpoint"){
  118. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click()
  119. } */
  120. })
  121. //滚动阻止事件
  122. $(".toolRight div.content").on("mousewheel", function(event) {
  123. event.stopPropagation()
  124. });
  125. // 输入框阻止事件
  126. $('.toolRight').on('keydown', function(ev) {
  127. ev.stopPropagation();
  128. })
  129. }
  130. //保存按钮
  131. EditTools.prototype.initSaveAll = function() {
  132. var that = this;
  133. $('#save').on('click', function() {
  134. $(".edit-loading").removeClass("hide");
  135. var $shareImages = $(".information .edit-fun-images a.result");
  136. new Promise(function(resolve, reject) {//分享图
  137. upload($shareImages, 'images', resolve)
  138. }).then(function(imgUrls) {
  139. //导览的数据
  140. var guides = that.editGuide.getSavingInfo()/* Array.from($('.tourFolderList ul li')).map(function(dom) {
  141. return dom.data
  142. }) */
  143. var hots = {}
  144. // 热点数据
  145. var hotLength = 0;
  146. for (let i in player.model.hots) {
  147. let hot = player.model.hots[i];
  148. let hotData = {
  149. position: {
  150. x: toPrecision(hot.position.x, 3),
  151. y: toPrecision(hot.position.y, 3),
  152. z: toPrecision(hot.position.z, 3),
  153. },
  154. //有的定制场景代码是旧的,只能使用rotation,所以不输出quaternion :
  155. rotation: new THREE.Euler().setFromQuaternion(hot.quaternion).toObject(),
  156. isSprite: hot.isSprite ? 1 : 0,
  157. noAction: hot.noAction ? 1 : 0,
  158. linkType: hot.linkType,
  159. actionType: hot.actionType,
  160. infoAttribute: hot.infoAttribute,
  161. order: hotLength++//因为热点保存后在hots里的顺序会被修改,所以使用order来记录顺序
  162. }
  163. if (hot.visiblePanos)
  164. hotData.visiblePanos = hot.visiblePanos
  165. if (hot.hotIconScale)
  166. hotData.hotIconScale = hot.hotIconScale
  167. hotData.transformAtPanos = {}
  168. for(let i in hot.transformAtPanos){
  169. hotData.transformAtPanos[i] = {
  170. pos : toPrecision(hot.transformAtPanos[i].pos.toArray(), 3),
  171. }
  172. if(hot.transformAtPanos[i].qua){
  173. hotData.transformAtPanos[i].qua = toPrecision(hot.transformAtPanos[i].qua.toArray(), 5)
  174. }
  175. }
  176. if (hot.infoAttribute) {
  177. delete hot.infoAttribute.position;
  178. delete hot.infoAttribute.quaternion;
  179. delete hot.infoAttribute.rotation;
  180. delete hot.infoAttribute.transformAtPanos
  181. }
  182. hots[i] = hotData
  183. }
  184. var info = {
  185. name: $('#pjtName').val(),
  186. summary: $('#info-summary').val(),
  187. weixinDesc: $('#weixin-summary').val(),
  188. shareImgUrl: imgUrls[0] || '',
  189. backgroundMusic: $('#query-bgm').attr('href'),
  190. bgName: $(".music .audio.mediaUpload .title").text(),
  191. hoticon: JSON.parse($(".hotStyle-item li.active").attr("data-val")),
  192. camera_start: $('#camera-start')[0].data,
  193. loadlogo: $("#loadlogo").is(':checked'),
  194. special: $("#g_specialScene").is(':checked'),
  195. vision_version: $("#twoData").is(':checked') ? "1.1.562.17209" : false,
  196. /************************************** 方奕卓 场景可配置项 ******************************************/
  197. hotImageScale: $("#hotImgScale").is(':checked'),
  198. // 热点图片可放大
  199. hideFloorMarker: $("#hideFloorMarker").is(':checked'),
  200. // 地面标记
  201. hideMouseMarker: $("#hideMouseMarker").is(':checked'),
  202. showingLabels: $("#showingLabels").is(':checked'),
  203. // 鼠标标记
  204. floorMarkerColor: $('#floorMarkerColor').val(),
  205. // 地面/导览标志颜色
  206. mouseMarkerColor: $('#mouseMarkerColor').val(),
  207. // 鼠标标志颜色
  208. momentTour: $('#tourSwitch input').is(':checked') ? 'black' : 'walk',
  209. // 导览瞬间过渡
  210. showHotListSta: $('#hotListSwitch input').is(':checked'),
  211. // 开启热点列表
  212. hotIconScale: $('#hotIconScale input').val(),
  213. // 热点缩放
  214. supportsVR: $('#VRSwitch input').is(':checked'),
  215. // 开启VR功能
  216. /**************** 陈志广 小地图可配置项 *********** */
  217. cadSignColor: $('#cadSignColor').val(),
  218. cadBorderColor: $('#cadBorderColor').val(),
  219. cadBorderWidth: $('#cad-size').val(),
  220. showCad: $('input[name="show-cad"]').is(':checked'),
  221. }
  222. var overlayInfo = []
  223. player.overlayGroup.children.forEach((overlay)=>{
  224. var info = EditOverlay.getSavingInfo(overlay)
  225. if (info)
  226. overlayInfo.push(info);
  227. })
  228. /* console.log("保存数据");
  229. console.log({
  230. guides: reData(guides, '[]'),
  231. info: info,
  232. })
  233. console.log(JSON.stringify(guides) )
  234. debugger; */
  235. let url = cmp ? ('/api/scene/edit/' + cmp) : '/manage/scene/edit'
  236. $.ajax({
  237. method: 'POST',
  238. headers: {
  239. 'Content-Type': 'application/json',
  240. token: token
  241. },
  242. dataType: 'json',
  243. contentType: 'application/json',
  244. url: ceshi + url,
  245. data: JSON.stringify({
  246. sceneCode: number,
  247. hots: reData(hots, '{}'),
  248. name: number,
  249. guides: reData(guides, '[]'),
  250. info: info,
  251. //tourAudio: reData(that.editGuide.getTourAudio(), '{}'),
  252. overlays: reData(overlayInfo, '[]')
  253. }),
  254. success: function(data) {
  255. if (data.code === 0) {//成功
  256. //manage.showInfo("保存成功")
  257. location.reload()
  258. }else if (data.code === 5001) {
  259. alert('请重新登录')
  260. localStorage.dcj_token = ''
  261. location.reload()
  262. }else{
  263. alert(`saveAll (url:${url}) code : ${data.code} \n${data.msg}`)
  264. }
  265. }
  266. })
  267. });
  268. })
  269. }
  270. //场景信息编辑
  271. var SceneInformation = function() {}
  272. SceneInformation.prototype.init = function(data, data2) {
  273. var $options = $('.hotStyle-item li');
  274. var $loadlogo = $("#loadlogo");
  275. var $hotImageScale = $("#hotImgScale");
  276. var $hideFloorMarker = $("#hideFloorMarker");
  277. var $hideMouseMarker = $("#hideMouseMarker");
  278. var $showingLabels = $("#showingLabels");
  279. var $g_specialScene = $("#g_specialScene");
  280. var $twoData = $("#twoData");
  281. /*******************方奕卓 其他项需要用到data来初始化, 故一并放到这里 ******************/
  282. let momentTour = $('#tourSwitch input');
  283. // 导览瞬间过渡开关
  284. let hotListSwitch = $('#hotListSwitch input');
  285. // 热点列表开关
  286. let hotIconScale = $('#hotIconScale input');
  287. // 热点图标缩放
  288. let VRSwitch = $('#VRSwitch input');
  289. // VR功能开启
  290. /***********************************************************************************/
  291. $(".model-title2").text(data.name);
  292. $('#pjtName').val(data.name);
  293. $('#info-summary').val(data.summary);
  294. //if (data2) $('#weixin-summary').val(data2.weixinDesc);
  295. $('#weixin-summary').val(data.weixinDesc);
  296. for (var i = 0; i < $options.length; i++) {
  297. if ($options.eq(i).attr('data-val') === JSON.stringify(data.hoticon)) {
  298. $options.eq(i).addClass("active").siblings().removeClass("active");
  299. }
  300. }
  301. $('#camera-start')[0].data = data.camera_start;
  302. $(".shotImg.innerBtn").on("click", ()=>{
  303. var EntryInfo = $('#camera-start')[0].data
  304. if (EntryInfo) {
  305. var to = player.model.panos.get(EntryInfo.pano.uuid);
  306. var q = new THREE.Quaternion().fromArray(EntryInfo.camera.quaternion);
  307. var lookAtPoint = new THREE.Vector3(0,0,-1).applyQuaternion(q).add(to.position);
  308. player.flyToPano({
  309. pano: to,
  310. lookAtPoint: lookAtPoint
  311. })
  312. }
  313. }
  314. )
  315. if(data.shareImgUrl){
  316. var imagesHTML = '<div><a class=" result success"><span></span><img src="' + data.shareImgUrl + '"></a></div>'
  317. $(".information .edit-fun-images.list ").html(imagesHTML);
  318. $("#shareImgUpload").addClass("hide")
  319. }
  320. if(data.spotImgUrl){
  321. }
  322. /*************方奕卓 其他项的初始化操作 ************/
  323. initColorElem(data);
  324. addListener();
  325. // 给其他元素绑定事件
  326. if (data.momentTour === 'black') {
  327. momentTour.prop('checked', true);
  328. }
  329. if (data.showHotListSta) {
  330. hotListSwitch.prop('checked', true);
  331. }
  332. if (data.hotIconScale) {
  333. hotIconScale.val(parseFloat(data.hotIconScale));
  334. }
  335. hotIconScale.on('change',(e)=>{
  336. var s = THREE.Math.clamp(parseFloat(e.target.value), 0.1, 100)
  337. e.target.value = s
  338. for(let i in player.model.hots){
  339. if(!player.model.hots[i].hotIconScale){
  340. player.model.hots[i].mesh.scale.set(s,s,s)
  341. }
  342. }
  343. })
  344. $('#hotIconScale_2 input').on('change',(e)=>{
  345. var s = THREE.Math.clamp(parseFloat(e.target.value), 0.1, 100)
  346. e.target.value = s
  347. editTool.hotpoint.editSpot.mesh.scale.set(s,s,s)
  348. })
  349. if (data.supportsVR) {
  350. VRSwitch.prop('checked', true);
  351. }
  352. /************************************************/
  353. //隐藏公司logo
  354. if (data.loadlogo) {
  355. $loadlogo[0].checked = true
  356. showLogo();
  357. }
  358. // 热点图片放大
  359. if (data.hotImageScale) {
  360. $hotImageScale[0].checked = true
  361. }
  362. // 隐藏地面标记
  363. if (data.hideFloorMarker) {
  364. $hideFloorMarker[0].checked = true
  365. }
  366. // 隐藏鼠标标记
  367. if (data.hideMouseMarker) {
  368. $hideMouseMarker[0].checked = true
  369. }
  370. if (data.showingLabels) {
  371. $showingLabels[0].checked = true
  372. }
  373. //特殊大场景
  374. if (data.special) {
  375. $g_specialScene[0].checked = true
  376. }
  377. //启动二代的数据
  378. if (data.vision_version === "1.1.562.17209" || data.vision_version) {
  379. $twoData[0].checked = true
  380. }
  381. }
  382. /**
  383. * 初始化颜色选择的html元素
  384. * @param {*} data
  385. * @param {*} elem
  386. */
  387. function initColorElem(data, elem) {
  388. let $floorMarkerColor = $('#floorMarkerColor');
  389. let $mouseMarkerColor = $('#mouseMarkerColor');
  390. let $floorMarkerColorTex = $('#floorMarkerColorTex');
  391. let $mouseMarkerColorTex = $('#mouseMarkerColorTex');
  392. let $cadSignColor = $('#cadSignColor');
  393. let $cadSignColorTex = $('#cadSignColorTex');
  394. let $cadBorderColor = $('#cadBorderColor');
  395. let $cadBorderColorTex = $('#cadBorderColorTex');
  396. var colorRe = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
  397. // 事件监听
  398. $floorMarkerColor.on('change', function(e) {
  399. $('#floorMarkerColorTex').val(e.target.value)
  400. })
  401. $floorMarkerColorTex.on('blur keydown', function(e) {
  402. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $floorMarkerColor, this);
  403. })
  404. $mouseMarkerColor.on('change', function(e) {
  405. $('#mouseMarkerColorTex').val(e.target.value)
  406. })
  407. $mouseMarkerColorTex.on('blur keydown', function(e) {
  408. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $mouseMarkerColor, this);
  409. })
  410. // 事件监听
  411. $cadSignColor.on('change', function(e) {
  412. $('#cadSignColorTex').val( e.target.value)
  413. })
  414. $cadSignColorTex.on('blur keydown', function(e) {
  415. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadSignColor, this);
  416. })
  417. // 事件监听
  418. $cadBorderColor.on('change', function(e) {
  419. $('#cadBorderColorTex').val( e.target.value)
  420. })
  421. $cadBorderColorTex.on('blur keydown', function(e) {
  422. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadBorderColor, this);
  423. })
  424. // 设置颜色值
  425. function setColor(e, colorElem, inputElem) {
  426. var isColor = colorRe.test(e.target.value);
  427. isColor && colorElem.val(e.target.value);
  428. // isColor ? colorElem.val(e.target.value): (inputElem.placeholder = colorElem.val());
  429. }
  430. // 判断data中是否有存在的颜色值, 否则设置默认值
  431. data.floorMarkerColor ? $floorMarkerColor.val(data.floorMarkerColor) : $floorMarkerColor.val('#4bcdfc');
  432. data.mouseMarkerColor ? $mouseMarkerColor.val(data.mouseMarkerColor) : $mouseMarkerColor.val('#4bcdfc');
  433. // 判断data中是否有存在的颜色值, 否则设置默认值
  434. data.cadSignColor ? $cadSignColor.val(data.cadSignColor) : $cadSignColor.val('#00c8af');
  435. data.cadBorderColor ? $cadBorderColor.val(data.cadBorderColor) : $cadBorderColor.val('#ffffff');
  436. $('input[name="show-cad"]')[0].checked = !!data.showCad
  437. $('#cad-size > option[value="'+(data.cadBorderWidth ? data.cadBorderWidth : '0.01')+'"]').attr("selected",true);
  438. if (data.showCad) {
  439. $('input[name="show-cad"]').trigger('change')
  440. }
  441. $('#panoIdColor').on('change', function(e) {
  442. $('#panoIdColorTex').val(e.target.value)
  443. VisiSet.changePanoIdColor(e.target.value)
  444. })
  445. $('#panoIdColorTex').on('blur keydown', function(e) {
  446. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $('#panoIdColor'), this);
  447. VisiSet.changePanoIdColor(e.target.value)
  448. })
  449. $('#panoIdColor').val('#c13e3e')//初始颜色
  450. $('#panoIdColorTex').val('#c13e3e')
  451. }
  452. $('input[name="show-cad"]').on('change', function(ev) {
  453. if (!ev.target.checked) {
  454. return $('.cad').hide()
  455. }
  456. let taht = this
  457. if (!taht.floorJSON) {
  458. $.ajax({
  459. url: '//super.4dage.com/data/'+ window.number +'/floor.json',
  460. method: 'GET',
  461. success(res) {
  462. taht.floorJSON = res
  463. loadCAD(taht.floorJSON)
  464. $('#cadSignColor').on('change', function(ev) {
  465. loadCAD()
  466. })
  467. $('#cadBorderColor').on('change', function(ev) {
  468. loadCAD()
  469. })
  470. $('#cad-size').on('change', function(ev) {
  471. loadCAD()
  472. })
  473. },
  474. error() {
  475. alert('当前场景没有小地图floor.json文件,请联系三维部门添加')
  476. ev.target.checked = false
  477. }
  478. })
  479. } else {
  480. console.log('0000000000000000000')
  481. $('.cad').show()
  482. }
  483. })
  484. function loadCAD(data) {
  485. grendCAD(data, $('#player')[0], $('#cadSignColor').val(), $('#cadBorderColor').val(), $('#cad-size').val())
  486. }
  487. function addListener() {}
  488. //设置初始界面
  489. function getSeft(seft) {
  490. $('#camera-start').on('click', function() {
  491. if (VisiSet.setPanoVisible) {
  492. return VisiSet.savePanoVisibles()
  493. } else if (VisiSet.setTagVisible) {
  494. return VisiSet.saveTagVisibles()
  495. }
  496. // 这部分内容需要配合main_2018.js中来进行修改
  497. var snap = JSON.parse("{" + seft.getSnapAngleInfo() + "}")
  498. this.data = {
  499. camera: {
  500. position: snap.metadata.camera_position,
  501. quaternion: snap.metadata.camera_quaternion// 相机朝向
  502. },
  503. pano: {
  504. uuid: snap.metadata.scan_id // 起始点位的id
  505. }
  506. }
  507. var ev = document.createEvent("MouseEvent");
  508. //点击截取视图
  509. g_snapShotWidth = 240 * 4;
  510. g_snapShotHeight = 118 * 4;
  511. window.screenSta = 'startScreen';
  512. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  513. ev.__callback = (imgData,info)=>{
  514. uploadImg(imgData, (rs)=>{
  515. if (rs.code === 0) {
  516. $(".shotImg.innerBtn").css("background-image", "url(" + rs.data + ")")
  517. this.data.thumbImg = rs.data;
  518. }
  519. }
  520. , "thumbImg.jpg")
  521. }
  522. window.dispatchEvent(ev);
  523. });
  524. }
  525. //热点编辑
  526. var Hotpoint = function() {
  527. this.spotList = $(".spotList");
  528. this.hotpointDetail = $("#hotpointDetail");
  529. // fyz 导览编辑页面同样采取热点编辑的样式, 这里确保只查找到热点编辑
  530. }
  531. Hotpoint.prototype.init = function(n) {
  532. var that = this;
  533. this.active();
  534. this.addmedia();
  535. // 添加多媒体
  536. this.addMusicInit();
  537. // 添加音乐
  538. this.addModel();
  539. // 添加模型
  540. this.addwebPack();
  541. // 添加外链
  542. //this.initSaveHot();
  543. // 保存热点
  544. this.hotpointDetail.find(".tail .submit").on('click', this.saveHot.bind(this))
  545. $("#isSprite").on("change", function(e) {
  546. that.editSpot.isSprite = this.checked;
  547. if (this.checked) {
  548. that.editSpot.update(player.camera)
  549. } else {
  550. var curPanoTransform = that.editSpot.transformAtPanos[ getTransformSid()] || {}
  551. that.editSpot.mesh.quaternion.copy(curPanoTransform.qua || that.editSpot.quaternion)
  552. }
  553. })
  554. /* $("#noAction").on("change", function(e) {
  555. that.editSpot.noAction = this.checked;
  556. }) */
  557. let hotIconScale = $('#hotIconScale');
  558. //点击添加热点按钮
  559. $('#addHotSpots').on("click", function() {
  560. //点击添加热点
  561. g_HotStatus = g_HotStatus === "add" ? null : "add";
  562. $("#player").css("cursor", "cell");
  563. });
  564. //点击热点列表弹出按钮
  565. this.spotList.on("click", function(e) {
  566. var target = $(e.target);
  567. let li = searchParent(e.target, { className: 'listItem' }, 7);
  568. if(!li)return;
  569. var hotId = $(li).attr("data-spid");
  570. var hot = player.model.hots[hotId]
  571. if(VisiSet.setTagVisible){
  572. return VisiSet.SetOneTagVisible(hot)
  573. }
  574. if (target.hasClass("del")) {
  575. e.stopPropagation();
  576. target.siblings(".DelConfirm").addClass("active");
  577. that.spotList.find("i").text(that.spotList.find("ul li").length);
  578. } else {
  579. if (target.hasClass("DelConfirm")) {
  580. e.stopPropagation();
  581. that.removeHot(hot, $(li));
  582. } else {
  583. //点击热点列表弹出编辑热点窗口
  584. that.editHot(hot, $(li))
  585. }
  586. }
  587. });
  588. //点击热点编辑窗口右上角的关闭按钮
  589. this.hotpointDetail.find("a.close, button.cancel").on("click", function() {
  590. var spot_id = that.hotpointDetail.attr("data-id");
  591. var hot = player.model.hots[spot_id];
  592. //var info = hot.infoAttribute;
  593. that.styleList.recover()
  594. hot.setFromInfo()
  595. /* if (info) {
  596. info.position && hot.mesh.position.copy(info.position)
  597. info.quaternion && hot.mesh.quaternion.copy(info.quaternion)
  598. hot.isSprite = info.isSprite
  599. hot.noAction = info.noAction
  600. hot.linkOutside = info.linkOutside
  601. } */
  602. that.editSpot = null
  603. that.hotpointDetail.addClass("atRight");
  604. transformControls.detach()
  605. for(let i in player.model.hots){
  606. let hot_ = player.model.hots[i]
  607. hot_.styleImg = hot_.infoAttribute.styleImg.map((e)=>{return {src:e}});
  608. hot_.changeTex() //恢复贴图
  609. }
  610. });
  611. //创建列表
  612. for (let i in player.model.hots) {
  613. this.addHotList(player.model.hots[i]);
  614. }
  615. // 初始话的时候把热点信息添加到对应的热点中 直接使用data2.json的会怎样?
  616. /* $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
  617. .then(function (infos) {
  618. that.infos = infos ;
  619. Object.keys(infos).forEach(function (key) {
  620. //sxm增加热点列表可读性,方便查看删除操作等
  621. 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));
  622. })
  623. }) */
  624. $("#hotpointDetail .scale .MenuOptions li").on("click", (e)=>{ //更改大小
  625. curr = $(e.target).attr("index")
  626. if (curr == "default") {
  627. $("#userHotScale").addClass("hide")
  628. var s = parseFloat($("#hotIconScale input").val());
  629. editTool.hotpoint.editSpot.mesh.scale.set(s,s,s)
  630. } else {
  631. $("#userHotScale").removeClass("hide")
  632. var s = editTool.hotpoint.editSpot.mesh.scale.x;
  633. $('#hotIconScale_2 input').val(s)
  634. }
  635. })
  636. $("#hotpointDetail .MenuOptions[name='linkType'] li").on("click", (e)=>{ //链接打开方式切换
  637. editTool.hotpoint.editSpot.linkType = $(e.target).attr("index")
  638. $("#hotpointDetail .MenuOptions[name='linkType'] li").removeClass("chosen");
  639. $(e.target).addClass("chosen")
  640. })
  641. $("#hotpointDetail .MenuOptions[name='actionType'] li").on("click", (e)=>{ //
  642. editTool.hotpoint.editSpot.actionType = $(e.target).attr("index")
  643. $("#hotpointDetail .MenuOptions[name='actionType'] li").removeClass("chosen");
  644. $(e.target).addClass("chosen")
  645. })
  646. $('#setHotPosForPano input').on("change", ()=>{
  647. var on = $('#setHotPosForPano input').is(':checked')
  648. if(!on){
  649. delete this.editSpot.transformAtPanos[getTransformSid()]
  650. this.editSpot.mesh.position.copy(this.editSpot.position)
  651. this.editSpot.mesh.quaternion.copy(this.editSpot.quaternion)
  652. //this.editSpot.usingTransformData = false
  653. }
  654. })
  655. }
  656. Hotpoint.prototype.getTransformAtPano = function(type){
  657. var name = getTransformSid()
  658. var info = {
  659. pos : this.editSpot.mesh.position.clone()
  660. }
  661. if(!this.editSpot.isSprite){
  662. info.qua = this.editSpot.mesh.quaternion.clone()
  663. }else{
  664. if(type == 'quaternion')return; //如果恒朝向相机且调整的是quaternion,不要保存position
  665. }
  666. this.editSpot.transformAtPanos[name] = info
  667. //this.editSpot.usingTransformData = true
  668. }
  669. Hotpoint.prototype.updateTransform = function(type){
  670. var on = $('#setHotPosForPano input').is(':checked')
  671. var name = getTransformSid()
  672. if(on){
  673. this.getTransformAtPano(type)
  674. }else{
  675. if(type == 'position'){
  676. this.editSpot.position.copy(this.editSpot.mesh.position)
  677. }else if(type == 'quaternion'){
  678. if(!this.editSpot.isSprite){ //如果恒朝向相机就不保存quaternion
  679. this.editSpot.quaternion.copy(this.editSpot.mesh.quaternion)
  680. }
  681. }
  682. }
  683. }
  684. Hotpoint.prototype.updatePano = function(){
  685. if(!this.editSpot ) return;
  686. $('#setHotPosForPano input').prop('checked', !!this.editSpot.transformAtPanos[getTransformSid()]);
  687. }
  688. var ifSameTex = function(imgs0, imgs1){//是否是相同的图 (两个都是空的不算相同)
  689. return !!(imgs0[0] && imgs1[0] && imgs0[0].src == imgs1[0].src &&
  690. (imgs0[1] ? (imgs1[1] && imgs0[1].src == imgs1[1].src) : !imgs1[1] ))
  691. }
  692. Hotpoint.prototype.findSpotByImgs = (imgs=[])=>{////使用了该贴图的所有热点
  693. var spots = []
  694. for(var i in player.model.hots){
  695. var styleImg = player.model.hots[i].styleImg || [];
  696. if(ifSameTex(styleImg, imgs)){
  697. spots.push(player.model.hots[i])
  698. }
  699. }
  700. return spots
  701. }
  702. Hotpoint.prototype.initTexSelect = function(hots) {//热点样式图列表
  703. var countElem = $("<a></a>").css({"width":'40px','display': 'block', 'color':'#aeaeae', 'white-space':'break-spaces', 'line-height':'25px', 'margin-left':'10px'})
  704. var uploadInput = $('<input type="file" style="display:none" accept="image/*"></input>');
  705. var getListItem = ()=>{
  706. var elem = $('<li><ul class="hotTexUpload"><li class="upload"><div></div><a class="del hasHover"></a></li><li class="upload hide"><div></div><a class="del hasHover"></a></li></ul></li>')
  707. elem[0]._styleImg = []
  708. return elem
  709. }
  710. var editHotStyleInfo = {}
  711. var setImgContent = function($dom, index, src) {
  712. var li = $dom.find('li').eq(index)
  713. var div = li.find('>div');
  714. if (src) {
  715. li.addClass("uploaded")
  716. div.css("background-image", `url(${src})`)
  717. } else {
  718. li.removeClass("uploaded")
  719. div.css("background-image", '')
  720. }
  721. }
  722. var hotIcons = []; // 从所有热点tex中搜集
  723. for(let i in hots){
  724. let imgs = hots[i].infoAttribute && hots[i].infoAttribute.styleImg;
  725. if(imgs && imgs.length){
  726. if(!hotIcons.find(e=>e[0] == imgs[0] && e[1] == imgs[1])){
  727. hotIcons.push(imgs)
  728. }
  729. }
  730. }
  731. hotIcons = hotIcons.map(imgs=>imgs = imgs.map((a)=>{return {src:a}}))
  732. hotIcons.push([])//放末尾用来添加的
  733. var list = hotIcons.map(arr=>{//初始列表
  734. var elem = getListItem()
  735. elem[0]._styleImg = arr //每个li上绑定一个 _styleImg,存储它包含的图, 和热点的styleImg对应
  736. var divs = elem.find("li>div")
  737. arr.forEach((img,i)=>{
  738. setImgContent(elem, i, img.src)
  739. })
  740. arr.length && elem.find("li").eq(1).removeClass('hide')
  741. return elem
  742. })
  743. this.styleList = new ListBox(list, $('#spotTexSelect'), {//列表
  744. selectFun:()=>{//选中时要改变选中项selection缩略图 以及改变热点
  745. if(this.styleList.chosenItem == void 0){
  746. this.styleList.listTitle.find('li').addClass('hide')
  747. }else{
  748. this.styleList.listTitle.find('li').removeClass('hide')
  749. var divs = this.styleList.listTitle.find('li>div')//selection
  750. var imgs = this.styleList.chosenItem[0]._styleImg;
  751. if(imgs[0]){
  752. divs.eq(0).css("background-image", 'url("'+imgs[0].src+'")')
  753. divs.eq(0).parent().removeClass('hide')
  754. }else{
  755. divs.eq(0).parent().addClass('hide')
  756. }
  757. if(imgs[1]){
  758. divs.eq(1).css("background-image", 'url("'+imgs[1].src+'")')
  759. divs.eq(1).parent().removeClass('hide')
  760. }else{
  761. divs.eq(1).parent().addClass('hide')
  762. }
  763. //应用到热点:
  764. this.editSpot.changeTex(imgs)
  765. }
  766. Array.from(this.styleList.listDom.children()).forEach(li=>{//更新一下所有的li的使用的spot
  767. li.sameTexSpots = this.findSpotByImgs(li._styleImg)
  768. })
  769. },
  770. /* delFun: ()=>{
  771. }, */
  772. addFun: ($li)=>{ //列表新增时对li的操作
  773. $li[0].sameTexSpots = this.findSpotByImgs($li[0]._styleImg)
  774. $li.find('li').bind('click', (e)=>{
  775. e.stopPropagation()
  776. var index = $(e.currentTarget).index();
  777. if (e.target.classList.contains("del")) { //删除图片
  778. if ($li[0]._styleImg.length == 2 && index == 0) { //删除第一个 且有第二个的话
  779. setImgContent($li, 0, $li[0]._styleImg[1].src);
  780. setImgContent($li, 1, null);
  781. $li[0]._styleImg = [$li[0]._styleImg[1]]
  782. } else {
  783. setImgContent($li, index, null);
  784. $li[0]._styleImg.pop()
  785. if ($li[0]._styleImg.length == 0) {
  786. $li.find("li").eq(1).addClass("hide");
  787. }
  788. }
  789. $li[0].sameTexSpots.forEach(hot=>{
  790. hot.changeTex($li[0]._styleImg)
  791. })
  792. if($li.hasClass('selected')){//是当前spot的
  793. //this.editSpot.changeTex($li[0]._styleImg)
  794. this.styleList.options.selectFun()
  795. }
  796. } else {
  797. //添加图片
  798. uploadInput.click()
  799. editHotStyleInfo = {
  800. imgs : $li[0]._styleImg, index, $li
  801. };
  802. }
  803. })
  804. $li.bind('mouseover', (e)=>{
  805. this.showTitileSpots = $li[0].sameTexSpots;
  806. this.showTitileSpots.forEach(a=>a.showTitle())
  807. countElem.text("热点个数:"+this.showTitileSpots.length).removeClass('hide')
  808. $li.find("ul").append(countElem)
  809. })
  810. $li.bind('mouseout', (e)=>{
  811. this.showTitileSpots.forEach(a=>a.hideTitle())
  812. this.showTitileSpots = null;
  813. countElem.addClass('hide')
  814. })
  815. },
  816. saveTemp: (list)=>{//编辑热点时保存一份副本
  817. this._styleImgTemp = Array.from(list.listDom.children()).map((li)=>{
  818. return li._styleImg.slice()
  819. })
  820. },
  821. recover : (list)=>{//取消编辑时恢复
  822. Array.from(list.listDom.children()).forEach((li,i)=>{
  823. li._styleImg = this._styleImgTemp[i]
  824. })
  825. },
  826. })
  827. this.styleList.findChosenByImgs = (imgs=[])=>{//找到某图对应的li
  828. var list = Array.from(this.styleList.listDom.children())
  829. var item = list.find(e=>ifSameTex(e._styleImg, imgs ))
  830. return {index: item ? list.indexOf(item) : null, item: item }
  831. }
  832. this.styleList.clearVoid = ()=>{//清理空的
  833. var length = this.styleList.listDom.children().length;
  834. Array.from(this.styleList.listDom.children()).forEach((e, i)=>{
  835. if(i < length-1){
  836. if(e._styleImg.length == 0) this.styleList.removeItem($(e))
  837. }
  838. })
  839. }
  840. this.styleList.addNew = ()=>{//看是否在最后一行增加新的
  841. var lastOne = this.styleList.listDom.children().last();
  842. if(lastOne[0]._styleImg.length != 0){
  843. this.styleList.addItem(getListItem())
  844. }
  845. }
  846. uploadInput.on("change", (e)=>{
  847. inputMedia({
  848. enableTypes: ["photo"],
  849. photoDone: (resultImg)=>{
  850. editHotStyleInfo.imgs[editHotStyleInfo.index] = {file: resultImg.file, needSave:true, src:resultImg.src}//resultImg
  851. setImgContent(editHotStyleInfo.$li, editHotStyleInfo.index, resultImg.src)
  852. if (editHotStyleInfo.index == 0){
  853. editHotStyleInfo.$li.find('li').eq(1).removeClass("hide");
  854. }
  855. //resultImg.needSave = true
  856. editHotStyleInfo.$li[0].sameTexSpots.forEach(hot=>{
  857. hot.changeTex(editHotStyleInfo.$li[0]._styleImg)
  858. })
  859. if(editHotStyleInfo.$li.hasClass('selected')){//是当前spot的
  860. this.styleList.options.selectFun()//更新选中状态
  861. }
  862. this.styleList.addNew()
  863. }
  864. }, "photo", e);
  865. })
  866. $("#hotpointDetail .style .MenuOptions li").on("click", (e)=>{ //切换是默认还是自定义
  867. var currStyle = $(e.target).attr("index")
  868. if (currStyle == "default") {
  869. $("#spotTexSelect").addClass("hide")
  870. $("#hotpointDetail .style label").addClass("hide")
  871. editTool.hotpoint.editSpot.changeTex([])
  872. } else {
  873. this.styleList.options.selectFun()
  874. $("#hotpointDetail .style label").removeClass("hide")
  875. $("#spotTexSelect").removeClass("hide")
  876. }
  877. })
  878. }
  879. Hotpoint.prototype.initStyle = function(hot) { //每次开始编辑热点时更新样式
  880. if (!hot.styleImg)
  881. hot.styleImg = [];
  882. this.styleList.clearVoid();
  883. if(hot.styleImg.length){
  884. var info = this.styleList.findChosenByImgs(hot.styleImg)
  885. var chosenIndex = info.index
  886. this.styleList.selectFromOutSide(chosenIndex)
  887. $("#hotpointDetail .style .MenuOptions li").eq(1).click();
  888. }else{
  889. this.styleList.selectFromOutSide(null)
  890. $("#hotpointDetail .style .MenuOptions li").eq(0).click()
  891. }
  892. this.styleList.saveTemp()
  893. }
  894. /**
  895. * 显示编辑热点的窗口和初始化热点窗口的数据
  896. */
  897. Hotpoint.prototype.editHot = function(hot, $li) {
  898. this.hotpointDetail.removeClass("atRight");
  899. $("#hotpointDetail .audio.mediaUpload").find("input").val('');
  900. // 点击编辑导览清空上一次文件
  901. var playIcon = 'images/play.png';
  902. var $layout = $("#hotpointDetail")[0];
  903. //$layout.targetDOM = target.closest("li")[0];
  904. //closest匹配选择器的第一个祖先元素
  905. //编辑时将热点列表唯一标识带入,以便后期保存使用识别
  906. //var li_id = $li.attr("data-spid");
  907. this.editSpot = hot
  908. this.hotpointDetail.attr("data-id", hot.sid);
  909. var info = this.editSpot.infoAttribute || {}
  910. //$layout.targetDOM.infoAttribute || {}
  911. $(".MenuOptions[name='transform'] li[index='translate']").click()//transformControls.transCtlChangeMode("translate")
  912. // 参数初始化
  913. info.title = info.title || '';
  914. info.content = info.content || '';
  915. info.iframe = info.iframe || [];
  916. info.model = info.model || [];
  917. info.images = info.images || [];
  918. info.video = info.video || [];
  919. info.isSprite = this.editSpot.isSprite
  920. info.actionType = this.editSpot.actionType
  921. info.linkType = this.editSpot.linkType
  922. info.transformAtPanos = {}
  923. for(var i in this.editSpot.transformAtPanos){
  924. info.transformAtPanos[i] = {
  925. pos : this.editSpot.transformAtPanos[i].pos.clone(),
  926. qua : this.editSpot.transformAtPanos[i].qua && this.editSpot.transformAtPanos[i].qua.clone(),
  927. }
  928. }
  929. try {
  930. transformControls.attach(hot.mesh)
  931. if(player.mode == 'panorama'){
  932. hot.examine(player, {
  933. dontOpen: true,
  934. aimDuration : 600,
  935. duration : 600
  936. })
  937. }else{
  938. player.focusPoint({aim: hot.position, radius:hot.position.distanceTo(player.position)})
  939. }
  940. info.position = hot.position.clone()
  941. info.quaternion = hot.quaternion.clone()
  942. } catch (e) {}
  943. this.updatePano()
  944. this.initStyle(hot);
  945. if(hot.infoAttribute.hotIconScale){
  946. $("#hotpointDetail .scale .MenuOptions li[index=user]").click()
  947. }else $("#hotpointDetail .scale .MenuOptions li[index=default]").click()
  948. $("#hotpointDetail .MenuOptions[name='linkType'] li").removeClass("chosen")
  949. $("#hotpointDetail .MenuOptions[name='actionType'] li").removeClass("chosen")
  950. $("#hotpointDetail .MenuOptions[name='linkType'] li[index = " + this.editSpot.linkType+"]").addClass("chosen")
  951. $("#hotpointDetail .MenuOptions[name='actionType'] li[index = " + this.editSpot.actionType+"]").addClass("chosen")
  952. $("#isSprite")[0].checked = this.editSpot.isSprite
  953. //$("#noAction")[0].checked = this.editSpot.noAction
  954. var iframesHTML = info.iframe.map(function(iframe) {
  955. return this.inputList("请填写网页链接", iframe)
  956. }
  957. .bind(this))
  958. var modulesHTML = info.model.map(function(module) {
  959. return this.inputList("请填写网页链接", module)
  960. }
  961. .bind(this))
  962. var imagesHTML = info.images.map(function(image) {
  963. return '<div><a class=" result success" data-type="photo"><span></span><img src="' + image + '" class="bg"></a></div>'
  964. })
  965. var videosHTML = info.video.map(function(ly) {
  966. //var imgDom = (!ly.img || ly.img === "undefined") ? '' : 'success';
  967. //var imgUrl = (!ly.img || ly.img === "undefined") ? playIcon : ly.img;
  968. //return '<div><a class=" result success" data-type="video"><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>'
  969. var thumb = (!ly.img || ly.img === "undefined") ? '' : '<img src='+ ly.img +' class="bg"></img>'
  970. var thumbResult = (!ly.img || ly.img === "undefined") ? '' : 'success';
  971. var dom = '<div><a class=" result success" data-type="video"><span></span>' + thumb + ' <img class="play-video" videoURL="' + ly.url + '" src="' + playIcon + '"></a> <span class="upload-thum ' + thumbResult + ' result" attr-thum="' + ly.img + '">上传封面<i><input type="file" accept="image/*"></i></span></div>'
  972. return dom
  973. })
  974. this.hotpointDetail.find(".name > input").val(info.title);
  975. this.hotpointDetail.find(".editText").val(info.content);
  976. this.hotpointDetail.find(".photo .list").html(imagesHTML);
  977. this.hotpointDetail.find(".video .list").html(videosHTML);
  978. this.hotpointDetail.find(".model .list").html(modulesHTML);
  979. this.hotpointDetail.find(".webPage .list").html(iframesHTML);
  980. let bgName = info.bgName || '热点背景音乐';
  981. if (info.backgroundMusic) {
  982. /* this.hotpointDetail.find(".audio .playBox").removeClass("hide");
  983. this.hotpointDetail.find("#upload-hotBgm").attr('data-hotBgm', info.backgroundMusic)
  984. this.hotpointDetail.find(".audio .playBox a").attr("href", info.backgroundMusic);
  985. this.hotpointDetail.find('#hotBgName')[0].innerHTML = bgName;
  986. this.hotpointDetail.find(".audio .submit").text("替换"); */
  987. this.musicBox.show(this.hotpointDetail.find(".audio.mediaUpload"), bgName, info.backgroundMusic)
  988. } else {
  989. this.musicBox.hide()
  990. /* this.hotpointDetail.find(".audio .playBox").addClass("hide");
  991. this.hotpointDetail.find("#upload-hotBgm").removeAttr('data-hotBgm') */
  992. // 没有背景音乐,则移除该属性, 避免其他热点的干扰
  993. }
  994. // $layout.targetDOM.infoAttribute = info
  995. this.editSpot.infoAttribute = info
  996. }
  997. //添加图片和视频
  998. Hotpoint.prototype.addmedia = function() {
  999. // 视频预览控制
  1000. var $videoLayout = $('.fun-view-video')
  1001. $videoLayout.find('span').on('click', function() {
  1002. $videoLayout.hide();
  1003. $videoLayout.find('video').attr('src', '')[0].pause()
  1004. });
  1005. // 图片加载回调
  1006. function imageSuccess(file) {
  1007. if (!/image\/\w+/.test(file.type)) {
  1008. alert("文件必须为图片!");
  1009. return false;
  1010. }
  1011. if (!restrictedSize(file, 9)) {
  1012. return false;
  1013. }
  1014. var img = new Image()
  1015. img.src = URL.createObjectURL(file);
  1016. img.className = 'bg'
  1017. return img
  1018. }
  1019. // 视频加载回调
  1020. function videoSuccess(file, $elayout) {
  1021. if (!/video\/\w+/.test(file.type)) {
  1022. alert("视频必须为map4格式!");
  1023. return false;
  1024. }
  1025. $elayout.append('<span class="upload-thum">上传封面<i><input type="file" accept="image/*"></i></span>')
  1026. return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) + '">'
  1027. }
  1028. // 视频封面回调
  1029. function thumbSuccess(file, $elayout, $seft) {
  1030. if (!/image\/\w+/.test(file.type)) {
  1031. alert("文件必须为图片!");
  1032. return false;
  1033. }
  1034. if (!restrictedSize(file, 2)) {
  1035. return false;
  1036. }
  1037. var img = $seft.closest('div').find('img.bg');
  1038. if(!img[0]){
  1039. img = $("<img class='bg'></img>");
  1040. $seft.closest('div').find('a').append(img)
  1041. }
  1042. img.attr('src', URL.createObjectURL(file));
  1043. $seft.closest('span').removeClass("success")
  1044. }
  1045. // 图片与视频加载
  1046. function fileHandle() {
  1047. var $seft = $(this) //input
  1048. var file = this.files[0];
  1049. var type = this.activeElem ? this.activeElem.attr('data-type') : $seft.parent().attr('data-type');
  1050. var $din = $(document.createElement('div'));
  1051. var fnc = type === 'photo' ? imageSuccess : type === 'video' ? videoSuccess : thumbSuccess //再次传都会是thumSuccess
  1052. var $dom = fnc(file, $din, $seft)
  1053. if (type === 'photo' || type === 'video') {
  1054. if (!$dom)
  1055. return $seft.val('');
  1056. if(!this.activeElem){//创建新的item
  1057. var $layout = $seft.closest("li");
  1058. var $addLayout = $(document.createElement('a'));
  1059. $addLayout.attr("data-type", type)
  1060. var $close = $(document.createElement('span'));
  1061. $addLayout[0].file = file;
  1062. $addLayout.append($close);
  1063. $addLayout.append($dom);
  1064. $addLayout.addClass("result");
  1065. $din.prepend($addLayout);
  1066. $layout.find('.edit-fun-images').append($din);
  1067. }else{//重传
  1068. if (type === 'photo'){
  1069. this.activeElem.find("img.bg").remove();
  1070. }else{
  1071. this.activeElem.find(".play-video").remove();
  1072. }
  1073. this.activeElem.removeClass("success")
  1074. this.activeElem.append($dom)
  1075. this.activeElem[0].file = file;
  1076. this.value = ''
  1077. }
  1078. }
  1079. if (searchParent($seft[0], {
  1080. id: 'shareImgUpload'
  1081. })) {
  1082. //信息页面的分享图片
  1083. $("#shareImgUpload").addClass("hide")
  1084. }else if(searchParent($seft[0], {
  1085. id: 'SpotStyle'
  1086. })){
  1087. $("#SpotStyle").addClass("hide")
  1088. }
  1089. }
  1090. //用于重传的input
  1091. var imgInput = $("<input accept='image/*' type='file'></input>")
  1092. var videoInput = $("<input accept='video/*' type='file'></input>")
  1093. // 图片与视频加载
  1094. $('.upload, .edit-fun-images').on('change', function(ev) {
  1095. if (ev.target.tagName.toUpperCase() === 'INPUT') {
  1096. ev.target.files.length && fileHandle.call(ev.target)
  1097. }
  1098. })
  1099. imgInput.on('change', (ev)=>{fileHandle.call(ev.target)})
  1100. videoInput.on('change', (ev)=>{fileHandle.call(ev.target)})
  1101. $('.edit-fun-images').on('click', function(ev) {//点击item时
  1102. var $tag = $(ev.target)
  1103. var tagName = ev.target.tagName.toUpperCase()
  1104. if (tagName === 'SPAN') {
  1105. if (searchParent($tag[0], {
  1106. className: 'forShareImg'
  1107. })) {
  1108. //信息页面的分享图片
  1109. $("#shareImgUpload").removeClass('hide')
  1110. }else if(searchParent($tag[0], {
  1111. className: 'SpotStyle'
  1112. })){
  1113. $("#SpotStyle").removeClass('hide')
  1114. }
  1115. $tag.parent().parent().remove()
  1116. }else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
  1117. $videoLayout.css('display', 'flex').find('video').attr('src', $tag.attr('videoURL'))[0].play()
  1118. }else{// 替换
  1119. var a = searchParent($tag[0], {
  1120. tagName: 'a'
  1121. })
  1122. if(a) {
  1123. var input
  1124. if(searchParent($tag[0], {
  1125. className: 'video'
  1126. })){
  1127. input = videoInput
  1128. }else{
  1129. input = imgInput
  1130. }
  1131. input[0].activeElem = $(a)
  1132. input.click()
  1133. }
  1134. }
  1135. })
  1136. }
  1137. //选择热点的样式
  1138. Hotpoint.prototype.active = function() {
  1139. $(".hotStyle-item li").on('click', function() {
  1140. $(this).addClass('active').siblings().removeClass('active');
  1141. })
  1142. }
  1143. //当前处于的状态,比如是否是添加热点的状态
  1144. Hotpoint.prototype.state = function(that, Hot) {
  1145. if (g_HotStatus === "add") {
  1146. //console.log(Hot)
  1147. this.addHot(that, Hot, (hot)=>{
  1148. this.addHotList(hot);
  1149. }
  1150. );
  1151. }
  1152. }
  1153. Hotpoint.prototype.updateNumDisplay = function() {
  1154. this.spotList.find("i").text(this.spotList.find("ul li").length);
  1155. }
  1156. //删除热点
  1157. Hotpoint.prototype.removeHot = function(hot, $li ) {
  1158. hot.dispose();
  1159. delete player.model.hots[hot.sid]
  1160. $li.remove();
  1161. this.updateNumDisplay()
  1162. }
  1163. //添加热点模型
  1164. Hotpoint.prototype.addHot = function(that, Hot, fn) {
  1165. if (!window.hotIntersect)
  1166. return;
  1167. // 没有正确的热点位置, return
  1168. var position = hotIntersect.point.toArray();
  1169. //var sid = g_HotMeshes.length > 0 ? "sprite_" + (parseInt(g_HotMeshes[g_HotMeshes.length - 1].name.substring(7)) + 1) : "sprite_" + g_HotMeshes.length;//这么写出bug了。因为当前热点名字不是按照从小到大
  1170. var sid = getRandomSid()
  1171. var hot = new Hot(sid,{
  1172. position: position,
  1173. rotation: [0, 0, 0],
  1174. size: 1.05
  1175. },that.model);
  1176. that.model.hots[sid] = hot;
  1177. if (player.getMouseDirection().angleTo(window.hotIntersect.face.normal) < Math.PI / 2) {
  1178. hot.mesh.lookAt(window.hotIntersect.face.normal.clone().negate().add(hotIntersect.point));
  1179. hot.mesh.position.add(window.hotIntersect.face.normal.clone().negate().multiplyScalar(0.01))
  1180. //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  1181. } else {
  1182. hot.mesh.lookAt(window.hotIntersect.face.normal.clone().add(hotIntersect.point));
  1183. hot.mesh.position.add(window.hotIntersect.face.normal.clone().multiplyScalar(0.01))
  1184. }
  1185. hot.quaternion.copy(hot.mesh.quaternion)
  1186. hot.position.copy(hot.mesh.position)
  1187. g_HotStatus = false;
  1188. that.mouseCouldBeClickToMove = false;
  1189. $("#player").css("cursor", "");
  1190. //添加完热点之后的回调函数
  1191. if (g_HotMeshes && g_newHot.length === g_newHot.length++) {
  1192. var thisScene = that;
  1193. //fn && fn.call(this, thisScene);
  1194. fn && fn(hot)
  1195. }
  1196. }
  1197. //添加热点列表
  1198. Hotpoint.prototype.addHotList = function(hot) {
  1199. var li = $("<li class='listItem' data-spid=" + hot.sid + ">" + "<div class=icon></div>" + "<div class=number title=热点>" + (++_hotNum) + "</div>" + "<div class=title title=热点>" + (hot.infoAttribute && hot.infoAttribute.title || "") + "</div>" + "<div class=DelConfirm>确定删除</div>" + "<div class=del></div>" + "</li>");
  1200. li.hot = hot
  1201. $(".spotList ul").append(li);
  1202. this.updateNumDisplay()
  1203. }
  1204. //添加热点音乐
  1205. Hotpoint.prototype.addMusicInit = function() {
  1206. /* var mediaUpload = $("#hotpointDetail .audio.mediaUpload");
  1207. mediaUpload.find("input").on("change", function() {
  1208. var file = this.files[0];
  1209. mediaUpload.find(".innerBtn").text("替换");
  1210. mediaUpload.find(".playBox").removeClass("hide");
  1211. mediaUpload.find(".title").text(file.name);
  1212. mediaUpload.find('#query-bgm').attr('href', URL.createObjectURL(file));
  1213. });
  1214. //删除音乐
  1215. mediaUpload.on("click", ".delete", function() {
  1216. mediaUpload.find('#query-bgm').attr('href', "");
  1217. mediaUpload.find(".playBox").addClass("hide");
  1218. mediaUpload.find(".innerBtn").text("上传");
  1219. mediaUpload.find("input").val("").removeAttr("data-hotbgm");
  1220. }) */
  1221. this.musicBox = musicPlayBoxBind($("#hotpointDetail .audio.mediaUpload"), null )
  1222. }
  1223. //添加热点模型列表dom
  1224. Hotpoint.prototype.inputList = function(text, val) {
  1225. var _val = '';
  1226. if (arguments[1]) {
  1227. _val = 'value=' + val;
  1228. }
  1229. return '<div class="link"> <input class="text" type="text" placeholder=' + text + ' spellcheck="false" ' + _val + ' > </div>'
  1230. }
  1231. //添加热点模型
  1232. Hotpoint.prototype.addModel = function() {
  1233. var text = this.inputList("请填写模型链接(https开头)");
  1234. this.hotpointDetail.find(".model .add").on('click', function() {
  1235. $(this).closest(".model").find(".list").append(text)
  1236. });
  1237. this.hotpointDetail.find(".model .delete").on('click', function() {
  1238. $(this).closest(".model").find(".list > div:last").remove();
  1239. });
  1240. }
  1241. //添加网页链接
  1242. Hotpoint.prototype.addwebPack = function() {
  1243. var text = this.inputList("请填写网页链接", "");
  1244. this.hotpointDetail.find(".webPage .add").on('click', function() {
  1245. $(this).closest(".webPage").find(".list").append(text)
  1246. });
  1247. this.hotpointDetail.find(".webPage .delete").on('click', function() {
  1248. $(this).closest(".webPage").find(".list > div:last").remove();
  1249. });
  1250. }
  1251. // 保存热点信息
  1252. Hotpoint.prototype.saveHot = function() {
  1253. var $layout = $(".edit-loading");
  1254. var hotpointDetail = this.hotpointDetail;
  1255. var that = this
  1256. //获取唯一标识
  1257. var spot_id = hotpointDetail.attr("data-id");
  1258. var spot = this.spotList.find("li[data-spid=" + spot_id + "]");
  1259. var hot = player.model.hots[spot_id];
  1260. //显示loading
  1261. $layout.removeClass('hide');
  1262. var args = {};
  1263. //热点标题
  1264. var $title = hotpointDetail.find(".info input");
  1265. //热点内容
  1266. var $content = hotpointDetail.find(".info textarea");
  1267. //热点图片
  1268. var $images = hotpointDetail.find(".photo .edit-fun-images a.result");
  1269. //热点视频
  1270. var $videos = hotpointDetail.find(".video .edit-fun-images a.result");
  1271. //热点视频的图片
  1272. var $thums = hotpointDetail.find(".video .edit-fun-images .upload-thum");
  1273. //热点模型
  1274. var $modules = hotpointDetail.find(".model input");
  1275. //热点内嵌网页
  1276. var $iframes = hotpointDetail.find(".webPage input.text");
  1277. //热点音乐
  1278. var $miusc = hotpointDetail.find("#upload-hotBgm");
  1279. let $bgName = hotpointDetail.find('.title');
  1280. var promise = new Promise(function(resolve, reject) {
  1281. //获取图片路径
  1282. upload($images, 'images', resolve)
  1283. }).then(function(imgUrls) {
  1284. args.images = imgUrls
  1285. //获取视频路径
  1286. return new Promise(function(resolve, reject) {
  1287. upload($videos, 'videos', resolve)
  1288. }
  1289. )
  1290. }).then(function(videoUrls) {
  1291. args.video = videoUrls
  1292. //获取视频封面路径
  1293. return new Promise(function(resolve, reject) {
  1294. upload($thums, 'images', resolve)
  1295. }
  1296. )
  1297. }).then(function(thums) {
  1298. args.video = args.video.map(function(video, index) {//整合视频+封面
  1299. return {
  1300. url: video,
  1301. img: thums[index]
  1302. }
  1303. })
  1304. }).then(function() {
  1305. //获取热点音乐所有的路径
  1306. //console.log($miusc)
  1307. if ($miusc[0].files.length > 0) {
  1308. return new Promise(function(resolve) {
  1309. upload($miusc, 'miusc', function(res) {
  1310. resolve(res[0])
  1311. })
  1312. }
  1313. )
  1314. } else {
  1315. return $miusc.attr('data-hotBgm')
  1316. }
  1317. }).then(function(src) {
  1318. if(that.musicBox.hasMusic && !src){
  1319. args.backgroundMusic = hot.infoAttribute.backgroundMusic
  1320. args.bgName = hot.infoAttribute.bgName
  1321. }else{
  1322. args.backgroundMusic = src
  1323. args.bgName = $bgName[0].innerHTML;
  1324. }
  1325. }).then(function() {
  1326. //上传所有热点的style图片
  1327. var a = $.Deferred();
  1328. var doneNum = 0;
  1329. var imgsNeedSave = [];
  1330. Array.from(that.styleList.listDom.children()).forEach(li=>{
  1331. if(li.sameTexSpots.length == 0)return;//没被热点用到就不保存
  1332. li.sameTexSpots.forEach(spot=>spot.styleImg = li._styleImg)//同步下
  1333. li._styleImg.forEach(img=>{
  1334. if(img.needSave && !imgsNeedSave.includes(img)){
  1335. imgsNeedSave.push(img)
  1336. }
  1337. })
  1338. })
  1339. if(imgsNeedSave.length){
  1340. imgsNeedSave.forEach(img=>{
  1341. uploadFile(img.file, 'hot/image', function(rs) {
  1342. if (rs.code === 0) {
  1343. img.needSave = false;
  1344. //img.saveURL = rs.data;
  1345. img.src = rs.data;
  1346. if (++doneNum >= imgsNeedSave.length) {
  1347. a.resolve();
  1348. }
  1349. } else {
  1350. alert("样式图上传失败");
  1351. a.reject();
  1352. }
  1353. })
  1354. })
  1355. return a.promise()
  1356. }else{
  1357. return a.resolve()
  1358. }
  1359. }).then(function() {
  1360. //获取热点标题、内容、内嵌网页、模型网页。
  1361. args.title = $title.val()
  1362. args.content = $content.val()
  1363. var iframes = []
  1364. for (var i = 0; i < $iframes.length; i++) {
  1365. var iframe = $iframes.eq(i).val()
  1366. iframe && iframes.push(iframe)
  1367. }
  1368. args.iframe = iframes
  1369. var modules = []
  1370. for (var i = 0; i < $modules.length; i++) {
  1371. var module = $modules.eq(i).val()
  1372. module && modules.push(module)
  1373. }
  1374. args.model = modules
  1375. if(!hot.isSprite){
  1376. args.quaternion = hot.quaternion.clone()
  1377. //hot.quaternion.copy(hot.mesh.quaternion)
  1378. }
  1379. args.position = hot.position.clone()
  1380. //hot.position.copy(hot.mesh.position)
  1381. return args
  1382. }).then(function(args) {
  1383. console.log(args);
  1384. //把获取的所有信息都保存在对应热点的dom元素里面
  1385. //hotpointDetail[0].targetDOM.infoAttribute = args;
  1386. if($("#hotpointDetail .scale .MenuOptions li.chosen").attr('index') == 'user' ){
  1387. args.hotIconScale = $("#hotIconScale_2 input").val();
  1388. }else{
  1389. delete args.hotIconScale
  1390. }
  1391. hot.infoAttribute = args;
  1392. for(let i in player.model.hots){//修改所有的热点贴图数据
  1393. let hot = player.model.hots[i];
  1394. let li = that.styleList.findChosenByImgs(hot.styleImg).item
  1395. if(li) hot.infoAttribute.styleImg = li._styleImg.map(img=> img.src)//将blob更换成线上链接
  1396. }
  1397. hot.setTitleElem()//更新名称
  1398. $layout.addClass('hide');
  1399. hotpointDetail.addClass("atRight");
  1400. spot.find(".title").html(args.title);
  1401. transformControls.detach()
  1402. that.editSpot = null
  1403. })
  1404. return promise
  1405. }
  1406. //背景音乐
  1407. var EditMiuse = function() {
  1408. this.mediaUpload = $(".music .audio.mediaUpload");
  1409. this.musicBox = musicPlayBoxBind(this.mediaUpload, (file)=>{
  1410. uploadMiuse(file, (rs, file)=>{
  1411. if (rs.code === 0) {
  1412. this.musicBox.show(this.mediaUpload, file.name, rs.data)
  1413. }else{
  1414. this.musicBox.hide()
  1415. }
  1416. })
  1417. }, null)
  1418. /* this.success = function(text, url) {
  1419. this.mediaUpload.find(".innerBtn").text("替换");
  1420. this.mediaUpload.find(".playBox").removeClass("hide");
  1421. this.mediaUpload.find(".title").text(text);
  1422. this.mediaUpload.find('#query-bgm').attr('href', url)
  1423. }
  1424. ;
  1425. this.delete = function() {
  1426. this.mediaUpload.find('#query-bgm').attr('href', "");
  1427. this.mediaUpload.find(".playBox").addClass("hide");
  1428. this.mediaUpload.find(".innerBtn").text("上传");
  1429. this.mediaUpload.find("input").val("");
  1430. }
  1431. ;
  1432. var that = this;
  1433. $('#upload-bgm').on('change', function(e) {
  1434. var file = this.files[0];
  1435. uploadMiuse(file, function(rs, file) {
  1436. if (rs.code === 0) {
  1437. that.success(file.name, rs.data)
  1438. }
  1439. })
  1440. e.target.value = null
  1441. });
  1442. //删除音乐
  1443. this.mediaUpload.on("click", ".delete", function() {
  1444. that.delete();
  1445. }) */
  1446. }
  1447. EditMiuse.prototype.init = function(data) {
  1448. if (!data.backgroundMusic)
  1449. return;
  1450. this.musicBox.show(this.mediaUpload, data.bgName || "backgound", data.backgroundMusic);
  1451. }
  1452. //导览编辑
  1453. var EditGuide = function() {
  1454. this.$list = $('#guide-list')
  1455. //$('#tourItemEdit') = $('#tourItemEdit');
  1456. this.targetTourPoint = null;
  1457. // fyz 记录当前编辑的导览点
  1458. // fyz 导览音乐队列
  1459. //this.tourAudio = {};
  1460. }
  1461. /**
  1462. * @author fyz 2019.07.31
  1463. * @description 新增参数data2, 表示data2.js中的数据
  1464. */
  1465. /* function snapATourView(that, renew) {
  1466. var ev = document.createEvent("MouseEvent");
  1467. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1468. g_snapShotWidth = 200;
  1469. g_snapShotHeight = 140;
  1470. window.screenSta = 'tour';
  1471. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  1472. ev.__callback = function(imgData, info) {
  1473. that.uploadGuide(imgData, info, renew, that.targetTourPoint)
  1474. }.bind(that);
  1475. window.dispatchEvent(ev);
  1476. } */
  1477. EditGuide.prototype.snapATourView = function(renew, insideFolder){
  1478. var ev = document.createEvent("MouseEvent");
  1479. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1480. g_snapShotWidth = 200;
  1481. g_snapShotHeight = 140;
  1482. window.screenSta = 'tour';
  1483. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  1484. ev.__callback = (imgData, info)=> {
  1485. this.uploadGuide(imgData, info, renew, insideFolder)
  1486. };
  1487. window.dispatchEvent(ev);
  1488. }
  1489. EditGuide.prototype.init = function(data, data2) {
  1490. this.createDom(data, data2);
  1491. //this.tourAudio = data2.tourAudio || {};
  1492. var that = this;
  1493. //点击添加导览
  1494. $('.addTour .innerBtn').eq(0).on("click", function () {
  1495. this.addFolderDom({name:"区域"+($("#tourList .listItem").length+1) } );//点击增加一段导览
  1496. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight //scroll to bottom
  1497. }.bind(this));
  1498. $('.addTour .innerBtn').eq(1).on("click", function () {
  1499. this.snapATourView()//点击截取视图
  1500. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight
  1501. }.bind(this));
  1502. $('.snapATourView .innerBtn').on("click", function() {
  1503. this.snapATourView(null,true);//folder内点击截取视图
  1504. $("#tourItemList ul")[0].scrollTop = $("#tourItemList ul")[0].scrollHeight
  1505. }.bind(this));
  1506. $('#renewTourBtn').on("click", function() { // 重新截取视图
  1507. this.snapATourView(this, !!this.editingFolderLi);
  1508. }.bind(this));
  1509. // 确认并保存导览信息
  1510. $('#tourFolderEdit .tourSubmit').on("click", function() {
  1511. this.completeFolder();
  1512. }.bind(this));
  1513. $('#tourItemEdit .tourSubmit').on("click", function() {
  1514. this.completeItem();
  1515. }.bind(this));
  1516. //点击导览编辑窗口右上角的关闭按钮
  1517. /* $("#tourItemEdit a.close, button.cancel").on("click", function() {
  1518. that.targetTourPoint[0].musicSta = true; ///??????????
  1519. // 取消操作, 重置状态
  1520. that.tourDetail.addClass("atRight");
  1521. }); */
  1522. //导览目录
  1523. $("#tourList").on("click", function(e) {
  1524. var target = $(e.target);
  1525. let folder = searchParent(e.target, { className: 'listItem' }, 7);
  1526. if(!folder)return;//可能点到了item
  1527. if (target.hasClass("del")) {
  1528. e.stopPropagation();
  1529. target.siblings(".DelConfirm").addClass("active");
  1530. } else {
  1531. if (target.hasClass("DelConfirm")) {
  1532. e.stopPropagation();
  1533. $(folder).remove()
  1534. //that.removeFolder(folder);//删除
  1535. } else {
  1536. if (target.hasClass("title") || target.hasClass("icon")) {
  1537. that.editFolder(folder)//编辑
  1538. }
  1539. }
  1540. }
  1541. });
  1542. //编辑item
  1543. $('.tourList ul').on('click', function(e) {
  1544. var target = $(e.target);
  1545. let itemDom = searchParent(e.target, { className: 'guideItem' }, 7);
  1546. if(!itemDom)return;//可能点到了folder
  1547. if(searchParent(e.target, { className: 'preview' })){
  1548. var choice = confirm("你确定删除吗?");
  1549. if (choice) {
  1550. var ul = searchParent(e.target, { className: 'tourList' })
  1551. target.closest('li').remove();
  1552. reIndexTourList(ul)
  1553. } else {
  1554. return false
  1555. }
  1556. }else{
  1557. that.editItem(itemDom);
  1558. }
  1559. })
  1560. //fyz 拖拽以改变顺序
  1561. let tourListNode = $("#tourList>ul")[0];
  1562. let tourItemListNode = $("#tourItemList>ul")[0];
  1563. let draging = null;
  1564. let dragStart = (event)=> {
  1565. event.dataTransfer.setData("te", event.target.innerText); //不能使用text,firefox会打开新tab
  1566. draging = event.target;
  1567. }
  1568. let dragOver = (event)=>{
  1569. event.preventDefault();
  1570. let target = searchParent(event.target, { tagName: 'LI' }, 7); //event.target.parentNode.parentNode;
  1571. // 判断dragover是否发生在LI元素上
  1572. if ((target.classList.contains('guideItem') || target.classList.contains('listItem')) && target !== draging ) {
  1573. let dragingIndex = $(draging).index()//draging.querySelector('#index');
  1574. let targetIndex = $(target).index()//target.querySelector('#index');
  1575. var targetRect = target.getBoundingClientRect();
  1576. var dragingRect = draging.getBoundingClientRect();
  1577. if (target && target.animated) {
  1578. return;
  1579. }
  1580. let ulElem = target.parentNode;
  1581. // 寻找到 ul节点
  1582. if (getIndex(draging) < getIndex(target)) {
  1583. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1584. // 交换两个节点的序号
  1585. if(event.clientY<targetRect.top+targetRect.height*0.3)return
  1586. ulElem.insertBefore(draging, target.nextSibling);
  1587. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];// 交换两个节点的序号
  1588. } else {
  1589. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1590. if(event.clientY>targetRect.bottom-targetRect.height*0.3)return
  1591. ulElem.insertBefore(draging, target);
  1592. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1593. }
  1594. _animate(dragingRect, draging);
  1595. _animate(targetRect, target);
  1596. var ul = searchParent(event.target, { className: 'tourList' })
  1597. reIndexTourList(ul)
  1598. }
  1599. }
  1600. tourListNode.ondragstart = dragStart
  1601. tourItemListNode.ondragstart = dragStart
  1602. tourListNode.ondragover = dragOver
  1603. tourItemListNode.ondragover = dragOver
  1604. //音乐
  1605. this.musicBox = musicPlayBoxBind($(".snapTour .audio.mediaUpload"), null, ()=>{
  1606. (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
  1607. })
  1608. /*
  1609. var mediaUpload = $(".snapTour .audio.mediaUpload");
  1610. var that = this;
  1611. mediaUpload.find("input").on("change", function(e) {
  1612. if(!e.target.files.length) return;
  1613. var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  1614. var file = e.target.files[0];
  1615. mediaDom.find(".innerBtn").text("替换");
  1616. mediaDom.find(".playBox").removeClass("hide");
  1617. mediaDom.find(".title").text(file.name);
  1618. mediaDom.find('#query-bgm').attr('href', URL.createObjectURL(file));
  1619. //that.editingFolderLi.musicSta = true;
  1620. });
  1621. mediaUpload.find("input").on("click", function() {
  1622. mediaUpload
  1623. });
  1624. //删除音乐
  1625. mediaUpload.on("click", ".delete", function(e) {
  1626. var mediaDom = $(searchParent(e.target, { className: '.mediaUpload' }));
  1627. mediaDom.find('#query-bgm').attr('href', "");
  1628. mediaDom.find(".playBox").addClass("hide");
  1629. mediaDom.find(".innerBtn").text("上传");
  1630. mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
  1631. //that.editingFolderLi.musicSta = false;
  1632. (that.editingFolderLi || that.editingItemLi).data.musicInfo = {}//直接删除 不可逆
  1633. }) */
  1634. }
  1635. function musicPlayBoxBind($dom, addCallback, delCallback){
  1636. var musicBox = {
  1637. hasMusic:false,
  1638. show: function(mediaDom, name, url){
  1639. mediaDom = mediaDom || $dom
  1640. mediaDom.find(".innerBtn").text("替换");
  1641. mediaDom.find(".playBox").removeClass("hide");
  1642. mediaDom.find(".title").text(name);
  1643. mediaDom.find('#query-bgm').attr('href', url);
  1644. musicBox.hasMusic = true
  1645. },
  1646. addMusic : function(e) {
  1647. if(!e.target.files.length) return;
  1648. var file = e.target.files[0];
  1649. if (!/audio\/\w+/.test(file.type)) {
  1650. alert("文件必须为音乐!");
  1651. return false;
  1652. }
  1653. //限制大小不大于8m
  1654. if (!restrictedSize(file, _musicMaxWeight)) {
  1655. return false
  1656. }
  1657. var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  1658. musicBox.show(mediaDom, file.name, URL.createObjectURL(file))
  1659. addCallback && addCallback(file)
  1660. },
  1661. hide : function(e) {
  1662. var mediaDom = e ? $(searchParent(e.target, { className: 'mediaUpload' })) : $dom
  1663. mediaDom.find('#query-bgm').attr('href', "");
  1664. mediaDom.find(".playBox").addClass("hide");
  1665. mediaDom.find(".innerBtn").text("上传");
  1666. mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
  1667. musicBox.hasMusic = false
  1668. delCallback && delCallback()
  1669. }
  1670. }
  1671. $dom.find("input").on("change", musicBox.addMusic)
  1672. /* $dom.find("input").on("click", function() {
  1673. mediaUpload
  1674. }); */
  1675. //删除音乐
  1676. $dom.on("click", ".delete", musicBox.hide)
  1677. return musicBox;
  1678. }
  1679. function reIndexTourList(ul) {
  1680. Array.from($(ul).find('li.guideItem')).forEach((li,index)=>{
  1681. $(li).find("div:first-child span").text(index + 1);
  1682. })
  1683. }
  1684. EditGuide.prototype.addFolderDom = function( tourData){
  1685. var $folder = $("<li class='listItem' draggable='true'>" + "<div class=icon></div>" + "<div class=title >" + (tourData.name || "") + "</div>" + "<div class=DelConfirm>确定删除</div>" + "<div class=del></div>" + "</li>");
  1686. $folder[0].tourItemDoms = [] //记录所有item的li dom
  1687. $folder[0].tourData = tourData //注: data中的locations不会更新,保存时直接读取li
  1688. $("#tourList ul").append($folder);
  1689. return $folder
  1690. }
  1691. EditGuide.prototype.getItemDom = function(title, img) {
  1692. return '<li draggable="true" class="guideItem">' + '<div>' + '<span id="index"></span>' + '<div class="line"></div>' + '</div>' + '<div>' + '<span class="guide-name" >' + title + '</span>' + '<input maxlength="14" class="hide" data-oper=tour-input>' + '</div>' + '<div class="preview" >' + '<div id="tourBg" style="background-image: url(' + img + ');" >' + '</div>' + '</div>' + '</li >';
  1693. }
  1694. EditGuide.prototype.createDom = function(data, data2) {
  1695. var that = this;
  1696. var tourAudio = data2.tourAudio || {};
  1697. data.model.images.forEach((Info,index)=>{
  1698. if(Info.locations){//是folder
  1699. var $folder = this.addFolderDom(Info)
  1700. // 音频链接
  1701. Info.locations = Info.locations.filter(e=>e)
  1702. Info.locations.forEach(function(info, index) {
  1703. if (info.thumbnail_signed_src) {
  1704. var $li = $(that.getItemDom( info.name, info.thumbnail_signed_src));
  1705. $li[0].tourData = info
  1706. $folder[0].tourItemDoms.push($li[0])
  1707. }
  1708. })
  1709. }else{//是散落在外的item
  1710. if (Info.thumbnail_signed_src) {
  1711. var $li = $(that.getItemDom(Info.name, Info.thumbnail_signed_src));
  1712. $li[0].tourData = Info
  1713. // 音频链接
  1714. $li[0].tourData.musicInfo = $li[0].tourData.musicInfo || tourAudio[Info.sid] || {}//新的music数据统一写在每个info下
  1715. $("#tourList ul").append($li)
  1716. /* if (Info.sid in tourAudio && tourAudio[info.sid].music && tourAudio[info.sid].music !== '') {
  1717. //$li[0].musicUrl = tourAudio[info.sid].music;
  1718. $li[0].musicInfo = tourAudio[info.sid]
  1719. } */
  1720. }
  1721. }
  1722. })
  1723. reIndexTourList($("#tourList")[0])
  1724. }
  1725. //暂时不实时更新左侧场景,所以信息全写在UI上,不保存data
  1726. EditGuide.prototype.editFolder = function(folderDom){
  1727. this.editingFolderLi = folderDom;
  1728. $("#tourFolderEdit").removeClass('atRight');
  1729. $("#tourFolderEdit .tourName input").val( $(folderDom).find('.title').text()||'');
  1730. //$("#folderTourSwitch input").prop('checked', folderDom.tourData.momentTour === 'black');
  1731. var momentTour = folderDom.tourData.momentTour || "default"
  1732. $("#folderTourSwitch li").removeClass('chosen')
  1733. $("#folderTourSwitch li[index="+ momentTour +"]").addClass('chosen');
  1734. folderDom.tourItemDoms.forEach(li=>{
  1735. $("#tourItemList>ul").append(li)
  1736. })
  1737. reIndexTourList($("#tourItemList>ul")[0])
  1738. //判断当前点是否有导览音频
  1739. //target[0].musicSta = true;
  1740. //var audio = this.tourAudio[target.closest('li')[0].data.sid];
  1741. var musicInfo = this.editingFolderLi.tourData.musicInfo //audio ? audio.music : null;
  1742. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  1743. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  1744. /* $('#tourFolderEdit').find(".audio .playBox").removeClass("hide");
  1745. $('#tourFolderEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
  1746. $('#tourFolderEdit').find(".audio .submit").text("替换");
  1747. $('#tourFolderEdit').find(".title").text(musicName); */
  1748. this.musicBox.show($('#tourFolderEdit .mediaUpload'), musicName, "//" + musicInfo.music)
  1749. } else {
  1750. /* $('#tourFolderEdit').find(".audio .playBox").addClass("hide");
  1751. $('#tourFolderEdit').find(".audio .submit").text("上传"); */
  1752. this.musicBox.hide()
  1753. }
  1754. }
  1755. /**
  1756. * @author fyz 编辑单个导览item
  1757. * @param {any} target 所点击的导览点
  1758. */
  1759. EditGuide.prototype.editItem = function(li) {
  1760. //this.targetTourPoint = target;
  1761. this.editingItemLi = li
  1762. // 记录当前编辑的导览点
  1763. var that = this;
  1764. $('#tourItemEdit').removeClass('atRight');
  1765. $('#tourItemEdit .tourName input').val( $(li).find('.guide-name').text() );
  1766. var momentTour = li.tourData.momentTour || "default"
  1767. $("#tourSwitch_Slice li").removeClass('chosen')
  1768. $("#tourSwitch_Slice li[index="+ momentTour +"]").addClass('chosen');
  1769. var metadata = JSON.parse(li.tourData.metadata);
  1770. if(metadata.scan_id != 'outside'){
  1771. var pano = player.model.panos.index[metadata.scan_id]
  1772. if(pano){
  1773. var q = new THREE.Quaternion().copy(metadata.camera_quaternion);
  1774. player.flyToPano({
  1775. pano: pano,
  1776. quaternion: q,
  1777. zoomLevel: metadata.zoom
  1778. })
  1779. }
  1780. }
  1781. if(!this.editingFolderLi){//在外的item, 可以上传音乐
  1782. $('#tourItemEdit .mediaUpload').removeClass('hide')
  1783. var musicInfo = li.tourData.musicInfo //audio ? audio.music : null;
  1784. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  1785. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  1786. /* $('#tourItemEdit').find(".audio .playBox").removeClass("hide");
  1787. $('#tourItemEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
  1788. $('#tourItemEdit').find(".audio .submit").text("替换");
  1789. $('#tourItemEdit').find(".title").text(musicName); */
  1790. this.musicBox.show($('#tourItemEdit .mediaUpload'), musicName, "//" + musicInfo.music)
  1791. } else {
  1792. this.musicBox.hide()
  1793. /* $('#tourItemEdit').find(".audio .playBox").addClass("hide");
  1794. $('#tourItemEdit').find(".audio .submit").text("上传"); */
  1795. }
  1796. }else{
  1797. $('#tourItemEdit .mediaUpload').addClass('hide')
  1798. }
  1799. }
  1800. EditGuide.prototype.completeFolder = function(){//点击完成
  1801. var tourName = $('#tourFolderEdit .tourName input').val() //|| this.targetTourPoint.context.innerText;
  1802. $(this.editingFolderLi).find(".title").text(tourName)
  1803. //this.editingFolderLi.tourData.momentTour = $("#folderTourSwitch input").is(':checked') ? "black" : 'walk'
  1804. var momentTour = $("#folderTourSwitch li.chosen").attr("index");
  1805. this.editingFolderLi.tourData.momentTour = momentTour != 'default' ? momentTour : null;
  1806. this.editingFolderLi.tourItemDoms = Array.from($('#tourItemList ul li'));
  1807. var done = ()=>{
  1808. $("#tourFolderEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
  1809. this.editingFolderLi = null
  1810. $("#tourFolderEdit").addClass('atRight');
  1811. $(".edit-loading").addClass('hide');
  1812. $("#tourItemList>ul").html('')
  1813. }
  1814. //save导览音乐
  1815. var tourAudio = $('#tourFolderEdit .mediaUpload input');
  1816. // 记录音频名称
  1817. //判断当前编辑的导览点位是否已上传音乐
  1818. if (tourAudio[0].files.length > 0/* && this.targetTourPoint[0].musicSta */) { //有input文件
  1819. $(".edit-loading").removeClass('hide');
  1820. var musicName = $('#tourFolderEdit .mediaUpload .title').text();
  1821. new Promise( (resolve, reject)=> {
  1822. uploadMiuse(tourAudio[0].files[0], function(res) {
  1823. resolve(res.data);
  1824. })
  1825. } ).then( (src)=>{
  1826. var audio = new Audio();
  1827. audio.src = src;
  1828. audio.onloadedmetadata = ()=>{
  1829. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  1830. srcArr[0] = '';
  1831. src = srcArr.join('/');
  1832. //var sid = this.editingFolderLi.data.sid
  1833. //that.tourAudio[sid] = {
  1834. this.editingFolderLi.tourData.musicInfo = {
  1835. "name": musicName,
  1836. "music": '/' + src,
  1837. "time": Math.round(audio.duration * 1000 + 1000)
  1838. }
  1839. done()
  1840. }
  1841. })
  1842. }else done()
  1843. }
  1844. EditGuide.prototype.completeItem = function() {//点击完成
  1845. var done = ()=>{
  1846. $("#tourItemEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
  1847. this.editingItemLi = null
  1848. $("#tourItemEdit").addClass('atRight');
  1849. $(".edit-loading").addClass('hide');
  1850. }
  1851. var tourName = $('#tourItemEdit .tourName input').val()
  1852. $(this.editingItemLi).find('.guide-name').text(tourName)
  1853. var momentTour = $("#tourSwitch_Slice li.chosen").attr("index");
  1854. this.editingItemLi.tourData.momentTour = momentTour != 'default' ? momentTour : null;
  1855. //save导览音乐
  1856. var tourAudio = $('#tourItemEdit .mediaUpload input');
  1857. //判断当前编辑的导览点位是否已上传音乐
  1858. if (!this.editingFolderLi && tourAudio[0].files.length > 0) { //有input文件
  1859. $(".edit-loading").removeClass('hide');
  1860. var musicName = $('#tourItemEdit .mediaUpload .title').text();
  1861. new Promise( (resolve, reject)=>{
  1862. uploadMiuse(tourAudio[0].files[0], function(res) {
  1863. resolve(res.data);
  1864. })
  1865. } ).then( (src)=>{
  1866. var audio = new Audio();
  1867. audio.src = src;
  1868. audio.onloadedmetadata = ()=>{
  1869. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  1870. srcArr[0] = '';
  1871. src = srcArr.join('/');
  1872. //that.tourAudio[sid] = {
  1873. this.editingItemLi.tourData.musicInfo = {
  1874. "name": musicName,
  1875. "music": '/' + src,
  1876. "time": Math.round(audio.duration * 1000 + 1000)
  1877. }
  1878. done()
  1879. }
  1880. })
  1881. }else done()
  1882. }
  1883. /**
  1884. * @author fyz 2019.07.31
  1885. * @description uploadGuide方法新增参数renew状态码, 表示是否重新录制当前导览, 新增targetTourPoint, 记录当前的导览点元素
  1886. */
  1887. EditGuide.prototype.uploadGuide = function(urlData, guide, renew, insideFolder) {
  1888. var that = this;
  1889. uploadImg(urlData, function(rs) {
  1890. if (rs.code === 0) {
  1891. //var editGuide = new EditGuide();
  1892. var sid = rs.data.substring(rs.data.lastIndexOf('/') + 1, rs.data.lastIndexOf('.'));
  1893. var thumbnail_signed_src = rs.data;
  1894. var args = JSON.parse("{" + guide + "}");
  1895. args.sid = sid;
  1896. args.name = sid;
  1897. args.thumbnail_signed_src = thumbnail_signed_src;
  1898. args.metadata = JSON.stringify({
  1899. camera_mode: args.metadata.camera_mode,
  1900. camera_position: {
  1901. x: args.metadata.camera_position[0],
  1902. y: args.metadata.camera_position[1],
  1903. z: args.metadata.camera_position[2]
  1904. },
  1905. camera_quaternion: {
  1906. x: args.metadata.camera_quaternion[0],
  1907. y: args.metadata.camera_quaternion[1],
  1908. z: args.metadata.camera_quaternion[2],
  1909. w: args.metadata.camera_quaternion[3]
  1910. },
  1911. ortho_zoom: args.metadata.ortho_zoom,
  1912. scan_id: args.metadata.scan_id || "outside",
  1913. //这个"outside"不能随便改成别的
  1914. /* final_angle: 110,
  1915. is_ortho: false, */
  1916. zoom: args.metadata.zoom // fyz zoom是内部计算的zoomLevel, 乘以系数1.06才是实际缩放倍数
  1917. })
  1918. if (renew/* && target */) { // 重新录制导览
  1919. // 更新数据
  1920. var musicInfo = insideFolder || that.editingItemLi.tourData.musicInfo;
  1921. musicInfo && (args.musicInfo = musicInfo);
  1922. $(that.editingItemLi).find('#tourBg')[0].style.backgroundImage = 'url(' + args.thumbnail_signed_src + ')';
  1923. //args.name = insideFolder $('#tourItemEdit').find('#tourNameInput').val()
  1924. /* var oldId = target.closest('li')[0].data.sid;
  1925. that.tourAudio[args.sid] = that.tourAudio[oldId];
  1926. // 新生成的id指向以前的导览音频
  1927. delete that.tourAudio[oldId];
  1928. // 删除导览音频中的旧导览id */
  1929. that.editingItemLi.tourData = args;
  1930. //target.text(args.name); // 更新导览列表中的导览名称 //不改名字
  1931. //$('#tourItemEdit').find('#tourNameInput').val(args.name); // 修改输入框内容
  1932. } else {
  1933. var $li = $(that.getItemDom(args.name, args.thumbnail_signed_src));
  1934. $li[0].tourData = args;
  1935. var $ul = insideFolder ? $("#tourItemList>ul") : $("#tourList>ul")
  1936. $ul.append($li);
  1937. reIndexTourList($ul[0])
  1938. }
  1939. }
  1940. })
  1941. }
  1942. EditGuide.prototype.getSavingInfo = function(){
  1943. var data = []
  1944. Array.from($("#tourList ul li")).forEach(dom=>{
  1945. if(dom.classList.contains("guideItem")){//item
  1946. dom.tourData.name = $(dom).find('.guide-name').text()
  1947. data.push(dom.tourData)
  1948. }else{//folder
  1949. var dataFolder = dom.tourData;
  1950. dataFolder.name = $(dom).find('.title').text()
  1951. dataFolder.locations = dom.tourItemDoms.map(li => li.tourData )
  1952. data.push(dataFolder)
  1953. }
  1954. })
  1955. return data
  1956. }
  1957. /* -- 以下是一些公用的方法 -- */
  1958. //限制大小
  1959. var restrictedSize = function(file, _size) {
  1960. //限制大小不大于8m
  1961. var fileSize = 0;
  1962. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  1963. if (isIE && !file) {
  1964. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  1965. var _file = fileSystem.GetFile(filepath);
  1966. fileSize = _file.Size;
  1967. } else {
  1968. fileSize = file.size;
  1969. }
  1970. var size = fileSize / 1024;
  1971. var RSize = _size * 1024;
  1972. if (size > RSize) {
  1973. alert("文件不能大于" + _size + "M");
  1974. return false;
  1975. }
  1976. if (size <= 0) {
  1977. alert("文件大小不能为0M!");
  1978. return false;
  1979. }
  1980. return true
  1981. }
  1982. //上传音乐
  1983. var uploadMiuse = function(file, callback) {
  1984. uploadFile(file, 'audio', callback);
  1985. }
  1986. $(".toolRight .music .itemTitle span").text(`背景音乐 (<${_musicMaxWeight}M)`)
  1987. //上传图片
  1988. function uploadImg(urlData, callback, fileName) {
  1989. //console.log('urlData',urlData);
  1990. var bytes = window.atob(urlData.split(',')[1]);
  1991. //去掉url的头,并转换为byte
  1992. //处理异常,将ascii码小于0的转换为大于0
  1993. var ab = new ArrayBuffer(bytes.length);
  1994. var ia = new Uint8Array(ab);
  1995. for (var i = 0; i < bytes.length; i++) {
  1996. ia[i] = bytes.charCodeAt(i);
  1997. }
  1998. var blob = new Blob([ab],{
  1999. type: 'image/jpeg',
  2000. });
  2001. uploadFile(blob, 'hot/images', callback, fileName);
  2002. }
  2003. //上传文件
  2004. function uploadFile(file, type, callback, fileName) {
  2005. $(".edit-loading").removeClass("hide");
  2006. var formData = new FormData()
  2007. formData.append('name', number)
  2008. formData.append('dir', type)
  2009. formData.append('random', true)
  2010. //formData.append('file', file)
  2011. formData.append("file", file, fileName);
  2012. let url = cmp ? ('/api/scene/upload/' + number) : ('/manage/scene/upload/' + number)
  2013. $.ajax({
  2014. url: ceshi + url,
  2015. data: formData,
  2016. headers: {
  2017. token: token
  2018. },
  2019. dataType: 'json',
  2020. type: 'POST',
  2021. cache: false,
  2022. //上传文件无需缓存
  2023. processData: false,
  2024. //用于对data参数进行序列化处理 这里必须false
  2025. contentType: false,
  2026. //必须
  2027. success: function(rs) {
  2028. if(rs.code === 0){
  2029. callback(rs, file);
  2030. $(".edit-loading").addClass("hide");
  2031. }else if (rs.code === 5001) {
  2032. alert('请重新登录')
  2033. localStorage.dcj_token = ''
  2034. location.reload()
  2035. }else{
  2036. alert(`uploadFile (url:${url}) code : ${rs.code} \n${rs.msg}`)
  2037. }
  2038. }
  2039. })
  2040. }
  2041. function _animate(prevRect, target) {
  2042. var ms = 300;
  2043. if (ms) {
  2044. var currentRect = target.getBoundingClientRect();
  2045. if (prevRect.nodeType === 1) {
  2046. prevRect = prevRect.getBoundingClientRect();
  2047. }
  2048. _css(target, 'transition', 'none');
  2049. _css(target, 'transform', 'translate3d(' + (prevRect.left - currentRect.left) + 'px,' + (prevRect.top - currentRect.top) + 'px,0)');
  2050. target.offsetWidth;
  2051. // 触发重绘
  2052. //放在timeout里面也可以
  2053. // setTimeout(function() {
  2054. // _css(target, 'transition', 'all ' + ms + 'ms');
  2055. // _css(target, 'transform', 'translate3d(0,0,0)');
  2056. // }, 0);
  2057. _css(target, 'transition', 'all ' + ms + 'ms');
  2058. _css(target, 'transform', 'translate3d(0,0,0)');
  2059. clearTimeout(target.animated);
  2060. target.animated = setTimeout(function() {
  2061. _css(target, 'transition', '');
  2062. _css(target, 'transform', '');
  2063. target.animated = false;
  2064. }, ms);
  2065. }
  2066. }
  2067. //给元素添加style
  2068. function _css(el, prop, val) {
  2069. var style = el && el.style;
  2070. if (style) {
  2071. if (val === void 0) {
  2072. if (document.defaultView && document.defaultView.getComputedStyle) {
  2073. val = document.defaultView.getComputedStyle(el, '');
  2074. } else if (el.currentStyle) {
  2075. val = el.currentStyle;
  2076. }
  2077. return prop === void 0 ? val : val[prop];
  2078. } else {
  2079. if (!(prop in style)) {
  2080. prop = '-webkit-' + prop;
  2081. }
  2082. style[prop] = val + (typeof val === 'string' ? '' : 'px');
  2083. }
  2084. }
  2085. }
  2086. function upload($files, type, cb) {
  2087. var length = $files.length
  2088. var rcount = 0
  2089. var result = []
  2090. Array.from($files).forEach(function(dFile, index) {
  2091. //a 标签的success 是用来判断是否是已经上传过的文件
  2092. //attr-thum 属性是视频的图片
  2093. //videoURL 是判断是否有视频
  2094. var $file = $(dFile)
  2095. var $image = type == 'videos' ? $file.find('img.play-video') : $file.find('img')
  2096. if ($file.hasClass('success')) {//已经上传过,有链接
  2097. if ($file.attr('attr-thum')) {//视频的封面
  2098. result[index] = $file.attr('attr-thum')
  2099. } else if ($image.attr('videoURL')) {//视频
  2100. result[index] = $image.attr('videoURL')
  2101. } else {
  2102. result[index] = $image.attr('src')
  2103. }
  2104. return success(++rcount);
  2105. } else {
  2106. switch ($file[0].localName) {
  2107. case "input":
  2108. dFile = $file[0]
  2109. break;
  2110. case "span"://封面
  2111. dFile = $file.find('input')[0];
  2112. break;
  2113. case "a"://重传的图or视频
  2114. dFile = {files:[$file[0].file]}
  2115. //dFile = $file.find('input')[0];
  2116. break;
  2117. default:
  2118. dFile = $file.closest("li").find('.upload input')[0];
  2119. break;
  2120. }
  2121. // dFile = $file[0].localName === "input" ? $file[0] : $file[0].localName === "span" ? $file.find('input')[0] : $file.closest("li").find('.upload input')[0];
  2122. }
  2123. var file = (dFile.files && dFile.files[0]) || '';
  2124. if (!file)
  2125. return success(++rcount);
  2126. uploadFile(file, 'hot/' + type, function(rs) {
  2127. //似乎所有图保存路径都是这个hot/前缀。图地址 :"场景id/edit/重新生成的文件名.原后缀", 展示页面也是。
  2128. if (rs.code === 0) {
  2129. result[index] = rs.data
  2130. }
  2131. ;success(++rcount);
  2132. })
  2133. })
  2134. //判断当前队列元素是否处理成功
  2135. function success() {
  2136. if (rcount === length) {
  2137. cb(result)
  2138. }
  2139. }
  2140. success()
  2141. }
  2142. function getIndex(el) {
  2143. let index = 0;
  2144. if (!el || !el.parentNode) {
  2145. return -1;
  2146. }
  2147. while (el && (el = el.previousElementSibling)) {
  2148. index++;
  2149. }
  2150. return index;
  2151. }
  2152. dataURLtoBlob = function(dataurl) {
  2153. //将base64转换blob
  2154. var arr = dataurl.split(',')
  2155. , mime = arr[0].match(/:(.*?);/)[1]
  2156. , bstr = atob(arr[1])
  2157. , n = bstr.length
  2158. , u8arr = new Uint8Array(n);
  2159. while (n--) {
  2160. u8arr[n] = bstr.charCodeAt(n);
  2161. }
  2162. return new Blob([u8arr],{
  2163. type: mime
  2164. });
  2165. }
  2166. ;
  2167. //=========================
  2168. var eachMaxWeights = {
  2169. //大小限制
  2170. "photo": 10,
  2171. "video": 1000,//50, expand size for overlayVideo
  2172. //20,
  2173. "audio": 10, //5
  2174. "model": 1 //5
  2175. }
  2176. var supportTypes = {
  2177. //支持后缀
  2178. "photo": ["jpg", "png", "jpeg", "bmp", "gif"],
  2179. "audio": ["mp3", "aac", "ogg", "wav"/* , "m4a" */],
  2180. "video": ["mp4", "mov"/* ,"webm", "rmvb", "wmv" */],//ios:mov
  2181. 'model':["obj"]
  2182. }
  2183. function getExt(name) {
  2184. //后缀
  2185. if (name.indexOf('.') > -1) {
  2186. var a = name.split(".");
  2187. return a.pop();
  2188. } else {
  2189. return '';
  2190. }
  2191. }
  2192. function detectType(fileName) {
  2193. //检测文件后缀类型
  2194. console.log("名:" + fileName)
  2195. var ext = getExt(fileName);
  2196. console.log("后缀:" + ext)
  2197. //不一定所有浏览器都可以
  2198. var type;
  2199. //仅能根据后缀判断类型,尽管后缀可能被修改。 其他方法如file.type和base64开头的字符串均是根据后缀。
  2200. for (var i in supportTypes) {
  2201. if (supportTypes[i].indexOf(ext.toLowerCase()) > -1) {
  2202. type = i;
  2203. break;
  2204. }
  2205. }
  2206. if (type) {
  2207. return type;
  2208. } else {
  2209. return false;
  2210. }
  2211. }
  2212. //手机上的相片会不会太大?
  2213. var detectWeights = function(file, type) {
  2214. //检测大小
  2215. var size = file.size / 1024 / 1024;
  2216. console.log("weight" + size)
  2217. var over;
  2218. if (size > eachMaxWeights[type]) {
  2219. over = Math.ceil(size * 100) / 100;
  2220. }
  2221. return over;
  2222. }
  2223. var exitUpload = function(input) {
  2224. $('.waiting').removeClass('showloading');
  2225. input.value = "";
  2226. }
  2227. var inputMedia = function(options, type, e) {
  2228. var input = e.target;
  2229. if (!window.FileReader) {
  2230. alert('您的浏览器不支持上传文件');
  2231. exitUpload(input);
  2232. return;
  2233. } else if (e.target.files.length === 0) {
  2234. /* exitUpload(input); */
  2235. return;
  2236. }
  2237. $('.waiting').addClass('showloading');
  2238. var file = e.target.files[0];
  2239. var elemType = type;
  2240. var inputType = detectType(file.name);
  2241. var chType = {
  2242. "photo": '图片',
  2243. "video": '视频',
  2244. "audio": '音乐',
  2245. 'model': '模型'
  2246. }
  2247. var overWeight = detectWeights(file, inputType);
  2248. if (elemType) {
  2249. //有指定其中一种类型
  2250. if (inputType != elemType) {
  2251. alert("您选择的不是浏览器支持的" + chType[elemType] + '文件,请重新选择');
  2252. exitUpload(e.target);
  2253. return;
  2254. }
  2255. } else {
  2256. if (!options.enableTypes.includes(inputType)) {
  2257. var text = "";
  2258. options.enableTypes.forEach((type,index)=>{
  2259. text += ((index != 0 ? " / " : "") + chType[elemType])
  2260. }
  2261. )
  2262. alert("您选择的不是浏览器支持的" + text + '文件,请重新选择');
  2263. exitUpload(e.target);
  2264. return;
  2265. }
  2266. }
  2267. if (overWeight) {
  2268. alert(`文件过大(${overWeight}兆),不能大于${eachMaxWeights[inputType]} 兆`)
  2269. exitUpload(e.target);
  2270. return;
  2271. }
  2272. var loadError = function() {
  2273. exitUpload(e.target);
  2274. alert(`文件出错, 无法加载此${chType[inputType]}文件。 文件可能损坏,或者浏览器不支持,或者后缀与文件不匹配。建议在IE以外的浏览器上传`)
  2275. }
  2276. deal(type);
  2277. function deal(type) {
  2278. console.log('开始deal文件')
  2279. var reader = new FileReader();
  2280. //reader.name = file.name;
  2281. if(type == 'model'){
  2282. reader.readAsText( file );
  2283. }else{
  2284. reader.readAsDataURL(file);
  2285. }
  2286. reader.onload = function(evt) {
  2287. if (inputType == "model") {
  2288. var object = new THREE.OBJLoader().parse( evt.target.result );
  2289. object.name = file.name;
  2290. player.model.add(object)
  2291. //object.children[5].position.set(0,10,0)
  2292. window.extModel = object
  2293. $('.waiting').removeClass('showloading');
  2294. return;
  2295. }
  2296. var blob = dataURLtoBlob(evt.target.result);
  2297. var blobSrc = window.URL.createObjectURL(blob);
  2298. if (inputType == "photo") {
  2299. /* EXIF.getData(file, function () {
  2300. //获取相片旋转
  2301. EXIF.getAllTags(this);
  2302. var orient = EXIF.getTag(this, 'Orientation');
  2303. var img = new Image();
  2304. img.src = evt.target.result;
  2305. img.onload = function (e) { //这时img才有宽高,才能赋予texture宽高
  2306. var smallerImg = CompressImg(e.target, {
  2307. weight: blob.size,
  2308. maxWeight: 0.5 * 1024 * 1024,
  2309. maxSize: 1480
  2310. });
  2311. //最大500k
  2312. smallerImg.onload = function () {
  2313. var f = function (resultImg) {//处理结束回调
  2314. options.photoDone(resultImg)
  2315. $('.waiting').removeClass('showloading');
  2316. }
  2317. Rotate(smallerImg, orient, f)
  2318. window.URL.revokeObjectURL(blobSrc);
  2319. }
  2320. }
  2321. .bind(this)
  2322. img.onerror = loadError;
  2323. }); */
  2324. var img = new Image();
  2325. img.src = blobSrc;
  2326. img.base64Src = evt.target.result;
  2327. img.file = file;
  2328. img.onload = function(e) {
  2329. options.photoDone(img)
  2330. $('.waiting').removeClass('showloading');
  2331. }
  2332. } else if (inputType == "video") {
  2333. var video = $('<video controls="controls" x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>')[0]
  2334. video.setAttribute("crossOrigin", 'Anonymous')
  2335. //要在src设置好前解决跨域
  2336. $(video).on('contextmenu', function() {
  2337. return false;
  2338. });
  2339. //禁止右键点击出现选项(尤其是下载选项)
  2340. $(video).attr('src', blobSrc);
  2341. //华为无法使用blobSrc,否则加载不出来
  2342. //$(video).attr('src', evt.target.result);
  2343. video.base64Src = evt.target.result;
  2344. var hasload = false;
  2345. var error = false;
  2346. var up = function() {
  2347. if (hasload)
  2348. return;
  2349. hasload = true;
  2350. options.videoDone(file, video)
  2351. $('.waiting').removeClass('showloading');
  2352. }
  2353. video.addEventListener('loadeddata', function(e) {
  2354. up()
  2355. })
  2356. //video.onerror = loadError;
  2357. video.onerror = function(e) {
  2358. console.log('error')
  2359. error = true;
  2360. loadError();
  2361. //将mp4改成mov后缀会error
  2362. }
  2363. } else if (inputType == "audio") {
  2364. //林俊波 new Howl For IE&Safari:
  2365. var sound = new Howl({
  2366. src: [blobSrc],
  2367. format: ["mp3"]
  2368. });
  2369. // Clear listener after first call.
  2370. sound.once('load', function() {
  2371. console.log('loaded sound')
  2372. sound.unload()
  2373. console.log("audio.onloadeddata");
  2374. var audio = new Audio;
  2375. audio.controls = "controls";
  2376. audio.src = blobSrc;
  2377. audio.base64Src = evt.target.result;
  2378. options.audioDone(file, audio)
  2379. $('.waiting').removeClass('showloading');
  2380. //}
  2381. });
  2382. sound.once('loaderror', function() {
  2383. loadError.apply(this, arguments)
  2384. console.log('loaderror sound')
  2385. });
  2386. // Fires when the sound finishes playing.
  2387. sound.on('end', function() {
  2388. console.log('Finished sound');
  2389. });
  2390. }
  2391. }
  2392. }
  2393. e.target.value = "";
  2394. //更改value会触发change
  2395. }
  2396. .bind(player)
  2397. //滑动条控件
  2398. var SlideBar = function(o) {
  2399. var scope = this;
  2400. this.name = o.name;
  2401. this.value = o.value;
  2402. //初始值
  2403. this.min = o.min != void 0 ? o.min : 0;
  2404. this.max = this.oriMax = o.max != void 0 ? o.max : 100;
  2405. this.noValue = o.noValue;
  2406. //是否数值输入
  2407. this.precision = o.precision;
  2408. //精度 保留几位小数
  2409. 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>'))
  2410. div.addClass('slider')
  2411. if (o.unitStr) {
  2412. div.find(".BarTxt").append($('<span>' + o.unitStr + '</span>'));
  2413. }
  2414. o.root.append(div);
  2415. this.line = $(".scrollBar", div);
  2416. this.knot = $(".scroll_Thumb", div);
  2417. o.noValue || (this.textArea = $(".scrollBarTxt", div));
  2418. this.track = $(".scroll_Track", div);
  2419. this.unitStr = o.unitStr;
  2420. //unitStr是单位字符串,比如角度的°。不能是数字
  2421. this.onchange = o.onchange;
  2422. this.percent = null;
  2423. this.dragStart = false;
  2424. this.offsetToBody = null;
  2425. this.getOffset();
  2426. this.checkError();
  2427. this.percent = this.getPercent();
  2428. o.noValue || this.displayValue();
  2429. this.moveKnot();
  2430. this.knotWidth = 0;
  2431. this.lineWidth = 0;
  2432. //this.waitValue;//等待要触发事件的值,防止崩溃
  2433. this.avoidCrash = o.avoidCrash;
  2434. this.realMax = !this.noValue ? o.realMax : null;
  2435. //如果传入realMax,代表可以通过输入数字修改最大值范围,最大值不可以超过realMax。
  2436. this.scrollUnit = (scope.max - scope.min) * 0.001;
  2437. if (this.precision != void 0) {
  2438. var prec = Math.pow(10, -this.precision);
  2439. this.scrollUnit < prec && (this.scrollUnit = prec);
  2440. } else {
  2441. //默认化为整数
  2442. this.scrollUnit < 1 && (this.scrollUnit = 1);
  2443. }
  2444. this.dragStartEvent = o.dragStartEvent;
  2445. this.line.on("mousedown touchstart", function(event) {
  2446. scope.dragStart = true;
  2447. scope.dragChange(event);
  2448. if (scope.dragStartEvent)
  2449. scope.dragStartEvent()
  2450. //if(o.avoidCrash && isMobile)scope.dealInterval();
  2451. });
  2452. !window.isMobile && this.line.on("mousewheel DOMMouseScroll wheel", function(event) {
  2453. event.preventDefault();
  2454. var v = event.originalEvent.deltaY > 0 ? -scope.scrollUnit : scope.scrollUnit;
  2455. scope.setValue(scope.value + v);
  2456. });
  2457. this.dragEndEvent = o.dragEndEvent;
  2458. var stop = function() {
  2459. if (scope.dragStart) {
  2460. scope.dragStart = false;
  2461. if (scope.dragEndEvent)
  2462. scope.dragEndEvent()
  2463. }
  2464. }
  2465. $(document).on("mouseup touchend", stop)
  2466. /* isMobile || */
  2467. $("#player").on("mouseup", stop)
  2468. var lastChangeTime = 0;
  2469. $(document).on("mousemove touchmove", function() {
  2470. if (scope.dragStart) {
  2471. /* if(isMobile && o.avoidCrash){
  2472. scope.lastDragEvent = event;
  2473. }else */
  2474. scope.dragChange(event);
  2475. }
  2476. })
  2477. o.noValue || this.textArea.on("change", function() {
  2478. var v = parseFloat(scope.textArea.val());
  2479. if (v != v)
  2480. //NaN
  2481. return;
  2482. scope.setValueFromOutside(v);
  2483. });
  2484. window.addEventListener("resize",()=>{
  2485. if(this.line[0].clientWidth){
  2486. this.getOffset()
  2487. this.moveKnot();
  2488. }
  2489. })
  2490. }
  2491. SlideBar.prototype.dealInterval = function() {
  2492. this.interval = setInterval(function() {
  2493. this.lastDragEvent && this.dragChange(this.lastDragEvent);
  2494. this.lastDragEvent = null
  2495. if (!this.dragStart)
  2496. clearInterval(this.interval)
  2497. }
  2498. .bind(this), 90)
  2499. }
  2500. SlideBar.prototype.changeLimit = function(o) {
  2501. if (o.min)
  2502. this.min = o.min;
  2503. if (o.max)
  2504. this.max = o.max;
  2505. }
  2506. SlideBar.prototype.getOffset = function() {
  2507. //为了检测鼠标位置需要获得相对body的offset
  2508. var left = this.line[0].offsetLeft;
  2509. var element = this.line[0];
  2510. while (element = element.offsetParent) {
  2511. left += element.offsetLeft;
  2512. }
  2513. this.offsetToBody = (left == 0) ? (this.offsetToBody || 0) : left;
  2514. //如果left为0,很可能是它不可见,那么最好使用旧的offsetToBody
  2515. }
  2516. SlideBar.prototype.InitOffset = function() {
  2517. //如果一开始scroller没有显示,要在显示时获取一下offset
  2518. this.getOffset();
  2519. this.getWidth();
  2520. this.moveKnot();
  2521. }
  2522. SlideBar.prototype.checkError = function() {
  2523. if (this.min >= this.max) {
  2524. console.log("scrollbar值有误 " + name);
  2525. return;
  2526. }
  2527. }
  2528. SlideBar.prototype.getPercent = function() {
  2529. return (this.value - this.min) / (this.max - this.min);
  2530. }
  2531. SlideBar.prototype.displayValue = function(value) {
  2532. //this.textArea.val(this.value + (this.unitStr ? " " + this.unitStr : ""));
  2533. if (value != void 0)
  2534. this.value = value;
  2535. this.textArea.val(this.value)
  2536. }
  2537. SlideBar.prototype.getWidth = function() {
  2538. this.knotWidth = this.knot.width();
  2539. this.lineWidth = this.line.width() - this.knotWidth
  2540. }
  2541. SlideBar.prototype.moveKnot = function() {
  2542. //this.getWidth();
  2543. var width = this.percent * this.lineWidth;
  2544. this.knot.css('left', width + "px")
  2545. if (this.track)
  2546. this.track.css('width', (width + this.knotWidth / 2) + "px")
  2547. }
  2548. SlideBar.prototype.bind = function(f) {
  2549. this.onchange = f;
  2550. }
  2551. SlideBar.prototype.setValue = function(v, noEvent, changeMax) {
  2552. //设置数值并改变knot位置 noEvent为true的话就可以不触发回调函数,仅仅改变显示
  2553. //if(this.value==v)return; //因为换选材质需要执行后面onchange才会带动preview的改变,所以这里一样还是执行,而拉动滑动条的部分值不变就不执行
  2554. if (this.precision != void 0) {
  2555. this.value = parseFloat(v.toFixed(this.precision))
  2556. } else {
  2557. //默认化为整数
  2558. this.value = Math.round(v);
  2559. }
  2560. if (changeMax && this.realMax != void 0) {
  2561. if (this.value > this.oriMax) {
  2562. this.value = Math.min(this.value, this.realMax);
  2563. this.changeLimit({
  2564. max: this.value
  2565. })
  2566. } else {
  2567. this.changeLimit({
  2568. max: this.oriMax
  2569. })
  2570. }
  2571. }
  2572. this.percent = this.getPercent();
  2573. var makeit = true;
  2574. if (this.onchange && !noEvent) {
  2575. var result = this.onchange(this.value);
  2576. //如果执行的函数不允许这个值,就不能变
  2577. if (result === false) {
  2578. makeit = false;
  2579. }
  2580. }
  2581. if (makeit) {
  2582. this.moveKnot();
  2583. //console.log("SlideBarV-"+this.name + " : "+this.value)
  2584. this.noValue || this.displayValue();
  2585. }
  2586. }
  2587. SlideBar.prototype.dragChange = function(event) {
  2588. //拖动时触发 计算数值
  2589. //this.getWidth();
  2590. //if(!this.offsetToBody || isNaN(this.offsetToBody)this.getOffset();
  2591. if (event.clientX != void 0) {
  2592. this.percent = (event.clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2593. } else {
  2594. if (event.touches != void 0) {
  2595. this.percent = (event.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2596. } else
  2597. this.percent = (event.originalEvent.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2598. }
  2599. if (this.percent < 0)
  2600. this.percent = 0;
  2601. else if (this.percent > 1)
  2602. this.percent = 1;
  2603. //var v = this.percent * this.max;
  2604. var v = this.percent * (this.max - this.min) + this.min;
  2605. //var v = Math.round(this.percent * this.max * 10)/10; //精度为0.1
  2606. if (this.value == v)
  2607. return;
  2608. this.setValue(v);
  2609. }
  2610. SlideBar.prototype.setValueFromOutside = function(v) {
  2611. //外面的事件触发的
  2612. if (this.line.width() == 0)
  2613. return;
  2614. //不可见就不执行。
  2615. //v = Math.round(v*10)/10;
  2616. if (this.realMax != void 0) {
  2617. v = THREE.Math.clamp(v, this.min, this.realMax);
  2618. if (v > this.max)
  2619. this.changeLimit({
  2620. max: v
  2621. });
  2622. } else
  2623. v = THREE.Math.clamp(v, this.min, this.max);
  2624. this.setValue(v);
  2625. }
  2626. //-----------------------------------------------------
  2627. var LineDraw = {
  2628. createLine: function(posArr, o) {
  2629. var e = new THREE.BufferGeometry
  2630. , p = new Float32Array(6);
  2631. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  2632. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  2633. var p = e.attributes.position.array;
  2634. for (var i = 0; i < 2; i++) {
  2635. p[i * 3] = posArr[i].x;
  2636. p[i * 3 + 1] = posArr[i].y;
  2637. p[i * 3 + 2] = posArr[i].z;
  2638. }
  2639. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  2640. linewidth: o.width || 1,
  2641. //windows无效。 似乎mac/ios上粗细有效 ?
  2642. color: o.color || defaultColor,
  2643. transparent: o.dontAlwaysSeen ? false : true,
  2644. depthTest: o.dontAlwaysSeen ? true : false
  2645. })
  2646. var line = new THREE.Line(e,mat);
  2647. line.renderOrder = o.renderOrder || 4
  2648. //同tagStem; //如果不加高,可能会部分被model遮住
  2649. return line;
  2650. }
  2651. }
  2652. var toPrecision = function(e, t) {
  2653. function i(e, t) {
  2654. var i = Math.pow(10, t);
  2655. return Math.round(e * i) / i
  2656. }
  2657. if (e instanceof Array) {
  2658. for (var n = 0; n < e.length; n++)
  2659. e[n] = i(e[n], t);
  2660. return e
  2661. }
  2662. return i(e, t)
  2663. }
  2664. var transformControls;
  2665. var initTransformCtl = function(THREE) {
  2666. TransformControls.init(THREE)
  2667. TransformControls.prototype.transCtlChangeMode = function(mode) {
  2668. //if(!this.editing)return;
  2669. if (mode && this.mode != mode) {
  2670. this.mode = mode;
  2671. }
  2672. }
  2673. ,
  2674. transformControls = new TransformControls(player.camera,player.domElement,{
  2675. player: player,
  2676. dontHideWhenFaceCamera: true,
  2677. scaleAxis: ["x", "y"],
  2678. //隐藏了z轴。虽然参数没用上
  2679. NoScaleZ: true //整体缩放时只缩放xy轴。
  2680. });
  2681. transformControls.space = 'local'//为了在当前方向上平移
  2682. transformControls.setSize(1.5)
  2683. player.model.add(transformControls)
  2684. $(".MenuOptions[name='transform'] li").on("click", (e)=>{
  2685. transformControls.transCtlChangeMode($(e.target).attr("index"))
  2686. })
  2687. }
  2688. var EditOverlay = {
  2689. editing: false,
  2690. overlayMaxCount: 10,
  2691. scroller: {
  2692. videoDepth: new SlideBar({
  2693. root: $('#videoDepth').eq(0),
  2694. value: settings.overlay.depth * 100,
  2695. min: 0 * 100,
  2696. max: 1 * 100,
  2697. name: "videoDepth",
  2698. unitStr: "cm",
  2699. avoidCrash: true,
  2700. onchange: function(s) {
  2701. if (s == 0) {
  2702. EditOverlay.editPlane.addBox(false)
  2703. } else {
  2704. EditOverlay.editPlane.addBox(true)
  2705. EditOverlay.editPlane.scale.z = s / 100 / settings.overlay.depth;
  2706. }
  2707. },
  2708. dragEndEvent: function() {
  2709. }
  2710. })
  2711. },
  2712. panoPosSwitch : $('#setOverlayPosForPano input') // 当前漫游点独立调整位置开关
  2713. ,
  2714. init: function(THREE) {
  2715. var mat = new THREE.MeshBasicMaterial({
  2716. wireframe: true,
  2717. opacity: 0.5,
  2718. color: "#57e4f3",
  2719. transparent: true
  2720. })
  2721. var wireframeModel = this.wireframeModel = new THREE.Object3D;
  2722. wireframeModel.name = 'wireframeModel'
  2723. player.model.chunks.forEach((mesh)=>{
  2724. var chunk = mesh.clone();
  2725. chunk.material = mat;
  2726. wireframeModel.add(chunk)
  2727. }
  2728. )
  2729. wireframeModel.visible = false
  2730. player.model.add(wireframeModel)
  2731. //------------------------------
  2732. this.panoPosSwitch.on("change", this.panoPosSwitchOnChange.bind(this))
  2733. $('.overlay .addBtn button').on("click", this.beginToAddPlane.bind(this))
  2734. $("#overlayProp a.close").on("click", ()=>{
  2735. this.closeOverlayPanel("cancel")
  2736. }
  2737. )
  2738. $("#overlayProp button.submit").on("click", (e)=>{
  2739. this.SaveOverlay()
  2740. }
  2741. )
  2742. $("#overlayProp button.delete").on("click", (e)=>{
  2743. this.DeleteOverlay();
  2744. }
  2745. )
  2746. $('#overlayUpload [name="useImgRatio"] button').on("click", this.useImgRatio.bind(this));
  2747. var uploadInputs = {
  2748. video : $('<input type="file" style="display:none" accept="video/*"></input>'),
  2749. photo : $('<input type="file" style="display:none" accept="image/*"></input>'),
  2750. model: $('<input type="file" style="display:none" accept=".obj, .OBJ"></input>'),
  2751. }
  2752. $('#overlayUpload [name="upload"] button').on('click', ()=>{
  2753. uploadInputs[this.editType].click()
  2754. })
  2755. uploadInputs.video.on("change", (e)=>{
  2756. inputMedia({
  2757. enableTypes: [this.editType ],
  2758. videoDone: (file,video)=>{
  2759. var plane = this.editPlane.plane
  2760. $(video).css('width', '100%')
  2761. $(video).css('height', '100%')
  2762. plane.material.map = new THREE.VideoTexture(video);
  2763. plane.material.map.image.play();
  2764. plane.material.map.minFilter = THREE.LinearFilter;
  2765. this.editPlane.overlayType = "video";
  2766. $('#overlayUpload .preview video').remove();
  2767. //$('#overlayUpload .preview').css('background-image',"").append($(video));
  2768. video.autoplay = true;
  2769. video.loop = true;
  2770. video.volume = 0
  2771. video.muted = true
  2772. this.useImgRatio()
  2773. //自适应比例
  2774. this.editPlane.file = file;
  2775. plane.material.opacity = 1;
  2776. plane.material.color = new THREE.Color(1,1,1)
  2777. plane.material.needsUpdate = true;
  2778. }
  2779. }, "video", e);
  2780. }
  2781. )
  2782. uploadInputs.photo.on("change", (e)=>{
  2783. inputMedia({
  2784. enableTypes: [this.editType ],
  2785. photoDone: (photo)=>{
  2786. var plane = this.editPlane.plane
  2787. /* $(video).css('width', '100%')
  2788. $(video).css('height', '100%') */
  2789. plane.material.map = new THREE.Texture();
  2790. plane.material.map.image = photo
  2791. plane.material.map.needsUpdate = !0
  2792. plane.material.map.minFilter = THREE.LinearFilter;
  2793. this.editPlane.overlayType = "photo";
  2794. $('#overlayUpload .preview video').remove();
  2795. //$('#overlayUpload .preview').css('background-image',"").append($(video));
  2796. this.useImgRatio()
  2797. this.updateGifPanel(this.editPlane)
  2798. if(this.editPlane.animateInfo){
  2799. GifTexDeal.remove(this.editPlane.animation)
  2800. this.editPlane.animation = GifTexDeal.addAnimation(this.editPlane.plane.material.map, this.editPlane, this.editPlane.animateInfo, this.editPlane.sid)
  2801. GifTexDeal.start(this.editPlane.animation)
  2802. }
  2803. //自适应比例
  2804. this.editPlane.file = photo.file;
  2805. plane.material.opacity = 1;
  2806. plane.material.color = new THREE.Color(1,1,1)
  2807. plane.material.needsUpdate = true;
  2808. }
  2809. }, "photo", e);
  2810. }
  2811. )
  2812. //模型
  2813. uploadInputs.model.on("change", (e)=>{
  2814. inputMedia({
  2815. //enableTypes: [this.editType ],
  2816. modelDone: (obj)=>{
  2817. console.log(obj)
  2818. }
  2819. }, "model", e);
  2820. })
  2821. $('#overlayModel [name="upload"] button').on('click', ()=>{
  2822. uploadInputs['model'].click()
  2823. })
  2824. player.overlayGroup.children.forEach((overlay)=>{
  2825. if(!overlay.plane.material.map || !overlay.plane.material.map.image){
  2826. overlay._loadDones = [()=>{this.getOverlayInfo(overlay)}]
  2827. }
  2828. else {
  2829. this.getOverlayInfo(overlay)
  2830. }
  2831. this.addToList(overlay)
  2832. } )
  2833. $("#gifSwitch input").on("change", (e)=>{
  2834. var on = $("#gifSwitch input").is(':checked');
  2835. $("#gifInfoEdit").css({display: on ? 'block' : 'none'})
  2836. if(on){
  2837. EditOverlay.editPlane.animateInfo = {
  2838. cellXcount : parseInt($("#gifXCount").val()),
  2839. cellYcount : parseInt($("#gifYCount").val()),
  2840. voidCount : parseInt($("#voidCount").val()),
  2841. loop : true,
  2842. duration : parseFloat($("#gifDuration").val()) * 1000
  2843. }
  2844. EditOverlay.editPlane.animation = GifTexDeal.addAnimation(EditOverlay.editPlane.plane.material.map, EditOverlay.editPlane, EditOverlay.editPlane.animateInfo, EditOverlay.editPlane.sid)
  2845. GifTexDeal.start(EditOverlay.editPlane.animation)
  2846. }else{
  2847. GifTexDeal.remove(EditOverlay.editPlane.animation)
  2848. EditOverlay.editPlane.animateInfo = null
  2849. }
  2850. })
  2851. {//gif动画 input
  2852. let strictInputNum = function(e, precision, min=0,max){//precision:保留小数位数
  2853. var value = e.target.value.trim();
  2854. var lastOne = value[value.length-1];
  2855. var preContent = value.substr(0,value.length-1)
  2856. var hasPoint = precision > 0 && lastOne == '.' ;
  2857. var a = Math.pow(10, precision)
  2858. value = parseFloat(value) || 0;
  2859. if(isNaN(value)){
  2860. e.target.value = preContent //还原
  2861. return
  2862. }
  2863. e.target.value = Math.max(min, parseInt(value * a) / a )
  2864. hasPoint && (e.target.value += '.')//补小数点
  2865. }
  2866. let changeAnimation = function(){
  2867. GifTexDeal.setRepeart(EditOverlay.editPlane.animation)
  2868. }
  2869. let restartAnimation = function(){
  2870. GifTexDeal.stop(EditOverlay.editPlane.animation)
  2871. GifTexDeal.start(EditOverlay.editPlane.animation)
  2872. }
  2873. let changeFrameCount = function(){
  2874. var a = EditOverlay.editPlane.animateInfo
  2875. var frameCount = a.cellXcount * a.cellYcount - (a.voidCount||0)
  2876. $("#gifFrameCount").text(frameCount)
  2877. var fps = parseFloat($("#gifFps").val())
  2878. a.duration = frameCount / fps * 1000
  2879. $("#gifDuration").val(toPrecision(a.duration/1000, 2))
  2880. }
  2881. let gifXCountFun = function(value){
  2882. EditOverlay.editPlane.animateInfo.cellXcount = value
  2883. var gifImgWidth = parseFloat($("#gifImgWidth").text())
  2884. var gifCellWidth = toPrecision(gifImgWidth / EditOverlay.editPlane.animateInfo.cellXcount,1);
  2885. $("#gifCellWidth").val(gifCellWidth)
  2886. changeFrameCount()
  2887. changeAnimation()
  2888. }
  2889. $("#gifXCount").on('input',(e)=>{
  2890. strictInputNum(e, 0)
  2891. gifXCountFun(parseFloat(e.target.value))
  2892. })
  2893. $("#gifXCount").on('change',(e)=>{
  2894. strictInputNum(e, 0, 1)
  2895. gifXCountFun(parseFloat(e.target.value))
  2896. restartAnimation()
  2897. })
  2898. let gifYCountFun = function(value){
  2899. EditOverlay.editPlane.animateInfo.cellYcount = value
  2900. var gifImgHeight = parseFloat($("#gifImgHeight").text())
  2901. var gifCellHeight = toPrecision(gifImgHeight / EditOverlay.editPlane.animateInfo.cellYcount,1);
  2902. $("#gifCellHeight").val(gifCellHeight)
  2903. changeFrameCount()
  2904. changeAnimation()
  2905. }
  2906. $("#gifYCount").on('input',(e)=>{
  2907. strictInputNum(e, 0)
  2908. gifYCountFun(parseFloat(e.target.value))
  2909. })
  2910. $("#gifYCount").on('change',(e)=>{
  2911. strictInputNum(e, 0, 1)
  2912. gifYCountFun(parseFloat(e.target.value))
  2913. changeAnimation()
  2914. restartAnimation()
  2915. })
  2916. let gifCellWidthFun = function(value){
  2917. var gifCellWidth = value;
  2918. var gifImgWidth = parseFloat($("#gifImgWidth").text())
  2919. var cellXcount = toPrecision(gifImgWidth / gifCellWidth,2);
  2920. $("#gifXCount").val(cellXcount)
  2921. changeAnimation()
  2922. }
  2923. $("#gifCellWidth").on('input',(e)=>{
  2924. strictInputNum(e, 0)
  2925. gifCellWidthFun(parseFloat(e.target.value))
  2926. })
  2927. $("#gifCellWidth").on('change',(e)=>{
  2928. strictInputNum(e, 0, 1)
  2929. gifCellWidthFun(parseFloat(e.target.value))
  2930. var cellXcount = $("#gifXCount").val();
  2931. var cellXcountInt = Math.round(cellXcount)
  2932. if(cellXcountInt != cellXcount){
  2933. $("#gifXCount").val(cellXcountInt)
  2934. gifXCountFun(cellXcountInt)
  2935. changeAnimation()
  2936. }
  2937. restartAnimation()
  2938. })
  2939. let gifCellHeightFun = function(value){
  2940. var gifCellHeight = parseFloat(e.target.value);
  2941. var gifImgHeight = parseFloat($("#gifImgHeight").text())
  2942. var cellYcount = toPrecision(gifImgHeight / gifCellHeight,2);
  2943. $("#gifYCount").val(cellYcount)
  2944. }
  2945. $("#gifCellHeight").on('input',(e)=>{
  2946. strictInputNum(e, 0)
  2947. gifCellHeightFun(parseFloat(e.target.value))
  2948. })
  2949. $("#gifCellHeight").on('change',(e)=>{
  2950. strictInputNum(e, 0, 1)
  2951. gifCellHeightFun(parseFloat(e.target.value))
  2952. var cellYcount = $("#gifYCount").val();
  2953. var cellYcountInt = Math.round(cellYcount)
  2954. if(cellYcountInt != cellYcount){
  2955. $("#gifYCount").val(cellYcountInt)
  2956. gifYCountFun(cellYcountInt)
  2957. changeAnimation()
  2958. }
  2959. restartAnimation()
  2960. })
  2961. $("#voidCount").on('change',(e)=>{
  2962. strictInputNum(e, 0);
  2963. EditOverlay.editPlane.animateInfo.voidCount = parseInt(e.target.value)
  2964. changeFrameCount()
  2965. changeAnimation()
  2966. })
  2967. let gifDurationFun = function(value){
  2968. var a = EditOverlay.editPlane.animateInfo
  2969. let frameCount = a.cellXcount * a.cellYcount
  2970. a.duration = value
  2971. $("#gifFps").val(toPrecision(frameCount / a.duration * 1000, 1))
  2972. }
  2973. $("#gifDuration").on('input',(e)=>{
  2974. strictInputNum(e, 1);
  2975. gifDurationFun(parseFloat(e.target.value) * 1000)
  2976. })
  2977. $("#gifDuration").on('change',(e)=>{
  2978. strictInputNum(e, 1, 0.01);
  2979. gifDurationFun(parseFloat(e.target.value) * 1000)
  2980. restartAnimation()
  2981. })
  2982. var gifFpsFun = function(e){
  2983. strictInputNum(e, 0, 1);
  2984. var fps = parseFloat(e.target.value)
  2985. var a = EditOverlay.editPlane.animateInfo
  2986. let frameCount = a.cellXcount * a.cellYcount - (a.voidCount||0)
  2987. a.duration = frameCount / fps * 1000
  2988. $("#gifDuration").val(toPrecision(a.duration / 1000, 2))
  2989. }
  2990. $("#gifFps").on('input',(e)=>{
  2991. gifFpsFun(e)
  2992. })
  2993. $("#gifFps").on('change',(e)=>{
  2994. gifFpsFun(e)
  2995. restartAnimation()
  2996. })
  2997. }
  2998. },
  2999. enter: function() {
  3000. this.editing = true;
  3001. this.wireframeModel.visible = true;
  3002. },
  3003. leave: function() {
  3004. if (!this.editing)
  3005. return;
  3006. this.editing = false
  3007. $("#overlayProp a.close").click();
  3008. this.endAddPlane();
  3009. this.wireframeModel.visible = false;
  3010. },
  3011. switchEditType : function(type){
  3012. this.editType = type;
  3013. $('#overlayUpload [name="upload"] button').text(type == 'video' ? "上传视频" : "上传图片")
  3014. $('#overlayUpload .preview span').eq(0).text(type == 'video' ? "支持MP4、MOV等,<20M" : "支持jpg、png等,<20M");
  3015. if(type != 'photo' || !this.editPlane) $('#overlayProp #gifEdit').css({display: 'none'})
  3016. },
  3017. beginToAddPlane: function(event) {
  3018. this.switchEditType($(event.target).attr("data-type"))
  3019. player.reticule.visible = false;
  3020. this.objCursorType = 'overlay';
  3021. player.currentCursor = 'url(images/edit/box_video.png), auto'
  3022. $('#player').css('cursor', player.currentCursor)
  3023. $('.overlay .addBtn button').addClass("unable")
  3024. //可以加多个视频时的按钮
  3025. },
  3026. endAddPlane: function() {
  3027. this.objCursorType = null;
  3028. player.currentCursor = '';
  3029. $('#player').css('cursor', '')
  3030. $('.overlay .addBtn button').removeClass("unable")
  3031. player.reticule.visible = true
  3032. },
  3033. addPlane: function(o) {
  3034. if(!o.intersect)return;
  3035. var pos = o.intersect.point;
  3036. var overlay = new Overlay({
  3037. sid: new Date().getTime() + ""
  3038. })
  3039. overlay.hasRequestLoad = true
  3040. overlay.position.copy(pos);
  3041. if (player.getMouseDirection().angleTo(o.intersect.face.normal) < Math.PI / 2) {
  3042. overlay.lookAt(o.intersect.face.normal.clone().negate().add(pos));
  3043. overlay.position.add(o.intersect.face.normal.clone().negate().multiplyScalar(0.01))
  3044. //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  3045. } else {
  3046. overlay.lookAt(o.intersect.face.normal.clone().add(pos));
  3047. overlay.position.add(o.intersect.face.normal.clone().multiplyScalar(0.01))
  3048. }
  3049. overlay.posCustom = overlay.position.clone();
  3050. overlay.quaCustom = overlay.quaternion.clone();
  3051. overlay.widthCustom = overlay.width;
  3052. overlay.heightCustom = overlay.height;
  3053. overlay.isNew = true
  3054. player.clickOverlay(overlay)
  3055. transformControls.transCtlChangeMode("translate")
  3056. this.addToList(overlay)
  3057. },
  3058. updateOverlayScaleDisplay: function() {
  3059. var overlay = this.editPlane;
  3060. var maxWidth = 193
  3061. , maxHeight = maxWidth
  3062. //maxWidth/2;
  3063. var ratioW = Math.abs(overlay.width) / maxWidth;
  3064. var ratioH = Math.abs(overlay.height) / maxHeight;
  3065. var ratio = 1 / Math.max(ratioW, ratioH);
  3066. //缩放比例
  3067. var w = Math.round(Math.abs(overlay.width) * ratio)
  3068. var h = Math.round(Math.abs(overlay.height) * ratio)
  3069. $('#overlayUpload .preview').css({
  3070. "width": w + 'px',
  3071. "height": h + 'px',
  3072. });
  3073. $('#overlayUpload .preview [attr-type="width"]').text(toPrecision(overlay.width, 2))
  3074. $('#overlayUpload .preview [attr-type="height"]').text(toPrecision(overlay.height, 2))
  3075. $("#gifSwitch input").prop('checked', !!overlay.animateInfo);
  3076. $("#gifInfoEdit").css({display: !!overlay.animateInfo ? 'block' : 'none'})
  3077. },
  3078. updateOverlayPreview : function(overlay){
  3079. var plane = overlay.plane
  3080. var src = plane.material.map && (plane.material.map.image ? plane.material.map.image.src : overlay.fileSrc );
  3081. $('#overlayUpload .preview video').remove();
  3082. if (overlay.overlayType == "video") {
  3083. var video = plane.material.map.image
  3084. $('#overlayUpload .preview').css({'background-image':"", 'background-size':""}).append(video);
  3085. } else if(overlay.overlayType == "photo" || overlay.overlayType == "text"){
  3086. $('#overlayUpload .preview').css({
  3087. 'background-image': src ? ("url(" + src + ")") : "",
  3088. 'background-size': "100% 100%"
  3089. })
  3090. }else{
  3091. $('#overlayUpload .preview').css({
  3092. 'background-image': "",
  3093. 'background-size': ""
  3094. })
  3095. }
  3096. if (overlay.overlayType) {
  3097. $('#overlayUpload [name="useImgRatio"]').removeClass("hide")
  3098. $('#overlayUpload .preview').addClass('uploaded')
  3099. } else {
  3100. $('#overlayUpload [name="useImgRatio"]').addClass("hide")
  3101. $('#overlayUpload .preview').removeClass('uploaded')
  3102. }
  3103. }
  3104. ,
  3105. updateOverlayPanel: function(overlay) {//开始编辑时更新
  3106. overlay.overlayType && this.switchEditType(overlay.overlayType)
  3107. this.updateOverlayPreview(overlay)
  3108. this.updateOverlayScaleDisplay()
  3109. this.updateGifPanel(overlay)
  3110. if (overlay.hasBox) {
  3111. this.scroller.videoDepth.setValue(overlay.scale.z * settings.overlay.depth * 100, true)
  3112. } else {
  3113. this.scroller.videoDepth.setValue(0, true)
  3114. }
  3115. setTimeout(()=>{
  3116. this.scroller.videoDepth.InitOffset()
  3117. }
  3118. , 201)
  3119. this.updatePano()
  3120. },
  3121. //----------------------------
  3122. updateGifPanel : function(overlay){
  3123. if(this.editType == 'photo'){
  3124. if(!overlay.plane.material.map)return;
  3125. $('#overlayProp #gifEdit').css({display: 'block'})
  3126. let w = overlay.plane.material.map.image.width
  3127. let h = overlay.plane.material.map.image.height
  3128. if(overlay.animateInfo){
  3129. let a = overlay.animateInfo
  3130. $("#gifXCount").val(a.cellXcount);
  3131. $("#gifYCount").val(a.cellYcount);
  3132. $("#gifImgWidth").text(w)
  3133. $("#gifImgHeight").text(h)
  3134. $("#gifCellWidth").val(toPrecision(w / a.cellXcount, 2));
  3135. $("#gifCellHeight").val(toPrecision(h / a.cellYcount, 2));
  3136. $("#voidCount").val(a.voidCount || 0);
  3137. let frameCount = a.cellXcount * a.cellYcount - (a.voidCount || 0)
  3138. $("#gifFrameCount").text(frameCount)
  3139. $("#gifDuration").val(toPrecision(a.duration / 1000, 2));
  3140. $("#gifFps").val(toPrecision(frameCount / a.duration * 1000, 1) );
  3141. }else{
  3142. $("#gifXCount").val(1);
  3143. $("#gifYCount").val(1);
  3144. $("#gifImgWidth").text(w)
  3145. $("#gifImgHeight").text(h)
  3146. $("#gifCellWidth").val(w);
  3147. $("#gifCellHeight").val(h)
  3148. $("#voidCount").val(0);
  3149. $("#gifFrameCount").text(1)
  3150. $("#gifDuration").val(1);
  3151. $("#gifFps").val(1);
  3152. }
  3153. }
  3154. }
  3155. ,
  3156. beginEdit : function(overlay){
  3157. $('#overlayProp').removeClass('atRight').removeClass('hide')
  3158. this.endAddPlane();
  3159. this.editPlane = overlay;
  3160. overlay.requestDownload()
  3161. if(overlay._loadDones){
  3162. $('.waiting').addClass('showloading');
  3163. overlay._loadDones.push(()=>{
  3164. $('.waiting').removeClass('showloading');
  3165. })
  3166. }
  3167. overlay.visible = true
  3168. this.updateOverlayPanel(overlay)
  3169. transformControls.attach(overlay)
  3170. }
  3171. ,
  3172. panoPosSwitchOnChange : function(){
  3173. var on = this.panoPosSwitch.is(':checked')
  3174. if(!on){
  3175. delete this.editPlane.transformAtPanos[getTransformSid()]
  3176. this.editPlane.position.copy(this.editPlane.posCustom)
  3177. this.editPlane.quaternion.copy(this.editPlane.quaCustom)
  3178. var scale = this.editPlane.getScaleBySize(this.editPlane.widthCustom, this.editPlane.heightCustom)
  3179. this.editPlane.scale.set(scale.x, scale.y, this.editPlane.scale.z)
  3180. //this.editPlane.usingTransformData = false
  3181. }
  3182. }
  3183. ,
  3184. getTransformAtPano : function(){
  3185. var name = getTransformSid()
  3186. this.editPlane.transformAtPanos[name] = {
  3187. pos : this.editPlane.position.clone(),
  3188. qua : this.editPlane.quaternion.clone(),
  3189. width : this.editPlane.width,
  3190. height : this.editPlane.height,
  3191. }
  3192. //this.editPlane.usingTransformData = true
  3193. },
  3194. updatePosition:function(){
  3195. var on = this.panoPosSwitch.is(':checked')
  3196. if(on){
  3197. this.getTransformAtPano()
  3198. }else{
  3199. this.editPlane.posCustom.copy(this.editPlane.position)
  3200. }
  3201. },
  3202. updateScale : function(){
  3203. var on = this.panoPosSwitch.is(':checked')
  3204. var size = this.editPlane.getSizeByScale( )
  3205. this.editPlane.width = size.width
  3206. this.editPlane.height = size.height
  3207. if(on){
  3208. this.getTransformAtPano()
  3209. }else{
  3210. this.editPlane.widthCustom = this.editPlane.width
  3211. this.editPlane.heightCustom = this.editPlane.height
  3212. }
  3213. this.updateOverlayScaleDisplay()
  3214. }
  3215. ,
  3216. updateQua : function(){
  3217. var on = this.panoPosSwitch.is(':checked')
  3218. if(on){
  3219. this.getTransformAtPano()
  3220. }else{
  3221. this.editPlane.quaCustom.copy(this.editPlane.quaternion)
  3222. }
  3223. }
  3224. ,
  3225. updatePano:function(){
  3226. if(!EditOverlay.editPlane ) return;
  3227. this.panoPosSwitch.prop('checked', !!EditOverlay.editPlane.transformAtPanos[ getTransformSid()]);
  3228. },
  3229. //------------------------------
  3230. closeOverlayPanel: function(type) {
  3231. if (!this.editPlane)
  3232. return;
  3233. if (type == 'cancel') {
  3234. if (!this.editPlane.isNew && !this.editPlane.needDelete)
  3235. this.editPlane.setFromInfo(this.editPlane.info)
  3236. else
  3237. this.disposeOverlay(this.editPlane);
  3238. //删除
  3239. }
  3240. this.editPlane = null;
  3241. transformControls.detach()
  3242. $("#overlayProp").addClass("atRight");
  3243. //if(player.model.overlayPlanes.length < this.overlayMaxCount) this.beginToAddPlane()
  3244. },
  3245. useImgRatio: function(o) {
  3246. var plane = this.editPlane.plane;
  3247. if (!plane.material.map)
  3248. return;
  3249. var img = plane.material.map.image;
  3250. var mintranRatio = 200;
  3251. //default is 200 , 防止图片太小时在墙上依旧很大
  3252. var width = this.editPlane.overlayType == "video" ? img.videoWidth : img.width;
  3253. var height = this.editPlane.overlayType == "video" ? img.videoHeight : img.height;
  3254. if (o == "suitSize") {
  3255. var boundWidth = Math.min(Math.max(width, height) / mintranRatio, 1)
  3256. if (width > height) {
  3257. var w = boundWidth;
  3258. var h = boundWidth * height / width
  3259. } else {
  3260. var h = boundWidth;
  3261. var w = boundWidth * width / height;
  3262. }
  3263. } else {
  3264. //假设不变总面积
  3265. var k = Math.sqrt(Math.abs(this.editPlane.width * this.editPlane.height) / (width * height))
  3266. var w = k * width * (this.editPlane.width < 0 ? -1 : 1);
  3267. var h = k * height * (this.editPlane.height < 0 ? -1 : 1);
  3268. }
  3269. this.editPlane.scale.setX(w / settings.overlay.width)
  3270. this.editPlane.scale.setY(h / settings.overlay.height)
  3271. this.editPlane.width = w;
  3272. this.editPlane.height = h;
  3273. this.updateScale()
  3274. //this.updateOverlayPanel(this.editPlane)
  3275. this.updateOverlayPreview(this.editPlane)
  3276. },
  3277. getOverlayInfo: function(overlay) {
  3278. //2 编辑前, 从当前状态获取info
  3279. var plane = overlay.plane;
  3280. var transformAtPanos = {}
  3281. for(var i in overlay.transformAtPanos){
  3282. transformAtPanos[i] = {
  3283. width : overlay.transformAtPanos[i].width,
  3284. height : overlay.transformAtPanos[i].height,
  3285. pos : overlay.transformAtPanos[i].pos.clone(),
  3286. qua : overlay.transformAtPanos[i].qua.clone(),
  3287. }
  3288. }
  3289. overlay.info = {
  3290. width: overlay.widthCustom,
  3291. height: overlay.heightCustom,
  3292. depth: settings.overlay.depth * overlay.scale.z,
  3293. pos: overlay.posCustom.clone(),
  3294. qua: overlay.quaCustom.clone(),
  3295. media: plane.material.map.image,
  3296. file: overlay.file,
  3297. type: overlay.overlayType,
  3298. hasBox: overlay.hasBox,
  3299. transformAtPanos: transformAtPanos
  3300. }
  3301. if(overlay.animateInfo ){
  3302. overlay.info.animateInfo = CloneObject(overlay.animateInfo)
  3303. }
  3304. },
  3305. getSavingInfo: function(overlay) {
  3306. if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
  3307. return;
  3308. }
  3309. var transformAtPanos = {}
  3310. for(var i in overlay.transformAtPanos){
  3311. transformAtPanos[i] = {
  3312. width : toPrecision(overlay.transformAtPanos[i].width, 4),
  3313. height : toPrecision(overlay.transformAtPanos[i].height, 4),
  3314. pos : toPrecision(overlay.transformAtPanos[i].pos.toArray(), 3),
  3315. qua : toPrecision(overlay.transformAtPanos[i].qua.toArray(), 5)
  3316. }
  3317. }
  3318. var info = {
  3319. width: toPrecision(overlay.widthCustom, 4),
  3320. height: toPrecision(overlay.heightCustom, 4),
  3321. depth: toPrecision(settings.overlay.depth * overlay.scale.z, 4),
  3322. pos: toPrecision(overlay.posCustom.toArray(), 3),
  3323. qua: toPrecision(overlay.quaCustom.toArray(), 5),
  3324. sid: overlay.sid,
  3325. hasBox: overlay.hasBox ? 1 : 0,
  3326. media: [overlay.overlayType],
  3327. file: overlay.fileSrc || overlay.plane.material.map.image.src,
  3328. transformAtPanos : transformAtPanos,
  3329. }
  3330. if(overlay.animateInfo && overlay.animateInfo.cellXcount * overlay.animateInfo.cellYcount > 1){
  3331. info.animateInfo = overlay.animateInfo
  3332. }
  3333. return info
  3334. },
  3335. SaveOverlay: function() {
  3336. var overlay = this.editPlane;
  3337. if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
  3338. this.editType == "video" ? alert("请上传视频") : alert("请上传图片");
  3339. return;
  3340. }
  3341. var saveInfo = ()=>{
  3342. //overlay.savingInfo = JSON.stringify(info)//准备写入的info
  3343. //saveDone:
  3344. overlay.isNew = false;
  3345. overlay.getVisiblePanos()
  3346. this.getOverlayInfo(overlay);
  3347. this.closeOverlayPanel()
  3348. $('.waiting').removeClass('showloading');
  3349. }
  3350. if (!overlay.info || overlay.file != overlay.info.file) {
  3351. $('.waiting').addClass('showloading');
  3352. uploadFile(overlay.file, 'overlay', function(rs) {
  3353. if (rs.code === 0) {
  3354. overlay.fileSrc = rs.data;
  3355. saveInfo()
  3356. }
  3357. ;
  3358. })
  3359. } else
  3360. saveInfo();
  3361. },
  3362. disposeOverlay: function(overlay) {
  3363. var plane = overlay.plane
  3364. if (overlay == player.hoveringPlane) {
  3365. player.hoverOverlay(null, "soon");
  3366. }
  3367. if (plane.material.map) {//删除视频src
  3368. //overlay.info && common.destroyBlob(overlay.info.media.src)
  3369. //common.destroyBlob(plane.material.map.image.src)
  3370. }
  3371. plane.material.dispose();
  3372. overlay.parent.remove(overlay);
  3373. this.removeFromList(overlay)
  3374. if(this.animation){
  3375. GifTexDeal.remove(this.animation)
  3376. }
  3377. //this.beginToAddPlane()
  3378. },
  3379. DeleteOverlay: function() {
  3380. var overlay = this.editPlane;
  3381. if (!overlay.isNew) {
  3382. if (confirm(overlay.overlayType== "photo" ? "确定删除该图片?" : "确定删除该视频?")) {
  3383. overlay.needDelete = true;
  3384. $("#overlayProp a.close").click()
  3385. //this.closeOverlayPanel()
  3386. }
  3387. } else {
  3388. //刚创建时的删除按钮等同于取消按钮
  3389. $("#overlayProp a.close").click()
  3390. //this.closeOverlayPanel()
  3391. }
  3392. },
  3393. addToList: function(overlay) {
  3394. var li = $(`<li class='listItem'><div class="icon"></div><div class="title">${(overlay.overlayType == "video" ? "视频 ":"图片 ")+ overlay.sid}</div></li>`)
  3395. $(".overlayList ul").append(li);
  3396. li.on("click", ()=>{
  3397. player.clickOverlay(overlay)
  3398. player.focusPoint({aim: overlay.position})
  3399. })
  3400. overlay.domLi = li;
  3401. },
  3402. removeFromList: function(overlay) {
  3403. overlay.domLi.remove();
  3404. }
  3405. }
  3406. //----------------漫游可见性---------------------------------
  3407. var VisiSet = {
  3408. setPanoVisible: false,
  3409. setTagVisible: false,
  3410. setPanoLog:false,
  3411. panoVLines: {},
  3412. //线条
  3413. panoVTemp: {},
  3414. //修改后还没保存的临时数据
  3415. tagVsetting: null,
  3416. //正在设置的热点中心点
  3417. tagsVLines: {},
  3418. //线条
  3419. //tagVTemp //修改后还没保存的临时数据
  3420. $confirmSnap: $("#camera-start"),
  3421. changeBtn : $(".toolMid .midBottom #midBtns>button").eq(1),
  3422. colors: {
  3423. green: "#00c8ae"
  3424. },
  3425. init: function() {
  3426. this.footIconSizeRatio = Math.max(player.model.size.x, player.model.size.z) / 30;
  3427. this.meshGroup = new THREE.Object3D;
  3428. this.meshGroup.name = "setVisible-group"
  3429. player.model.add(this.meshGroup)
  3430. $("#hotVisible").on("click", ()=>{
  3431. VisiSet.enterSet(VisiSet.beginSetTagVisible.bind(VisiSet))
  3432. })
  3433. this.changeBtn.on("click",()=>{//隐藏与显示该点
  3434. if(this.changeBtn.attr("function") == "hide"){
  3435. for(let i in this.panoVLines){
  3436. this.panoVLines[i].visible && this.dealPanoVisible(i);
  3437. }
  3438. }else{
  3439. //显示该点时,显示周围一定距离内、到该点没有遮挡的pano
  3440. //?????
  3441. var list = player.model.panos.sortByScore([e=>e.isAligned()], [(pano)=>{return -pano.position.distanceTo(this.panoVsetting.position)}])
  3442. if(list.length == 1){
  3443. console.log('仅有一个漫游点')
  3444. return;
  3445. }
  3446. var ifBlock = function(panoA, panoB ){
  3447. var A = panoA.position.clone();
  3448. var B = panoB.position.clone();
  3449. return convertTool.ifIntersectChunks(A, B, {})
  3450. }
  3451. var okList
  3452. var s = Math.max(-list[1].score*2, 4); //i==1的一定显示
  3453. for(var i=1;i<list.length;i++){
  3454. if(-list[i].score < s){
  3455. if(ifBlock(this.panoVsetting, list[i].pano)){
  3456. list[i].block = true //有阻挡
  3457. }
  3458. list[i].good = true
  3459. }else{
  3460. okList || (okList = list.filter(e=>e.good && !e.block));//绝对可以使用的
  3461. if(okList.length <2 ){
  3462. if(!ifBlock(this.panoVsetting, list[i].pano)){
  3463. if(okList.length == 0){
  3464. okList.push(list[i])
  3465. }else{//1
  3466. var lastPos = okList[0].pano.position.clone().sub(this.panoVsetting.position).setY(0);
  3467. var thisPos = list[i].pano.position.clone().sub(this.panoVsetting.position).setY(0);
  3468. if(lastPos.angleTo(thisPos) > Math.PI / 2){
  3469. console.log('再加一个 角度'+THREE.Math.radToDeg(lastPos.angleTo(thisPos)))
  3470. break;
  3471. }
  3472. }
  3473. }
  3474. }else{
  3475. break;
  3476. }
  3477. }
  3478. }
  3479. if(okList.length==0){//如果length为0,至少加一个pano, 虽然是遮挡的
  3480. okList.push(list[0].pano)
  3481. }
  3482. okList.forEach(e=>this.dealPanoVisible(e.pano.id))
  3483. console.log(okList)
  3484. }
  3485. })
  3486. },
  3487. enterSet: function(fun) {
  3488. var enter = function() {
  3489. if (player.modeTran.split('-')[1] != "floorplan") {
  3490. setTimeout(fun, 300)
  3491. //提前一点出现
  3492. }
  3493. player.flyToMode("floorplan", fun);
  3494. }
  3495. permitTranMode(false)
  3496. if (!player.modeTran) {
  3497. player.afterCModeFuc = ()=>{
  3498. enter()
  3499. }
  3500. } else
  3501. enter()
  3502. },
  3503. beginSetPanoLog: function() {
  3504. player.flying || $(".toolLeft").removeClass("unable")
  3505. if (this.setPanoLog)
  3506. return;
  3507. this.setPanoLog = true
  3508. this.panosSelect = []
  3509. this.updateFootIconSize()
  3510. this.showFootIcons(null, true);
  3511. for(let i in player.model.hots){
  3512. player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
  3513. player.model.hots[i].mesh.visible = false
  3514. }
  3515. player.model.panos.forEach(e=>{
  3516. e.addTextSprite(e.id, $('#panoIdColorTex').val(), e.footIcon)
  3517. })
  3518. },
  3519. finishSetPanoLog: function() {
  3520. //结束 退出这个设置
  3521. if (!this.setPanoLog)
  3522. return;
  3523. //否则会加多个侦听
  3524. this.setPanoLog = false;
  3525. this.hideFootIcons();
  3526. this.recoverAllState2();
  3527. this.panosSelect = null
  3528. player.flyoutType = null
  3529. permitTranMode(true)
  3530. for(let i in player.model.hots){
  3531. player.model.hots[i].mesh.visible = player.model.hots[i].visi_
  3532. }
  3533. $("#panosIdShow").val('')
  3534. player.model.panos.forEach(e=>{
  3535. e.removeTextSprite()
  3536. })
  3537. },
  3538. dealPanoLogClick: function(object) {
  3539. var id = object.name == '' ? object.parent.name : object.name
  3540. var panos = player.model.panos;
  3541. var index = this.panosSelect.indexOf(id)
  3542. if (index==-1) {
  3543. this.changeFIconState(panos.index[id].footIcon, "linked" )
  3544. this.panosSelect.push(id)
  3545. }else{
  3546. this.changeFIconState(panos.index[id].footIcon, false)
  3547. this.panosSelect.splice(index,1)
  3548. }
  3549. $("#panosIdShow").val('"'+this.panosSelect.join('","')+'"');
  3550. }
  3551. ,
  3552. changePanoIdColor:function(color){
  3553. player.model.panos.forEach(e=>{
  3554. e.removeTextSprite();
  3555. e.addTextSprite(e.id,color, e.footIcon)
  3556. })
  3557. }
  3558. ,
  3559. //--------------
  3560. beginSetPanoVisible: function() {
  3561. player.flying || $(".toolLeft").removeClass("unable")
  3562. if (this.setPanoVisible)
  3563. return;
  3564. this.setPanoVisible = true;
  3565. this.panoVTemp = {};
  3566. this.SetOnePanoVisible(player.currentPano)
  3567. //先设置currentPano
  3568. this.$confirmSnap.text('保存当前设置').removeClass("hide")
  3569. //objects.tagManager.hideAllTags();
  3570. this.setDisplay(true)
  3571. this.updateFootIconSize()
  3572. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3573. for(let i in player.model.hots){
  3574. player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
  3575. player.model.hots[i].mesh.visible = false
  3576. }
  3577. },
  3578. SetOnePanoVisible: function(pano) {
  3579. //点击某个pano后就对该pano点进行设置
  3580. if (this.panoVsetting == pano)
  3581. return;
  3582. //if (this.panoVsetting) saveLastPanoVi(this.panoVsetting);
  3583. this.panoVsetting = pano;
  3584. //记录正在修改的
  3585. this.delVisibleLines();
  3586. //删除线
  3587. this.showFootIcons(pano, true);
  3588. this.createPanoVisiLines(pano);
  3589. //创线
  3590. this.changeBtn.removeClass('hide')
  3591. },
  3592. saveLastPanoVi: function() {
  3593. //保存刚设置过的pano
  3594. var change = [];
  3595. for (var r in this.panoVLines) {
  3596. var line = this.panoVLines[r];
  3597. if (line.name.indexOf("new") > -1 && line.visible) {
  3598. //新设置为visible且没有取消
  3599. change.push({
  3600. type: "add",
  3601. id: r
  3602. })
  3603. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  3604. //旧的且已经取消
  3605. change.push({
  3606. type: "sub",
  3607. id: r
  3608. })
  3609. }
  3610. }
  3611. if (change.length) {
  3612. //添加双向的neighbour:
  3613. var self = this.searchNeib(this.panoVsetting.id)
  3614. //var seeMarkers_self = self.seeMarkers;
  3615. var neighbourUUIDs_self = self.neighbourUUIDs
  3616. var neighbourPanos_self = self.neighbourPanos;
  3617. for (var i = 0; i < change.length; i++) {
  3618. var other = this.searchNeib(change[i].id)
  3619. //var seeMarkers = other.seeMarkers;
  3620. var neighbourUUIDs = other.neighbourUUIDs;
  3621. var neighbourPanos = other.neighbourPanos;
  3622. if (change[i].type == "add") {
  3623. //seeMarkers.push(this.panoVsetting.id);
  3624. neighbourUUIDs.push(this.panoVsetting.id);
  3625. neighbourPanos[this.panoVsetting.id] = true;
  3626. //seeMarkers_self.push(change[i].id);
  3627. neighbourUUIDs_self.push(change[i].id);
  3628. neighbourPanos_self[change[i].id] = true;
  3629. } else {
  3630. //var index = seeMarkers.indexOf(this.panoVsetting.id);
  3631. //index > -1 && seeMarkers.splice(index, 1);
  3632. var index = neighbourUUIDs.indexOf(this.panoVsetting.id);
  3633. index > -1 && neighbourUUIDs.splice(index, 1);
  3634. neighbourPanos[this.panoVsetting.id] = false;
  3635. //var index = seeMarkers_self.indexOf(change[i].id);
  3636. //index > -1 && seeMarkers_self.splice(index, 1);
  3637. var index = neighbourUUIDs_self.indexOf(change[i].id);
  3638. index > -1 && neighbourUUIDs_self.splice(index, 1);
  3639. neighbourPanos_self[change[i].id] = false;
  3640. }
  3641. this.panoVTemp[change[i].id] = {
  3642. //后面两个是作为保存到后台的数据存储,临时需要用到的是第一个
  3643. neighbourPanos: neighbourPanos,
  3644. //seeMarkers: seeMarkers,
  3645. neighbourUUIDs: neighbourUUIDs
  3646. }
  3647. }
  3648. this.panoVTemp[this.panoVsetting.id] = {
  3649. //加上自己
  3650. neighbourPanos: neighbourPanos_self,
  3651. //seeMarkers: seeMarkers_self,
  3652. neighbourUUIDs: neighbourUUIDs_self
  3653. }
  3654. }
  3655. },
  3656. pauseSetPanoVisible: function(type) {
  3657. //暂停 因为点击了保存设置 但没有退出设置
  3658. if (!this.setPanoVisible)
  3659. return;
  3660. if (type == "unsaved") {
  3661. //中途点击pano从而停止一个热点的设置
  3662. this.saveLastPanoVi();
  3663. } else {
  3664. this.panoVTemp = {};
  3665. //清空数据
  3666. }
  3667. this.delVisibleLines();
  3668. this.showFootIcons();
  3669. //清空选择
  3670. var lastPanoSetting = this.panoVsetting;
  3671. this.panoVsetting = null;
  3672. lastPanoSetting && this.changeFIconState2(lastPanoSetting.footIcon, this.checkHasNeighbor(lastPanoSetting))
  3673. //这句要放在this.panoVsetting = null后。 根据可见性更改透明度
  3674. this.changeBtn.addClass('hide')
  3675. },
  3676. //按理说改变了neighbourPano,tag的初始visible也要改。但是这样还要考虑已经改过的tag。。很麻烦
  3677. finishSetPanoVisible: function() {
  3678. //结束 退出这个设置
  3679. if (!this.setPanoVisible)
  3680. return;
  3681. //否则会加多个侦听
  3682. this.setPanoVisible = false;
  3683. this.hideFootIcons();
  3684. this.delVisibleLines();
  3685. //objects.tagManager.showAllTags();
  3686. this.recoverAllState2();
  3687. this.panoVsetting = null;
  3688. this.panoVTemp = {};
  3689. player.flyoutType = null
  3690. this.$confirmSnap.addClass("hide")
  3691. permitTranMode(true)
  3692. this.setDisplay(false)
  3693. for(let i in player.model.hots){
  3694. player.model.hots[i].mesh.visible = player.model.hots[i].visi_
  3695. }
  3696. },
  3697. changeVisiBtnState: function(state){
  3698. this.changeBtn.attr("function", state ? "hide" : "show")
  3699. this.changeBtn.html(state ? "隐藏该点位置":"显示该点位置")
  3700. },
  3701. recoverAllState2: function() {
  3702. //为了热点可视恢复成pano全部可见
  3703. if(!this.footIcons)return;
  3704. for (var i = 0; i < this.footIcons.length; i++) {
  3705. this.footIcons[i].material.uniforms.opacity.value = 1;
  3706. this.footIcons[i].material.uniforms.map.value = footTex1;
  3707. }
  3708. },
  3709. afterSavePanoVisibles: function() {
  3710. //实施:
  3711. var panos = player.model.panos;
  3712. for (var i in this.panoVTemp) {
  3713. var pano = panos.index[i];
  3714. //pano.seeMarkers = this.panoVTemp[i].seeMarkers;
  3715. pano.neighbourUUIDs = this.panoVTemp[i].neighbourUUIDs;
  3716. pano.neighbourPanos = this.panoVTemp[i].neighbourPanos;
  3717. }
  3718. if (!this.checkHasNeighbor(player.currentPano)) {
  3719. //currentPano变为孤立点 就要换一个防止飞入
  3720. var list = panos.sortByScore([pano=>{
  3721. return this.checkHasNeighbor(pano)
  3722. }
  3723. ], [function(pano) {
  3724. return -pano.position.distanceTo(player.currentPano.position)
  3725. }
  3726. ])
  3727. if (list && list.length) {
  3728. player.currentPano = list[0].pano;
  3729. //找最近的一非孤立点
  3730. //this.noPanoHasNeighbor = false; //更新状态
  3731. } else {//this.noPanoHasNeighbor = true; //更新状态
  3732. }
  3733. } else {//this.noPanoHasNeighbor = false; //更新状态
  3734. }
  3735. //dataDeal.done();
  3736. //暂时:
  3737. this.pauseSetPanoVisible()
  3738. this.updateFootIconSize()
  3739. //更新一下center大小 写在最后
  3740. },
  3741. //最佳推荐操作顺序: 先设置pano可见性 再创建热点 这样热点的visible正确些,否则之后再设置热点可见性会改更多
  3742. savePanoVisibles: function() {
  3743. //保存
  3744. if (this.panoVsetting)
  3745. this.saveLastPanoVi(this.panoVsetting);
  3746. //获取最后设置的那个热点的改动
  3747. var PanoData = [];
  3748. for (var i in this.panoVTemp) {
  3749. PanoData.push({
  3750. //希望算法部不会更改index排序,或者更改后能将visible信息一并更改
  3751. panoID: i,
  3752. //visibles: this.turnToPanoIndex(this.panoVTemp[i].seeMarkers),
  3753. visibles3: this.turnToPanoIndex(this.panoVTemp[i].neighbourUUIDs)
  3754. })
  3755. }
  3756. if (PanoData.length == 0) {
  3757. //没改变
  3758. alert("保存成功")
  3759. return;
  3760. }
  3761. /* this.afterSavePanoVisibles()
  3762. alert("保存成功")
  3763. console.log(JSON.stringify(PanoData)) */
  3764. let url = cmp ? ('/api/scene/roamViable/' + cmp) : '/manage/scene/roamViable'
  3765. $.ajax({
  3766. method: 'POST',
  3767. url: ceshi + url,
  3768. headers: {
  3769. 'Content-Type': 'application/json',
  3770. token: token
  3771. },
  3772. contentType: 'application/json',
  3773. data: JSON.stringify({
  3774. data: JSON.stringify(PanoData),
  3775. sceneCode: window.number
  3776. }),
  3777. success: (data)=>{
  3778. if (data.code === 0) {
  3779. this.afterSavePanoVisibles()
  3780. alert("保存漫游可行成功")
  3781. } else
  3782. alert("保存漫游可行失败")
  3783. if (data.code === 5001) {
  3784. alert('请重新登录')
  3785. localStorage.dcj_token = ''
  3786. location.reload()
  3787. }
  3788. }
  3789. ,
  3790. fail: function() {
  3791. alert("保存漫游可行失败")
  3792. }
  3793. })
  3794. /* var o = {
  3795. name_t: "panoVisible",
  3796. f: this.pauseSetPanoVisible,
  3797. url: Config.prefixEditProPCApi+"/saveLinkPano",
  3798. dialog: i18n.get('设置'),
  3799. data: { data: JSON.stringify(PanoData) }
  3800. }
  3801. var dataDeal = uploadsSaving.saveFucforPC(o);
  3802. dataDeal.group[0] = function () {
  3803. //实施:
  3804. for (var i in player.panoVTemp) {
  3805. var pano = player.model.panos.index[i];
  3806. pano.seeMarkers = player.panoVTemp[i].seeMarkers;
  3807. pano.neighbourUUIDs = player.panoVTemp[i].neighbourUUIDs;
  3808. pano.neighbourPanos = player.panoVTemp[i].neighbourPanos;
  3809. }
  3810. if(!player.model.checkHasNeighbor(player.currentPano)){//currentPano变为孤立点 就要换一个防止飞入
  3811. var list = player.model.panos.sortByScore([function(pano){return player.model.checkHasNeighbor(pano)}],
  3812. [function(pano){return -pano.position.distanceTo(player.currentPano.position)}])
  3813. if(list && list.length){
  3814. player.currentPano = list[0].pano;//找最近的一非孤立点
  3815. player.model.noPanoHasNeighbor = false; //更新状态
  3816. }else{
  3817. player.model.noPanoHasNeighbor = true; //更新状态
  3818. }
  3819. }else{
  3820. player.model.noPanoHasNeighbor = false; //更新状态
  3821. }
  3822. dataDeal.done();
  3823. player.model.updateFootIconSize(player.cameraControls.activeControl)//更新一下center大小 写在最后
  3824. } */
  3825. },
  3826. searchNeib: function(panoId) {
  3827. //寻找某pano的相关neighbour 可能是修改过的
  3828. var panos = player.model.panos;
  3829. var o = {};
  3830. if (this.panoVTemp[panoId]) {
  3831. //o.seeMarkers = this.panoVTemp[panoId].seeMarkers;
  3832. o.neighbourUUIDs = this.panoVTemp[panoId].neighbourUUIDs;
  3833. o.neighbourPanos = this.panoVTemp[panoId].neighbourPanos;
  3834. } else {
  3835. //o.seeMarkers = panos.index[panoId].seeMarkers.slice(0);
  3836. o.neighbourUUIDs = panos.index[panoId].neighbourUUIDs.slice(0);
  3837. o.neighbourPanos = CloneObject(panos.index[panoId].neighbourPanos);
  3838. }
  3839. return o;
  3840. },
  3841. turnToPanoIndex: function(panoArr) {
  3842. var panos = player.model.panos;
  3843. var array = [];
  3844. for (var i = 0; i < panoArr.length; i++) {
  3845. var pano = panos.index[panoArr[i]];
  3846. var index = panos.list.indexOf(pano)
  3847. array.push(index);
  3848. }
  3849. return array;
  3850. },
  3851. setDisplay: function(state) {
  3852. var panos = player.model.panos;
  3853. if (state) {
  3854. this.$confirmSnap.text('保存当前设置');
  3855. this.$confirmSnap.removeClass('hide');
  3856. } else {
  3857. this.$confirmSnap.addClass('hide');
  3858. this.changeBtn.addClass('hide')
  3859. }
  3860. player.path.currentPanoMarker.mesh.visible = !state;
  3861. player.overlayGroup.visible = !state;
  3862. player.reticule.visible = !state;
  3863. },
  3864. delVisibleLines: function() {
  3865. //xzw add 所有线都删除
  3866. for (var i in this.tagsVLines) {
  3867. this.tagsVLines[i].geometry.dispose();
  3868. this.tagsVLines[i].material.dispose();
  3869. this.meshGroup.remove(this.tagsVLines[i]);
  3870. delete this.tagsVLines[i];
  3871. }
  3872. for (var i in this.panoVLines) {
  3873. this.panoVLines[i].geometry.dispose();
  3874. this.panoVLines[i].material.dispose();
  3875. this.meshGroup.remove(this.panoVLines[i]);
  3876. delete this.panoVLines[i];
  3877. }
  3878. },
  3879. //--------panoVisible
  3880. createPanoVisiLines: function(pano) {
  3881. // pano可见性线条
  3882. var neighbours = this.panoVTemp[pano.id] && this.panoVTemp[pano.id].neighbourPanos || pano.neighbourPanos;
  3883. for (var r in neighbours) {
  3884. if (neighbours[r] && r != pano.id) {
  3885. this.createPanoSingleLine(pano, "old", r)
  3886. }
  3887. }
  3888. },
  3889. createPanoSingleLine: function(pano, type, id) {
  3890. //pano是中心
  3891. var panos = player.model.panos;
  3892. var p2 = panos.index[id].floorPosition.clone()
  3893. /* .sub(player.model.position) */
  3894. var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
  3895. , p2], {
  3896. color: this.colors.green
  3897. });
  3898. this.meshGroup.add(line);
  3899. line.name = "PanoVL-" + type + "-" + id;
  3900. this.panoVLines[id] = line;
  3901. this.changeFIconState(panos.index[id].footIcon, "linked")
  3902. },
  3903. dealPanoVisible: function(id) {
  3904. //外部调用
  3905. var panos = player.model.panos;
  3906. if (this.panoVsetting) {
  3907. if (id == this.panoVsetting.id) {
  3908. //关闭当前pano设置
  3909. this.pauseSetPanoVisible('unsaved')
  3910. } else {
  3911. var link;
  3912. //结果是否连接
  3913. if (this.panoVLines[id]) {
  3914. this.panoVLines[id].visible = !this.panoVLines[id].visible;
  3915. link = this.panoVLines[id].visible;
  3916. this.changeFIconState(panos.index[id].footIcon, this.panoVLines[id].visible ? "linked" : false)
  3917. } else {
  3918. this.createPanoSingleLine(this.panoVsetting, "new", id)
  3919. link = true;
  3920. }
  3921. if (link) {
  3922. //如果连接上了,直接判断该点是可见的(有附近点),(不能通过checkHasNeighbor来判断,因为新增的线条可能不在它的neighbour中
  3923. this.changeFIconState2(panos.index[id].footIcon, true)
  3924. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, true)
  3925. } else {
  3926. //否则需要checkHasNeighbor
  3927. this.changeFIconState2(panos.index[id].footIcon, this.checkHasNeighbor(panos.index[id]))
  3928. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, this.checkHasNeighbor(this.panoVsetting))
  3929. }
  3930. /* if(window.routeArray){//箭头路线
  3931. if(this.panoVLines[id].visible)window.routeArray.push(id)
  3932. else{
  3933. let index = window.routeArray.indexOf(id)
  3934. index > -1 && routeArray.splice(index, 1)
  3935. }
  3936. } */
  3937. }
  3938. } else {
  3939. //点击开始设置要设置的pano
  3940. this.SetOnePanoVisible(panos.index[id])
  3941. }
  3942. this.updateFootIconSize()
  3943. },
  3944. showFootIcons: function(pano, isPanovisible) {
  3945. if (!this.footIcons) {
  3946. footTex1 = Texture.load("images/edit/End_128.png");
  3947. //Store.FootIcon);
  3948. footTex2 = Texture.load("images/edit/End_unable_128.png");
  3949. //Store.FootIcon_unable);
  3950. this.footIcons = [];
  3951. var scale = 0.4;
  3952. scale *= 40 / Math.sqrt(Math.min($("#player").width(), $("#player").height()));
  3953. //屏幕越小,放得越大
  3954. scale = THREE.Math.clamp(scale, 0.3, 0.7)
  3955. //console.log("scale"+scale)
  3956. var geo = new THREE.PlaneGeometry(scale,scale,1,1)
  3957. var panos = player.model.panos;
  3958. for (var r in panos.index) {
  3959. if (!panos.index[r].isAligned())
  3960. continue;
  3961. var t = THREE.UniformsUtils.clone(shaders.waypoint.uniforms);
  3962. t.map.value = footTex1
  3963. t.color.value.set("#ffffff");
  3964. var mat = new THREE.RawShaderMaterial({
  3965. vertexShader: shaders.waypoint.vertexShader,
  3966. fragmentShader: shaders.waypoint.fragmentShader,
  3967. uniforms: t,
  3968. side: THREE.DoubleSide,
  3969. transparent: !0,
  3970. depthWrite: !1,
  3971. depthTest: false,
  3972. name: "footIcon"
  3973. })
  3974. var foot = new THREE.Mesh(geo,mat)
  3975. foot.position.copy(panos.index[r].floorPosition.clone()/* .sub(player.model.position) */
  3976. )
  3977. foot.lookAt(foot.position.clone().add(new THREE.Vector3(0,1,0)));
  3978. foot.name = panos.index[r].id;
  3979. foot.visible = false;
  3980. foot.renderOrder = 6,
  3981. panos.index[r].footIcon = foot;
  3982. this.meshGroup.add(foot);
  3983. this.footIcons.push(foot)
  3984. }
  3985. }
  3986. for (var i = 0; i < this.footIcons.length; i++) {
  3987. this.footIcons[i].visible = true;
  3988. this.changeFIconState(this.footIcons[i], false)
  3989. var panos = player.model.panos;
  3990. if (isPanovisible) {
  3991. this.changeFIconState2(this.footIcons[i], this.checkHasNeighbor(panos.index[this.footIcons[i].name], "showFoot"))
  3992. }
  3993. if (pano && (this.footIcons[i].name == pano.id)) {
  3994. //pano为中心 或者 currentPano 所以放大一点
  3995. this.footIcons[i].oriScale = new THREE.Vector3(1.5,1.5,1.5)
  3996. if (isPanovisible) {
  3997. //currentPano特殊些:
  3998. this.changeFIconState(this.footIcons[i], "center")
  3999. //this.footIcons[i].Unclick = true;//不让点击和hover
  4000. }
  4001. } else {
  4002. this.footIcons[i].oriScale = new THREE.Vector3(1,1,1)
  4003. }
  4004. }
  4005. },
  4006. checkHasNeighbor: function(pano, state) {
  4007. //检查当前状态pano点是否有可通行点
  4008. var neighbours = /* this.panoVTemp && */
  4009. this.panoVTemp[pano.id] ? this.panoVTemp[pano.id].neighbourPanos : pano.neighbourPanos;
  4010. if (state != "showFoot" && pano == this.panoVsetting) {
  4011. //是中心点的话。state == "showFoot"代表是showFootIcon时, 这时候线还没创建,无法用线判断中心点有几个相邻点,直接用neighbourPanos
  4012. for (var i in this.panoVLines) {
  4013. if (this.panoVLines[i].visible) {
  4014. return true;
  4015. //有一条线即可
  4016. }
  4017. }
  4018. return;
  4019. }
  4020. for (var i in neighbours) {
  4021. if (i == pano.id)
  4022. continue;
  4023. if (neighbours[i]) {
  4024. if (this.panoVsetting && this.panoVsetting.id == i && this.panoVLines[pano.id] && !this.panoVLines[pano.id].visible)
  4025. continue;
  4026. return true;
  4027. }
  4028. }
  4029. return false;
  4030. },
  4031. /* ifAllPanoNoNeighbor : function(){//检查是否全是孤立点
  4032. var panos = player.model.panos;
  4033. for(var i in panos.index){
  4034. if(this.checkHasNeighbor(panos.index[i])){
  4035. return false;
  4036. }
  4037. }
  4038. this.noPanoHasNeighbor = true;
  4039. return true;//是全部没有neighbour
  4040. }, */
  4041. changeFIconState: function(footIcon, state) {
  4042. var color = state == "linked" ? this.colors.green : (state == "center" ? /* "#d7f244" */
  4043. "#d5f12e" : "#ffffff");
  4044. footIcon.material.uniforms.color.value.set(color)
  4045. },
  4046. changeFIconState2: function(footIcon, state) {
  4047. //是可见点还是不可见点
  4048. if (state) {
  4049. footIcon.material.uniforms.map.value = footTex1;
  4050. if (this.panoVsetting) {
  4051. if (this.panoVsetting.id != footIcon.name) {
  4052. footIcon.material.uniforms.opacity.value = 1;
  4053. } else {
  4054. this.changeVisiBtnState(true)
  4055. }
  4056. }
  4057. } else {
  4058. //不可见
  4059. footIcon.material.uniforms.map.value = footTex2;
  4060. if (!this.panoVsetting || this.panoVsetting.id != footIcon.name) {
  4061. //非中心点时
  4062. footIcon.material.uniforms.opacity.value = 0.5;
  4063. } else {
  4064. //变为中心点时
  4065. footIcon.material.uniforms.opacity.value = 1;
  4066. this.changeVisiBtnState(false)
  4067. }
  4068. }
  4069. },
  4070. hideFootIcons: function() {
  4071. if (!this.footIcons)
  4072. return;
  4073. for (var i = 0; i < this.footIcons.length; i++) {
  4074. this.footIcons[i].visible = false;
  4075. }
  4076. },
  4077. updateFootIconSize: function() {
  4078. //根据相机位置 改变footIcon大小,使在范围内看到的热点大小一致,防止太小点击不到
  4079. if (!this.footIcons)
  4080. return;
  4081. var s = player.cameraControls.controls.floorplan.absoluteScale * 2.8
  4082. s = THREE.Math.clamp(s, 0.5 * this.footIconSizeRatio, 1.4 * this.footIconSizeRatio);
  4083. this.footIcons.forEach(function(f) {
  4084. try {
  4085. f.scale.copy(f.oriScale).multiplyScalar(s);
  4086. } catch (e) {
  4087. console.log(e)
  4088. }
  4089. })
  4090. }
  4091. //========热点可见性==============
  4092. ,
  4093. beginSetTagVisible: function() {
  4094. if (this.setTagVisible)
  4095. return;
  4096. $(".toolTop").addClass("unable")
  4097. $("#hotVisible").addClass("unable")
  4098. this.setTagVisible = true;
  4099. this.tagVTemp = {};
  4100. this.$confirmSnap.text('完成设置').removeClass("hide")
  4101. //objects.tagManager.hideAllTags();
  4102. for (let i in player.model.hots) {
  4103. player.model.hots[i]._isSprite = player.model.hots[i].isSprite;
  4104. player.model.hots[i].isSprite = true;
  4105. player.model.hots[i].mesh.material.depthTest = false;
  4106. }
  4107. this.setDisplay(true)
  4108. this.updateFootIconSize()
  4109. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  4110. },
  4111. SetOneTagVisible: function(tag) {
  4112. //点击某个热点后就对该热点进行设置,或者在热点修改时对其进行设置
  4113. if (this.tagVsetting == tag)
  4114. return;
  4115. if (this.tagVsetting) {
  4116. this.saveLastTagVi(this.tagVsetting);
  4117. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL);
  4118. }
  4119. this.tagVsetting = tag;
  4120. //记录正在修改的
  4121. this.delVisibleLines();
  4122. //删除线
  4123. this.showFootIcons(player.currentPano);
  4124. this.createTagVisiLines(tag);
  4125. //创线
  4126. this.updateFootIconSize()
  4127. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  4128. },
  4129. saveLastTagVi: function() {
  4130. //保存刚设置过的tag
  4131. var change = false;
  4132. var newVPs = this.tagVTemp[this.tagVsetting.sid] || this.tagVsetting.visiblePanos.slice(0);
  4133. for (var r in this.tagsVLines) {
  4134. var line = this.tagsVLines[r];
  4135. if (line.name.indexOf("new") > -1 && line.visible) {
  4136. //新设置为visible且没有取消
  4137. newVPs.push(r)
  4138. change = true;
  4139. //console.log("add: "+r)
  4140. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  4141. //旧的且已经取消
  4142. var i = newVPs.indexOf(r);
  4143. if (i == -1) {
  4144. console.log("visiblePanos删除error");
  4145. continue;
  4146. }
  4147. newVPs.splice(i, 1);
  4148. change = true;
  4149. //console.log("sub: "+r)
  4150. }
  4151. }
  4152. if (change) {
  4153. this.tagVTemp[this.tagVsetting.sid] = newVPs;
  4154. }
  4155. },
  4156. pauseSetTagVisible: function() {
  4157. //pc保存后删除连线 但还在继续设置 点选热点即开始
  4158. if (!this.setTagVisible || !this.tagVsetting)
  4159. return;
  4160. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL );
  4161. this.delVisibleLines();
  4162. this.hideFootIcons();
  4163. this.tagVTemp = {};
  4164. this.tagVsetting = null;
  4165. },
  4166. finishSetTagVisible: function() {
  4167. if (!this.setTagVisible)
  4168. return;
  4169. $(".toolTop").removeClass("unable")
  4170. $("#hotVisible").removeClass("unable")
  4171. this.pauseSetTagVisible();
  4172. this.setTagVisible = false;
  4173. this.setDisplay(false)
  4174. this.$confirmSnap.addClass("hide")
  4175. permitTranMode(true)
  4176. /* for (var r in objects.tagManager.tags) {
  4177. if(objects.tagManager.tags[r].state == "videoPanoFlag")continue;
  4178. objects.tagManager.tags[r].disc.visible = false;
  4179. objects.tagManager.tags[r].disc.material.depthTest = true;
  4180. } */
  4181. for (let i in player.model.hots) {
  4182. player.model.hots[i].isSprite = player.model.hots[i]._isSprite;
  4183. player.model.hots[i].isSprite || player.model.hots[i].mesh.quaternion.copy(player.model.hots[i].quaternion)
  4184. player.model.hots[i].mesh.material.depthTest = true;
  4185. }
  4186. },
  4187. /* saveTagVisibles : function () { //保存到服务器
  4188. if (this.tagVsetting) this.saveLastTagVi(this.tagVsetting); //获取最后设置的那个热点的改动
  4189. //可能出现数据没变但保存的情况。比如先改变了然后切换别的热点但切换回来时又改回来。
  4190. var tags = [];
  4191. for (var i in this.tagVTemp) {
  4192. tags.push({
  4193. sid: i,
  4194. value: this.tagVTemp[i]//turnToPanoIndex(this.tagVTemp[i])
  4195. })
  4196. }
  4197. if (tags.length == 0) {//没有需要保存的改动
  4198. this.finishSetTagVisible()
  4199. return;
  4200. }
  4201. return tags;
  4202. } */
  4203. //afterSaveTagVisibles : function(){
  4204. saveTagVisibles: function() {
  4205. if (this.tagVsetting)
  4206. this.saveLastTagVi(this.tagVsetting);
  4207. for (var i in this.tagVTemp) {
  4208. //保持成功于是生效
  4209. player.model.hots[i].visiblePanos = this.tagVTemp[i];
  4210. }
  4211. this.finishSetTagVisible()
  4212. //还是保存完直接结束吧,因为现在热点可视不放在单独的设置页面了
  4213. },
  4214. createTagVisiLines: function(tag) {
  4215. // 热点可见性线条
  4216. var panos = player.model.panos;
  4217. tag.visiblePanos || tag.setVisiblePanos("get")
  4218. var visibleList = this.tagVTemp[tag.sid] || tag.visiblePanos;
  4219. //如果是刚在设置的要读取设置过的数据
  4220. for (var r = 0; r < visibleList.length; r++) {
  4221. var pano = panos.index[visibleList[r]];
  4222. this.createTagSingleLine(pano, "old", tag)
  4223. }
  4224. },
  4225. createTagSingleLine: function(pano, type, tag) {
  4226. var panos = player.model.panos;
  4227. var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
  4228. , tag.mesh.position.clone()], {
  4229. color: this.colors.green
  4230. });
  4231. this.meshGroup.add(line);
  4232. line.name = "tagVL-" + type + "-" + pano.id;
  4233. this.tagsVLines[pano.id] = line;
  4234. this.changeFIconState(panos.index[pano.id].footIcon, "linked")
  4235. },
  4236. dealTagVisible: function(tag, panoName) {
  4237. //外部调用
  4238. var panos = player.model.panos;
  4239. if (this.tagsVLines[panoName]) {
  4240. this.tagsVLines[panoName].visible = !this.tagsVLines[panoName].visible;
  4241. this.changeFIconState(panos.index[panoName].footIcon, this.tagsVLines[panoName].visible ? "linked" : false)
  4242. } else {
  4243. this.createTagSingleLine(panos.index[panoName], "new", tag)
  4244. }
  4245. },
  4246. delVisibleLines: function() {
  4247. //xzw add 所有线都删除
  4248. for (var i in this.tagsVLines) {
  4249. this.tagsVLines[i].geometry.dispose();
  4250. this.tagsVLines[i].material.dispose();
  4251. this.meshGroup.remove(this.tagsVLines[i]);
  4252. delete this.tagsVLines[i];
  4253. }
  4254. for (var i in this.panoVLines) {
  4255. this.panoVLines[i].geometry.dispose();
  4256. this.panoVLines[i].material.dispose();
  4257. this.meshGroup.remove(this.panoVLines[i]);
  4258. delete this.panoVLines[i];
  4259. }
  4260. }
  4261. }
  4262. function permitTranMode(state) {
  4263. state ? $(".pinBottom.left").removeClass('hide') : $(".pinBottom.left").addClass('hide');
  4264. }
  4265. function randomWord(randomFlag, min, max) {
  4266. //随机字符串
  4267. var str = ""
  4268. , range = min
  4269. , 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'];
  4270. if (randomFlag) {
  4271. // 随机长度
  4272. range = Math.round(Math.random() * (max - min)) + min;
  4273. }
  4274. for (var i = 0; i < range; i++) {
  4275. var pos = Math.round(Math.random() * (arr.length - 1));
  4276. str += arr[pos];
  4277. }
  4278. return str;
  4279. }
  4280. function getRandomSid() {
  4281. //5-7位随机字符串 + 6位时间 为热点准备
  4282. var pre = randomWord(true, 5, 7);
  4283. var post = new Date().getTime() + "";
  4284. var len = post.length;
  4285. post = post.substring(len - 8, len - 5) + post.substring(len - 3, len)
  4286. //其实还是有可能重复的....
  4287. return pre + post;
  4288. }
  4289. function searchParent(searchArea, o, maxTimes) {
  4290. //是否是某种元素的下级,并找出该元素
  4291. maxTimes = maxTimes || 20;
  4292. var count = 0
  4293. var f = function(dom) {
  4294. if (o.id && o.id == dom.id)
  4295. return dom
  4296. else if (o.className && dom.classList && dom.classList.contains(o.className))
  4297. return dom
  4298. else if (o.tagName && dom.tagName && o.tagName.toUpperCase() == dom.tagName.toUpperCase())
  4299. return dom
  4300. }
  4301. var find;
  4302. while (searchArea && count < maxTimes) {
  4303. if (find = f(searchArea))
  4304. return find
  4305. searchArea = searchArea.parentNode;
  4306. count++;
  4307. }
  4308. }
  4309. class ListBox{//下拉列表
  4310. //elemArr:初始的列表,内含每项的dom.
  4311. constructor(elemArr, $rootDom, options={}){
  4312. this.listDom = $rootDom.find('ul.list')
  4313. this.listTitle = $rootDom.find('.selection')
  4314. this.chosenItem = null
  4315. this.options = options;
  4316. this.bindEvents()
  4317. elemArr.forEach(($dom, i)=>{
  4318. this.addItem($dom)
  4319. })
  4320. }
  4321. updateSelectDisplay(){
  4322. this.listDom.children().removeClass('selected')
  4323. this.chosenItem && this.chosenItem.addClass("selected")
  4324. this.options.selectFun(this.chosenIndex)
  4325. }
  4326. selectFromOutSide(index ){
  4327. this.chosenIndex = index;
  4328. this.chosenItem = index == void 0 ? null : this.listDom.children().eq(index)
  4329. this.updateSelectDisplay()
  4330. }
  4331. addItem($dom){
  4332. this.listDom.append($dom)
  4333. if(this.options.addFun){
  4334. this.options.addFun($dom)
  4335. }
  4336. $dom.on('click',()=>{
  4337. this.chosenItem = $dom;
  4338. this.chosenIndex = $dom.index();
  4339. this.updateSelectDisplay()
  4340. })
  4341. }
  4342. removeItem($dom){
  4343. $dom.remove()
  4344. if(this.options.delFun){
  4345. this.options.delFun($dom)
  4346. }
  4347. }
  4348. saveTemp(){//编辑热点时保存一份副本
  4349. this.temp = Array.from(this.listDom.children()).map((li)=>{
  4350. return li.outerHTML
  4351. })
  4352. this.options.saveTemp && this.options.saveTemp(this)
  4353. }
  4354. recover(){//取消编辑时恢复
  4355. this.listDom.html('')
  4356. this.temp.forEach(html=>{
  4357. this.addItem($(html));
  4358. })
  4359. this.options.recover && this.options.recover(this)
  4360. this.selectFromOutSide(this.chosenIndex)
  4361. }
  4362. bindEvents(){
  4363. this.listTitle.on('click',(e)=>{
  4364. e.stopPropagation()
  4365. this.listDom.toggleClass('hide')
  4366. })
  4367. document.addEventListener('click',()=>{
  4368. this.listDom.addClass('hide')
  4369. })
  4370. }
  4371. }