edit.js 184 KB

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