edit.js 243 KB

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