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