edit.js 203 KB

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