edit.js 205 KB

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