edit.js 261 KB

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