edit.js 219 KB

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