laya.d3.js 1.4 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336
  1. (function (exports, Laya) {
  2. 'use strict';
  3. class MathUtils3D {
  4. constructor() {
  5. }
  6. static isZero(v) {
  7. return Math.abs(v) < MathUtils3D.zeroTolerance;
  8. }
  9. static nearEqual(n1, n2) {
  10. if (MathUtils3D.isZero(n1 - n2))
  11. return true;
  12. return false;
  13. }
  14. static fastInvSqrt(value) {
  15. if (MathUtils3D.isZero(value))
  16. return value;
  17. return 1.0 / Math.sqrt(value);
  18. }
  19. }
  20. MathUtils3D.zeroTolerance = 1e-6;
  21. MathUtils3D.MaxValue = 3.40282347e+38;
  22. MathUtils3D.MinValue = -3.40282347e+38;
  23. class Vector2 {
  24. constructor(x = 0, y = 0) {
  25. this.x = x;
  26. this.y = y;
  27. }
  28. setValue(x, y) {
  29. this.x = x;
  30. this.y = y;
  31. }
  32. static scale(a, b, out) {
  33. out.x = a.x * b;
  34. out.y = a.y * b;
  35. }
  36. fromArray(array, offset = 0) {
  37. this.x = array[offset + 0];
  38. this.y = array[offset + 1];
  39. }
  40. cloneTo(destObject) {
  41. var destVector2 = destObject;
  42. destVector2.x = this.x;
  43. destVector2.y = this.y;
  44. }
  45. static dot(a, b) {
  46. return (a.x * b.x) + (a.y * b.y);
  47. }
  48. static normalize(s, out) {
  49. var x = s.x, y = s.y;
  50. var len = x * x + y * y;
  51. if (len > 0) {
  52. len = 1 / Math.sqrt(len);
  53. out.x = x * len;
  54. out.y = y * len;
  55. }
  56. }
  57. static scalarLength(a) {
  58. var x = a.x, y = a.y;
  59. return Math.sqrt(x * x + y * y);
  60. }
  61. clone() {
  62. var destVector2 = new Vector2();
  63. this.cloneTo(destVector2);
  64. return destVector2;
  65. }
  66. forNativeElement(nativeElements = null) {
  67. if (nativeElements) {
  68. this.elements = nativeElements;
  69. this.elements[0] = this.x;
  70. this.elements[1] = this.y;
  71. }
  72. else {
  73. this.elements = new Float32Array([this.x, this.y]);
  74. }
  75. Vector2.rewriteNumProperty(this, "x", 0);
  76. Vector2.rewriteNumProperty(this, "y", 1);
  77. }
  78. static rewriteNumProperty(proto, name, index) {
  79. Object["defineProperty"](proto, name, {
  80. "get": function () {
  81. return this.elements[index];
  82. },
  83. "set": function (v) {
  84. this.elements[index] = v;
  85. }
  86. });
  87. }
  88. }
  89. Vector2.ZERO = new Vector2(0.0, 0.0);
  90. Vector2.ONE = new Vector2(1.0, 1.0);
  91. class Vector4 {
  92. constructor(x = 0, y = 0, z = 0, w = 0) {
  93. this.x = x;
  94. this.y = y;
  95. this.z = z;
  96. this.w = w;
  97. }
  98. setValue(x, y, z, w) {
  99. this.x = x;
  100. this.y = y;
  101. this.z = z;
  102. this.w = w;
  103. }
  104. fromArray(array, offset = 0) {
  105. this.x = array[offset + 0];
  106. this.y = array[offset + 1];
  107. this.z = array[offset + 2];
  108. this.w = array[offset + 3];
  109. }
  110. cloneTo(destObject) {
  111. var destVector4 = destObject;
  112. destVector4.x = this.x;
  113. destVector4.y = this.y;
  114. destVector4.z = this.z;
  115. destVector4.w = this.w;
  116. }
  117. clone() {
  118. var destVector4 = new Vector4();
  119. this.cloneTo(destVector4);
  120. return destVector4;
  121. }
  122. static lerp(a, b, t, out) {
  123. var ax = a.x, ay = a.y, az = a.z, aw = a.w;
  124. out.x = ax + t * (b.x - ax);
  125. out.y = ay + t * (b.y - ay);
  126. out.z = az + t * (b.z - az);
  127. out.w = aw + t * (b.w - aw);
  128. }
  129. static transformByM4x4(vector4, m4x4, out) {
  130. var vx = vector4.x;
  131. var vy = vector4.y;
  132. var vz = vector4.z;
  133. var vw = vector4.w;
  134. var me = m4x4.elements;
  135. out.x = vx * me[0] + vy * me[4] + vz * me[8] + vw * me[12];
  136. out.y = vx * me[1] + vy * me[5] + vz * me[9] + vw * me[13];
  137. out.z = vx * me[2] + vy * me[6] + vz * me[10] + vw * me[14];
  138. out.w = vx * me[3] + vy * me[7] + vz * me[11] + vw * me[15];
  139. }
  140. static equals(a, b) {
  141. return MathUtils3D.nearEqual(Math.abs(a.x), Math.abs(b.x)) && MathUtils3D.nearEqual(Math.abs(a.y), Math.abs(b.y)) && MathUtils3D.nearEqual(Math.abs(a.z), Math.abs(b.z)) && MathUtils3D.nearEqual(Math.abs(a.w), Math.abs(b.w));
  142. }
  143. length() {
  144. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  145. }
  146. lengthSquared() {
  147. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  148. }
  149. static normalize(s, out) {
  150. var len = s.length();
  151. if (len > 0) {
  152. out.x = s.x * len;
  153. out.y = s.y * len;
  154. out.z = s.z * len;
  155. out.w = s.w * len;
  156. }
  157. }
  158. static add(a, b, out) {
  159. out.x = a.x + b.x;
  160. out.y = a.y + b.y;
  161. out.z = a.z + b.z;
  162. out.w = a.w + b.w;
  163. }
  164. static subtract(a, b, out) {
  165. out.x = a.x - b.x;
  166. out.y = a.y - b.y;
  167. out.z = a.z - b.z;
  168. out.w = a.w - b.w;
  169. }
  170. static multiply(a, b, out) {
  171. out.x = a.x * b.x;
  172. out.y = a.y * b.y;
  173. out.z = a.z * b.z;
  174. out.w = a.w * b.w;
  175. }
  176. static scale(a, b, out) {
  177. out.x = a.x * b;
  178. out.y = a.y * b;
  179. out.z = a.z * b;
  180. out.w = a.w * b;
  181. }
  182. static Clamp(value, min, max, out) {
  183. var x = value.x;
  184. var y = value.y;
  185. var z = value.z;
  186. var w = value.w;
  187. var mineX = min.x;
  188. var mineY = min.y;
  189. var mineZ = min.z;
  190. var mineW = min.w;
  191. var maxeX = max.x;
  192. var maxeY = max.y;
  193. var maxeZ = max.z;
  194. var maxeW = max.w;
  195. x = (x > maxeX) ? maxeX : x;
  196. x = (x < mineX) ? mineX : x;
  197. y = (y > maxeY) ? maxeY : y;
  198. y = (y < mineY) ? mineY : y;
  199. z = (z > maxeZ) ? maxeZ : z;
  200. z = (z < mineZ) ? mineZ : z;
  201. w = (w > maxeW) ? maxeW : w;
  202. w = (w < mineW) ? mineW : w;
  203. out.x = x;
  204. out.y = y;
  205. out.z = z;
  206. out.w = w;
  207. }
  208. static distanceSquared(value1, value2) {
  209. var x = value1.x - value2.x;
  210. var y = value1.y - value2.y;
  211. var z = value1.z - value2.z;
  212. var w = value1.w - value2.w;
  213. return (x * x) + (y * y) + (z * z) + (w * w);
  214. }
  215. static distance(value1, value2) {
  216. var x = value1.x - value2.x;
  217. var y = value1.y - value2.y;
  218. var z = value1.z - value2.z;
  219. var w = value1.w - value2.w;
  220. return Math.sqrt((x * x) + (y * y) + (z * z) + (w * w));
  221. }
  222. static dot(a, b) {
  223. return (a.x * b.x) + (a.y * b.y) + (a.z * b.z) + (a.w * b.w);
  224. }
  225. static min(a, b, out) {
  226. out.x = Math.min(a.x, b.x);
  227. out.y = Math.min(a.y, b.y);
  228. out.z = Math.min(a.z, b.z);
  229. out.w = Math.min(a.w, b.w);
  230. }
  231. static max(a, b, out) {
  232. out.x = Math.max(a.x, b.x);
  233. out.y = Math.max(a.y, b.y);
  234. out.z = Math.max(a.z, b.z);
  235. out.w = Math.max(a.w, b.w);
  236. }
  237. forNativeElement(nativeElements = null) {
  238. if (nativeElements) {
  239. this.elements = nativeElements;
  240. this.elements[0] = this.x;
  241. this.elements[1] = this.y;
  242. this.elements[2] = this.z;
  243. this.elements[3] = this.w;
  244. }
  245. else {
  246. this.elements = new Float32Array([this.x, this.y, this.z, this.w]);
  247. }
  248. Vector2.rewriteNumProperty(this, "x", 0);
  249. Vector2.rewriteNumProperty(this, "y", 1);
  250. Vector2.rewriteNumProperty(this, "z", 2);
  251. Vector2.rewriteNumProperty(this, "w", 3);
  252. }
  253. }
  254. Vector4.ZERO = new Vector4();
  255. Vector4.ONE = new Vector4(1.0, 1.0, 1.0, 1.0);
  256. Vector4.UnitX = new Vector4(1.0, 0.0, 0.0, 0.0);
  257. Vector4.UnitY = new Vector4(0.0, 1.0, 0.0, 0.0);
  258. Vector4.UnitZ = new Vector4(0.0, 0.0, 1.0, 0.0);
  259. Vector4.UnitW = new Vector4(0.0, 0.0, 0.0, 1.0);
  260. class Vector3 {
  261. constructor(x = 0, y = 0, z = 0, nativeElements = null) {
  262. this.x = x;
  263. this.y = y;
  264. this.z = z;
  265. }
  266. static distanceSquared(value1, value2) {
  267. var x = value1.x - value2.x;
  268. var y = value1.y - value2.y;
  269. var z = value1.z - value2.z;
  270. return (x * x) + (y * y) + (z * z);
  271. }
  272. static distance(value1, value2) {
  273. var x = value1.x - value2.x;
  274. var y = value1.y - value2.y;
  275. var z = value1.z - value2.z;
  276. return Math.sqrt((x * x) + (y * y) + (z * z));
  277. }
  278. static min(a, b, out) {
  279. out.x = Math.min(a.x, b.x);
  280. out.y = Math.min(a.y, b.y);
  281. out.z = Math.min(a.z, b.z);
  282. }
  283. static max(a, b, out) {
  284. out.x = Math.max(a.x, b.x);
  285. out.y = Math.max(a.y, b.y);
  286. out.z = Math.max(a.z, b.z);
  287. }
  288. static transformQuat(source, rotation, out) {
  289. var x = source.x, y = source.y, z = source.z, qx = rotation.x, qy = rotation.y, qz = rotation.z, qw = rotation.w, ix = qw * x + qy * z - qz * y, iy = qw * y + qz * x - qx * z, iz = qw * z + qx * y - qy * x, iw = -qx * x - qy * y - qz * z;
  290. out.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  291. out.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  292. out.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  293. }
  294. static scalarLength(a) {
  295. var x = a.x, y = a.y, z = a.z;
  296. return Math.sqrt(x * x + y * y + z * z);
  297. }
  298. static scalarLengthSquared(a) {
  299. var x = a.x, y = a.y, z = a.z;
  300. return x * x + y * y + z * z;
  301. }
  302. static normalize(s, out) {
  303. var x = s.x, y = s.y, z = s.z;
  304. var len = x * x + y * y + z * z;
  305. if (len > 0) {
  306. len = 1 / Math.sqrt(len);
  307. out.x = s.x * len;
  308. out.y = s.y * len;
  309. out.z = s.z * len;
  310. }
  311. }
  312. static multiply(a, b, out) {
  313. out.x = a.x * b.x;
  314. out.y = a.y * b.y;
  315. out.z = a.z * b.z;
  316. }
  317. static scale(a, b, out) {
  318. out.x = a.x * b;
  319. out.y = a.y * b;
  320. out.z = a.z * b;
  321. }
  322. static lerp(a, b, t, out) {
  323. var ax = a.x, ay = a.y, az = a.z;
  324. out.x = ax + t * (b.x - ax);
  325. out.y = ay + t * (b.y - ay);
  326. out.z = az + t * (b.z - az);
  327. }
  328. static transformV3ToV3(vector, transform, result) {
  329. var intermediate = Vector3._tempVector4;
  330. Vector3.transformV3ToV4(vector, transform, intermediate);
  331. result.x = intermediate.x;
  332. result.y = intermediate.y;
  333. result.z = intermediate.z;
  334. }
  335. static transformV3ToV4(vector, transform, result) {
  336. var vectorX = vector.x;
  337. var vectorY = vector.y;
  338. var vectorZ = vector.z;
  339. var transformElem = transform.elements;
  340. result.x = (vectorX * transformElem[0]) + (vectorY * transformElem[4]) + (vectorZ * transformElem[8]) + transformElem[12];
  341. result.y = (vectorX * transformElem[1]) + (vectorY * transformElem[5]) + (vectorZ * transformElem[9]) + transformElem[13];
  342. result.z = (vectorX * transformElem[2]) + (vectorY * transformElem[6]) + (vectorZ * transformElem[10]) + transformElem[14];
  343. result.w = (vectorX * transformElem[3]) + (vectorY * transformElem[7]) + (vectorZ * transformElem[11]) + transformElem[15];
  344. }
  345. static TransformNormal(normal, transform, result) {
  346. var normalX = normal.x;
  347. var normalY = normal.y;
  348. var normalZ = normal.z;
  349. var transformElem = transform.elements;
  350. result.x = (normalX * transformElem[0]) + (normalY * transformElem[4]) + (normalZ * transformElem[8]);
  351. result.y = (normalX * transformElem[1]) + (normalY * transformElem[5]) + (normalZ * transformElem[9]);
  352. result.z = (normalX * transformElem[2]) + (normalY * transformElem[6]) + (normalZ * transformElem[10]);
  353. }
  354. static transformCoordinate(coordinate, transform, result) {
  355. var coordinateX = coordinate.x;
  356. var coordinateY = coordinate.y;
  357. var coordinateZ = coordinate.z;
  358. var transformElem = transform.elements;
  359. var w = ((coordinateX * transformElem[3]) + (coordinateY * transformElem[7]) + (coordinateZ * transformElem[11]) + transformElem[15]);
  360. result.x = (coordinateX * transformElem[0]) + (coordinateY * transformElem[4]) + (coordinateZ * transformElem[8]) + transformElem[12] / w;
  361. result.y = (coordinateX * transformElem[1]) + (coordinateY * transformElem[5]) + (coordinateZ * transformElem[9]) + transformElem[13] / w;
  362. result.z = (coordinateX * transformElem[2]) + (coordinateY * transformElem[6]) + (coordinateZ * transformElem[10]) + transformElem[14] / w;
  363. }
  364. static Clamp(value, min, max, out) {
  365. var x = value.x;
  366. var y = value.y;
  367. var z = value.z;
  368. var mineX = min.x;
  369. var mineY = min.y;
  370. var mineZ = min.z;
  371. var maxeX = max.x;
  372. var maxeY = max.y;
  373. var maxeZ = max.z;
  374. x = (x > maxeX) ? maxeX : x;
  375. x = (x < mineX) ? mineX : x;
  376. y = (y > maxeY) ? maxeY : y;
  377. y = (y < mineY) ? mineY : y;
  378. z = (z > maxeZ) ? maxeZ : z;
  379. z = (z < mineZ) ? mineZ : z;
  380. out.x = x;
  381. out.y = y;
  382. out.z = z;
  383. }
  384. static add(a, b, out) {
  385. out.x = a.x + b.x;
  386. out.y = a.y + b.y;
  387. out.z = a.z + b.z;
  388. }
  389. static subtract(a, b, o) {
  390. o.x = a.x - b.x;
  391. o.y = a.y - b.y;
  392. o.z = a.z - b.z;
  393. }
  394. static cross(a, b, o) {
  395. var ax = a.x, ay = a.y, az = a.z, bx = b.x, by = b.y, bz = b.z;
  396. o.x = ay * bz - az * by;
  397. o.y = az * bx - ax * bz;
  398. o.z = ax * by - ay * bx;
  399. }
  400. static dot(a, b) {
  401. return (a.x * b.x) + (a.y * b.y) + (a.z * b.z);
  402. }
  403. static equals(a, b) {
  404. return MathUtils3D.nearEqual(a.x, b.x) && MathUtils3D.nearEqual(a.y, b.y) && MathUtils3D.nearEqual(a.z, b.z);
  405. }
  406. setValue(x, y, z) {
  407. this.x = x;
  408. this.y = y;
  409. this.z = z;
  410. }
  411. fromArray(array, offset = 0) {
  412. this.x = array[offset + 0];
  413. this.y = array[offset + 1];
  414. this.z = array[offset + 2];
  415. }
  416. cloneTo(destObject) {
  417. var destVector3 = destObject;
  418. destVector3.x = this.x;
  419. destVector3.y = this.y;
  420. destVector3.z = this.z;
  421. }
  422. clone() {
  423. var destVector3 = new Vector3();
  424. this.cloneTo(destVector3);
  425. return destVector3;
  426. }
  427. toDefault() {
  428. this.x = 0;
  429. this.y = 0;
  430. this.z = 0;
  431. }
  432. forNativeElement(nativeElements = null) {
  433. if (nativeElements) {
  434. this.elements = nativeElements;
  435. this.elements[0] = this.x;
  436. this.elements[1] = this.y;
  437. this.elements[2] = this.z;
  438. }
  439. else {
  440. this.elements = new Float32Array([this.x, this.y, this.z]);
  441. }
  442. Vector2.rewriteNumProperty(this, "x", 0);
  443. Vector2.rewriteNumProperty(this, "y", 1);
  444. Vector2.rewriteNumProperty(this, "z", 2);
  445. }
  446. }
  447. Vector3._tempVector4 = new Vector4();
  448. Vector3._ZERO = new Vector3(0.0, 0.0, 0.0);
  449. Vector3._ONE = new Vector3(1.0, 1.0, 1.0);
  450. Vector3._NegativeUnitX = new Vector3(-1, 0, 0);
  451. Vector3._UnitX = new Vector3(1, 0, 0);
  452. Vector3._UnitY = new Vector3(0, 1, 0);
  453. Vector3._UnitZ = new Vector3(0, 0, 1);
  454. Vector3._ForwardRH = new Vector3(0, 0, -1);
  455. Vector3._ForwardLH = new Vector3(0, 0, 1);
  456. Vector3._Up = new Vector3(0, 1, 0);
  457. class Config3D {
  458. constructor() {
  459. this._defaultPhysicsMemory = 16;
  460. this._editerEnvironment = false;
  461. this.isAntialias = true;
  462. this.isAlpha = false;
  463. this.premultipliedAlpha = true;
  464. this.isStencil = true;
  465. this.octreeCulling = false;
  466. this.octreeInitialSize = 64.0;
  467. this.octreeInitialCenter = new Vector3(0, 0, 0);
  468. this.octreeMinNodeSize = 2.0;
  469. this.octreeLooseness = 1.25;
  470. this.debugFrustumCulling = false;
  471. }
  472. get defaultPhysicsMemory() {
  473. return this._defaultPhysicsMemory;
  474. }
  475. set defaultPhysicsMemory(value) {
  476. if (value < 16)
  477. throw "defaultPhysicsMemory must large than 16M";
  478. this._defaultPhysicsMemory = value;
  479. }
  480. cloneTo(dest) {
  481. var destConfig3D = dest;
  482. destConfig3D._defaultPhysicsMemory = this._defaultPhysicsMemory;
  483. destConfig3D._editerEnvironment = this._editerEnvironment;
  484. destConfig3D.isAntialias = this.isAntialias;
  485. destConfig3D.isAlpha = this.isAlpha;
  486. destConfig3D.premultipliedAlpha = this.premultipliedAlpha;
  487. destConfig3D.isStencil = this.isStencil;
  488. destConfig3D.octreeCulling = this.octreeCulling;
  489. this.octreeInitialCenter.cloneTo(destConfig3D.octreeInitialCenter);
  490. destConfig3D.octreeInitialSize = this.octreeInitialSize;
  491. destConfig3D.octreeMinNodeSize = this.octreeMinNodeSize;
  492. destConfig3D.octreeLooseness = this.octreeLooseness;
  493. destConfig3D.debugFrustumCulling = this.debugFrustumCulling;
  494. }
  495. clone() {
  496. var dest = new Config3D();
  497. this.cloneTo(dest);
  498. return dest;
  499. }
  500. }
  501. Config3D._default = new Config3D();
  502. window.Config3D = Config3D;
  503. class ILaya3D {
  504. }
  505. ILaya3D.Scene3D = null;
  506. ILaya3D.MeshRenderStaticBatchManager = null;
  507. ILaya3D.MeshRenderDynamicBatchManager = null;
  508. ILaya3D.SubMeshDynamicBatch = null;
  509. ILaya3D.Laya3D = null;
  510. ILaya3D.Matrix4x4 = null;
  511. class DynamicBatchManager {
  512. constructor() {
  513. this._batchRenderElementPool = [];
  514. }
  515. static _registerManager(manager) {
  516. DynamicBatchManager._managers.push(manager);
  517. }
  518. _clear() {
  519. this._batchRenderElementPoolIndex = 0;
  520. }
  521. _getBatchRenderElementFromPool() {
  522. throw "StaticBatch:must override this function.";
  523. }
  524. dispose() {
  525. }
  526. }
  527. DynamicBatchManager._managers = [];
  528. class BufferState extends Laya.BufferStateBase {
  529. constructor() {
  530. super();
  531. }
  532. applyVertexBuffer(vertexBuffer) {
  533. if (Laya.BufferStateBase._curBindedBufferState === this) {
  534. var gl = Laya.LayaGL.instance;
  535. var verDec = vertexBuffer.vertexDeclaration;
  536. var valueData = verDec._shaderValues.getData();
  537. this.vertexDeclaration = verDec;
  538. vertexBuffer.bind();
  539. for (var k in valueData) {
  540. var loc = parseInt(k);
  541. var attribute = valueData[k];
  542. gl.enableVertexAttribArray(loc);
  543. gl.vertexAttribPointer(loc, attribute[0], attribute[1], !!attribute[2], attribute[3], attribute[4]);
  544. }
  545. }
  546. else {
  547. throw "BufferState: must call bind() function first.";
  548. }
  549. }
  550. applyVertexBuffers(vertexBuffers) {
  551. if (Laya.BufferStateBase._curBindedBufferState === this) {
  552. var gl = Laya.LayaGL.instance;
  553. for (var i = 0, n = vertexBuffers.length; i < n; i++) {
  554. var verBuf = vertexBuffers[i];
  555. var verDec = verBuf.vertexDeclaration;
  556. var valueData = verDec._shaderValues.getData();
  557. verBuf.bind();
  558. for (var k in valueData) {
  559. var loc = parseInt(k);
  560. var attribute = valueData[k];
  561. gl.enableVertexAttribArray(loc);
  562. gl.vertexAttribPointer(loc, attribute[0], attribute[1], !!attribute[2], attribute[3], attribute[4]);
  563. }
  564. }
  565. }
  566. else {
  567. throw "BufferState: must call bind() function first.";
  568. }
  569. }
  570. applyInstanceVertexBuffer(vertexBuffer) {
  571. if (Laya.LayaGL.layaGPUInstance.supportInstance()) {
  572. if (Laya.BufferStateBase._curBindedBufferState === this) {
  573. var gl = Laya.LayaGL.instance;
  574. var verDec = vertexBuffer.vertexDeclaration;
  575. var valueData = verDec._shaderValues.getData();
  576. vertexBuffer.bind();
  577. for (var k in valueData) {
  578. var loc = parseInt(k);
  579. var attribute = valueData[k];
  580. gl.enableVertexAttribArray(loc);
  581. gl.vertexAttribPointer(loc, attribute[0], attribute[1], !!attribute[2], attribute[3], attribute[4]);
  582. Laya.LayaGL.layaGPUInstance.vertexAttribDivisor(loc, 1);
  583. }
  584. }
  585. else {
  586. throw "BufferState: must call bind() function first.";
  587. }
  588. }
  589. }
  590. applyIndexBuffer(indexBuffer) {
  591. if (Laya.BufferStateBase._curBindedBufferState === this) {
  592. if (this._bindedIndexBuffer !== indexBuffer) {
  593. indexBuffer._bindForVAO();
  594. this._bindedIndexBuffer = indexBuffer;
  595. }
  596. }
  597. else {
  598. throw "BufferState: must call bind() function first.";
  599. }
  600. }
  601. }
  602. class GeometryElement {
  603. constructor() {
  604. this._destroyed = false;
  605. }
  606. get destroyed() {
  607. return this._destroyed;
  608. }
  609. _getType() {
  610. throw "GeometryElement:must override it.";
  611. }
  612. _prepareRender(state) {
  613. return true;
  614. }
  615. _render(state) {
  616. throw "GeometryElement:must override it.";
  617. }
  618. destroy() {
  619. if (this._destroyed)
  620. return;
  621. this._destroyed = true;
  622. }
  623. }
  624. GeometryElement._typeCounter = 0;
  625. class IndexBuffer3D extends Laya.Buffer {
  626. constructor(indexType, indexCount, bufferUsage = 0x88E4, canRead = false) {
  627. super();
  628. this._indexType = indexType;
  629. this._indexCount = indexCount;
  630. this._bufferUsage = bufferUsage;
  631. this._bufferType = Laya.LayaGL.instance.ELEMENT_ARRAY_BUFFER;
  632. this._canRead = canRead;
  633. var byteLength;
  634. if (indexType == IndexBuffer3D.INDEXTYPE_USHORT)
  635. this._indexTypeByteCount = 2;
  636. else if (indexType == IndexBuffer3D.INDEXTYPE_UBYTE)
  637. this._indexTypeByteCount = 1;
  638. else
  639. throw new Error("unidentification index type.");
  640. byteLength = this._indexTypeByteCount * indexCount;
  641. this._byteLength = byteLength;
  642. var curBufSta = Laya.BufferStateBase._curBindedBufferState;
  643. if (curBufSta) {
  644. if (curBufSta._bindedIndexBuffer === this) {
  645. Laya.LayaGL.instance.bufferData(this._bufferType, byteLength, this._bufferUsage);
  646. }
  647. else {
  648. curBufSta.unBind();
  649. this.bind();
  650. Laya.LayaGL.instance.bufferData(this._bufferType, byteLength, this._bufferUsage);
  651. curBufSta.bind();
  652. }
  653. }
  654. else {
  655. this.bind();
  656. Laya.LayaGL.instance.bufferData(this._bufferType, byteLength, this._bufferUsage);
  657. }
  658. if (canRead) {
  659. if (indexType == IndexBuffer3D.INDEXTYPE_USHORT)
  660. this._buffer = new Uint16Array(indexCount);
  661. else if (indexType == IndexBuffer3D.INDEXTYPE_UBYTE)
  662. this._buffer = new Uint8Array(indexCount);
  663. }
  664. }
  665. get indexType() {
  666. return this._indexType;
  667. }
  668. get indexTypeByteCount() {
  669. return this._indexTypeByteCount;
  670. }
  671. get indexCount() {
  672. return this._indexCount;
  673. }
  674. get canRead() {
  675. return this._canRead;
  676. }
  677. _bindForVAO() {
  678. if (Laya.BufferStateBase._curBindedBufferState) {
  679. var gl = Laya.LayaGL.instance;
  680. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._glBuffer);
  681. }
  682. else {
  683. throw "IndexBuffer3D: must bind current BufferState.";
  684. }
  685. }
  686. bind() {
  687. if (Laya.BufferStateBase._curBindedBufferState) {
  688. throw "IndexBuffer3D: must unbind current BufferState.";
  689. }
  690. else {
  691. if (Laya.Buffer._bindedIndexBuffer !== this._glBuffer) {
  692. var gl = Laya.LayaGL.instance;
  693. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._glBuffer);
  694. Laya.Buffer._bindedIndexBuffer = this._glBuffer;
  695. return true;
  696. }
  697. else {
  698. return false;
  699. }
  700. }
  701. }
  702. setData(data, bufferOffset = 0, dataStartIndex = 0, dataCount = 4294967295) {
  703. var byteCount;
  704. if (this._indexType == IndexBuffer3D.INDEXTYPE_USHORT) {
  705. byteCount = 2;
  706. if (dataStartIndex !== 0 || dataCount !== 4294967295)
  707. data = new Uint16Array(data.buffer, dataStartIndex * byteCount, dataCount);
  708. }
  709. else if (this._indexType == IndexBuffer3D.INDEXTYPE_UBYTE) {
  710. byteCount = 1;
  711. if (dataStartIndex !== 0 || dataCount !== 4294967295)
  712. data = new Uint8Array(data.buffer, dataStartIndex * byteCount, dataCount);
  713. }
  714. var curBufSta = Laya.BufferStateBase._curBindedBufferState;
  715. if (curBufSta) {
  716. if (curBufSta._bindedIndexBuffer === this) {
  717. Laya.LayaGL.instance.bufferSubData(this._bufferType, bufferOffset * byteCount, data);
  718. }
  719. else {
  720. curBufSta.unBind();
  721. this.bind();
  722. Laya.LayaGL.instance.bufferSubData(this._bufferType, bufferOffset * byteCount, data);
  723. curBufSta.bind();
  724. }
  725. }
  726. else {
  727. this.bind();
  728. Laya.LayaGL.instance.bufferSubData(this._bufferType, bufferOffset * byteCount, data);
  729. }
  730. if (this._canRead) {
  731. if (bufferOffset !== 0 || dataStartIndex !== 0 || dataCount !== 4294967295) {
  732. var maxLength = this._buffer.length - bufferOffset;
  733. if (dataCount > maxLength)
  734. dataCount = maxLength;
  735. for (var i = 0; i < dataCount; i++)
  736. this._buffer[bufferOffset + i] = data[i];
  737. }
  738. else {
  739. this._buffer = data;
  740. }
  741. }
  742. }
  743. getData() {
  744. if (this._canRead)
  745. return this._buffer;
  746. else
  747. throw new Error("Can't read data from VertexBuffer with only write flag!");
  748. }
  749. destroy() {
  750. super.destroy();
  751. this._buffer = null;
  752. }
  753. }
  754. IndexBuffer3D.INDEXTYPE_UBYTE = "ubyte";
  755. IndexBuffer3D.INDEXTYPE_USHORT = "ushort";
  756. class VertexBuffer3D extends Laya.Buffer {
  757. constructor(byteLength, bufferUsage, canRead = false) {
  758. super();
  759. this._vertexCount = 0;
  760. this._vertexDeclaration = null;
  761. this._float32Reader = null;
  762. var gl = Laya.LayaGL.instance;
  763. this._vertexCount = -1;
  764. this._bufferUsage = bufferUsage;
  765. this._bufferType = gl.ARRAY_BUFFER;
  766. this._canRead = canRead;
  767. this._byteLength = byteLength;
  768. this.bind();
  769. gl.bufferData(this._bufferType, this._byteLength, this._bufferUsage);
  770. if (canRead) {
  771. this._buffer = new Uint8Array(byteLength);
  772. this._float32Reader = new Float32Array(this._buffer.buffer);
  773. }
  774. }
  775. get vertexDeclaration() {
  776. return this._vertexDeclaration;
  777. }
  778. set vertexDeclaration(value) {
  779. if (this._vertexDeclaration !== value) {
  780. this._vertexDeclaration = value;
  781. this._vertexCount = value ? this._byteLength / value.vertexStride : -1;
  782. }
  783. }
  784. get vertexCount() {
  785. return this._vertexCount;
  786. }
  787. get canRead() {
  788. return this._canRead;
  789. }
  790. bind() {
  791. if (Laya.Buffer._bindedVertexBuffer !== this._glBuffer) {
  792. var gl = Laya.LayaGL.instance;
  793. gl.bindBuffer(gl.ARRAY_BUFFER, this._glBuffer);
  794. Laya.Buffer._bindedVertexBuffer = this._glBuffer;
  795. return true;
  796. }
  797. else {
  798. return false;
  799. }
  800. }
  801. setData(buffer, bufferOffset = 0, dataStartIndex = 0, dataCount = 4294967295) {
  802. this.bind();
  803. var needSubData = dataStartIndex !== 0 || dataCount !== 4294967295;
  804. if (needSubData) {
  805. var subData = new Uint8Array(buffer, dataStartIndex, dataCount);
  806. Laya.LayaGL.instance.bufferSubData(this._bufferType, bufferOffset, subData);
  807. if (this._canRead)
  808. this._buffer.set(subData, bufferOffset);
  809. }
  810. else {
  811. Laya.LayaGL.instance.bufferSubData(this._bufferType, bufferOffset, buffer);
  812. if (this._canRead)
  813. this._buffer.set(new Uint8Array(buffer), bufferOffset);
  814. }
  815. }
  816. getUint8Data() {
  817. if (this._canRead)
  818. return this._buffer;
  819. else
  820. throw new Error("Can't read data from VertexBuffer with only write flag!");
  821. }
  822. getFloat32Data() {
  823. if (this._canRead)
  824. return this._float32Reader;
  825. else
  826. throw new Error("Can't read data from VertexBuffer with only write flag!");
  827. }
  828. markAsUnreadbale() {
  829. this._canRead = false;
  830. this._buffer = null;
  831. this._float32Reader = null;
  832. }
  833. destroy() {
  834. super.destroy();
  835. this._buffer = null;
  836. this._float32Reader = null;
  837. this._vertexDeclaration = null;
  838. }
  839. }
  840. VertexBuffer3D.DATATYPE_FLOAT32ARRAY = 0;
  841. VertexBuffer3D.DATATYPE_UINT8ARRAY = 1;
  842. class VertexElementFormat {
  843. static __init__() {
  844. var gl = Laya.LayaGL.instance;
  845. VertexElementFormat._elementInfos = {
  846. "single": [1, gl.FLOAT, 0],
  847. "vector2": [2, gl.FLOAT, 0],
  848. "vector3": [3, gl.FLOAT, 0],
  849. "vector4": [4, gl.FLOAT, 0],
  850. "color": [4, gl.FLOAT, 0],
  851. "byte4": [4, gl.UNSIGNED_BYTE, 0],
  852. "short2": [2, gl.FLOAT, 0],
  853. "short4": [4, gl.FLOAT, 0],
  854. "normalizedshort2": [2, gl.FLOAT, 0],
  855. "normalizedshort4": [4, gl.FLOAT, 0],
  856. "halfvector2": [2, gl.FLOAT, 0],
  857. "halfvector4": [4, gl.FLOAT, 0]
  858. };
  859. }
  860. static getElementInfos(element) {
  861. var info = VertexElementFormat._elementInfos[element];
  862. if (info)
  863. return info;
  864. else
  865. throw "VertexElementFormat: this vertexElementFormat is not implement.";
  866. }
  867. }
  868. VertexElementFormat.Single = "single";
  869. VertexElementFormat.Vector2 = "vector2";
  870. VertexElementFormat.Vector3 = "vector3";
  871. VertexElementFormat.Vector4 = "vector4";
  872. VertexElementFormat.Color = "color";
  873. VertexElementFormat.Byte4 = "byte4";
  874. VertexElementFormat.Short2 = "short2";
  875. VertexElementFormat.Short4 = "short4";
  876. VertexElementFormat.NormalizedShort2 = "normalizedshort2";
  877. VertexElementFormat.NormalizedShort4 = "normalizedshort4";
  878. VertexElementFormat.HalfVector2 = "halfvector2";
  879. VertexElementFormat.HalfVector4 = "halfvector4";
  880. class Matrix3x3 {
  881. constructor() {
  882. var e = this.elements = new Float32Array(9);
  883. e[0] = 1;
  884. e[1] = 0;
  885. e[2] = 0;
  886. e[3] = 0;
  887. e[4] = 1;
  888. e[5] = 0;
  889. e[6] = 0;
  890. e[7] = 0;
  891. e[8] = 1;
  892. }
  893. static createRotationQuaternion(rotation, out) {
  894. var rotX = rotation.x;
  895. var rotY = rotation.y;
  896. var rotZ = rotation.z;
  897. var rotW = rotation.w;
  898. var xx = rotX * rotX;
  899. var yy = rotY * rotY;
  900. var zz = rotZ * rotZ;
  901. var xy = rotX * rotY;
  902. var zw = rotZ * rotW;
  903. var zx = rotZ * rotX;
  904. var yw = rotY * rotW;
  905. var yz = rotY * rotZ;
  906. var xw = rotX * rotW;
  907. var resultE = out.elements;
  908. resultE[0] = 1.0 - (2.0 * (yy + zz));
  909. resultE[1] = 2.0 * (xy + zw);
  910. resultE[2] = 2.0 * (zx - yw);
  911. resultE[3] = 2.0 * (xy - zw);
  912. resultE[4] = 1.0 - (2.0 * (zz + xx));
  913. resultE[5] = 2.0 * (yz + xw);
  914. resultE[6] = 2.0 * (zx + yw);
  915. resultE[7] = 2.0 * (yz - xw);
  916. resultE[8] = 1.0 - (2.0 * (yy + xx));
  917. }
  918. static createFromTranslation(trans, out) {
  919. var e = out.elements;
  920. out[0] = 1;
  921. out[1] = 0;
  922. out[2] = 0;
  923. out[3] = 0;
  924. out[4] = 1;
  925. out[5] = 0;
  926. out[6] = trans.x;
  927. out[7] = trans.y;
  928. out[8] = 1;
  929. }
  930. static createFromRotation(rad, out) {
  931. var e = out.elements;
  932. var s = Math.sin(rad), c = Math.cos(rad);
  933. e[0] = c;
  934. e[1] = s;
  935. e[2] = 0;
  936. e[3] = -s;
  937. e[4] = c;
  938. e[5] = 0;
  939. e[6] = 0;
  940. e[7] = 0;
  941. e[8] = 1;
  942. }
  943. static createFromScaling(scale, out) {
  944. var e = out.elements;
  945. e[0] = scale.x;
  946. e[1] = 0;
  947. e[2] = 0;
  948. e[3] = 0;
  949. e[4] = scale.y;
  950. e[5] = 0;
  951. e[6] = 0;
  952. e[7] = 0;
  953. e[8] = scale.z;
  954. }
  955. static createFromMatrix4x4(sou, out) {
  956. var souE = sou.elements;
  957. var outE = out.elements;
  958. outE[0] = souE[0];
  959. outE[1] = souE[1];
  960. outE[2] = souE[2];
  961. outE[3] = souE[4];
  962. outE[4] = souE[5];
  963. outE[5] = souE[6];
  964. outE[6] = souE[8];
  965. outE[7] = souE[9];
  966. outE[8] = souE[10];
  967. }
  968. static multiply(left, right, out) {
  969. var l = left.elements;
  970. var r = right.elements;
  971. var e = out.elements;
  972. var l11 = l[0], l12 = l[1], l13 = l[2];
  973. var l21 = l[3], l22 = l[4], l23 = l[5];
  974. var l31 = l[6], l32 = l[7], l33 = l[8];
  975. var r11 = r[0], r12 = r[1], r13 = r[2];
  976. var r21 = r[3], r22 = r[4], r23 = r[5];
  977. var r31 = r[6], r32 = r[7], r33 = r[8];
  978. e[0] = r11 * l11 + r12 * l21 + r13 * l31;
  979. e[1] = r11 * l12 + r12 * l22 + r13 * r32;
  980. e[2] = r11 * l13 + r12 * l23 + r13 * l33;
  981. e[3] = r21 * l11 + r22 * l21 + r23 * l31;
  982. e[4] = r21 * l12 + r22 * l22 + r23 * l32;
  983. e[5] = r21 * l13 + r22 * l23 + r23 * l33;
  984. e[6] = r31 * l11 + r32 * l21 + r33 * l31;
  985. e[7] = r31 * l12 + r32 * l22 + r33 * l32;
  986. e[8] = r31 * l13 + r32 * l23 + r33 * l33;
  987. }
  988. determinant() {
  989. var f = this.elements;
  990. var a00 = f[0], a01 = f[1], a02 = f[2];
  991. var a10 = f[3], a11 = f[4], a12 = f[5];
  992. var a20 = f[6], a21 = f[7], a22 = f[8];
  993. return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
  994. }
  995. translate(trans, out) {
  996. var e = out.elements;
  997. var f = this.elements;
  998. var a00 = f[0], a01 = f[1], a02 = f[2];
  999. var a10 = f[3], a11 = f[4], a12 = f[5];
  1000. var a20 = f[6], a21 = f[7], a22 = f[8];
  1001. var x = trans.x, y = trans.y;
  1002. e[0] = a00;
  1003. e[1] = a01;
  1004. e[2] = a02;
  1005. e[3] = a10;
  1006. e[4] = a11;
  1007. e[5] = a12;
  1008. e[6] = x * a00 + y * a10 + a20;
  1009. e[7] = x * a01 + y * a11 + a21;
  1010. e[8] = x * a02 + y * a12 + a22;
  1011. }
  1012. rotate(rad, out) {
  1013. var e = out.elements;
  1014. var f = this.elements;
  1015. var a00 = f[0], a01 = f[1], a02 = f[2];
  1016. var a10 = f[3], a11 = f[4], a12 = f[5];
  1017. var a20 = f[6], a21 = f[7], a22 = f[8];
  1018. var s = Math.sin(rad);
  1019. var c = Math.cos(rad);
  1020. e[0] = c * a00 + s * a10;
  1021. e[1] = c * a01 + s * a11;
  1022. e[2] = c * a02 + s * a12;
  1023. e[3] = c * a10 - s * a00;
  1024. e[4] = c * a11 - s * a01;
  1025. e[5] = c * a12 - s * a02;
  1026. e[6] = a20;
  1027. e[7] = a21;
  1028. e[8] = a22;
  1029. }
  1030. scale(scale, out) {
  1031. var e = out.elements;
  1032. var f = this.elements;
  1033. var x = scale.x, y = scale.y;
  1034. e[0] = x * f[0];
  1035. e[1] = x * f[1];
  1036. e[2] = x * f[2];
  1037. e[3] = y * f[3];
  1038. e[4] = y * f[4];
  1039. e[5] = y * f[5];
  1040. e[6] = f[6];
  1041. e[7] = f[7];
  1042. e[8] = f[8];
  1043. }
  1044. invert(out) {
  1045. var e = out.elements;
  1046. var f = this.elements;
  1047. var a00 = f[0], a01 = f[1], a02 = f[2];
  1048. var a10 = f[3], a11 = f[4], a12 = f[5];
  1049. var a20 = f[6], a21 = f[7], a22 = f[8];
  1050. var b01 = a22 * a11 - a12 * a21;
  1051. var b11 = -a22 * a10 + a12 * a20;
  1052. var b21 = a21 * a10 - a11 * a20;
  1053. var det = a00 * b01 + a01 * b11 + a02 * b21;
  1054. if (!det) {
  1055. out = null;
  1056. }
  1057. det = 1.0 / det;
  1058. e[0] = b01 * det;
  1059. e[1] = (-a22 * a01 + a02 * a21) * det;
  1060. e[2] = (a12 * a01 - a02 * a11) * det;
  1061. e[3] = b11 * det;
  1062. e[4] = (a22 * a00 - a02 * a20) * det;
  1063. e[5] = (-a12 * a00 + a02 * a10) * det;
  1064. e[6] = b21 * det;
  1065. e[7] = (-a21 * a00 + a01 * a20) * det;
  1066. e[8] = (a11 * a00 - a01 * a10) * det;
  1067. }
  1068. transpose(out) {
  1069. var e = out.elements;
  1070. var f = this.elements;
  1071. if (out === this) {
  1072. var a01 = f[1], a02 = f[2], a12 = f[5];
  1073. e[1] = f[3];
  1074. e[2] = f[6];
  1075. e[3] = a01;
  1076. e[5] = f[7];
  1077. e[6] = a02;
  1078. e[7] = a12;
  1079. }
  1080. else {
  1081. e[0] = f[0];
  1082. e[1] = f[3];
  1083. e[2] = f[6];
  1084. e[3] = f[1];
  1085. e[4] = f[4];
  1086. e[5] = f[7];
  1087. e[6] = f[2];
  1088. e[7] = f[5];
  1089. e[8] = f[8];
  1090. }
  1091. }
  1092. identity() {
  1093. var e = this.elements;
  1094. e[0] = 1;
  1095. e[1] = 0;
  1096. e[2] = 0;
  1097. e[3] = 0;
  1098. e[4] = 1;
  1099. e[5] = 0;
  1100. e[6] = 0;
  1101. e[7] = 0;
  1102. e[8] = 1;
  1103. }
  1104. cloneTo(destObject) {
  1105. var i, s, d;
  1106. s = this.elements;
  1107. d = destObject.elements;
  1108. if (s === d) {
  1109. return;
  1110. }
  1111. for (i = 0; i < 9; ++i) {
  1112. d[i] = s[i];
  1113. }
  1114. }
  1115. clone() {
  1116. var dest = new Matrix3x3();
  1117. this.cloneTo(dest);
  1118. return dest;
  1119. }
  1120. static lookAt(eye, target, up, out) {
  1121. Vector3.subtract(eye, target, Matrix3x3._tempV30);
  1122. Vector3.normalize(Matrix3x3._tempV30, Matrix3x3._tempV30);
  1123. Vector3.cross(up, Matrix3x3._tempV30, Matrix3x3._tempV31);
  1124. Vector3.normalize(Matrix3x3._tempV31, Matrix3x3._tempV31);
  1125. Vector3.cross(Matrix3x3._tempV30, Matrix3x3._tempV31, Matrix3x3._tempV32);
  1126. var v0 = Matrix3x3._tempV30;
  1127. var v1 = Matrix3x3._tempV31;
  1128. var v2 = Matrix3x3._tempV32;
  1129. var me = out.elements;
  1130. me[0] = v1.x;
  1131. me[3] = v1.y;
  1132. me[6] = v1.z;
  1133. me[1] = v2.x;
  1134. me[4] = v2.y;
  1135. me[7] = v2.z;
  1136. me[2] = v0.x;
  1137. me[5] = v0.y;
  1138. me[8] = v0.z;
  1139. }
  1140. }
  1141. Matrix3x3.DEFAULT = new Matrix3x3();
  1142. Matrix3x3._tempV30 = new Vector3();
  1143. Matrix3x3._tempV31 = new Vector3();
  1144. Matrix3x3._tempV32 = new Vector3();
  1145. class Quaternion {
  1146. constructor(x = 0, y = 0, z = 0, w = 1, nativeElements = null) {
  1147. this.x = x;
  1148. this.y = y;
  1149. this.z = z;
  1150. this.w = w;
  1151. }
  1152. static createFromYawPitchRoll(yaw, pitch, roll, out) {
  1153. var halfRoll = roll * 0.5;
  1154. var halfPitch = pitch * 0.5;
  1155. var halfYaw = yaw * 0.5;
  1156. var sinRoll = Math.sin(halfRoll);
  1157. var cosRoll = Math.cos(halfRoll);
  1158. var sinPitch = Math.sin(halfPitch);
  1159. var cosPitch = Math.cos(halfPitch);
  1160. var sinYaw = Math.sin(halfYaw);
  1161. var cosYaw = Math.cos(halfYaw);
  1162. out.x = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);
  1163. out.y = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);
  1164. out.z = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);
  1165. out.w = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);
  1166. }
  1167. static multiply(left, right, out) {
  1168. var lx = left.x;
  1169. var ly = left.y;
  1170. var lz = left.z;
  1171. var lw = left.w;
  1172. var rx = right.x;
  1173. var ry = right.y;
  1174. var rz = right.z;
  1175. var rw = right.w;
  1176. var a = (ly * rz - lz * ry);
  1177. var b = (lz * rx - lx * rz);
  1178. var c = (lx * ry - ly * rx);
  1179. var d = (lx * rx + ly * ry + lz * rz);
  1180. out.x = (lx * rw + rx * lw) + a;
  1181. out.y = (ly * rw + ry * lw) + b;
  1182. out.z = (lz * rw + rz * lw) + c;
  1183. out.w = lw * rw - d;
  1184. }
  1185. static arcTanAngle(x, y) {
  1186. if (x == 0) {
  1187. if (y == 1)
  1188. return Math.PI / 2;
  1189. return -Math.PI / 2;
  1190. }
  1191. if (x > 0)
  1192. return Math.atan(y / x);
  1193. if (x < 0) {
  1194. if (y > 0)
  1195. return Math.atan(y / x) + Math.PI;
  1196. return Math.atan(y / x) - Math.PI;
  1197. }
  1198. return 0;
  1199. }
  1200. static angleTo(from, location, angle) {
  1201. Vector3.subtract(location, from, Quaternion.TEMPVector30);
  1202. Vector3.normalize(Quaternion.TEMPVector30, Quaternion.TEMPVector30);
  1203. angle.x = Math.asin(Quaternion.TEMPVector30.y);
  1204. angle.y = Quaternion.arcTanAngle(-Quaternion.TEMPVector30.z, -Quaternion.TEMPVector30.x);
  1205. }
  1206. static createFromAxisAngle(axis, rad, out) {
  1207. rad = rad * 0.5;
  1208. var s = Math.sin(rad);
  1209. out.x = s * axis.x;
  1210. out.y = s * axis.y;
  1211. out.z = s * axis.z;
  1212. out.w = Math.cos(rad);
  1213. }
  1214. static createFromMatrix4x4(mat, out) {
  1215. var me = mat.elements;
  1216. var sqrt;
  1217. var half;
  1218. var scale = me[0] + me[5] + me[10];
  1219. if (scale > 0.0) {
  1220. sqrt = Math.sqrt(scale + 1.0);
  1221. out.w = sqrt * 0.5;
  1222. sqrt = 0.5 / sqrt;
  1223. out.x = (me[6] - me[9]) * sqrt;
  1224. out.y = (me[8] - me[2]) * sqrt;
  1225. out.z = (me[1] - me[4]) * sqrt;
  1226. }
  1227. else if ((me[0] >= me[5]) && (me[0] >= me[10])) {
  1228. sqrt = Math.sqrt(1.0 + me[0] - me[5] - me[10]);
  1229. half = 0.5 / sqrt;
  1230. out.x = 0.5 * sqrt;
  1231. out.y = (me[1] + me[4]) * half;
  1232. out.z = (me[2] + me[8]) * half;
  1233. out.w = (me[6] - me[9]) * half;
  1234. }
  1235. else if (me[5] > me[10]) {
  1236. sqrt = Math.sqrt(1.0 + me[5] - me[0] - me[10]);
  1237. half = 0.5 / sqrt;
  1238. out.x = (me[4] + me[1]) * half;
  1239. out.y = 0.5 * sqrt;
  1240. out.z = (me[9] + me[6]) * half;
  1241. out.w = (me[8] - me[2]) * half;
  1242. }
  1243. else {
  1244. sqrt = Math.sqrt(1.0 + me[10] - me[0] - me[5]);
  1245. half = 0.5 / sqrt;
  1246. out.x = (me[8] + me[2]) * half;
  1247. out.y = (me[9] + me[6]) * half;
  1248. out.z = 0.5 * sqrt;
  1249. out.w = (me[1] - me[4]) * half;
  1250. }
  1251. }
  1252. static slerp(left, right, t, out) {
  1253. var ax = left.x, ay = left.y, az = left.z, aw = left.w, bx = right.x, by = right.y, bz = right.z, bw = right.w;
  1254. var omega, cosom, sinom, scale0, scale1;
  1255. cosom = ax * bx + ay * by + az * bz + aw * bw;
  1256. if (cosom < 0.0) {
  1257. cosom = -cosom;
  1258. bx = -bx;
  1259. by = -by;
  1260. bz = -bz;
  1261. bw = -bw;
  1262. }
  1263. if ((1.0 - cosom) > 0.000001) {
  1264. omega = Math.acos(cosom);
  1265. sinom = Math.sin(omega);
  1266. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  1267. scale1 = Math.sin(t * omega) / sinom;
  1268. }
  1269. else {
  1270. scale0 = 1.0 - t;
  1271. scale1 = t;
  1272. }
  1273. out.x = scale0 * ax + scale1 * bx;
  1274. out.y = scale0 * ay + scale1 * by;
  1275. out.z = scale0 * az + scale1 * bz;
  1276. out.w = scale0 * aw + scale1 * bw;
  1277. return out;
  1278. }
  1279. static lerp(left, right, amount, out) {
  1280. var inverse = 1.0 - amount;
  1281. if (Quaternion.dot(left, right) >= 0) {
  1282. out.x = (inverse * left.x) + (amount * right.x);
  1283. out.y = (inverse * left.y) + (amount * right.y);
  1284. out.z = (inverse * left.z) + (amount * right.z);
  1285. out.w = (inverse * left.w) + (amount * right.w);
  1286. }
  1287. else {
  1288. out.x = (inverse * left.x) - (amount * right.x);
  1289. out.y = (inverse * left.y) - (amount * right.y);
  1290. out.z = (inverse * left.z) - (amount * right.z);
  1291. out.w = (inverse * left.w) - (amount * right.w);
  1292. }
  1293. out.normalize(out);
  1294. }
  1295. static add(left, right, out) {
  1296. out.x = left.x + right.x;
  1297. out.y = left.y + right.y;
  1298. out.z = left.z + right.z;
  1299. out.w = left.w + right.w;
  1300. }
  1301. static dot(left, right) {
  1302. return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
  1303. }
  1304. scaling(scaling, out) {
  1305. out.x = this.x * scaling;
  1306. out.y = this.y * scaling;
  1307. out.z = this.z * scaling;
  1308. out.w = this.w * scaling;
  1309. }
  1310. normalize(out) {
  1311. var len = this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1312. if (len > 0) {
  1313. len = 1 / Math.sqrt(len);
  1314. out.x = this.x * len;
  1315. out.y = this.y * len;
  1316. out.z = this.z * len;
  1317. out.w = this.w * len;
  1318. }
  1319. }
  1320. length() {
  1321. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  1322. }
  1323. rotateX(rad, out) {
  1324. rad *= 0.5;
  1325. var bx = Math.sin(rad), bw = Math.cos(rad);
  1326. out.x = this.x * bw + this.w * bx;
  1327. out.y = this.y * bw + this.z * bx;
  1328. out.z = this.z * bw - this.y * bx;
  1329. out.w = this.w * bw - this.x * bx;
  1330. }
  1331. rotateY(rad, out) {
  1332. rad *= 0.5;
  1333. var by = Math.sin(rad), bw = Math.cos(rad);
  1334. out.x = this.x * bw - this.z * by;
  1335. out.y = this.y * bw + this.w * by;
  1336. out.z = this.z * bw + this.x * by;
  1337. out.w = this.w * bw - this.y * by;
  1338. }
  1339. rotateZ(rad, out) {
  1340. rad *= 0.5;
  1341. var bz = Math.sin(rad), bw = Math.cos(rad);
  1342. out.x = this.x * bw + this.y * bz;
  1343. out.y = this.y * bw - this.x * bz;
  1344. out.z = this.z * bw + this.w * bz;
  1345. out.w = this.w * bw - this.z * bz;
  1346. }
  1347. getYawPitchRoll(out) {
  1348. Vector3.transformQuat(Vector3._ForwardRH, this, Quaternion.TEMPVector31);
  1349. Vector3.transformQuat(Vector3._Up, this, Quaternion.TEMPVector32);
  1350. var upe = Quaternion.TEMPVector32;
  1351. Quaternion.angleTo(Vector3._ZERO, Quaternion.TEMPVector31, Quaternion.TEMPVector33);
  1352. var angle = Quaternion.TEMPVector33;
  1353. if (angle.x == Math.PI / 2) {
  1354. angle.y = Quaternion.arcTanAngle(upe.z, upe.x);
  1355. angle.z = 0;
  1356. }
  1357. else if (angle.x == -Math.PI / 2) {
  1358. angle.y = Quaternion.arcTanAngle(-upe.z, -upe.x);
  1359. angle.z = 0;
  1360. }
  1361. else {
  1362. ILaya3D.Matrix4x4.createRotationY(-angle.y, ILaya3D.Matrix4x4.TEMPMatrix0);
  1363. ILaya3D.Matrix4x4.createRotationX(-angle.x, ILaya3D.Matrix4x4.TEMPMatrix1);
  1364. Vector3.transformCoordinate(Quaternion.TEMPVector32, ILaya3D.Matrix4x4.TEMPMatrix0, Quaternion.TEMPVector32);
  1365. Vector3.transformCoordinate(Quaternion.TEMPVector32, ILaya3D.Matrix4x4.TEMPMatrix1, Quaternion.TEMPVector32);
  1366. angle.z = Quaternion.arcTanAngle(upe.y, -upe.x);
  1367. }
  1368. if (angle.y <= -Math.PI)
  1369. angle.y = Math.PI;
  1370. if (angle.z <= -Math.PI)
  1371. angle.z = Math.PI;
  1372. if (angle.y >= Math.PI && angle.z >= Math.PI) {
  1373. angle.y = 0;
  1374. angle.z = 0;
  1375. angle.x = Math.PI - angle.x;
  1376. }
  1377. var oe = out;
  1378. oe.x = angle.y;
  1379. oe.y = angle.x;
  1380. oe.z = angle.z;
  1381. }
  1382. invert(out) {
  1383. var a0 = this.x, a1 = this.y, a2 = this.z, a3 = this.w;
  1384. var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
  1385. var invDot = dot ? 1.0 / dot : 0;
  1386. out.x = -a0 * invDot;
  1387. out.y = -a1 * invDot;
  1388. out.z = -a2 * invDot;
  1389. out.w = a3 * invDot;
  1390. }
  1391. identity() {
  1392. this.x = 0;
  1393. this.y = 0;
  1394. this.z = 0;
  1395. this.w = 1;
  1396. }
  1397. fromArray(array, offset = 0) {
  1398. this.x = array[offset + 0];
  1399. this.y = array[offset + 1];
  1400. this.z = array[offset + 2];
  1401. this.w = array[offset + 3];
  1402. }
  1403. cloneTo(destObject) {
  1404. if (this === destObject) {
  1405. return;
  1406. }
  1407. destObject.x = this.x;
  1408. destObject.y = this.y;
  1409. destObject.z = this.z;
  1410. destObject.w = this.w;
  1411. }
  1412. clone() {
  1413. var dest = new Quaternion();
  1414. this.cloneTo(dest);
  1415. return dest;
  1416. }
  1417. equals(b) {
  1418. return MathUtils3D.nearEqual(this.x, b.x) && MathUtils3D.nearEqual(this.y, b.y) && MathUtils3D.nearEqual(this.z, b.z) && MathUtils3D.nearEqual(this.w, b.w);
  1419. }
  1420. static rotationLookAt(forward, up, out) {
  1421. Quaternion.lookAt(Vector3._ZERO, forward, up, out);
  1422. }
  1423. static lookAt(eye, target, up, out) {
  1424. Matrix3x3.lookAt(eye, target, up, Quaternion._tempMatrix3x3);
  1425. Quaternion.rotationMatrix(Quaternion._tempMatrix3x3, out);
  1426. }
  1427. lengthSquared() {
  1428. return (this.x * this.x) + (this.y * this.y) + (this.z * this.z) + (this.w * this.w);
  1429. }
  1430. static invert(value, out) {
  1431. var lengthSq = value.lengthSquared();
  1432. if (!MathUtils3D.isZero(lengthSq)) {
  1433. lengthSq = 1.0 / lengthSq;
  1434. out.x = -value.x * lengthSq;
  1435. out.y = -value.y * lengthSq;
  1436. out.z = -value.z * lengthSq;
  1437. out.w = value.w * lengthSq;
  1438. }
  1439. }
  1440. static rotationMatrix(matrix3x3, out) {
  1441. var me = matrix3x3.elements;
  1442. var m11 = me[0];
  1443. var m12 = me[1];
  1444. var m13 = me[2];
  1445. var m21 = me[3];
  1446. var m22 = me[4];
  1447. var m23 = me[5];
  1448. var m31 = me[6];
  1449. var m32 = me[7];
  1450. var m33 = me[8];
  1451. var sqrt, half;
  1452. var scale = m11 + m22 + m33;
  1453. if (scale > 0) {
  1454. sqrt = Math.sqrt(scale + 1);
  1455. out.w = sqrt * 0.5;
  1456. sqrt = 0.5 / sqrt;
  1457. out.x = (m23 - m32) * sqrt;
  1458. out.y = (m31 - m13) * sqrt;
  1459. out.z = (m12 - m21) * sqrt;
  1460. }
  1461. else if ((m11 >= m22) && (m11 >= m33)) {
  1462. sqrt = Math.sqrt(1 + m11 - m22 - m33);
  1463. half = 0.5 / sqrt;
  1464. out.x = 0.5 * sqrt;
  1465. out.y = (m12 + m21) * half;
  1466. out.z = (m13 + m31) * half;
  1467. out.w = (m23 - m32) * half;
  1468. }
  1469. else if (m22 > m33) {
  1470. sqrt = Math.sqrt(1 + m22 - m11 - m33);
  1471. half = 0.5 / sqrt;
  1472. out.x = (m21 + m12) * half;
  1473. out.y = 0.5 * sqrt;
  1474. out.z = (m32 + m23) * half;
  1475. out.w = (m31 - m13) * half;
  1476. }
  1477. else {
  1478. sqrt = Math.sqrt(1 + m33 - m11 - m22);
  1479. half = 0.5 / sqrt;
  1480. out.x = (m31 + m13) * half;
  1481. out.y = (m32 + m23) * half;
  1482. out.z = 0.5 * sqrt;
  1483. out.w = (m12 - m21) * half;
  1484. }
  1485. }
  1486. forNativeElement(nativeElements = null) {
  1487. if (nativeElements) {
  1488. this.elements = nativeElements;
  1489. this.elements[0] = this.x;
  1490. this.elements[1] = this.y;
  1491. this.elements[2] = this.z;
  1492. this.elements[3] = this.w;
  1493. }
  1494. else {
  1495. this.elements = new Float32Array([this.x, this.y, this.z, this.w]);
  1496. }
  1497. Vector2.rewriteNumProperty(this, "x", 0);
  1498. Vector2.rewriteNumProperty(this, "y", 1);
  1499. Vector2.rewriteNumProperty(this, "z", 2);
  1500. Vector2.rewriteNumProperty(this, "w", 3);
  1501. }
  1502. }
  1503. Quaternion.TEMPVector30 = new Vector3();
  1504. Quaternion.TEMPVector31 = new Vector3();
  1505. Quaternion.TEMPVector32 = new Vector3();
  1506. Quaternion.TEMPVector33 = new Vector3();
  1507. Quaternion._tempMatrix3x3 = new Matrix3x3();
  1508. Quaternion.DEFAULT = new Quaternion();
  1509. Quaternion.NAN = new Quaternion(NaN, NaN, NaN, NaN);
  1510. class Matrix4x4 {
  1511. constructor(m11 = 1, m12 = 0, m13 = 0, m14 = 0, m21 = 0, m22 = 1, m23 = 0, m24 = 0, m31 = 0, m32 = 0, m33 = 1, m34 = 0, m41 = 0, m42 = 0, m43 = 0, m44 = 1, elements = null) {
  1512. var e = elements ? this.elements = elements : this.elements = new Float32Array(16);
  1513. e[0] = m11;
  1514. e[1] = m12;
  1515. e[2] = m13;
  1516. e[3] = m14;
  1517. e[4] = m21;
  1518. e[5] = m22;
  1519. e[6] = m23;
  1520. e[7] = m24;
  1521. e[8] = m31;
  1522. e[9] = m32;
  1523. e[10] = m33;
  1524. e[11] = m34;
  1525. e[12] = m41;
  1526. e[13] = m42;
  1527. e[14] = m43;
  1528. e[15] = m44;
  1529. }
  1530. static createRotationX(rad, out) {
  1531. var oe = out.elements;
  1532. var s = Math.sin(rad), c = Math.cos(rad);
  1533. oe[1] = oe[2] = oe[3] = oe[4] = oe[7] = oe[8] = oe[11] = oe[12] = oe[13] = oe[14] = 0;
  1534. oe[0] = oe[15] = 1;
  1535. oe[5] = oe[10] = c;
  1536. oe[6] = s;
  1537. oe[9] = -s;
  1538. }
  1539. static createRotationY(rad, out) {
  1540. var oe = out.elements;
  1541. var s = Math.sin(rad), c = Math.cos(rad);
  1542. oe[1] = oe[3] = oe[4] = oe[6] = oe[7] = oe[9] = oe[11] = oe[12] = oe[13] = oe[14] = 0;
  1543. oe[5] = oe[15] = 1;
  1544. oe[0] = oe[10] = c;
  1545. oe[2] = -s;
  1546. oe[8] = s;
  1547. }
  1548. static createRotationZ(rad, out) {
  1549. var oe = out.elements;
  1550. var s = Math.sin(rad), c = Math.cos(rad);
  1551. oe[2] = oe[3] = oe[6] = oe[7] = oe[8] = oe[9] = oe[11] = oe[12] = oe[13] = oe[14] = 0;
  1552. oe[10] = oe[15] = 1;
  1553. oe[0] = oe[5] = c;
  1554. oe[1] = s;
  1555. oe[4] = -s;
  1556. }
  1557. static createRotationYawPitchRoll(yaw, pitch, roll, result) {
  1558. Quaternion.createFromYawPitchRoll(yaw, pitch, roll, Matrix4x4._tempQuaternion);
  1559. Matrix4x4.createRotationQuaternion(Matrix4x4._tempQuaternion, result);
  1560. }
  1561. static createRotationAxis(axis, angle, result) {
  1562. var x = axis.x;
  1563. var y = axis.y;
  1564. var z = axis.z;
  1565. var cos = Math.cos(angle);
  1566. var sin = Math.sin(angle);
  1567. var xx = x * x;
  1568. var yy = y * y;
  1569. var zz = z * z;
  1570. var xy = x * y;
  1571. var xz = x * z;
  1572. var yz = y * z;
  1573. var resultE = result.elements;
  1574. resultE[3] = resultE[7] = resultE[11] = resultE[12] = resultE[13] = resultE[14] = 0;
  1575. resultE[15] = 1.0;
  1576. resultE[0] = xx + (cos * (1.0 - xx));
  1577. resultE[1] = (xy - (cos * xy)) + (sin * z);
  1578. resultE[2] = (xz - (cos * xz)) - (sin * y);
  1579. resultE[4] = (xy - (cos * xy)) - (sin * z);
  1580. resultE[5] = yy + (cos * (1.0 - yy));
  1581. resultE[6] = (yz - (cos * yz)) + (sin * x);
  1582. resultE[8] = (xz - (cos * xz)) + (sin * y);
  1583. resultE[9] = (yz - (cos * yz)) - (sin * x);
  1584. resultE[10] = zz + (cos * (1.0 - zz));
  1585. }
  1586. setRotation(rotation) {
  1587. var rotationX = rotation.x;
  1588. var rotationY = rotation.y;
  1589. var rotationZ = rotation.z;
  1590. var rotationW = rotation.w;
  1591. var xx = rotationX * rotationX;
  1592. var yy = rotationY * rotationY;
  1593. var zz = rotationZ * rotationZ;
  1594. var xy = rotationX * rotationY;
  1595. var zw = rotationZ * rotationW;
  1596. var zx = rotationZ * rotationX;
  1597. var yw = rotationY * rotationW;
  1598. var yz = rotationY * rotationZ;
  1599. var xw = rotationX * rotationW;
  1600. var e = this.elements;
  1601. e[0] = 1.0 - (2.0 * (yy + zz));
  1602. e[1] = 2.0 * (xy + zw);
  1603. e[2] = 2.0 * (zx - yw);
  1604. e[4] = 2.0 * (xy - zw);
  1605. e[5] = 1.0 - (2.0 * (zz + xx));
  1606. e[6] = 2.0 * (yz + xw);
  1607. e[8] = 2.0 * (zx + yw);
  1608. e[9] = 2.0 * (yz - xw);
  1609. e[10] = 1.0 - (2.0 * (yy + xx));
  1610. }
  1611. setPosition(position) {
  1612. var e = this.elements;
  1613. e[12] = position.x;
  1614. e[13] = position.y;
  1615. e[14] = position.z;
  1616. }
  1617. static createRotationQuaternion(rotation, result) {
  1618. var resultE = result.elements;
  1619. var rotationX = rotation.x;
  1620. var rotationY = rotation.y;
  1621. var rotationZ = rotation.z;
  1622. var rotationW = rotation.w;
  1623. var xx = rotationX * rotationX;
  1624. var yy = rotationY * rotationY;
  1625. var zz = rotationZ * rotationZ;
  1626. var xy = rotationX * rotationY;
  1627. var zw = rotationZ * rotationW;
  1628. var zx = rotationZ * rotationX;
  1629. var yw = rotationY * rotationW;
  1630. var yz = rotationY * rotationZ;
  1631. var xw = rotationX * rotationW;
  1632. resultE[3] = resultE[7] = resultE[11] = resultE[12] = resultE[13] = resultE[14] = 0;
  1633. resultE[15] = 1.0;
  1634. resultE[0] = 1.0 - (2.0 * (yy + zz));
  1635. resultE[1] = 2.0 * (xy + zw);
  1636. resultE[2] = 2.0 * (zx - yw);
  1637. resultE[4] = 2.0 * (xy - zw);
  1638. resultE[5] = 1.0 - (2.0 * (zz + xx));
  1639. resultE[6] = 2.0 * (yz + xw);
  1640. resultE[8] = 2.0 * (zx + yw);
  1641. resultE[9] = 2.0 * (yz - xw);
  1642. resultE[10] = 1.0 - (2.0 * (yy + xx));
  1643. }
  1644. static createTranslate(trans, out) {
  1645. var oe = out.elements;
  1646. oe[4] = oe[8] = oe[1] = oe[9] = oe[2] = oe[6] = oe[3] = oe[7] = oe[11] = 0;
  1647. oe[0] = oe[5] = oe[10] = oe[15] = 1;
  1648. oe[12] = trans.x;
  1649. oe[13] = trans.y;
  1650. oe[14] = trans.z;
  1651. }
  1652. static createScaling(scale, out) {
  1653. var oe = out.elements;
  1654. oe[0] = scale.x;
  1655. oe[5] = scale.y;
  1656. oe[10] = scale.z;
  1657. oe[1] = oe[4] = oe[8] = oe[12] = oe[9] = oe[13] = oe[2] = oe[6] = oe[14] = oe[3] = oe[7] = oe[11] = 0;
  1658. oe[15] = 1;
  1659. }
  1660. static multiply(left, right, out) {
  1661. var l = right.elements;
  1662. var r = left.elements;
  1663. var e = out.elements;
  1664. var l11 = l[0], l12 = l[1], l13 = l[2], l14 = l[3];
  1665. var l21 = l[4], l22 = l[5], l23 = l[6], l24 = l[7];
  1666. var l31 = l[8], l32 = l[9], l33 = l[10], l34 = l[11];
  1667. var l41 = l[12], l42 = l[13], l43 = l[14], l44 = l[15];
  1668. var r11 = r[0], r12 = r[1], r13 = r[2], r14 = r[3];
  1669. var r21 = r[4], r22 = r[5], r23 = r[6], r24 = r[7];
  1670. var r31 = r[8], r32 = r[9], r33 = r[10], r34 = r[11];
  1671. var r41 = r[12], r42 = r[13], r43 = r[14], r44 = r[15];
  1672. e[0] = (l11 * r11) + (l12 * r21) + (l13 * r31) + (l14 * r41);
  1673. e[1] = (l11 * r12) + (l12 * r22) + (l13 * r32) + (l14 * r42);
  1674. e[2] = (l11 * r13) + (l12 * r23) + (l13 * r33) + (l14 * r43);
  1675. e[3] = (l11 * r14) + (l12 * r24) + (l13 * r34) + (l14 * r44);
  1676. e[4] = (l21 * r11) + (l22 * r21) + (l23 * r31) + (l24 * r41);
  1677. e[5] = (l21 * r12) + (l22 * r22) + (l23 * r32) + (l24 * r42);
  1678. e[6] = (l21 * r13) + (l22 * r23) + (l23 * r33) + (l24 * r43);
  1679. e[7] = (l21 * r14) + (l22 * r24) + (l23 * r34) + (l24 * r44);
  1680. e[8] = (l31 * r11) + (l32 * r21) + (l33 * r31) + (l34 * r41);
  1681. e[9] = (l31 * r12) + (l32 * r22) + (l33 * r32) + (l34 * r42);
  1682. e[10] = (l31 * r13) + (l32 * r23) + (l33 * r33) + (l34 * r43);
  1683. e[11] = (l31 * r14) + (l32 * r24) + (l33 * r34) + (l34 * r44);
  1684. e[12] = (l41 * r11) + (l42 * r21) + (l43 * r31) + (l44 * r41);
  1685. e[13] = (l41 * r12) + (l42 * r22) + (l43 * r32) + (l44 * r42);
  1686. e[14] = (l41 * r13) + (l42 * r23) + (l43 * r33) + (l44 * r43);
  1687. e[15] = (l41 * r14) + (l42 * r24) + (l43 * r34) + (l44 * r44);
  1688. }
  1689. static multiplyForNative(left, right, out) {
  1690. Laya.LayaGL.instance.matrix4x4Multiply(left.elements, right.elements, out.elements);
  1691. }
  1692. static createFromQuaternion(rotation, out) {
  1693. var e = out.elements;
  1694. var x = rotation.x, y = rotation.y, z = rotation.z, w = rotation.w;
  1695. var x2 = x + x;
  1696. var y2 = y + y;
  1697. var z2 = z + z;
  1698. var xx = x * x2;
  1699. var yx = y * x2;
  1700. var yy = y * y2;
  1701. var zx = z * x2;
  1702. var zy = z * y2;
  1703. var zz = z * z2;
  1704. var wx = w * x2;
  1705. var wy = w * y2;
  1706. var wz = w * z2;
  1707. e[0] = 1 - yy - zz;
  1708. e[1] = yx + wz;
  1709. e[2] = zx - wy;
  1710. e[3] = 0;
  1711. e[4] = yx - wz;
  1712. e[5] = 1 - xx - zz;
  1713. e[6] = zy + wx;
  1714. e[7] = 0;
  1715. e[8] = zx + wy;
  1716. e[9] = zy - wx;
  1717. e[10] = 1 - xx - yy;
  1718. e[11] = 0;
  1719. e[12] = 0;
  1720. e[13] = 0;
  1721. e[14] = 0;
  1722. e[15] = 1;
  1723. }
  1724. static createAffineTransformation(trans, rot, scale, out) {
  1725. var oe = out.elements;
  1726. var x = rot.x, y = rot.y, z = rot.z, w = rot.w, x2 = x + x, y2 = y + y, z2 = z + z;
  1727. var xx = x * x2, xy = x * y2, xz = x * z2, yy = y * y2, yz = y * z2, zz = z * z2;
  1728. var wx = w * x2, wy = w * y2, wz = w * z2, sx = scale.x, sy = scale.y, sz = scale.z;
  1729. oe[0] = (1 - (yy + zz)) * sx;
  1730. oe[1] = (xy + wz) * sx;
  1731. oe[2] = (xz - wy) * sx;
  1732. oe[3] = 0;
  1733. oe[4] = (xy - wz) * sy;
  1734. oe[5] = (1 - (xx + zz)) * sy;
  1735. oe[6] = (yz + wx) * sy;
  1736. oe[7] = 0;
  1737. oe[8] = (xz + wy) * sz;
  1738. oe[9] = (yz - wx) * sz;
  1739. oe[10] = (1 - (xx + yy)) * sz;
  1740. oe[11] = 0;
  1741. oe[12] = trans.x;
  1742. oe[13] = trans.y;
  1743. oe[14] = trans.z;
  1744. oe[15] = 1;
  1745. }
  1746. static createLookAt(eye, target, up, out) {
  1747. var oE = out.elements;
  1748. var xaxis = Matrix4x4._tempVector0;
  1749. var yaxis = Matrix4x4._tempVector1;
  1750. var zaxis = Matrix4x4._tempVector2;
  1751. Vector3.subtract(eye, target, zaxis);
  1752. Vector3.normalize(zaxis, zaxis);
  1753. Vector3.cross(up, zaxis, xaxis);
  1754. Vector3.normalize(xaxis, xaxis);
  1755. Vector3.cross(zaxis, xaxis, yaxis);
  1756. out.identity();
  1757. oE[0] = xaxis.x;
  1758. oE[4] = xaxis.y;
  1759. oE[8] = xaxis.z;
  1760. oE[1] = yaxis.x;
  1761. oE[5] = yaxis.y;
  1762. oE[9] = yaxis.z;
  1763. oE[2] = zaxis.x;
  1764. oE[6] = zaxis.y;
  1765. oE[10] = zaxis.z;
  1766. oE[12] = -Vector3.dot(xaxis, eye);
  1767. oE[13] = -Vector3.dot(yaxis, eye);
  1768. oE[14] = -Vector3.dot(zaxis, eye);
  1769. }
  1770. static createPerspective(fov, aspect, znear, zfar, out) {
  1771. var yScale = 1.0 / Math.tan(fov * 0.5);
  1772. var xScale = yScale / aspect;
  1773. var halfWidth = znear / xScale;
  1774. var halfHeight = znear / yScale;
  1775. Matrix4x4.createPerspectiveOffCenter(-halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out);
  1776. }
  1777. static createPerspectiveOffCenter(left, right, bottom, top, znear, zfar, out) {
  1778. var oe = out.elements;
  1779. var zRange = zfar / (zfar - znear);
  1780. oe[1] = oe[2] = oe[3] = oe[4] = oe[6] = oe[7] = oe[12] = oe[13] = oe[15] = 0;
  1781. oe[0] = 2.0 * znear / (right - left);
  1782. oe[5] = 2.0 * znear / (top - bottom);
  1783. oe[8] = (left + right) / (right - left);
  1784. oe[9] = (top + bottom) / (top - bottom);
  1785. oe[10] = -zRange;
  1786. oe[11] = -1.0;
  1787. oe[14] = -znear * zRange;
  1788. }
  1789. static createOrthoOffCenter(left, right, bottom, top, znear, zfar, out) {
  1790. var oe = out.elements;
  1791. var zRange = 1.0 / (zfar - znear);
  1792. oe[1] = oe[2] = oe[3] = oe[4] = oe[6] = oe[8] = oe[7] = oe[9] = oe[11] = 0;
  1793. oe[15] = 1;
  1794. oe[0] = 2.0 / (right - left);
  1795. oe[5] = 2.0 / (top - bottom);
  1796. oe[10] = -zRange;
  1797. oe[12] = (left + right) / (left - right);
  1798. oe[13] = (top + bottom) / (bottom - top);
  1799. oe[14] = -znear * zRange;
  1800. }
  1801. getElementByRowColumn(row, column) {
  1802. if (row < 0 || row > 3)
  1803. throw new Error("row Rows and columns for matrices run from 0 to 3, inclusive.");
  1804. if (column < 0 || column > 3)
  1805. throw new Error("column Rows and columns for matrices run from 0 to 3, inclusive.");
  1806. return this.elements[(row * 4) + column];
  1807. }
  1808. setElementByRowColumn(row, column, value) {
  1809. if (row < 0 || row > 3)
  1810. throw new Error("row Rows and columns for matrices run from 0 to 3, inclusive.");
  1811. if (column < 0 || column > 3)
  1812. throw new Error("column Rows and columns for matrices run from 0 to 3, inclusive.");
  1813. this.elements[(row * 4) + column] = value;
  1814. }
  1815. equalsOtherMatrix(other) {
  1816. var e = this.elements;
  1817. var oe = other.elements;
  1818. return (MathUtils3D.nearEqual(e[0], oe[0]) && MathUtils3D.nearEqual(e[1], oe[1]) && MathUtils3D.nearEqual(e[2], oe[2]) && MathUtils3D.nearEqual(e[3], oe[3]) && MathUtils3D.nearEqual(e[4], oe[4]) && MathUtils3D.nearEqual(e[5], oe[5]) && MathUtils3D.nearEqual(e[6], oe[6]) && MathUtils3D.nearEqual(e[7], oe[7]) && MathUtils3D.nearEqual(e[8], oe[8]) && MathUtils3D.nearEqual(e[9], oe[9]) && MathUtils3D.nearEqual(e[10], oe[10]) && MathUtils3D.nearEqual(e[11], oe[11]) && MathUtils3D.nearEqual(e[12], oe[12]) && MathUtils3D.nearEqual(e[13], oe[13]) && MathUtils3D.nearEqual(e[14], oe[14]) && MathUtils3D.nearEqual(e[15], oe[15]));
  1819. }
  1820. decomposeTransRotScale(translation, rotation, scale) {
  1821. var rotationMatrix = Matrix4x4._tempMatrix4x4;
  1822. if (this.decomposeTransRotMatScale(translation, rotationMatrix, scale)) {
  1823. Quaternion.createFromMatrix4x4(rotationMatrix, rotation);
  1824. return true;
  1825. }
  1826. else {
  1827. rotation.identity();
  1828. return false;
  1829. }
  1830. }
  1831. decomposeTransRotMatScale(translation, rotationMatrix, scale) {
  1832. var e = this.elements;
  1833. var te = translation;
  1834. var re = rotationMatrix.elements;
  1835. var se = scale;
  1836. te.x = e[12];
  1837. te.y = e[13];
  1838. te.z = e[14];
  1839. var m11 = e[0], m12 = e[1], m13 = e[2];
  1840. var m21 = e[4], m22 = e[5], m23 = e[6];
  1841. var m31 = e[8], m32 = e[9], m33 = e[10];
  1842. var sX = se.x = Math.sqrt((m11 * m11) + (m12 * m12) + (m13 * m13));
  1843. var sY = se.y = Math.sqrt((m21 * m21) + (m22 * m22) + (m23 * m23));
  1844. var sZ = se.z = Math.sqrt((m31 * m31) + (m32 * m32) + (m33 * m33));
  1845. if (MathUtils3D.isZero(sX) || MathUtils3D.isZero(sY) || MathUtils3D.isZero(sZ)) {
  1846. re[1] = re[2] = re[3] = re[4] = re[6] = re[7] = re[8] = re[9] = re[11] = re[12] = re[13] = re[14] = 0;
  1847. re[0] = re[5] = re[10] = re[15] = 1;
  1848. return false;
  1849. }
  1850. var at = Matrix4x4._tempVector0;
  1851. at.x = m31 / sZ;
  1852. at.y = m32 / sZ;
  1853. at.z = m33 / sZ;
  1854. var tempRight = Matrix4x4._tempVector1;
  1855. tempRight.x = m11 / sX;
  1856. tempRight.y = m12 / sX;
  1857. tempRight.z = m13 / sX;
  1858. var up = Matrix4x4._tempVector2;
  1859. Vector3.cross(at, tempRight, up);
  1860. var right = Matrix4x4._tempVector1;
  1861. Vector3.cross(up, at, right);
  1862. re[3] = re[7] = re[11] = re[12] = re[13] = re[14] = 0;
  1863. re[15] = 1;
  1864. re[0] = right.x;
  1865. re[1] = right.y;
  1866. re[2] = right.z;
  1867. re[4] = up.x;
  1868. re[5] = up.y;
  1869. re[6] = up.z;
  1870. re[8] = at.x;
  1871. re[9] = at.y;
  1872. re[10] = at.z;
  1873. ((re[0] * m11 + re[1] * m12 + re[2] * m13) < 0.0) && (se.x = -sX);
  1874. ((re[4] * m21 + re[5] * m22 + re[6] * m23) < 0.0) && (se.y = -sY);
  1875. ((re[8] * m31 + re[9] * m32 + re[10] * m33) < 0.0) && (se.z = -sZ);
  1876. return true;
  1877. }
  1878. decomposeYawPitchRoll(yawPitchRoll) {
  1879. var pitch = Math.asin(-this.elements[9]);
  1880. yawPitchRoll.y = pitch;
  1881. var test = Math.cos(pitch);
  1882. if (test > MathUtils3D.zeroTolerance) {
  1883. yawPitchRoll.z = Math.atan2(this.elements[1], this.elements[5]);
  1884. yawPitchRoll.x = Math.atan2(this.elements[8], this.elements[10]);
  1885. }
  1886. else {
  1887. yawPitchRoll.z = Math.atan2(-this.elements[4], this.elements[0]);
  1888. yawPitchRoll.x = 0.0;
  1889. }
  1890. }
  1891. normalize() {
  1892. var v = this.elements;
  1893. var c = v[0], d = v[1], e = v[2], g = Math.sqrt(c * c + d * d + e * e);
  1894. if (g) {
  1895. if (g == 1)
  1896. return;
  1897. }
  1898. else {
  1899. v[0] = 0;
  1900. v[1] = 0;
  1901. v[2] = 0;
  1902. return;
  1903. }
  1904. g = 1 / g;
  1905. v[0] = c * g;
  1906. v[1] = d * g;
  1907. v[2] = e * g;
  1908. }
  1909. transpose() {
  1910. var e, t;
  1911. e = this.elements;
  1912. t = e[1];
  1913. e[1] = e[4];
  1914. e[4] = t;
  1915. t = e[2];
  1916. e[2] = e[8];
  1917. e[8] = t;
  1918. t = e[3];
  1919. e[3] = e[12];
  1920. e[12] = t;
  1921. t = e[6];
  1922. e[6] = e[9];
  1923. e[9] = t;
  1924. t = e[7];
  1925. e[7] = e[13];
  1926. e[13] = t;
  1927. t = e[11];
  1928. e[11] = e[14];
  1929. e[14] = t;
  1930. return this;
  1931. }
  1932. invert(out) {
  1933. var ae = this.elements;
  1934. var oe = out.elements;
  1935. var a00 = ae[0], a01 = ae[1], a02 = ae[2], a03 = ae[3], a10 = ae[4], a11 = ae[5], a12 = ae[6], a13 = ae[7], a20 = ae[8], a21 = ae[9], a22 = ae[10], a23 = ae[11], a30 = ae[12], a31 = ae[13], a32 = ae[14], a33 = ae[15], b00 = a00 * a11 - a01 * a10, b01 = a00 * a12 - a02 * a10, b02 = a00 * a13 - a03 * a10, b03 = a01 * a12 - a02 * a11, b04 = a01 * a13 - a03 * a11, b05 = a02 * a13 - a03 * a12, b06 = a20 * a31 - a21 * a30, b07 = a20 * a32 - a22 * a30, b08 = a20 * a33 - a23 * a30, b09 = a21 * a32 - a22 * a31, b10 = a21 * a33 - a23 * a31, b11 = a22 * a33 - a23 * a32, det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  1936. if (Math.abs(det) === 0.0) {
  1937. return;
  1938. }
  1939. det = 1.0 / det;
  1940. oe[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  1941. oe[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  1942. oe[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  1943. oe[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
  1944. oe[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  1945. oe[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  1946. oe[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  1947. oe[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
  1948. oe[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  1949. oe[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  1950. oe[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  1951. oe[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
  1952. oe[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
  1953. oe[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
  1954. oe[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
  1955. oe[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
  1956. }
  1957. static billboard(objectPosition, cameraPosition, cameraRight, cameraUp, cameraForward, mat) {
  1958. Vector3.subtract(objectPosition, cameraPosition, Matrix4x4._tempVector0);
  1959. var lengthSq = Vector3.scalarLengthSquared(Matrix4x4._tempVector0);
  1960. if (MathUtils3D.isZero(lengthSq)) {
  1961. Vector3.scale(cameraForward, -1, Matrix4x4._tempVector1);
  1962. Matrix4x4._tempVector1.cloneTo(Matrix4x4._tempVector0);
  1963. }
  1964. else {
  1965. Vector3.scale(Matrix4x4._tempVector0, 1 / Math.sqrt(lengthSq), Matrix4x4._tempVector0);
  1966. }
  1967. Vector3.cross(cameraUp, Matrix4x4._tempVector0, Matrix4x4._tempVector2);
  1968. Vector3.normalize(Matrix4x4._tempVector2, Matrix4x4._tempVector2);
  1969. Vector3.cross(Matrix4x4._tempVector0, Matrix4x4._tempVector2, Matrix4x4._tempVector3);
  1970. var crosse = Matrix4x4._tempVector2;
  1971. var finale = Matrix4x4._tempVector3;
  1972. var diffee = Matrix4x4._tempVector0;
  1973. var obpose = objectPosition;
  1974. var mate = mat.elements;
  1975. mate[0] = crosse.x;
  1976. mate[1] = crosse.y;
  1977. mate[2] = crosse.z;
  1978. mate[3] = 0.0;
  1979. mate[4] = finale.x;
  1980. mate[5] = finale.y;
  1981. mate[6] = finale.z;
  1982. mate[7] = 0.0;
  1983. mate[8] = diffee.x;
  1984. mate[9] = diffee.y;
  1985. mate[10] = diffee.z;
  1986. mate[11] = 0.0;
  1987. mate[12] = obpose.x;
  1988. mate[13] = obpose.y;
  1989. mate[14] = obpose.z;
  1990. mate[15] = 1.0;
  1991. }
  1992. identity() {
  1993. var e = this.elements;
  1994. e[1] = e[2] = e[3] = e[4] = e[6] = e[7] = e[8] = e[9] = e[11] = e[12] = e[13] = e[14] = 0;
  1995. e[0] = e[5] = e[10] = e[15] = 1;
  1996. }
  1997. cloneTo(destObject) {
  1998. var i, s, d;
  1999. s = this.elements;
  2000. d = destObject.elements;
  2001. if (s === d) {
  2002. return;
  2003. }
  2004. for (i = 0; i < 16; ++i) {
  2005. d[i] = s[i];
  2006. }
  2007. }
  2008. clone() {
  2009. var dest = new Matrix4x4();
  2010. this.cloneTo(dest);
  2011. return dest;
  2012. }
  2013. static translation(v3, out) {
  2014. var oe = out.elements;
  2015. oe[0] = oe[5] = oe[10] = oe[15] = 1;
  2016. oe[12] = v3.x;
  2017. oe[13] = v3.y;
  2018. oe[14] = v3.z;
  2019. }
  2020. getTranslationVector(out) {
  2021. var me = this.elements;
  2022. out.x = me[12];
  2023. out.y = me[13];
  2024. out.z = me[14];
  2025. }
  2026. setTranslationVector(translate) {
  2027. var me = this.elements;
  2028. var ve = translate;
  2029. me[12] = ve.x;
  2030. me[13] = ve.y;
  2031. me[14] = ve.z;
  2032. }
  2033. getForward(out) {
  2034. var me = this.elements;
  2035. out.x = -me[8];
  2036. out.y = -me[9];
  2037. out.z = -me[10];
  2038. }
  2039. setForward(forward) {
  2040. var me = this.elements;
  2041. me[8] = -forward.x;
  2042. me[9] = -forward.y;
  2043. me[10] = -forward.z;
  2044. }
  2045. }
  2046. Matrix4x4._tempMatrix4x4 = new Matrix4x4();
  2047. Matrix4x4.TEMPMatrix0 = new Matrix4x4();
  2048. Matrix4x4.TEMPMatrix1 = new Matrix4x4();
  2049. Matrix4x4._tempVector0 = new Vector3();
  2050. Matrix4x4._tempVector1 = new Vector3();
  2051. Matrix4x4._tempVector2 = new Vector3();
  2052. Matrix4x4._tempVector3 = new Vector3();
  2053. Matrix4x4._tempQuaternion = new Quaternion();
  2054. Matrix4x4.DEFAULT = new Matrix4x4();
  2055. Matrix4x4.ZERO = new Matrix4x4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  2056. class DefineDatas {
  2057. constructor() {
  2058. this.value = 0;
  2059. }
  2060. add(define) {
  2061. this.value |= define;
  2062. }
  2063. remove(define) {
  2064. this.value &= ~define;
  2065. }
  2066. has(define) {
  2067. return (this.value & define) > 0;
  2068. }
  2069. cloneTo(destObject) {
  2070. var destDefineData = destObject;
  2071. destDefineData.value = this.value;
  2072. }
  2073. clone() {
  2074. var dest = new DefineDatas();
  2075. this.cloneTo(dest);
  2076. return dest;
  2077. }
  2078. }
  2079. class ShaderData {
  2080. constructor(ownerResource = null) {
  2081. this._ownerResource = null;
  2082. this._data = null;
  2083. this._defineDatas = new DefineDatas();
  2084. this._runtimeCopyValues = [];
  2085. this._ownerResource = ownerResource;
  2086. this._initData();
  2087. }
  2088. _initData() {
  2089. this._data = new Object();
  2090. }
  2091. getData() {
  2092. return this._data;
  2093. }
  2094. addDefine(define) {
  2095. this._defineDatas.add(define);
  2096. }
  2097. removeDefine(define) {
  2098. this._defineDatas.remove(define);
  2099. }
  2100. hasDefine(define) {
  2101. return (this._defineDatas.value & define) > 0;
  2102. }
  2103. clearDefine() {
  2104. this._defineDatas.value = 0;
  2105. }
  2106. getBool(index) {
  2107. return this._data[index];
  2108. }
  2109. setBool(index, value) {
  2110. this._data[index] = value;
  2111. }
  2112. getInt(index) {
  2113. return this._data[index];
  2114. }
  2115. setInt(index, value) {
  2116. this._data[index] = value;
  2117. }
  2118. getNumber(index) {
  2119. return this._data[index];
  2120. }
  2121. setNumber(index, value) {
  2122. this._data[index] = value;
  2123. }
  2124. getVector2(index) {
  2125. return this._data[index];
  2126. }
  2127. setVector2(index, value) {
  2128. this._data[index] = value;
  2129. }
  2130. getVector3(index) {
  2131. return this._data[index];
  2132. }
  2133. setVector3(index, value) {
  2134. this._data[index] = value;
  2135. }
  2136. getVector(index) {
  2137. return this._data[index];
  2138. }
  2139. setVector(index, value) {
  2140. this._data[index] = value;
  2141. }
  2142. getQuaternion(index) {
  2143. return this._data[index];
  2144. }
  2145. setQuaternion(index, value) {
  2146. this._data[index] = value;
  2147. }
  2148. getMatrix4x4(index) {
  2149. return this._data[index];
  2150. }
  2151. setMatrix4x4(index, value) {
  2152. this._data[index] = value;
  2153. }
  2154. getBuffer(shaderIndex) {
  2155. return this._data[shaderIndex];
  2156. }
  2157. setBuffer(index, value) {
  2158. this._data[index] = value;
  2159. }
  2160. setTexture(index, value) {
  2161. var lastValue = this._data[index];
  2162. this._data[index] = value;
  2163. if (this._ownerResource && this._ownerResource.referenceCount > 0) {
  2164. (lastValue) && (lastValue._removeReference());
  2165. (value) && (value._addReference());
  2166. }
  2167. }
  2168. getTexture(index) {
  2169. return this._data[index];
  2170. }
  2171. setAttribute(index, value) {
  2172. this._data[index] = value;
  2173. }
  2174. getAttribute(index) {
  2175. return this._data[index];
  2176. }
  2177. getLength() {
  2178. return this._data.length;
  2179. }
  2180. setLength(value) {
  2181. this._data.length = value;
  2182. }
  2183. cloneTo(destObject) {
  2184. var dest = destObject;
  2185. var destData = dest._data;
  2186. for (var k in this._data) {
  2187. var value = this._data[k];
  2188. if (value != null) {
  2189. if (typeof (value) == 'number') {
  2190. destData[k] = value;
  2191. }
  2192. else if (typeof (value) == 'number') {
  2193. destData[k] = value;
  2194. }
  2195. else if (typeof (value) == "boolean") {
  2196. destData[k] = value;
  2197. }
  2198. else if (value instanceof Vector2) {
  2199. var v2 = (destData[k]) || (destData[k] = new Vector2());
  2200. value.cloneTo(v2);
  2201. destData[k] = v2;
  2202. }
  2203. else if (value instanceof Vector3) {
  2204. var v3 = (destData[k]) || (destData[k] = new Vector3());
  2205. value.cloneTo(v3);
  2206. destData[k] = v3;
  2207. }
  2208. else if (value instanceof Vector4) {
  2209. var v4 = (destData[k]) || (destData[k] = new Vector4());
  2210. value.cloneTo(v4);
  2211. destData[k] = v4;
  2212. }
  2213. else if (value instanceof Matrix4x4) {
  2214. var mat = (destData[k]) || (destData[k] = new Matrix4x4());
  2215. value.cloneTo(mat);
  2216. destData[k] = mat;
  2217. }
  2218. else if (value instanceof Laya.BaseTexture) {
  2219. destData[k] = value;
  2220. }
  2221. }
  2222. }
  2223. this._defineDatas.cloneTo(dest._defineDatas);
  2224. }
  2225. clone() {
  2226. var dest = new ShaderData();
  2227. this.cloneTo(dest);
  2228. return dest;
  2229. }
  2230. cloneToForNative(destObject) {
  2231. var dest = destObject;
  2232. var diffSize = this._int32Data.length - dest._int32Data.length;
  2233. if (diffSize > 0) {
  2234. dest.needRenewArrayBufferForNative(this._int32Data.length);
  2235. }
  2236. dest._int32Data.set(this._int32Data, 0);
  2237. var destData = dest._nativeArray;
  2238. var dataCount = this._nativeArray.length;
  2239. destData.length = dataCount;
  2240. for (var i = 0; i < dataCount; i++) {
  2241. var value = this._nativeArray[i];
  2242. if (value) {
  2243. if (typeof (value) == 'number') {
  2244. destData[i] = value;
  2245. dest.setNumber(i, value);
  2246. }
  2247. else if (typeof (value) == 'number') {
  2248. destData[i] = value;
  2249. dest.setInt(i, value);
  2250. }
  2251. else if (typeof (value) == "boolean") {
  2252. destData[i] = value;
  2253. dest.setBool(i, value);
  2254. }
  2255. else if (value instanceof Vector2) {
  2256. var v2 = (destData[i]) || (destData[i] = new Vector2());
  2257. value.cloneTo(v2);
  2258. destData[i] = v2;
  2259. dest.setVector2(i, v2);
  2260. }
  2261. else if (value instanceof Vector3) {
  2262. var v3 = (destData[i]) || (destData[i] = new Vector3());
  2263. value.cloneTo(v3);
  2264. destData[i] = v3;
  2265. dest.setVector3(i, v3);
  2266. }
  2267. else if (value instanceof Vector4) {
  2268. var v4 = (destData[i]) || (destData[i] = new Vector4());
  2269. value.cloneTo(v4);
  2270. destData[i] = v4;
  2271. dest.setVector(i, v4);
  2272. }
  2273. else if (value instanceof Matrix4x4) {
  2274. var mat = (destData[i]) || (destData[i] = new Matrix4x4());
  2275. value.cloneTo(mat);
  2276. destData[i] = mat;
  2277. dest.setMatrix4x4(i, mat);
  2278. }
  2279. else if (value instanceof Laya.BaseTexture) {
  2280. destData[i] = value;
  2281. dest.setTexture(i, value);
  2282. }
  2283. }
  2284. }
  2285. this._defineDatas.cloneTo(dest._defineDatas);
  2286. }
  2287. _initDataForNative() {
  2288. var length = 8;
  2289. this._frameCount = -1;
  2290. this._runtimeCopyValues.length = 0;
  2291. this._nativeArray = [];
  2292. this._data = new ArrayBuffer(length * 4);
  2293. this._int32Data = new Int32Array(this._data);
  2294. this._float32Data = new Float32Array(this._data);
  2295. Laya.LayaGL.instance.createArrayBufferRef(this._data, Laya.LayaGL.ARRAY_BUFFER_TYPE_DATA, true);
  2296. }
  2297. needRenewArrayBufferForNative(index) {
  2298. if (index >= this._int32Data.length) {
  2299. var nByteLen = (index + 1) * 4;
  2300. var pre = this._int32Data;
  2301. var preConchRef = this._data["conchRef"];
  2302. var prePtrID = this._data["_ptrID"];
  2303. this._data = new ArrayBuffer(nByteLen);
  2304. this._int32Data = new Int32Array(this._data);
  2305. this._float32Data = new Float32Array(this._data);
  2306. this._data["conchRef"] = preConchRef;
  2307. this._data["_ptrID"] = prePtrID;
  2308. pre && this._int32Data.set(pre, 0);
  2309. var layagl = Laya.LayaGL.instance;
  2310. if (layagl.updateArrayBufferRef) {
  2311. layagl.updateArrayBufferRef(this._data['_ptrID'], preConchRef.isSyncToRender(), this._data);
  2312. }
  2313. else {
  2314. window.conch.updateArrayBufferRef(this._data['_ptrID'], preConchRef.isSyncToRender(), this._data);
  2315. }
  2316. }
  2317. }
  2318. getDataForNative() {
  2319. return this._nativeArray;
  2320. }
  2321. getIntForNative(index) {
  2322. return this._int32Data[index];
  2323. }
  2324. setIntForNative(index, value) {
  2325. this.needRenewArrayBufferForNative(index);
  2326. this._int32Data[index] = value;
  2327. this._nativeArray[index] = value;
  2328. }
  2329. getBoolForNative(index) {
  2330. return this._int32Data[index] == 1;
  2331. }
  2332. setBoolForNative(index, value) {
  2333. this.needRenewArrayBufferForNative(index);
  2334. this._int32Data[index] = value ? 1 : 0;
  2335. this._nativeArray[index] = value;
  2336. }
  2337. getNumberForNative(index) {
  2338. return this._float32Data[index];
  2339. }
  2340. setNumberForNative(index, value) {
  2341. this.needRenewArrayBufferForNative(index);
  2342. this._float32Data[index] = value;
  2343. this._nativeArray[index] = value;
  2344. }
  2345. getMatrix4x4ForNative(index) {
  2346. return this._nativeArray[index];
  2347. }
  2348. setMatrix4x4ForNative(index, value) {
  2349. this.needRenewArrayBufferForNative(index);
  2350. this._nativeArray[index] = value;
  2351. var nPtrID = this.setReferenceForNative(value.elements);
  2352. this._int32Data[index] = nPtrID;
  2353. }
  2354. getVectorForNative(index) {
  2355. return this._nativeArray[index];
  2356. }
  2357. setVectorForNative(index, value) {
  2358. this.needRenewArrayBufferForNative(index);
  2359. this._nativeArray[index] = value;
  2360. if (!value.elements) {
  2361. value.forNativeElement();
  2362. }
  2363. var nPtrID = this.setReferenceForNative(value.elements);
  2364. this._int32Data[index] = nPtrID;
  2365. }
  2366. getVector2ForNative(index) {
  2367. return this._nativeArray[index];
  2368. }
  2369. setVector2ForNative(index, value) {
  2370. this.needRenewArrayBufferForNative(index);
  2371. this._nativeArray[index] = value;
  2372. if (!value.elements) {
  2373. value.forNativeElement();
  2374. }
  2375. var nPtrID = this.setReferenceForNative(value.elements);
  2376. this._int32Data[index] = nPtrID;
  2377. }
  2378. getVector3ForNative(index) {
  2379. return this._nativeArray[index];
  2380. }
  2381. setVector3ForNative(index, value) {
  2382. this.needRenewArrayBufferForNative(index);
  2383. this._nativeArray[index] = value;
  2384. if (!value.elements) {
  2385. value.forNativeElement();
  2386. }
  2387. var nPtrID = this.setReferenceForNative(value.elements);
  2388. this._int32Data[index] = nPtrID;
  2389. }
  2390. getQuaternionForNative(index) {
  2391. return this._nativeArray[index];
  2392. }
  2393. setQuaternionForNative(index, value) {
  2394. this.needRenewArrayBufferForNative(index);
  2395. this._nativeArray[index] = value;
  2396. if (!value.elements) {
  2397. value.forNativeElement();
  2398. }
  2399. var nPtrID = this.setReferenceForNative(value.elements);
  2400. this._int32Data[index] = nPtrID;
  2401. }
  2402. getBufferForNative(shaderIndex) {
  2403. return this._nativeArray[shaderIndex];
  2404. }
  2405. setBufferForNative(index, value) {
  2406. this.needRenewArrayBufferForNative(index);
  2407. this._nativeArray[index] = value;
  2408. var nPtrID = this.setReferenceForNative(value);
  2409. this._int32Data[index] = nPtrID;
  2410. }
  2411. getAttributeForNative(index) {
  2412. return this._nativeArray[index];
  2413. }
  2414. setAttributeForNative(index, value) {
  2415. this._nativeArray[index] = value;
  2416. if (!value["_ptrID"]) {
  2417. Laya.LayaGL.instance.createArrayBufferRef(value, Laya.LayaGL.ARRAY_BUFFER_TYPE_DATA, true);
  2418. }
  2419. Laya.LayaGL.instance.syncBufferToRenderThread(value);
  2420. this._int32Data[index] = value["_ptrID"];
  2421. }
  2422. getTextureForNative(index) {
  2423. return this._nativeArray[index];
  2424. }
  2425. setTextureForNative(index, value) {
  2426. if (!value)
  2427. return;
  2428. this.needRenewArrayBufferForNative(index);
  2429. var lastValue = this._nativeArray[index];
  2430. this._nativeArray[index] = value;
  2431. this._int32Data[index] = value._glTexture.id;
  2432. if (this._ownerResource && this._ownerResource.referenceCount > 0) {
  2433. (lastValue) && (lastValue._removeReference());
  2434. (value) && (value._addReference());
  2435. }
  2436. }
  2437. setReferenceForNative(value) {
  2438. this.clearRuntimeCopyArray();
  2439. var nRefID = 0;
  2440. var nPtrID = 0;
  2441. if (ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_) {
  2442. Laya.LayaGL.instance.createArrayBufferRefs(value, Laya.LayaGL.ARRAY_BUFFER_TYPE_DATA, true, Laya.LayaGL.ARRAY_BUFFER_REF_REFERENCE);
  2443. nRefID = 0;
  2444. nPtrID = value.getPtrID(nRefID);
  2445. }
  2446. else {
  2447. Laya.LayaGL.instance.createArrayBufferRefs(value, Laya.LayaGL.ARRAY_BUFFER_TYPE_DATA, true, Laya.LayaGL.ARRAY_BUFFER_REF_COPY);
  2448. nRefID = value.getRefNum() - 1;
  2449. nPtrID = value.getPtrID(nRefID);
  2450. this._runtimeCopyValues.push({ "obj": value, "refID": nRefID, "ptrID": nPtrID });
  2451. }
  2452. Laya.LayaGL.instance.syncBufferToRenderThread(value, nRefID);
  2453. return nPtrID;
  2454. }
  2455. static setRuntimeValueMode(bReference) {
  2456. ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_ = bReference;
  2457. }
  2458. clearRuntimeCopyArray() {
  2459. var currentFrame = Laya.Stat.loopCount;
  2460. if (this._frameCount != currentFrame) {
  2461. this._frameCount = currentFrame;
  2462. for (var i = 0, n = this._runtimeCopyValues.length; i < n; i++) {
  2463. var obj = this._runtimeCopyValues[i];
  2464. obj.obj.clearRefNum();
  2465. }
  2466. this._runtimeCopyValues.length = 0;
  2467. }
  2468. }
  2469. }
  2470. ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_ = true;
  2471. class VertexDeclaration {
  2472. constructor(vertexStride, vertexElements) {
  2473. this._id = ++VertexDeclaration._uniqueIDCounter;
  2474. this._vertexElementsDic = {};
  2475. this._vertexStride = vertexStride;
  2476. this._vertexElements = vertexElements;
  2477. var count = vertexElements.length;
  2478. this._shaderValues = new ShaderData(null);
  2479. for (var j = 0; j < count; j++) {
  2480. var vertexElement = vertexElements[j];
  2481. var name = vertexElement._elementUsage;
  2482. this._vertexElementsDic[name] = vertexElement;
  2483. var value = new Int32Array(5);
  2484. var elmentInfo = VertexElementFormat.getElementInfos(vertexElement._elementFormat);
  2485. value[0] = elmentInfo[0];
  2486. value[1] = elmentInfo[1];
  2487. value[2] = elmentInfo[2];
  2488. value[3] = this._vertexStride;
  2489. value[4] = vertexElement._offset;
  2490. this._shaderValues.setAttribute(name, value);
  2491. }
  2492. }
  2493. get id() {
  2494. return this._id;
  2495. }
  2496. get vertexStride() {
  2497. return this._vertexStride;
  2498. }
  2499. get vertexElementCount() {
  2500. return this._vertexElements.length;
  2501. }
  2502. getVertexElementByIndex(index) {
  2503. return this._vertexElements[index];
  2504. }
  2505. getVertexElementByUsage(usage) {
  2506. return this._vertexElementsDic[usage];
  2507. }
  2508. }
  2509. VertexDeclaration._uniqueIDCounter = 1;
  2510. class VertexElement {
  2511. get offset() {
  2512. return this._offset;
  2513. }
  2514. get elementFormat() {
  2515. return this._elementFormat;
  2516. }
  2517. get elementUsage() {
  2518. return this._elementUsage;
  2519. }
  2520. constructor(offset, elementFormat, elementUsage) {
  2521. this._offset = offset;
  2522. this._elementFormat = elementFormat;
  2523. this._elementUsage = elementUsage;
  2524. }
  2525. }
  2526. class VertexMesh {
  2527. static __init__() {
  2528. VertexMesh.instanceWorldMatrixDeclaration = new VertexDeclaration(64, [new VertexElement(0, VertexElementFormat.Vector4, VertexMesh.MESH_WORLDMATRIX_ROW0),
  2529. new VertexElement(16, VertexElementFormat.Vector4, VertexMesh.MESH_WORLDMATRIX_ROW1),
  2530. new VertexElement(32, VertexElementFormat.Vector4, VertexMesh.MESH_WORLDMATRIX_ROW2),
  2531. new VertexElement(48, VertexElementFormat.Vector4, VertexMesh.MESH_WORLDMATRIX_ROW3)]);
  2532. VertexMesh.instanceMVPMatrixDeclaration = new VertexDeclaration(64, [new VertexElement(0, VertexElementFormat.Vector4, VertexMesh.MESH_MVPMATRIX_ROW0),
  2533. new VertexElement(16, VertexElementFormat.Vector4, VertexMesh.MESH_MVPMATRIX_ROW1),
  2534. new VertexElement(32, VertexElementFormat.Vector4, VertexMesh.MESH_MVPMATRIX_ROW2),
  2535. new VertexElement(48, VertexElementFormat.Vector4, VertexMesh.MESH_MVPMATRIX_ROW3)]);
  2536. }
  2537. static getVertexDeclaration(vertexFlag, compatible = true) {
  2538. var verDec = VertexMesh._vertexDeclarationMap[vertexFlag + (compatible ? "_0" : "_1")];
  2539. if (!verDec) {
  2540. var subFlags = vertexFlag.split(",");
  2541. var offset = 0;
  2542. var elements = [];
  2543. for (var i = 0, n = subFlags.length; i < n; i++) {
  2544. var element;
  2545. switch (subFlags[i]) {
  2546. case "POSITION":
  2547. element = new VertexElement(offset, VertexElementFormat.Vector3, VertexMesh.MESH_POSITION0);
  2548. offset += 12;
  2549. break;
  2550. case "NORMAL":
  2551. element = new VertexElement(offset, VertexElementFormat.Vector3, VertexMesh.MESH_NORMAL0);
  2552. offset += 12;
  2553. break;
  2554. case "COLOR":
  2555. element = new VertexElement(offset, VertexElementFormat.Vector4, VertexMesh.MESH_COLOR0);
  2556. offset += 16;
  2557. break;
  2558. case "UV":
  2559. element = new VertexElement(offset, VertexElementFormat.Vector2, VertexMesh.MESH_TEXTURECOORDINATE0);
  2560. offset += 8;
  2561. break;
  2562. case "UV1":
  2563. element = new VertexElement(offset, VertexElementFormat.Vector2, VertexMesh.MESH_TEXTURECOORDINATE1);
  2564. offset += 8;
  2565. break;
  2566. case "BLENDWEIGHT":
  2567. element = new VertexElement(offset, VertexElementFormat.Vector4, VertexMesh.MESH_BLENDWEIGHT0);
  2568. offset += 16;
  2569. break;
  2570. case "BLENDINDICES":
  2571. if (compatible) {
  2572. element = new VertexElement(offset, VertexElementFormat.Vector4, VertexMesh.MESH_BLENDINDICES0);
  2573. offset += 16;
  2574. }
  2575. else {
  2576. element = new VertexElement(offset, VertexElementFormat.Byte4, VertexMesh.MESH_BLENDINDICES0);
  2577. offset += 4;
  2578. }
  2579. break;
  2580. case "TANGENT":
  2581. element = new VertexElement(offset, VertexElementFormat.Vector4, VertexMesh.MESH_TANGENT0);
  2582. offset += 16;
  2583. break;
  2584. default:
  2585. throw "VertexMesh: unknown vertex flag.";
  2586. }
  2587. elements.push(element);
  2588. }
  2589. verDec = new VertexDeclaration(offset, elements);
  2590. VertexMesh._vertexDeclarationMap[vertexFlag + (compatible ? "_0" : "_1")] = verDec;
  2591. }
  2592. return verDec;
  2593. }
  2594. }
  2595. VertexMesh.MESH_POSITION0 = 0;
  2596. VertexMesh.MESH_COLOR0 = 1;
  2597. VertexMesh.MESH_TEXTURECOORDINATE0 = 2;
  2598. VertexMesh.MESH_NORMAL0 = 3;
  2599. VertexMesh.MESH_TANGENT0 = 4;
  2600. VertexMesh.MESH_BLENDINDICES0 = 5;
  2601. VertexMesh.MESH_BLENDWEIGHT0 = 6;
  2602. VertexMesh.MESH_TEXTURECOORDINATE1 = 7;
  2603. VertexMesh.MESH_WORLDMATRIX_ROW0 = 8;
  2604. VertexMesh.MESH_WORLDMATRIX_ROW1 = 9;
  2605. VertexMesh.MESH_WORLDMATRIX_ROW2 = 10;
  2606. VertexMesh.MESH_WORLDMATRIX_ROW3 = 11;
  2607. VertexMesh.MESH_MVPMATRIX_ROW0 = 12;
  2608. VertexMesh.MESH_MVPMATRIX_ROW1 = 13;
  2609. VertexMesh.MESH_MVPMATRIX_ROW2 = 14;
  2610. VertexMesh.MESH_MVPMATRIX_ROW3 = 15;
  2611. VertexMesh._vertexDeclarationMap = {};
  2612. class SubMeshDynamicBatch extends GeometryElement {
  2613. constructor() {
  2614. super();
  2615. this._bufferState = new BufferState();
  2616. var gl = Laya.LayaGL.instance;
  2617. var maxVerDec = VertexMesh.getVertexDeclaration("POSITION,NORMAL,COLOR,UV,UV1,TANGENT");
  2618. var maxByteCount = maxVerDec.vertexStride * SubMeshDynamicBatch.maxIndicesCount;
  2619. this._vertices = new Float32Array(maxByteCount / 4);
  2620. this._vertexBuffer = new VertexBuffer3D(maxByteCount, gl.DYNAMIC_DRAW);
  2621. this._indices = new Int16Array(SubMeshDynamicBatch.maxIndicesCount);
  2622. this._indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, this._indices.length, gl.DYNAMIC_DRAW);
  2623. var memorySize = this._vertexBuffer._byteLength + this._indexBuffer._byteLength;
  2624. Laya.Resource._addMemory(memorySize, memorySize);
  2625. }
  2626. static __init__() {
  2627. SubMeshDynamicBatch.instance = new SubMeshDynamicBatch();
  2628. }
  2629. _getBatchVertices(vertexDeclaration, batchVertices, batchOffset, transform, element, subMesh) {
  2630. var vertexFloatCount = vertexDeclaration.vertexStride / 4;
  2631. var oriVertexes = subMesh._vertexBuffer.getFloat32Data();
  2632. var lightmapScaleOffset = element.render.lightmapScaleOffset;
  2633. var multiSubMesh = element._dynamicMultiSubMesh;
  2634. var vertexCount = element._dynamicVertexCount;
  2635. element._computeWorldPositionsAndNormals(this._positionOffset, this._normalOffset, multiSubMesh, vertexCount);
  2636. var worldPositions = element._dynamicWorldPositions;
  2637. var worldNormals = element._dynamicWorldNormals;
  2638. var indices = subMesh._indices;
  2639. for (var i = 0; i < vertexCount; i++) {
  2640. var index = multiSubMesh ? indices[i] : i;
  2641. var oriOffset = index * vertexFloatCount;
  2642. var bakeOffset = (i + batchOffset) * vertexFloatCount;
  2643. var oriOff = i * 3;
  2644. var bakOff = bakeOffset + this._positionOffset;
  2645. batchVertices[bakOff] = worldPositions[oriOff];
  2646. batchVertices[bakOff + 1] = worldPositions[oriOff + 1];
  2647. batchVertices[bakOff + 2] = worldPositions[oriOff + 2];
  2648. if (this._normalOffset !== -1) {
  2649. bakOff = bakeOffset + this._normalOffset;
  2650. batchVertices[bakOff] = worldNormals[oriOff];
  2651. batchVertices[bakOff + 1] = worldNormals[oriOff + 1];
  2652. batchVertices[bakOff + 2] = worldNormals[oriOff + 2];
  2653. }
  2654. if (this._colorOffset !== -1) {
  2655. bakOff = bakeOffset + this._colorOffset;
  2656. oriOff = oriOffset + this._colorOffset;
  2657. batchVertices[bakOff] = oriVertexes[oriOff];
  2658. batchVertices[bakOff + 1] = oriVertexes[oriOff + 1];
  2659. batchVertices[bakOff + 2] = oriVertexes[oriOff + 2];
  2660. batchVertices[bakOff + 3] = oriVertexes[oriOff + 3];
  2661. }
  2662. if (this._uv0Offset !== -1) {
  2663. bakOff = bakeOffset + this._uv0Offset;
  2664. oriOff = oriOffset + this._uv0Offset;
  2665. batchVertices[bakOff] = oriVertexes[oriOff];
  2666. batchVertices[bakOff + 1] = oriVertexes[oriOff + 1];
  2667. }
  2668. if (this._sTangentOffset !== -1) {
  2669. bakOff = bakeOffset + this._sTangentOffset;
  2670. oriOff = oriOffset + this._sTangentOffset;
  2671. batchVertices[bakOff] = oriVertexes[oriOff];
  2672. batchVertices[bakOff + 1] = oriVertexes[oriOff + 1];
  2673. batchVertices[bakOff + 2] = oriVertexes[oriOff + 2];
  2674. batchVertices[bakOff + 3] = oriVertexes[oriOff + 3];
  2675. bakOff = bakeOffset + this._sTangentOffset;
  2676. oriOff = oriOffset + this._sTangentOffset;
  2677. batchVertices[bakOff] = oriVertexes[oriOff];
  2678. batchVertices[bakOff + 1] = oriVertexes[oriOff + 1];
  2679. batchVertices[bakOff + 2] = oriVertexes[oriOff + 2];
  2680. batchVertices[bakOff + 3] = oriVertexes[oriOff + 3];
  2681. }
  2682. }
  2683. }
  2684. _getBatchIndices(batchIndices, batchIndexCount, batchVertexCount, transform, subMesh, multiSubMesh) {
  2685. var subIndices = subMesh._indices;
  2686. var k, m, batchOffset;
  2687. var isInvert = transform._isFrontFaceInvert;
  2688. if (multiSubMesh) {
  2689. if (isInvert) {
  2690. for (k = 0, m = subIndices.length; k < m; k += 3) {
  2691. batchOffset = batchIndexCount + k;
  2692. var index = batchVertexCount + k;
  2693. batchIndices[batchOffset] = index;
  2694. batchIndices[batchOffset + 1] = index + 2;
  2695. batchIndices[batchOffset + 2] = index + 1;
  2696. }
  2697. }
  2698. else {
  2699. for (k = 0, m = subIndices.length; k < m; k += 3) {
  2700. batchOffset = batchIndexCount + k;
  2701. index = batchVertexCount + k;
  2702. batchIndices[batchOffset] = index;
  2703. batchIndices[batchOffset + 1] = index + 1;
  2704. batchIndices[batchOffset + 2] = index + 2;
  2705. }
  2706. }
  2707. }
  2708. else {
  2709. if (isInvert) {
  2710. for (k = 0, m = subIndices.length; k < m; k += 3) {
  2711. batchOffset = batchIndexCount + k;
  2712. batchIndices[batchOffset] = batchVertexCount + subIndices[k];
  2713. batchIndices[batchOffset + 1] = batchVertexCount + subIndices[k + 2];
  2714. batchIndices[batchOffset + 2] = batchVertexCount + subIndices[k + 1];
  2715. }
  2716. }
  2717. else {
  2718. for (k = 0, m = subIndices.length; k < m; k += 3) {
  2719. batchOffset = batchIndexCount + k;
  2720. batchIndices[batchOffset] = batchVertexCount + subIndices[k];
  2721. batchIndices[batchOffset + 1] = batchVertexCount + subIndices[k + 1];
  2722. batchIndices[batchOffset + 2] = batchVertexCount + subIndices[k + 2];
  2723. }
  2724. }
  2725. }
  2726. }
  2727. _flush(vertexCount, indexCount) {
  2728. var gl = Laya.LayaGL.instance;
  2729. this._vertexBuffer.setData(this._vertices.buffer, 0, 0, vertexCount * (this._bufferState.vertexDeclaration.vertexStride));
  2730. this._indexBuffer.setData(this._indices, 0, 0, indexCount);
  2731. gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, 0);
  2732. }
  2733. _prepareRender(state) {
  2734. var element = state.renderElement;
  2735. var vertexDeclaration = element.vertexBatchVertexDeclaration;
  2736. this._bufferState = ILaya3D.MeshRenderDynamicBatchManager.instance._getBufferState(vertexDeclaration);
  2737. this._positionOffset = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_POSITION0)._offset / 4;
  2738. var normalElement = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_NORMAL0);
  2739. this._normalOffset = normalElement ? normalElement._offset / 4 : -1;
  2740. var colorElement = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_COLOR0);
  2741. this._colorOffset = colorElement ? colorElement._offset / 4 : -1;
  2742. var uv0Element = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_TEXTURECOORDINATE0);
  2743. this._uv0Offset = uv0Element ? uv0Element._offset / 4 : -1;
  2744. var uv1Element = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_TEXTURECOORDINATE1);
  2745. this._uv1Offset = uv1Element ? uv1Element._offset / 4 : -1;
  2746. var tangentElement = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_TANGENT0);
  2747. this._sTangentOffset = tangentElement ? tangentElement._offset / 4 : -1;
  2748. return true;
  2749. }
  2750. _render(context) {
  2751. this._bufferState.bind();
  2752. var element = context.renderElement;
  2753. var vertexDeclaration = element.vertexBatchVertexDeclaration;
  2754. var batchElements = element.vertexBatchElementList;
  2755. var batchVertexCount = 0;
  2756. var batchIndexCount = 0;
  2757. var floatStride = vertexDeclaration.vertexStride / 4;
  2758. var renderBatchCount = 0;
  2759. var elementCount = batchElements.length;
  2760. var elements = batchElements.elements;
  2761. for (var i = 0; i < elementCount; i++) {
  2762. var subElement = elements[i];
  2763. var subMesh = subElement._geometry;
  2764. var indexCount = subMesh._indexCount;
  2765. if (batchIndexCount + indexCount > SubMeshDynamicBatch.maxIndicesCount) {
  2766. this._flush(batchVertexCount, batchIndexCount);
  2767. renderBatchCount++;
  2768. Laya.Stat.trianglesFaces += batchIndexCount / 3;
  2769. batchVertexCount = batchIndexCount = 0;
  2770. }
  2771. var transform = subElement._transform;
  2772. this._getBatchVertices(vertexDeclaration, this._vertices, batchVertexCount, transform, subElement, subMesh);
  2773. this._getBatchIndices(this._indices, batchIndexCount, batchVertexCount, transform, subMesh, subElement._dynamicMultiSubMesh);
  2774. batchVertexCount += subElement._dynamicVertexCount;
  2775. batchIndexCount += indexCount;
  2776. }
  2777. this._flush(batchVertexCount, batchIndexCount);
  2778. renderBatchCount++;
  2779. Laya.Stat.renderBatches += renderBatchCount;
  2780. Laya.Stat.savedRenderBatches += elementCount - renderBatchCount;
  2781. Laya.Stat.trianglesFaces += batchIndexCount / 3;
  2782. }
  2783. }
  2784. SubMeshDynamicBatch.maxAllowVertexCount = 10;
  2785. SubMeshDynamicBatch.maxAllowAttribueCount = 900;
  2786. SubMeshDynamicBatch.maxIndicesCount = 32000;
  2787. class BatchMark {
  2788. constructor() {
  2789. this.updateMark = -1;
  2790. this.indexInList = -1;
  2791. this.batched = false;
  2792. }
  2793. }
  2794. class SubMeshInstanceBatch extends GeometryElement {
  2795. constructor() {
  2796. super();
  2797. this.maxInstanceCount = 1024;
  2798. this.instanceWorldMatrixData = new Float32Array(this.maxInstanceCount * 16);
  2799. this.instanceMVPMatrixData = new Float32Array(this.maxInstanceCount * 16);
  2800. var gl = Laya.LayaGL.instance;
  2801. this.instanceWorldMatrixBuffer = new VertexBuffer3D(this.instanceWorldMatrixData.length * 4, gl.DYNAMIC_DRAW);
  2802. this.instanceMVPMatrixBuffer = new VertexBuffer3D(this.instanceMVPMatrixData.length * 4, gl.DYNAMIC_DRAW);
  2803. this.instanceWorldMatrixBuffer.vertexDeclaration = VertexMesh.instanceWorldMatrixDeclaration;
  2804. this.instanceMVPMatrixBuffer.vertexDeclaration = VertexMesh.instanceMVPMatrixDeclaration;
  2805. }
  2806. static __init__() {
  2807. SubMeshInstanceBatch.instance = new SubMeshInstanceBatch();
  2808. }
  2809. _render(state) {
  2810. var gl = Laya.LayaGL.instance;
  2811. var element = state.renderElement;
  2812. var subMesh = element.instanceSubMesh;
  2813. var count = element.instanceBatchElementList.length;
  2814. var indexCount = subMesh._indexCount;
  2815. subMesh._mesh._instanceBufferState.bind();
  2816. Laya.LayaGL.layaGPUInstance.drawElementsInstanced(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, subMesh._indexStart * 2, count);
  2817. Laya.Stat.renderBatches++;
  2818. Laya.Stat.savedRenderBatches += count - 1;
  2819. Laya.Stat.trianglesFaces += indexCount * count / 3;
  2820. }
  2821. }
  2822. class Color {
  2823. constructor(r = 1, g = 1, b = 1, a = 1) {
  2824. this.r = r;
  2825. this.g = g;
  2826. this.b = b;
  2827. this.a = a;
  2828. }
  2829. static gammaToLinearSpace(value) {
  2830. if (value <= 0.04045)
  2831. return value / 12.92;
  2832. else if (value < 1.0)
  2833. return Math.pow((value + 0.055) / 1.055, 2.4);
  2834. else
  2835. return Math.pow(value, 2.4);
  2836. }
  2837. static linearToGammaSpace(value) {
  2838. if (value <= 0.0)
  2839. return 0.0;
  2840. else if (value <= 0.0031308)
  2841. return 12.92 * value;
  2842. else if (value <= 1.0)
  2843. return 1.055 * Math.pow(value, 0.41666) - 0.055;
  2844. else
  2845. return Math.pow(value, 0.41666);
  2846. }
  2847. toLinear(out) {
  2848. out.r = Color.gammaToLinearSpace(this.r);
  2849. out.g = Color.gammaToLinearSpace(this.g);
  2850. out.b = Color.gammaToLinearSpace(this.b);
  2851. }
  2852. toGamma(out) {
  2853. out.r = Color.linearToGammaSpace(this.r);
  2854. out.g = Color.linearToGammaSpace(this.g);
  2855. out.b = Color.linearToGammaSpace(this.b);
  2856. }
  2857. cloneTo(destObject) {
  2858. var destColor = destObject;
  2859. destColor.r = this.r;
  2860. destColor.g = this.g;
  2861. destColor.b = this.b;
  2862. destColor.a = this.a;
  2863. }
  2864. clone() {
  2865. var dest = new Color();
  2866. this.cloneTo(dest);
  2867. return dest;
  2868. }
  2869. forNativeElement() {
  2870. }
  2871. }
  2872. Color.RED = new Color(1, 0, 0, 1);
  2873. Color.GREEN = new Color(0, 1, 0, 1);
  2874. Color.BLUE = new Color(0, 0, 1, 1);
  2875. Color.CYAN = new Color(0, 1, 1, 1);
  2876. Color.YELLOW = new Color(1, 0.92, 0.016, 1);
  2877. Color.MAGENTA = new Color(1, 0, 1, 1);
  2878. Color.GRAY = new Color(0.5, 0.5, 0.5, 1);
  2879. Color.WHITE = new Color(1, 1, 1, 1);
  2880. Color.BLACK = new Color(0, 0, 0, 1);
  2881. class TextureGenerator {
  2882. constructor() {
  2883. }
  2884. static lightAttenTexture(x, y, maxX, maxY, index, data) {
  2885. var sqrRange = x / maxX;
  2886. var atten = 1.0 / (1.0 + 25.0 * sqrRange);
  2887. if (sqrRange >= 0.64) {
  2888. if (sqrRange > 1.0) {
  2889. atten = 0;
  2890. }
  2891. else {
  2892. atten *= 1 - (sqrRange - 0.64) / (1 - 0.64);
  2893. }
  2894. }
  2895. data[index] = Math.floor(atten * 255.0 + 0.5);
  2896. }
  2897. static haloTexture(x, y, maxX, maxY, index, data) {
  2898. maxX >>= 1;
  2899. maxY >>= 1;
  2900. var xFac = (x - maxX) / maxX;
  2901. var yFac = (y - maxY) / maxY;
  2902. var sqrRange = xFac * xFac + yFac * yFac;
  2903. if (sqrRange > 1.0) {
  2904. sqrRange = 1.0;
  2905. }
  2906. data[index] = Math.floor((1.0 - sqrRange) * 255.0 + 0.5);
  2907. }
  2908. static _generateTexture2D(texture, textureWidth, textureHeight, func) {
  2909. var index = 0;
  2910. var size = 0;
  2911. switch (texture.format) {
  2912. case Laya.BaseTexture.FORMAT_R8G8B8:
  2913. size = 3;
  2914. break;
  2915. case Laya.BaseTexture.FORMAT_R8G8B8A8:
  2916. size = 4;
  2917. break;
  2918. case Laya.BaseTexture.FORMAT_ALPHA8:
  2919. size = 1;
  2920. break;
  2921. default:
  2922. throw "GeneratedTexture._generateTexture: unkonw texture format.";
  2923. }
  2924. var data = new Uint8Array(textureWidth * textureHeight * size);
  2925. for (var y = 0; y < textureHeight; y++) {
  2926. for (var x = 0; x < textureWidth; x++) {
  2927. func(x, y, textureWidth, textureHeight, index, data);
  2928. index += size;
  2929. }
  2930. }
  2931. texture.setPixels(data);
  2932. }
  2933. }
  2934. class Utils3D {
  2935. static _convertToLayaVec3(bVector, out, inverseX) {
  2936. out.x = inverseX ? -bVector.x() : bVector.x();
  2937. out.y = bVector.y();
  2938. out.z = bVector.z();
  2939. }
  2940. static _convertToBulletVec3(lVector, out, inverseX) {
  2941. out.setValue(inverseX ? -lVector.x : lVector.x, lVector.y, lVector.z);
  2942. }
  2943. static _rotationTransformScaleSkinAnimation(tx, ty, tz, qx, qy, qz, qw, sx, sy, sz, outArray, outOffset) {
  2944. var re = Utils3D._tempArray16_0;
  2945. var se = Utils3D._tempArray16_1;
  2946. var tse = Utils3D._tempArray16_2;
  2947. var x2 = qx + qx;
  2948. var y2 = qy + qy;
  2949. var z2 = qz + qz;
  2950. var xx = qx * x2;
  2951. var yx = qy * x2;
  2952. var yy = qy * y2;
  2953. var zx = qz * x2;
  2954. var zy = qz * y2;
  2955. var zz = qz * z2;
  2956. var wx = qw * x2;
  2957. var wy = qw * y2;
  2958. var wz = qw * z2;
  2959. re[15] = 1;
  2960. re[0] = 1 - yy - zz;
  2961. re[1] = yx + wz;
  2962. re[2] = zx - wy;
  2963. re[4] = yx - wz;
  2964. re[5] = 1 - xx - zz;
  2965. re[6] = zy + wx;
  2966. re[8] = zx + wy;
  2967. re[9] = zy - wx;
  2968. re[10] = 1 - xx - yy;
  2969. se[15] = 1;
  2970. se[0] = sx;
  2971. se[5] = sy;
  2972. se[10] = sz;
  2973. var i, ai0, ai1, ai2, ai3;
  2974. for (i = 0; i < 4; i++) {
  2975. ai0 = re[i];
  2976. ai1 = re[i + 4];
  2977. ai2 = re[i + 8];
  2978. ai3 = re[i + 12];
  2979. tse[i] = ai0;
  2980. tse[i + 4] = ai1;
  2981. tse[i + 8] = ai2;
  2982. tse[i + 12] = ai0 * tx + ai1 * ty + ai2 * tz + ai3;
  2983. }
  2984. for (i = 0; i < 4; i++) {
  2985. ai0 = tse[i];
  2986. ai1 = tse[i + 4];
  2987. ai2 = tse[i + 8];
  2988. ai3 = tse[i + 12];
  2989. outArray[i + outOffset] = ai0 * se[0] + ai1 * se[1] + ai2 * se[2] + ai3 * se[3];
  2990. outArray[i + outOffset + 4] = ai0 * se[4] + ai1 * se[5] + ai2 * se[6] + ai3 * se[7];
  2991. outArray[i + outOffset + 8] = ai0 * se[8] + ai1 * se[9] + ai2 * se[10] + ai3 * se[11];
  2992. outArray[i + outOffset + 12] = ai0 * se[12] + ai1 * se[13] + ai2 * se[14] + ai3 * se[15];
  2993. }
  2994. }
  2995. static _computeBoneAndAnimationDatasByBindPoseMatrxix(bones, curData, inverGlobalBindPose, outBonesDatas, outAnimationDatas, boneIndexToMesh) {
  2996. var offset = 0;
  2997. var matOffset = 0;
  2998. var i;
  2999. var parentOffset;
  3000. var boneLength = bones.length;
  3001. for (i = 0; i < boneLength; offset += bones[i].keyframeWidth, matOffset += 16, i++) {
  3002. Utils3D._rotationTransformScaleSkinAnimation(curData[offset + 0], curData[offset + 1], curData[offset + 2], curData[offset + 3], curData[offset + 4], curData[offset + 5], curData[offset + 6], curData[offset + 7], curData[offset + 8], curData[offset + 9], outBonesDatas, matOffset);
  3003. if (i != 0) {
  3004. parentOffset = bones[i].parentIndex * 16;
  3005. Utils3D.mulMatrixByArray(outBonesDatas, parentOffset, outBonesDatas, matOffset, outBonesDatas, matOffset);
  3006. }
  3007. }
  3008. var n = inverGlobalBindPose.length;
  3009. for (i = 0; i < n; i++) {
  3010. Utils3D.mulMatrixByArrayAndMatrixFast(outBonesDatas, boneIndexToMesh[i] * 16, inverGlobalBindPose[i], outAnimationDatas, i * 16);
  3011. }
  3012. }
  3013. static _computeAnimationDatasByArrayAndMatrixFast(inverGlobalBindPose, bonesDatas, outAnimationDatas, boneIndexToMesh) {
  3014. for (var i = 0, n = inverGlobalBindPose.length; i < n; i++)
  3015. Utils3D.mulMatrixByArrayAndMatrixFast(bonesDatas, boneIndexToMesh[i] * 16, inverGlobalBindPose[i], outAnimationDatas, i * 16);
  3016. }
  3017. static _computeBoneAndAnimationDatasByBindPoseMatrxixOld(bones, curData, inverGlobalBindPose, outBonesDatas, outAnimationDatas) {
  3018. var offset = 0;
  3019. var matOffset = 0;
  3020. var i;
  3021. var parentOffset;
  3022. var boneLength = bones.length;
  3023. for (i = 0; i < boneLength; offset += bones[i].keyframeWidth, matOffset += 16, i++) {
  3024. Utils3D._rotationTransformScaleSkinAnimation(curData[offset + 7], curData[offset + 8], curData[offset + 9], curData[offset + 3], curData[offset + 4], curData[offset + 5], curData[offset + 6], curData[offset + 0], curData[offset + 1], curData[offset + 2], outBonesDatas, matOffset);
  3025. if (i != 0) {
  3026. parentOffset = bones[i].parentIndex * 16;
  3027. Utils3D.mulMatrixByArray(outBonesDatas, parentOffset, outBonesDatas, matOffset, outBonesDatas, matOffset);
  3028. }
  3029. }
  3030. var n = inverGlobalBindPose.length;
  3031. for (i = 0; i < n; i++) {
  3032. var arrayOffset = i * 16;
  3033. Utils3D.mulMatrixByArrayAndMatrixFast(outBonesDatas, arrayOffset, inverGlobalBindPose[i], outAnimationDatas, arrayOffset);
  3034. }
  3035. }
  3036. static _computeAnimationDatasByArrayAndMatrixFastOld(inverGlobalBindPose, bonesDatas, outAnimationDatas) {
  3037. var n = inverGlobalBindPose.length;
  3038. for (var i = 0; i < n; i++) {
  3039. var arrayOffset = i * 16;
  3040. Utils3D.mulMatrixByArrayAndMatrixFast(bonesDatas, arrayOffset, inverGlobalBindPose[i], outAnimationDatas, arrayOffset);
  3041. }
  3042. }
  3043. static _computeRootAnimationData(bones, curData, animationDatas) {
  3044. for (var i = 0, offset = 0, matOffset = 0, boneLength = bones.length; i < boneLength; offset += bones[i].keyframeWidth, matOffset += 16, i++)
  3045. Utils3D.createAffineTransformationArray(curData[offset + 0], curData[offset + 1], curData[offset + 2], curData[offset + 3], curData[offset + 4], curData[offset + 5], curData[offset + 6], curData[offset + 7], curData[offset + 8], curData[offset + 9], animationDatas, matOffset);
  3046. }
  3047. static transformVector3ArrayByQuat(sourceArray, sourceOffset, rotation, outArray, outOffset) {
  3048. var x = sourceArray[sourceOffset], y = sourceArray[sourceOffset + 1], z = sourceArray[sourceOffset + 2], qx = rotation.x, qy = rotation.y, qz = rotation.z, qw = rotation.w, ix = qw * x + qy * z - qz * y, iy = qw * y + qz * x - qx * z, iz = qw * z + qx * y - qy * x, iw = -qx * x - qy * y - qz * z;
  3049. outArray[outOffset] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3050. outArray[outOffset + 1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3051. outArray[outOffset + 2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3052. }
  3053. static mulMatrixByArray(leftArray, leftOffset, rightArray, rightOffset, outArray, outOffset) {
  3054. var i, ai0, ai1, ai2, ai3;
  3055. if (outArray === rightArray) {
  3056. rightArray = Utils3D._tempArray16_3;
  3057. for (i = 0; i < 16; ++i) {
  3058. rightArray[i] = outArray[outOffset + i];
  3059. }
  3060. rightOffset = 0;
  3061. }
  3062. for (i = 0; i < 4; i++) {
  3063. ai0 = leftArray[leftOffset + i];
  3064. ai1 = leftArray[leftOffset + i + 4];
  3065. ai2 = leftArray[leftOffset + i + 8];
  3066. ai3 = leftArray[leftOffset + i + 12];
  3067. outArray[outOffset + i] = ai0 * rightArray[rightOffset + 0] + ai1 * rightArray[rightOffset + 1] + ai2 * rightArray[rightOffset + 2] + ai3 * rightArray[rightOffset + 3];
  3068. outArray[outOffset + i + 4] = ai0 * rightArray[rightOffset + 4] + ai1 * rightArray[rightOffset + 5] + ai2 * rightArray[rightOffset + 6] + ai3 * rightArray[rightOffset + 7];
  3069. outArray[outOffset + i + 8] = ai0 * rightArray[rightOffset + 8] + ai1 * rightArray[rightOffset + 9] + ai2 * rightArray[rightOffset + 10] + ai3 * rightArray[rightOffset + 11];
  3070. outArray[outOffset + i + 12] = ai0 * rightArray[rightOffset + 12] + ai1 * rightArray[rightOffset + 13] + ai2 * rightArray[rightOffset + 14] + ai3 * rightArray[rightOffset + 15];
  3071. }
  3072. }
  3073. static mulMatrixByArrayFast(leftArray, leftOffset, rightArray, rightOffset, outArray, outOffset) {
  3074. var i, ai0, ai1, ai2, ai3;
  3075. for (i = 0; i < 4; i++) {
  3076. ai0 = leftArray[leftOffset + i];
  3077. ai1 = leftArray[leftOffset + i + 4];
  3078. ai2 = leftArray[leftOffset + i + 8];
  3079. ai3 = leftArray[leftOffset + i + 12];
  3080. outArray[outOffset + i] = ai0 * rightArray[rightOffset + 0] + ai1 * rightArray[rightOffset + 1] + ai2 * rightArray[rightOffset + 2] + ai3 * rightArray[rightOffset + 3];
  3081. outArray[outOffset + i + 4] = ai0 * rightArray[rightOffset + 4] + ai1 * rightArray[rightOffset + 5] + ai2 * rightArray[rightOffset + 6] + ai3 * rightArray[rightOffset + 7];
  3082. outArray[outOffset + i + 8] = ai0 * rightArray[rightOffset + 8] + ai1 * rightArray[rightOffset + 9] + ai2 * rightArray[rightOffset + 10] + ai3 * rightArray[rightOffset + 11];
  3083. outArray[outOffset + i + 12] = ai0 * rightArray[rightOffset + 12] + ai1 * rightArray[rightOffset + 13] + ai2 * rightArray[rightOffset + 14] + ai3 * rightArray[rightOffset + 15];
  3084. }
  3085. }
  3086. static mulMatrixByArrayAndMatrixFast(leftArray, leftOffset, rightMatrix, outArray, outOffset) {
  3087. var i, ai0, ai1, ai2, ai3;
  3088. var rightMatrixE = rightMatrix.elements;
  3089. var m11 = rightMatrixE[0], m12 = rightMatrixE[1], m13 = rightMatrixE[2], m14 = rightMatrixE[3];
  3090. var m21 = rightMatrixE[4], m22 = rightMatrixE[5], m23 = rightMatrixE[6], m24 = rightMatrixE[7];
  3091. var m31 = rightMatrixE[8], m32 = rightMatrixE[9], m33 = rightMatrixE[10], m34 = rightMatrixE[11];
  3092. var m41 = rightMatrixE[12], m42 = rightMatrixE[13], m43 = rightMatrixE[14], m44 = rightMatrixE[15];
  3093. var ai0LeftOffset = leftOffset;
  3094. var ai1LeftOffset = leftOffset + 4;
  3095. var ai2LeftOffset = leftOffset + 8;
  3096. var ai3LeftOffset = leftOffset + 12;
  3097. var ai0OutOffset = outOffset;
  3098. var ai1OutOffset = outOffset + 4;
  3099. var ai2OutOffset = outOffset + 8;
  3100. var ai3OutOffset = outOffset + 12;
  3101. for (i = 0; i < 4; i++) {
  3102. ai0 = leftArray[ai0LeftOffset + i];
  3103. ai1 = leftArray[ai1LeftOffset + i];
  3104. ai2 = leftArray[ai2LeftOffset + i];
  3105. ai3 = leftArray[ai3LeftOffset + i];
  3106. outArray[ai0OutOffset + i] = ai0 * m11 + ai1 * m12 + ai2 * m13 + ai3 * m14;
  3107. outArray[ai1OutOffset + i] = ai0 * m21 + ai1 * m22 + ai2 * m23 + ai3 * m24;
  3108. outArray[ai2OutOffset + i] = ai0 * m31 + ai1 * m32 + ai2 * m33 + ai3 * m34;
  3109. outArray[ai3OutOffset + i] = ai0 * m41 + ai1 * m42 + ai2 * m43 + ai3 * m44;
  3110. }
  3111. }
  3112. static createAffineTransformationArray(tX, tY, tZ, rX, rY, rZ, rW, sX, sY, sZ, outArray, outOffset) {
  3113. var x2 = rX + rX, y2 = rY + rY, z2 = rZ + rZ;
  3114. var xx = rX * x2, xy = rX * y2, xz = rX * z2, yy = rY * y2, yz = rY * z2, zz = rZ * z2;
  3115. var wx = rW * x2, wy = rW * y2, wz = rW * z2;
  3116. outArray[outOffset + 0] = (1 - (yy + zz)) * sX;
  3117. outArray[outOffset + 1] = (xy + wz) * sX;
  3118. outArray[outOffset + 2] = (xz - wy) * sX;
  3119. outArray[outOffset + 3] = 0;
  3120. outArray[outOffset + 4] = (xy - wz) * sY;
  3121. outArray[outOffset + 5] = (1 - (xx + zz)) * sY;
  3122. outArray[outOffset + 6] = (yz + wx) * sY;
  3123. outArray[outOffset + 7] = 0;
  3124. outArray[outOffset + 8] = (xz + wy) * sZ;
  3125. outArray[outOffset + 9] = (yz - wx) * sZ;
  3126. outArray[outOffset + 10] = (1 - (xx + yy)) * sZ;
  3127. outArray[outOffset + 11] = 0;
  3128. outArray[outOffset + 12] = tX;
  3129. outArray[outOffset + 13] = tY;
  3130. outArray[outOffset + 14] = tZ;
  3131. outArray[outOffset + 15] = 1;
  3132. }
  3133. static transformVector3ArrayToVector3ArrayCoordinate(source, sourceOffset, transform, result, resultOffset) {
  3134. var coordinateX = source[sourceOffset + 0];
  3135. var coordinateY = source[sourceOffset + 1];
  3136. var coordinateZ = source[sourceOffset + 2];
  3137. var transformElem = transform.elements;
  3138. var w = ((coordinateX * transformElem[3]) + (coordinateY * transformElem[7]) + (coordinateZ * transformElem[11]) + transformElem[15]);
  3139. result[resultOffset] = (coordinateX * transformElem[0]) + (coordinateY * transformElem[4]) + (coordinateZ * transformElem[8]) + transformElem[12] / w;
  3140. result[resultOffset + 1] = (coordinateX * transformElem[1]) + (coordinateY * transformElem[5]) + (coordinateZ * transformElem[9]) + transformElem[13] / w;
  3141. result[resultOffset + 2] = (coordinateX * transformElem[2]) + (coordinateY * transformElem[6]) + (coordinateZ * transformElem[10]) + transformElem[14] / w;
  3142. }
  3143. static transformLightingMapTexcoordArray(source, sourceOffset, lightingMapScaleOffset, result, resultOffset) {
  3144. result[resultOffset + 0] = source[sourceOffset + 0] * lightingMapScaleOffset.x + lightingMapScaleOffset.z;
  3145. result[resultOffset + 1] = 1.0 - ((1.0 - source[sourceOffset + 1]) * lightingMapScaleOffset.y + lightingMapScaleOffset.w);
  3146. }
  3147. static getURLVerion(url) {
  3148. var index = url.indexOf("?");
  3149. return index >= 0 ? url.substr(index) : null;
  3150. }
  3151. static _createAffineTransformationArray(trans, rot, scale, outE) {
  3152. var x = rot.x, y = rot.y, z = rot.z, w = rot.w, x2 = x + x, y2 = y + y, z2 = z + z;
  3153. var xx = x * x2, xy = x * y2, xz = x * z2, yy = y * y2, yz = y * z2, zz = z * z2;
  3154. var wx = w * x2, wy = w * y2, wz = w * z2, sx = scale.x, sy = scale.y, sz = scale.z;
  3155. outE[0] = (1 - (yy + zz)) * sx;
  3156. outE[1] = (xy + wz) * sx;
  3157. outE[2] = (xz - wy) * sx;
  3158. outE[3] = 0;
  3159. outE[4] = (xy - wz) * sy;
  3160. outE[5] = (1 - (xx + zz)) * sy;
  3161. outE[6] = (yz + wx) * sy;
  3162. outE[7] = 0;
  3163. outE[8] = (xz + wy) * sz;
  3164. outE[9] = (yz - wx) * sz;
  3165. outE[10] = (1 - (xx + yy)) * sz;
  3166. outE[11] = 0;
  3167. outE[12] = trans.x;
  3168. outE[13] = trans.y;
  3169. outE[14] = trans.z;
  3170. outE[15] = 1;
  3171. }
  3172. static _mulMatrixArray(leftMatrixE, rightMatrix, outArray, outOffset) {
  3173. var i, ai0, ai1, ai2, ai3;
  3174. var rightMatrixE = rightMatrix.elements;
  3175. var m11 = rightMatrixE[0], m12 = rightMatrixE[1], m13 = rightMatrixE[2], m14 = rightMatrixE[3];
  3176. var m21 = rightMatrixE[4], m22 = rightMatrixE[5], m23 = rightMatrixE[6], m24 = rightMatrixE[7];
  3177. var m31 = rightMatrixE[8], m32 = rightMatrixE[9], m33 = rightMatrixE[10], m34 = rightMatrixE[11];
  3178. var m41 = rightMatrixE[12], m42 = rightMatrixE[13], m43 = rightMatrixE[14], m44 = rightMatrixE[15];
  3179. var ai0OutOffset = outOffset;
  3180. var ai1OutOffset = outOffset + 4;
  3181. var ai2OutOffset = outOffset + 8;
  3182. var ai3OutOffset = outOffset + 12;
  3183. for (i = 0; i < 4; i++) {
  3184. ai0 = leftMatrixE[i];
  3185. ai1 = leftMatrixE[i + 4];
  3186. ai2 = leftMatrixE[i + 8];
  3187. ai3 = leftMatrixE[i + 12];
  3188. outArray[ai0OutOffset + i] = ai0 * m11 + ai1 * m12 + ai2 * m13 + ai3 * m14;
  3189. outArray[ai1OutOffset + i] = ai0 * m21 + ai1 * m22 + ai2 * m23 + ai3 * m24;
  3190. outArray[ai2OutOffset + i] = ai0 * m31 + ai1 * m32 + ai2 * m33 + ai3 * m34;
  3191. outArray[ai3OutOffset + i] = ai0 * m41 + ai1 * m42 + ai2 * m43 + ai3 * m44;
  3192. }
  3193. }
  3194. static arcTanAngle(x, y) {
  3195. if (x == 0) {
  3196. if (y == 1)
  3197. return Math.PI / 2;
  3198. return -Math.PI / 2;
  3199. }
  3200. if (x > 0)
  3201. return Math.atan(y / x);
  3202. if (x < 0) {
  3203. if (y > 0)
  3204. return Math.atan(y / x) + Math.PI;
  3205. return Math.atan(y / x) - Math.PI;
  3206. }
  3207. return 0;
  3208. }
  3209. static angleTo(from, location, angle) {
  3210. Vector3.subtract(location, from, Quaternion.TEMPVector30);
  3211. Vector3.normalize(Quaternion.TEMPVector30, Quaternion.TEMPVector30);
  3212. angle.x = Math.asin(Quaternion.TEMPVector30.y);
  3213. angle.y = Utils3D.arcTanAngle(-Quaternion.TEMPVector30.z, -Quaternion.TEMPVector30.x);
  3214. }
  3215. static transformQuat(source, rotation, out) {
  3216. var re = rotation;
  3217. var x = source.x, y = source.y, z = source.z, qx = re[0], qy = re[1], qz = re[2], qw = re[3], ix = qw * x + qy * z - qz * y, iy = qw * y + qz * x - qx * z, iz = qw * z + qx * y - qy * x, iw = -qx * x - qy * y - qz * z;
  3218. out.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3219. out.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3220. out.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3221. }
  3222. static quaternionWeight(f, weight, e) {
  3223. e.x = f.x * weight;
  3224. e.y = f.y * weight;
  3225. e.z = f.z * weight;
  3226. e.w = f.w;
  3227. }
  3228. static quaternionConjugate(value, result) {
  3229. result.x = -value.x;
  3230. result.y = -value.y;
  3231. result.z = -value.z;
  3232. result.w = value.w;
  3233. }
  3234. static scaleWeight(s, w, out) {
  3235. var sX = s.x, sY = s.y, sZ = s.z;
  3236. out.x = sX > 0 ? Math.pow(Math.abs(sX), w) : -Math.pow(Math.abs(sX), w);
  3237. out.y = sY > 0 ? Math.pow(Math.abs(sY), w) : -Math.pow(Math.abs(sY), w);
  3238. out.z = sZ > 0 ? Math.pow(Math.abs(sZ), w) : -Math.pow(Math.abs(sZ), w);
  3239. }
  3240. static scaleBlend(sa, sb, w, out) {
  3241. var saw = Utils3D._tempVector3_0;
  3242. var sbw = Utils3D._tempVector3_1;
  3243. Utils3D.scaleWeight(sa, 1.0 - w, saw);
  3244. Utils3D.scaleWeight(sb, w, sbw);
  3245. var sng = w > 0.5 ? sb : sa;
  3246. out.x = sng.x > 0 ? Math.abs(saw.x * sbw.x) : -Math.abs(saw.x * sbw.x);
  3247. out.y = sng.y > 0 ? Math.abs(saw.y * sbw.y) : -Math.abs(saw.y * sbw.y);
  3248. out.z = sng.z > 0 ? Math.abs(saw.z * sbw.z) : -Math.abs(saw.z * sbw.z);
  3249. }
  3250. static matrix4x4MultiplyFFF(a, b, e) {
  3251. var i, ai0, ai1, ai2, ai3;
  3252. if (e === b) {
  3253. b = new Float32Array(16);
  3254. for (i = 0; i < 16; ++i) {
  3255. b[i] = e[i];
  3256. }
  3257. }
  3258. var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
  3259. var b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7];
  3260. var b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11];
  3261. var b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
  3262. for (i = 0; i < 4; i++) {
  3263. ai0 = a[i];
  3264. ai1 = a[i + 4];
  3265. ai2 = a[i + 8];
  3266. ai3 = a[i + 12];
  3267. e[i] = ai0 * b0 + ai1 * b1 + ai2 * b2 + ai3 * b3;
  3268. e[i + 4] = ai0 * b4 + ai1 * b5 + ai2 * b6 + ai3 * b7;
  3269. e[i + 8] = ai0 * b8 + ai1 * b9 + ai2 * b10 + ai3 * b11;
  3270. e[i + 12] = ai0 * b12 + ai1 * b13 + ai2 * b14 + ai3 * b15;
  3271. }
  3272. }
  3273. static matrix4x4MultiplyFFFForNative(a, b, e) {
  3274. Laya.LayaGL.instance.matrix4x4Multiply(a, b, e);
  3275. }
  3276. static matrix4x4MultiplyMFM(left, right, out) {
  3277. Utils3D.matrix4x4MultiplyFFF(left.elements, right, out.elements);
  3278. }
  3279. static _buildTexture2D(width, height, format, colorFunc, mipmaps = false) {
  3280. var texture = new Laya.Texture2D(width, height, format, mipmaps, true);
  3281. texture.anisoLevel = 1;
  3282. texture.filterMode = Laya.BaseTexture.FILTERMODE_POINT;
  3283. TextureGenerator._generateTexture2D(texture, width, height, colorFunc);
  3284. return texture;
  3285. }
  3286. static _drawBound(debugLine, boundBox, color) {
  3287. if (debugLine.lineCount + 12 > debugLine.maxLineCount)
  3288. debugLine.maxLineCount += 12;
  3289. var start = Utils3D._tempVector3_0;
  3290. var end = Utils3D._tempVector3_1;
  3291. var min = boundBox.min;
  3292. var max = boundBox.max;
  3293. start.setValue(min.x, min.y, min.z);
  3294. end.setValue(max.x, min.y, min.z);
  3295. debugLine.addLine(start, end, color, color);
  3296. start.setValue(min.x, min.y, min.z);
  3297. end.setValue(min.x, min.y, max.z);
  3298. debugLine.addLine(start, end, color, color);
  3299. start.setValue(max.x, min.y, min.z);
  3300. end.setValue(max.x, min.y, max.z);
  3301. debugLine.addLine(start, end, color, color);
  3302. start.setValue(min.x, min.y, max.z);
  3303. end.setValue(max.x, min.y, max.z);
  3304. debugLine.addLine(start, end, color, color);
  3305. start.setValue(min.x, min.y, min.z);
  3306. end.setValue(min.x, max.y, min.z);
  3307. debugLine.addLine(start, end, color, color);
  3308. start.setValue(min.x, min.y, max.z);
  3309. end.setValue(min.x, max.y, max.z);
  3310. debugLine.addLine(start, end, color, color);
  3311. start.setValue(max.x, min.y, min.z);
  3312. end.setValue(max.x, max.y, min.z);
  3313. debugLine.addLine(start, end, color, color);
  3314. start.setValue(max.x, min.y, max.z);
  3315. end.setValue(max.x, max.y, max.z);
  3316. debugLine.addLine(start, end, color, color);
  3317. start.setValue(min.x, max.y, min.z);
  3318. end.setValue(max.x, max.y, min.z);
  3319. debugLine.addLine(start, end, color, color);
  3320. start.setValue(min.x, max.y, min.z);
  3321. end.setValue(min.x, max.y, max.z);
  3322. debugLine.addLine(start, end, color, color);
  3323. start.setValue(max.x, max.y, min.z);
  3324. end.setValue(max.x, max.y, max.z);
  3325. debugLine.addLine(start, end, color, color);
  3326. start.setValue(min.x, max.y, max.z);
  3327. end.setValue(max.x, max.y, max.z);
  3328. debugLine.addLine(start, end, color, color);
  3329. }
  3330. static _getHierarchyPath(rootSprite, checkSprite, path) {
  3331. path.length = 0;
  3332. var sprite = checkSprite;
  3333. while (sprite !== rootSprite) {
  3334. var parent = sprite._parent;
  3335. if (parent)
  3336. path.push(parent.getChildIndex(sprite));
  3337. else
  3338. return null;
  3339. sprite = parent;
  3340. }
  3341. return path;
  3342. }
  3343. static _getNodeByHierarchyPath(rootSprite, invPath) {
  3344. var sprite = rootSprite;
  3345. for (var i = invPath.length - 1; i >= 0; i--) {
  3346. sprite = sprite.getChildAt(invPath[i]);
  3347. }
  3348. return sprite;
  3349. }
  3350. }
  3351. Utils3D._tempVector3_0 = new Vector3();
  3352. Utils3D._tempVector3_1 = new Vector3();
  3353. Utils3D._tempVector3_2 = new Vector3();
  3354. Utils3D._tempColor0 = new Color();
  3355. Utils3D._tempArray16_0 = new Float32Array(16);
  3356. Utils3D._tempArray16_1 = new Float32Array(16);
  3357. Utils3D._tempArray16_2 = new Float32Array(16);
  3358. Utils3D._tempArray16_3 = new Float32Array(16);
  3359. Utils3D._compIdToNode = new Object();
  3360. class Shader3D {
  3361. constructor(name, attributeMap, uniformMap, enableInstancing) {
  3362. this._attributeMap = null;
  3363. this._uniformMap = null;
  3364. this._enableInstancing = false;
  3365. this._subShaders = [];
  3366. this._name = name;
  3367. this._attributeMap = attributeMap;
  3368. this._uniformMap = uniformMap;
  3369. this._enableInstancing = enableInstancing;
  3370. }
  3371. static propertyNameToID(name) {
  3372. if (Shader3D._propertyNameMap[name] != null) {
  3373. return Shader3D._propertyNameMap[name];
  3374. }
  3375. else {
  3376. var id = Shader3D._propertyNameCounter++;
  3377. Shader3D._propertyNameMap[name] = id;
  3378. return id;
  3379. }
  3380. }
  3381. static addInclude(fileName, txt) {
  3382. txt = txt.replace(Laya.ShaderCompile._clearCR, "");
  3383. Laya.ShaderCompile.addInclude(fileName, txt);
  3384. }
  3385. static registerPublicDefine(name) {
  3386. var value = Math.pow(2, Shader3D._publicCounter++);
  3387. Shader3D._globleDefines[value] = name;
  3388. return value;
  3389. }
  3390. static compileShader(name, subShaderIndex, passIndex, publicDefine, spriteDefine, materialDefine) {
  3391. var shader = Shader3D.find(name);
  3392. if (shader) {
  3393. var subShader = shader.getSubShaderAt(subShaderIndex);
  3394. if (subShader) {
  3395. var pass = subShader._passes[passIndex];
  3396. if (pass) {
  3397. if (Laya.WebGL.shaderHighPrecision)
  3398. pass.withCompile(publicDefine, spriteDefine, materialDefine);
  3399. else
  3400. pass.withCompile(publicDefine - Shader3D.SHADERDEFINE_HIGHPRECISION, spriteDefine, materialDefine);
  3401. }
  3402. else {
  3403. console.warn("Shader3D: unknown passIndex.");
  3404. }
  3405. }
  3406. else {
  3407. console.warn("Shader3D: unknown subShaderIndex.");
  3408. }
  3409. }
  3410. else {
  3411. console.warn("Shader3D: unknown shader name.");
  3412. }
  3413. }
  3414. static add(name, attributeMap = null, uniformMap = null, enableInstancing = false) {
  3415. return Shader3D._preCompileShader[name] = new Shader3D(name, attributeMap, uniformMap, enableInstancing);
  3416. }
  3417. static find(name) {
  3418. return Shader3D._preCompileShader[name];
  3419. }
  3420. addSubShader(subShader) {
  3421. this._subShaders.push(subShader);
  3422. subShader._owner = this;
  3423. }
  3424. getSubShaderAt(index) {
  3425. return this._subShaders[index];
  3426. }
  3427. }
  3428. Shader3D.RENDER_STATE_CULL = 0;
  3429. Shader3D.RENDER_STATE_BLEND = 1;
  3430. Shader3D.RENDER_STATE_BLEND_SRC = 2;
  3431. Shader3D.RENDER_STATE_BLEND_DST = 3;
  3432. Shader3D.RENDER_STATE_BLEND_SRC_RGB = 4;
  3433. Shader3D.RENDER_STATE_BLEND_DST_RGB = 5;
  3434. Shader3D.RENDER_STATE_BLEND_SRC_ALPHA = 6;
  3435. Shader3D.RENDER_STATE_BLEND_DST_ALPHA = 7;
  3436. Shader3D.RENDER_STATE_BLEND_CONST_COLOR = 8;
  3437. Shader3D.RENDER_STATE_BLEND_EQUATION = 9;
  3438. Shader3D.RENDER_STATE_BLEND_EQUATION_RGB = 10;
  3439. Shader3D.RENDER_STATE_BLEND_EQUATION_ALPHA = 11;
  3440. Shader3D.RENDER_STATE_DEPTH_TEST = 12;
  3441. Shader3D.RENDER_STATE_DEPTH_WRITE = 13;
  3442. Shader3D.PERIOD_CUSTOM = 0;
  3443. Shader3D.PERIOD_MATERIAL = 1;
  3444. Shader3D.PERIOD_SPRITE = 2;
  3445. Shader3D.PERIOD_CAMERA = 3;
  3446. Shader3D.PERIOD_SCENE = 4;
  3447. Shader3D._propertyNameCounter = 0;
  3448. Shader3D._propertyNameMap = {};
  3449. Shader3D._publicCounter = 0;
  3450. Shader3D._globleDefines = [];
  3451. Shader3D._preCompileShader = {};
  3452. Shader3D.debugMode = false;
  3453. class ShaderDefines {
  3454. constructor(superDefines = null) {
  3455. this._counter = 0;
  3456. this.defines = {};
  3457. if (superDefines) {
  3458. this._counter = superDefines._counter;
  3459. for (var k in superDefines.defines)
  3460. this.defines[k] = superDefines.defines[k];
  3461. }
  3462. }
  3463. registerDefine(name) {
  3464. var value = Math.pow(2, this._counter++);
  3465. this.defines[value] = name;
  3466. return value;
  3467. }
  3468. }
  3469. class AnimatorPlayState {
  3470. get normalizedTime() {
  3471. return this._normalizedTime;
  3472. }
  3473. get duration() {
  3474. return this._duration;
  3475. }
  3476. constructor() {
  3477. }
  3478. _resetPlayState(startTime) {
  3479. this._finish = false;
  3480. this._startPlayTime = startTime;
  3481. this._elapsedTime = startTime;
  3482. this._playEventIndex = 0;
  3483. this._lastIsFront = true;
  3484. }
  3485. _cloneTo(dest) {
  3486. dest._finish = this._finish;
  3487. dest._startPlayTime = this._startPlayTime;
  3488. dest._elapsedTime = this._elapsedTime;
  3489. dest._playEventIndex = this._playEventIndex;
  3490. dest._lastIsFront = this._lastIsFront;
  3491. }
  3492. }
  3493. class AnimatorControllerLayer {
  3494. constructor(name) {
  3495. this._defaultState = null;
  3496. this._referenceCount = 0;
  3497. this._statesMap = {};
  3498. this.playOnWake = true;
  3499. this._playType = -1;
  3500. this._crossMark = 0;
  3501. this._crossDuration = -1;
  3502. this._crossNodesOwnersIndicesMap = {};
  3503. this._crossNodesOwnersCount = 0;
  3504. this._crossNodesOwners = [];
  3505. this._currentPlayState = null;
  3506. this._states = [];
  3507. this._playStateInfo = new AnimatorPlayState();
  3508. this._crossPlayStateInfo = new AnimatorPlayState();
  3509. this._srcCrossClipNodeIndices = [];
  3510. this._destCrossClipNodeIndices = [];
  3511. this.name = name;
  3512. this.defaultWeight = 1.0;
  3513. this.blendingMode = AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
  3514. }
  3515. get defaultState() {
  3516. return this._defaultState;
  3517. }
  3518. set defaultState(value) {
  3519. this._defaultState = value;
  3520. this._statesMap[value.name] = value;
  3521. }
  3522. _removeClip(clipStateInfos, statesMap, index, state) {
  3523. var clip = state._clip;
  3524. var clipStateInfo = clipStateInfos[index];
  3525. clipStateInfos.splice(index, 1);
  3526. delete statesMap[state.name];
  3527. if (this._animator) {
  3528. var frameNodes = clip._nodes;
  3529. var nodeOwners = clipStateInfo._nodeOwners;
  3530. clip._removeReference();
  3531. for (var i = 0, n = frameNodes.count; i < n; i++)
  3532. this._animator._removeKeyframeNodeOwner(nodeOwners, frameNodes.getNodeByIndex(i));
  3533. }
  3534. }
  3535. _getReferenceCount() {
  3536. return this._referenceCount;
  3537. }
  3538. _addReference(count = 1) {
  3539. for (var i = 0, n = this._states.length; i < n; i++)
  3540. this._states[i]._addReference(count);
  3541. this._referenceCount += count;
  3542. }
  3543. _removeReference(count = 1) {
  3544. for (var i = 0, n = this._states.length; i < n; i++)
  3545. this._states[i]._removeReference(count);
  3546. this._referenceCount -= count;
  3547. }
  3548. _clearReference() {
  3549. this._removeReference(-this._referenceCount);
  3550. }
  3551. getAnimatorState(name) {
  3552. var state = this._statesMap[name];
  3553. return state ? state : null;
  3554. }
  3555. addState(state) {
  3556. var stateName = state.name;
  3557. if (this._statesMap[stateName]) {
  3558. throw "AnimatorControllerLayer:this stat's name has exist.";
  3559. }
  3560. else {
  3561. this._statesMap[stateName] = state;
  3562. this._states.push(state);
  3563. if (this._animator) {
  3564. state._clip._addReference();
  3565. this._animator._getOwnersByClip(state);
  3566. }
  3567. }
  3568. }
  3569. removeState(state) {
  3570. var states = this._states;
  3571. var index = -1;
  3572. for (var i = 0, n = states.length; i < n; i++) {
  3573. if (states[i] === state) {
  3574. index = i;
  3575. break;
  3576. }
  3577. }
  3578. if (index !== -1)
  3579. this._removeClip(states, this._statesMap, index, state);
  3580. }
  3581. destroy() {
  3582. this._clearReference();
  3583. this._statesMap = null;
  3584. this._states = null;
  3585. this._playStateInfo = null;
  3586. this._crossPlayStateInfo = null;
  3587. this._defaultState = null;
  3588. }
  3589. cloneTo(destObject) {
  3590. var dest = destObject;
  3591. dest.name = this.name;
  3592. dest.blendingMode = this.blendingMode;
  3593. dest.defaultWeight = this.defaultWeight;
  3594. dest.playOnWake = this.playOnWake;
  3595. }
  3596. clone() {
  3597. var dest = new AnimatorControllerLayer(this.name);
  3598. this.cloneTo(dest);
  3599. return dest;
  3600. }
  3601. }
  3602. AnimatorControllerLayer.BLENDINGMODE_OVERRIDE = 0;
  3603. AnimatorControllerLayer.BLENDINGMODE_ADDTIVE = 1;
  3604. class AnimatorState {
  3605. constructor() {
  3606. this._referenceCount = 0;
  3607. this._clip = null;
  3608. this._nodeOwners = [];
  3609. this._currentFrameIndices = null;
  3610. this._scripts = null;
  3611. this.speed = 1.0;
  3612. this.clipStart = 0.0;
  3613. this.clipEnd = 1.0;
  3614. }
  3615. get clip() {
  3616. return this._clip;
  3617. }
  3618. set clip(value) {
  3619. if (this._clip !== value) {
  3620. if (this._clip)
  3621. (this._referenceCount > 0) && (this._clip._removeReference(this._referenceCount));
  3622. if (value) {
  3623. this._currentFrameIndices = new Int16Array(value._nodes.count);
  3624. this._resetFrameIndices();
  3625. (this._referenceCount > 0) && (this._clip._addReference(this._referenceCount));
  3626. }
  3627. this._clip = value;
  3628. }
  3629. }
  3630. _getReferenceCount() {
  3631. return this._referenceCount;
  3632. }
  3633. _addReference(count = 1) {
  3634. (this._clip) && (this._clip._addReference(count));
  3635. this._referenceCount += count;
  3636. }
  3637. _removeReference(count = 1) {
  3638. (this._clip) && (this._clip._removeReference(count));
  3639. this._referenceCount -= count;
  3640. }
  3641. _clearReference() {
  3642. this._removeReference(-this._referenceCount);
  3643. }
  3644. _resetFrameIndices() {
  3645. for (var i = 0, n = this._currentFrameIndices.length; i < n; i++)
  3646. this._currentFrameIndices[i] = -1;
  3647. }
  3648. addScript(type) {
  3649. var script = new type();
  3650. this._scripts = this._scripts || [];
  3651. this._scripts.push(script);
  3652. return script;
  3653. }
  3654. getScript(type) {
  3655. if (this._scripts) {
  3656. for (var i = 0, n = this._scripts.length; i < n; i++) {
  3657. var script = this._scripts[i];
  3658. if (script instanceof type)
  3659. return script;
  3660. }
  3661. }
  3662. return null;
  3663. }
  3664. getScripts(type) {
  3665. var coms;
  3666. if (this._scripts) {
  3667. for (var i = 0, n = this._scripts.length; i < n; i++) {
  3668. var script = this._scripts[i];
  3669. if (script instanceof type) {
  3670. coms = coms || [];
  3671. coms.push(script);
  3672. }
  3673. }
  3674. }
  3675. return coms;
  3676. }
  3677. cloneTo(destObject) {
  3678. var dest = destObject;
  3679. dest.name = this.name;
  3680. dest.speed = this.speed;
  3681. dest.clipStart = this.clipStart;
  3682. dest.clipEnd = this.clipEnd;
  3683. dest.clip = this._clip;
  3684. }
  3685. clone() {
  3686. var dest = new AnimatorState();
  3687. this.cloneTo(dest);
  3688. return dest;
  3689. }
  3690. }
  3691. class KeyframeNodeOwner {
  3692. constructor() {
  3693. this.indexInList = -1;
  3694. this.referenceCount = 0;
  3695. this.updateMark = -1;
  3696. this.type = -1;
  3697. this.fullPath = null;
  3698. this.propertyOwner = null;
  3699. this.property = null;
  3700. this.defaultValue = null;
  3701. this.crossFixedValue = null;
  3702. }
  3703. saveCrossFixedValue() {
  3704. var pro = this.propertyOwner;
  3705. if (pro) {
  3706. switch (this.type) {
  3707. case 0:
  3708. var proPat = this.property;
  3709. var m = proPat.length - 1;
  3710. for (var j = 0; j < m; j++) {
  3711. pro = pro[proPat[j]];
  3712. if (!pro)
  3713. break;
  3714. }
  3715. this.crossFixedValue = pro[proPat[m]];
  3716. break;
  3717. case 1:
  3718. var locPos = pro.localPosition;
  3719. this.crossFixedValue || (this.crossFixedValue = new Vector3());
  3720. this.crossFixedValue.x = locPos.x;
  3721. this.crossFixedValue.y = locPos.y;
  3722. this.crossFixedValue.z = locPos.z;
  3723. break;
  3724. case 2:
  3725. var locRot = pro.localRotation;
  3726. this.crossFixedValue || (this.crossFixedValue = new Quaternion());
  3727. this.crossFixedValue.x = locRot.x;
  3728. this.crossFixedValue.y = locRot.y;
  3729. this.crossFixedValue.z = locRot.z;
  3730. this.crossFixedValue.w = locRot.w;
  3731. break;
  3732. case 3:
  3733. var locSca = pro.localScale;
  3734. this.crossFixedValue || (this.crossFixedValue = new Vector3());
  3735. this.crossFixedValue.x = locSca.x;
  3736. this.crossFixedValue.y = locSca.y;
  3737. this.crossFixedValue.z = locSca.z;
  3738. break;
  3739. case 4:
  3740. var locEul = pro.localRotationEuler;
  3741. this.crossFixedValue || (this.crossFixedValue = new Vector3());
  3742. this.crossFixedValue.x = locEul.x;
  3743. this.crossFixedValue.y = locEul.y;
  3744. this.crossFixedValue.z = locEul.z;
  3745. break;
  3746. default:
  3747. throw "Animator:unknown type.";
  3748. }
  3749. }
  3750. }
  3751. }
  3752. class Animator extends Laya.Component {
  3753. constructor() {
  3754. super();
  3755. this._keyframeNodeOwners = [];
  3756. this._linkAvatarSpritesData = {};
  3757. this._linkAvatarSprites = [];
  3758. this._renderableSprites = [];
  3759. this.cullingMode = Animator.CULLINGMODE_CULLCOMPLETELY;
  3760. this._controllerLayers = [];
  3761. this._linkSprites = {};
  3762. this._speed = 1.0;
  3763. this._keyframeNodeOwnerMap = {};
  3764. this._updateMark = 0;
  3765. }
  3766. static _update(scene) {
  3767. var pool = scene._animatorPool;
  3768. var elements = pool.elements;
  3769. for (var i = 0, n = pool.length; i < n; i++) {
  3770. var animator = elements[i];
  3771. (animator && animator.enabled) && (animator._update());
  3772. }
  3773. }
  3774. get speed() {
  3775. return this._speed;
  3776. }
  3777. set speed(value) {
  3778. this._speed = value;
  3779. }
  3780. _linkToSprites(linkSprites) {
  3781. for (var k in linkSprites) {
  3782. var nodeOwner = this.owner;
  3783. var path = linkSprites[k];
  3784. for (var j = 0, m = path.length; j < m; j++) {
  3785. var p = path[j];
  3786. if (p === "") {
  3787. break;
  3788. }
  3789. else {
  3790. nodeOwner = nodeOwner.getChildByName(p);
  3791. if (!nodeOwner)
  3792. break;
  3793. }
  3794. }
  3795. (nodeOwner) && (this.linkSprite3DToAvatarNode(k, nodeOwner));
  3796. }
  3797. }
  3798. _addKeyframeNodeOwner(clipOwners, node, propertyOwner) {
  3799. var nodeIndex = node._indexInList;
  3800. var fullPath = node.fullPath;
  3801. var keyframeNodeOwner = this._keyframeNodeOwnerMap[fullPath];
  3802. if (keyframeNodeOwner) {
  3803. keyframeNodeOwner.referenceCount++;
  3804. clipOwners[nodeIndex] = keyframeNodeOwner;
  3805. }
  3806. else {
  3807. var property = propertyOwner;
  3808. for (var i = 0, n = node.propertyCount; i < n; i++) {
  3809. property = property[node.getPropertyByIndex(i)];
  3810. if (!property)
  3811. break;
  3812. }
  3813. keyframeNodeOwner = this._keyframeNodeOwnerMap[fullPath] = new KeyframeNodeOwner();
  3814. keyframeNodeOwner.fullPath = fullPath;
  3815. keyframeNodeOwner.indexInList = this._keyframeNodeOwners.length;
  3816. keyframeNodeOwner.referenceCount = 1;
  3817. keyframeNodeOwner.propertyOwner = propertyOwner;
  3818. var propertyCount = node.propertyCount;
  3819. var propertys = [];
  3820. for (i = 0; i < propertyCount; i++)
  3821. propertys[i] = node.getPropertyByIndex(i);
  3822. keyframeNodeOwner.property = propertys;
  3823. keyframeNodeOwner.type = node.type;
  3824. if (property) {
  3825. if (node.type === 0) {
  3826. keyframeNodeOwner.defaultValue = property;
  3827. }
  3828. else {
  3829. var defaultValue = new property.constructor();
  3830. property.cloneTo(defaultValue);
  3831. keyframeNodeOwner.defaultValue = defaultValue;
  3832. }
  3833. }
  3834. this._keyframeNodeOwners.push(keyframeNodeOwner);
  3835. clipOwners[nodeIndex] = keyframeNodeOwner;
  3836. }
  3837. }
  3838. _removeKeyframeNodeOwner(nodeOwners, node) {
  3839. var fullPath = node.fullPath;
  3840. var keyframeNodeOwner = this._keyframeNodeOwnerMap[fullPath];
  3841. if (keyframeNodeOwner) {
  3842. keyframeNodeOwner.referenceCount--;
  3843. if (keyframeNodeOwner.referenceCount === 0) {
  3844. delete this._keyframeNodeOwnerMap[fullPath];
  3845. this._keyframeNodeOwners.splice(this._keyframeNodeOwners.indexOf(keyframeNodeOwner), 1);
  3846. }
  3847. nodeOwners[node._indexInList] = null;
  3848. }
  3849. }
  3850. _getOwnersByClip(clipStateInfo) {
  3851. var frameNodes = clipStateInfo._clip._nodes;
  3852. var frameNodesCount = frameNodes.count;
  3853. var nodeOwners = clipStateInfo._nodeOwners;
  3854. nodeOwners.length = frameNodesCount;
  3855. for (var i = 0; i < frameNodesCount; i++) {
  3856. var node = frameNodes.getNodeByIndex(i);
  3857. var property = this._avatar ? this._avatarNodeMap[this._avatar._rootNode.name] : this.owner;
  3858. for (var j = 0, m = node.ownerPathCount; j < m; j++) {
  3859. var ownPat = node.getOwnerPathByIndex(j);
  3860. if (ownPat === "") {
  3861. break;
  3862. }
  3863. else {
  3864. property = property.getChildByName(ownPat);
  3865. if (!property)
  3866. break;
  3867. }
  3868. }
  3869. if (property) {
  3870. var propertyOwner = node.propertyOwner;
  3871. (propertyOwner) && (property = property[propertyOwner]);
  3872. property && this._addKeyframeNodeOwner(nodeOwners, node, property);
  3873. }
  3874. }
  3875. }
  3876. _updatePlayer(animatorState, playState, elapsedTime, islooping) {
  3877. var clipDuration = animatorState._clip._duration * (animatorState.clipEnd - animatorState.clipStart);
  3878. var lastElapsedTime = playState._elapsedTime;
  3879. var elapsedPlaybackTime = lastElapsedTime + elapsedTime;
  3880. playState._lastElapsedTime = lastElapsedTime;
  3881. playState._elapsedTime = elapsedPlaybackTime;
  3882. var normalizedTime = elapsedPlaybackTime / clipDuration;
  3883. playState._normalizedTime = normalizedTime;
  3884. var playTime = normalizedTime % 1.0;
  3885. playState._normalizedPlayTime = playTime < 0 ? playTime + 1.0 : playTime;
  3886. playState._duration = clipDuration;
  3887. var scripts = animatorState._scripts;
  3888. if ((!islooping && elapsedPlaybackTime >= clipDuration)) {
  3889. playState._finish = true;
  3890. playState._elapsedTime = clipDuration;
  3891. playState._normalizedPlayTime = 1.0;
  3892. if (scripts) {
  3893. for (var i = 0, n = scripts.length; i < n; i++)
  3894. scripts[i].onStateExit();
  3895. }
  3896. return;
  3897. }
  3898. if (scripts) {
  3899. for (i = 0, n = scripts.length; i < n; i++)
  3900. scripts[i].onStateUpdate();
  3901. }
  3902. }
  3903. _eventScript(scripts, events, eventIndex, endTime, front) {
  3904. if (front) {
  3905. for (var n = events.length; eventIndex < n; eventIndex++) {
  3906. var event = events[eventIndex];
  3907. if (event.time <= endTime) {
  3908. for (var j = 0, m = scripts.length; j < m; j++) {
  3909. var script = scripts[j];
  3910. var fun = script[event.eventName];
  3911. (fun) && (fun.apply(script, event.params));
  3912. }
  3913. }
  3914. else {
  3915. break;
  3916. }
  3917. }
  3918. }
  3919. else {
  3920. for (; eventIndex >= 0; eventIndex--) {
  3921. event = events[eventIndex];
  3922. if (event.time >= endTime) {
  3923. for (j = 0, m = scripts.length; j < m; j++) {
  3924. script = scripts[j];
  3925. fun = script[event.eventName];
  3926. (fun) && (fun.apply(script, event.params));
  3927. }
  3928. }
  3929. else {
  3930. break;
  3931. }
  3932. }
  3933. }
  3934. return eventIndex;
  3935. }
  3936. _updateEventScript(stateInfo, playStateInfo) {
  3937. var scripts = this.owner._scripts;
  3938. if (scripts) {
  3939. var clip = stateInfo._clip;
  3940. var events = clip._animationEvents;
  3941. var clipDuration = clip._duration;
  3942. var elapsedTime = playStateInfo._elapsedTime;
  3943. var time = elapsedTime % clipDuration;
  3944. var loopCount = Math.abs(Math.floor(elapsedTime / clipDuration) - Math.floor(playStateInfo._lastElapsedTime / clipDuration));
  3945. var frontPlay = playStateInfo._elapsedTime >= playStateInfo._lastElapsedTime;
  3946. if (playStateInfo._lastIsFront !== frontPlay) {
  3947. if (frontPlay)
  3948. playStateInfo._playEventIndex++;
  3949. else
  3950. playStateInfo._playEventIndex--;
  3951. playStateInfo._lastIsFront = frontPlay;
  3952. }
  3953. if (loopCount == 0) {
  3954. playStateInfo._playEventIndex = this._eventScript(scripts, events, playStateInfo._playEventIndex, time, frontPlay);
  3955. }
  3956. else {
  3957. if (frontPlay) {
  3958. this._eventScript(scripts, events, playStateInfo._playEventIndex, clipDuration, true);
  3959. for (var i = 0, n = loopCount - 1; i < n; i++)
  3960. this._eventScript(scripts, events, 0, clipDuration, true);
  3961. playStateInfo._playEventIndex = this._eventScript(scripts, events, 0, time, true);
  3962. }
  3963. else {
  3964. this._eventScript(scripts, events, playStateInfo._playEventIndex, 0, false);
  3965. var eventIndex = events.length - 1;
  3966. for (i = 0, n = loopCount - 1; i < n; i++)
  3967. this._eventScript(scripts, events, eventIndex, 0, false);
  3968. playStateInfo._playEventIndex = this._eventScript(scripts, events, eventIndex, time, false);
  3969. }
  3970. }
  3971. }
  3972. }
  3973. _updateClipDatas(animatorState, addtive, playStateInfo, scale) {
  3974. var clip = animatorState._clip;
  3975. var clipDuration = clip._duration;
  3976. var curPlayTime = animatorState.clipStart * clipDuration + playStateInfo._normalizedPlayTime * playStateInfo._duration;
  3977. var currentFrameIndices = animatorState._currentFrameIndices;
  3978. var frontPlay = playStateInfo._elapsedTime > playStateInfo._lastElapsedTime;
  3979. clip._evaluateClipDatasRealTime(clip._nodes, curPlayTime, currentFrameIndices, addtive, frontPlay);
  3980. }
  3981. _applyFloat(pro, proName, nodeOwner, additive, weight, isFirstLayer, data) {
  3982. if (nodeOwner.updateMark === this._updateMark) {
  3983. if (additive) {
  3984. pro[proName] += weight * (data);
  3985. }
  3986. else {
  3987. var oriValue = pro[proName];
  3988. pro[proName] = oriValue + weight * (data - oriValue);
  3989. }
  3990. }
  3991. else {
  3992. if (isFirstLayer) {
  3993. if (additive)
  3994. pro[proName] = nodeOwner.defaultValue + data;
  3995. else
  3996. pro[proName] = data;
  3997. }
  3998. else {
  3999. if (additive) {
  4000. pro[proName] = nodeOwner.defaultValue + weight * (data);
  4001. }
  4002. else {
  4003. var defValue = nodeOwner.defaultValue;
  4004. pro[proName] = defValue + weight * (data - defValue);
  4005. }
  4006. }
  4007. }
  4008. }
  4009. _applyPositionAndRotationEuler(nodeOwner, additive, weight, isFirstLayer, data, out) {
  4010. if (nodeOwner.updateMark === this._updateMark) {
  4011. if (additive) {
  4012. out.x += weight * data.x;
  4013. out.y += weight * data.y;
  4014. out.z += weight * data.z;
  4015. }
  4016. else {
  4017. var oriX = out.x;
  4018. var oriY = out.y;
  4019. var oriZ = out.z;
  4020. out.x = oriX + weight * (data.x - oriX);
  4021. out.y = oriY + weight * (data.y - oriY);
  4022. out.z = oriZ + weight * (data.z - oriZ);
  4023. }
  4024. }
  4025. else {
  4026. if (isFirstLayer) {
  4027. if (additive) {
  4028. var defValue = nodeOwner.defaultValue;
  4029. out.x = defValue.x + data.x;
  4030. out.y = defValue.y + data.y;
  4031. out.z = defValue.z + data.z;
  4032. }
  4033. else {
  4034. out.x = data.x;
  4035. out.y = data.y;
  4036. out.z = data.z;
  4037. }
  4038. }
  4039. else {
  4040. defValue = nodeOwner.defaultValue;
  4041. if (additive) {
  4042. out.x = defValue.x + weight * data.x;
  4043. out.y = defValue.y + weight * data.y;
  4044. out.z = defValue.z + weight * data.z;
  4045. }
  4046. else {
  4047. var defX = defValue.x;
  4048. var defY = defValue.y;
  4049. var defZ = defValue.z;
  4050. out.x = defX + weight * (data.x - defX);
  4051. out.y = defY + weight * (data.y - defY);
  4052. out.z = defZ + weight * (data.z - defZ);
  4053. }
  4054. }
  4055. }
  4056. }
  4057. _applyRotation(nodeOwner, additive, weight, isFirstLayer, clipRot, localRotation) {
  4058. if (nodeOwner.updateMark === this._updateMark) {
  4059. if (additive) {
  4060. var tempQuat = Animator._tempQuaternion1;
  4061. Utils3D.quaternionWeight(clipRot, weight, tempQuat);
  4062. tempQuat.normalize(tempQuat);
  4063. Quaternion.multiply(localRotation, tempQuat, localRotation);
  4064. }
  4065. else {
  4066. Quaternion.lerp(localRotation, clipRot, weight, localRotation);
  4067. }
  4068. }
  4069. else {
  4070. if (isFirstLayer) {
  4071. if (additive) {
  4072. var defaultRot = nodeOwner.defaultValue;
  4073. Quaternion.multiply(defaultRot, clipRot, localRotation);
  4074. }
  4075. else {
  4076. localRotation.x = clipRot.x;
  4077. localRotation.y = clipRot.y;
  4078. localRotation.z = clipRot.z;
  4079. localRotation.w = clipRot.w;
  4080. }
  4081. }
  4082. else {
  4083. defaultRot = nodeOwner.defaultValue;
  4084. if (additive) {
  4085. tempQuat = Animator._tempQuaternion1;
  4086. Utils3D.quaternionWeight(clipRot, weight, tempQuat);
  4087. tempQuat.normalize(tempQuat);
  4088. Quaternion.multiply(defaultRot, tempQuat, localRotation);
  4089. }
  4090. else {
  4091. Quaternion.lerp(defaultRot, clipRot, weight, localRotation);
  4092. }
  4093. }
  4094. }
  4095. }
  4096. _applyScale(nodeOwner, additive, weight, isFirstLayer, clipSca, localScale) {
  4097. if (nodeOwner.updateMark === this._updateMark) {
  4098. if (additive) {
  4099. var scale = Animator._tempVector31;
  4100. Utils3D.scaleWeight(clipSca, weight, scale);
  4101. localScale.x = localScale.x * scale.x;
  4102. localScale.y = localScale.y * scale.y;
  4103. localScale.z = localScale.z * scale.z;
  4104. }
  4105. else {
  4106. Utils3D.scaleBlend(localScale, clipSca, weight, localScale);
  4107. }
  4108. }
  4109. else {
  4110. if (isFirstLayer) {
  4111. if (additive) {
  4112. var defaultSca = nodeOwner.defaultValue;
  4113. localScale.x = defaultSca.x * clipSca.x;
  4114. localScale.y = defaultSca.y * clipSca.y;
  4115. localScale.z = defaultSca.z * clipSca.z;
  4116. }
  4117. else {
  4118. localScale.x = clipSca.x;
  4119. localScale.y = clipSca.y;
  4120. localScale.z = clipSca.z;
  4121. }
  4122. }
  4123. else {
  4124. defaultSca = nodeOwner.defaultValue;
  4125. if (additive) {
  4126. scale = Animator._tempVector31;
  4127. Utils3D.scaleWeight(clipSca, weight, scale);
  4128. localScale.x = defaultSca.x * scale.x;
  4129. localScale.y = defaultSca.y * scale.y;
  4130. localScale.z = defaultSca.z * scale.z;
  4131. }
  4132. else {
  4133. Utils3D.scaleBlend(defaultSca, clipSca, weight, localScale);
  4134. }
  4135. }
  4136. }
  4137. }
  4138. _applyCrossData(nodeOwner, additive, weight, isFirstLayer, srcValue, desValue, crossWeight) {
  4139. var pro = nodeOwner.propertyOwner;
  4140. if (pro) {
  4141. switch (nodeOwner.type) {
  4142. case 0:
  4143. var proPat = nodeOwner.property;
  4144. var m = proPat.length - 1;
  4145. for (var j = 0; j < m; j++) {
  4146. pro = pro[proPat[j]];
  4147. if (!pro)
  4148. break;
  4149. }
  4150. var crossValue = srcValue + crossWeight * (desValue - srcValue);
  4151. this._applyFloat(pro, proPat[m], nodeOwner, additive, weight, isFirstLayer, crossValue);
  4152. break;
  4153. case 1:
  4154. var localPos = pro.localPosition;
  4155. var position = Animator._tempVector30;
  4156. var srcX = srcValue.x, srcY = srcValue.y, srcZ = srcValue.z;
  4157. position.x = srcX + crossWeight * (desValue.x - srcX);
  4158. position.y = srcY + crossWeight * (desValue.y - srcY);
  4159. position.z = srcZ + crossWeight * (desValue.z - srcZ);
  4160. this._applyPositionAndRotationEuler(nodeOwner, additive, weight, isFirstLayer, position, localPos);
  4161. pro.localPosition = localPos;
  4162. break;
  4163. case 2:
  4164. var localRot = pro.localRotation;
  4165. var rotation = Animator._tempQuaternion0;
  4166. Quaternion.lerp(srcValue, desValue, crossWeight, rotation);
  4167. this._applyRotation(nodeOwner, additive, weight, isFirstLayer, rotation, localRot);
  4168. pro.localRotation = localRot;
  4169. break;
  4170. case 3:
  4171. var localSca = pro.localScale;
  4172. var scale = Animator._tempVector30;
  4173. Utils3D.scaleBlend(srcValue, desValue, crossWeight, scale);
  4174. this._applyScale(nodeOwner, additive, weight, isFirstLayer, scale, localSca);
  4175. pro.localScale = localSca;
  4176. break;
  4177. case 4:
  4178. var localEuler = pro.localRotationEuler;
  4179. var rotationEuler = Animator._tempVector30;
  4180. srcX = srcValue.x, srcY = srcValue.y, srcZ = srcValue.z;
  4181. rotationEuler.x = srcX + crossWeight * (desValue.x - srcX);
  4182. rotationEuler.y = srcY + crossWeight * (desValue.y - srcY);
  4183. rotationEuler.z = srcZ + crossWeight * (desValue.z - srcZ);
  4184. this._applyPositionAndRotationEuler(nodeOwner, additive, weight, isFirstLayer, rotationEuler, localEuler);
  4185. pro.localRotationEuler = localEuler;
  4186. break;
  4187. }
  4188. nodeOwner.updateMark = this._updateMark;
  4189. }
  4190. }
  4191. _setClipDatasToNode(stateInfo, additive, weight, isFirstLayer) {
  4192. var nodes = stateInfo._clip._nodes;
  4193. var nodeOwners = stateInfo._nodeOwners;
  4194. for (var i = 0, n = nodes.count; i < n; i++) {
  4195. var nodeOwner = nodeOwners[i];
  4196. if (nodeOwner) {
  4197. var pro = nodeOwner.propertyOwner;
  4198. if (pro) {
  4199. switch (nodeOwner.type) {
  4200. case 0:
  4201. var proPat = nodeOwner.property;
  4202. var m = proPat.length - 1;
  4203. for (var j = 0; j < m; j++) {
  4204. pro = pro[proPat[j]];
  4205. if (!pro)
  4206. break;
  4207. }
  4208. this._applyFloat(pro, proPat[m], nodeOwner, additive, weight, isFirstLayer, nodes.getNodeByIndex(i).data);
  4209. break;
  4210. case 1:
  4211. var localPos = pro.localPosition;
  4212. this._applyPositionAndRotationEuler(nodeOwner, additive, weight, isFirstLayer, nodes.getNodeByIndex(i).data, localPos);
  4213. pro.localPosition = localPos;
  4214. break;
  4215. case 2:
  4216. var localRot = pro.localRotation;
  4217. this._applyRotation(nodeOwner, additive, weight, isFirstLayer, nodes.getNodeByIndex(i).data, localRot);
  4218. pro.localRotation = localRot;
  4219. break;
  4220. case 3:
  4221. var localSca = pro.localScale;
  4222. this._applyScale(nodeOwner, additive, weight, isFirstLayer, nodes.getNodeByIndex(i).data, localSca);
  4223. pro.localScale = localSca;
  4224. break;
  4225. case 4:
  4226. var localEuler = pro.localRotationEuler;
  4227. this._applyPositionAndRotationEuler(nodeOwner, additive, weight, isFirstLayer, nodes.getNodeByIndex(i).data, localEuler);
  4228. pro.localRotationEuler = localEuler;
  4229. break;
  4230. }
  4231. nodeOwner.updateMark = this._updateMark;
  4232. }
  4233. }
  4234. }
  4235. }
  4236. _setCrossClipDatasToNode(controllerLayer, srcState, destState, crossWeight, isFirstLayer) {
  4237. var nodeOwners = controllerLayer._crossNodesOwners;
  4238. var ownerCount = controllerLayer._crossNodesOwnersCount;
  4239. var additive = controllerLayer.blendingMode !== AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
  4240. var weight = controllerLayer.defaultWeight;
  4241. var destDataIndices = controllerLayer._destCrossClipNodeIndices;
  4242. var destNodes = destState._clip._nodes;
  4243. var destNodeOwners = destState._nodeOwners;
  4244. var srcDataIndices = controllerLayer._srcCrossClipNodeIndices;
  4245. var srcNodeOwners = srcState._nodeOwners;
  4246. var srcNodes = srcState._clip._nodes;
  4247. for (var i = 0; i < ownerCount; i++) {
  4248. var nodeOwner = nodeOwners[i];
  4249. if (nodeOwner) {
  4250. var srcIndex = srcDataIndices[i];
  4251. var destIndex = destDataIndices[i];
  4252. var srcValue = srcIndex !== -1 ? srcNodes.getNodeByIndex(srcIndex).data : destNodeOwners[destIndex].defaultValue;
  4253. var desValue = destIndex !== -1 ? destNodes.getNodeByIndex(destIndex).data : srcNodeOwners[srcIndex].defaultValue;
  4254. this._applyCrossData(nodeOwner, additive, weight, isFirstLayer, srcValue, desValue, crossWeight);
  4255. }
  4256. }
  4257. }
  4258. _setFixedCrossClipDatasToNode(controllerLayer, destState, crossWeight, isFirstLayer) {
  4259. var nodeOwners = controllerLayer._crossNodesOwners;
  4260. var ownerCount = controllerLayer._crossNodesOwnersCount;
  4261. var additive = controllerLayer.blendingMode !== AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
  4262. var weight = controllerLayer.defaultWeight;
  4263. var destDataIndices = controllerLayer._destCrossClipNodeIndices;
  4264. var destNodes = destState._clip._nodes;
  4265. for (var i = 0; i < ownerCount; i++) {
  4266. var nodeOwner = nodeOwners[i];
  4267. if (nodeOwner) {
  4268. var destIndex = destDataIndices[i];
  4269. var srcValue = nodeOwner.crossFixedValue;
  4270. var desValue = destIndex !== -1 ? destNodes.getNodeByIndex(destIndex).data : nodeOwner.defaultValue;
  4271. this._applyCrossData(nodeOwner, additive, weight, isFirstLayer, srcValue, desValue, crossWeight);
  4272. }
  4273. }
  4274. }
  4275. _revertDefaultKeyframeNodes(clipStateInfo) {
  4276. var nodeOwners = clipStateInfo._nodeOwners;
  4277. for (var i = 0, n = nodeOwners.length; i < n; i++) {
  4278. var nodeOwner = nodeOwners[i];
  4279. if (nodeOwner) {
  4280. var pro = nodeOwner.propertyOwner;
  4281. if (pro) {
  4282. switch (nodeOwner.type) {
  4283. case 0:
  4284. var proPat = nodeOwner.property;
  4285. var m = proPat.length - 1;
  4286. for (var j = 0; j < m; j++) {
  4287. pro = pro[proPat[j]];
  4288. if (!pro)
  4289. break;
  4290. }
  4291. pro[proPat[m]] = nodeOwner.defaultValue;
  4292. break;
  4293. case 1:
  4294. var locPos = pro.localPosition;
  4295. var def = nodeOwner.defaultValue;
  4296. locPos.x = def.x;
  4297. locPos.y = def.y;
  4298. locPos.z = def.z;
  4299. pro.localPosition = locPos;
  4300. break;
  4301. case 2:
  4302. var locRot = pro.localRotation;
  4303. var defQua = nodeOwner.defaultValue;
  4304. locRot.x = defQua.x;
  4305. locRot.y = defQua.y;
  4306. locRot.z = defQua.z;
  4307. locRot.w = defQua.w;
  4308. pro.localRotation = locRot;
  4309. break;
  4310. case 3:
  4311. var locSca = pro.localScale;
  4312. def = nodeOwner.defaultValue;
  4313. locSca.x = def.x;
  4314. locSca.y = def.y;
  4315. locSca.z = def.z;
  4316. pro.localScale = locSca;
  4317. break;
  4318. case 4:
  4319. var locEul = pro.localRotationEuler;
  4320. def = nodeOwner.defaultValue;
  4321. locEul.x = def.x;
  4322. locEul.y = def.y;
  4323. locEul.z = def.z;
  4324. pro.localRotationEuler = locEul;
  4325. break;
  4326. default:
  4327. throw "Animator:unknown type.";
  4328. }
  4329. }
  4330. }
  4331. }
  4332. }
  4333. _onAdded() {
  4334. var parent = this.owner._parent;
  4335. this.owner._setHierarchyAnimator(this, parent ? parent._hierarchyAnimator : null);
  4336. this.owner._changeAnimatorToLinkSprite3DNoAvatar(this, true, []);
  4337. }
  4338. _onDestroy() {
  4339. for (var i = 0, n = this._controllerLayers.length; i < n; i++)
  4340. this._controllerLayers[i]._removeReference();
  4341. var parent = this.owner._parent;
  4342. this.owner._clearHierarchyAnimator(this, parent ? parent._hierarchyAnimator : null);
  4343. }
  4344. _onEnable() {
  4345. this.owner._scene._animatorPool.add(this);
  4346. for (var i = 0, n = this._controllerLayers.length; i < n; i++) {
  4347. if (this._controllerLayers[i].playOnWake) {
  4348. var defaultClip = this.getDefaultState(i);
  4349. (defaultClip) && (this.play(null, i, 0));
  4350. }
  4351. }
  4352. }
  4353. _onDisable() {
  4354. this.owner._scene._animatorPool.remove(this);
  4355. }
  4356. _handleSpriteOwnersBySprite(isLink, path, sprite) {
  4357. for (var i = 0, n = this._controllerLayers.length; i < n; i++) {
  4358. var clipStateInfos = this._controllerLayers[i]._states;
  4359. for (var j = 0, m = clipStateInfos.length; j < m; j++) {
  4360. var clipStateInfo = clipStateInfos[j];
  4361. var clip = clipStateInfo._clip;
  4362. var nodePath = path.join("/");
  4363. var ownersNodes = clip._nodesMap[nodePath];
  4364. if (ownersNodes) {
  4365. var nodeOwners = clipStateInfo._nodeOwners;
  4366. for (var k = 0, p = ownersNodes.length; k < p; k++) {
  4367. if (isLink)
  4368. this._addKeyframeNodeOwner(nodeOwners, ownersNodes[k], sprite);
  4369. else
  4370. this._removeKeyframeNodeOwner(nodeOwners, ownersNodes[k]);
  4371. }
  4372. }
  4373. }
  4374. }
  4375. }
  4376. _parse(data) {
  4377. var avatarData = data.avatar;
  4378. if (avatarData) {
  4379. this.avatar = Laya.Loader.getRes(avatarData.path);
  4380. var linkSprites = avatarData.linkSprites;
  4381. this._linkSprites = linkSprites;
  4382. this._linkToSprites(linkSprites);
  4383. }
  4384. var clipPaths = data.clipPaths;
  4385. var play = data.playOnWake;
  4386. var layersData = data.layers;
  4387. for (var i = 0; i < layersData.length; i++) {
  4388. var layerData = layersData[i];
  4389. var animatorLayer = new AnimatorControllerLayer(layerData.name);
  4390. if (i === 0)
  4391. animatorLayer.defaultWeight = 1.0;
  4392. else
  4393. animatorLayer.defaultWeight = layerData.weight;
  4394. var blendingModeData = layerData.blendingMode;
  4395. (blendingModeData) && (animatorLayer.blendingMode = blendingModeData);
  4396. this.addControllerLayer(animatorLayer);
  4397. var states = layerData.states;
  4398. for (var j = 0, m = states.length; j < m; j++) {
  4399. var state = states[j];
  4400. var clipPath = state.clipPath;
  4401. if (clipPath) {
  4402. var name = state.name;
  4403. var motion;
  4404. motion = Laya.Loader.getRes(clipPath);
  4405. if (motion) {
  4406. var animatorState = new AnimatorState();
  4407. animatorState.name = name;
  4408. animatorState.clip = motion;
  4409. animatorLayer.addState(animatorState);
  4410. (j === 0) && (this.getControllerLayer(i).defaultState = animatorState);
  4411. }
  4412. }
  4413. }
  4414. (play !== undefined) && (animatorLayer.playOnWake = play);
  4415. }
  4416. var cullingModeData = data.cullingMode;
  4417. (cullingModeData !== undefined) && (this.cullingMode = cullingModeData);
  4418. }
  4419. _update() {
  4420. var timer = this.owner._scene.timer;
  4421. var delta = timer._delta / 1000.0;
  4422. if (this._speed === 0 || delta === 0)
  4423. return;
  4424. var needRender;
  4425. if (this.cullingMode === Animator.CULLINGMODE_CULLCOMPLETELY) {
  4426. needRender = false;
  4427. for (var i = 0, n = this._renderableSprites.length; i < n; i++) {
  4428. if (this._renderableSprites[i]._render._visible) {
  4429. needRender = true;
  4430. break;
  4431. }
  4432. }
  4433. }
  4434. else {
  4435. needRender = true;
  4436. }
  4437. this._updateMark++;
  4438. var timerScale = timer.scale;
  4439. for (i = 0, n = this._controllerLayers.length; i < n; i++) {
  4440. var controllerLayer = this._controllerLayers[i];
  4441. var playStateInfo = controllerLayer._playStateInfo;
  4442. var crossPlayStateInfo = controllerLayer._crossPlayStateInfo;
  4443. addtive = controllerLayer.blendingMode !== AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
  4444. switch (controllerLayer._playType) {
  4445. case 0:
  4446. var animatorState = controllerLayer._currentPlayState;
  4447. var clip = animatorState._clip;
  4448. var speed = this._speed * animatorState.speed;
  4449. var finish = playStateInfo._finish;
  4450. finish || this._updatePlayer(animatorState, playStateInfo, delta * speed, clip.islooping);
  4451. if (needRender) {
  4452. var addtive = controllerLayer.blendingMode !== AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
  4453. this._updateClipDatas(animatorState, addtive, playStateInfo, timerScale * speed);
  4454. this._setClipDatasToNode(animatorState, addtive, controllerLayer.defaultWeight, i === 0);
  4455. finish || this._updateEventScript(animatorState, playStateInfo);
  4456. }
  4457. break;
  4458. case 1:
  4459. animatorState = controllerLayer._currentPlayState;
  4460. clip = animatorState._clip;
  4461. var crossClipState = controllerLayer._crossPlayState;
  4462. var crossClip = crossClipState._clip;
  4463. var crossDuratuion = controllerLayer._crossDuration;
  4464. var startPlayTime = crossPlayStateInfo._startPlayTime;
  4465. var crossClipDuration = crossClip._duration - startPlayTime;
  4466. var crossScale = crossDuratuion > crossClipDuration ? crossClipDuration / crossDuratuion : 1.0;
  4467. var crossSpeed = this._speed * crossClipState.speed;
  4468. this._updatePlayer(crossClipState, crossPlayStateInfo, delta * crossScale * crossSpeed, crossClip.islooping);
  4469. var crossWeight = ((crossPlayStateInfo._elapsedTime - startPlayTime) / crossScale) / crossDuratuion;
  4470. if (crossWeight >= 1.0) {
  4471. if (needRender) {
  4472. this._updateClipDatas(crossClipState, addtive, crossPlayStateInfo, timerScale * crossSpeed);
  4473. this._setClipDatasToNode(crossClipState, addtive, controllerLayer.defaultWeight, i === 0);
  4474. controllerLayer._playType = 0;
  4475. controllerLayer._currentPlayState = crossClipState;
  4476. crossPlayStateInfo._cloneTo(playStateInfo);
  4477. }
  4478. }
  4479. else {
  4480. if (!playStateInfo._finish) {
  4481. speed = this._speed * animatorState.speed;
  4482. this._updatePlayer(animatorState, playStateInfo, delta * speed, clip.islooping);
  4483. }
  4484. if (needRender) {
  4485. this._updateClipDatas(animatorState, addtive, playStateInfo, timerScale * speed);
  4486. this._updateClipDatas(crossClipState, addtive, crossPlayStateInfo, timerScale * crossScale * crossSpeed);
  4487. this._setCrossClipDatasToNode(controllerLayer, animatorState, crossClipState, crossWeight, i === 0);
  4488. }
  4489. }
  4490. if (needRender) {
  4491. this._updateEventScript(animatorState, playStateInfo);
  4492. this._updateEventScript(crossClipState, crossPlayStateInfo);
  4493. }
  4494. break;
  4495. case 2:
  4496. crossClipState = controllerLayer._crossPlayState;
  4497. crossClip = crossClipState._clip;
  4498. crossDuratuion = controllerLayer._crossDuration;
  4499. startPlayTime = crossPlayStateInfo._startPlayTime;
  4500. crossClipDuration = crossClip._duration - startPlayTime;
  4501. crossScale = crossDuratuion > crossClipDuration ? crossClipDuration / crossDuratuion : 1.0;
  4502. crossSpeed = this._speed * crossClipState.speed;
  4503. this._updatePlayer(crossClipState, crossPlayStateInfo, delta * crossScale * crossSpeed, crossClip.islooping);
  4504. if (needRender) {
  4505. crossWeight = ((crossPlayStateInfo._elapsedTime - startPlayTime) / crossScale) / crossDuratuion;
  4506. if (crossWeight >= 1.0) {
  4507. this._updateClipDatas(crossClipState, addtive, crossPlayStateInfo, timerScale * crossSpeed);
  4508. this._setClipDatasToNode(crossClipState, addtive, 1.0, i === 0);
  4509. controllerLayer._playType = 0;
  4510. controllerLayer._currentPlayState = crossClipState;
  4511. crossPlayStateInfo._cloneTo(playStateInfo);
  4512. }
  4513. else {
  4514. this._updateClipDatas(crossClipState, addtive, crossPlayStateInfo, timerScale * crossScale * crossSpeed);
  4515. this._setFixedCrossClipDatasToNode(controllerLayer, crossClipState, crossWeight, i === 0);
  4516. }
  4517. this._updateEventScript(crossClipState, crossPlayStateInfo);
  4518. }
  4519. break;
  4520. }
  4521. }
  4522. if (needRender) {
  4523. if (this._avatar) {
  4524. Laya.Render.supportWebGLPlusAnimation && this._updateAnimationNodeWorldMatix(this._animationNodeLocalPositions, this._animationNodeLocalRotations, this._animationNodeLocalScales, this._animationNodeWorldMatrixs, this._animationNodeParentIndices);
  4525. this._updateAvatarNodesToSprite();
  4526. }
  4527. }
  4528. }
  4529. _cloneTo(dest) {
  4530. var animator = dest;
  4531. animator.avatar = this.avatar;
  4532. animator.cullingMode = this.cullingMode;
  4533. for (var i = 0, n = this._controllerLayers.length; i < n; i++) {
  4534. var controllLayer = this._controllerLayers[i];
  4535. animator.addControllerLayer(controllLayer.clone());
  4536. var animatorStates = controllLayer._states;
  4537. for (var j = 0, m = animatorStates.length; j < m; j++) {
  4538. var state = animatorStates[j].clone();
  4539. var cloneLayer = animator.getControllerLayer(i);
  4540. cloneLayer.addState(state);
  4541. (j == 0) && (cloneLayer.defaultState = state);
  4542. }
  4543. }
  4544. animator._linkSprites = this._linkSprites;
  4545. animator._linkToSprites(this._linkSprites);
  4546. }
  4547. getDefaultState(layerIndex = 0) {
  4548. var controllerLayer = this._controllerLayers[layerIndex];
  4549. return controllerLayer.defaultState;
  4550. }
  4551. addState(state, layerIndex = 0) {
  4552. var controllerLayer = this._controllerLayers[layerIndex];
  4553. controllerLayer.addState(state);
  4554. console.warn("Animator:this function is discard,please use animatorControllerLayer.addState() instead.");
  4555. }
  4556. removeState(state, layerIndex = 0) {
  4557. var controllerLayer = this._controllerLayers[layerIndex];
  4558. controllerLayer.removeState(state);
  4559. console.warn("Animator:this function is discard,please use animatorControllerLayer.removeState() instead.");
  4560. }
  4561. addControllerLayer(controllderLayer) {
  4562. this._controllerLayers.push(controllderLayer);
  4563. controllderLayer._animator = this;
  4564. controllderLayer._addReference();
  4565. var states = controllderLayer._states;
  4566. for (var i = 0, n = states.length; i < n; i++)
  4567. this._getOwnersByClip(states[i]);
  4568. }
  4569. getControllerLayer(layerInex = 0) {
  4570. return this._controllerLayers[layerInex];
  4571. }
  4572. getCurrentAnimatorPlayState(layerInex = 0) {
  4573. return this._controllerLayers[layerInex]._playStateInfo;
  4574. }
  4575. play(name = null, layerIndex = 0, normalizedTime = Number.NEGATIVE_INFINITY) {
  4576. var controllerLayer = this._controllerLayers[layerIndex];
  4577. if (controllerLayer) {
  4578. var defaultState = controllerLayer.defaultState;
  4579. if (!name && !defaultState)
  4580. throw new Error("Animator:must have default clip value,please set clip property.");
  4581. var curPlayState = controllerLayer._currentPlayState;
  4582. var playStateInfo = controllerLayer._playStateInfo;
  4583. var animatorState = name ? controllerLayer._statesMap[name] : defaultState;
  4584. var clipDuration = animatorState._clip._duration;
  4585. if (curPlayState !== animatorState) {
  4586. if (normalizedTime !== Number.NEGATIVE_INFINITY)
  4587. playStateInfo._resetPlayState(clipDuration * normalizedTime);
  4588. else
  4589. playStateInfo._resetPlayState(0.0);
  4590. (curPlayState !== null && curPlayState !== animatorState) && (this._revertDefaultKeyframeNodes(curPlayState));
  4591. controllerLayer._playType = 0;
  4592. controllerLayer._currentPlayState = animatorState;
  4593. }
  4594. else {
  4595. if (normalizedTime !== Number.NEGATIVE_INFINITY) {
  4596. playStateInfo._resetPlayState(clipDuration * normalizedTime);
  4597. controllerLayer._playType = 0;
  4598. }
  4599. }
  4600. var scripts = animatorState._scripts;
  4601. if (scripts) {
  4602. for (var i = 0, n = scripts.length; i < n; i++)
  4603. scripts[i].onStateEnter();
  4604. }
  4605. }
  4606. else {
  4607. // console.warn("Invalid layerIndex " + layerIndex + ".");
  4608. }
  4609. }
  4610. crossFade(name, transitionDuration, layerIndex = 0, normalizedTime = Number.NEGATIVE_INFINITY) {
  4611. var controllerLayer = this._controllerLayers[layerIndex];
  4612. if (controllerLayer) {
  4613. var destAnimatorState = controllerLayer._statesMap[name];
  4614. if (destAnimatorState) {
  4615. var playType = controllerLayer._playType;
  4616. if (playType === -1) {
  4617. this.play(name, layerIndex, normalizedTime);
  4618. return;
  4619. }
  4620. var crossPlayStateInfo = controllerLayer._crossPlayStateInfo;
  4621. var crossNodeOwners = controllerLayer._crossNodesOwners;
  4622. var crossNodeOwnerIndicesMap = controllerLayer._crossNodesOwnersIndicesMap;
  4623. var srcAnimatorState = controllerLayer._currentPlayState;
  4624. var destNodeOwners = destAnimatorState._nodeOwners;
  4625. var destCrossClipNodeIndices = controllerLayer._destCrossClipNodeIndices;
  4626. var destClip = destAnimatorState._clip;
  4627. var destNodes = destClip._nodes;
  4628. var destNodesMap = destClip._nodesDic;
  4629. switch (playType) {
  4630. case 0:
  4631. var srcNodeOwners = srcAnimatorState._nodeOwners;
  4632. var scrCrossClipNodeIndices = controllerLayer._srcCrossClipNodeIndices;
  4633. var srcClip = srcAnimatorState._clip;
  4634. var srcNodes = srcClip._nodes;
  4635. var srcNodesMap = srcClip._nodesDic;
  4636. controllerLayer._playType = 1;
  4637. var crossMark = ++controllerLayer._crossMark;
  4638. var crossCount = controllerLayer._crossNodesOwnersCount = 0;
  4639. for (var i = 0, n = srcNodes.count; i < n; i++) {
  4640. var srcNode = srcNodes.getNodeByIndex(i);
  4641. var srcIndex = srcNode._indexInList;
  4642. var srcNodeOwner = srcNodeOwners[srcIndex];
  4643. if (srcNodeOwner) {
  4644. var srcFullPath = srcNode.fullPath;
  4645. scrCrossClipNodeIndices[crossCount] = srcIndex;
  4646. var destNode = destNodesMap[srcFullPath];
  4647. if (destNode)
  4648. destCrossClipNodeIndices[crossCount] = destNode._indexInList;
  4649. else
  4650. destCrossClipNodeIndices[crossCount] = -1;
  4651. crossNodeOwnerIndicesMap[srcFullPath] = crossMark;
  4652. crossNodeOwners[crossCount] = srcNodeOwner;
  4653. crossCount++;
  4654. }
  4655. }
  4656. for (i = 0, n = destNodes.count; i < n; i++) {
  4657. destNode = destNodes.getNodeByIndex(i);
  4658. var destIndex = destNode._indexInList;
  4659. var destNodeOwner = destNodeOwners[destIndex];
  4660. if (destNodeOwner) {
  4661. var destFullPath = destNode.fullPath;
  4662. if (!srcNodesMap[destFullPath]) {
  4663. scrCrossClipNodeIndices[crossCount] = -1;
  4664. destCrossClipNodeIndices[crossCount] = destIndex;
  4665. crossNodeOwnerIndicesMap[destFullPath] = crossMark;
  4666. crossNodeOwners[crossCount] = destNodeOwner;
  4667. crossCount++;
  4668. }
  4669. }
  4670. }
  4671. break;
  4672. case 1:
  4673. case 2:
  4674. controllerLayer._playType = 2;
  4675. for (i = 0, n = crossNodeOwners.length; i < n; i++) {
  4676. var nodeOwner = crossNodeOwners[i];
  4677. nodeOwner.saveCrossFixedValue();
  4678. destNode = destNodesMap[nodeOwner.fullPath];
  4679. if (destNode)
  4680. destCrossClipNodeIndices[i] = destNode._indexInList;
  4681. else
  4682. destCrossClipNodeIndices[i] = -1;
  4683. }
  4684. crossCount = controllerLayer._crossNodesOwnersCount;
  4685. crossMark = controllerLayer._crossMark;
  4686. for (i = 0, n = destNodes.count; i < n; i++) {
  4687. destNode = destNodes.getNodeByIndex(i);
  4688. destIndex = destNode._indexInList;
  4689. destNodeOwner = destNodeOwners[destIndex];
  4690. if (destNodeOwner) {
  4691. destFullPath = destNode.fullPath;
  4692. if (crossNodeOwnerIndicesMap[destFullPath] !== crossMark) {
  4693. destCrossClipNodeIndices[crossCount] = destIndex;
  4694. crossNodeOwnerIndicesMap[destFullPath] = crossMark;
  4695. nodeOwner = destNodeOwners[destIndex];
  4696. crossNodeOwners[crossCount] = nodeOwner;
  4697. nodeOwner.saveCrossFixedValue();
  4698. crossCount++;
  4699. }
  4700. }
  4701. }
  4702. break;
  4703. default:
  4704. }
  4705. controllerLayer._crossNodesOwnersCount = crossCount;
  4706. controllerLayer._crossPlayState = destAnimatorState;
  4707. controllerLayer._crossDuration = srcAnimatorState._clip._duration * transitionDuration;
  4708. if (normalizedTime !== Number.NEGATIVE_INFINITY)
  4709. crossPlayStateInfo._resetPlayState(destClip._duration * normalizedTime);
  4710. else
  4711. crossPlayStateInfo._resetPlayState(0.0);
  4712. var scripts = destAnimatorState._scripts;
  4713. if (scripts) {
  4714. for (i = 0, n = scripts.length; i < n; i++)
  4715. scripts[i].onStateEnter();
  4716. }
  4717. }
  4718. else {
  4719. console.warn("Invalid name " + layerIndex + ".");
  4720. }
  4721. }
  4722. else {
  4723. console.warn("Invalid layerIndex " + layerIndex + ".");
  4724. }
  4725. }
  4726. get avatar() {
  4727. return this._avatar;
  4728. }
  4729. set avatar(value) {
  4730. if (this._avatar !== value) {
  4731. this._avatar = value;
  4732. if (value) {
  4733. this._getAvatarOwnersAndInitDatasAsync();
  4734. this.owner._changeHierarchyAnimatorAvatar(this, value);
  4735. }
  4736. else {
  4737. var parent = this.owner._parent;
  4738. this.owner._changeHierarchyAnimatorAvatar(this, parent ? parent._hierarchyAnimator._avatar : null);
  4739. }
  4740. }
  4741. }
  4742. _getAvatarOwnersAndInitDatasAsync() {
  4743. for (var i = 0, n = this._controllerLayers.length; i < n; i++) {
  4744. var clipStateInfos = this._controllerLayers[i]._states;
  4745. for (var j = 0, m = clipStateInfos.length; j < m; j++)
  4746. this._getOwnersByClip(clipStateInfos[j]);
  4747. }
  4748. this._avatar._cloneDatasToAnimator(this);
  4749. for (var k in this._linkAvatarSpritesData) {
  4750. var sprites = this._linkAvatarSpritesData[k];
  4751. if (sprites) {
  4752. for (var c = 0, p = sprites.length; c < p; c++)
  4753. this._isLinkSpriteToAnimationNode(sprites[c], k, true);
  4754. }
  4755. }
  4756. }
  4757. _isLinkSpriteToAnimationNode(sprite, nodeName, isLink) {
  4758. if (this._avatar) {
  4759. var node = this._avatarNodeMap[nodeName];
  4760. if (node) {
  4761. if (isLink) {
  4762. sprite._transform._dummy = node.transform;
  4763. this._linkAvatarSprites.push(sprite);
  4764. var nodeTransform = node.transform;
  4765. var spriteTransform = sprite.transform;
  4766. if (!spriteTransform.owner.isStatic && nodeTransform) {
  4767. var spriteWorldMatrix = spriteTransform.worldMatrix;
  4768. var ownParTra = this.owner._transform._parent;
  4769. if (ownParTra) {
  4770. Utils3D.matrix4x4MultiplyMFM(ownParTra.worldMatrix, nodeTransform.getWorldMatrix(), spriteWorldMatrix);
  4771. }
  4772. else {
  4773. var sprWorE = spriteWorldMatrix.elements;
  4774. var nodWorE = nodeTransform.getWorldMatrix();
  4775. for (var i = 0; i < 16; i++)
  4776. sprWorE[i] = nodWorE[i];
  4777. }
  4778. spriteTransform.worldMatrix = spriteWorldMatrix;
  4779. }
  4780. }
  4781. else {
  4782. sprite._transform._dummy = null;
  4783. this._linkAvatarSprites.splice(this._linkAvatarSprites.indexOf(sprite), 1);
  4784. }
  4785. }
  4786. }
  4787. }
  4788. _isLinkSpriteToAnimationNodeData(sprite, nodeName, isLink) {
  4789. var linkSprites = this._linkAvatarSpritesData[nodeName];
  4790. if (isLink) {
  4791. linkSprites || (this._linkAvatarSpritesData[nodeName] = linkSprites = []);
  4792. linkSprites.push(sprite);
  4793. }
  4794. else {
  4795. var index = linkSprites.indexOf(sprite);
  4796. linkSprites.splice(index, 1);
  4797. }
  4798. }
  4799. _updateAvatarNodesToSprite() {
  4800. for (var i = 0, n = this._linkAvatarSprites.length; i < n; i++) {
  4801. var sprite = this._linkAvatarSprites[i];
  4802. var nodeTransform = sprite.transform._dummy;
  4803. var spriteTransform = sprite.transform;
  4804. if (!spriteTransform.owner.isStatic && nodeTransform) {
  4805. var spriteWorldMatrix = spriteTransform.worldMatrix;
  4806. var ownTra = this.owner._transform;
  4807. Utils3D.matrix4x4MultiplyMFM(ownTra.worldMatrix, nodeTransform.getWorldMatrix(), spriteWorldMatrix);
  4808. spriteTransform.worldMatrix = spriteWorldMatrix;
  4809. }
  4810. }
  4811. }
  4812. linkSprite3DToAvatarNode(nodeName, sprite3D) {
  4813. this._isLinkSpriteToAnimationNodeData(sprite3D, nodeName, true);
  4814. this._isLinkSpriteToAnimationNode(sprite3D, nodeName, true);
  4815. return true;
  4816. }
  4817. unLinkSprite3DToAvatarNode(sprite3D) {
  4818. if (sprite3D._hierarchyAnimator === this) {
  4819. var dummy = sprite3D.transform._dummy;
  4820. if (dummy) {
  4821. var nodeName = dummy._owner.name;
  4822. this._isLinkSpriteToAnimationNodeData(sprite3D, nodeName, false);
  4823. this._isLinkSpriteToAnimationNode(sprite3D, nodeName, false);
  4824. return true;
  4825. }
  4826. else {
  4827. return false;
  4828. }
  4829. }
  4830. else {
  4831. throw ("Animator:sprite3D must belong to this Animator");
  4832. return false;
  4833. }
  4834. }
  4835. _updateAnimationNodeWorldMatix(localPositions, localRotations, localScales, worldMatrixs, parentIndices) {
  4836. Laya.LayaGL.instance.updateAnimationNodeWorldMatix(localPositions, localRotations, localScales, parentIndices, worldMatrixs);
  4837. }
  4838. }
  4839. Animator._tempVector30 = new Vector3();
  4840. Animator._tempVector31 = new Vector3();
  4841. Animator._tempQuaternion0 = new Quaternion();
  4842. Animator._tempQuaternion1 = new Quaternion();
  4843. Animator._tempVector3Array0 = new Float32Array(3);
  4844. Animator._tempVector3Array1 = new Float32Array(3);
  4845. Animator._tempQuaternionArray0 = new Float32Array(4);
  4846. Animator._tempQuaternionArray1 = new Float32Array(4);
  4847. Animator.CULLINGMODE_ALWAYSANIMATE = 0;
  4848. Animator.CULLINGMODE_CULLCOMPLETELY = 2;
  4849. class Transform3D extends Laya.EventDispatcher {
  4850. constructor(owner) {
  4851. super();
  4852. this._localPosition = new Vector3(0, 0, 0);
  4853. this._localRotation = new Quaternion(0, 0, 0, 1);
  4854. this._localScale = new Vector3(1, 1, 1);
  4855. this._localRotationEuler = new Vector3(0, 0, 0);
  4856. this._localMatrix = new Matrix4x4();
  4857. this._position = new Vector3(0, 0, 0);
  4858. this._rotation = new Quaternion(0, 0, 0, 1);
  4859. this._scale = new Vector3(1, 1, 1);
  4860. this._rotationEuler = new Vector3(0, 0, 0);
  4861. this._worldMatrix = new Matrix4x4();
  4862. this._children = null;
  4863. this._parent = null;
  4864. this._dummy = null;
  4865. this._transformFlag = 0;
  4866. this._owner = owner;
  4867. this._children = [];
  4868. this._setTransformFlag(Transform3D.TRANSFORM_LOCALQUATERNION | Transform3D.TRANSFORM_LOCALEULER | Transform3D.TRANSFORM_LOCALMATRIX, false);
  4869. this._setTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDEULER | Transform3D.TRANSFORM_WORLDSCALE | Transform3D.TRANSFORM_WORLDMATRIX, true);
  4870. }
  4871. get _isFrontFaceInvert() {
  4872. var scale = this.getWorldLossyScale();
  4873. var isInvert = scale.x < 0;
  4874. (scale.y < 0) && (isInvert = !isInvert);
  4875. (scale.z < 0) && (isInvert = !isInvert);
  4876. return isInvert;
  4877. }
  4878. get owner() {
  4879. return this._owner;
  4880. }
  4881. get worldNeedUpdate() {
  4882. return this._getTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX);
  4883. }
  4884. get localPositionX() {
  4885. return this._localPosition.x;
  4886. }
  4887. set localPositionX(x) {
  4888. this._localPosition.x = x;
  4889. this.localPosition = this._localPosition;
  4890. }
  4891. get localPositionY() {
  4892. return this._localPosition.y;
  4893. }
  4894. set localPositionY(y) {
  4895. this._localPosition.y = y;
  4896. this.localPosition = this._localPosition;
  4897. }
  4898. get localPositionZ() {
  4899. return this._localPosition.z;
  4900. }
  4901. set localPositionZ(z) {
  4902. this._localPosition.z = z;
  4903. this.localPosition = this._localPosition;
  4904. }
  4905. get localPosition() {
  4906. return this._localPosition;
  4907. }
  4908. set localPosition(value) {
  4909. if (this._localPosition !== value)
  4910. value.cloneTo(this._localPosition);
  4911. this._setTransformFlag(Transform3D.TRANSFORM_LOCALMATRIX, true);
  4912. this._onWorldPositionTransform();
  4913. }
  4914. get localRotationX() {
  4915. return this.localRotation.x;
  4916. }
  4917. set localRotationX(x) {
  4918. this._localRotation.x = x;
  4919. this.localRotation = this._localRotation;
  4920. }
  4921. get localRotationY() {
  4922. return this.localRotation.y;
  4923. }
  4924. set localRotationY(y) {
  4925. this._localRotation.y = y;
  4926. this.localRotation = this._localRotation;
  4927. }
  4928. get localRotationZ() {
  4929. return this.localRotation.z;
  4930. }
  4931. set localRotationZ(z) {
  4932. this._localRotation.z = z;
  4933. this.localRotation = this._localRotation;
  4934. }
  4935. get localRotationW() {
  4936. return this.localRotation.w;
  4937. }
  4938. set localRotationW(w) {
  4939. this._localRotation.w = w;
  4940. this.localRotation = this._localRotation;
  4941. }
  4942. get localRotation() {
  4943. if (this._getTransformFlag(Transform3D.TRANSFORM_LOCALQUATERNION)) {
  4944. var eulerE = this._localRotationEuler;
  4945. Quaternion.createFromYawPitchRoll(eulerE.y / Transform3D._angleToRandin, eulerE.x / Transform3D._angleToRandin, eulerE.z / Transform3D._angleToRandin, this._localRotation);
  4946. this._setTransformFlag(Transform3D.TRANSFORM_LOCALQUATERNION, false);
  4947. }
  4948. return this._localRotation;
  4949. }
  4950. set localRotation(value) {
  4951. if (this._localRotation !== value)
  4952. value.cloneTo(this._localRotation);
  4953. this._localRotation.normalize(this._localRotation);
  4954. this._setTransformFlag(Transform3D.TRANSFORM_LOCALEULER | Transform3D.TRANSFORM_LOCALMATRIX, true);
  4955. this._setTransformFlag(Transform3D.TRANSFORM_LOCALQUATERNION, false);
  4956. this._onWorldRotationTransform();
  4957. }
  4958. get localScaleX() {
  4959. return this._localScale.x;
  4960. }
  4961. set localScaleX(value) {
  4962. this._localScale.x = value;
  4963. this.localScale = this._localScale;
  4964. }
  4965. get localScaleY() {
  4966. return this._localScale.y;
  4967. }
  4968. set localScaleY(value) {
  4969. this._localScale.y = value;
  4970. this.localScale = this._localScale;
  4971. }
  4972. get localScaleZ() {
  4973. return this._localScale.z;
  4974. }
  4975. set localScaleZ(value) {
  4976. this._localScale.z = value;
  4977. this.localScale = this._localScale;
  4978. }
  4979. get localScale() {
  4980. return this._localScale;
  4981. }
  4982. set localScale(value) {
  4983. if (this._localScale !== value)
  4984. value.cloneTo(this._localScale);
  4985. this._setTransformFlag(Transform3D.TRANSFORM_LOCALMATRIX, true);
  4986. this._onWorldScaleTransform();
  4987. }
  4988. get localRotationEulerX() {
  4989. return this.localRotationEuler.x;
  4990. }
  4991. set localRotationEulerX(value) {
  4992. this._localRotationEuler.x = value;
  4993. this.localRotationEuler = this._localRotationEuler;
  4994. }
  4995. get localRotationEulerY() {
  4996. return this.localRotationEuler.y;
  4997. }
  4998. set localRotationEulerY(value) {
  4999. this._localRotationEuler.y = value;
  5000. this.localRotationEuler = this._localRotationEuler;
  5001. }
  5002. get localRotationEulerZ() {
  5003. return this.localRotationEuler.z;
  5004. }
  5005. set localRotationEulerZ(value) {
  5006. this._localRotationEuler.z = value;
  5007. this.localRotationEuler = this._localRotationEuler;
  5008. }
  5009. get localRotationEuler() {
  5010. if (this._getTransformFlag(Transform3D.TRANSFORM_LOCALEULER)) {
  5011. this._localRotation.getYawPitchRoll(Transform3D._tempVector30);
  5012. var euler = Transform3D._tempVector30;
  5013. var localRotationEuler = this._localRotationEuler;
  5014. localRotationEuler.x = euler.y * Transform3D._angleToRandin;
  5015. localRotationEuler.y = euler.x * Transform3D._angleToRandin;
  5016. localRotationEuler.z = euler.z * Transform3D._angleToRandin;
  5017. this._setTransformFlag(Transform3D.TRANSFORM_LOCALEULER, false);
  5018. }
  5019. return this._localRotationEuler;
  5020. }
  5021. set localRotationEuler(value) {
  5022. if (this._localRotationEuler !== value)
  5023. value.cloneTo(this._localRotationEuler);
  5024. this._setTransformFlag(Transform3D.TRANSFORM_LOCALEULER, false);
  5025. this._setTransformFlag(Transform3D.TRANSFORM_LOCALQUATERNION | Transform3D.TRANSFORM_LOCALMATRIX, true);
  5026. this._onWorldRotationTransform();
  5027. }
  5028. get localMatrix() {
  5029. if (this._getTransformFlag(Transform3D.TRANSFORM_LOCALMATRIX)) {
  5030. Matrix4x4.createAffineTransformation(this._localPosition, this.localRotation, this._localScale, this._localMatrix);
  5031. this._setTransformFlag(Transform3D.TRANSFORM_LOCALMATRIX, false);
  5032. }
  5033. return this._localMatrix;
  5034. }
  5035. set localMatrix(value) {
  5036. if (this._localMatrix !== value)
  5037. value.cloneTo(this._localMatrix);
  5038. this._localMatrix.decomposeTransRotScale(this._localPosition, this._localRotation, this._localScale);
  5039. this._setTransformFlag(Transform3D.TRANSFORM_LOCALEULER, true);
  5040. this._setTransformFlag(Transform3D.TRANSFORM_LOCALMATRIX, false);
  5041. this._onWorldTransform();
  5042. }
  5043. get position() {
  5044. if (this._getTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION)) {
  5045. if (this._parent != null) {
  5046. var worldMatE = this.worldMatrix.elements;
  5047. this._position.x = worldMatE[12];
  5048. this._position.y = worldMatE[13];
  5049. this._position.z = worldMatE[14];
  5050. }
  5051. else {
  5052. this._localPosition.cloneTo(this._position);
  5053. }
  5054. this._setTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION, false);
  5055. }
  5056. return this._position;
  5057. }
  5058. set position(value) {
  5059. if (this._parent != null) {
  5060. var parentInvMat = Transform3D._tempMatrix0;
  5061. this._parent.worldMatrix.invert(parentInvMat);
  5062. Vector3.transformCoordinate(value, parentInvMat, this._localPosition);
  5063. }
  5064. else {
  5065. value.cloneTo(this._localPosition);
  5066. }
  5067. this.localPosition = this._localPosition;
  5068. if (this._position !== value)
  5069. value.cloneTo(this._position);
  5070. this._setTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION, false);
  5071. }
  5072. get rotation() {
  5073. if (this._getTransformFlag(Transform3D.TRANSFORM_WORLDQUATERNION)) {
  5074. if (this._parent != null)
  5075. Quaternion.multiply(this._parent.rotation, this.localRotation, this._rotation);
  5076. else
  5077. this.localRotation.cloneTo(this._rotation);
  5078. this._setTransformFlag(Transform3D.TRANSFORM_WORLDQUATERNION, false);
  5079. }
  5080. return this._rotation;
  5081. }
  5082. set rotation(value) {
  5083. if (this._parent != null) {
  5084. this._parent.rotation.invert(Transform3D._tempQuaternion0);
  5085. Quaternion.multiply(Transform3D._tempQuaternion0, value, this._localRotation);
  5086. }
  5087. else {
  5088. value.cloneTo(this._localRotation);
  5089. }
  5090. this.localRotation = this._localRotation;
  5091. if (value !== this._rotation)
  5092. value.cloneTo(this._rotation);
  5093. this._setTransformFlag(Transform3D.TRANSFORM_WORLDQUATERNION, false);
  5094. }
  5095. get rotationEuler() {
  5096. if (this._getTransformFlag(Transform3D.TRANSFORM_WORLDEULER)) {
  5097. this.rotation.getYawPitchRoll(Transform3D._tempVector30);
  5098. var eulerE = Transform3D._tempVector30;
  5099. var rotationEulerE = this._rotationEuler;
  5100. rotationEulerE.x = eulerE.y * Transform3D._angleToRandin;
  5101. rotationEulerE.y = eulerE.x * Transform3D._angleToRandin;
  5102. rotationEulerE.z = eulerE.z * Transform3D._angleToRandin;
  5103. this._setTransformFlag(Transform3D.TRANSFORM_WORLDEULER, false);
  5104. }
  5105. return this._rotationEuler;
  5106. }
  5107. set rotationEuler(value) {
  5108. Quaternion.createFromYawPitchRoll(value.y / Transform3D._angleToRandin, value.x / Transform3D._angleToRandin, value.z / Transform3D._angleToRandin, this._rotation);
  5109. this.rotation = this._rotation;
  5110. if (this._rotationEuler !== value)
  5111. value.cloneTo(this._rotationEuler);
  5112. this._setTransformFlag(Transform3D.TRANSFORM_WORLDEULER, false);
  5113. }
  5114. get worldMatrix() {
  5115. if (this._getTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX)) {
  5116. if (this._parent != null)
  5117. Matrix4x4.multiply(this._parent.worldMatrix, this.localMatrix, this._worldMatrix);
  5118. else
  5119. this.localMatrix.cloneTo(this._worldMatrix);
  5120. this._setTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX, false);
  5121. }
  5122. return this._worldMatrix;
  5123. }
  5124. set worldMatrix(value) {
  5125. if (this._parent === null) {
  5126. value.cloneTo(this._localMatrix);
  5127. }
  5128. else {
  5129. this._parent.worldMatrix.invert(this._localMatrix);
  5130. Matrix4x4.multiply(this._localMatrix, value, this._localMatrix);
  5131. }
  5132. this.localMatrix = this._localMatrix;
  5133. if (this._worldMatrix !== value)
  5134. value.cloneTo(this._worldMatrix);
  5135. this._setTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX, false);
  5136. }
  5137. _getScaleMatrix() {
  5138. var invRotation = Transform3D._tempQuaternion0;
  5139. var invRotationMat = Transform3D._tempMatrix3x30;
  5140. var worldRotScaMat = Transform3D._tempMatrix3x31;
  5141. var scaMat = Transform3D._tempMatrix3x32;
  5142. Matrix3x3.createFromMatrix4x4(this.worldMatrix, worldRotScaMat);
  5143. this.rotation.invert(invRotation);
  5144. Matrix3x3.createRotationQuaternion(invRotation, invRotationMat);
  5145. Matrix3x3.multiply(invRotationMat, worldRotScaMat, scaMat);
  5146. return scaMat;
  5147. }
  5148. _setTransformFlag(type, value) {
  5149. if (value)
  5150. this._transformFlag |= type;
  5151. else
  5152. this._transformFlag &= ~type;
  5153. }
  5154. _getTransformFlag(type) {
  5155. return (this._transformFlag & type) != 0;
  5156. }
  5157. _setParent(value) {
  5158. if (this._parent !== value) {
  5159. if (this._parent) {
  5160. var parentChilds = this._parent._children;
  5161. var index = parentChilds.indexOf(this);
  5162. parentChilds.splice(index, 1);
  5163. }
  5164. if (value) {
  5165. value._children.push(this);
  5166. (value) && (this._onWorldTransform());
  5167. }
  5168. this._parent = value;
  5169. }
  5170. }
  5171. _onWorldPositionRotationTransform() {
  5172. if (!this._getTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDQUATERNION) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDEULER)) {
  5173. this._setTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX | Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDEULER, true);
  5174. this.event(Laya.Event.TRANSFORM_CHANGED, this._transformFlag);
  5175. for (var i = 0, n = this._children.length; i < n; i++)
  5176. this._children[i]._onWorldPositionRotationTransform();
  5177. }
  5178. }
  5179. _onWorldPositionScaleTransform() {
  5180. if (!this._getTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDSCALE)) {
  5181. this._setTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX | Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDSCALE, true);
  5182. this.event(Laya.Event.TRANSFORM_CHANGED, this._transformFlag);
  5183. for (var i = 0, n = this._children.length; i < n; i++)
  5184. this._children[i]._onWorldPositionScaleTransform();
  5185. }
  5186. }
  5187. _onWorldPositionTransform() {
  5188. if (!this._getTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION)) {
  5189. this._setTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX | Transform3D.TRANSFORM_WORLDPOSITION, true);
  5190. this.event(Laya.Event.TRANSFORM_CHANGED, this._transformFlag);
  5191. for (var i = 0, n = this._children.length; i < n; i++)
  5192. this._children[i]._onWorldPositionTransform();
  5193. }
  5194. }
  5195. _onWorldRotationTransform() {
  5196. if (!this._getTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDQUATERNION) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDEULER)) {
  5197. this._setTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDEULER, true);
  5198. this.event(Laya.Event.TRANSFORM_CHANGED, this._transformFlag);
  5199. for (var i = 0, n = this._children.length; i < n; i++)
  5200. this._children[i]._onWorldPositionRotationTransform();
  5201. }
  5202. }
  5203. _onWorldScaleTransform() {
  5204. if (!this._getTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDSCALE)) {
  5205. this._setTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX | Transform3D.TRANSFORM_WORLDSCALE, true);
  5206. this.event(Laya.Event.TRANSFORM_CHANGED, this._transformFlag);
  5207. for (var i = 0, n = this._children.length; i < n; i++)
  5208. this._children[i]._onWorldPositionScaleTransform();
  5209. }
  5210. }
  5211. _onWorldTransform() {
  5212. if (!this._getTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDQUATERNION) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDEULER) || !this._getTransformFlag(Transform3D.TRANSFORM_WORLDSCALE)) {
  5213. this._setTransformFlag(Transform3D.TRANSFORM_WORLDMATRIX | Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDEULER | Transform3D.TRANSFORM_WORLDSCALE, true);
  5214. this.event(Laya.Event.TRANSFORM_CHANGED, this._transformFlag);
  5215. for (var i = 0, n = this._children.length; i < n; i++)
  5216. this._children[i]._onWorldTransform();
  5217. }
  5218. }
  5219. translate(translation, isLocal = true) {
  5220. if (isLocal) {
  5221. Matrix4x4.createFromQuaternion(this.localRotation, Transform3D._tempMatrix0);
  5222. Vector3.transformCoordinate(translation, Transform3D._tempMatrix0, Transform3D._tempVector30);
  5223. Vector3.add(this.localPosition, Transform3D._tempVector30, this._localPosition);
  5224. this.localPosition = this._localPosition;
  5225. }
  5226. else {
  5227. Vector3.add(this.position, translation, this._position);
  5228. this.position = this._position;
  5229. }
  5230. }
  5231. rotate(rotation, isLocal = true, isRadian = true) {
  5232. var rot;
  5233. if (isRadian) {
  5234. rot = rotation;
  5235. }
  5236. else {
  5237. Vector3.scale(rotation, Math.PI / 180.0, Transform3D._tempVector30);
  5238. rot = Transform3D._tempVector30;
  5239. }
  5240. Quaternion.createFromYawPitchRoll(rot.y, rot.x, rot.z, Transform3D._tempQuaternion0);
  5241. if (isLocal) {
  5242. Quaternion.multiply(this._localRotation, Transform3D._tempQuaternion0, this._localRotation);
  5243. this.localRotation = this._localRotation;
  5244. }
  5245. else {
  5246. Quaternion.multiply(Transform3D._tempQuaternion0, this.rotation, this._rotation);
  5247. this.rotation = this._rotation;
  5248. }
  5249. }
  5250. getForward(forward) {
  5251. var worldMatElem = this.worldMatrix.elements;
  5252. forward.x = -worldMatElem[8];
  5253. forward.y = -worldMatElem[9];
  5254. forward.z = -worldMatElem[10];
  5255. }
  5256. getUp(up) {
  5257. var worldMatElem = this.worldMatrix.elements;
  5258. up.x = worldMatElem[4];
  5259. up.y = worldMatElem[5];
  5260. up.z = worldMatElem[6];
  5261. }
  5262. getRight(right) {
  5263. var worldMatElem = this.worldMatrix.elements;
  5264. right.x = worldMatElem[0];
  5265. right.y = worldMatElem[1];
  5266. right.z = worldMatElem[2];
  5267. }
  5268. lookAt(target, up, isLocal = false) {
  5269. var eye;
  5270. if (isLocal) {
  5271. eye = this._localPosition;
  5272. if (Math.abs(eye.x - target.x) < MathUtils3D.zeroTolerance && Math.abs(eye.y - target.y) < MathUtils3D.zeroTolerance && Math.abs(eye.z - target.z) < MathUtils3D.zeroTolerance)
  5273. return;
  5274. Quaternion.lookAt(this._localPosition, target, up, this._localRotation);
  5275. this._localRotation.invert(this._localRotation);
  5276. this.localRotation = this._localRotation;
  5277. }
  5278. else {
  5279. var worldPosition = this.position;
  5280. eye = worldPosition;
  5281. if (Math.abs(eye.x - target.x) < MathUtils3D.zeroTolerance && Math.abs(eye.y - target.y) < MathUtils3D.zeroTolerance && Math.abs(eye.z - target.z) < MathUtils3D.zeroTolerance)
  5282. return;
  5283. Quaternion.lookAt(worldPosition, target, up, this._rotation);
  5284. this._rotation.invert(this._rotation);
  5285. this.rotation = this._rotation;
  5286. }
  5287. }
  5288. getWorldLossyScale() {
  5289. if (this._getTransformFlag(Transform3D.TRANSFORM_WORLDSCALE)) {
  5290. if (this._parent !== null) {
  5291. var scaMatE = this._getScaleMatrix().elements;
  5292. this._scale.x = scaMatE[0];
  5293. this._scale.y = scaMatE[4];
  5294. this._scale.z = scaMatE[8];
  5295. }
  5296. else {
  5297. this._localScale.cloneTo(this._scale);
  5298. }
  5299. this._setTransformFlag(Transform3D.TRANSFORM_WORLDSCALE, false);
  5300. }
  5301. return this._scale;
  5302. }
  5303. setWorldLossyScale(value) {
  5304. if (this._parent !== null) {
  5305. var scaleMat = Transform3D._tempMatrix3x33;
  5306. var localScaleMat = Transform3D._tempMatrix3x33;
  5307. var localScaleMatE = localScaleMat.elements;
  5308. var parInvScaleMat = this._parent._getScaleMatrix();
  5309. parInvScaleMat.invert(parInvScaleMat);
  5310. Matrix3x3.createFromScaling(value, scaleMat);
  5311. Matrix3x3.multiply(parInvScaleMat, scaleMat, localScaleMat);
  5312. this._localScale.x = localScaleMatE[0];
  5313. this._localScale.y = localScaleMatE[4];
  5314. this._localScale.z = localScaleMatE[8];
  5315. }
  5316. else {
  5317. value.cloneTo(this._localScale);
  5318. }
  5319. this.localScale = this._localScale;
  5320. if (this._scale !== value)
  5321. value.cloneTo(this._scale);
  5322. this._setTransformFlag(Transform3D.TRANSFORM_WORLDSCALE, false);
  5323. }
  5324. get scale() {
  5325. console.warn("Transfrm3D: discard function,please use getWorldLossyScale instead.");
  5326. return this.getWorldLossyScale();
  5327. }
  5328. set scale(value) {
  5329. console.warn("Transfrm3D: discard function,please use setWorldLossyScale instead.");
  5330. this.setWorldLossyScale(value);
  5331. }
  5332. }
  5333. Transform3D._tempVector30 = new Vector3();
  5334. Transform3D._tempQuaternion0 = new Quaternion();
  5335. Transform3D._tempMatrix0 = new Matrix4x4();
  5336. Transform3D._tempMatrix3x30 = new Matrix3x3();
  5337. Transform3D._tempMatrix3x31 = new Matrix3x3();
  5338. Transform3D._tempMatrix3x32 = new Matrix3x3();
  5339. Transform3D._tempMatrix3x33 = new Matrix3x3();
  5340. Transform3D.TRANSFORM_LOCALQUATERNION = 0x01;
  5341. Transform3D.TRANSFORM_LOCALEULER = 0x02;
  5342. Transform3D.TRANSFORM_LOCALMATRIX = 0x04;
  5343. Transform3D.TRANSFORM_WORLDPOSITION = 0x08;
  5344. Transform3D.TRANSFORM_WORLDQUATERNION = 0x10;
  5345. Transform3D.TRANSFORM_WORLDSCALE = 0x20;
  5346. Transform3D.TRANSFORM_WORLDMATRIX = 0x40;
  5347. Transform3D.TRANSFORM_WORLDEULER = 0x80;
  5348. Transform3D._angleToRandin = 180 / Math.PI;
  5349. class Sprite3D extends Laya.Node {
  5350. constructor(name = null, isStatic = false) {
  5351. super();
  5352. this._needProcessCollisions = false;
  5353. this._needProcessTriggers = false;
  5354. this._id = ++Sprite3D._uniqueIDCounter;
  5355. this._transform = new Transform3D(this);
  5356. this._isStatic = isStatic;
  5357. this.layer = 0;
  5358. this.name = name ? name : "New Sprite3D";
  5359. }
  5360. static __init__() {
  5361. }
  5362. static instantiate(original, parent = null, worldPositionStays = true, position = null, rotation = null) {
  5363. var destSprite3D = original.clone();
  5364. (parent) && (parent.addChild(destSprite3D));
  5365. var transform = destSprite3D.transform;
  5366. if (worldPositionStays) {
  5367. var worldMatrix = transform.worldMatrix;
  5368. original.transform.worldMatrix.cloneTo(worldMatrix);
  5369. transform.worldMatrix = worldMatrix;
  5370. }
  5371. else {
  5372. (position) && (transform.position = position);
  5373. (rotation) && (transform.rotation = rotation);
  5374. }
  5375. return destSprite3D;
  5376. }
  5377. static load(url, complete) {
  5378. Laya.Laya.loader.create(url, complete, null, Sprite3D.HIERARCHY);
  5379. }
  5380. get id() {
  5381. return this._id;
  5382. }
  5383. get layer() {
  5384. return this._layer;
  5385. }
  5386. set layer(value) {
  5387. if (this._layer !== value) {
  5388. if (value >= 0 && value <= 30) {
  5389. this._layer = value;
  5390. }
  5391. else {
  5392. throw new Error("Layer value must be 0-30.");
  5393. }
  5394. }
  5395. }
  5396. get url() {
  5397. return this._url;
  5398. }
  5399. get isStatic() {
  5400. return this._isStatic;
  5401. }
  5402. get transform() {
  5403. return this._transform;
  5404. }
  5405. _setCreateURL(url) {
  5406. this._url = Laya.URL.formatURL(url);
  5407. }
  5408. _changeAnimatorsToLinkSprite3D(sprite3D, isLink, path) {
  5409. var animator = this.getComponent(Animator);
  5410. if (animator) {
  5411. if (!animator.avatar)
  5412. sprite3D._changeAnimatorToLinkSprite3DNoAvatar(animator, isLink, path);
  5413. }
  5414. if (this._parent && this._parent instanceof Sprite3D) {
  5415. path.unshift(this._parent.name);
  5416. var p = this._parent;
  5417. (p._hierarchyAnimator) && (p._changeAnimatorsToLinkSprite3D(sprite3D, isLink, path));
  5418. }
  5419. }
  5420. _setHierarchyAnimator(animator, parentAnimator) {
  5421. this._changeHierarchyAnimator(animator);
  5422. this._changeAnimatorAvatar(animator.avatar);
  5423. for (var i = 0, n = this._children.length; i < n; i++) {
  5424. var child = this._children[i];
  5425. (child._hierarchyAnimator == parentAnimator) && (child._setHierarchyAnimator(animator, parentAnimator));
  5426. }
  5427. }
  5428. _clearHierarchyAnimator(animator, parentAnimator) {
  5429. this._changeHierarchyAnimator(parentAnimator);
  5430. this._changeAnimatorAvatar(parentAnimator ? parentAnimator.avatar : null);
  5431. for (var i = 0, n = this._children.length; i < n; i++) {
  5432. var child = this._children[i];
  5433. (child._hierarchyAnimator == animator) && (child._clearHierarchyAnimator(animator, parentAnimator));
  5434. }
  5435. }
  5436. _changeHierarchyAnimatorAvatar(animator, avatar) {
  5437. this._changeAnimatorAvatar(avatar);
  5438. for (var i = 0, n = this._children.length; i < n; i++) {
  5439. var child = this._children[i];
  5440. (child._hierarchyAnimator == animator) && (child._changeHierarchyAnimatorAvatar(animator, avatar));
  5441. }
  5442. }
  5443. _changeAnimatorToLinkSprite3DNoAvatar(animator, isLink, path) {
  5444. animator._handleSpriteOwnersBySprite(isLink, path, this);
  5445. for (var i = 0, n = this._children.length; i < n; i++) {
  5446. var child = this._children[i];
  5447. var index = path.length;
  5448. path.push(child.name);
  5449. child._changeAnimatorToLinkSprite3DNoAvatar(animator, isLink, path);
  5450. path.splice(index, 1);
  5451. }
  5452. }
  5453. _changeHierarchyAnimator(animator) {
  5454. this._hierarchyAnimator = animator;
  5455. }
  5456. _changeAnimatorAvatar(avatar) {
  5457. }
  5458. _onAdded() {
  5459. if (this._parent instanceof Sprite3D) {
  5460. var parent3D = this._parent;
  5461. this.transform._setParent(parent3D.transform);
  5462. if (parent3D._hierarchyAnimator) {
  5463. (!this._hierarchyAnimator) && (this._setHierarchyAnimator(parent3D._hierarchyAnimator, null));
  5464. parent3D._changeAnimatorsToLinkSprite3D(this, true, [this.name]);
  5465. }
  5466. }
  5467. super._onAdded();
  5468. }
  5469. _onRemoved() {
  5470. super._onRemoved();
  5471. if (this._parent instanceof Sprite3D) {
  5472. var parent3D = this._parent;
  5473. this.transform._setParent(null);
  5474. if (parent3D._hierarchyAnimator) {
  5475. (this._hierarchyAnimator == parent3D._hierarchyAnimator) && (this._clearHierarchyAnimator(parent3D._hierarchyAnimator, null));
  5476. parent3D._changeAnimatorsToLinkSprite3D(this, false, [this.name]);
  5477. }
  5478. }
  5479. }
  5480. _parse(data, spriteMap) {
  5481. (data.isStatic !== undefined) && (this._isStatic = data.isStatic);
  5482. (data.active !== undefined) && (this.active = data.active);
  5483. (data.name != undefined) && (this.name = data.name);
  5484. if (data.position !== undefined) {
  5485. var loccalPosition = this.transform.localPosition;
  5486. loccalPosition.fromArray(data.position);
  5487. this.transform.localPosition = loccalPosition;
  5488. }
  5489. if (data.rotationEuler !== undefined) {
  5490. var localRotationEuler = this.transform.localRotationEuler;
  5491. localRotationEuler.fromArray(data.rotationEuler);
  5492. this.transform.localRotationEuler = localRotationEuler;
  5493. }
  5494. if (data.rotation !== undefined) {
  5495. var localRotation = this.transform.localRotation;
  5496. localRotation.fromArray(data.rotation);
  5497. this.transform.localRotation = localRotation;
  5498. }
  5499. if (data.scale !== undefined) {
  5500. var localScale = this.transform.localScale;
  5501. localScale.fromArray(data.scale);
  5502. this.transform.localScale = localScale;
  5503. }
  5504. (data.layer != undefined) && (this.layer = data.layer);
  5505. }
  5506. _cloneTo(destObject, srcRoot, dstRoot) {
  5507. if (this.destroyed)
  5508. throw new Error("Sprite3D: Can't be cloned if the Sprite3D has destroyed.");
  5509. var destSprite3D = destObject;
  5510. destSprite3D.name = this.name;
  5511. destSprite3D.destroyed = this.destroyed;
  5512. destSprite3D.active = this.active;
  5513. var destLocalPosition = destSprite3D.transform.localPosition;
  5514. this.transform.localPosition.cloneTo(destLocalPosition);
  5515. destSprite3D.transform.localPosition = destLocalPosition;
  5516. var destLocalRotation = destSprite3D.transform.localRotation;
  5517. this.transform.localRotation.cloneTo(destLocalRotation);
  5518. destSprite3D.transform.localRotation = destLocalRotation;
  5519. var destLocalScale = destSprite3D.transform.localScale;
  5520. this.transform.localScale.cloneTo(destLocalScale);
  5521. destSprite3D.transform.localScale = destLocalScale;
  5522. destSprite3D._isStatic = this._isStatic;
  5523. destSprite3D.layer = this.layer;
  5524. super._cloneTo(destSprite3D, srcRoot, dstRoot);
  5525. }
  5526. static _createSprite3DInstance(scrSprite) {
  5527. var node = scrSprite._create();
  5528. var children = scrSprite._children;
  5529. for (var i = 0, n = children.length; i < n; i++) {
  5530. var child = Sprite3D._createSprite3DInstance(children[i]);
  5531. node.addChild(child);
  5532. }
  5533. return node;
  5534. }
  5535. static _parseSprite3DInstance(srcRoot, dstRoot, scrSprite, dstSprite) {
  5536. var srcChildren = scrSprite._children;
  5537. var dstChildren = dstSprite._children;
  5538. for (var i = 0, n = srcChildren.length; i < n; i++)
  5539. Sprite3D._parseSprite3DInstance(srcRoot, dstRoot, srcChildren[i], dstChildren[i]);
  5540. scrSprite._cloneTo(dstSprite, srcRoot, dstRoot);
  5541. }
  5542. clone() {
  5543. var dstSprite3D = Sprite3D._createSprite3DInstance(this);
  5544. Sprite3D._parseSprite3DInstance(this, dstSprite3D, this, dstSprite3D);
  5545. return dstSprite3D;
  5546. }
  5547. destroy(destroyChild = true) {
  5548. if (this.destroyed)
  5549. return;
  5550. super.destroy(destroyChild);
  5551. this._transform = null;
  5552. this._scripts = null;
  5553. this._url && Laya.Loader.clearRes(this._url);
  5554. }
  5555. _create() {
  5556. return new Sprite3D();
  5557. }
  5558. }
  5559. Sprite3D.HIERARCHY = "HIERARCHY";
  5560. Sprite3D.WORLDMATRIX = Shader3D.propertyNameToID("u_WorldMat");
  5561. Sprite3D.MVPMATRIX = Shader3D.propertyNameToID("u_MvpMatrix");
  5562. Sprite3D._uniqueIDCounter = 0;
  5563. class RenderableSprite3D extends Sprite3D {
  5564. constructor(name) {
  5565. super(name);
  5566. }
  5567. static __init__() {
  5568. RenderableSprite3D.SHADERDEFINE_RECEIVE_SHADOW = RenderableSprite3D.shaderDefines.registerDefine("RECEIVESHADOW");
  5569. RenderableSprite3D.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV = RenderableSprite3D.shaderDefines.registerDefine("SCALEOFFSETLIGHTINGMAPUV");
  5570. RenderableSprite3D.SAHDERDEFINE_LIGHTMAP = RenderableSprite3D.shaderDefines.registerDefine("LIGHTMAP");
  5571. }
  5572. _onInActive() {
  5573. super._onInActive();
  5574. var scene3D = this._scene;
  5575. scene3D._removeRenderObject(this._render);
  5576. (this._render.castShadow) && (scene3D._removeShadowCastRenderObject(this._render));
  5577. }
  5578. _onActive() {
  5579. super._onActive();
  5580. var scene3D = this._scene;
  5581. scene3D._addRenderObject(this._render);
  5582. (this._render.castShadow) && (scene3D._addShadowCastRenderObject(this._render));
  5583. }
  5584. _onActiveInScene() {
  5585. super._onActiveInScene();
  5586. if (ILaya3D.Laya3D._editerEnvironment) {
  5587. var scene = this._scene;
  5588. var pickColor = new Vector4();
  5589. scene._allotPickColorByID(this.id, pickColor);
  5590. scene._pickIdToSprite[this.id] = this;
  5591. this._render._shaderValues.setVector(RenderableSprite3D.PICKCOLOR, pickColor);
  5592. }
  5593. }
  5594. _addToInitStaticBatchManager() {
  5595. }
  5596. _setBelongScene(scene) {
  5597. super._setBelongScene(scene);
  5598. this._render._setBelongScene(scene);
  5599. }
  5600. _setUnBelongScene() {
  5601. this._render._shaderValues.removeDefine(RenderableSprite3D.SAHDERDEFINE_LIGHTMAP);
  5602. super._setUnBelongScene();
  5603. }
  5604. _changeHierarchyAnimator(animator) {
  5605. if (this._hierarchyAnimator) {
  5606. var renderableSprites = this._hierarchyAnimator._renderableSprites;
  5607. renderableSprites.splice(renderableSprites.indexOf(this), 1);
  5608. }
  5609. if (animator)
  5610. animator._renderableSprites.push(this);
  5611. super._changeHierarchyAnimator(animator);
  5612. }
  5613. destroy(destroyChild = true) {
  5614. super.destroy(destroyChild);
  5615. this._render._destroy();
  5616. this._render = null;
  5617. }
  5618. _create() {
  5619. return new RenderableSprite3D(this.name);
  5620. }
  5621. }
  5622. RenderableSprite3D.LIGHTMAPSCALEOFFSET = Shader3D.propertyNameToID("u_LightmapScaleOffset");
  5623. RenderableSprite3D.LIGHTMAP = Shader3D.propertyNameToID("u_LightMap");
  5624. RenderableSprite3D.PICKCOLOR = Shader3D.propertyNameToID("u_PickColor");
  5625. RenderableSprite3D.shaderDefines = new ShaderDefines();
  5626. class StaticBatchManager {
  5627. constructor() {
  5628. this._initBatchSprites = [];
  5629. this._staticBatches = {};
  5630. this._batchRenderElementPoolIndex = 0;
  5631. this._batchRenderElementPool = [];
  5632. }
  5633. static _registerManager(manager) {
  5634. StaticBatchManager._managers.push(manager);
  5635. }
  5636. static _addToStaticBatchQueue(sprite3D, renderableSprite3D) {
  5637. if (sprite3D instanceof RenderableSprite3D && sprite3D.isStatic)
  5638. renderableSprite3D.push(sprite3D);
  5639. for (var i = 0, n = sprite3D.numChildren; i < n; i++)
  5640. StaticBatchManager._addToStaticBatchQueue(sprite3D._children[i], renderableSprite3D);
  5641. }
  5642. static combine(staticBatchRoot, renderableSprite3Ds = null) {
  5643. if (!renderableSprite3Ds) {
  5644. renderableSprite3Ds = [];
  5645. if (staticBatchRoot)
  5646. StaticBatchManager._addToStaticBatchQueue(staticBatchRoot, renderableSprite3Ds);
  5647. }
  5648. var batchSpritesCount = renderableSprite3Ds.length;
  5649. if (batchSpritesCount > 0) {
  5650. for (var i = 0; i < batchSpritesCount; i++) {
  5651. var renderableSprite3D = renderableSprite3Ds[i];
  5652. (renderableSprite3D.isStatic) && (renderableSprite3D._addToInitStaticBatchManager());
  5653. }
  5654. for (var k = 0, m = StaticBatchManager._managers.length; k < m; k++) {
  5655. var manager = StaticBatchManager._managers[k];
  5656. manager._initStaticBatchs(staticBatchRoot);
  5657. }
  5658. }
  5659. }
  5660. _partition(items, left, right) {
  5661. var pivot = items[Math.floor((right + left) / 2)];
  5662. while (left <= right) {
  5663. while (this._compare(items[left], pivot) < 0)
  5664. left++;
  5665. while (this._compare(items[right], pivot) > 0)
  5666. right--;
  5667. if (left < right) {
  5668. var temp = items[left];
  5669. items[left] = items[right];
  5670. items[right] = temp;
  5671. left++;
  5672. right--;
  5673. }
  5674. else if (left === right) {
  5675. left++;
  5676. break;
  5677. }
  5678. }
  5679. return left;
  5680. }
  5681. _quickSort(items, left, right) {
  5682. if (items.length > 1) {
  5683. var index = this._partition(items, left, right);
  5684. var leftIndex = index - 1;
  5685. if (left < leftIndex)
  5686. this._quickSort(items, left, leftIndex);
  5687. if (index < right)
  5688. this._quickSort(items, index, right);
  5689. }
  5690. }
  5691. _compare(left, right) {
  5692. throw "StaticBatch:must override this function.";
  5693. }
  5694. _initStaticBatchs(rootSprite) {
  5695. throw "StaticBatch:must override this function.";
  5696. }
  5697. _getBatchRenderElementFromPool() {
  5698. throw "StaticBatch:must override this function.";
  5699. }
  5700. _addBatchSprite(renderableSprite3D) {
  5701. this._initBatchSprites.push(renderableSprite3D);
  5702. }
  5703. _clear() {
  5704. this._batchRenderElementPoolIndex = 0;
  5705. }
  5706. _garbageCollection() {
  5707. throw "StaticBatchManager: must override it.";
  5708. }
  5709. dispose() {
  5710. this._staticBatches = null;
  5711. }
  5712. }
  5713. StaticBatchManager._managers = [];
  5714. class FrustumCulling {
  5715. constructor() {
  5716. }
  5717. static __init__() {
  5718. if (Laya.Render.supportWebGLPlusCulling) {
  5719. FrustumCulling._cullingBufferLength = 0;
  5720. FrustumCulling._cullingBuffer = new Float32Array(4096);
  5721. }
  5722. }
  5723. static _drawTraversalCullingBound(renderList, debugTool) {
  5724. var validCount = renderList.length;
  5725. var renders = renderList.elements;
  5726. for (var i = 0, n = renderList.length; i < n; i++) {
  5727. var color = FrustumCulling._tempColor0;
  5728. color.r = 0;
  5729. color.g = 1;
  5730. color.b = 0;
  5731. color.a = 1;
  5732. Utils3D._drawBound(debugTool, renders[i].bounds._getBoundBox(), color);
  5733. }
  5734. }
  5735. static _traversalCulling(camera, scene, context, renderList, customShader, replacementTag) {
  5736. var validCount = renderList.length;
  5737. var renders = renderList.elements;
  5738. var boundFrustum = camera.boundFrustum;
  5739. var camPos = camera._transform.position;
  5740. for (var i = 0; i < validCount; i++) {
  5741. var render = renders[i];
  5742. if (camera._isLayerVisible(render._owner._layer) && render._enable) {
  5743. Laya.Stat.frustumCulling++;
  5744. if (!camera.useOcclusionCulling || render._needRender(boundFrustum, context)) {
  5745. render._visible = true;
  5746. render._distanceForSort = Vector3.distance(render.bounds.getCenter(), camPos);
  5747. var elements = render._renderElements;
  5748. for (var j = 0, m = elements.length; j < m; j++)
  5749. elements[j]._update(scene, context, customShader, replacementTag);
  5750. }
  5751. else {
  5752. render._visible = false;
  5753. }
  5754. }
  5755. else {
  5756. render._visible = false;
  5757. }
  5758. }
  5759. }
  5760. static renderObjectCulling(camera, scene, context, renderList, customShader, replacementTag) {
  5761. var i, n;
  5762. var opaqueQueue = scene._opaqueQueue;
  5763. var transparentQueue = scene._transparentQueue;
  5764. opaqueQueue.clear();
  5765. transparentQueue.clear();
  5766. var staticBatchManagers = StaticBatchManager._managers;
  5767. for (i = 0, n = staticBatchManagers.length; i < n; i++)
  5768. staticBatchManagers[i]._clear();
  5769. var dynamicBatchManagers = DynamicBatchManager._managers;
  5770. for (i = 0, n = dynamicBatchManagers.length; i < n; i++)
  5771. dynamicBatchManagers[i]._clear();
  5772. var octree = scene._octree;
  5773. if (octree) {
  5774. octree.updateMotionObjects();
  5775. octree.shrinkRootIfPossible();
  5776. octree.getCollidingWithFrustum(context, customShader, replacementTag);
  5777. }
  5778. FrustumCulling._traversalCulling(camera, scene, context, renderList, customShader, replacementTag);
  5779. if (FrustumCulling.debugFrustumCulling) {
  5780. var debugTool = scene._debugTool;
  5781. debugTool.clear();
  5782. if (octree) {
  5783. octree.drawAllBounds(debugTool);
  5784. octree.drawAllObjects(debugTool);
  5785. }
  5786. FrustumCulling._drawTraversalCullingBound(renderList, debugTool);
  5787. }
  5788. var count = opaqueQueue.elements.length;
  5789. (count > 0) && (opaqueQueue._quickSort(0, count - 1));
  5790. count = transparentQueue.elements.length;
  5791. (count > 0) && (transparentQueue._quickSort(0, count - 1));
  5792. }
  5793. static renderObjectCullingNative(camera, scene, context, renderList, customShader, replacementTag) {
  5794. var i, n, j, m;
  5795. var opaqueQueue = scene._opaqueQueue;
  5796. var transparentQueue = scene._transparentQueue;
  5797. opaqueQueue.clear();
  5798. transparentQueue.clear();
  5799. var staticBatchManagers = StaticBatchManager._managers;
  5800. for (i = 0, n = staticBatchManagers.length; i < n; i++)
  5801. staticBatchManagers[i]._clear();
  5802. var dynamicBatchManagers = DynamicBatchManager._managers;
  5803. for (i = 0, n = dynamicBatchManagers.length; i < n; i++)
  5804. dynamicBatchManagers[i]._clear();
  5805. var validCount = renderList.length;
  5806. var renders = renderList.elements;
  5807. for (i = 0; i < validCount; i++) {
  5808. renders[i].bounds;
  5809. renders[i]._updateForNative && renders[i]._updateForNative(context);
  5810. }
  5811. var boundFrustum = camera.boundFrustum;
  5812. FrustumCulling.cullingNative(camera._boundFrustumBuffer, FrustumCulling._cullingBuffer, scene._cullingBufferIndices, validCount, scene._cullingBufferResult);
  5813. var camPos = context.camera._transform.position;
  5814. for (var i = 0; i < validCount; i++) {
  5815. var render = renders[i];
  5816. if (camera._isLayerVisible(render._owner._layer) && render._enable) {
  5817. Laya.Stat.frustumCulling++;
  5818. if (!camera.useOcclusionCulling || scene._cullingBufferResult[i]) {
  5819. render._visible = true;
  5820. render._distanceForSort = Vector3.distance(render.bounds.getCenter(), camPos);
  5821. var elements = render._renderElements;
  5822. for (var j = 0, m = elements.length; j < m; j++)
  5823. elements[j]._update(scene, context, customShader, replacementTag);
  5824. }
  5825. else {
  5826. render._visible = false;
  5827. }
  5828. }
  5829. else {
  5830. render._visible = false;
  5831. }
  5832. }
  5833. var count = opaqueQueue.elements.length;
  5834. (count > 0) && (opaqueQueue._quickSort(0, count - 1));
  5835. count = transparentQueue.elements.length;
  5836. (count > 0) && (transparentQueue._quickSort(0, count - 1));
  5837. }
  5838. static cullingNative(boundFrustumBuffer, cullingBuffer, cullingBufferIndices, cullingCount, cullingBufferResult) {
  5839. return Laya.LayaGL.instance.culling(boundFrustumBuffer, cullingBuffer, cullingBufferIndices, cullingCount, cullingBufferResult);
  5840. }
  5841. }
  5842. FrustumCulling._tempVector3 = new Vector3();
  5843. FrustumCulling._tempColor0 = new Color();
  5844. FrustumCulling.debugFrustumCulling = false;
  5845. class Plane {
  5846. constructor(normal, d = 0) {
  5847. this.normal = normal;
  5848. this.distance = d;
  5849. }
  5850. static createPlaneBy3P(point1, point2, point3) {
  5851. var x1 = point2.x - point1.x;
  5852. var y1 = point2.y - point1.y;
  5853. var z1 = point2.z - point1.z;
  5854. var x2 = point3.x - point1.x;
  5855. var y2 = point3.y - point1.y;
  5856. var z2 = point3.z - point1.z;
  5857. var yz = (y1 * z2) - (z1 * y2);
  5858. var xz = (z1 * x2) - (x1 * z2);
  5859. var xy = (x1 * y2) - (y1 * x2);
  5860. var invPyth = 1 / (Math.sqrt((yz * yz) + (xz * xz) + (xy * xy)));
  5861. var x = yz * invPyth;
  5862. var y = xz * invPyth;
  5863. var z = xy * invPyth;
  5864. Plane._TEMPVec3.x = x;
  5865. Plane._TEMPVec3.y = y;
  5866. Plane._TEMPVec3.z = z;
  5867. var d = -((x * point1.x) + (y * point1.y) + (z * point1.z));
  5868. var plane = new Plane(Plane._TEMPVec3, d);
  5869. return plane;
  5870. }
  5871. normalize() {
  5872. var normalEX = this.normal.x;
  5873. var normalEY = this.normal.y;
  5874. var normalEZ = this.normal.z;
  5875. var magnitude = 1 / Math.sqrt(normalEX * normalEX + normalEY * normalEY + normalEZ * normalEZ);
  5876. this.normal.x = normalEX * magnitude;
  5877. this.normal.y = normalEY * magnitude;
  5878. this.normal.z = normalEZ * magnitude;
  5879. this.distance *= magnitude;
  5880. }
  5881. }
  5882. Plane._TEMPVec3 = new Vector3();
  5883. Plane.PlaneIntersectionType_Back = 0;
  5884. Plane.PlaneIntersectionType_Front = 1;
  5885. Plane.PlaneIntersectionType_Intersecting = 2;
  5886. class Ray {
  5887. constructor(origin, direction) {
  5888. this.origin = origin;
  5889. this.direction = direction;
  5890. }
  5891. }
  5892. class ContainmentType {
  5893. }
  5894. ContainmentType.Disjoint = 0;
  5895. ContainmentType.Contains = 1;
  5896. ContainmentType.Intersects = 2;
  5897. class CollisionUtils {
  5898. constructor() {
  5899. }
  5900. static distancePlaneToPoint(plane, point) {
  5901. var dot = Vector3.dot(plane.normal, point);
  5902. return dot - plane.distance;
  5903. }
  5904. static distanceBoxToPoint(box, point) {
  5905. var boxMin = box.min;
  5906. var boxMineX = boxMin.x;
  5907. var boxMineY = boxMin.y;
  5908. var boxMineZ = boxMin.z;
  5909. var boxMax = box.max;
  5910. var boxMaxeX = boxMax.x;
  5911. var boxMaxeY = boxMax.y;
  5912. var boxMaxeZ = boxMax.z;
  5913. var pointeX = point.x;
  5914. var pointeY = point.y;
  5915. var pointeZ = point.z;
  5916. var distance = 0;
  5917. if (pointeX < boxMineX)
  5918. distance += (boxMineX - pointeX) * (boxMineX - pointeX);
  5919. if (pointeX > boxMaxeX)
  5920. distance += (boxMaxeX - pointeX) * (boxMaxeX - pointeX);
  5921. if (pointeY < boxMineY)
  5922. distance += (boxMineY - pointeY) * (boxMineY - pointeY);
  5923. if (pointeY > boxMaxeY)
  5924. distance += (boxMaxeY - pointeY) * (boxMaxeY - pointeY);
  5925. if (pointeZ < boxMineZ)
  5926. distance += (boxMineZ - pointeZ) * (boxMineZ - pointeZ);
  5927. if (pointeZ > boxMaxeZ)
  5928. distance += (boxMaxeZ - pointeZ) * (boxMaxeZ - pointeZ);
  5929. return Math.sqrt(distance);
  5930. }
  5931. static distanceBoxToBox(box1, box2) {
  5932. var box1Mine = box1.min;
  5933. var box1MineX = box1Mine.x;
  5934. var box1MineY = box1Mine.y;
  5935. var box1MineZ = box1Mine.z;
  5936. var box1Maxe = box1.max;
  5937. var box1MaxeX = box1Maxe.x;
  5938. var box1MaxeY = box1Maxe.y;
  5939. var box1MaxeZ = box1Maxe.z;
  5940. var box2Mine = box2.min;
  5941. var box2MineX = box2Mine.x;
  5942. var box2MineY = box2Mine.y;
  5943. var box2MineZ = box2Mine.z;
  5944. var box2Maxe = box2.max;
  5945. var box2MaxeX = box2Maxe.x;
  5946. var box2MaxeY = box2Maxe.y;
  5947. var box2MaxeZ = box2Maxe.z;
  5948. var distance = 0;
  5949. var delta;
  5950. if (box1MineX > box2MaxeX) {
  5951. delta = box1MineX - box2MaxeX;
  5952. distance += delta * delta;
  5953. }
  5954. else if (box2MineX > box1MaxeX) {
  5955. delta = box2MineX - box1MaxeX;
  5956. distance += delta * delta;
  5957. }
  5958. if (box1MineY > box2MaxeY) {
  5959. delta = box1MineY - box2MaxeY;
  5960. distance += delta * delta;
  5961. }
  5962. else if (box2MineY > box1MaxeY) {
  5963. delta = box2MineY - box1MaxeY;
  5964. distance += delta * delta;
  5965. }
  5966. if (box1MineZ > box2MaxeZ) {
  5967. delta = box1MineZ - box2MaxeZ;
  5968. distance += delta * delta;
  5969. }
  5970. else if (box2MineZ > box1MaxeZ) {
  5971. delta = box2MineZ - box1MaxeZ;
  5972. distance += delta * delta;
  5973. }
  5974. return Math.sqrt(distance);
  5975. }
  5976. static distanceSphereToPoint(sphere, point) {
  5977. var distance = Math.sqrt(Vector3.distanceSquared(sphere.center, point));
  5978. distance -= sphere.radius;
  5979. return Math.max(distance, 0);
  5980. }
  5981. static distanceSphereToSphere(sphere1, sphere2) {
  5982. var distance = Math.sqrt(Vector3.distanceSquared(sphere1.center, sphere2.center));
  5983. distance -= sphere1.radius + sphere2.radius;
  5984. return Math.max(distance, 0);
  5985. }
  5986. static intersectsRayAndTriangleRD(ray, vertex1, vertex2, vertex3, out) {
  5987. var rayO = ray.origin;
  5988. var rayOeX = rayO.x;
  5989. var rayOeY = rayO.y;
  5990. var rayOeZ = rayO.z;
  5991. var rayD = ray.direction;
  5992. var rayDeX = rayD.x;
  5993. var rayDeY = rayD.y;
  5994. var rayDeZ = rayD.z;
  5995. var v1eX = vertex1.x;
  5996. var v1eY = vertex1.y;
  5997. var v1eZ = vertex1.z;
  5998. var v2eX = vertex2.x;
  5999. var v2eY = vertex2.y;
  6000. var v2eZ = vertex2.z;
  6001. var v3eX = vertex3.x;
  6002. var v3eY = vertex3.y;
  6003. var v3eZ = vertex3.z;
  6004. var _tempV30eX = CollisionUtils._tempV30.x;
  6005. var _tempV30eY = CollisionUtils._tempV30.y;
  6006. var _tempV30eZ = CollisionUtils._tempV30.z;
  6007. _tempV30eX = v2eX - v1eX;
  6008. _tempV30eY = v2eY - v1eY;
  6009. _tempV30eZ = v2eZ - v1eZ;
  6010. var _tempV31eX = CollisionUtils._tempV31.x;
  6011. var _tempV31eY = CollisionUtils._tempV31.y;
  6012. var _tempV31eZ = CollisionUtils._tempV31.z;
  6013. _tempV31eX = v3eX - v1eX;
  6014. _tempV31eY = v3eY - v1eY;
  6015. _tempV31eZ = v3eZ - v1eZ;
  6016. var _tempV32eX = CollisionUtils._tempV32.x;
  6017. var _tempV32eY = CollisionUtils._tempV32.y;
  6018. var _tempV32eZ = CollisionUtils._tempV32.z;
  6019. _tempV32eX = (rayDeY * _tempV31eZ) - (rayDeZ * _tempV31eY);
  6020. _tempV32eY = (rayDeZ * _tempV31eX) - (rayDeX * _tempV31eZ);
  6021. _tempV32eZ = (rayDeX * _tempV31eY) - (rayDeY * _tempV31eX);
  6022. var determinant = (_tempV30eX * _tempV32eX) + (_tempV30eY * _tempV32eY) + (_tempV30eZ * _tempV32eZ);
  6023. if (MathUtils3D.isZero(determinant)) {
  6024. return false;
  6025. }
  6026. var inversedeterminant = 1 / determinant;
  6027. var _tempV33eX = CollisionUtils._tempV33.x;
  6028. var _tempV33eY = CollisionUtils._tempV33.y;
  6029. var _tempV33eZ = CollisionUtils._tempV33.z;
  6030. _tempV33eX = rayOeX - v1eX;
  6031. _tempV33eY = rayOeY - v1eY;
  6032. _tempV33eZ = rayOeZ - v1eZ;
  6033. var triangleU = (_tempV33eX * _tempV32eX) + (_tempV33eY * _tempV32eY) + (_tempV33eZ * _tempV32eZ);
  6034. triangleU *= inversedeterminant;
  6035. if (triangleU < 0 || triangleU > 1) {
  6036. return false;
  6037. }
  6038. var _tempV34eX = CollisionUtils._tempV34.x;
  6039. var _tempV34eY = CollisionUtils._tempV34.y;
  6040. var _tempV34eZ = CollisionUtils._tempV34.z;
  6041. _tempV34eX = (_tempV33eY * _tempV30eZ) - (_tempV33eZ * _tempV30eY);
  6042. _tempV34eY = (_tempV33eZ * _tempV30eX) - (_tempV33eX * _tempV30eZ);
  6043. _tempV34eZ = (_tempV33eX * _tempV30eY) - (_tempV33eY * _tempV30eX);
  6044. var triangleV = ((rayDeX * _tempV34eX) + (rayDeY * _tempV34eY)) + (rayDeZ * _tempV34eZ);
  6045. triangleV *= inversedeterminant;
  6046. if (triangleV < 0 || triangleU + triangleV > 1) {
  6047. return false;
  6048. }
  6049. var raydistance = (_tempV31eX * _tempV34eX) + (_tempV31eY * _tempV34eY) + (_tempV31eZ * _tempV34eZ);
  6050. raydistance *= inversedeterminant;
  6051. if (raydistance < 0) {
  6052. return false;
  6053. }
  6054. return true;
  6055. }
  6056. static intersectsRayAndTriangleRP(ray, vertex1, vertex2, vertex3, out) {
  6057. var distance;
  6058. if (!CollisionUtils.intersectsRayAndTriangleRD(ray, vertex1, vertex2, vertex3, distance)) {
  6059. out = Vector3._ZERO;
  6060. return false;
  6061. }
  6062. Vector3.scale(ray.direction, distance, CollisionUtils._tempV30);
  6063. Vector3.add(ray.origin, CollisionUtils._tempV30, out);
  6064. return true;
  6065. }
  6066. static intersectsRayAndPoint(ray, point) {
  6067. Vector3.subtract(ray.origin, point, CollisionUtils._tempV30);
  6068. var b = Vector3.dot(CollisionUtils._tempV30, ray.direction);
  6069. var c = Vector3.dot(CollisionUtils._tempV30, CollisionUtils._tempV30) - MathUtils3D.zeroTolerance;
  6070. if (c > 0 && b > 0)
  6071. return false;
  6072. var discriminant = b * b - c;
  6073. if (discriminant < 0)
  6074. return false;
  6075. return true;
  6076. }
  6077. static intersectsRayAndRay(ray1, ray2, out) {
  6078. var ray1o = ray1.origin;
  6079. var ray1oeX = ray1o.x;
  6080. var ray1oeY = ray1o.y;
  6081. var ray1oeZ = ray1o.z;
  6082. var ray1d = ray1.direction;
  6083. var ray1deX = ray1d.x;
  6084. var ray1deY = ray1d.y;
  6085. var ray1deZ = ray1d.z;
  6086. var ray2o = ray2.origin;
  6087. var ray2oeX = ray2o.x;
  6088. var ray2oeY = ray2o.y;
  6089. var ray2oeZ = ray2o.z;
  6090. var ray2d = ray2.direction;
  6091. var ray2deX = ray2d.x;
  6092. var ray2deY = ray2d.y;
  6093. var ray2deZ = ray2d.z;
  6094. Vector3.cross(ray1d, ray2d, CollisionUtils._tempV30);
  6095. var tempV3 = CollisionUtils._tempV30;
  6096. var denominator = Vector3.scalarLength(CollisionUtils._tempV30);
  6097. if (MathUtils3D.isZero(denominator)) {
  6098. if (MathUtils3D.nearEqual(ray2oeX, ray1oeX) && MathUtils3D.nearEqual(ray2oeY, ray1oeY) && MathUtils3D.nearEqual(ray2oeZ, ray1oeZ)) {
  6099. return true;
  6100. }
  6101. }
  6102. denominator = denominator * denominator;
  6103. var m11 = ray2oeX - ray1oeX;
  6104. var m12 = ray2oeY - ray1oeY;
  6105. var m13 = ray2oeZ - ray1oeZ;
  6106. var m21 = ray2deX;
  6107. var m22 = ray2deY;
  6108. var m23 = ray2deZ;
  6109. var m31 = tempV3.x;
  6110. var m32 = tempV3.y;
  6111. var m33 = tempV3.z;
  6112. var dets = m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32 - m11 * m23 * m32 - m12 * m21 * m33 - m13 * m22 * m31;
  6113. m21 = ray1deX;
  6114. m22 = ray1deY;
  6115. m23 = ray1deZ;
  6116. var s = dets / denominator;
  6117. Vector3.scale(ray1d, s, CollisionUtils._tempV30);
  6118. Vector3.scale(ray2d, s, CollisionUtils._tempV31);
  6119. Vector3.add(ray1o, CollisionUtils._tempV30, CollisionUtils._tempV32);
  6120. Vector3.add(ray2o, CollisionUtils._tempV31, CollisionUtils._tempV33);
  6121. var point1e = CollisionUtils._tempV32;
  6122. var point2e = CollisionUtils._tempV33;
  6123. if (!MathUtils3D.nearEqual(point2e.x, point1e.x) || !MathUtils3D.nearEqual(point2e.y, point1e.y) || !MathUtils3D.nearEqual(point2e.z, point1e.z)) {
  6124. return false;
  6125. }
  6126. return true;
  6127. }
  6128. static intersectsPlaneAndTriangle(plane, vertex1, vertex2, vertex3) {
  6129. var test1 = CollisionUtils.intersectsPlaneAndPoint(plane, vertex1);
  6130. var test2 = CollisionUtils.intersectsPlaneAndPoint(plane, vertex2);
  6131. var test3 = CollisionUtils.intersectsPlaneAndPoint(plane, vertex3);
  6132. if (test1 == Plane.PlaneIntersectionType_Front && test2 == Plane.PlaneIntersectionType_Front && test3 == Plane.PlaneIntersectionType_Front)
  6133. return Plane.PlaneIntersectionType_Front;
  6134. if (test1 == Plane.PlaneIntersectionType_Back && test2 == Plane.PlaneIntersectionType_Back && test3 == Plane.PlaneIntersectionType_Back)
  6135. return Plane.PlaneIntersectionType_Back;
  6136. return Plane.PlaneIntersectionType_Intersecting;
  6137. }
  6138. static intersectsRayAndPlaneRD(ray, plane, out) {
  6139. var planeNor = plane.normal;
  6140. var direction = Vector3.dot(planeNor, ray.direction);
  6141. if (MathUtils3D.isZero(direction)) {
  6142. out = 0;
  6143. return false;
  6144. }
  6145. var position = Vector3.dot(planeNor, ray.origin);
  6146. out = (-plane.distance - position) / direction;
  6147. if (out < 0) {
  6148. out = 0;
  6149. return false;
  6150. }
  6151. return true;
  6152. }
  6153. static intersectsRayAndPlaneRP(ray, plane, out) {
  6154. var distance;
  6155. if (!CollisionUtils.intersectsRayAndPlaneRD(ray, plane, distance)) {
  6156. return false;
  6157. }
  6158. Vector3.scale(ray.direction, distance, CollisionUtils._tempV30);
  6159. Vector3.add(ray.origin, CollisionUtils._tempV30, CollisionUtils._tempV31);
  6160. return true;
  6161. }
  6162. static intersectsRayAndBoxRD(ray, box) {
  6163. var rayoe = ray.origin;
  6164. var rayoeX = rayoe.x;
  6165. var rayoeY = rayoe.y;
  6166. var rayoeZ = rayoe.z;
  6167. var rayde = ray.direction;
  6168. var raydeX = rayde.x;
  6169. var raydeY = rayde.y;
  6170. var raydeZ = rayde.z;
  6171. var boxMine = box.min;
  6172. var boxMineX = boxMine.x;
  6173. var boxMineY = boxMine.y;
  6174. var boxMineZ = boxMine.z;
  6175. var boxMaxe = box.max;
  6176. var boxMaxeX = boxMaxe.x;
  6177. var boxMaxeY = boxMaxe.y;
  6178. var boxMaxeZ = boxMaxe.z;
  6179. var out = 0;
  6180. var tmax = MathUtils3D.MaxValue;
  6181. if (MathUtils3D.isZero(raydeX)) {
  6182. if (rayoeX < boxMineX || rayoeX > boxMaxeX) {
  6183. return -1;
  6184. }
  6185. }
  6186. else {
  6187. var inverse = 1 / raydeX;
  6188. var t1 = (boxMineX - rayoeX) * inverse;
  6189. var t2 = (boxMaxeX - rayoeX) * inverse;
  6190. if (t1 > t2) {
  6191. var temp = t1;
  6192. t1 = t2;
  6193. t2 = temp;
  6194. }
  6195. out = Math.max(t1, out);
  6196. tmax = Math.min(t2, tmax);
  6197. if (out > tmax) {
  6198. return -1;
  6199. }
  6200. }
  6201. if (MathUtils3D.isZero(raydeY)) {
  6202. if (rayoeY < boxMineY || rayoeY > boxMaxeY) {
  6203. return -1;
  6204. }
  6205. }
  6206. else {
  6207. var inverse1 = 1 / raydeY;
  6208. var t3 = (boxMineY - rayoeY) * inverse1;
  6209. var t4 = (boxMaxeY - rayoeY) * inverse1;
  6210. if (t3 > t4) {
  6211. var temp1 = t3;
  6212. t3 = t4;
  6213. t4 = temp1;
  6214. }
  6215. out = Math.max(t3, out);
  6216. tmax = Math.min(t4, tmax);
  6217. if (out > tmax) {
  6218. return -1;
  6219. }
  6220. }
  6221. if (MathUtils3D.isZero(raydeZ)) {
  6222. if (rayoeZ < boxMineZ || rayoeZ > boxMaxeZ) {
  6223. return -1;
  6224. }
  6225. }
  6226. else {
  6227. var inverse2 = 1 / raydeZ;
  6228. var t5 = (boxMineZ - rayoeZ) * inverse2;
  6229. var t6 = (boxMaxeZ - rayoeZ) * inverse2;
  6230. if (t5 > t6) {
  6231. var temp2 = t5;
  6232. t5 = t6;
  6233. t6 = temp2;
  6234. }
  6235. out = Math.max(t5, out);
  6236. tmax = Math.min(t6, tmax);
  6237. if (out > tmax) {
  6238. return -1;
  6239. }
  6240. }
  6241. return out;
  6242. }
  6243. static intersectsRayAndBoxRP(ray, box, out) {
  6244. var distance = CollisionUtils.intersectsRayAndBoxRD(ray, box);
  6245. if (distance === -1) {
  6246. Vector3._ZERO.cloneTo(out);
  6247. return distance;
  6248. }
  6249. Vector3.scale(ray.direction, distance, CollisionUtils._tempV30);
  6250. Vector3.add(ray.origin, CollisionUtils._tempV30, CollisionUtils._tempV31);
  6251. CollisionUtils._tempV31.cloneTo(out);
  6252. return distance;
  6253. }
  6254. static intersectsRayAndSphereRD(ray, sphere) {
  6255. var sphereR = sphere.radius;
  6256. Vector3.subtract(ray.origin, sphere.center, CollisionUtils._tempV30);
  6257. var b = Vector3.dot(CollisionUtils._tempV30, ray.direction);
  6258. var c = Vector3.dot(CollisionUtils._tempV30, CollisionUtils._tempV30) - (sphereR * sphereR);
  6259. if (c > 0 && b > 0) {
  6260. return -1;
  6261. }
  6262. var discriminant = b * b - c;
  6263. if (discriminant < 0) {
  6264. return -1;
  6265. }
  6266. var distance = -b - Math.sqrt(discriminant);
  6267. if (distance < 0)
  6268. distance = 0;
  6269. return distance;
  6270. }
  6271. static intersectsRayAndSphereRP(ray, sphere, out) {
  6272. var distance = CollisionUtils.intersectsRayAndSphereRD(ray, sphere);
  6273. if (distance === -1) {
  6274. Vector3._ZERO.cloneTo(out);
  6275. return distance;
  6276. }
  6277. Vector3.scale(ray.direction, distance, CollisionUtils._tempV30);
  6278. Vector3.add(ray.origin, CollisionUtils._tempV30, CollisionUtils._tempV31);
  6279. CollisionUtils._tempV31.cloneTo(out);
  6280. return distance;
  6281. }
  6282. static intersectsSphereAndTriangle(sphere, vertex1, vertex2, vertex3) {
  6283. var sphereC = sphere.center;
  6284. var sphereR = sphere.radius;
  6285. CollisionUtils.closestPointPointTriangle(sphereC, vertex1, vertex2, vertex3, CollisionUtils._tempV30);
  6286. Vector3.subtract(CollisionUtils._tempV30, sphereC, CollisionUtils._tempV31);
  6287. var dot = Vector3.dot(CollisionUtils._tempV31, CollisionUtils._tempV31);
  6288. return dot <= sphereR * sphereR;
  6289. }
  6290. static intersectsPlaneAndPoint(plane, point) {
  6291. var distance = Vector3.dot(plane.normal, point) + plane.distance;
  6292. if (distance > 0)
  6293. return Plane.PlaneIntersectionType_Front;
  6294. if (distance < 0)
  6295. return Plane.PlaneIntersectionType_Back;
  6296. return Plane.PlaneIntersectionType_Intersecting;
  6297. }
  6298. static intersectsPlaneAndPlane(plane1, plane2) {
  6299. Vector3.cross(plane1.normal, plane2.normal, CollisionUtils._tempV30);
  6300. var denominator = Vector3.dot(CollisionUtils._tempV30, CollisionUtils._tempV30);
  6301. if (MathUtils3D.isZero(denominator))
  6302. return false;
  6303. return true;
  6304. }
  6305. static intersectsPlaneAndPlaneRL(plane1, plane2, line) {
  6306. var plane1nor = plane1.normal;
  6307. var plane2nor = plane2.normal;
  6308. Vector3.cross(plane1nor, plane2nor, CollisionUtils._tempV34);
  6309. var denominator = Vector3.dot(CollisionUtils._tempV34, CollisionUtils._tempV34);
  6310. if (MathUtils3D.isZero(denominator))
  6311. return false;
  6312. Vector3.scale(plane2nor, plane1.distance, CollisionUtils._tempV30);
  6313. Vector3.scale(plane1nor, plane2.distance, CollisionUtils._tempV31);
  6314. Vector3.subtract(CollisionUtils._tempV30, CollisionUtils._tempV31, CollisionUtils._tempV32);
  6315. Vector3.cross(CollisionUtils._tempV32, CollisionUtils._tempV34, CollisionUtils._tempV33);
  6316. Vector3.normalize(CollisionUtils._tempV34, CollisionUtils._tempV34);
  6317. return true;
  6318. }
  6319. static intersectsPlaneAndBox(plane, box) {
  6320. var planeD = plane.distance;
  6321. var planeNor = plane.normal;
  6322. var planeNoreX = planeNor.x;
  6323. var planeNoreY = planeNor.y;
  6324. var planeNoreZ = planeNor.z;
  6325. var boxMine = box.min;
  6326. var boxMineX = boxMine.x;
  6327. var boxMineY = boxMine.y;
  6328. var boxMineZ = boxMine.z;
  6329. var boxMaxe = box.max;
  6330. var boxMaxeX = boxMaxe.x;
  6331. var boxMaxeY = boxMaxe.y;
  6332. var boxMaxeZ = boxMaxe.z;
  6333. CollisionUtils._tempV30.x = (planeNoreX > 0) ? boxMineX : boxMaxeX;
  6334. CollisionUtils._tempV30.y = (planeNoreY > 0) ? boxMineY : boxMaxeY;
  6335. CollisionUtils._tempV30.z = (planeNoreZ > 0) ? boxMineZ : boxMaxeZ;
  6336. CollisionUtils._tempV31.x = (planeNoreX > 0) ? boxMaxeX : boxMineX;
  6337. CollisionUtils._tempV31.y = (planeNoreY > 0) ? boxMaxeY : boxMineY;
  6338. CollisionUtils._tempV31.z = (planeNoreZ > 0) ? boxMaxeZ : boxMineZ;
  6339. var distance = Vector3.dot(planeNor, CollisionUtils._tempV30);
  6340. if (distance + planeD > 0)
  6341. return Plane.PlaneIntersectionType_Front;
  6342. distance = Vector3.dot(planeNor, CollisionUtils._tempV31);
  6343. if (distance + planeD < 0)
  6344. return Plane.PlaneIntersectionType_Back;
  6345. return Plane.PlaneIntersectionType_Intersecting;
  6346. }
  6347. static intersectsPlaneAndSphere(plane, sphere) {
  6348. var sphereR = sphere.radius;
  6349. var distance = Vector3.dot(plane.normal, sphere.center) + plane.distance;
  6350. if (distance > sphereR)
  6351. return Plane.PlaneIntersectionType_Front;
  6352. if (distance < -sphereR)
  6353. return Plane.PlaneIntersectionType_Back;
  6354. return Plane.PlaneIntersectionType_Intersecting;
  6355. }
  6356. static intersectsBoxAndBox(box1, box2) {
  6357. var box1Mine = box1.min;
  6358. var box1Maxe = box1.max;
  6359. var box2Mine = box2.min;
  6360. var box2Maxe = box2.max;
  6361. if (box1Mine.x > box2Maxe.x || box2Mine.x > box1Maxe.x)
  6362. return false;
  6363. if (box1Mine.y > box2Maxe.y || box2Mine.y > box1Maxe.y)
  6364. return false;
  6365. if (box1Mine.z > box2Maxe.z || box2Mine.z > box1Maxe.z)
  6366. return false;
  6367. return true;
  6368. }
  6369. static intersectsBoxAndSphere(box, sphere) {
  6370. var sphereC = sphere.center;
  6371. var sphereR = sphere.radius;
  6372. Vector3.Clamp(sphereC, box.min, box.max, CollisionUtils._tempV30);
  6373. var distance = Vector3.distanceSquared(sphereC, CollisionUtils._tempV30);
  6374. return distance <= sphereR * sphereR;
  6375. }
  6376. static intersectsSphereAndSphere(sphere1, sphere2) {
  6377. var radiisum = sphere1.radius + sphere2.radius;
  6378. return Vector3.distanceSquared(sphere1.center, sphere2.center) <= radiisum * radiisum;
  6379. }
  6380. static boxContainsPoint(box, point) {
  6381. var boxMine = box.min;
  6382. var boxMaxe = box.max;
  6383. if (boxMine.x <= point.x && boxMaxe.x >= point.x && boxMine.y <= point.y && boxMaxe.y >= point.y && boxMine.z <= point.z && boxMaxe.z >= point.z)
  6384. return ContainmentType.Contains;
  6385. return ContainmentType.Disjoint;
  6386. }
  6387. static boxContainsBox(box1, box2) {
  6388. var box1Mine = box1.min;
  6389. var box1MineX = box1Mine.x;
  6390. var box1MineY = box1Mine.y;
  6391. var box1MineZ = box1Mine.z;
  6392. var box1Maxe = box1.max;
  6393. var box1MaxeX = box1Maxe.x;
  6394. var box1MaxeY = box1Maxe.y;
  6395. var box1MaxeZ = box1Maxe.z;
  6396. var box2Mine = box2.min;
  6397. var box2MineX = box2Mine.x;
  6398. var box2MineY = box2Mine.y;
  6399. var box2MineZ = box2Mine.z;
  6400. var box2Maxe = box2.max;
  6401. var box2MaxeX = box2Maxe.x;
  6402. var box2MaxeY = box2Maxe.y;
  6403. var box2MaxeZ = box2Maxe.z;
  6404. if (box1MaxeX < box2MineX || box1MineX > box2MaxeX)
  6405. return ContainmentType.Disjoint;
  6406. if (box1MaxeY < box2MineY || box1MineY > box2MaxeY)
  6407. return ContainmentType.Disjoint;
  6408. if (box1MaxeZ < box2MineZ || box1MineZ > box2MaxeZ)
  6409. return ContainmentType.Disjoint;
  6410. if (box1MineX <= box2MineX && box2MaxeX <= box1MaxeX && box1MineY <= box2MineY && box2MaxeY <= box1MaxeY && box1MineZ <= box2MineZ && box2MaxeZ <= box1MaxeZ) {
  6411. return ContainmentType.Contains;
  6412. }
  6413. return ContainmentType.Intersects;
  6414. }
  6415. static boxContainsSphere(box, sphere) {
  6416. var boxMin = box.min;
  6417. var boxMineX = boxMin.x;
  6418. var boxMineY = boxMin.y;
  6419. var boxMineZ = boxMin.z;
  6420. var boxMax = box.max;
  6421. var boxMaxeX = boxMax.x;
  6422. var boxMaxeY = boxMax.y;
  6423. var boxMaxeZ = boxMax.z;
  6424. var sphereC = sphere.center;
  6425. var sphereCeX = sphereC.x;
  6426. var sphereCeY = sphereC.y;
  6427. var sphereCeZ = sphereC.z;
  6428. var sphereR = sphere.radius;
  6429. Vector3.Clamp(sphereC, boxMin, boxMax, CollisionUtils._tempV30);
  6430. var distance = Vector3.distanceSquared(sphereC, CollisionUtils._tempV30);
  6431. if (distance > sphereR * sphereR)
  6432. return ContainmentType.Disjoint;
  6433. if ((((boxMineX + sphereR <= sphereCeX) && (sphereCeX <= boxMaxeX - sphereR)) && ((boxMaxeX - boxMineX > sphereR) &&
  6434. (boxMineY + sphereR <= sphereCeY))) && (((sphereCeY <= boxMaxeY - sphereR) && (boxMaxeY - boxMineY > sphereR)) &&
  6435. (((boxMineZ + sphereR <= sphereCeZ) && (sphereCeZ <= boxMaxeZ - sphereR)) && (boxMaxeZ - boxMineZ > sphereR))))
  6436. return ContainmentType.Contains;
  6437. return ContainmentType.Intersects;
  6438. }
  6439. static sphereContainsPoint(sphere, point) {
  6440. if (Vector3.distanceSquared(point, sphere.center) <= sphere.radius * sphere.radius)
  6441. return ContainmentType.Contains;
  6442. return ContainmentType.Disjoint;
  6443. }
  6444. static sphereContainsTriangle(sphere, vertex1, vertex2, vertex3) {
  6445. var test1 = CollisionUtils.sphereContainsPoint(sphere, vertex1);
  6446. var test2 = CollisionUtils.sphereContainsPoint(sphere, vertex2);
  6447. var test3 = CollisionUtils.sphereContainsPoint(sphere, vertex3);
  6448. if (test1 == ContainmentType.Contains && test2 == ContainmentType.Contains && test3 == ContainmentType.Contains)
  6449. return ContainmentType.Contains;
  6450. if (CollisionUtils.intersectsSphereAndTriangle(sphere, vertex1, vertex2, vertex3))
  6451. return ContainmentType.Intersects;
  6452. return ContainmentType.Disjoint;
  6453. }
  6454. static sphereContainsBox(sphere, box) {
  6455. var sphereC = sphere.center;
  6456. var sphereCeX = sphereC.x;
  6457. var sphereCeY = sphereC.y;
  6458. var sphereCeZ = sphereC.z;
  6459. var sphereR = sphere.radius;
  6460. var boxMin = box.min;
  6461. var boxMineX = boxMin.x;
  6462. var boxMineY = boxMin.y;
  6463. var boxMineZ = boxMin.z;
  6464. var boxMax = box.max;
  6465. var boxMaxeX = boxMax.x;
  6466. var boxMaxeY = boxMax.y;
  6467. var boxMaxeZ = boxMax.z;
  6468. var _tempV30e = CollisionUtils._tempV30;
  6469. var _tempV30eX = _tempV30e.x;
  6470. var _tempV30eY = _tempV30e.y;
  6471. var _tempV30eZ = _tempV30e.z;
  6472. if (!CollisionUtils.intersectsBoxAndSphere(box, sphere))
  6473. return ContainmentType.Disjoint;
  6474. var radiusSquared = sphereR * sphereR;
  6475. _tempV30eX = sphereCeX - boxMineX;
  6476. _tempV30eY = sphereCeY - boxMaxeY;
  6477. _tempV30eZ = sphereCeZ - boxMaxeZ;
  6478. if (Vector3.scalarLengthSquared(CollisionUtils._tempV30) > radiusSquared)
  6479. return ContainmentType.Intersects;
  6480. _tempV30eX = sphereCeX - boxMaxeX;
  6481. _tempV30eY = sphereCeY - boxMaxeY;
  6482. _tempV30eZ = sphereCeZ - boxMaxeZ;
  6483. if (Vector3.scalarLengthSquared(CollisionUtils._tempV30) > radiusSquared)
  6484. return ContainmentType.Intersects;
  6485. _tempV30eX = sphereCeX - boxMaxeX;
  6486. _tempV30eY = sphereCeY - boxMineY;
  6487. _tempV30eZ = sphereCeZ - boxMaxeZ;
  6488. if (Vector3.scalarLengthSquared(CollisionUtils._tempV30) > radiusSquared)
  6489. return ContainmentType.Intersects;
  6490. _tempV30eX = sphereCeX - boxMineX;
  6491. _tempV30eY = sphereCeY - boxMineY;
  6492. _tempV30eZ = sphereCeZ - boxMaxeZ;
  6493. if (Vector3.scalarLengthSquared(CollisionUtils._tempV30) > radiusSquared)
  6494. return ContainmentType.Intersects;
  6495. _tempV30eX = sphereCeX - boxMineX;
  6496. _tempV30eY = sphereCeY - boxMaxeY;
  6497. _tempV30eZ = sphereCeZ - boxMineZ;
  6498. if (Vector3.scalarLengthSquared(CollisionUtils._tempV30) > radiusSquared)
  6499. return ContainmentType.Intersects;
  6500. _tempV30eX = sphereCeX - boxMaxeX;
  6501. _tempV30eY = sphereCeY - boxMaxeY;
  6502. _tempV30eZ = sphereCeZ - boxMineZ;
  6503. if (Vector3.scalarLengthSquared(CollisionUtils._tempV30) > radiusSquared)
  6504. return ContainmentType.Intersects;
  6505. _tempV30eX = sphereCeX - boxMaxeX;
  6506. _tempV30eY = sphereCeY - boxMineY;
  6507. _tempV30eZ = sphereCeZ - boxMineZ;
  6508. if (Vector3.scalarLengthSquared(CollisionUtils._tempV30) > radiusSquared)
  6509. return ContainmentType.Intersects;
  6510. _tempV30eX = sphereCeX - boxMineX;
  6511. _tempV30eY = sphereCeY - boxMineY;
  6512. _tempV30eZ = sphereCeZ - boxMineZ;
  6513. if (Vector3.scalarLengthSquared(CollisionUtils._tempV30) > radiusSquared)
  6514. return ContainmentType.Intersects;
  6515. return ContainmentType.Contains;
  6516. }
  6517. static sphereContainsSphere(sphere1, sphere2) {
  6518. var sphere1R = sphere1.radius;
  6519. var sphere2R = sphere2.radius;
  6520. var distance = Vector3.distance(sphere1.center, sphere2.center);
  6521. if (sphere1R + sphere2R < distance)
  6522. return ContainmentType.Disjoint;
  6523. if (sphere1R - sphere2R < distance)
  6524. return ContainmentType.Intersects;
  6525. return ContainmentType.Contains;
  6526. }
  6527. static closestPointPointTriangle(point, vertex1, vertex2, vertex3, out) {
  6528. Vector3.subtract(vertex2, vertex1, CollisionUtils._tempV30);
  6529. Vector3.subtract(vertex3, vertex1, CollisionUtils._tempV31);
  6530. Vector3.subtract(point, vertex1, CollisionUtils._tempV32);
  6531. Vector3.subtract(point, vertex2, CollisionUtils._tempV33);
  6532. Vector3.subtract(point, vertex3, CollisionUtils._tempV34);
  6533. var d1 = Vector3.dot(CollisionUtils._tempV30, CollisionUtils._tempV32);
  6534. var d2 = Vector3.dot(CollisionUtils._tempV31, CollisionUtils._tempV32);
  6535. var d3 = Vector3.dot(CollisionUtils._tempV30, CollisionUtils._tempV33);
  6536. var d4 = Vector3.dot(CollisionUtils._tempV31, CollisionUtils._tempV33);
  6537. var d5 = Vector3.dot(CollisionUtils._tempV30, CollisionUtils._tempV34);
  6538. var d6 = Vector3.dot(CollisionUtils._tempV31, CollisionUtils._tempV34);
  6539. if (d1 <= 0 && d2 <= 0) {
  6540. vertex1.cloneTo(out);
  6541. return;
  6542. }
  6543. if (d3 >= 0 && d4 <= d3) {
  6544. vertex2.cloneTo(out);
  6545. return;
  6546. }
  6547. var vc = d1 * d4 - d3 * d2;
  6548. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  6549. var v = d1 / (d1 - d3);
  6550. Vector3.scale(CollisionUtils._tempV30, v, out);
  6551. Vector3.add(vertex1, out, out);
  6552. return;
  6553. }
  6554. if (d6 >= 0 && d5 <= d6) {
  6555. vertex3.cloneTo(out);
  6556. return;
  6557. }
  6558. var vb = d5 * d2 - d1 * d6;
  6559. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  6560. var w = d2 / (d2 - d6);
  6561. Vector3.scale(CollisionUtils._tempV31, w, out);
  6562. Vector3.add(vertex1, out, out);
  6563. return;
  6564. }
  6565. var va = d3 * d6 - d5 * d4;
  6566. if (va <= 0 && (d4 - d3) >= 0 && (d5 - d6) >= 0) {
  6567. var w3 = (d4 - d3) / ((d4 - d3) + (d5 - d6));
  6568. Vector3.subtract(vertex3, vertex2, out);
  6569. Vector3.scale(out, w3, out);
  6570. Vector3.add(vertex2, out, out);
  6571. return;
  6572. }
  6573. var denom = 1 / (va + vb + vc);
  6574. var v2 = vb * denom;
  6575. var w2 = vc * denom;
  6576. Vector3.scale(CollisionUtils._tempV30, v2, CollisionUtils._tempV35);
  6577. Vector3.scale(CollisionUtils._tempV31, w2, CollisionUtils._tempV36);
  6578. Vector3.add(CollisionUtils._tempV35, CollisionUtils._tempV36, out);
  6579. Vector3.add(vertex1, out, out);
  6580. }
  6581. static closestPointPlanePoint(plane, point, out) {
  6582. var planeN = plane.normal;
  6583. var t = Vector3.dot(planeN, point) - plane.distance;
  6584. Vector3.scale(planeN, t, CollisionUtils._tempV30);
  6585. Vector3.subtract(point, CollisionUtils._tempV30, out);
  6586. }
  6587. static closestPointBoxPoint(box, point, out) {
  6588. Vector3.max(point, box.min, CollisionUtils._tempV30);
  6589. Vector3.min(CollisionUtils._tempV30, box.max, out);
  6590. }
  6591. static closestPointSpherePoint(sphere, point, out) {
  6592. var sphereC = sphere.center;
  6593. Vector3.subtract(point, sphereC, out);
  6594. Vector3.normalize(out, out);
  6595. Vector3.scale(out, sphere.radius, out);
  6596. Vector3.add(out, sphereC, out);
  6597. }
  6598. static closestPointSphereSphere(sphere1, sphere2, out) {
  6599. var sphere1C = sphere1.center;
  6600. Vector3.subtract(sphere2.center, sphere1C, out);
  6601. Vector3.normalize(out, out);
  6602. Vector3.scale(out, sphere1.radius, out);
  6603. Vector3.add(out, sphere1C, out);
  6604. }
  6605. }
  6606. CollisionUtils._tempV30 = new Vector3();
  6607. CollisionUtils._tempV31 = new Vector3();
  6608. CollisionUtils._tempV32 = new Vector3();
  6609. CollisionUtils._tempV33 = new Vector3();
  6610. CollisionUtils._tempV34 = new Vector3();
  6611. CollisionUtils._tempV35 = new Vector3();
  6612. CollisionUtils._tempV36 = new Vector3();
  6613. class BoundFrustum {
  6614. constructor(matrix) {
  6615. this._matrix = matrix;
  6616. this._near = new Plane(new Vector3());
  6617. this._far = new Plane(new Vector3());
  6618. this._left = new Plane(new Vector3());
  6619. this._right = new Plane(new Vector3());
  6620. this._top = new Plane(new Vector3());
  6621. this._bottom = new Plane(new Vector3());
  6622. BoundFrustum._getPlanesFromMatrix(this._matrix, this._near, this._far, this._left, this._right, this._top, this._bottom);
  6623. }
  6624. get matrix() {
  6625. return this._matrix;
  6626. }
  6627. set matrix(matrix) {
  6628. this._matrix = matrix;
  6629. BoundFrustum._getPlanesFromMatrix(this._matrix, this._near, this._far, this._left, this._right, this._top, this._bottom);
  6630. }
  6631. get near() {
  6632. return this._near;
  6633. }
  6634. get far() {
  6635. return this._far;
  6636. }
  6637. get left() {
  6638. return this._left;
  6639. }
  6640. get right() {
  6641. return this._right;
  6642. }
  6643. get top() {
  6644. return this._top;
  6645. }
  6646. get bottom() {
  6647. return this._bottom;
  6648. }
  6649. equalsBoundFrustum(other) {
  6650. return this._matrix.equalsOtherMatrix(other.matrix);
  6651. }
  6652. equalsObj(obj) {
  6653. if (obj instanceof BoundFrustum) {
  6654. var bf = obj;
  6655. return this.equalsBoundFrustum(bf);
  6656. }
  6657. return false;
  6658. }
  6659. getPlane(index) {
  6660. switch (index) {
  6661. case 0:
  6662. return this._near;
  6663. case 1:
  6664. return this._far;
  6665. case 2:
  6666. return this._left;
  6667. case 3:
  6668. return this._right;
  6669. case 4:
  6670. return this._top;
  6671. case 5:
  6672. return this._bottom;
  6673. default:
  6674. return null;
  6675. }
  6676. }
  6677. static _getPlanesFromMatrix(m, np, fp, lp, rp, tp, bp) {
  6678. var matrixE = m.elements;
  6679. var m11 = matrixE[0];
  6680. var m12 = matrixE[1];
  6681. var m13 = matrixE[2];
  6682. var m14 = matrixE[3];
  6683. var m21 = matrixE[4];
  6684. var m22 = matrixE[5];
  6685. var m23 = matrixE[6];
  6686. var m24 = matrixE[7];
  6687. var m31 = matrixE[8];
  6688. var m32 = matrixE[9];
  6689. var m33 = matrixE[10];
  6690. var m34 = matrixE[11];
  6691. var m41 = matrixE[12];
  6692. var m42 = matrixE[13];
  6693. var m43 = matrixE[14];
  6694. var m44 = matrixE[15];
  6695. var nearNorE = np.normal;
  6696. nearNorE.x = m14 + m13;
  6697. nearNorE.y = m24 + m23;
  6698. nearNorE.z = m34 + m33;
  6699. np.distance = m44 + m43;
  6700. np.normalize();
  6701. var farNorE = fp.normal;
  6702. farNorE.x = m14 - m13;
  6703. farNorE.y = m24 - m23;
  6704. farNorE.z = m34 - m33;
  6705. fp.distance = m44 - m43;
  6706. fp.normalize();
  6707. var leftNorE = lp.normal;
  6708. leftNorE.x = m14 + m11;
  6709. leftNorE.y = m24 + m21;
  6710. leftNorE.z = m34 + m31;
  6711. lp.distance = m44 + m41;
  6712. lp.normalize();
  6713. var rightNorE = rp.normal;
  6714. rightNorE.x = m14 - m11;
  6715. rightNorE.y = m24 - m21;
  6716. rightNorE.z = m34 - m31;
  6717. rp.distance = m44 - m41;
  6718. rp.normalize();
  6719. var topNorE = tp.normal;
  6720. topNorE.x = m14 - m12;
  6721. topNorE.y = m24 - m22;
  6722. topNorE.z = m34 - m32;
  6723. tp.distance = m44 - m42;
  6724. tp.normalize();
  6725. var bottomNorE = bp.normal;
  6726. bottomNorE.x = m14 + m12;
  6727. bottomNorE.y = m24 + m22;
  6728. bottomNorE.z = m34 + m32;
  6729. bp.distance = m44 + m42;
  6730. bp.normalize();
  6731. }
  6732. static _get3PlaneInterPoint(p1, p2, p3) {
  6733. var p1Nor = p1.normal;
  6734. var p2Nor = p2.normal;
  6735. var p3Nor = p3.normal;
  6736. Vector3.cross(p2Nor, p3Nor, BoundFrustum._tempV30);
  6737. Vector3.cross(p3Nor, p1Nor, BoundFrustum._tempV31);
  6738. Vector3.cross(p1Nor, p2Nor, BoundFrustum._tempV32);
  6739. var a = Vector3.dot(p1Nor, BoundFrustum._tempV30);
  6740. var b = Vector3.dot(p2Nor, BoundFrustum._tempV31);
  6741. var c = Vector3.dot(p3Nor, BoundFrustum._tempV32);
  6742. Vector3.scale(BoundFrustum._tempV30, -p1.distance / a, BoundFrustum._tempV33);
  6743. Vector3.scale(BoundFrustum._tempV31, -p2.distance / b, BoundFrustum._tempV34);
  6744. Vector3.scale(BoundFrustum._tempV32, -p3.distance / c, BoundFrustum._tempV35);
  6745. Vector3.add(BoundFrustum._tempV33, BoundFrustum._tempV34, BoundFrustum._tempV36);
  6746. Vector3.add(BoundFrustum._tempV35, BoundFrustum._tempV36, BoundFrustum._tempV37);
  6747. var v = BoundFrustum._tempV37;
  6748. return v;
  6749. }
  6750. getCorners(corners) {
  6751. BoundFrustum._get3PlaneInterPoint(this._near, this._bottom, this._right).cloneTo(corners[0]);
  6752. BoundFrustum._get3PlaneInterPoint(this._near, this._top, this._right).cloneTo(corners[1]);
  6753. BoundFrustum._get3PlaneInterPoint(this._near, this._top, this._left).cloneTo(corners[2]);
  6754. BoundFrustum._get3PlaneInterPoint(this._near, this._bottom, this._left).cloneTo(corners[3]);
  6755. BoundFrustum._get3PlaneInterPoint(this._far, this._bottom, this._right).cloneTo(corners[4]);
  6756. BoundFrustum._get3PlaneInterPoint(this._far, this._top, this._right).cloneTo(corners[5]);
  6757. BoundFrustum._get3PlaneInterPoint(this._far, this._top, this._left).cloneTo(corners[6]);
  6758. BoundFrustum._get3PlaneInterPoint(this._far, this._bottom, this._left).cloneTo(corners[7]);
  6759. }
  6760. containsPoint(point) {
  6761. var result = Plane.PlaneIntersectionType_Front;
  6762. var planeResult = Plane.PlaneIntersectionType_Front;
  6763. for (var i = 0; i < 6; i++) {
  6764. switch (i) {
  6765. case 0:
  6766. planeResult = CollisionUtils.intersectsPlaneAndPoint(this._near, point);
  6767. break;
  6768. case 1:
  6769. planeResult = CollisionUtils.intersectsPlaneAndPoint(this._far, point);
  6770. break;
  6771. case 2:
  6772. planeResult = CollisionUtils.intersectsPlaneAndPoint(this._left, point);
  6773. break;
  6774. case 3:
  6775. planeResult = CollisionUtils.intersectsPlaneAndPoint(this._right, point);
  6776. break;
  6777. case 4:
  6778. planeResult = CollisionUtils.intersectsPlaneAndPoint(this._top, point);
  6779. break;
  6780. case 5:
  6781. planeResult = CollisionUtils.intersectsPlaneAndPoint(this._bottom, point);
  6782. break;
  6783. }
  6784. switch (planeResult) {
  6785. case Plane.PlaneIntersectionType_Back:
  6786. return ContainmentType.Disjoint;
  6787. case Plane.PlaneIntersectionType_Intersecting:
  6788. result = Plane.PlaneIntersectionType_Intersecting;
  6789. break;
  6790. }
  6791. }
  6792. switch (result) {
  6793. case Plane.PlaneIntersectionType_Intersecting:
  6794. return ContainmentType.Intersects;
  6795. default:
  6796. return ContainmentType.Contains;
  6797. }
  6798. }
  6799. intersects(box) {
  6800. var min = box.min;
  6801. var max = box.max;
  6802. var minX = min.x;
  6803. var minY = min.y;
  6804. var minZ = min.z;
  6805. var maxX = max.x;
  6806. var maxY = max.y;
  6807. var maxZ = max.z;
  6808. var nearNormal = this._near.normal;
  6809. if (this._near.distance + (nearNormal.x * (nearNormal.x < 0 ? minX : maxX)) + (nearNormal.y * (nearNormal.y < 0 ? minY : maxY)) + (nearNormal.z * (nearNormal.z < 0 ? minZ : maxZ)) < 0)
  6810. return false;
  6811. var leftNormal = this._left.normal;
  6812. if (this._left.distance + (leftNormal.x * (leftNormal.x < 0 ? minX : maxX)) + (leftNormal.y * (leftNormal.y < 0 ? minY : maxY)) + (leftNormal.z * (leftNormal.z < 0 ? minZ : maxZ)) < 0)
  6813. return false;
  6814. var rightNormal = this._right.normal;
  6815. if (this._right.distance + (rightNormal.x * (rightNormal.x < 0 ? minX : maxX)) + (rightNormal.y * (rightNormal.y < 0 ? minY : maxY)) + (rightNormal.z * (rightNormal.z < 0 ? minZ : maxZ)) < 0)
  6816. return false;
  6817. var bottomNormal = this._bottom.normal;
  6818. if (this._bottom.distance + (bottomNormal.x * (bottomNormal.x < 0 ? minX : maxX)) + (bottomNormal.y * (bottomNormal.y < 0 ? minY : maxY)) + (bottomNormal.z * (bottomNormal.z < 0 ? minZ : maxZ)) < 0)
  6819. return false;
  6820. var topNormal = this._top.normal;
  6821. if (this._top.distance + (topNormal.x * (topNormal.x < 0 ? minX : maxX)) + (topNormal.y * (topNormal.y < 0 ? minY : maxY)) + (topNormal.z * (topNormal.z < 0 ? minZ : maxZ)) < 0)
  6822. return false;
  6823. var farNormal = this._far.normal;
  6824. if (this._far.distance + (farNormal.x * (farNormal.x < 0 ? minX : maxX)) + (farNormal.y * (farNormal.y < 0 ? minY : maxY)) + (farNormal.z * (farNormal.z < 0 ? minZ : maxZ)) < 0)
  6825. return false;
  6826. return true;
  6827. }
  6828. containsBoundBox(box) {
  6829. var p = BoundFrustum._tempV30, n = BoundFrustum._tempV31;
  6830. var boxMin = box.min;
  6831. var boxMax = box.max;
  6832. var result = ContainmentType.Contains;
  6833. for (var i = 0; i < 6; i++) {
  6834. var plane = this.getPlane(i);
  6835. var planeNor = plane.normal;
  6836. if (planeNor.x >= 0) {
  6837. p.x = boxMax.x;
  6838. n.x = boxMin.x;
  6839. }
  6840. else {
  6841. p.x = boxMin.x;
  6842. n.x = boxMax.x;
  6843. }
  6844. if (planeNor.y >= 0) {
  6845. p.y = boxMax.y;
  6846. n.y = boxMin.y;
  6847. }
  6848. else {
  6849. p.y = boxMin.y;
  6850. n.y = boxMax.y;
  6851. }
  6852. if (planeNor.z >= 0) {
  6853. p.z = boxMax.z;
  6854. n.z = boxMin.z;
  6855. }
  6856. else {
  6857. p.z = boxMin.z;
  6858. n.z = boxMax.z;
  6859. }
  6860. if (CollisionUtils.intersectsPlaneAndPoint(plane, p) === Plane.PlaneIntersectionType_Back)
  6861. return ContainmentType.Disjoint;
  6862. if (CollisionUtils.intersectsPlaneAndPoint(plane, n) === Plane.PlaneIntersectionType_Back)
  6863. result = ContainmentType.Intersects;
  6864. }
  6865. return result;
  6866. }
  6867. containsBoundSphere(sphere) {
  6868. var result = Plane.PlaneIntersectionType_Front;
  6869. var planeResult = Plane.PlaneIntersectionType_Front;
  6870. for (var i = 0; i < 6; i++) {
  6871. switch (i) {
  6872. case 0:
  6873. planeResult = CollisionUtils.intersectsPlaneAndSphere(this._near, sphere);
  6874. break;
  6875. case 1:
  6876. planeResult = CollisionUtils.intersectsPlaneAndSphere(this._far, sphere);
  6877. break;
  6878. case 2:
  6879. planeResult = CollisionUtils.intersectsPlaneAndSphere(this._left, sphere);
  6880. break;
  6881. case 3:
  6882. planeResult = CollisionUtils.intersectsPlaneAndSphere(this._right, sphere);
  6883. break;
  6884. case 4:
  6885. planeResult = CollisionUtils.intersectsPlaneAndSphere(this._top, sphere);
  6886. break;
  6887. case 5:
  6888. planeResult = CollisionUtils.intersectsPlaneAndSphere(this._bottom, sphere);
  6889. break;
  6890. }
  6891. switch (planeResult) {
  6892. case Plane.PlaneIntersectionType_Back:
  6893. return ContainmentType.Disjoint;
  6894. case Plane.PlaneIntersectionType_Intersecting:
  6895. result = Plane.PlaneIntersectionType_Intersecting;
  6896. break;
  6897. }
  6898. }
  6899. switch (result) {
  6900. case Plane.PlaneIntersectionType_Intersecting:
  6901. return ContainmentType.Intersects;
  6902. default:
  6903. return ContainmentType.Contains;
  6904. }
  6905. }
  6906. }
  6907. BoundFrustum._tempV30 = new Vector3();
  6908. BoundFrustum._tempV31 = new Vector3();
  6909. BoundFrustum._tempV32 = new Vector3();
  6910. BoundFrustum._tempV33 = new Vector3();
  6911. BoundFrustum._tempV34 = new Vector3();
  6912. BoundFrustum._tempV35 = new Vector3();
  6913. BoundFrustum._tempV36 = new Vector3();
  6914. BoundFrustum._tempV37 = new Vector3();
  6915. class Viewport {
  6916. constructor(x, y, width, height) {
  6917. this.minDepth = 0.0;
  6918. this.maxDepth = 1.0;
  6919. this.x = x;
  6920. this.y = y;
  6921. this.width = width;
  6922. this.height = height;
  6923. }
  6924. project(source, matrix, out) {
  6925. Vector3.transformV3ToV3(source, matrix, out);
  6926. var matrixEleme = matrix.elements;
  6927. var a = (((source.x * matrixEleme[3]) + (source.y * matrixEleme[7])) + (source.z * matrixEleme[11])) + matrixEleme[15];
  6928. if (a !== 1.0) {
  6929. out.x = out.x / a;
  6930. out.y = out.y / a;
  6931. out.z = out.z / a;
  6932. }
  6933. out.x = (((out.x + 1.0) * 0.5) * this.width) + this.x;
  6934. out.y = (((-out.y + 1.0) * 0.5) * this.height) + this.y;
  6935. out.z = (out.z * (this.maxDepth - this.minDepth)) + this.minDepth;
  6936. }
  6937. unprojectFromMat(source, matrix, out) {
  6938. var matrixEleme = matrix.elements;
  6939. out.x = (((source.x - this.x) / (this.width)) * 2.0) - 1.0;
  6940. out.y = -((((source.y - this.y) / (this.height)) * 2.0) - 1.0);
  6941. var halfDepth = (this.maxDepth - this.minDepth) / 2;
  6942. out.z = (source.z - this.minDepth - halfDepth) / halfDepth;
  6943. var a = (((out.x * matrixEleme[3]) + (out.y * matrixEleme[7])) + (out.z * matrixEleme[11])) + matrixEleme[15];
  6944. Vector3.transformV3ToV3(out, matrix, out);
  6945. if (a !== 1.0) {
  6946. out.x = out.x / a;
  6947. out.y = out.y / a;
  6948. out.z = out.z / a;
  6949. }
  6950. }
  6951. unprojectFromWVP(source, projection, view, world, out) {
  6952. Matrix4x4.multiply(projection, view, Viewport._tempMatrix4x4);
  6953. (world) && (Matrix4x4.multiply(Viewport._tempMatrix4x4, world, Viewport._tempMatrix4x4));
  6954. Viewport._tempMatrix4x4.invert(Viewport._tempMatrix4x4);
  6955. this.unprojectFromMat(source, Viewport._tempMatrix4x4, out);
  6956. }
  6957. cloneTo(out) {
  6958. out.x = this.x;
  6959. out.y = this.y;
  6960. out.width = this.width;
  6961. out.height = this.height;
  6962. out.minDepth = this.minDepth;
  6963. out.maxDepth = this.maxDepth;
  6964. }
  6965. }
  6966. Viewport._tempMatrix4x4 = new Matrix4x4();
  6967. class RenderTexture extends Laya.BaseTexture {
  6968. constructor(width, height, format = Laya.BaseTexture.FORMAT_R8G8B8, depthStencilFormat = Laya.BaseTexture.FORMAT_DEPTH_16) {
  6969. super(format, false);
  6970. this._inPool = false;
  6971. this._glTextureType = Laya.LayaGL.instance.TEXTURE_2D;
  6972. this._width = width;
  6973. this._height = height;
  6974. this._depthStencilFormat = depthStencilFormat;
  6975. this._create(width, height);
  6976. }
  6977. static get currentActive() {
  6978. return RenderTexture._currentActive;
  6979. }
  6980. static createFromPool(width, height, format = Laya.BaseTexture.FORMAT_R8G8B8, depthStencilFormat = Laya.BaseTexture.FORMAT_DEPTH_16, filterMode = Laya.BaseTexture.FILTERMODE_BILINEAR) {
  6981. var tex;
  6982. for (var i = 0, n = RenderTexture._pool.length; i < n; i++) {
  6983. tex = RenderTexture._pool[i];
  6984. if (tex._width == width && tex._height == height && tex._format == format && tex._depthStencilFormat == depthStencilFormat && tex._filterMode == filterMode) {
  6985. tex._inPool = false;
  6986. var end = RenderTexture._pool[n - 1];
  6987. RenderTexture._pool[i] = end;
  6988. RenderTexture._pool.length -= 1;
  6989. return tex;
  6990. }
  6991. }
  6992. tex = new RenderTexture(width, height, format, depthStencilFormat);
  6993. tex.filterMode = filterMode;
  6994. tex.lock = true;
  6995. return tex;
  6996. }
  6997. static recoverToPool(renderTexture) {
  6998. if (renderTexture._inPool)
  6999. return;
  7000. RenderTexture._pool.push(renderTexture);
  7001. renderTexture._inPool = true;
  7002. }
  7003. get depthStencilFormat() {
  7004. return this._depthStencilFormat;
  7005. }
  7006. get defaulteTexture() {
  7007. return Laya.Texture2D.grayTexture;
  7008. }
  7009. _texImage2D(gl, glTextureType, width, height) {
  7010. switch (this._format) {
  7011. case Laya.BaseTexture.FORMAT_R8G8B8:
  7012. gl.texImage2D(glTextureType, 0, gl.RGB, width, height, 0, gl.RGB, gl.UNSIGNED_BYTE, null);
  7013. break;
  7014. case Laya.BaseTexture.FORMAT_R8G8B8A8:
  7015. gl.texImage2D(glTextureType, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  7016. break;
  7017. case Laya.BaseTexture.FORMAT_ALPHA8:
  7018. gl.texImage2D(glTextureType, 0, gl.ALPHA, width, height, 0, gl.ALPHA, gl.UNSIGNED_BYTE, null);
  7019. break;
  7020. case Laya.BaseTexture.RENDERTEXTURE_FORMAT_RGBA_HALF_FLOAT:
  7021. if (Laya.LayaGL.layaGPUInstance._isWebGL2)
  7022. gl.texImage2D(this._glTextureType, 0, gl.RGBA16F, width, height, 0, gl.RGBA, gl.HALF_FLOAT, null);
  7023. else
  7024. gl.texImage2D(this._glTextureType, 0, gl.RGBA, width, height, 0, gl.RGBA, Laya.LayaGL.layaGPUInstance._oesTextureHalfFloat.HALF_FLOAT_OES, null);
  7025. break;
  7026. default:
  7027. break;
  7028. }
  7029. }
  7030. _create(width, height) {
  7031. var gl = Laya.LayaGL.instance;
  7032. this._frameBuffer = gl.createFramebuffer();
  7033. Laya.WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  7034. this._texImage2D(gl, this._glTextureType, width, height);
  7035. this._setGPUMemory(width * height * 4);
  7036. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  7037. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, 0);
  7038. if (this._depthStencilFormat !== Laya.BaseTexture.FORMAT_DEPTHSTENCIL_NONE) {
  7039. this._depthStencilBuffer = gl.createRenderbuffer();
  7040. gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthStencilBuffer);
  7041. switch (this._depthStencilFormat) {
  7042. case Laya.BaseTexture.FORMAT_DEPTH_16:
  7043. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
  7044. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  7045. break;
  7046. case Laya.BaseTexture.FORMAT_STENCIL_8:
  7047. gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, width, height);
  7048. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  7049. break;
  7050. case Laya.BaseTexture.FORMAT_DEPTHSTENCIL_16_8:
  7051. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
  7052. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  7053. break;
  7054. default:
  7055. throw "RenderTexture: unkonw depth format.";
  7056. }
  7057. }
  7058. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  7059. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  7060. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  7061. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  7062. this._setFilterMode(this._filterMode);
  7063. this._setAnisotropy(this._anisoLevel);
  7064. this._readyed = true;
  7065. this._activeResource();
  7066. }
  7067. _start() {
  7068. var gl = Laya.LayaGL.instance;
  7069. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  7070. RenderTexture._currentActive = this;
  7071. this._readyed = false;
  7072. }
  7073. _end() {
  7074. var gl = Laya.LayaGL.instance;
  7075. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  7076. RenderTexture._currentActive = null;
  7077. this._readyed = true;
  7078. }
  7079. getData(x, y, width, height, out) {
  7080. if (Laya.Render.isConchApp && window.conchConfig.threadMode == 2) {
  7081. throw "native 2 thread mode use getDataAsync";
  7082. }
  7083. var gl = Laya.LayaGL.instance;
  7084. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  7085. var canRead = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE);
  7086. if (!canRead) {
  7087. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  7088. return null;
  7089. }
  7090. gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, out);
  7091. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  7092. return out;
  7093. }
  7094. getDataAsync(x, y, width, height, callBack) {
  7095. var gl = Laya.LayaGL.instance;
  7096. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  7097. gl.readPixelsAsync(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, function (data) {
  7098. callBack(new Uint8Array(data));
  7099. });
  7100. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  7101. }
  7102. _disposeResource() {
  7103. if (this._frameBuffer) {
  7104. var gl = Laya.LayaGL.instance;
  7105. gl.deleteTexture(this._glTexture);
  7106. gl.deleteFramebuffer(this._frameBuffer);
  7107. gl.deleteRenderbuffer(this._depthStencilBuffer);
  7108. this._glTexture = null;
  7109. this._frameBuffer = null;
  7110. this._depthStencilBuffer = null;
  7111. this._setGPUMemory(0);
  7112. }
  7113. }
  7114. }
  7115. RenderTexture._pool = [];
  7116. class Picker {
  7117. constructor() {
  7118. }
  7119. static calculateCursorRay(point, viewPort, projectionMatrix, viewMatrix, world, out) {
  7120. var x = point.x;
  7121. var y = point.y;
  7122. var nearSource = Picker._tempVector30;
  7123. var nerSourceE = nearSource;
  7124. nerSourceE.x = x;
  7125. nerSourceE.y = y;
  7126. nerSourceE.z = viewPort.minDepth;
  7127. var farSource = Picker._tempVector31;
  7128. var farSourceE = farSource;
  7129. farSourceE.x = x;
  7130. farSourceE.y = y;
  7131. farSourceE.z = viewPort.maxDepth;
  7132. var nearPoint = out.origin;
  7133. var farPoint = Picker._tempVector32;
  7134. viewPort.unprojectFromWVP(nearSource, projectionMatrix, viewMatrix, world, nearPoint);
  7135. viewPort.unprojectFromWVP(farSource, projectionMatrix, viewMatrix, world, farPoint);
  7136. var outDire = out.direction;
  7137. outDire.x = farPoint.x - nearPoint.x;
  7138. outDire.y = farPoint.y - nearPoint.y;
  7139. outDire.z = farPoint.z - nearPoint.z;
  7140. Vector3.normalize(out.direction, out.direction);
  7141. }
  7142. static rayIntersectsTriangle(ray, vertex1, vertex2, vertex3) {
  7143. var result;
  7144. var edge1 = Picker._tempVector30, edge2 = Picker._tempVector31;
  7145. Vector3.subtract(vertex2, vertex1, edge1);
  7146. Vector3.subtract(vertex3, vertex1, edge2);
  7147. var directionCrossEdge2 = Picker._tempVector32;
  7148. Vector3.cross(ray.direction, edge2, directionCrossEdge2);
  7149. var determinant;
  7150. determinant = Vector3.dot(edge1, directionCrossEdge2);
  7151. if (determinant > -Number.MIN_VALUE && determinant < Number.MIN_VALUE) {
  7152. result = Number.NaN;
  7153. return result;
  7154. }
  7155. var inverseDeterminant = 1.0 / determinant;
  7156. var distanceVector = Picker._tempVector33;
  7157. Vector3.subtract(ray.origin, vertex1, distanceVector);
  7158. var triangleU;
  7159. triangleU = Vector3.dot(distanceVector, directionCrossEdge2);
  7160. triangleU *= inverseDeterminant;
  7161. if (triangleU < 0 || triangleU > 1) {
  7162. result = Number.NaN;
  7163. return result;
  7164. }
  7165. var distanceCrossEdge1 = Picker._tempVector34;
  7166. Vector3.cross(distanceVector, edge1, distanceCrossEdge1);
  7167. var triangleV;
  7168. triangleV = Vector3.dot(ray.direction, distanceCrossEdge1);
  7169. triangleV *= inverseDeterminant;
  7170. if (triangleV < 0 || triangleU + triangleV > 1) {
  7171. result = Number.NaN;
  7172. return result;
  7173. }
  7174. var rayDistance;
  7175. rayDistance = Vector3.dot(edge2, distanceCrossEdge1);
  7176. rayDistance *= inverseDeterminant;
  7177. if (rayDistance < 0) {
  7178. result = Number.NaN;
  7179. return result;
  7180. }
  7181. result = rayDistance;
  7182. return result;
  7183. }
  7184. }
  7185. Picker._tempVector30 = new Vector3();
  7186. Picker._tempVector31 = new Vector3();
  7187. Picker._tempVector32 = new Vector3();
  7188. Picker._tempVector33 = new Vector3();
  7189. Picker._tempVector34 = new Vector3();
  7190. class SkyMesh {
  7191. constructor() {
  7192. }
  7193. _render(state) {
  7194. }
  7195. }
  7196. class SkyBox extends SkyMesh {
  7197. static __init__() {
  7198. SkyBox.instance = new SkyBox();
  7199. }
  7200. constructor() {
  7201. super();
  7202. var gl = Laya.LayaGL.instance;
  7203. var halfHeight = 1.0;
  7204. var halfWidth = 1.0;
  7205. var halfDepth = 1.0;
  7206. var vertices = new Float32Array([-halfDepth, halfHeight, -halfWidth, halfDepth, halfHeight, -halfWidth, halfDepth, halfHeight, halfWidth, -halfDepth, halfHeight, halfWidth,
  7207. -halfDepth, -halfHeight, -halfWidth, halfDepth, -halfHeight, -halfWidth, halfDepth, -halfHeight, halfWidth, -halfDepth, -halfHeight, halfWidth]);
  7208. var indices = new Uint8Array([
  7209. 0, 1, 2, 2, 3, 0,
  7210. 4, 7, 6, 6, 5, 4,
  7211. 0, 3, 7, 7, 4, 0,
  7212. 1, 5, 6, 6, 2, 1,
  7213. 3, 2, 6, 6, 7, 3,
  7214. 0, 4, 5, 5, 1, 0
  7215. ]);
  7216. var verDec = VertexMesh.getVertexDeclaration("POSITION");
  7217. this._vertexBuffer = new VertexBuffer3D(verDec.vertexStride * 8, gl.STATIC_DRAW, false);
  7218. this._vertexBuffer.vertexDeclaration = verDec;
  7219. this._indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_UBYTE, 36, gl.STATIC_DRAW, false);
  7220. this._vertexBuffer.setData(vertices.buffer);
  7221. this._indexBuffer.setData(indices);
  7222. var bufferState = new BufferState();
  7223. bufferState.bind();
  7224. bufferState.applyVertexBuffer(this._vertexBuffer);
  7225. bufferState.applyIndexBuffer(this._indexBuffer);
  7226. bufferState.unBind();
  7227. this._bufferState = bufferState;
  7228. }
  7229. _render(state) {
  7230. var gl = Laya.LayaGL.instance;
  7231. gl.drawElements(gl.TRIANGLES, 36, gl.UNSIGNED_BYTE, 0);
  7232. Laya.Stat.trianglesFaces += 12;
  7233. Laya.Stat.renderBatches++;
  7234. }
  7235. }
  7236. class SkyRenderer {
  7237. constructor() {
  7238. this._mesh = SkyBox.instance;
  7239. }
  7240. get material() {
  7241. return this._material;
  7242. }
  7243. set material(value) {
  7244. if (this._material !== value) {
  7245. (this._material) && (this._material._removeReference());
  7246. (value) && (value._addReference());
  7247. this._material = value;
  7248. }
  7249. }
  7250. get mesh() {
  7251. return this._mesh;
  7252. }
  7253. set mesh(value) {
  7254. if (this._mesh !== value) {
  7255. this._mesh = value;
  7256. }
  7257. }
  7258. _isAvailable() {
  7259. return this._material && this._mesh ? true : false;
  7260. }
  7261. _render(state) {
  7262. if (this._material && this._mesh) {
  7263. var gl = Laya.LayaGL.instance;
  7264. var scene = state.scene;
  7265. var camera = state.camera;
  7266. var noteValue = ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_;
  7267. Laya.ILaya.Render.supportWebGLPlusRendering && ShaderData.setRuntimeValueMode(false);
  7268. Laya.WebGLContext.setCullFace(gl, false);
  7269. Laya.WebGLContext.setDepthFunc(gl, gl.LEQUAL);
  7270. Laya.WebGLContext.setDepthMask(gl, false);
  7271. var shader = state.shader = this._material._shader.getSubShaderAt(0)._passes[0].withCompile(0, 0, this._material._shaderValues._defineDatas.value);
  7272. var switchShader = shader.bind();
  7273. var switchShaderLoop = (Laya.Stat.loopCount !== shader._uploadMark);
  7274. var uploadScene = (shader._uploadScene !== scene) || switchShaderLoop;
  7275. if (uploadScene || switchShader) {
  7276. shader.uploadUniforms(shader._sceneUniformParamsMap, scene._shaderValues, uploadScene);
  7277. shader._uploadScene = scene;
  7278. }
  7279. var renderTar = camera._renderTexture || camera._offScreenRenderTexture;
  7280. var uploadCamera = (shader._uploadCamera !== camera) || switchShaderLoop;
  7281. if (uploadCamera || switchShader) {
  7282. var viewMatrix = SkyRenderer._tempMatrix0;
  7283. var projectionMatrix = camera.projectionMatrix;
  7284. camera.transform.worldMatrix.cloneTo(viewMatrix);
  7285. viewMatrix.transpose();
  7286. if (camera.orthographic) {
  7287. projectionMatrix = SkyRenderer._tempMatrix1;
  7288. Matrix4x4.createPerspective(camera.fieldOfView, camera.aspectRatio, camera.nearPlane, camera.farPlane, projectionMatrix);
  7289. }
  7290. camera._applyViewProject(state, viewMatrix, projectionMatrix, renderTar ? true : false);
  7291. shader.uploadUniforms(shader._cameraUniformParamsMap, camera._shaderValues, uploadCamera);
  7292. shader._uploadCamera = camera;
  7293. }
  7294. var uploadMaterial = (shader._uploadMaterial !== this._material) || switchShaderLoop;
  7295. if (uploadMaterial || switchShader) {
  7296. shader.uploadUniforms(shader._materialUniformParamsMap, this._material._shaderValues, uploadMaterial);
  7297. shader._uploadMaterial = this._material;
  7298. }
  7299. this._mesh._bufferState.bind();
  7300. this._mesh._render(state);
  7301. Laya.ILaya.Render.supportWebGLPlusRendering && ShaderData.setRuntimeValueMode(noteValue);
  7302. Laya.WebGLContext.setDepthFunc(gl, gl.LESS);
  7303. Laya.WebGLContext.setDepthMask(gl, true);
  7304. camera._applyViewProject(state, camera.viewMatrix, camera.projectionMatrix, renderTar ? true : false);
  7305. }
  7306. }
  7307. destroy() {
  7308. if (this._material) {
  7309. this._material._removeReference();
  7310. this._material = null;
  7311. }
  7312. }
  7313. }
  7314. SkyRenderer._tempMatrix0 = new Matrix4x4();
  7315. SkyRenderer._tempMatrix1 = new Matrix4x4();
  7316. class BaseCamera extends Sprite3D {
  7317. constructor(nearPlane = 0.3, farPlane = 1000) {
  7318. super();
  7319. this._skyRenderer = new SkyRenderer();
  7320. this._forward = new Vector3();
  7321. this._up = new Vector3();
  7322. this.clearColor = new Vector4(100 / 255, 149 / 255, 237 / 255, 255 / 255);
  7323. this._shaderValues = new ShaderData(null);
  7324. this._fieldOfView = 60;
  7325. this._useUserProjectionMatrix = false;
  7326. this._orthographic = false;
  7327. this._orthographicVerticalSize = 10;
  7328. this.renderingOrder = 0;
  7329. this._nearPlane = nearPlane;
  7330. this._farPlane = farPlane;
  7331. this.cullingMask = 2147483647;
  7332. this.clearFlag = BaseCamera.CLEARFLAG_SOLIDCOLOR;
  7333. this.useOcclusionCulling = true;
  7334. }
  7335. get skyRenderer() {
  7336. return this._skyRenderer;
  7337. }
  7338. get fieldOfView() {
  7339. return this._fieldOfView;
  7340. }
  7341. set fieldOfView(value) {
  7342. this._fieldOfView = value;
  7343. this._calculateProjectionMatrix();
  7344. }
  7345. get nearPlane() {
  7346. return this._nearPlane;
  7347. }
  7348. set nearPlane(value) {
  7349. this._nearPlane = value;
  7350. this._calculateProjectionMatrix();
  7351. }
  7352. get farPlane() {
  7353. return this._farPlane;
  7354. }
  7355. set farPlane(vaule) {
  7356. this._farPlane = vaule;
  7357. this._calculateProjectionMatrix();
  7358. }
  7359. get orthographic() {
  7360. return this._orthographic;
  7361. }
  7362. set orthographic(vaule) {
  7363. this._orthographic = vaule;
  7364. this._calculateProjectionMatrix();
  7365. }
  7366. get orthographicVerticalSize() {
  7367. return this._orthographicVerticalSize;
  7368. }
  7369. set orthographicVerticalSize(vaule) {
  7370. this._orthographicVerticalSize = vaule;
  7371. this._calculateProjectionMatrix();
  7372. }
  7373. get renderingOrder() {
  7374. return this._renderingOrder;
  7375. }
  7376. set renderingOrder(value) {
  7377. this._renderingOrder = value;
  7378. this._sortCamerasByRenderingOrder();
  7379. }
  7380. _sortCamerasByRenderingOrder() {
  7381. if (this.displayedInStage) {
  7382. var cameraPool = this.scene._cameraPool;
  7383. var n = cameraPool.length - 1;
  7384. for (var i = 0; i < n; i++) {
  7385. if (cameraPool[i].renderingOrder > cameraPool[n].renderingOrder) {
  7386. var tempCamera = cameraPool[i];
  7387. cameraPool[i] = cameraPool[n];
  7388. cameraPool[n] = tempCamera;
  7389. }
  7390. }
  7391. }
  7392. }
  7393. _calculateProjectionMatrix() {
  7394. }
  7395. _onScreenSizeChanged() {
  7396. this._calculateProjectionMatrix();
  7397. }
  7398. _prepareCameraToRender() {
  7399. var cameraSV = this._shaderValues;
  7400. this.transform.getForward(this._forward);
  7401. this.transform.getUp(this._up);
  7402. cameraSV.setVector3(BaseCamera.CAMERAPOS, this.transform.position);
  7403. cameraSV.setVector3(BaseCamera.CAMERADIRECTION, this._forward);
  7404. cameraSV.setVector3(BaseCamera.CAMERAUP, this._up);
  7405. }
  7406. render(shader = null, replacementTag = null) {
  7407. }
  7408. addLayer(layer) {
  7409. this.cullingMask |= Math.pow(2, layer);
  7410. }
  7411. removeLayer(layer) {
  7412. this.cullingMask &= ~Math.pow(2, layer);
  7413. }
  7414. addAllLayers() {
  7415. this.cullingMask = 2147483647;
  7416. }
  7417. removeAllLayers() {
  7418. this.cullingMask = 0;
  7419. }
  7420. resetProjectionMatrix() {
  7421. this._useUserProjectionMatrix = false;
  7422. this._calculateProjectionMatrix();
  7423. }
  7424. _onActive() {
  7425. this._scene._addCamera(this);
  7426. super._onActive();
  7427. }
  7428. _onInActive() {
  7429. this._scene._removeCamera(this);
  7430. super._onInActive();
  7431. }
  7432. _parse(data, spriteMap) {
  7433. super._parse(data, spriteMap);
  7434. var clearFlagData = data.clearFlag;
  7435. (clearFlagData !== undefined) && (this.clearFlag = clearFlagData);
  7436. this.orthographic = data.orthographic;
  7437. (data.orthographicVerticalSize !== undefined) && (this.orthographicVerticalSize = data.orthographicVerticalSize);
  7438. (data.fieldOfView !== undefined) && (this.fieldOfView = data.fieldOfView);
  7439. this.nearPlane = data.nearPlane;
  7440. this.farPlane = data.farPlane;
  7441. var color = data.clearColor;
  7442. this.clearColor = new Vector4(color[0], color[1], color[2], color[3]);
  7443. var skyboxMaterial = data.skyboxMaterial;
  7444. if (skyboxMaterial) {
  7445. this._skyRenderer.material = Laya.Loader.getRes(skyboxMaterial.path);
  7446. }
  7447. }
  7448. destroy(destroyChild = true) {
  7449. this._skyRenderer.destroy();
  7450. this._skyRenderer = null;
  7451. Laya.Laya.stage.off(Laya.Event.RESIZE, this, this._onScreenSizeChanged);
  7452. super.destroy(destroyChild);
  7453. }
  7454. _create() {
  7455. return new BaseCamera();
  7456. }
  7457. }
  7458. BaseCamera._tempMatrix4x40 = new Matrix4x4();
  7459. BaseCamera.CAMERAPOS = Shader3D.propertyNameToID("u_CameraPos");
  7460. BaseCamera.VIEWMATRIX = Shader3D.propertyNameToID("u_View");
  7461. BaseCamera.PROJECTMATRIX = Shader3D.propertyNameToID("u_Projection");
  7462. BaseCamera.VIEWPROJECTMATRIX = Shader3D.propertyNameToID("u_ViewProjection");
  7463. BaseCamera.CAMERADIRECTION = Shader3D.propertyNameToID("u_CameraDirection");
  7464. BaseCamera.CAMERAUP = Shader3D.propertyNameToID("u_CameraUp");
  7465. BaseCamera.RENDERINGTYPE_DEFERREDLIGHTING = "DEFERREDLIGHTING";
  7466. BaseCamera.RENDERINGTYPE_FORWARDRENDERING = "FORWARDRENDERING";
  7467. BaseCamera.CLEARFLAG_SOLIDCOLOR = 0;
  7468. BaseCamera.CLEARFLAG_SKY = 1;
  7469. BaseCamera.CLEARFLAG_DEPTHONLY = 2;
  7470. BaseCamera.CLEARFLAG_NONE = 3;
  7471. BaseCamera._invertYScaleMatrix = new Matrix4x4(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  7472. BaseCamera._invertYProjectionMatrix = new Matrix4x4();
  7473. BaseCamera._invertYProjectionViewMatrix = new Matrix4x4();
  7474. class RenderContext3D {
  7475. constructor() {
  7476. }
  7477. }
  7478. RenderContext3D._instance = new RenderContext3D();
  7479. class ScreenQuad extends Laya.Resource {
  7480. constructor() {
  7481. super();
  7482. this._bufferState = new BufferState();
  7483. this._bufferStateInvertUV = new BufferState();
  7484. var gl = Laya.LayaGL.instance;
  7485. this._vertexBuffer = new VertexBuffer3D(16 * 4, gl.STATIC_DRAW, false);
  7486. this._vertexBuffer.vertexDeclaration = ScreenQuad._vertexDeclaration;
  7487. this._vertexBuffer.setData(ScreenQuad._vertices.buffer);
  7488. this._bufferState.bind();
  7489. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  7490. this._bufferState.unBind();
  7491. this._vertexBufferInvertUV = new VertexBuffer3D(16 * 4, gl.STATIC_DRAW, false);
  7492. this._vertexBufferInvertUV.vertexDeclaration = ScreenQuad._vertexDeclaration;
  7493. this._vertexBufferInvertUV.setData(ScreenQuad._verticesInvertUV.buffer);
  7494. this._bufferStateInvertUV.bind();
  7495. this._bufferStateInvertUV.applyVertexBuffer(this._vertexBufferInvertUV);
  7496. this._bufferStateInvertUV.unBind();
  7497. this._setGPUMemory(this._vertexBuffer._byteLength + this._vertexBufferInvertUV._byteLength);
  7498. }
  7499. static __init__() {
  7500. ScreenQuad._vertexDeclaration = new VertexDeclaration(16, [new VertexElement(0, VertexElementFormat.Vector4, ScreenQuad.SCREENQUAD_POSITION_UV)]);
  7501. ScreenQuad.instance = new ScreenQuad();
  7502. ScreenQuad.instance.lock = true;
  7503. }
  7504. render() {
  7505. var gl = Laya.LayaGL.instance;
  7506. this._bufferState.bind();
  7507. gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  7508. Laya.Stat.renderBatches++;
  7509. }
  7510. renderInvertUV() {
  7511. var gl = Laya.LayaGL.instance;
  7512. this._bufferStateInvertUV.bind();
  7513. gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  7514. Laya.Stat.renderBatches++;
  7515. }
  7516. destroy() {
  7517. super.destroy();
  7518. this._bufferState.destroy();
  7519. this._vertexBuffer.destroy();
  7520. this._bufferStateInvertUV.destroy();
  7521. this._vertexBufferInvertUV.destroy();
  7522. this._setGPUMemory(0);
  7523. }
  7524. }
  7525. ScreenQuad.SCREENQUAD_POSITION_UV = 0;
  7526. ScreenQuad._vertices = new Float32Array([1, 1, 1, 0, 1, -1, 1, 1, -1, 1, 0, 0, -1, -1, 0, 1]);
  7527. ScreenQuad._verticesInvertUV = new Float32Array([1, 1, 1, 1, 1, -1, 1, 0, -1, 1, 0, 1, -1, -1, 0, 0]);
  7528. class ScreenTriangle extends Laya.Resource {
  7529. constructor() {
  7530. super();
  7531. this._bufferState = new BufferState();
  7532. this._bufferStateInvertUV = new BufferState();
  7533. var gl = Laya.LayaGL.instance;
  7534. this._vertexBuffer = new VertexBuffer3D(12 * 4, gl.STATIC_DRAW, false);
  7535. this._vertexBuffer.vertexDeclaration = ScreenTriangle._vertexDeclaration;
  7536. this._vertexBuffer.setData(ScreenTriangle._vertices.buffer);
  7537. this._bufferState.bind();
  7538. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  7539. this._bufferState.unBind();
  7540. this._vertexBufferInvertUV = new VertexBuffer3D(12 * 4, gl.STATIC_DRAW, false);
  7541. this._vertexBufferInvertUV.vertexDeclaration = ScreenTriangle._vertexDeclaration;
  7542. this._vertexBufferInvertUV.setData(ScreenTriangle._verticesInvertUV.buffer);
  7543. this._bufferStateInvertUV.bind();
  7544. this._bufferStateInvertUV.applyVertexBuffer(this._vertexBufferInvertUV);
  7545. this._bufferStateInvertUV.unBind();
  7546. this._setGPUMemory(this._vertexBuffer._byteLength + this._vertexBufferInvertUV._byteLength);
  7547. }
  7548. static __init__() {
  7549. ScreenTriangle._vertexDeclaration = new VertexDeclaration(16, [new VertexElement(0, VertexElementFormat.Vector4, ScreenTriangle.SCREENTRIANGLE_POSITION_UV)]);
  7550. ScreenTriangle.instance = new ScreenTriangle();
  7551. ScreenTriangle.instance.lock = true;
  7552. }
  7553. render() {
  7554. var gl = Laya.LayaGL.instance;
  7555. this._bufferState.bind();
  7556. gl.drawArrays(gl.TRIANGLES, 0, 3);
  7557. Laya.Stat.renderBatches++;
  7558. }
  7559. renderInvertUV() {
  7560. var gl = Laya.LayaGL.instance;
  7561. this._bufferStateInvertUV.bind();
  7562. gl.drawArrays(gl.TRIANGLES, 0, 3);
  7563. Laya.Stat.renderBatches++;
  7564. }
  7565. destroy() {
  7566. super.destroy();
  7567. this._bufferState.destroy();
  7568. this._vertexBuffer.destroy();
  7569. this._bufferStateInvertUV.destroy();
  7570. this._vertexBufferInvertUV.destroy();
  7571. this._setGPUMemory(0);
  7572. }
  7573. }
  7574. ScreenTriangle.SCREENTRIANGLE_POSITION_UV = 0;
  7575. ScreenTriangle._vertices = new Float32Array([-1, -1, 0, 1, -1, 3, 0, -1, 3, -1, 2, 1]);
  7576. ScreenTriangle._verticesInvertUV = new Float32Array([-1, -1, 0, 0, -1, 3, 0, 2, 3, -1, 2, 0]);
  7577. class Command {
  7578. constructor() {
  7579. this._commandBuffer = null;
  7580. }
  7581. static __init__() {
  7582. Command._screenShaderData = new ShaderData();
  7583. Command._screenShader = Shader3D.find("BlitScreen");
  7584. }
  7585. run() {
  7586. }
  7587. recover() {
  7588. this._commandBuffer = null;
  7589. }
  7590. }
  7591. Command.SCREENTEXTURE_NAME = "u_MainTex";
  7592. Command.MAINTEXTURE_TEXELSIZE_NAME = "u_MainTex_TexelSize";
  7593. Command.SCREENTEXTURE_ID = Shader3D.propertyNameToID(Command.SCREENTEXTURE_NAME);
  7594. Command.MAINTEXTURE_TEXELSIZE_ID = Shader3D.propertyNameToID(Command.MAINTEXTURE_TEXELSIZE_NAME);
  7595. class BlitScreenQuadCMD extends Command {
  7596. constructor() {
  7597. super(...arguments);
  7598. this._source = null;
  7599. this._dest = null;
  7600. this._shader = null;
  7601. this._shaderData = null;
  7602. this._subShader = 0;
  7603. this._sourceTexelSize = new Vector4();
  7604. this._screenType = 0;
  7605. }
  7606. static create(source, dest, shader = null, shaderData = null, subShader = 0, screenType = BlitScreenQuadCMD._SCREENTYPE_QUAD) {
  7607. var cmd;
  7608. cmd = BlitScreenQuadCMD._pool.length > 0 ? BlitScreenQuadCMD._pool.pop() : new BlitScreenQuadCMD();
  7609. cmd._source = source;
  7610. cmd._dest = dest;
  7611. cmd._shader = shader;
  7612. cmd._shaderData = shaderData;
  7613. cmd._subShader = subShader;
  7614. cmd._screenType = screenType;
  7615. return cmd;
  7616. }
  7617. run() {
  7618. var shader = this._shader || Command._screenShader;
  7619. var shaderData = this._shaderData || Command._screenShaderData;
  7620. var dest = this._dest;
  7621. Laya.LayaGL.instance.viewport(0, 0, dest ? dest.width : RenderContext3D.clientWidth, dest ? dest.height : RenderContext3D.clientHeight);
  7622. shaderData.setTexture(Command.SCREENTEXTURE_ID, this._source);
  7623. this._sourceTexelSize.setValue(1.0 / this._source.width, 1.0 / this._source.height, this._source.width, this._source.height);
  7624. shaderData.setVector(Command.MAINTEXTURE_TEXELSIZE_ID, this._sourceTexelSize);
  7625. (dest) && (dest._start());
  7626. var subShader = shader.getSubShaderAt(this._subShader);
  7627. var passes = subShader._passes;
  7628. for (var i = 0, n = passes.length; i < n; i++) {
  7629. var shaderPass = passes[i].withCompile(0, 0, shaderData._defineDatas.value);
  7630. shaderPass.bind();
  7631. shaderPass.uploadUniforms(shaderPass._materialUniformParamsMap, shaderData, true);
  7632. shaderPass.uploadRenderStateBlendDepth(shaderData);
  7633. shaderPass.uploadRenderStateFrontFace(shaderData, false, null);
  7634. switch (this._screenType) {
  7635. case BlitScreenQuadCMD._SCREENTYPE_QUAD:
  7636. dest ? ScreenQuad.instance.renderInvertUV() : ScreenQuad.instance.render();
  7637. break;
  7638. case BlitScreenQuadCMD._SCREENTYPE_TRIANGLE:
  7639. dest ? ScreenTriangle.instance.renderInvertUV() : ScreenTriangle.instance.render();
  7640. break;
  7641. throw "BlitScreenQuadCMD:unknown screen Type.";
  7642. }
  7643. }
  7644. (dest) && (dest._end());
  7645. }
  7646. recover() {
  7647. BlitScreenQuadCMD._pool.push(this);
  7648. this._dest = null;
  7649. this._shader = null;
  7650. this._shaderData = null;
  7651. super.recover();
  7652. }
  7653. }
  7654. BlitScreenQuadCMD._SCREENTYPE_QUAD = 0;
  7655. BlitScreenQuadCMD._SCREENTYPE_TRIANGLE = 1;
  7656. BlitScreenQuadCMD._pool = [];
  7657. class SetRenderTargetCMD extends Command {
  7658. constructor() {
  7659. super(...arguments);
  7660. this._renderTexture = null;
  7661. }
  7662. static create(renderTexture) {
  7663. var cmd;
  7664. cmd = SetRenderTargetCMD._pool.length > 0 ? SetRenderTargetCMD._pool.pop() : new SetRenderTargetCMD();
  7665. cmd._renderTexture = renderTexture;
  7666. return cmd;
  7667. }
  7668. run() {
  7669. this._renderTexture._start();
  7670. }
  7671. recover() {
  7672. SetRenderTargetCMD._pool.push(this);
  7673. this._renderTexture = null;
  7674. }
  7675. }
  7676. SetRenderTargetCMD._pool = [];
  7677. class SetShaderDataTextureCMD extends Command {
  7678. constructor() {
  7679. super(...arguments);
  7680. this._shaderData = null;
  7681. this._nameID = 0;
  7682. this._texture = null;
  7683. }
  7684. static create(shaderData, nameID, texture) {
  7685. var cmd;
  7686. cmd = SetShaderDataTextureCMD._pool.length > 0 ? SetShaderDataTextureCMD._pool.pop() : new SetShaderDataTextureCMD();
  7687. cmd._shaderData = shaderData;
  7688. cmd._nameID = nameID;
  7689. cmd._texture = texture;
  7690. return cmd;
  7691. }
  7692. run() {
  7693. this._shaderData.setTexture(this._nameID, this._texture);
  7694. }
  7695. recover() {
  7696. SetShaderDataTextureCMD._pool.push(this);
  7697. this._shaderData = null;
  7698. this._nameID = 0;
  7699. this._texture = null;
  7700. }
  7701. }
  7702. SetShaderDataTextureCMD._pool = [];
  7703. class CommandBuffer {
  7704. constructor() {
  7705. this._camera = null;
  7706. this._commands = [];
  7707. }
  7708. _apply() {
  7709. for (var i = 0, n = this._commands.length; i < n; i++)
  7710. this._commands[i].run();
  7711. }
  7712. setShaderDataTexture(shaderData, nameID, source) {
  7713. this._commands.push(SetShaderDataTextureCMD.create(shaderData, nameID, source));
  7714. }
  7715. blitScreenQuad(source, dest, shader = null, shaderData = null, subShader = 0) {
  7716. this._commands.push(BlitScreenQuadCMD.create(source, dest, shader, shaderData, subShader, BlitScreenQuadCMD._SCREENTYPE_QUAD));
  7717. }
  7718. blitScreenTriangle(source, dest, shader = null, shaderData = null, subShader = 0) {
  7719. this._commands.push(BlitScreenQuadCMD.create(source, dest, shader, shaderData, subShader, BlitScreenQuadCMD._SCREENTYPE_TRIANGLE));
  7720. }
  7721. setRenderTarget(renderTexture) {
  7722. this._commands.push(SetRenderTargetCMD.create(renderTexture));
  7723. }
  7724. clear() {
  7725. for (var i = 0, n = this._commands.length; i < n; i++)
  7726. this._commands[i].recover();
  7727. this._commands.length = 0;
  7728. }
  7729. }
  7730. class Scene3DShaderDeclaration {
  7731. }
  7732. class Camera extends BaseCamera {
  7733. constructor(aspectRatio = 0, nearPlane = 0.3, farPlane = 1000) {
  7734. super(nearPlane, farPlane);
  7735. this._updateViewMatrix = true;
  7736. this._offScreenRenderTexture = null;
  7737. this._postProcess = null;
  7738. this._enableHDR = false;
  7739. this._renderTexture = null;
  7740. this._postProcessCommandBuffers = [];
  7741. this.enableRender = true;
  7742. this._viewMatrix = new Matrix4x4();
  7743. this._projectionMatrix = new Matrix4x4();
  7744. this._projectionViewMatrix = new Matrix4x4();
  7745. this._viewport = new Viewport(0, 0, 0, 0);
  7746. this._normalizedViewport = new Viewport(0, 0, 1, 1);
  7747. this._aspectRatio = aspectRatio;
  7748. this._boundFrustum = new BoundFrustum(Matrix4x4.DEFAULT);
  7749. if (Laya.Render.supportWebGLPlusCulling)
  7750. this._boundFrustumBuffer = new Float32Array(24);
  7751. this._calculateProjectionMatrix();
  7752. Laya.Laya.stage.on(Laya.Event.RESIZE, this, this._onScreenSizeChanged);
  7753. this.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onTransformChanged);
  7754. }
  7755. get aspectRatio() {
  7756. if (this._aspectRatio === 0) {
  7757. var vp = this.viewport;
  7758. return vp.width / vp.height;
  7759. }
  7760. return this._aspectRatio;
  7761. }
  7762. set aspectRatio(value) {
  7763. if (value < 0)
  7764. throw new Error("Camera: the aspect ratio has to be a positive real number.");
  7765. this._aspectRatio = value;
  7766. this._calculateProjectionMatrix();
  7767. }
  7768. get viewport() {
  7769. if (this._offScreenRenderTexture)
  7770. this._calculationViewport(this._normalizedViewport, this._offScreenRenderTexture.width, this._offScreenRenderTexture.height);
  7771. else
  7772. this._calculationViewport(this._normalizedViewport, RenderContext3D.clientWidth, RenderContext3D.clientHeight);
  7773. return this._viewport;
  7774. }
  7775. set viewport(value) {
  7776. var width;
  7777. var height;
  7778. if (this._offScreenRenderTexture) {
  7779. width = this._offScreenRenderTexture.width;
  7780. height = this._offScreenRenderTexture.height;
  7781. }
  7782. else {
  7783. width = RenderContext3D.clientWidth;
  7784. height = RenderContext3D.clientHeight;
  7785. }
  7786. this._normalizedViewport.x = value.x / width;
  7787. this._normalizedViewport.y = value.y / height;
  7788. this._normalizedViewport.width = value.width / width;
  7789. this._normalizedViewport.height = value.height / height;
  7790. this._calculationViewport(this._normalizedViewport, width, height);
  7791. this._calculateProjectionMatrix();
  7792. }
  7793. get normalizedViewport() {
  7794. return this._normalizedViewport;
  7795. }
  7796. set normalizedViewport(value) {
  7797. var width;
  7798. var height;
  7799. if (this._offScreenRenderTexture) {
  7800. width = this._offScreenRenderTexture.width;
  7801. height = this._offScreenRenderTexture.height;
  7802. }
  7803. else {
  7804. width = RenderContext3D.clientWidth;
  7805. height = RenderContext3D.clientHeight;
  7806. }
  7807. if (this._normalizedViewport !== value)
  7808. value.cloneTo(this._normalizedViewport);
  7809. this._calculationViewport(value, width, height);
  7810. this._calculateProjectionMatrix();
  7811. }
  7812. get viewMatrix() {
  7813. if (this._updateViewMatrix) {
  7814. var scale = this.transform.getWorldLossyScale();
  7815. var scaleX = scale.x;
  7816. var scaleY = scale.y;
  7817. var scaleZ = scale.z;
  7818. var viewMatE = this._viewMatrix.elements;
  7819. this.transform.worldMatrix.cloneTo(this._viewMatrix);
  7820. viewMatE[0] /= scaleX;
  7821. viewMatE[1] /= scaleX;
  7822. viewMatE[2] /= scaleX;
  7823. viewMatE[4] /= scaleY;
  7824. viewMatE[5] /= scaleY;
  7825. viewMatE[6] /= scaleY;
  7826. viewMatE[8] /= scaleZ;
  7827. viewMatE[9] /= scaleZ;
  7828. viewMatE[10] /= scaleZ;
  7829. this._viewMatrix.invert(this._viewMatrix);
  7830. this._updateViewMatrix = false;
  7831. }
  7832. return this._viewMatrix;
  7833. }
  7834. get projectionMatrix() {
  7835. return this._projectionMatrix;
  7836. }
  7837. set projectionMatrix(value) {
  7838. this._projectionMatrix = value;
  7839. this._useUserProjectionMatrix = true;
  7840. }
  7841. get projectionViewMatrix() {
  7842. Matrix4x4.multiply(this.projectionMatrix, this.viewMatrix, this._projectionViewMatrix);
  7843. return this._projectionViewMatrix;
  7844. }
  7845. get boundFrustum() {
  7846. this._boundFrustum.matrix = this.projectionViewMatrix;
  7847. if (Laya.Render.supportWebGLPlusCulling) {
  7848. var near = this._boundFrustum.near;
  7849. var far = this._boundFrustum.far;
  7850. var left = this._boundFrustum.left;
  7851. var right = this._boundFrustum.right;
  7852. var top = this._boundFrustum.top;
  7853. var bottom = this._boundFrustum.bottom;
  7854. var nearNE = near.normal;
  7855. var farNE = far.normal;
  7856. var leftNE = left.normal;
  7857. var rightNE = right.normal;
  7858. var topNE = top.normal;
  7859. var bottomNE = bottom.normal;
  7860. var buffer = this._boundFrustumBuffer;
  7861. buffer[0] = nearNE.x, buffer[1] = nearNE.y, buffer[2] = nearNE.z, buffer[3] = near.distance;
  7862. buffer[4] = farNE.x, buffer[5] = farNE.y, buffer[6] = farNE.z, buffer[7] = far.distance;
  7863. buffer[8] = leftNE.x, buffer[9] = leftNE.y, buffer[10] = leftNE.z, buffer[11] = left.distance;
  7864. buffer[12] = rightNE.x, buffer[13] = rightNE.y, buffer[14] = rightNE.z, buffer[15] = right.distance;
  7865. buffer[16] = topNE.x, buffer[17] = topNE.y, buffer[18] = topNE.z, buffer[19] = top.distance;
  7866. buffer[20] = bottomNE.x, buffer[21] = bottomNE.y, buffer[22] = bottomNE.z, buffer[23] = bottom.distance;
  7867. }
  7868. return this._boundFrustum;
  7869. }
  7870. get renderTarget() {
  7871. return this._offScreenRenderTexture;
  7872. }
  7873. set renderTarget(value) {
  7874. if (this._offScreenRenderTexture !== value) {
  7875. this._offScreenRenderTexture = value;
  7876. this._calculateProjectionMatrix();
  7877. }
  7878. }
  7879. get postProcess() {
  7880. return this._postProcess;
  7881. }
  7882. set postProcess(value) {
  7883. this._postProcess = value;
  7884. var postProcessCommandBuffer = new CommandBuffer();
  7885. this.addCommandBuffer(Camera.CAMERAEVENT_POSTPROCESS, postProcessCommandBuffer);
  7886. value._init(this, postProcessCommandBuffer);
  7887. }
  7888. get enableHDR() {
  7889. return this._enableHDR;
  7890. }
  7891. set enableHDR(value) {
  7892. this._enableHDR = value;
  7893. }
  7894. _isLayerVisible(layer) {
  7895. return (Math.pow(2, layer) & this.cullingMask) != 0;
  7896. }
  7897. _onTransformChanged(flag) {
  7898. flag &= Transform3D.TRANSFORM_WORLDMATRIX;
  7899. (flag) && (this._updateViewMatrix = true);
  7900. }
  7901. _calculationViewport(normalizedViewport, width, height) {
  7902. var lx = normalizedViewport.x * width;
  7903. var ly = normalizedViewport.y * height;
  7904. var rx = lx + Math.max(normalizedViewport.width * width, 0);
  7905. var ry = ly + Math.max(normalizedViewport.height * height, 0);
  7906. var ceilLeftX = Math.ceil(lx);
  7907. var ceilLeftY = Math.ceil(ly);
  7908. var floorRightX = Math.floor(rx);
  7909. var floorRightY = Math.floor(ry);
  7910. var pixelLeftX = ceilLeftX - lx >= 0.5 ? Math.floor(lx) : ceilLeftX;
  7911. var pixelLeftY = ceilLeftY - ly >= 0.5 ? Math.floor(ly) : ceilLeftY;
  7912. var pixelRightX = rx - floorRightX >= 0.5 ? Math.ceil(rx) : floorRightX;
  7913. var pixelRightY = ry - floorRightY >= 0.5 ? Math.ceil(ry) : floorRightY;
  7914. this._viewport.x = pixelLeftX;
  7915. this._viewport.y = pixelLeftY;
  7916. this._viewport.width = pixelRightX - pixelLeftX;
  7917. this._viewport.height = pixelRightY - pixelLeftY;
  7918. }
  7919. _parse(data, spriteMap) {
  7920. super._parse(data, spriteMap);
  7921. var viewport = data.viewport;
  7922. this.normalizedViewport = new Viewport(viewport[0], viewport[1], viewport[2], viewport[3]);
  7923. var enableHDR = data.enableHDR;
  7924. (enableHDR !== undefined) && (this.enableHDR = enableHDR);
  7925. }
  7926. _calculateProjectionMatrix() {
  7927. if (!this._useUserProjectionMatrix) {
  7928. if (this._orthographic) {
  7929. var halfWidth = this.orthographicVerticalSize * this.aspectRatio * 0.5;
  7930. var halfHeight = this.orthographicVerticalSize * 0.5;
  7931. Matrix4x4.createOrthoOffCenter(-halfWidth, halfWidth, -halfHeight, halfHeight, this.nearPlane, this.farPlane, this._projectionMatrix);
  7932. }
  7933. else {
  7934. Matrix4x4.createPerspective(3.1416 * this.fieldOfView / 180.0, this.aspectRatio, this.nearPlane, this.farPlane, this._projectionMatrix);
  7935. }
  7936. }
  7937. }
  7938. _getCanvasHeight() {
  7939. if (this._offScreenRenderTexture)
  7940. return this._offScreenRenderTexture.height;
  7941. else
  7942. return RenderContext3D.clientHeight;
  7943. }
  7944. _applyPostProcessCommandBuffers() {
  7945. for (var i = 0, n = this._postProcessCommandBuffers.length; i < n; i++)
  7946. this._postProcessCommandBuffers[i]._apply();
  7947. }
  7948. _getRenderTextureFormat() {
  7949. if (this._enableHDR)
  7950. return Laya.BaseTexture.RENDERTEXTURE_FORMAT_RGBA_HALF_FLOAT;
  7951. else
  7952. return Laya.BaseTexture.FORMAT_R8G8B8;
  7953. }
  7954. render(shader = null, replacementTag = null) {
  7955. if (!this._scene)
  7956. return;
  7957. var createRenderTexture = this._postProcess || this._enableHDR ? true : false;
  7958. if (createRenderTexture)
  7959. this._renderTexture = RenderTexture.createFromPool(RenderContext3D.clientWidth, RenderContext3D.clientHeight, this._getRenderTextureFormat(), Laya.BaseTexture.FORMAT_DEPTH_16, Laya.BaseTexture.FILTERMODE_BILINEAR);
  7960. var gl = Laya.LayaGL.instance;
  7961. var context = RenderContext3D._instance;
  7962. var scene = context.scene = this._scene;
  7963. if (scene.parallelSplitShadowMaps[0]) {
  7964. ShaderData.setRuntimeValueMode(false);
  7965. var parallelSplitShadowMap = scene.parallelSplitShadowMaps[0];
  7966. parallelSplitShadowMap._calcAllLightCameraInfo(this);
  7967. scene._shaderValues.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_CAST_SHADOW);
  7968. for (var i = 0, n = parallelSplitShadowMap.shadowMapCount; i < n; i++) {
  7969. var smCamera = parallelSplitShadowMap.cameras[i];
  7970. context.camera = smCamera;
  7971. FrustumCulling.renderObjectCulling(smCamera, scene, context, scene._castShadowRenders, shader, replacementTag);
  7972. var shadowMap = parallelSplitShadowMap.cameras[i + 1].renderTarget;
  7973. shadowMap._start();
  7974. context.camera = smCamera;
  7975. context.viewport = smCamera.viewport;
  7976. smCamera._prepareCameraToRender();
  7977. smCamera._applyViewProject(context, smCamera.viewMatrix, smCamera.projectionMatrix, false);
  7978. scene._clear(gl, context);
  7979. var queue = scene._opaqueQueue;
  7980. queue._render(context, false);
  7981. shadowMap._end();
  7982. }
  7983. scene._shaderValues.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_CAST_SHADOW);
  7984. ShaderData.setRuntimeValueMode(true);
  7985. }
  7986. context.camera = this;
  7987. scene._preRenderScript();
  7988. var renderTar = this._renderTexture || this._offScreenRenderTexture;
  7989. (renderTar) && (renderTar._start());
  7990. context.viewport = this.viewport;
  7991. this._prepareCameraToRender();
  7992. this._applyViewProject(context, this.viewMatrix, this._projectionMatrix, renderTar ? true : false);
  7993. scene._preCulling(context, this, shader, replacementTag);
  7994. scene._clear(gl, context);
  7995. scene._renderScene(context);
  7996. scene._postRenderScript();
  7997. (renderTar) && (renderTar._end());
  7998. if (createRenderTexture) {
  7999. if (this._postProcess) {
  8000. this._postProcess._render();
  8001. this._applyPostProcessCommandBuffers();
  8002. }
  8003. else if (this._enableHDR) {
  8004. var blit = BlitScreenQuadCMD.create(this._renderTexture, this._offScreenRenderTexture ? this._offScreenRenderTexture : null);
  8005. blit.run();
  8006. blit.recover();
  8007. }
  8008. RenderTexture.recoverToPool(this._renderTexture);
  8009. }
  8010. }
  8011. _applyViewProject(context, viewMat, proMat, inverseY) {
  8012. var projectView;
  8013. var shaderData = this._shaderValues;
  8014. if (inverseY) {
  8015. Matrix4x4.multiply(BaseCamera._invertYScaleMatrix, proMat, BaseCamera._invertYProjectionMatrix);
  8016. Matrix4x4.multiply(BaseCamera._invertYProjectionMatrix, viewMat, BaseCamera._invertYProjectionViewMatrix);
  8017. proMat = BaseCamera._invertYProjectionMatrix;
  8018. projectView = BaseCamera._invertYProjectionViewMatrix;
  8019. }
  8020. else {
  8021. Matrix4x4.multiply(proMat, viewMat, this._projectionViewMatrix);
  8022. projectView = this._projectionViewMatrix;
  8023. }
  8024. context.viewMatrix = viewMat;
  8025. context.projectionMatrix = proMat;
  8026. context.projectionViewMatrix = projectView;
  8027. shaderData.setMatrix4x4(BaseCamera.VIEWMATRIX, viewMat);
  8028. shaderData.setMatrix4x4(BaseCamera.PROJECTMATRIX, proMat);
  8029. shaderData.setMatrix4x4(BaseCamera.VIEWPROJECTMATRIX, projectView);
  8030. }
  8031. viewportPointToRay(point, out) {
  8032. Picker.calculateCursorRay(point, this.viewport, this._projectionMatrix, this.viewMatrix, null, out);
  8033. }
  8034. normalizedViewportPointToRay(point, out) {
  8035. var finalPoint = Camera._tempVector20;
  8036. var vp = this.viewport;
  8037. finalPoint.x = point.x * vp.width;
  8038. finalPoint.y = point.y * vp.height;
  8039. Picker.calculateCursorRay(finalPoint, this.viewport, this._projectionMatrix, this.viewMatrix, null, out);
  8040. }
  8041. worldToViewportPoint(position, out) {
  8042. Matrix4x4.multiply(this._projectionMatrix, this._viewMatrix, this._projectionViewMatrix);
  8043. this.viewport.project(position, this._projectionViewMatrix, out);
  8044. out.x = out.x / Laya.Laya.stage.clientScaleX;
  8045. out.y = out.y / Laya.Laya.stage.clientScaleY;
  8046. }
  8047. worldToNormalizedViewportPoint(position, out) {
  8048. Matrix4x4.multiply(this._projectionMatrix, this._viewMatrix, this._projectionViewMatrix);
  8049. this.normalizedViewport.project(position, this._projectionViewMatrix, out);
  8050. out.x = out.x / Laya.Laya.stage.clientScaleX;
  8051. out.y = out.y / Laya.Laya.stage.clientScaleY;
  8052. }
  8053. convertScreenCoordToOrthographicCoord(source, out) {
  8054. if (this._orthographic) {
  8055. var clientWidth = RenderContext3D.clientWidth;
  8056. var clientHeight = RenderContext3D.clientHeight;
  8057. var ratioX = this.orthographicVerticalSize * this.aspectRatio / clientWidth;
  8058. var ratioY = this.orthographicVerticalSize / clientHeight;
  8059. out.x = (-clientWidth / 2 + source.x) * ratioX;
  8060. out.y = (clientHeight / 2 - source.y) * ratioY;
  8061. out.z = (this.nearPlane - this.farPlane) * (source.z + 1) / 2 - this.nearPlane;
  8062. Vector3.transformCoordinate(out, this.transform.worldMatrix, out);
  8063. return true;
  8064. }
  8065. else {
  8066. return false;
  8067. }
  8068. }
  8069. destroy(destroyChild = true) {
  8070. this._offScreenRenderTexture = null;
  8071. this.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onTransformChanged);
  8072. super.destroy(destroyChild);
  8073. }
  8074. addCommandBuffer(event, commandBuffer) {
  8075. switch (event) {
  8076. case Camera.CAMERAEVENT_POSTPROCESS:
  8077. this._postProcessCommandBuffers.push(commandBuffer);
  8078. commandBuffer._camera = this;
  8079. break;
  8080. default:
  8081. throw "Camera:unknown event.";
  8082. }
  8083. }
  8084. removeCommandBuffer(event, commandBuffer) {
  8085. switch (event) {
  8086. case Camera.CAMERAEVENT_POSTPROCESS:
  8087. var index = this._postProcessCommandBuffers.indexOf(commandBuffer);
  8088. if (index !== -1)
  8089. this._postProcessCommandBuffers.splice(index, 1);
  8090. break;
  8091. default:
  8092. throw "Camera:unknown event.";
  8093. }
  8094. }
  8095. removeCommandBuffers(event) {
  8096. switch (event) {
  8097. case Camera.CAMERAEVENT_POSTPROCESS:
  8098. this._postProcessCommandBuffers.length = 0;
  8099. break;
  8100. default:
  8101. throw "Camera:unknown event.";
  8102. }
  8103. }
  8104. _create() {
  8105. return new Camera();
  8106. }
  8107. }
  8108. Camera.CAMERAEVENT_POSTPROCESS = 0;
  8109. Camera._tempVector20 = new Vector2();
  8110. Camera._updateMark = 0;
  8111. class RenderElement {
  8112. constructor() {
  8113. this.renderSubShader = null;
  8114. this.renderType = RenderElement.RENDERTYPE_NORMAL;
  8115. }
  8116. getInvertFront() {
  8117. return this._transform._isFrontFaceInvert;
  8118. }
  8119. setTransform(transform) {
  8120. this._transform = transform;
  8121. }
  8122. setGeometry(geometry) {
  8123. this._geometry = geometry;
  8124. }
  8125. addToOpaqueRenderQueue(context, queue) {
  8126. queue.elements.add(this);
  8127. }
  8128. addToTransparentRenderQueue(context, queue) {
  8129. queue.elements.add(this);
  8130. queue.lastTransparentBatched = false;
  8131. queue.lastTransparentRenderElement = this;
  8132. }
  8133. _update(scene, context, customShader, replacementTag) {
  8134. if (this.material) {
  8135. var subShader = this.material._shader.getSubShaderAt(0);
  8136. this.renderSubShader = null;
  8137. if (customShader) {
  8138. if (replacementTag) {
  8139. var oriTag = subShader.getFlag(replacementTag);
  8140. if (oriTag) {
  8141. var customSubShaders = customShader._subShaders;
  8142. for (var k = 0, p = customSubShaders.length; k < p; k++) {
  8143. var customSubShader = customSubShaders[k];
  8144. if (oriTag === customSubShader.getFlag(replacementTag)) {
  8145. this.renderSubShader = customSubShader;
  8146. break;
  8147. }
  8148. }
  8149. if (!this.renderSubShader)
  8150. return;
  8151. }
  8152. else {
  8153. return;
  8154. }
  8155. }
  8156. else {
  8157. this.renderSubShader = customShader.getSubShaderAt(0);
  8158. }
  8159. }
  8160. else {
  8161. this.renderSubShader = subShader;
  8162. }
  8163. var renderQueue = scene._getRenderQueue(this.material.renderQueue);
  8164. if (renderQueue.isTransparent)
  8165. this.addToTransparentRenderQueue(context, renderQueue);
  8166. else
  8167. this.addToOpaqueRenderQueue(context, renderQueue);
  8168. }
  8169. }
  8170. _render(context, isTarget) {
  8171. var lastStateMaterial, lastStateShaderInstance, lastStateRender;
  8172. var updateMark = Camera._updateMark;
  8173. var scene = context.scene;
  8174. var camera = context.camera;
  8175. var transform = this._transform;
  8176. var geometry = this._geometry;
  8177. context.renderElement = this;
  8178. var updateRender = updateMark !== this.render._updateMark || this.renderType !== this.render._updateRenderType;
  8179. if (updateRender) {
  8180. this.render._renderUpdate(context, transform);
  8181. this.render._renderUpdateWithCamera(context, transform);
  8182. this.render._updateMark = updateMark;
  8183. this.render._updateRenderType = this.renderType;
  8184. }
  8185. if (geometry._prepareRender(context)) {
  8186. var passes = this.renderSubShader._passes;
  8187. for (var j = 0, m = passes.length; j < m; j++) {
  8188. var shaderPass = context.shader = passes[j].withCompile((scene._shaderValues._defineDatas.value) & (~this.material._disablePublicDefineDatas.value), this.render._shaderValues._defineDatas.value, this.material._shaderValues._defineDatas.value);
  8189. var switchShader = shaderPass.bind();
  8190. var switchUpdateMark = (updateMark !== shaderPass._uploadMark);
  8191. var uploadScene = (shaderPass._uploadScene !== scene) || switchUpdateMark;
  8192. if (uploadScene || switchShader) {
  8193. shaderPass.uploadUniforms(shaderPass._sceneUniformParamsMap, scene._shaderValues, uploadScene);
  8194. shaderPass._uploadScene = scene;
  8195. }
  8196. var uploadSprite3D = (shaderPass._uploadRender !== this.render || shaderPass._uploadRenderType !== this.renderType) || switchUpdateMark;
  8197. if (uploadSprite3D || switchShader) {
  8198. shaderPass.uploadUniforms(shaderPass._spriteUniformParamsMap, this.render._shaderValues, uploadSprite3D);
  8199. shaderPass._uploadRender = this.render;
  8200. shaderPass._uploadRenderType = this.renderType;
  8201. }
  8202. var uploadCamera = shaderPass._uploadCamera !== camera || switchUpdateMark;
  8203. if (uploadCamera || switchShader) {
  8204. shaderPass.uploadUniforms(shaderPass._cameraUniformParamsMap, camera._shaderValues, uploadCamera);
  8205. shaderPass._uploadCamera = camera;
  8206. }
  8207. var uploadMaterial = (shaderPass._uploadMaterial !== this.material) || switchUpdateMark;
  8208. if (uploadMaterial || switchShader) {
  8209. shaderPass.uploadUniforms(shaderPass._materialUniformParamsMap, this.material._shaderValues, uploadMaterial);
  8210. shaderPass._uploadMaterial = this.material;
  8211. }
  8212. var matValues = this.material._shaderValues;
  8213. if (lastStateMaterial !== this.material || lastStateShaderInstance !== shaderPass) {
  8214. shaderPass.uploadRenderStateBlendDepth(matValues);
  8215. shaderPass.uploadRenderStateFrontFace(matValues, isTarget, this.getInvertFront());
  8216. lastStateMaterial = this.material;
  8217. lastStateShaderInstance = shaderPass;
  8218. lastStateRender = this.render;
  8219. }
  8220. else {
  8221. if (lastStateRender !== this.render) {
  8222. shaderPass.uploadRenderStateFrontFace(matValues, isTarget, this.getInvertFront());
  8223. lastStateRender = this.render;
  8224. }
  8225. }
  8226. geometry._render(context);
  8227. shaderPass._uploadMark = updateMark;
  8228. }
  8229. }
  8230. if (updateRender && this.renderType !== RenderElement.RENDERTYPE_NORMAL)
  8231. this.render._revertBatchRenderUpdate(context);
  8232. Camera._updateMark++;
  8233. }
  8234. destroy() {
  8235. this._transform = null;
  8236. this._geometry = null;
  8237. this.material = null;
  8238. this.render = null;
  8239. }
  8240. }
  8241. RenderElement.RENDERTYPE_NORMAL = 0;
  8242. RenderElement.RENDERTYPE_STATICBATCH = 1;
  8243. RenderElement.RENDERTYPE_INSTANCEBATCH = 2;
  8244. RenderElement.RENDERTYPE_VERTEXBATCH = 3;
  8245. class SubMeshRenderElement extends RenderElement {
  8246. constructor() {
  8247. super();
  8248. this._dynamicWorldPositionNormalNeedUpdate = true;
  8249. }
  8250. _onWorldMatrixChanged() {
  8251. this._dynamicWorldPositionNormalNeedUpdate = true;
  8252. }
  8253. _computeWorldPositionsAndNormals(positionOffset, normalOffset, multiSubMesh, vertexCount) {
  8254. if (this._dynamicWorldPositionNormalNeedUpdate) {
  8255. var subMesh = this._geometry;
  8256. var vertexBuffer = subMesh._vertexBuffer;
  8257. var vertexFloatCount = vertexBuffer.vertexDeclaration.vertexStride / 4;
  8258. var oriVertexes = vertexBuffer.getFloat32Data();
  8259. var worldMat = this._transform.worldMatrix;
  8260. var rotation = this._transform.rotation;
  8261. var indices = subMesh._indices;
  8262. for (var i = 0; i < vertexCount; i++) {
  8263. var index = multiSubMesh ? indices[i] : i;
  8264. var oriOffset = index * vertexFloatCount;
  8265. var bakeOffset = i * 3;
  8266. Utils3D.transformVector3ArrayToVector3ArrayCoordinate(oriVertexes, oriOffset + positionOffset, worldMat, this._dynamicWorldPositions, bakeOffset);
  8267. (normalOffset !== -1) && (Utils3D.transformVector3ArrayByQuat(oriVertexes, oriOffset + normalOffset, rotation, this._dynamicWorldNormals, bakeOffset));
  8268. }
  8269. this._dynamicWorldPositionNormalNeedUpdate = false;
  8270. }
  8271. }
  8272. setTransform(transform) {
  8273. if (this._transform !== transform) {
  8274. (this._transform) && (this._transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatrixChanged));
  8275. (transform) && (transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatrixChanged));
  8276. this._dynamicWorldPositionNormalNeedUpdate = true;
  8277. this._transform = transform;
  8278. }
  8279. }
  8280. setGeometry(geometry) {
  8281. if (this._geometry !== geometry) {
  8282. var subMesh = geometry;
  8283. var mesh = subMesh._mesh;
  8284. if (mesh) {
  8285. var multiSubMesh = mesh._subMeshes.length > 1;
  8286. var dynBatVerCount = multiSubMesh ? subMesh._indexCount : mesh._vertexCount;
  8287. if (dynBatVerCount <= ILaya3D.SubMeshDynamicBatch.maxAllowVertexCount) {
  8288. var length = dynBatVerCount * 3;
  8289. this._dynamicVertexBatch = true;
  8290. this._dynamicWorldPositions = new Float32Array(length);
  8291. this._dynamicWorldNormals = new Float32Array(length);
  8292. this._dynamicVertexCount = dynBatVerCount;
  8293. this._dynamicMultiSubMesh = multiSubMesh;
  8294. }
  8295. else {
  8296. this._dynamicVertexBatch = false;
  8297. }
  8298. }
  8299. this._geometry = geometry;
  8300. }
  8301. }
  8302. addToOpaqueRenderQueue(context, queue) {
  8303. var subMeshStaticBatch = this.staticBatch;
  8304. var queueElements = queue.elements;
  8305. var elements = queueElements.elements;
  8306. if (subMeshStaticBatch) {
  8307. var staManager = ILaya3D.MeshRenderStaticBatchManager.instance;
  8308. var staBatchMarks = staManager.getBatchOpaquaMark(this.render.lightmapIndex + 1, this.render.receiveShadow, this.material.id, subMeshStaticBatch._batchID);
  8309. if (staManager._updateCountMark === staBatchMarks.updateMark) {
  8310. var staBatchIndex = staBatchMarks.indexInList;
  8311. if (staBatchMarks.batched) {
  8312. elements[staBatchIndex].staticBatchElementList.add(this);
  8313. }
  8314. else {
  8315. var staOriElement = elements[staBatchIndex];
  8316. var staOriRender = staOriElement.render;
  8317. var staBatchElement = staManager._getBatchRenderElementFromPool();
  8318. staBatchElement.renderType = RenderElement.RENDERTYPE_STATICBATCH;
  8319. staBatchElement.setGeometry(subMeshStaticBatch);
  8320. staBatchElement.material = staOriElement.material;
  8321. var staRootOwner = subMeshStaticBatch.batchOwner;
  8322. var staBatchTransform = staRootOwner ? staRootOwner._transform : null;
  8323. staBatchElement.setTransform(staBatchTransform);
  8324. staBatchElement.render = staOriRender;
  8325. staBatchElement.renderSubShader = staOriElement.renderSubShader;
  8326. var staBatchList = staBatchElement.staticBatchElementList;
  8327. staBatchList.length = 0;
  8328. staBatchList.add(staOriElement);
  8329. staBatchList.add(this);
  8330. elements[staBatchIndex] = staBatchElement;
  8331. staBatchMarks.batched = true;
  8332. }
  8333. }
  8334. else {
  8335. staBatchMarks.updateMark = staManager._updateCountMark;
  8336. staBatchMarks.indexInList = queueElements.length;
  8337. staBatchMarks.batched = false;
  8338. queueElements.add(this);
  8339. }
  8340. }
  8341. else if (this.renderSubShader._owner._enableInstancing && Laya.LayaGL.layaGPUInstance.supportInstance() && this.render.lightmapIndex < 0) {
  8342. var subMesh = this._geometry;
  8343. var insManager = ILaya3D.MeshRenderDynamicBatchManager.instance;
  8344. var insBatchMarks = insManager.getInstanceBatchOpaquaMark(this.render.receiveShadow, this.material.id, subMesh._id, this._transform._isFrontFaceInvert);
  8345. if (insManager._updateCountMark === insBatchMarks.updateMark) {
  8346. var insBatchIndex = insBatchMarks.indexInList;
  8347. if (insBatchMarks.batched) {
  8348. var instanceBatchElementList = elements[insBatchIndex].instanceBatchElementList;
  8349. if (instanceBatchElementList.length === SubMeshInstanceBatch.instance.maxInstanceCount) {
  8350. insBatchMarks.updateMark = insManager._updateCountMark;
  8351. insBatchMarks.indexInList = queueElements.length;
  8352. insBatchMarks.batched = false;
  8353. queueElements.add(this);
  8354. }
  8355. else {
  8356. instanceBatchElementList.add(this);
  8357. }
  8358. }
  8359. else {
  8360. var insOriElement = elements[insBatchIndex];
  8361. var insOriRender = insOriElement.render;
  8362. var insBatchElement = insManager._getBatchRenderElementFromPool();
  8363. insBatchElement.renderType = RenderElement.RENDERTYPE_INSTANCEBATCH;
  8364. insBatchElement.setGeometry(SubMeshInstanceBatch.instance);
  8365. insBatchElement.material = insOriElement.material;
  8366. insBatchElement.setTransform(null);
  8367. insBatchElement.render = insOriRender;
  8368. insBatchElement.instanceSubMesh = subMesh;
  8369. insBatchElement.renderSubShader = insOriElement.renderSubShader;
  8370. var insBatchList = insBatchElement.instanceBatchElementList;
  8371. insBatchList.length = 0;
  8372. insBatchList.add(insOriElement);
  8373. insBatchList.add(this);
  8374. elements[insBatchIndex] = insBatchElement;
  8375. insBatchMarks.batched = true;
  8376. }
  8377. }
  8378. else {
  8379. insBatchMarks.updateMark = insManager._updateCountMark;
  8380. insBatchMarks.indexInList = queueElements.length;
  8381. insBatchMarks.batched = false;
  8382. queueElements.add(this);
  8383. }
  8384. }
  8385. else if (this._dynamicVertexBatch) {
  8386. var verDec = this._geometry._vertexBuffer.vertexDeclaration;
  8387. var dynManager = ILaya3D.MeshRenderDynamicBatchManager.instance;
  8388. var dynBatchMarks = dynManager.getVertexBatchOpaquaMark(this.render.lightmapIndex + 1, this.render.receiveShadow, this.material.id, verDec.id);
  8389. if (dynManager._updateCountMark === dynBatchMarks.updateMark) {
  8390. var dynBatchIndex = dynBatchMarks.indexInList;
  8391. if (dynBatchMarks.batched) {
  8392. elements[dynBatchIndex].vertexBatchElementList.add(this);
  8393. }
  8394. else {
  8395. var dynOriElement = elements[dynBatchIndex];
  8396. var dynOriRender = dynOriElement.render;
  8397. var dynBatchElement = dynManager._getBatchRenderElementFromPool();
  8398. dynBatchElement.renderType = RenderElement.RENDERTYPE_VERTEXBATCH;
  8399. dynBatchElement.setGeometry(ILaya3D.SubMeshDynamicBatch.instance);
  8400. dynBatchElement.material = dynOriElement.material;
  8401. dynBatchElement.setTransform(null);
  8402. dynBatchElement.render = dynOriRender;
  8403. dynBatchElement.vertexBatchVertexDeclaration = verDec;
  8404. dynBatchElement.renderSubShader = dynOriElement.renderSubShader;
  8405. var dynBatchList = dynBatchElement.vertexBatchElementList;
  8406. dynBatchList.length = 0;
  8407. dynBatchList.add(dynOriElement);
  8408. dynBatchList.add(this);
  8409. elements[dynBatchIndex] = dynBatchElement;
  8410. dynBatchMarks.batched = true;
  8411. }
  8412. }
  8413. else {
  8414. dynBatchMarks.updateMark = dynManager._updateCountMark;
  8415. dynBatchMarks.indexInList = queueElements.length;
  8416. dynBatchMarks.batched = false;
  8417. queueElements.add(this);
  8418. }
  8419. }
  8420. else {
  8421. queueElements.add(this);
  8422. }
  8423. }
  8424. addToTransparentRenderQueue(context, queue) {
  8425. var subMeshStaticBatch = this.staticBatch;
  8426. var queueElements = queue.elements;
  8427. var elements = queueElements.elements;
  8428. if (subMeshStaticBatch) {
  8429. var staManager = ILaya3D.MeshRenderStaticBatchManager.instance;
  8430. var staLastElement = queue.lastTransparentRenderElement;
  8431. if (staLastElement) {
  8432. var staLastRender = staLastElement.render;
  8433. if (staLastElement._geometry._getType() !== this._geometry._getType() || staLastElement.staticBatch !== subMeshStaticBatch || staLastElement.material !== this.material || staLastRender.receiveShadow !== this.render.receiveShadow || staLastRender.lightmapIndex !== this.render.lightmapIndex) {
  8434. queueElements.add(this);
  8435. queue.lastTransparentBatched = false;
  8436. }
  8437. else {
  8438. if (queue.lastTransparentBatched) {
  8439. elements[queueElements.length - 1].staticBatchElementList.add((this));
  8440. }
  8441. else {
  8442. var staBatchElement = staManager._getBatchRenderElementFromPool();
  8443. staBatchElement.renderType = RenderElement.RENDERTYPE_STATICBATCH;
  8444. staBatchElement.setGeometry(subMeshStaticBatch);
  8445. staBatchElement.material = staLastElement.material;
  8446. var staRootOwner = subMeshStaticBatch.batchOwner;
  8447. var staBatchTransform = staRootOwner ? staRootOwner._transform : null;
  8448. staBatchElement.setTransform(staBatchTransform);
  8449. staBatchElement.render = this.render;
  8450. staBatchElement.renderSubShader = staLastElement.renderSubShader;
  8451. var staBatchList = staBatchElement.staticBatchElementList;
  8452. staBatchList.length = 0;
  8453. staBatchList.add(staLastElement);
  8454. staBatchList.add(this);
  8455. elements[queueElements.length - 1] = staBatchElement;
  8456. }
  8457. queue.lastTransparentBatched = true;
  8458. }
  8459. }
  8460. else {
  8461. queueElements.add(this);
  8462. queue.lastTransparentBatched = false;
  8463. }
  8464. }
  8465. else if (this.renderSubShader._owner._enableInstancing && Laya.LayaGL.layaGPUInstance.supportInstance() && this.render.lightmapIndex < 0) {
  8466. var subMesh = this._geometry;
  8467. var insManager = ILaya3D.MeshRenderDynamicBatchManager.instance;
  8468. var insLastElement = queue.lastTransparentRenderElement;
  8469. if (insLastElement) {
  8470. var insLastRender = insLastElement.render;
  8471. if (insLastElement._geometry._getType() !== this._geometry._getType() || insLastElement._geometry !== subMesh || insLastElement.material !== this.material || insLastRender.receiveShadow !== this.render.receiveShadow) {
  8472. queueElements.add(this);
  8473. queue.lastTransparentBatched = false;
  8474. }
  8475. else {
  8476. if (queue.lastTransparentBatched) {
  8477. var instanceBatchElementList = elements[queueElements.length - 1].instanceBatchElementList;
  8478. if (instanceBatchElementList.length === SubMeshInstanceBatch.instance.maxInstanceCount) {
  8479. queueElements.add(this);
  8480. queue.lastTransparentBatched = false;
  8481. }
  8482. else {
  8483. instanceBatchElementList.add(this);
  8484. queue.lastTransparentBatched = true;
  8485. }
  8486. }
  8487. else {
  8488. var insBatchElement = insManager._getBatchRenderElementFromPool();
  8489. insBatchElement.renderType = RenderElement.RENDERTYPE_INSTANCEBATCH;
  8490. insBatchElement.setGeometry(SubMeshInstanceBatch.instance);
  8491. insBatchElement.material = insLastElement.material;
  8492. insBatchElement.setTransform(null);
  8493. insBatchElement.render = this.render;
  8494. insBatchElement.instanceSubMesh = subMesh;
  8495. insBatchElement.renderSubShader = insLastElement.renderSubShader;
  8496. var insBatchList = insBatchElement.instanceBatchElementList;
  8497. insBatchList.length = 0;
  8498. insBatchList.add(insLastElement);
  8499. insBatchList.add(this);
  8500. elements[queueElements.length - 1] = insBatchElement;
  8501. queue.lastTransparentBatched = true;
  8502. }
  8503. }
  8504. }
  8505. else {
  8506. queueElements.add(this);
  8507. queue.lastTransparentBatched = false;
  8508. }
  8509. }
  8510. else if (this._dynamicVertexBatch) {
  8511. var verDec = this._geometry._vertexBuffer.vertexDeclaration;
  8512. var dynManager = ILaya3D.MeshRenderDynamicBatchManager.instance;
  8513. var dynLastElement = queue.lastTransparentRenderElement;
  8514. if (dynLastElement) {
  8515. var dynLastRender = dynLastElement.render;
  8516. if (dynLastElement._geometry._getType() !== this._geometry._getType() || dynLastElement._geometry._vertexBuffer._vertexDeclaration !== verDec || dynLastElement.material !== this.material || dynLastRender.receiveShadow !== this.render.receiveShadow || dynLastRender.lightmapIndex !== this.render.lightmapIndex) {
  8517. queueElements.add(this);
  8518. queue.lastTransparentBatched = false;
  8519. }
  8520. else {
  8521. if (queue.lastTransparentBatched) {
  8522. elements[queueElements.length - 1].vertexBatchElementList.add((this));
  8523. }
  8524. else {
  8525. var dynBatchElement = dynManager._getBatchRenderElementFromPool();
  8526. dynBatchElement.renderType = RenderElement.RENDERTYPE_VERTEXBATCH;
  8527. dynBatchElement.setGeometry(ILaya3D.SubMeshDynamicBatch.instance);
  8528. dynBatchElement.material = dynLastElement.material;
  8529. dynBatchElement.setTransform(null);
  8530. dynBatchElement.render = this.render;
  8531. dynBatchElement.vertexBatchVertexDeclaration = verDec;
  8532. dynBatchElement.renderSubShader = dynLastElement.renderSubShader;
  8533. var dynBatchList = dynBatchElement.vertexBatchElementList;
  8534. dynBatchList.length = 0;
  8535. dynBatchList.add(dynLastElement);
  8536. dynBatchList.add(this);
  8537. elements[queueElements.length - 1] = dynBatchElement;
  8538. }
  8539. queue.lastTransparentBatched = true;
  8540. }
  8541. }
  8542. else {
  8543. queueElements.add(this);
  8544. queue.lastTransparentBatched = false;
  8545. }
  8546. }
  8547. else {
  8548. queueElements.add(this);
  8549. }
  8550. queue.lastTransparentRenderElement = this;
  8551. }
  8552. getInvertFront() {
  8553. switch (this.renderType) {
  8554. case RenderElement.RENDERTYPE_NORMAL:
  8555. return this._transform._isFrontFaceInvert;
  8556. case RenderElement.RENDERTYPE_STATICBATCH:
  8557. case RenderElement.RENDERTYPE_VERTEXBATCH:
  8558. return false;
  8559. case RenderElement.RENDERTYPE_INSTANCEBATCH:
  8560. return this.instanceBatchElementList.elements[0]._transform._isFrontFaceInvert;
  8561. default:
  8562. throw "SubMeshRenderElement: unknown renderType";
  8563. }
  8564. }
  8565. destroy() {
  8566. super.destroy();
  8567. this._dynamicWorldPositions = null;
  8568. this._dynamicWorldNormals = null;
  8569. this.staticBatch = null;
  8570. this.staticBatchElementList = null;
  8571. this.vertexBatchElementList = null;
  8572. this.vertexBatchVertexDeclaration = null;
  8573. }
  8574. }
  8575. class SingletonList {
  8576. constructor() {
  8577. this.elements = [];
  8578. this.length = 0;
  8579. }
  8580. _add(element) {
  8581. if (this.length === this.elements.length)
  8582. this.elements.push(element);
  8583. else
  8584. this.elements[this.length] = element;
  8585. }
  8586. add(element) {
  8587. if (this.length === this.elements.length)
  8588. this.elements.push(element);
  8589. else
  8590. this.elements[this.length] = element;
  8591. this.length++;
  8592. }
  8593. }
  8594. class MeshRenderDynamicBatchManager extends DynamicBatchManager {
  8595. constructor() {
  8596. super();
  8597. this._instanceBatchOpaqueMarks = [];
  8598. this._vertexBatchOpaqueMarks = [];
  8599. this._cacheBufferStates = [];
  8600. this._updateCountMark = 0;
  8601. }
  8602. getInstanceBatchOpaquaMark(receiveShadow, materialID, subMeshID, invertFace) {
  8603. var instanceReceiveShadowMarks = (this._instanceBatchOpaqueMarks[receiveShadow ? 0 : 1]) || (this._instanceBatchOpaqueMarks[receiveShadow ? 0 : 1] = []);
  8604. var instanceMaterialMarks = (instanceReceiveShadowMarks[materialID]) || (instanceReceiveShadowMarks[materialID] = []);
  8605. var instancSubMeshMarks = (instanceMaterialMarks[subMeshID]) || (instanceMaterialMarks[subMeshID] = []);
  8606. return instancSubMeshMarks[invertFace ? 1 : 0] || (instancSubMeshMarks[invertFace ? 1 : 0] = new BatchMark());
  8607. }
  8608. getVertexBatchOpaquaMark(lightMapIndex, receiveShadow, materialID, verDecID) {
  8609. var dynLightMapMarks = (this._vertexBatchOpaqueMarks[lightMapIndex]) || (this._vertexBatchOpaqueMarks[lightMapIndex] = []);
  8610. var dynReceiveShadowMarks = (dynLightMapMarks[receiveShadow ? 0 : 1]) || (dynLightMapMarks[receiveShadow ? 0 : 1] = []);
  8611. var dynMaterialMarks = (dynReceiveShadowMarks[materialID]) || (dynReceiveShadowMarks[materialID] = []);
  8612. return dynMaterialMarks[verDecID] || (dynMaterialMarks[verDecID] = new BatchMark());
  8613. }
  8614. _getBufferState(vertexDeclaration) {
  8615. var bufferState = this._cacheBufferStates[vertexDeclaration.id];
  8616. if (!bufferState) {
  8617. var instance = SubMeshDynamicBatch.instance;
  8618. bufferState = new BufferState();
  8619. bufferState.bind();
  8620. var vertexBuffer = instance._vertexBuffer;
  8621. vertexBuffer.vertexDeclaration = vertexDeclaration;
  8622. bufferState.applyVertexBuffer(vertexBuffer);
  8623. bufferState.applyIndexBuffer(instance._indexBuffer);
  8624. bufferState.unBind();
  8625. this._cacheBufferStates[vertexDeclaration.id] = bufferState;
  8626. }
  8627. return bufferState;
  8628. }
  8629. _getBatchRenderElementFromPool() {
  8630. var renderElement = this._batchRenderElementPool[this._batchRenderElementPoolIndex++];
  8631. if (!renderElement) {
  8632. renderElement = new SubMeshRenderElement();
  8633. this._batchRenderElementPool[this._batchRenderElementPoolIndex - 1] = renderElement;
  8634. renderElement.vertexBatchElementList = new SingletonList();
  8635. renderElement.instanceBatchElementList = new SingletonList();
  8636. }
  8637. return renderElement;
  8638. }
  8639. _clear() {
  8640. super._clear();
  8641. this._updateCountMark++;
  8642. }
  8643. }
  8644. MeshRenderDynamicBatchManager.instance = new MeshRenderDynamicBatchManager();
  8645. class SubMeshStaticBatch extends GeometryElement {
  8646. constructor(batchOwner, number, vertexDeclaration) {
  8647. super();
  8648. this._bufferState = new BufferState();
  8649. this._batchID = SubMeshStaticBatch._batchIDCounter++;
  8650. this._batchElements = [];
  8651. this._currentBatchVertexCount = 0;
  8652. this._currentBatchIndexCount = 0;
  8653. this._vertexDeclaration = vertexDeclaration;
  8654. this.batchOwner = batchOwner;
  8655. this.number = number;
  8656. }
  8657. _getStaticBatchBakedVertexs(batchVertices, batchOffset, batchOwnerTransform, transform, render, mesh) {
  8658. var vertexBuffer = mesh._vertexBuffer;
  8659. var vertexDeclaration = vertexBuffer.vertexDeclaration;
  8660. var positionOffset = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_POSITION0)._offset / 4;
  8661. var normalElement = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_NORMAL0);
  8662. var normalOffset = normalElement ? normalElement._offset / 4 : -1;
  8663. var colorElement = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_COLOR0);
  8664. var colorOffset = colorElement ? colorElement._offset / 4 : -1;
  8665. var uv0Element = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_TEXTURECOORDINATE0);
  8666. var uv0Offset = uv0Element ? uv0Element._offset / 4 : -1;
  8667. var uv1Element = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_TEXTURECOORDINATE1);
  8668. var uv1Offset = uv1Element ? uv1Element._offset / 4 : -1;
  8669. var tangentElement = vertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_TANGENT0);
  8670. var sTangentOffset = tangentElement ? tangentElement._offset / 4 : -1;
  8671. var bakeVertexFloatCount = 18;
  8672. var oriVertexFloatCount = vertexDeclaration.vertexStride / 4;
  8673. var oriVertexes = vertexBuffer.getFloat32Data();
  8674. var worldMat;
  8675. if (batchOwnerTransform) {
  8676. var rootMat = batchOwnerTransform.worldMatrix;
  8677. rootMat.invert(SubMeshStaticBatch._tempMatrix4x40);
  8678. worldMat = SubMeshStaticBatch._tempMatrix4x41;
  8679. Matrix4x4.multiply(SubMeshStaticBatch._tempMatrix4x40, transform.worldMatrix, worldMat);
  8680. }
  8681. else {
  8682. worldMat = transform.worldMatrix;
  8683. }
  8684. var rotation = SubMeshStaticBatch._tempQuaternion0;
  8685. worldMat.decomposeTransRotScale(SubMeshStaticBatch._tempVector30, rotation, SubMeshStaticBatch._tempVector31);
  8686. var lightmapScaleOffset = render.lightmapScaleOffset;
  8687. var vertexCount = mesh.vertexCount;
  8688. for (var i = 0; i < vertexCount; i++) {
  8689. var oriOffset = i * oriVertexFloatCount;
  8690. var bakeOffset = (i + batchOffset) * bakeVertexFloatCount;
  8691. Utils3D.transformVector3ArrayToVector3ArrayCoordinate(oriVertexes, oriOffset + positionOffset, worldMat, batchVertices, bakeOffset + 0);
  8692. if (normalOffset !== -1)
  8693. Utils3D.transformVector3ArrayByQuat(oriVertexes, oriOffset + normalOffset, rotation, batchVertices, bakeOffset + 3);
  8694. var j, m;
  8695. var bakOff = bakeOffset + 6;
  8696. if (colorOffset !== -1) {
  8697. var oriOff = oriOffset + colorOffset;
  8698. for (j = 0, m = 4; j < m; j++)
  8699. batchVertices[bakOff + j] = oriVertexes[oriOff + j];
  8700. }
  8701. else {
  8702. for (j = 0, m = 4; j < m; j++)
  8703. batchVertices[bakOff + j] = 1.0;
  8704. }
  8705. if (uv0Offset !== -1) {
  8706. var absUv0Offset = oriOffset + uv0Offset;
  8707. batchVertices[bakeOffset + 10] = oriVertexes[absUv0Offset];
  8708. batchVertices[bakeOffset + 11] = oriVertexes[absUv0Offset + 1];
  8709. }
  8710. if (lightmapScaleOffset) {
  8711. if (uv1Offset !== -1)
  8712. Utils3D.transformLightingMapTexcoordArray(oriVertexes, oriOffset + uv1Offset, lightmapScaleOffset, batchVertices, bakeOffset + 12);
  8713. else
  8714. Utils3D.transformLightingMapTexcoordArray(oriVertexes, oriOffset + uv0Offset, lightmapScaleOffset, batchVertices, bakeOffset + 12);
  8715. }
  8716. if (sTangentOffset !== -1) {
  8717. var absSTanegntOffset = oriOffset + sTangentOffset;
  8718. batchVertices[bakeOffset + 14] = oriVertexes[absSTanegntOffset];
  8719. batchVertices[bakeOffset + 15] = oriVertexes[absSTanegntOffset + 1];
  8720. batchVertices[bakeOffset + 16] = oriVertexes[absSTanegntOffset + 2];
  8721. batchVertices[bakeOffset + 17] = oriVertexes[absSTanegntOffset + 3];
  8722. }
  8723. }
  8724. return vertexCount;
  8725. }
  8726. addTest(sprite) {
  8727. var vertexCount;
  8728. var subMeshVertexCount = sprite.meshFilter.sharedMesh.vertexCount;
  8729. vertexCount = this._currentBatchVertexCount + subMeshVertexCount;
  8730. if (vertexCount > SubMeshStaticBatch.maxBatchVertexCount)
  8731. return false;
  8732. return true;
  8733. }
  8734. add(sprite) {
  8735. var oldStaticBatch = sprite._render._staticBatch;
  8736. (oldStaticBatch) && (oldStaticBatch.remove(sprite));
  8737. var mesh = sprite.meshFilter.sharedMesh;
  8738. var subMeshVertexCount = mesh.vertexCount;
  8739. this._batchElements.push(sprite);
  8740. var render = sprite._render;
  8741. render._isPartOfStaticBatch = true;
  8742. render._staticBatch = this;
  8743. var renderElements = render._renderElements;
  8744. for (var i = 0, n = renderElements.length; i < n; i++)
  8745. renderElements[i].staticBatch = this;
  8746. this._currentBatchIndexCount += mesh._indexBuffer.indexCount;
  8747. this._currentBatchVertexCount += subMeshVertexCount;
  8748. }
  8749. remove(sprite) {
  8750. var mesh = sprite.meshFilter.sharedMesh;
  8751. var index = this._batchElements.indexOf(sprite);
  8752. if (index !== -1) {
  8753. this._batchElements.splice(index, 1);
  8754. var render = sprite._render;
  8755. var renderElements = sprite._render._renderElements;
  8756. for (var i = 0, n = renderElements.length; i < n; i++)
  8757. renderElements[i].staticBatch = null;
  8758. var meshVertexCount = mesh.vertexCount;
  8759. this._currentBatchIndexCount = this._currentBatchIndexCount - mesh._indexBuffer.indexCount;
  8760. this._currentBatchVertexCount = this._currentBatchVertexCount - meshVertexCount;
  8761. sprite._render._isPartOfStaticBatch = false;
  8762. }
  8763. }
  8764. finishInit() {
  8765. if (this._vertexBuffer) {
  8766. this._vertexBuffer.destroy();
  8767. this._indexBuffer.destroy();
  8768. Laya.Resource._addGPUMemory(-(this._vertexBuffer._byteLength + this._indexBuffer._byteLength));
  8769. }
  8770. var gl = Laya.LayaGL.instance;
  8771. var batchVertexCount = 0;
  8772. var batchIndexCount = 0;
  8773. var rootOwner = this.batchOwner;
  8774. var floatStride = this._vertexDeclaration.vertexStride / 4;
  8775. var vertexDatas = new Float32Array(floatStride * this._currentBatchVertexCount);
  8776. var indexDatas = new Uint16Array(this._currentBatchIndexCount);
  8777. this._vertexBuffer = new VertexBuffer3D(this._vertexDeclaration.vertexStride * this._currentBatchVertexCount, gl.STATIC_DRAW);
  8778. this._vertexBuffer.vertexDeclaration = this._vertexDeclaration;
  8779. this._indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, this._currentBatchIndexCount, gl.STATIC_DRAW);
  8780. for (var i = 0, n = this._batchElements.length; i < n; i++) {
  8781. var sprite = this._batchElements[i];
  8782. var mesh = sprite.meshFilter.sharedMesh;
  8783. var meshVerCount = this._getStaticBatchBakedVertexs(vertexDatas, batchVertexCount, rootOwner ? rootOwner._transform : null, sprite._transform, sprite._render, mesh);
  8784. var indices = mesh._indexBuffer.getData();
  8785. var indexOffset = batchVertexCount;
  8786. var indexEnd = batchIndexCount + indices.length;
  8787. var elements = sprite._render._renderElements;
  8788. for (var j = 0, m = mesh.subMeshCount; j < m; j++) {
  8789. var subMesh = mesh._subMeshes[j];
  8790. var start = batchIndexCount + subMesh._indexStart;
  8791. var element = elements[j];
  8792. element.staticBatchIndexStart = start;
  8793. element.staticBatchIndexEnd = start + subMesh._indexCount;
  8794. }
  8795. indexDatas.set(indices, batchIndexCount);
  8796. var k;
  8797. var isInvert = rootOwner ? (sprite._transform._isFrontFaceInvert !== rootOwner.transform._isFrontFaceInvert) : sprite._transform._isFrontFaceInvert;
  8798. if (isInvert) {
  8799. for (k = batchIndexCount; k < indexEnd; k += 3) {
  8800. indexDatas[k] = indexOffset + indexDatas[k];
  8801. var index1 = indexDatas[k + 1];
  8802. var index2 = indexDatas[k + 2];
  8803. indexDatas[k + 1] = indexOffset + index2;
  8804. indexDatas[k + 2] = indexOffset + index1;
  8805. }
  8806. }
  8807. else {
  8808. for (k = batchIndexCount; k < indexEnd; k += 3) {
  8809. indexDatas[k] = indexOffset + indexDatas[k];
  8810. indexDatas[k + 1] = indexOffset + indexDatas[k + 1];
  8811. indexDatas[k + 2] = indexOffset + indexDatas[k + 2];
  8812. }
  8813. }
  8814. batchIndexCount += indices.length;
  8815. batchVertexCount += meshVerCount;
  8816. }
  8817. this._vertexBuffer.setData(vertexDatas.buffer);
  8818. this._indexBuffer.setData(indexDatas);
  8819. var memorySize = this._vertexBuffer._byteLength + this._indexBuffer._byteLength;
  8820. Laya.Resource._addGPUMemory(memorySize);
  8821. this._bufferState.bind();
  8822. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  8823. this._bufferState.applyIndexBuffer(this._indexBuffer);
  8824. this._bufferState.unBind();
  8825. }
  8826. _render(state) {
  8827. this._bufferState.bind();
  8828. var gl = Laya.LayaGL.instance;
  8829. var element = state.renderElement;
  8830. var staticBatchElementList = element.staticBatchElementList;
  8831. var batchElementList = staticBatchElementList.elements;
  8832. var from = 0;
  8833. var end = 0;
  8834. var count = staticBatchElementList.length;
  8835. for (var i = 1; i < count; i++) {
  8836. var lastElement = batchElementList[i - 1];
  8837. if (lastElement.staticBatchIndexEnd === batchElementList[i].staticBatchIndexStart) {
  8838. end++;
  8839. continue;
  8840. }
  8841. else {
  8842. var start = batchElementList[from].staticBatchIndexStart;
  8843. var indexCount = batchElementList[end].staticBatchIndexEnd - start;
  8844. gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, start * 2);
  8845. from = ++end;
  8846. Laya.Stat.trianglesFaces += indexCount / 3;
  8847. }
  8848. }
  8849. start = batchElementList[from].staticBatchIndexStart;
  8850. indexCount = batchElementList[end].staticBatchIndexEnd - start;
  8851. gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, start * 2);
  8852. Laya.Stat.renderBatches++;
  8853. Laya.Stat.savedRenderBatches += count - 1;
  8854. Laya.Stat.trianglesFaces += indexCount / 3;
  8855. }
  8856. dispose() {
  8857. var memorySize = this._vertexBuffer._byteLength + this._indexBuffer._byteLength;
  8858. Laya.Resource._addGPUMemory(-memorySize);
  8859. this._batchElements = null;
  8860. this.batchOwner = null;
  8861. this._vertexDeclaration = null;
  8862. this._bufferState.destroy();
  8863. this._vertexBuffer.destroy();
  8864. this._indexBuffer.destroy();
  8865. this._vertexBuffer = null;
  8866. this._indexBuffer = null;
  8867. this._bufferState = null;
  8868. }
  8869. }
  8870. SubMeshStaticBatch._tempVector30 = new Vector3();
  8871. SubMeshStaticBatch._tempVector31 = new Vector3();
  8872. SubMeshStaticBatch._tempQuaternion0 = new Quaternion();
  8873. SubMeshStaticBatch._tempMatrix4x40 = new Matrix4x4();
  8874. SubMeshStaticBatch._tempMatrix4x41 = new Matrix4x4();
  8875. SubMeshStaticBatch.maxBatchVertexCount = 65535;
  8876. SubMeshStaticBatch._batchIDCounter = 0;
  8877. class MeshRenderStaticBatchManager extends StaticBatchManager {
  8878. constructor() {
  8879. super();
  8880. this._opaqueBatchMarks = [];
  8881. this._updateCountMark = 0;
  8882. }
  8883. static __init__() {
  8884. MeshRenderStaticBatchManager._verDec = VertexMesh.getVertexDeclaration("POSITION,NORMAL,COLOR,UV,UV1,TANGENT");
  8885. }
  8886. _compare(left, right) {
  8887. var lRender = left._render, rRender = right._render;
  8888. var leftGeo = left.meshFilter.sharedMesh, rightGeo = right.meshFilter.sharedMesh;
  8889. var lightOffset = lRender.lightmapIndex - rRender.lightmapIndex;
  8890. if (lightOffset === 0) {
  8891. var receiveShadowOffset = (lRender.receiveShadow ? 1 : 0) - (rRender.receiveShadow ? 1 : 0);
  8892. if (receiveShadowOffset === 0) {
  8893. var materialOffset = lRender.sharedMaterial.id - rRender.sharedMaterial.id;
  8894. if (materialOffset === 0) {
  8895. var verDec = leftGeo._vertexBuffer.vertexDeclaration.id - rightGeo._vertexBuffer.vertexDeclaration.id;
  8896. if (verDec === 0) {
  8897. return rightGeo._indexBuffer.indexCount - leftGeo._indexBuffer.indexCount;
  8898. }
  8899. else {
  8900. return verDec;
  8901. }
  8902. }
  8903. else {
  8904. return materialOffset;
  8905. }
  8906. }
  8907. else {
  8908. return receiveShadowOffset;
  8909. }
  8910. }
  8911. else {
  8912. return lightOffset;
  8913. }
  8914. }
  8915. _getBatchRenderElementFromPool() {
  8916. var renderElement = this._batchRenderElementPool[this._batchRenderElementPoolIndex++];
  8917. if (!renderElement) {
  8918. renderElement = new SubMeshRenderElement();
  8919. this._batchRenderElementPool[this._batchRenderElementPoolIndex - 1] = renderElement;
  8920. renderElement.staticBatchElementList = new SingletonList();
  8921. }
  8922. return renderElement;
  8923. }
  8924. _getStaticBatch(rootOwner, number) {
  8925. var key = rootOwner ? rootOwner.id : 0;
  8926. var batchOwner = this._staticBatches[key];
  8927. (batchOwner) || (batchOwner = this._staticBatches[key] = []);
  8928. return (batchOwner[number]) || (batchOwner[number] = new SubMeshStaticBatch(rootOwner, number, MeshRenderStaticBatchManager._verDec));
  8929. }
  8930. _initStaticBatchs(rootOwner) {
  8931. this._quickSort(this._initBatchSprites, 0, this._initBatchSprites.length - 1);
  8932. var lastCanMerage = false;
  8933. var curStaticBatch;
  8934. var batchNumber = 0;
  8935. for (var i = 0, n = this._initBatchSprites.length; i < n; i++) {
  8936. var sprite = this._initBatchSprites[i];
  8937. if (lastCanMerage) {
  8938. if (curStaticBatch.addTest(sprite)) {
  8939. curStaticBatch.add(sprite);
  8940. }
  8941. else {
  8942. lastCanMerage = false;
  8943. batchNumber++;
  8944. }
  8945. }
  8946. else {
  8947. var lastIndex = n - 1;
  8948. if (i !== lastIndex) {
  8949. curStaticBatch = this._getStaticBatch(rootOwner, batchNumber);
  8950. curStaticBatch.add(sprite);
  8951. lastCanMerage = true;
  8952. }
  8953. }
  8954. }
  8955. for (var key in this._staticBatches) {
  8956. var batches = this._staticBatches[key];
  8957. for (i = 0, n = batches.length; i < n; i++)
  8958. batches[i].finishInit();
  8959. }
  8960. this._initBatchSprites.length = 0;
  8961. }
  8962. _destroyRenderSprite(sprite) {
  8963. var staticBatch = sprite._render._staticBatch;
  8964. staticBatch.remove(sprite);
  8965. if (staticBatch._batchElements.length === 0) {
  8966. var owner = staticBatch.batchOwner;
  8967. var ownerID = owner ? owner.id : 0;
  8968. var batches = this._staticBatches[ownerID];
  8969. batches[staticBatch.number] = null;
  8970. staticBatch.dispose();
  8971. var empty = true;
  8972. for (var i = 0; i < batches.length; i++) {
  8973. if (batches[i])
  8974. empty = false;
  8975. }
  8976. if (empty) {
  8977. delete this._staticBatches[ownerID];
  8978. }
  8979. }
  8980. }
  8981. _clear() {
  8982. super._clear();
  8983. this._updateCountMark++;
  8984. }
  8985. _garbageCollection() {
  8986. for (var key in this._staticBatches) {
  8987. var batches = this._staticBatches[key];
  8988. for (var i = 0, n = batches.length; i < n; i++) {
  8989. var staticBatch = batches[i];
  8990. if (staticBatch._batchElements.length === 0) {
  8991. staticBatch.dispose();
  8992. batches.splice(i, 1);
  8993. i--, n--;
  8994. if (n === 0)
  8995. delete this._staticBatches[key];
  8996. }
  8997. }
  8998. }
  8999. }
  9000. getBatchOpaquaMark(lightMapIndex, receiveShadow, materialID, staticBatchID) {
  9001. var receiveShadowIndex = receiveShadow ? 1 : 0;
  9002. var staLightMapMarks = (this._opaqueBatchMarks[lightMapIndex]) || (this._opaqueBatchMarks[lightMapIndex] = []);
  9003. var staReceiveShadowMarks = (staLightMapMarks[receiveShadowIndex]) || (staLightMapMarks[receiveShadowIndex] = []);
  9004. var staMaterialMarks = (staReceiveShadowMarks[materialID]) || (staReceiveShadowMarks[materialID] = []);
  9005. return (staMaterialMarks[staticBatchID]) || (staMaterialMarks[staticBatchID] = new BatchMark);
  9006. }
  9007. }
  9008. MeshRenderStaticBatchManager.instance = new MeshRenderStaticBatchManager();
  9009. class Physics3D {
  9010. }
  9011. Physics3D._physics3D = null;
  9012. Physics3D._enbalePhysics = false;
  9013. class Physics3DUtils {
  9014. constructor() {
  9015. }
  9016. static setColliderCollision(collider1, collider2, collsion) {
  9017. }
  9018. static getIColliderCollision(collider1, collider2) {
  9019. return false;
  9020. }
  9021. }
  9022. Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER = 0x1;
  9023. Physics3DUtils.COLLISIONFILTERGROUP_STATICFILTER = 0x2;
  9024. Physics3DUtils.COLLISIONFILTERGROUP_KINEMATICFILTER = 0x4;
  9025. Physics3DUtils.COLLISIONFILTERGROUP_DEBRISFILTER = 0x8;
  9026. Physics3DUtils.COLLISIONFILTERGROUP_SENSORTRIGGER = 0x10;
  9027. Physics3DUtils.COLLISIONFILTERGROUP_CHARACTERFILTER = 0x20;
  9028. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER1 = 0x40;
  9029. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER2 = 0x80;
  9030. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER3 = 0x100;
  9031. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER4 = 0x200;
  9032. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER5 = 0x400;
  9033. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER6 = 0x800;
  9034. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER7 = 0x1000;
  9035. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER8 = 0x2000;
  9036. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER9 = 0x4000;
  9037. Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER10 = 0x8000;
  9038. Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER = -1;
  9039. Physics3DUtils.gravity = new Vector3(0, -9.81, 0);
  9040. class ColliderShape {
  9041. constructor() {
  9042. this._scale = new Vector3(1, 1, 1);
  9043. this._centerMatrix = new Matrix4x4();
  9044. this._attatched = false;
  9045. this._indexInCompound = -1;
  9046. this._compoundParent = null;
  9047. this._attatchedCollisionObject = null;
  9048. this._referenceCount = 0;
  9049. this._localOffset = new Vector3(0, 0, 0);
  9050. this._localRotation = new Quaternion(0, 0, 0, 1);
  9051. this.needsCustomCollisionCallback = false;
  9052. }
  9053. static __init__() {
  9054. ColliderShape._nativeScale = new Physics3D._physics3D.btVector3(1, 1, 1);
  9055. ColliderShape._nativeVector30 = new Physics3D._physics3D.btVector3(0, 0, 0);
  9056. ColliderShape._nativQuaternion0 = new Physics3D._physics3D.btQuaternion(0, 0, 0, 1);
  9057. ColliderShape._nativeTransform0 = new Physics3D._physics3D.btTransform();
  9058. }
  9059. static _createAffineTransformation(trans, rot, outE) {
  9060. var x = rot.x, y = rot.y, z = rot.z, w = rot.w, x2 = x + x, y2 = y + y, z2 = z + z;
  9061. var xx = x * x2, xy = x * y2, xz = x * z2, yy = y * y2, yz = y * z2, zz = z * z2;
  9062. var wx = w * x2, wy = w * y2, wz = w * z2;
  9063. outE[0] = (1 - (yy + zz));
  9064. outE[1] = (xy + wz);
  9065. outE[2] = (xz - wy);
  9066. outE[3] = 0;
  9067. outE[4] = (xy - wz);
  9068. outE[5] = (1 - (xx + zz));
  9069. outE[6] = (yz + wx);
  9070. outE[7] = 0;
  9071. outE[8] = (xz + wy);
  9072. outE[9] = (yz - wx);
  9073. outE[10] = (1 - (xx + yy));
  9074. outE[11] = 0;
  9075. outE[12] = trans.x;
  9076. outE[13] = trans.y;
  9077. outE[14] = trans.z;
  9078. outE[15] = 1;
  9079. }
  9080. get type() {
  9081. return this._type;
  9082. }
  9083. get localOffset() {
  9084. return this._localOffset;
  9085. }
  9086. set localOffset(value) {
  9087. this._localOffset = value;
  9088. if (this._compoundParent)
  9089. this._compoundParent._updateChildTransform(this);
  9090. }
  9091. get localRotation() {
  9092. return this._localRotation;
  9093. }
  9094. set localRotation(value) {
  9095. this._localRotation = value;
  9096. if (this._compoundParent)
  9097. this._compoundParent._updateChildTransform(this);
  9098. }
  9099. _setScale(value) {
  9100. if (this._compoundParent) {
  9101. this.updateLocalTransformations();
  9102. }
  9103. else {
  9104. ColliderShape._nativeScale.setValue(value.x, value.y, value.z);
  9105. this._nativeShape.setLocalScaling(ColliderShape._nativeScale);
  9106. }
  9107. }
  9108. _addReference() {
  9109. this._referenceCount++;
  9110. }
  9111. _removeReference() {
  9112. this._referenceCount--;
  9113. }
  9114. updateLocalTransformations() {
  9115. if (this._compoundParent) {
  9116. var offset = ColliderShape._tempVector30;
  9117. Vector3.multiply(this.localOffset, this._scale, offset);
  9118. ColliderShape._createAffineTransformation(offset, this.localRotation, this._centerMatrix.elements);
  9119. }
  9120. else {
  9121. ColliderShape._createAffineTransformation(this.localOffset, this.localRotation, this._centerMatrix.elements);
  9122. }
  9123. }
  9124. cloneTo(destObject) {
  9125. var destColliderShape = destObject;
  9126. this._localOffset.cloneTo(destColliderShape.localOffset);
  9127. this._localRotation.cloneTo(destColliderShape.localRotation);
  9128. destColliderShape.localOffset = destColliderShape.localOffset;
  9129. destColliderShape.localRotation = destColliderShape.localRotation;
  9130. }
  9131. clone() {
  9132. return null;
  9133. }
  9134. destroy() {
  9135. if (this._nativeShape) {
  9136. Physics3D._physics3D.destroy(this._nativeShape);
  9137. this._nativeShape = null;
  9138. }
  9139. }
  9140. }
  9141. ColliderShape.SHAPEORIENTATION_UPX = 0;
  9142. ColliderShape.SHAPEORIENTATION_UPY = 1;
  9143. ColliderShape.SHAPEORIENTATION_UPZ = 2;
  9144. ColliderShape.SHAPETYPES_BOX = 0;
  9145. ColliderShape.SHAPETYPES_SPHERE = 1;
  9146. ColliderShape.SHAPETYPES_CYLINDER = 2;
  9147. ColliderShape.SHAPETYPES_CAPSULE = 3;
  9148. ColliderShape.SHAPETYPES_CONVEXHULL = 4;
  9149. ColliderShape.SHAPETYPES_COMPOUND = 5;
  9150. ColliderShape.SHAPETYPES_STATICPLANE = 6;
  9151. ColliderShape.SHAPETYPES_CONE = 7;
  9152. ColliderShape._tempVector30 = new Vector3();
  9153. class BoxColliderShape extends ColliderShape {
  9154. static __init__() {
  9155. BoxColliderShape._nativeSize = new Physics3D._physics3D.btVector3(0, 0, 0);
  9156. }
  9157. get sizeX() {
  9158. return this._sizeX;
  9159. }
  9160. get sizeY() {
  9161. return this._sizeY;
  9162. }
  9163. get sizeZ() {
  9164. return this._sizeZ;
  9165. }
  9166. constructor(sizeX = 1.0, sizeY = 1.0, sizeZ = 1.0) {
  9167. super();
  9168. this._sizeX = sizeX;
  9169. this._sizeY = sizeY;
  9170. this._sizeZ = sizeZ;
  9171. this._type = ColliderShape.SHAPETYPES_BOX;
  9172. BoxColliderShape._nativeSize.setValue(sizeX / 2, sizeY / 2, sizeZ / 2);
  9173. this._nativeShape = new Physics3D._physics3D.btBoxShape(BoxColliderShape._nativeSize);
  9174. }
  9175. clone() {
  9176. var dest = new BoxColliderShape(this._sizeX, this._sizeY, this._sizeZ);
  9177. this.cloneTo(dest);
  9178. return dest;
  9179. }
  9180. }
  9181. class CapsuleColliderShape extends ColliderShape {
  9182. constructor(radius = 0.5, length = 1.25, orientation = ColliderShape.SHAPEORIENTATION_UPY) {
  9183. super();
  9184. this._radius = radius;
  9185. this._length = length;
  9186. this._orientation = orientation;
  9187. this._type = ColliderShape.SHAPETYPES_CAPSULE;
  9188. switch (orientation) {
  9189. case ColliderShape.SHAPEORIENTATION_UPX:
  9190. this._nativeShape = new Physics3D._physics3D.btCapsuleShapeX(radius, length - radius * 2);
  9191. break;
  9192. case ColliderShape.SHAPEORIENTATION_UPY:
  9193. this._nativeShape = new Physics3D._physics3D.btCapsuleShape(radius, length - radius * 2);
  9194. break;
  9195. case ColliderShape.SHAPEORIENTATION_UPZ:
  9196. this._nativeShape = new Physics3D._physics3D.btCapsuleShapeZ(radius, length - radius * 2);
  9197. break;
  9198. default:
  9199. throw "CapsuleColliderShape:unknown orientation.";
  9200. }
  9201. }
  9202. get radius() {
  9203. return this._radius;
  9204. }
  9205. get length() {
  9206. return this._length;
  9207. }
  9208. get orientation() {
  9209. return this._orientation;
  9210. }
  9211. _setScale(value) {
  9212. var fixScale = CapsuleColliderShape._tempVector30;
  9213. switch (this.orientation) {
  9214. case ColliderShape.SHAPEORIENTATION_UPX:
  9215. fixScale.x = value.x;
  9216. fixScale.y = fixScale.z = Math.max(value.y, value.z);
  9217. break;
  9218. case ColliderShape.SHAPEORIENTATION_UPY:
  9219. fixScale.y = value.y;
  9220. fixScale.x = fixScale.z = Math.max(value.x, value.z);
  9221. break;
  9222. case ColliderShape.SHAPEORIENTATION_UPZ:
  9223. fixScale.z = value.z;
  9224. fixScale.x = fixScale.y = Math.max(value.x, value.y);
  9225. break;
  9226. default:
  9227. throw "CapsuleColliderShape:unknown orientation.";
  9228. }
  9229. super._setScale(fixScale);
  9230. }
  9231. clone() {
  9232. var dest = new CapsuleColliderShape(this._radius, this._length, this._orientation);
  9233. this.cloneTo(dest);
  9234. return dest;
  9235. }
  9236. }
  9237. CapsuleColliderShape._tempVector30 = new Vector3();
  9238. class CompoundColliderShape extends ColliderShape {
  9239. constructor() {
  9240. super();
  9241. this._childColliderShapes = [];
  9242. this._type = ColliderShape.SHAPETYPES_COMPOUND;
  9243. this._nativeShape = new Physics3D._physics3D.btCompoundShape();
  9244. }
  9245. static __init__() {
  9246. CompoundColliderShape._nativeVector3One = new Physics3D._physics3D.btVector3(1, 1, 1);
  9247. CompoundColliderShape._nativeTransform = new Physics3D._physics3D.btTransform();
  9248. CompoundColliderShape._nativeOffset = new Physics3D._physics3D.btVector3(0, 0, 0);
  9249. CompoundColliderShape._nativRotation = new Physics3D._physics3D.btQuaternion(0, 0, 0, 1);
  9250. }
  9251. _clearChildShape(shape) {
  9252. shape._attatched = false;
  9253. shape._compoundParent = null;
  9254. shape._indexInCompound = -1;
  9255. }
  9256. _addReference() {
  9257. }
  9258. _removeReference() {
  9259. }
  9260. _updateChildTransform(shape) {
  9261. var offset = shape.localOffset;
  9262. var rotation = shape.localRotation;
  9263. var nativeOffset = ColliderShape._nativeVector30;
  9264. var nativeQuaternion = ColliderShape._nativQuaternion0;
  9265. var nativeTransform = ColliderShape._nativeTransform0;
  9266. nativeOffset.setValue(-offset.x, offset.y, offset.z);
  9267. nativeQuaternion.setValue(-rotation.x, rotation.y, rotation.z, -rotation.w);
  9268. nativeTransform.setOrigin(nativeOffset);
  9269. nativeTransform.setRotation(nativeQuaternion);
  9270. this._nativeShape.updateChildTransform(shape._indexInCompound, nativeTransform, true);
  9271. }
  9272. addChildShape(shape) {
  9273. if (shape._attatched)
  9274. throw "CompoundColliderShape: this shape has attatched to other entity.";
  9275. shape._attatched = true;
  9276. shape._compoundParent = this;
  9277. shape._indexInCompound = this._childColliderShapes.length;
  9278. this._childColliderShapes.push(shape);
  9279. var offset = shape.localOffset;
  9280. var rotation = shape.localRotation;
  9281. CompoundColliderShape._nativeOffset.setValue(-offset.x, offset.y, offset.z);
  9282. CompoundColliderShape._nativRotation.setValue(-rotation.x, rotation.y, rotation.z, -rotation.w);
  9283. CompoundColliderShape._nativeTransform.setOrigin(CompoundColliderShape._nativeOffset);
  9284. CompoundColliderShape._nativeTransform.setRotation(CompoundColliderShape._nativRotation);
  9285. var nativeScale = this._nativeShape.getLocalScaling();
  9286. this._nativeShape.setLocalScaling(CompoundColliderShape._nativeVector3One);
  9287. this._nativeShape.addChildShape(CompoundColliderShape._nativeTransform, shape._nativeShape);
  9288. this._nativeShape.setLocalScaling(nativeScale);
  9289. (this._attatchedCollisionObject) && (this._attatchedCollisionObject.colliderShape = this);
  9290. }
  9291. removeChildShape(shape) {
  9292. if (shape._compoundParent === this) {
  9293. var index = shape._indexInCompound;
  9294. this._clearChildShape(shape);
  9295. var endShape = this._childColliderShapes[this._childColliderShapes.length - 1];
  9296. endShape._indexInCompound = index;
  9297. this._childColliderShapes[index] = endShape;
  9298. this._childColliderShapes.pop();
  9299. this._nativeShape.removeChildShapeByIndex(index);
  9300. }
  9301. }
  9302. clearChildShape() {
  9303. for (var i = 0, n = this._childColliderShapes.length; i < n; i++) {
  9304. this._clearChildShape(this._childColliderShapes[i]);
  9305. this._nativeShape.removeChildShapeByIndex(0);
  9306. }
  9307. this._childColliderShapes.length = 0;
  9308. }
  9309. getChildShapeCount() {
  9310. return this._childColliderShapes.length;
  9311. }
  9312. cloneTo(destObject) {
  9313. var destCompoundColliderShape = destObject;
  9314. destCompoundColliderShape.clearChildShape();
  9315. for (var i = 0, n = this._childColliderShapes.length; i < n; i++)
  9316. destCompoundColliderShape.addChildShape(this._childColliderShapes[i].clone());
  9317. }
  9318. clone() {
  9319. var dest = new CompoundColliderShape();
  9320. this.cloneTo(dest);
  9321. return dest;
  9322. }
  9323. destroy() {
  9324. super.destroy();
  9325. for (var i = 0, n = this._childColliderShapes.length; i < n; i++) {
  9326. var childShape = this._childColliderShapes[i];
  9327. if (childShape._referenceCount === 0)
  9328. childShape.destroy();
  9329. }
  9330. }
  9331. }
  9332. class ConeColliderShape extends ColliderShape {
  9333. constructor(radius = 0.5, height = 1.0, orientation = ColliderShape.SHAPEORIENTATION_UPY) {
  9334. super();
  9335. this._radius = 1;
  9336. this._height = 0.5;
  9337. this._radius = radius;
  9338. this._height = height;
  9339. this._orientation = orientation;
  9340. this._type = ColliderShape.SHAPETYPES_CYLINDER;
  9341. switch (orientation) {
  9342. case ColliderShape.SHAPEORIENTATION_UPX:
  9343. this._nativeShape = new Physics3D._physics3D.btConeShapeX(radius, height);
  9344. break;
  9345. case ColliderShape.SHAPEORIENTATION_UPY:
  9346. this._nativeShape = new Physics3D._physics3D.btConeShape(radius, height);
  9347. break;
  9348. case ColliderShape.SHAPEORIENTATION_UPZ:
  9349. this._nativeShape = new Physics3D._physics3D.btConeShapeZ(radius, height);
  9350. break;
  9351. default:
  9352. throw "ConeColliderShape:unknown orientation.";
  9353. }
  9354. }
  9355. get radius() {
  9356. return this._radius;
  9357. }
  9358. get height() {
  9359. return this._height;
  9360. }
  9361. get orientation() {
  9362. return this._orientation;
  9363. }
  9364. clone() {
  9365. var dest = new ConeColliderShape(this._radius, this._height, this._orientation);
  9366. this.cloneTo(dest);
  9367. return dest;
  9368. }
  9369. }
  9370. class CylinderColliderShape extends ColliderShape {
  9371. constructor(radius = 0.5, height = 1.0, orientation = ColliderShape.SHAPEORIENTATION_UPY) {
  9372. super();
  9373. this._radius = 1;
  9374. this._height = 0.5;
  9375. this._radius = radius;
  9376. this._height = height;
  9377. this._orientation = orientation;
  9378. this._type = ColliderShape.SHAPETYPES_CYLINDER;
  9379. switch (orientation) {
  9380. case ColliderShape.SHAPEORIENTATION_UPX:
  9381. CylinderColliderShape._nativeSize.setValue(height / 2, radius, radius);
  9382. this._nativeShape = new Physics3D._physics3D.btCylinderShapeX(CylinderColliderShape._nativeSize);
  9383. break;
  9384. case ColliderShape.SHAPEORIENTATION_UPY:
  9385. CylinderColliderShape._nativeSize.setValue(radius, height / 2, radius);
  9386. this._nativeShape = new Physics3D._physics3D.btCylinderShape(CylinderColliderShape._nativeSize);
  9387. break;
  9388. case ColliderShape.SHAPEORIENTATION_UPZ:
  9389. CylinderColliderShape._nativeSize.setValue(radius, radius, height / 2);
  9390. this._nativeShape = new Physics3D._physics3D.btCylinderShapeZ(CylinderColliderShape._nativeSize);
  9391. break;
  9392. default:
  9393. throw "CapsuleColliderShape:unknown orientation.";
  9394. }
  9395. }
  9396. static __init__() {
  9397. CylinderColliderShape._nativeSize = new Physics3D._physics3D.btVector3(0, 0, 0);
  9398. }
  9399. get radius() {
  9400. return this._radius;
  9401. }
  9402. get height() {
  9403. return this._height;
  9404. }
  9405. get orientation() {
  9406. return this._orientation;
  9407. }
  9408. clone() {
  9409. var dest = new CylinderColliderShape(this._radius, this._height, this._orientation);
  9410. this.cloneTo(dest);
  9411. return dest;
  9412. }
  9413. }
  9414. class MeshColliderShape extends ColliderShape {
  9415. constructor() {
  9416. super();
  9417. this._mesh = null;
  9418. this._convex = false;
  9419. }
  9420. get mesh() {
  9421. return this._mesh;
  9422. }
  9423. set mesh(value) {
  9424. if (this._mesh !== value) {
  9425. var physics3D = Physics3D._physics3D;
  9426. if (this._mesh) {
  9427. physics3D.destroy(this._nativeShape);
  9428. }
  9429. if (value) {
  9430. this._nativeShape = new Physics3D._physics3D.btGImpactMeshShape(value._getPhysicMesh());
  9431. this._nativeShape.updateBound();
  9432. }
  9433. this._mesh = value;
  9434. }
  9435. }
  9436. get convex() {
  9437. return this._convex;
  9438. }
  9439. set convex(value) {
  9440. this._convex = value;
  9441. }
  9442. _setScale(value) {
  9443. if (this._compoundParent) {
  9444. this.updateLocalTransformations();
  9445. }
  9446. else {
  9447. ColliderShape._nativeScale.setValue(value.x, value.y, value.z);
  9448. this._nativeShape.setLocalScaling(ColliderShape._nativeScale);
  9449. this._nativeShape.updateBound();
  9450. }
  9451. }
  9452. cloneTo(destObject) {
  9453. var destMeshCollider = destObject;
  9454. destMeshCollider.convex = this._convex;
  9455. destMeshCollider.mesh = this._mesh;
  9456. super.cloneTo(destObject);
  9457. }
  9458. clone() {
  9459. var dest = new MeshColliderShape();
  9460. this.cloneTo(dest);
  9461. return dest;
  9462. }
  9463. destroy() {
  9464. if (this._nativeShape) {
  9465. var physics3D = Physics3D._physics3D;
  9466. physics3D.destroy(this._nativeShape);
  9467. this._nativeShape = null;
  9468. }
  9469. }
  9470. }
  9471. class SphereColliderShape extends ColliderShape {
  9472. get radius() {
  9473. return this._radius;
  9474. }
  9475. constructor(radius = 0.5) {
  9476. super();
  9477. this._radius = radius;
  9478. this._type = ColliderShape.SHAPETYPES_SPHERE;
  9479. this._nativeShape = new Physics3D._physics3D.btSphereShape(radius);
  9480. }
  9481. clone() {
  9482. var dest = new SphereColliderShape(this._radius);
  9483. this.cloneTo(dest);
  9484. return dest;
  9485. }
  9486. }
  9487. class PhysicsComponent extends Laya.Component {
  9488. constructor(collisionGroup, canCollideWith) {
  9489. super();
  9490. this._restitution = 0.0;
  9491. this._friction = 0.5;
  9492. this._rollingFriction = 0.0;
  9493. this._ccdMotionThreshold = 0.0;
  9494. this._ccdSweptSphereRadius = 0.0;
  9495. this._collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER;
  9496. this._canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER;
  9497. this._colliderShape = null;
  9498. this._transformFlag = 2147483647;
  9499. this._enableProcessCollisions = true;
  9500. this._inPhysicUpdateListIndex = -1;
  9501. this.canScaleShape = true;
  9502. this._collisionGroup = collisionGroup;
  9503. this._canCollideWith = canCollideWith;
  9504. PhysicsComponent._physicObjectsMap[this.id] = this;
  9505. }
  9506. static __init__() {
  9507. PhysicsComponent._nativeVector30 = new Physics3D._physics3D.btVector3(0, 0, 0);
  9508. PhysicsComponent._nativeQuaternion0 = new Physics3D._physics3D.btQuaternion(0, 0, 0, 1);
  9509. }
  9510. static _createAffineTransformationArray(tranX, tranY, tranZ, rotX, rotY, rotZ, rotW, scale, outE) {
  9511. var x2 = rotX + rotX, y2 = rotY + rotY, z2 = rotZ + rotZ;
  9512. var xx = rotX * x2, xy = rotX * y2, xz = rotX * z2, yy = rotY * y2, yz = rotY * z2, zz = rotZ * z2;
  9513. var wx = rotW * x2, wy = rotW * y2, wz = rotW * z2, sx = scale[0], sy = scale[1], sz = scale[2];
  9514. outE[0] = (1 - (yy + zz)) * sx;
  9515. outE[1] = (xy + wz) * sx;
  9516. outE[2] = (xz - wy) * sx;
  9517. outE[3] = 0;
  9518. outE[4] = (xy - wz) * sy;
  9519. outE[5] = (1 - (xx + zz)) * sy;
  9520. outE[6] = (yz + wx) * sy;
  9521. outE[7] = 0;
  9522. outE[8] = (xz + wy) * sz;
  9523. outE[9] = (yz - wx) * sz;
  9524. outE[10] = (1 - (xx + yy)) * sz;
  9525. outE[11] = 0;
  9526. outE[12] = tranX;
  9527. outE[13] = tranY;
  9528. outE[14] = tranZ;
  9529. outE[15] = 1;
  9530. }
  9531. static _creatShape(shapeData) {
  9532. var colliderShape;
  9533. switch (shapeData.type) {
  9534. case "BoxColliderShape":
  9535. var sizeData = shapeData.size;
  9536. colliderShape = sizeData ? new BoxColliderShape(sizeData[0], sizeData[1], sizeData[2]) : new BoxColliderShape();
  9537. break;
  9538. case "SphereColliderShape":
  9539. colliderShape = new SphereColliderShape(shapeData.radius);
  9540. break;
  9541. case "CapsuleColliderShape":
  9542. colliderShape = new CapsuleColliderShape(shapeData.radius, shapeData.height, shapeData.orientation);
  9543. break;
  9544. case "MeshColliderShape":
  9545. var meshCollider = new MeshColliderShape();
  9546. shapeData.mesh && (meshCollider.mesh = Laya.Loader.getRes(shapeData.mesh));
  9547. colliderShape = meshCollider;
  9548. break;
  9549. case "ConeColliderShape":
  9550. colliderShape = new ConeColliderShape(shapeData.radius, shapeData.height, shapeData.orientation);
  9551. break;
  9552. case "CylinderColliderShape":
  9553. colliderShape = new CylinderColliderShape(shapeData.radius, shapeData.height, shapeData.orientation);
  9554. break;
  9555. default:
  9556. throw "unknown shape type.";
  9557. }
  9558. if (shapeData.center) {
  9559. var localOffset = colliderShape.localOffset;
  9560. localOffset.fromArray(shapeData.center);
  9561. colliderShape.localOffset = localOffset;
  9562. }
  9563. return colliderShape;
  9564. }
  9565. static physicVector3TransformQuat(source, qx, qy, qz, qw, out) {
  9566. var x = source.x, y = source.y, z = source.z, ix = qw * x + qy * z - qz * y, iy = qw * y + qz * x - qx * z, iz = qw * z + qx * y - qy * x, iw = -qx * x - qy * y - qz * z;
  9567. out.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  9568. out.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  9569. out.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  9570. }
  9571. static physicQuaternionMultiply(lx, ly, lz, lw, right, out) {
  9572. var rx = right.x;
  9573. var ry = right.y;
  9574. var rz = right.z;
  9575. var rw = right.w;
  9576. var a = (ly * rz - lz * ry);
  9577. var b = (lz * rx - lx * rz);
  9578. var c = (lx * ry - ly * rx);
  9579. var d = (lx * rx + ly * ry + lz * rz);
  9580. out.x = (lx * rw + rx * lw) + a;
  9581. out.y = (ly * rw + ry * lw) + b;
  9582. out.z = (lz * rw + rz * lw) + c;
  9583. out.w = lw * rw - d;
  9584. }
  9585. get restitution() {
  9586. return this._restitution;
  9587. }
  9588. set restitution(value) {
  9589. this._restitution = value;
  9590. this._nativeColliderObject && this._nativeColliderObject.setRestitution(value);
  9591. }
  9592. get friction() {
  9593. return this._friction;
  9594. }
  9595. set friction(value) {
  9596. this._friction = value;
  9597. this._nativeColliderObject && this._nativeColliderObject.setFriction(value);
  9598. }
  9599. get rollingFriction() {
  9600. return this._nativeColliderObject.getRollingFriction();
  9601. }
  9602. set rollingFriction(value) {
  9603. this._rollingFriction = value;
  9604. this._nativeColliderObject && this._nativeColliderObject.setRollingFriction(value);
  9605. }
  9606. get ccdMotionThreshold() {
  9607. return this._ccdMotionThreshold;
  9608. }
  9609. set ccdMotionThreshold(value) {
  9610. this._ccdMotionThreshold = value;
  9611. this._nativeColliderObject && this._nativeColliderObject.setCcdMotionThreshold(value);
  9612. }
  9613. get ccdSweptSphereRadius() {
  9614. return this._ccdSweptSphereRadius;
  9615. }
  9616. set ccdSweptSphereRadius(value) {
  9617. this._ccdSweptSphereRadius = value;
  9618. this._nativeColliderObject && this._nativeColliderObject.setCcdSweptSphereRadius(value);
  9619. }
  9620. get isActive() {
  9621. return this._nativeColliderObject ? this._nativeColliderObject.isActive() : false;
  9622. }
  9623. get enabled() {
  9624. return super.enabled;
  9625. }
  9626. set enabled(value) {
  9627. if (this._enabled != value) {
  9628. if (this._simulation && this._colliderShape) {
  9629. if (value) {
  9630. this._derivePhysicsTransformation(true);
  9631. this._addToSimulation();
  9632. }
  9633. else {
  9634. this._removeFromSimulation();
  9635. }
  9636. }
  9637. super.enabled = value;
  9638. }
  9639. }
  9640. get colliderShape() {
  9641. return this._colliderShape;
  9642. }
  9643. set colliderShape(value) {
  9644. var lastColliderShape = this._colliderShape;
  9645. if (lastColliderShape) {
  9646. lastColliderShape._attatched = false;
  9647. lastColliderShape._attatchedCollisionObject = null;
  9648. }
  9649. this._colliderShape = value;
  9650. if (value) {
  9651. if (value._attatched) {
  9652. throw "PhysicsComponent: this shape has attatched to other entity.";
  9653. }
  9654. else {
  9655. value._attatched = true;
  9656. value._attatchedCollisionObject = this;
  9657. }
  9658. if (this._nativeColliderObject) {
  9659. this._nativeColliderObject.setCollisionShape(value._nativeShape);
  9660. var canInSimulation = this._simulation && this._enabled;
  9661. (canInSimulation && lastColliderShape) && (this._removeFromSimulation());
  9662. this._onShapeChange(value);
  9663. if (canInSimulation) {
  9664. this._derivePhysicsTransformation(true);
  9665. this._addToSimulation();
  9666. }
  9667. }
  9668. }
  9669. else {
  9670. if (this._simulation && this._enabled)
  9671. lastColliderShape && this._removeFromSimulation();
  9672. }
  9673. }
  9674. get simulation() {
  9675. return this._simulation;
  9676. }
  9677. get collisionGroup() {
  9678. return this._collisionGroup;
  9679. }
  9680. set collisionGroup(value) {
  9681. if (this._collisionGroup !== value) {
  9682. this._collisionGroup = value;
  9683. if (this._simulation && this._colliderShape && this._enabled) {
  9684. this._removeFromSimulation();
  9685. this._addToSimulation();
  9686. }
  9687. }
  9688. }
  9689. get canCollideWith() {
  9690. return this._canCollideWith;
  9691. }
  9692. set canCollideWith(value) {
  9693. if (this._canCollideWith !== value) {
  9694. this._canCollideWith = value;
  9695. if (this._simulation && this._colliderShape && this._enabled) {
  9696. this._removeFromSimulation();
  9697. this._addToSimulation();
  9698. }
  9699. }
  9700. }
  9701. _isValid() {
  9702. return this._simulation && this._colliderShape && this._enabled;
  9703. }
  9704. _parse(data) {
  9705. (data.collisionGroup != null) && (this.collisionGroup = data.collisionGroup);
  9706. (data.canCollideWith != null) && (this.canCollideWith = data.canCollideWith);
  9707. (data.ccdMotionThreshold != null) && (this.ccdMotionThreshold = data.ccdMotionThreshold);
  9708. (data.ccdSweptSphereRadius != null) && (this.ccdSweptSphereRadius = data.ccdSweptSphereRadius);
  9709. }
  9710. _parseShape(shapesData) {
  9711. var shapeCount = shapesData.length;
  9712. if (shapeCount === 1) {
  9713. var shape = PhysicsComponent._creatShape(shapesData[0]);
  9714. this.colliderShape = shape;
  9715. }
  9716. else {
  9717. var compoundShape = new CompoundColliderShape();
  9718. for (var i = 0; i < shapeCount; i++) {
  9719. shape = PhysicsComponent._creatShape(shapesData[i]);
  9720. compoundShape.addChildShape(shape);
  9721. }
  9722. this.colliderShape = compoundShape;
  9723. }
  9724. }
  9725. _onScaleChange(scale) {
  9726. this._colliderShape._setScale(scale);
  9727. }
  9728. _setTransformFlag(type, value) {
  9729. if (value)
  9730. this._transformFlag |= type;
  9731. else
  9732. this._transformFlag &= ~type;
  9733. }
  9734. _getTransformFlag(type) {
  9735. return (this._transformFlag & type) != 0;
  9736. }
  9737. _addToSimulation() {
  9738. }
  9739. _removeFromSimulation() {
  9740. }
  9741. _derivePhysicsTransformation(force) {
  9742. this._innerDerivePhysicsTransformation(this._nativeColliderObject.getWorldTransform(), force);
  9743. }
  9744. _innerDerivePhysicsTransformation(physicTransformOut, force) {
  9745. var transform = this.owner._transform;
  9746. var rotation = transform.rotation;
  9747. if (force || this._getTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION)) {
  9748. var shapeOffset = this._colliderShape.localOffset;
  9749. var position = transform.position;
  9750. var nativePosition = PhysicsComponent._nativeVector30;
  9751. if (shapeOffset.x !== 0 || shapeOffset.y !== 0 || shapeOffset.z !== 0) {
  9752. var physicPosition = PhysicsComponent._tempVector30;
  9753. PhysicsComponent.physicVector3TransformQuat(shapeOffset, rotation.x, rotation.y, rotation.z, rotation.w, physicPosition);
  9754. Vector3.add(position, physicPosition, physicPosition);
  9755. nativePosition.setValue(-physicPosition.x, physicPosition.y, physicPosition.z);
  9756. }
  9757. else {
  9758. nativePosition.setValue(-position.x, position.y, position.z);
  9759. }
  9760. physicTransformOut.setOrigin(nativePosition);
  9761. this._setTransformFlag(Transform3D.TRANSFORM_WORLDPOSITION, false);
  9762. }
  9763. if (force || this._getTransformFlag(Transform3D.TRANSFORM_WORLDQUATERNION)) {
  9764. var shapeRotation = this._colliderShape.localRotation;
  9765. var nativeRotation = PhysicsComponent._nativeQuaternion0;
  9766. if (shapeRotation.x !== 0 || shapeRotation.y !== 0 || shapeRotation.z !== 0 || shapeRotation.w !== 1) {
  9767. var physicRotation = PhysicsComponent._tempQuaternion0;
  9768. PhysicsComponent.physicQuaternionMultiply(rotation.x, rotation.y, rotation.z, rotation.w, shapeRotation, physicRotation);
  9769. nativeRotation.setValue(-physicRotation.x, physicRotation.y, physicRotation.z, -physicRotation.w);
  9770. }
  9771. else {
  9772. nativeRotation.setValue(-rotation.x, rotation.y, rotation.z, -rotation.w);
  9773. }
  9774. physicTransformOut.setRotation(nativeRotation);
  9775. this._setTransformFlag(Transform3D.TRANSFORM_WORLDQUATERNION, false);
  9776. }
  9777. if (force || this._getTransformFlag(Transform3D.TRANSFORM_WORLDSCALE)) {
  9778. this._onScaleChange(transform.getWorldLossyScale());
  9779. this._setTransformFlag(Transform3D.TRANSFORM_WORLDSCALE, false);
  9780. }
  9781. }
  9782. _updateTransformComponent(physicsTransform) {
  9783. var localOffset = this._colliderShape.localOffset;
  9784. var localRotation = this._colliderShape.localRotation;
  9785. var transform = this.owner._transform;
  9786. var position = transform.position;
  9787. var rotation = transform.rotation;
  9788. var nativePosition = physicsTransform.getOrigin();
  9789. var nativeRotation = physicsTransform.getRotation();
  9790. var nativeRotX = -nativeRotation.x();
  9791. var nativeRotY = nativeRotation.y();
  9792. var nativeRotZ = nativeRotation.z();
  9793. var nativeRotW = -nativeRotation.w();
  9794. if (localOffset.x !== 0 || localOffset.y !== 0 || localOffset.z !== 0) {
  9795. var rotShapePosition = PhysicsComponent._tempVector30;
  9796. PhysicsComponent.physicVector3TransformQuat(localOffset, nativeRotX, nativeRotY, nativeRotZ, nativeRotW, rotShapePosition);
  9797. position.x = -nativePosition.x() - rotShapePosition.x;
  9798. position.y = nativePosition.y() - rotShapePosition.y;
  9799. position.z = nativePosition.z() - rotShapePosition.z;
  9800. }
  9801. else {
  9802. position.x = -nativePosition.x();
  9803. position.y = nativePosition.y();
  9804. position.z = nativePosition.z();
  9805. }
  9806. transform.position = position;
  9807. if (localRotation.x !== 0 || localRotation.y !== 0 || localRotation.z !== 0 || localRotation.w !== 1) {
  9808. var invertShapeRotaion = PhysicsComponent._tempQuaternion0;
  9809. localRotation.invert(invertShapeRotaion);
  9810. PhysicsComponent.physicQuaternionMultiply(nativeRotX, nativeRotY, nativeRotZ, nativeRotW, invertShapeRotaion, rotation);
  9811. }
  9812. else {
  9813. rotation.x = nativeRotX;
  9814. rotation.y = nativeRotY;
  9815. rotation.z = nativeRotZ;
  9816. rotation.w = nativeRotW;
  9817. }
  9818. transform.rotation = rotation;
  9819. }
  9820. _onEnable() {
  9821. this._simulation = this.owner._scene.physicsSimulation;
  9822. this._nativeColliderObject.setContactProcessingThreshold(1e30);
  9823. if (this._colliderShape && this._enabled) {
  9824. this._derivePhysicsTransformation(true);
  9825. this._addToSimulation();
  9826. }
  9827. }
  9828. _onDisable() {
  9829. if (this._colliderShape && this._enabled) {
  9830. this._removeFromSimulation();
  9831. (this._inPhysicUpdateListIndex !== -1) && (this._simulation._physicsUpdateList.remove(this));
  9832. }
  9833. this._simulation = null;
  9834. }
  9835. _onShapeChange(colShape) {
  9836. var btColObj = this._nativeColliderObject;
  9837. var flags = btColObj.getCollisionFlags();
  9838. if (colShape.needsCustomCollisionCallback) {
  9839. if ((flags & PhysicsComponent.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK) === 0)
  9840. btColObj.setCollisionFlags(flags | PhysicsComponent.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK);
  9841. }
  9842. else {
  9843. if ((flags & PhysicsComponent.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK) > 0)
  9844. btColObj.setCollisionFlags(flags ^ PhysicsComponent.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK);
  9845. }
  9846. }
  9847. _onAdded() {
  9848. this.enabled = this._enabled;
  9849. this.restitution = this._restitution;
  9850. this.friction = this._friction;
  9851. this.rollingFriction = this._rollingFriction;
  9852. this.ccdMotionThreshold = this._ccdMotionThreshold;
  9853. this.ccdSweptSphereRadius = this._ccdSweptSphereRadius;
  9854. this.owner.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onTransformChanged);
  9855. }
  9856. _onDestroy() {
  9857. var physics3D = Physics3D._physics3D;
  9858. delete PhysicsComponent._physicObjectsMap[this.id];
  9859. physics3D.destroy(this._nativeColliderObject);
  9860. this._colliderShape.destroy();
  9861. super._onDestroy();
  9862. this._nativeColliderObject = null;
  9863. this._colliderShape = null;
  9864. this._simulation = null;
  9865. this.owner.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onTransformChanged);
  9866. }
  9867. _onTransformChanged(flag) {
  9868. if (PhysicsComponent._addUpdateList) {
  9869. flag &= Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE;
  9870. if (flag) {
  9871. this._transformFlag |= flag;
  9872. if (this._isValid() && this._inPhysicUpdateListIndex === -1)
  9873. this._simulation._physicsUpdateList.add(this);
  9874. }
  9875. }
  9876. }
  9877. _cloneTo(dest) {
  9878. var destPhysicsComponent = dest;
  9879. destPhysicsComponent.restitution = this._restitution;
  9880. destPhysicsComponent.friction = this._friction;
  9881. destPhysicsComponent.rollingFriction = this._rollingFriction;
  9882. destPhysicsComponent.ccdMotionThreshold = this._ccdMotionThreshold;
  9883. destPhysicsComponent.ccdSweptSphereRadius = this._ccdSweptSphereRadius;
  9884. destPhysicsComponent.collisionGroup = this._collisionGroup;
  9885. destPhysicsComponent.canCollideWith = this._canCollideWith;
  9886. destPhysicsComponent.canScaleShape = this.canScaleShape;
  9887. (this._colliderShape) && (destPhysicsComponent.colliderShape = this._colliderShape.clone());
  9888. }
  9889. }
  9890. PhysicsComponent.ACTIVATIONSTATE_ACTIVE_TAG = 1;
  9891. PhysicsComponent.ACTIVATIONSTATE_ISLAND_SLEEPING = 2;
  9892. PhysicsComponent.ACTIVATIONSTATE_WANTS_DEACTIVATION = 3;
  9893. PhysicsComponent.ACTIVATIONSTATE_DISABLE_DEACTIVATION = 4;
  9894. PhysicsComponent.ACTIVATIONSTATE_DISABLE_SIMULATION = 5;
  9895. PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT = 1;
  9896. PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT = 2;
  9897. PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE = 4;
  9898. PhysicsComponent.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK = 8;
  9899. PhysicsComponent.COLLISIONFLAGS_CHARACTER_OBJECT = 16;
  9900. PhysicsComponent.COLLISIONFLAGS_DISABLE_VISUALIZE_OBJECT = 32;
  9901. PhysicsComponent.COLLISIONFLAGS_DISABLE_SPU_COLLISION_PROCESSING = 64;
  9902. PhysicsComponent._tempVector30 = new Vector3();
  9903. PhysicsComponent._tempQuaternion0 = new Quaternion();
  9904. PhysicsComponent._tempQuaternion1 = new Quaternion();
  9905. PhysicsComponent._tempMatrix4x40 = new Matrix4x4();
  9906. PhysicsComponent._physicObjectsMap = {};
  9907. PhysicsComponent._addUpdateList = true;
  9908. class PhysicsUpdateList extends SingletonList {
  9909. constructor() {
  9910. super();
  9911. }
  9912. add(element) {
  9913. var index = element._inPhysicUpdateListIndex;
  9914. if (index !== -1)
  9915. throw "PhysicsUpdateList:element has in PhysicsUpdateList.";
  9916. this._add(element);
  9917. element._inPhysicUpdateListIndex = this.length++;
  9918. }
  9919. remove(element) {
  9920. var index = element._inPhysicUpdateListIndex;
  9921. this.length--;
  9922. if (index !== this.length) {
  9923. var end = this.elements[this.length];
  9924. this.elements[index] = end;
  9925. end._inPhysicUpdateListIndex = index;
  9926. }
  9927. element._inPhysicUpdateListIndex = -1;
  9928. }
  9929. }
  9930. class ContactPoint {
  9931. constructor() {
  9932. this._idCounter = 0;
  9933. this.colliderA = null;
  9934. this.colliderB = null;
  9935. this.distance = 0;
  9936. this.normal = new Vector3();
  9937. this.positionOnA = new Vector3();
  9938. this.positionOnB = new Vector3();
  9939. this._id = ++this._idCounter;
  9940. }
  9941. }
  9942. class HitResult {
  9943. constructor() {
  9944. this.succeeded = false;
  9945. this.collider = null;
  9946. this.point = new Vector3();
  9947. this.normal = new Vector3();
  9948. this.hitFraction = 0;
  9949. }
  9950. }
  9951. class Collision {
  9952. constructor() {
  9953. this._lastUpdateFrame = -2147483648;
  9954. this._updateFrame = -2147483648;
  9955. this._isTrigger = false;
  9956. this.contacts = [];
  9957. }
  9958. _setUpdateFrame(farme) {
  9959. this._lastUpdateFrame = this._updateFrame;
  9960. this._updateFrame = farme;
  9961. }
  9962. }
  9963. class CollisionTool {
  9964. constructor() {
  9965. this._hitResultsPoolIndex = 0;
  9966. this._hitResultsPool = [];
  9967. this._contactPonintsPoolIndex = 0;
  9968. this._contactPointsPool = [];
  9969. this._collisionsPool = [];
  9970. this._collisions = {};
  9971. }
  9972. getHitResult() {
  9973. var hitResult = this._hitResultsPool[this._hitResultsPoolIndex++];
  9974. if (!hitResult) {
  9975. hitResult = new HitResult();
  9976. this._hitResultsPool.push(hitResult);
  9977. }
  9978. return hitResult;
  9979. }
  9980. recoverAllHitResultsPool() {
  9981. this._hitResultsPoolIndex = 0;
  9982. }
  9983. getContactPoints() {
  9984. var contactPoint = this._contactPointsPool[this._contactPonintsPoolIndex++];
  9985. if (!contactPoint) {
  9986. contactPoint = new ContactPoint();
  9987. this._contactPointsPool.push(contactPoint);
  9988. }
  9989. return contactPoint;
  9990. }
  9991. recoverAllContactPointsPool() {
  9992. this._contactPonintsPoolIndex = 0;
  9993. }
  9994. getCollision(physicComponentA, physicComponentB) {
  9995. var collision;
  9996. var idA = physicComponentA.id;
  9997. var idB = physicComponentB.id;
  9998. var subCollisionFirst = this._collisions[idA];
  9999. if (subCollisionFirst)
  10000. collision = subCollisionFirst[idB];
  10001. if (!collision) {
  10002. if (!subCollisionFirst) {
  10003. subCollisionFirst = {};
  10004. this._collisions[idA] = subCollisionFirst;
  10005. }
  10006. collision = this._collisionsPool.length === 0 ? new Collision() : this._collisionsPool.pop();
  10007. collision._colliderA = physicComponentA;
  10008. collision._colliderB = physicComponentB;
  10009. subCollisionFirst[idB] = collision;
  10010. }
  10011. return collision;
  10012. }
  10013. recoverCollision(collision) {
  10014. var idA = collision._colliderA.id;
  10015. var idB = collision._colliderB.id;
  10016. this._collisions[idA][idB] = null;
  10017. this._collisionsPool.push(collision);
  10018. }
  10019. garbageCollection() {
  10020. this._hitResultsPoolIndex = 0;
  10021. this._hitResultsPool.length = 0;
  10022. this._contactPonintsPoolIndex = 0;
  10023. this._contactPointsPool.length = 0;
  10024. this._collisionsPool.length = 0;
  10025. for (var subCollisionsKey in this._collisionsPool) {
  10026. var subCollisions = this._collisionsPool[subCollisionsKey];
  10027. var wholeDelete = true;
  10028. for (var collisionKey in subCollisions) {
  10029. if (subCollisions[collisionKey])
  10030. wholeDelete = false;
  10031. else
  10032. delete subCollisions[collisionKey];
  10033. }
  10034. if (wholeDelete)
  10035. delete this._collisionsPool[subCollisionsKey];
  10036. }
  10037. }
  10038. }
  10039. class PhysicsSimulation {
  10040. constructor(configuration, flags = 0) {
  10041. this._gravity = new Vector3(0, -10, 0);
  10042. this._nativeVector3Zero = new Physics3D._physics3D.btVector3(0, 0, 0);
  10043. this._nativeDefaultQuaternion = new Physics3D._physics3D.btQuaternion(0, 0, 0, -1);
  10044. this._collisionsUtils = new CollisionTool();
  10045. this._previousFrameCollisions = [];
  10046. this._currentFrameCollisions = [];
  10047. this._physicsUpdateList = new PhysicsUpdateList();
  10048. this._characters = [];
  10049. this._updatedRigidbodies = 0;
  10050. this.maxSubSteps = 1;
  10051. this.fixedTimeStep = 1.0 / 60.0;
  10052. this.maxSubSteps = configuration.maxSubSteps;
  10053. this.fixedTimeStep = configuration.fixedTimeStep;
  10054. var physics3D = Physics3D._physics3D;
  10055. this._nativeCollisionConfiguration = new physics3D.btDefaultCollisionConfiguration();
  10056. this._nativeDispatcher = new physics3D.btCollisionDispatcher(this._nativeCollisionConfiguration);
  10057. this._nativeBroadphase = new physics3D.btDbvtBroadphase();
  10058. this._nativeBroadphase.getOverlappingPairCache().setInternalGhostPairCallback(new physics3D.btGhostPairCallback());
  10059. var conFlags = configuration.flags;
  10060. if (conFlags & PhysicsSimulation.PHYSICSENGINEFLAGS_COLLISIONSONLY) {
  10061. this._nativeCollisionWorld = new physics3D.btCollisionWorld(this._nativeDispatcher, this._nativeBroadphase, this._nativeCollisionConfiguration);
  10062. }
  10063. else if (conFlags & PhysicsSimulation.PHYSICSENGINEFLAGS_SOFTBODYSUPPORT) {
  10064. throw "PhysicsSimulation:SoftBody processing is not yet available";
  10065. }
  10066. else {
  10067. var solver = new physics3D.btSequentialImpulseConstraintSolver();
  10068. this._nativeDiscreteDynamicsWorld = new physics3D.btDiscreteDynamicsWorld(this._nativeDispatcher, this._nativeBroadphase, solver, this._nativeCollisionConfiguration);
  10069. this._nativeCollisionWorld = this._nativeDiscreteDynamicsWorld;
  10070. }
  10071. if (this._nativeDiscreteDynamicsWorld) {
  10072. this._nativeSolverInfo = this._nativeDiscreteDynamicsWorld.getSolverInfo();
  10073. this._nativeDispatchInfo = this._nativeDiscreteDynamicsWorld.getDispatchInfo();
  10074. }
  10075. this._nativeClosestRayResultCallback = new physics3D.ClosestRayResultCallback(this._nativeVector3Zero, this._nativeVector3Zero);
  10076. this._nativeAllHitsRayResultCallback = new physics3D.AllHitsRayResultCallback(this._nativeVector3Zero, this._nativeVector3Zero);
  10077. this._nativeClosestConvexResultCallback = new physics3D.ClosestConvexResultCallback(this._nativeVector3Zero, this._nativeVector3Zero);
  10078. this._nativeAllConvexResultCallback = new physics3D.AllConvexResultCallback(this._nativeVector3Zero, this._nativeVector3Zero);
  10079. physics3D._btGImpactCollisionAlgorithm_RegisterAlgorithm(this._nativeDispatcher.a);
  10080. }
  10081. static __init__() {
  10082. PhysicsSimulation._nativeTempVector30 = new Physics3D._physics3D.btVector3(0, 0, 0);
  10083. PhysicsSimulation._nativeTempVector31 = new Physics3D._physics3D.btVector3(0, 0, 0);
  10084. PhysicsSimulation._nativeTempQuaternion0 = new Physics3D._physics3D.btQuaternion(0, 0, 0, 1);
  10085. PhysicsSimulation._nativeTempQuaternion1 = new Physics3D._physics3D.btQuaternion(0, 0, 0, 1);
  10086. PhysicsSimulation._nativeTempTransform0 = new Physics3D._physics3D.btTransform();
  10087. PhysicsSimulation._nativeTempTransform1 = new Physics3D._physics3D.btTransform();
  10088. }
  10089. static createConstraint() {
  10090. }
  10091. get continuousCollisionDetection() {
  10092. return this._nativeDispatchInfo.get_m_useContinuous();
  10093. }
  10094. set continuousCollisionDetection(value) {
  10095. this._nativeDispatchInfo.set_m_useContinuous(value);
  10096. }
  10097. get gravity() {
  10098. if (!this._nativeDiscreteDynamicsWorld)
  10099. throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
  10100. return this._gravity;
  10101. }
  10102. set gravity(value) {
  10103. if (!this._nativeDiscreteDynamicsWorld)
  10104. throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
  10105. this._gravity = value;
  10106. var nativeGravity = PhysicsSimulation._nativeTempVector30;
  10107. nativeGravity.setValue(-value.x, value.y, value.z);
  10108. this._nativeDiscreteDynamicsWorld.setGravity(nativeGravity);
  10109. }
  10110. get speculativeContactRestitution() {
  10111. if (!this._nativeDiscreteDynamicsWorld)
  10112. throw "Simulation:Cannot Cannot perform this action when the physics engine is set to CollisionsOnly";
  10113. return this._nativeDiscreteDynamicsWorld.getApplySpeculativeContactRestitution();
  10114. }
  10115. set speculativeContactRestitution(value) {
  10116. if (!this._nativeDiscreteDynamicsWorld)
  10117. throw "Simulation:Cannot Cannot perform this action when the physics engine is set to CollisionsOnly";
  10118. this._nativeDiscreteDynamicsWorld.setApplySpeculativeContactRestitution(value);
  10119. }
  10120. _simulate(deltaTime) {
  10121. this._updatedRigidbodies = 0;
  10122. if (this._nativeDiscreteDynamicsWorld)
  10123. this._nativeDiscreteDynamicsWorld.stepSimulation(deltaTime, this.maxSubSteps, this.fixedTimeStep);
  10124. else
  10125. this._nativeCollisionWorld.PerformDiscreteCollisionDetection();
  10126. }
  10127. _destroy() {
  10128. var physics3D = Physics3D._physics3D;
  10129. if (this._nativeDiscreteDynamicsWorld) {
  10130. physics3D.destroy(this._nativeDiscreteDynamicsWorld);
  10131. this._nativeDiscreteDynamicsWorld = null;
  10132. }
  10133. else {
  10134. physics3D.destroy(this._nativeCollisionWorld);
  10135. this._nativeCollisionWorld = null;
  10136. }
  10137. physics3D.destroy(this._nativeBroadphase);
  10138. this._nativeBroadphase = null;
  10139. physics3D.destroy(this._nativeDispatcher);
  10140. this._nativeDispatcher = null;
  10141. physics3D.destroy(this._nativeCollisionConfiguration);
  10142. this._nativeCollisionConfiguration = null;
  10143. }
  10144. _addPhysicsCollider(component, group, mask) {
  10145. this._nativeCollisionWorld.addCollisionObject(component._nativeColliderObject, group, mask);
  10146. }
  10147. _removePhysicsCollider(component) {
  10148. this._nativeCollisionWorld.removeCollisionObject(component._nativeColliderObject);
  10149. }
  10150. _addRigidBody(rigidBody, group, mask) {
  10151. if (!this._nativeDiscreteDynamicsWorld)
  10152. throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
  10153. this._nativeCollisionWorld.addRigidBody(rigidBody._nativeColliderObject, group, mask);
  10154. }
  10155. _removeRigidBody(rigidBody) {
  10156. if (!this._nativeDiscreteDynamicsWorld)
  10157. throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
  10158. this._nativeCollisionWorld.removeRigidBody(rigidBody._nativeColliderObject);
  10159. }
  10160. _addCharacter(character, group, mask) {
  10161. if (!this._nativeDiscreteDynamicsWorld)
  10162. throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
  10163. this._nativeCollisionWorld.addCollisionObject(character._nativeColliderObject, group, mask);
  10164. this._nativeCollisionWorld.addAction(character._nativeKinematicCharacter);
  10165. }
  10166. _removeCharacter(character) {
  10167. if (!this._nativeDiscreteDynamicsWorld)
  10168. throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
  10169. this._nativeCollisionWorld.removeCollisionObject(character._nativeColliderObject);
  10170. this._nativeCollisionWorld.removeAction(character._nativeKinematicCharacter);
  10171. }
  10172. raycastFromTo(from, to, out = null, collisonGroup = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER, collisionMask = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  10173. var rayResultCall = this._nativeClosestRayResultCallback;
  10174. var rayFrom = PhysicsSimulation._nativeTempVector30;
  10175. var rayTo = PhysicsSimulation._nativeTempVector31;
  10176. rayFrom.setValue(-from.x, from.y, from.z);
  10177. rayTo.setValue(-to.x, to.y, to.z);
  10178. rayResultCall.set_m_rayFromWorld(rayFrom);
  10179. rayResultCall.set_m_rayToWorld(rayTo);
  10180. rayResultCall.set_m_collisionFilterGroup(collisonGroup);
  10181. rayResultCall.set_m_collisionFilterMask(collisionMask);
  10182. rayResultCall.set_m_collisionObject(null);
  10183. rayResultCall.set_m_closestHitFraction(1);
  10184. this._nativeCollisionWorld.rayTest(rayFrom, rayTo, rayResultCall);
  10185. if (rayResultCall.hasHit()) {
  10186. if (out) {
  10187. out.succeeded = true;
  10188. out.collider = PhysicsComponent._physicObjectsMap[rayResultCall.get_m_collisionObject().getUserIndex()];
  10189. out.hitFraction = rayResultCall.get_m_closestHitFraction();
  10190. var nativePoint = rayResultCall.get_m_hitPointWorld();
  10191. var point = out.point;
  10192. point.x = -nativePoint.x();
  10193. point.y = nativePoint.y();
  10194. point.z = nativePoint.z();
  10195. var nativeNormal = rayResultCall.get_m_hitNormalWorld();
  10196. var normal = out.normal;
  10197. normal.x = -nativeNormal.x();
  10198. normal.y = nativeNormal.y();
  10199. normal.z = nativeNormal.z();
  10200. }
  10201. return true;
  10202. }
  10203. else {
  10204. if (out)
  10205. out.succeeded = false;
  10206. return false;
  10207. }
  10208. }
  10209. raycastAllFromTo(from, to, out, collisonGroup = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER, collisionMask = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  10210. var rayResultCall = this._nativeAllHitsRayResultCallback;
  10211. var rayFrom = PhysicsSimulation._nativeTempVector30;
  10212. var rayTo = PhysicsSimulation._nativeTempVector31;
  10213. out.length = 0;
  10214. rayFrom.setValue(-from.x, from.y, from.z);
  10215. rayTo.setValue(-to.x, to.y, to.z);
  10216. rayResultCall.set_m_rayFromWorld(rayFrom);
  10217. rayResultCall.set_m_rayToWorld(rayTo);
  10218. rayResultCall.set_m_collisionFilterGroup(collisonGroup);
  10219. rayResultCall.set_m_collisionFilterMask(collisionMask);
  10220. var collisionObjects = rayResultCall.get_m_collisionObjects();
  10221. var nativePoints = rayResultCall.get_m_hitPointWorld();
  10222. var nativeNormals = rayResultCall.get_m_hitNormalWorld();
  10223. var nativeFractions = rayResultCall.get_m_hitFractions();
  10224. collisionObjects.clear();
  10225. nativePoints.clear();
  10226. nativeNormals.clear();
  10227. nativeFractions.clear();
  10228. this._nativeCollisionWorld.rayTest(rayFrom, rayTo, rayResultCall);
  10229. var count = collisionObjects.size();
  10230. if (count > 0) {
  10231. this._collisionsUtils.recoverAllHitResultsPool();
  10232. for (var i = 0; i < count; i++) {
  10233. var hitResult = this._collisionsUtils.getHitResult();
  10234. out.push(hitResult);
  10235. hitResult.succeeded = true;
  10236. hitResult.collider = PhysicsComponent._physicObjectsMap[collisionObjects.at(i).getUserIndex()];
  10237. hitResult.hitFraction = nativeFractions.at(i);
  10238. var nativePoint = nativePoints.at(i);
  10239. var pointE = hitResult.point;
  10240. pointE.x = -nativePoint.x();
  10241. pointE.y = nativePoint.y();
  10242. pointE.z = nativePoint.z();
  10243. var nativeNormal = nativeNormals.at(i);
  10244. var normalE = hitResult.normal;
  10245. normalE.x = -nativeNormal.x();
  10246. normalE.y = nativeNormal.y();
  10247. normalE.z = nativeNormal.z();
  10248. }
  10249. return true;
  10250. }
  10251. else {
  10252. return false;
  10253. }
  10254. }
  10255. rayCast(ray, outHitResult = null, distance = 2147483647, collisonGroup = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER, collisionMask = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  10256. var from = ray.origin;
  10257. var to = PhysicsSimulation._tempVector30;
  10258. Vector3.normalize(ray.direction, to);
  10259. Vector3.scale(to, distance, to);
  10260. Vector3.add(from, to, to);
  10261. return this.raycastFromTo(from, to, outHitResult, collisonGroup, collisionMask);
  10262. }
  10263. rayCastAll(ray, out, distance = 2147483647, collisonGroup = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER, collisionMask = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  10264. var from = ray.origin;
  10265. var to = PhysicsSimulation._tempVector30;
  10266. Vector3.normalize(ray.direction, to);
  10267. Vector3.scale(to, distance, to);
  10268. Vector3.add(from, to, to);
  10269. return this.raycastAllFromTo(from, to, out, collisonGroup, collisionMask);
  10270. }
  10271. shapeCast(shape, fromPosition, toPosition, out = null, fromRotation = null, toRotation = null, collisonGroup = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER, collisionMask = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER, allowedCcdPenetration = 0.0) {
  10272. var convexResultCall = this._nativeClosestConvexResultCallback;
  10273. var convexPosFrom = PhysicsSimulation._nativeTempVector30;
  10274. var convexPosTo = PhysicsSimulation._nativeTempVector31;
  10275. var convexRotFrom = PhysicsSimulation._nativeTempQuaternion0;
  10276. var convexRotTo = PhysicsSimulation._nativeTempQuaternion1;
  10277. var convexTransform = PhysicsSimulation._nativeTempTransform0;
  10278. var convexTransTo = PhysicsSimulation._nativeTempTransform1;
  10279. var sweepShape = shape._nativeShape;
  10280. convexPosFrom.setValue(-fromPosition.x, fromPosition.y, fromPosition.z);
  10281. convexPosTo.setValue(-toPosition.x, toPosition.y, toPosition.z);
  10282. convexResultCall.set_m_collisionFilterGroup(collisonGroup);
  10283. convexResultCall.set_m_collisionFilterMask(collisionMask);
  10284. convexTransform.setOrigin(convexPosFrom);
  10285. convexTransTo.setOrigin(convexPosTo);
  10286. if (fromRotation) {
  10287. convexRotFrom.setValue(-fromRotation.x, fromRotation.y, fromRotation.z, -fromRotation.w);
  10288. convexTransform.setRotation(convexRotFrom);
  10289. }
  10290. else {
  10291. convexTransform.setRotation(this._nativeDefaultQuaternion);
  10292. }
  10293. if (toRotation) {
  10294. convexRotTo.setValue(-toRotation.x, toRotation.y, toRotation.z, -toRotation.w);
  10295. convexTransTo.setRotation(convexRotTo);
  10296. }
  10297. else {
  10298. convexTransTo.setRotation(this._nativeDefaultQuaternion);
  10299. }
  10300. convexResultCall.set_m_hitCollisionObject(null);
  10301. convexResultCall.set_m_closestHitFraction(1);
  10302. this._nativeCollisionWorld.convexSweepTest(sweepShape, convexTransform, convexTransTo, convexResultCall, allowedCcdPenetration);
  10303. if (convexResultCall.hasHit()) {
  10304. if (out) {
  10305. out.succeeded = true;
  10306. out.collider = PhysicsComponent._physicObjectsMap[convexResultCall.get_m_hitCollisionObject().getUserIndex()];
  10307. out.hitFraction = convexResultCall.get_m_closestHitFraction();
  10308. var nativePoint = convexResultCall.get_m_hitPointWorld();
  10309. var nativeNormal = convexResultCall.get_m_hitNormalWorld();
  10310. var point = out.point;
  10311. var normal = out.normal;
  10312. point.x = -nativePoint.x();
  10313. point.y = nativePoint.y();
  10314. point.z = nativePoint.z();
  10315. normal.x = -nativeNormal.x();
  10316. normal.y = nativeNormal.y();
  10317. normal.z = nativeNormal.z();
  10318. }
  10319. return true;
  10320. }
  10321. else {
  10322. if (out)
  10323. out.succeeded = false;
  10324. return false;
  10325. }
  10326. }
  10327. shapeCastAll(shape, fromPosition, toPosition, out, fromRotation = null, toRotation = null, collisonGroup = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER, collisionMask = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER, allowedCcdPenetration = 0.0) {
  10328. var convexResultCall = this._nativeAllConvexResultCallback;
  10329. var convexPosFrom = PhysicsSimulation._nativeTempVector30;
  10330. var convexPosTo = PhysicsSimulation._nativeTempVector31;
  10331. var convexRotFrom = PhysicsSimulation._nativeTempQuaternion0;
  10332. var convexRotTo = PhysicsSimulation._nativeTempQuaternion1;
  10333. var convexTransform = PhysicsSimulation._nativeTempTransform0;
  10334. var convexTransTo = PhysicsSimulation._nativeTempTransform1;
  10335. var sweepShape = shape._nativeShape;
  10336. out.length = 0;
  10337. convexPosFrom.setValue(-fromPosition.x, fromPosition.y, fromPosition.z);
  10338. convexPosTo.setValue(-toPosition.x, toPosition.y, toPosition.z);
  10339. convexResultCall.set_m_collisionFilterGroup(collisonGroup);
  10340. convexResultCall.set_m_collisionFilterMask(collisionMask);
  10341. convexTransform.setOrigin(convexPosFrom);
  10342. convexTransTo.setOrigin(convexPosTo);
  10343. if (fromRotation) {
  10344. convexRotFrom.setValue(-fromRotation.x, fromRotation.y, fromRotation.z, -fromRotation.w);
  10345. convexTransform.setRotation(convexRotFrom);
  10346. }
  10347. else {
  10348. convexTransform.setRotation(this._nativeDefaultQuaternion);
  10349. }
  10350. if (toRotation) {
  10351. convexRotTo.setValue(-toRotation.x, toRotation.y, toRotation.z, -toRotation.w);
  10352. convexTransTo.setRotation(convexRotTo);
  10353. }
  10354. else {
  10355. convexTransTo.setRotation(this._nativeDefaultQuaternion);
  10356. }
  10357. var collisionObjects = convexResultCall.get_m_collisionObjects();
  10358. collisionObjects.clear();
  10359. this._nativeCollisionWorld.convexSweepTest(sweepShape, convexTransform, convexTransTo, convexResultCall, allowedCcdPenetration);
  10360. var count = collisionObjects.size();
  10361. if (count > 0) {
  10362. var nativePoints = convexResultCall.get_m_hitPointWorld();
  10363. var nativeNormals = convexResultCall.get_m_hitNormalWorld();
  10364. var nativeFractions = convexResultCall.get_m_hitFractions();
  10365. for (var i = 0; i < count; i++) {
  10366. var hitResult = this._collisionsUtils.getHitResult();
  10367. out.push(hitResult);
  10368. hitResult.succeeded = true;
  10369. hitResult.collider = PhysicsComponent._physicObjectsMap[collisionObjects.at(i).getUserIndex()];
  10370. hitResult.hitFraction = nativeFractions.at(i);
  10371. var nativePoint = nativePoints.at(i);
  10372. var point = hitResult.point;
  10373. point.x = -nativePoint.x();
  10374. point.y = nativePoint.y();
  10375. point.z = nativePoint.z();
  10376. var nativeNormal = nativeNormals.at(i);
  10377. var normal = hitResult.normal;
  10378. normal.x = -nativeNormal.x();
  10379. normal.y = nativeNormal.y();
  10380. normal.z = nativeNormal.z();
  10381. }
  10382. return true;
  10383. }
  10384. else {
  10385. return false;
  10386. }
  10387. }
  10388. addConstraint(constraint, disableCollisionsBetweenLinkedBodies = false) {
  10389. if (!this._nativeDiscreteDynamicsWorld)
  10390. throw "Cannot perform this action when the physics engine is set to CollisionsOnly";
  10391. this._nativeDiscreteDynamicsWorld.addConstraint(constraint._nativeConstraint, disableCollisionsBetweenLinkedBodies);
  10392. constraint._simulation = this;
  10393. }
  10394. removeConstraint(constraint) {
  10395. if (!this._nativeDiscreteDynamicsWorld)
  10396. throw "Cannot perform this action when the physics engine is set to CollisionsOnly";
  10397. this._nativeDiscreteDynamicsWorld.removeConstraint(constraint._nativeConstraint);
  10398. }
  10399. _updatePhysicsTransformFromRender() {
  10400. var elements = this._physicsUpdateList.elements;
  10401. for (var i = 0, n = this._physicsUpdateList.length; i < n; i++) {
  10402. var physicCollider = elements[i];
  10403. physicCollider._derivePhysicsTransformation(false);
  10404. physicCollider._inPhysicUpdateListIndex = -1;
  10405. }
  10406. this._physicsUpdateList.length = 0;
  10407. }
  10408. _updateCharacters() {
  10409. for (var i = 0, n = this._characters.length; i < n; i++) {
  10410. var character = this._characters[i];
  10411. character._updateTransformComponent(character._nativeColliderObject.getWorldTransform());
  10412. }
  10413. }
  10414. _updateCollisions() {
  10415. this._collisionsUtils.recoverAllContactPointsPool();
  10416. var previous = this._currentFrameCollisions;
  10417. this._currentFrameCollisions = this._previousFrameCollisions;
  10418. this._currentFrameCollisions.length = 0;
  10419. this._previousFrameCollisions = previous;
  10420. var loopCount = Laya.Stat.loopCount;
  10421. var numManifolds = this._nativeDispatcher.getNumManifolds();
  10422. for (var i = 0; i < numManifolds; i++) {
  10423. var contactManifold = this._nativeDispatcher.getManifoldByIndexInternal(i);
  10424. var componentA = PhysicsComponent._physicObjectsMap[contactManifold.getBody0().getUserIndex()];
  10425. var componentB = PhysicsComponent._physicObjectsMap[contactManifold.getBody1().getUserIndex()];
  10426. var collision = null;
  10427. var isFirstCollision;
  10428. var contacts = null;
  10429. var isTrigger = componentA.isTrigger || componentB.isTrigger;
  10430. if (isTrigger && (componentA.owner._needProcessTriggers || componentB.owner._needProcessTriggers)) {
  10431. var numContacts = contactManifold.getNumContacts();
  10432. for (var j = 0; j < numContacts; j++) {
  10433. var pt = contactManifold.getContactPoint(j);
  10434. var distance = pt.getDistance();
  10435. if (distance <= 0) {
  10436. collision = this._collisionsUtils.getCollision(componentA, componentB);
  10437. contacts = collision.contacts;
  10438. isFirstCollision = collision._updateFrame !== loopCount;
  10439. if (isFirstCollision) {
  10440. collision._isTrigger = true;
  10441. contacts.length = 0;
  10442. }
  10443. break;
  10444. }
  10445. }
  10446. }
  10447. else if (componentA.owner._needProcessCollisions || componentB.owner._needProcessCollisions) {
  10448. if (componentA._enableProcessCollisions || componentB._enableProcessCollisions) {
  10449. numContacts = contactManifold.getNumContacts();
  10450. for (j = 0; j < numContacts; j++) {
  10451. pt = contactManifold.getContactPoint(j);
  10452. distance = pt.getDistance();
  10453. if (distance <= 0) {
  10454. var contactPoint = this._collisionsUtils.getContactPoints();
  10455. contactPoint.colliderA = componentA;
  10456. contactPoint.colliderB = componentB;
  10457. contactPoint.distance = distance;
  10458. var nativeNormal = pt.get_m_normalWorldOnB();
  10459. var normal = contactPoint.normal;
  10460. normal.x = -nativeNormal.x();
  10461. normal.y = nativeNormal.y();
  10462. normal.z = nativeNormal.z();
  10463. var nativePostionA = pt.get_m_positionWorldOnA();
  10464. var positionOnA = contactPoint.positionOnA;
  10465. positionOnA.x = -nativePostionA.x();
  10466. positionOnA.y = nativePostionA.y();
  10467. positionOnA.z = nativePostionA.z();
  10468. var nativePostionB = pt.get_m_positionWorldOnB();
  10469. var positionOnB = contactPoint.positionOnB;
  10470. positionOnB.x = -nativePostionB.x();
  10471. positionOnB.y = nativePostionB.y();
  10472. positionOnB.z = nativePostionB.z();
  10473. if (!collision) {
  10474. collision = this._collisionsUtils.getCollision(componentA, componentB);
  10475. contacts = collision.contacts;
  10476. isFirstCollision = collision._updateFrame !== loopCount;
  10477. if (isFirstCollision) {
  10478. collision._isTrigger = false;
  10479. contacts.length = 0;
  10480. }
  10481. }
  10482. contacts.push(contactPoint);
  10483. }
  10484. }
  10485. }
  10486. }
  10487. if (collision && isFirstCollision) {
  10488. this._currentFrameCollisions.push(collision);
  10489. collision._setUpdateFrame(loopCount);
  10490. }
  10491. }
  10492. }
  10493. _eventScripts() {
  10494. var loopCount = Laya.Stat.loopCount;
  10495. for (var i = 0, n = this._currentFrameCollisions.length; i < n; i++) {
  10496. var curFrameCol = this._currentFrameCollisions[i];
  10497. var colliderA = curFrameCol._colliderA;
  10498. var colliderB = curFrameCol._colliderB;
  10499. if (colliderA.destroyed || colliderB.destroyed)
  10500. continue;
  10501. if (loopCount - curFrameCol._lastUpdateFrame === 1) {
  10502. var ownerA = colliderA.owner;
  10503. var scriptsA = ownerA._scripts;
  10504. if (scriptsA) {
  10505. if (curFrameCol._isTrigger) {
  10506. if (ownerA._needProcessTriggers) {
  10507. for (var j = 0, m = scriptsA.length; j < m; j++)
  10508. scriptsA[j].onTriggerStay(colliderB);
  10509. }
  10510. }
  10511. else {
  10512. if (ownerA._needProcessCollisions) {
  10513. for (j = 0, m = scriptsA.length; j < m; j++) {
  10514. curFrameCol.other = colliderB;
  10515. scriptsA[j].onCollisionStay(curFrameCol);
  10516. }
  10517. }
  10518. }
  10519. }
  10520. var ownerB = colliderB.owner;
  10521. var scriptsB = ownerB._scripts;
  10522. if (scriptsB) {
  10523. if (curFrameCol._isTrigger) {
  10524. if (ownerB._needProcessTriggers) {
  10525. for (j = 0, m = scriptsB.length; j < m; j++)
  10526. scriptsB[j].onTriggerStay(colliderA);
  10527. }
  10528. }
  10529. else {
  10530. if (ownerB._needProcessCollisions) {
  10531. for (j = 0, m = scriptsB.length; j < m; j++) {
  10532. curFrameCol.other = colliderA;
  10533. scriptsB[j].onCollisionStay(curFrameCol);
  10534. }
  10535. }
  10536. }
  10537. }
  10538. }
  10539. else {
  10540. ownerA = colliderA.owner;
  10541. scriptsA = ownerA._scripts;
  10542. if (scriptsA) {
  10543. if (curFrameCol._isTrigger) {
  10544. if (ownerA._needProcessTriggers) {
  10545. for (j = 0, m = scriptsA.length; j < m; j++)
  10546. scriptsA[j].onTriggerEnter(colliderB);
  10547. }
  10548. }
  10549. else {
  10550. if (ownerA._needProcessCollisions) {
  10551. for (j = 0, m = scriptsA.length; j < m; j++) {
  10552. curFrameCol.other = colliderB;
  10553. scriptsA[j].onCollisionEnter(curFrameCol);
  10554. }
  10555. }
  10556. }
  10557. }
  10558. ownerB = colliderB.owner;
  10559. scriptsB = ownerB._scripts;
  10560. if (scriptsB) {
  10561. if (curFrameCol._isTrigger) {
  10562. if (ownerB._needProcessTriggers) {
  10563. for (j = 0, m = scriptsB.length; j < m; j++)
  10564. scriptsB[j].onTriggerEnter(colliderA);
  10565. }
  10566. }
  10567. else {
  10568. if (ownerB._needProcessCollisions) {
  10569. for (j = 0, m = scriptsB.length; j < m; j++) {
  10570. curFrameCol.other = colliderA;
  10571. scriptsB[j].onCollisionEnter(curFrameCol);
  10572. }
  10573. }
  10574. }
  10575. }
  10576. }
  10577. }
  10578. for (i = 0, n = this._previousFrameCollisions.length; i < n; i++) {
  10579. var preFrameCol = this._previousFrameCollisions[i];
  10580. var preColliderA = preFrameCol._colliderA;
  10581. var preColliderB = preFrameCol._colliderB;
  10582. if (preColliderA.destroyed || preColliderB.destroyed)
  10583. continue;
  10584. if (loopCount - preFrameCol._updateFrame === 1) {
  10585. this._collisionsUtils.recoverCollision(preFrameCol);
  10586. ownerA = preColliderA.owner;
  10587. scriptsA = ownerA._scripts;
  10588. if (scriptsA) {
  10589. if (preFrameCol._isTrigger) {
  10590. if (ownerA._needProcessTriggers) {
  10591. for (j = 0, m = scriptsA.length; j < m; j++)
  10592. scriptsA[j].onTriggerExit(preColliderB);
  10593. }
  10594. }
  10595. else {
  10596. if (ownerA._needProcessCollisions) {
  10597. for (j = 0, m = scriptsA.length; j < m; j++) {
  10598. preFrameCol.other = preColliderB;
  10599. scriptsA[j].onCollisionExit(preFrameCol);
  10600. }
  10601. }
  10602. }
  10603. }
  10604. ownerB = preColliderB.owner;
  10605. scriptsB = ownerB._scripts;
  10606. if (scriptsB) {
  10607. if (preFrameCol._isTrigger) {
  10608. if (ownerB._needProcessTriggers) {
  10609. for (j = 0, m = scriptsB.length; j < m; j++)
  10610. scriptsB[j].onTriggerExit(preColliderA);
  10611. }
  10612. }
  10613. else {
  10614. if (ownerB._needProcessCollisions) {
  10615. for (j = 0, m = scriptsB.length; j < m; j++) {
  10616. preFrameCol.other = preColliderA;
  10617. scriptsB[j].onCollisionExit(preFrameCol);
  10618. }
  10619. }
  10620. }
  10621. }
  10622. }
  10623. }
  10624. }
  10625. clearForces() {
  10626. if (!this._nativeDiscreteDynamicsWorld)
  10627. throw "Cannot perform this action when the physics engine is set to CollisionsOnly";
  10628. this._nativeDiscreteDynamicsWorld.clearForces();
  10629. }
  10630. }
  10631. PhysicsSimulation.PHYSICSENGINEFLAGS_NONE = 0x0;
  10632. PhysicsSimulation.PHYSICSENGINEFLAGS_COLLISIONSONLY = 0x1;
  10633. PhysicsSimulation.PHYSICSENGINEFLAGS_SOFTBODYSUPPORT = 0x2;
  10634. PhysicsSimulation.PHYSICSENGINEFLAGS_MULTITHREADED = 0x4;
  10635. PhysicsSimulation.PHYSICSENGINEFLAGS_USEHARDWAREWHENPOSSIBLE = 0x8;
  10636. PhysicsSimulation.SOLVERMODE_RANDMIZE_ORDER = 1;
  10637. PhysicsSimulation.SOLVERMODE_FRICTION_SEPARATE = 2;
  10638. PhysicsSimulation.SOLVERMODE_USE_WARMSTARTING = 4;
  10639. PhysicsSimulation.SOLVERMODE_USE_2_FRICTION_DIRECTIONS = 16;
  10640. PhysicsSimulation.SOLVERMODE_ENABLE_FRICTION_DIRECTION_CACHING = 32;
  10641. PhysicsSimulation.SOLVERMODE_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION = 64;
  10642. PhysicsSimulation.SOLVERMODE_CACHE_FRIENDLY = 128;
  10643. PhysicsSimulation.SOLVERMODE_SIMD = 256;
  10644. PhysicsSimulation.SOLVERMODE_INTERLEAVE_CONTACT_AND_FRICTION_CONSTRAINTS = 512;
  10645. PhysicsSimulation.SOLVERMODE_ALLOW_ZERO_LENGTH_FRICTION_DIRECTIONS = 1024;
  10646. PhysicsSimulation._tempVector30 = new Vector3();
  10647. PhysicsSimulation.disableSimulation = false;
  10648. class BoundBox {
  10649. constructor(min, max) {
  10650. this.min = min;
  10651. this.max = max;
  10652. }
  10653. _rotateExtents(extents, rotation, out) {
  10654. var extentsX = extents.x;
  10655. var extentsY = extents.y;
  10656. var extentsZ = extents.z;
  10657. var matElements = rotation.elements;
  10658. out.x = Math.abs(matElements[0] * extentsX) + Math.abs(matElements[4] * extentsY) + Math.abs(matElements[8] * extentsZ);
  10659. out.y = Math.abs(matElements[1] * extentsX) + Math.abs(matElements[5] * extentsY) + Math.abs(matElements[9] * extentsZ);
  10660. out.z = Math.abs(matElements[2] * extentsX) + Math.abs(matElements[6] * extentsY) + Math.abs(matElements[10] * extentsZ);
  10661. }
  10662. getCorners(corners) {
  10663. corners.length = 8;
  10664. var minX = this.min.x;
  10665. var minY = this.min.y;
  10666. var minZ = this.min.z;
  10667. var maxX = this.max.x;
  10668. var maxY = this.max.y;
  10669. var maxZ = this.max.z;
  10670. corners[0] = new Vector3(minX, maxY, maxZ);
  10671. corners[1] = new Vector3(maxX, maxY, maxZ);
  10672. corners[2] = new Vector3(maxX, minY, maxZ);
  10673. corners[3] = new Vector3(minX, minY, maxZ);
  10674. corners[4] = new Vector3(minX, maxY, minZ);
  10675. corners[5] = new Vector3(maxX, maxY, minZ);
  10676. corners[6] = new Vector3(maxX, minY, minZ);
  10677. corners[7] = new Vector3(minX, minY, minZ);
  10678. }
  10679. getCenter(out) {
  10680. Vector3.add(this.min, this.max, out);
  10681. Vector3.scale(out, 0.5, out);
  10682. }
  10683. getExtent(out) {
  10684. Vector3.subtract(this.max, this.min, out);
  10685. Vector3.scale(out, 0.5, out);
  10686. }
  10687. setCenterAndExtent(center, extent) {
  10688. Vector3.subtract(center, extent, this.min);
  10689. Vector3.add(center, extent, this.max);
  10690. }
  10691. tranform(matrix, out) {
  10692. var center = BoundBox._tempVector30;
  10693. var extent = BoundBox._tempVector31;
  10694. this.getCenter(center);
  10695. this.getExtent(extent);
  10696. Vector3.transformCoordinate(center, matrix, center);
  10697. this._rotateExtents(extent, matrix, extent);
  10698. out.setCenterAndExtent(center, extent);
  10699. }
  10700. toDefault() {
  10701. this.min.toDefault();
  10702. this.max.toDefault();
  10703. }
  10704. static createfromPoints(points, out) {
  10705. if (points == null)
  10706. throw new Error("points");
  10707. var min = out.min;
  10708. var max = out.max;
  10709. min.x = Number.MAX_VALUE;
  10710. min.y = Number.MAX_VALUE;
  10711. min.z = Number.MAX_VALUE;
  10712. max.x = -Number.MAX_VALUE;
  10713. max.y = -Number.MAX_VALUE;
  10714. max.z = -Number.MAX_VALUE;
  10715. for (var i = 0, n = points.length; i < n; ++i) {
  10716. Vector3.min(min, points[i], min);
  10717. Vector3.max(max, points[i], max);
  10718. }
  10719. }
  10720. static merge(box1, box2, out) {
  10721. Vector3.min(box1.min, box2.min, out.min);
  10722. Vector3.max(box1.max, box2.max, out.max);
  10723. }
  10724. cloneTo(destObject) {
  10725. var dest = destObject;
  10726. this.min.cloneTo(dest.min);
  10727. this.max.cloneTo(dest.max);
  10728. }
  10729. clone() {
  10730. var dest = new BoundBox(new Vector3(), new Vector3());
  10731. this.cloneTo(dest);
  10732. return dest;
  10733. }
  10734. }
  10735. BoundBox._tempVector30 = new Vector3();
  10736. BoundBox._tempVector31 = new Vector3();
  10737. class BoundSphere {
  10738. constructor(center, radius) {
  10739. this.center = center;
  10740. this.radius = radius;
  10741. }
  10742. toDefault() {
  10743. this.center.toDefault();
  10744. this.radius = 0;
  10745. }
  10746. static createFromSubPoints(points, start, count, out) {
  10747. if (points == null) {
  10748. throw new Error("points");
  10749. }
  10750. if (start < 0 || start >= points.length) {
  10751. throw new Error("start" + start + "Must be in the range [0, " + (points.length - 1) + "]");
  10752. }
  10753. if (count < 0 || (start + count) > points.length) {
  10754. throw new Error("count" + count + "Must be in the range <= " + points.length + "}");
  10755. }
  10756. var upperEnd = start + count;
  10757. var center = BoundSphere._tempVector3;
  10758. center.x = 0;
  10759. center.y = 0;
  10760. center.z = 0;
  10761. for (var i = start; i < upperEnd; ++i) {
  10762. Vector3.add(points[i], center, center);
  10763. }
  10764. var outCenter = out.center;
  10765. Vector3.scale(center, 1 / count, outCenter);
  10766. var radius = 0.0;
  10767. for (i = start; i < upperEnd; ++i) {
  10768. var distance = Vector3.distanceSquared(outCenter, points[i]);
  10769. if (distance > radius)
  10770. radius = distance;
  10771. }
  10772. out.radius = Math.sqrt(radius);
  10773. }
  10774. static createfromPoints(points, out) {
  10775. if (points == null) {
  10776. throw new Error("points");
  10777. }
  10778. BoundSphere.createFromSubPoints(points, 0, points.length, out);
  10779. }
  10780. intersectsRayDistance(ray) {
  10781. return CollisionUtils.intersectsRayAndSphereRD(ray, this);
  10782. }
  10783. intersectsRayPoint(ray, outPoint) {
  10784. return CollisionUtils.intersectsRayAndSphereRP(ray, this, outPoint);
  10785. }
  10786. cloneTo(destObject) {
  10787. var dest = destObject;
  10788. this.center.cloneTo(dest.center);
  10789. dest.radius = this.radius;
  10790. }
  10791. clone() {
  10792. var dest = new BoundSphere(new Vector3(), 0);
  10793. this.cloneTo(dest);
  10794. return dest;
  10795. }
  10796. }
  10797. BoundSphere._tempVector3 = new Vector3();
  10798. class ParallelSplitShadowMap {
  10799. constructor() {
  10800. this._spiltDistance = [];
  10801. this._currentPSSM = -1;
  10802. this._shadowMapCount = 3;
  10803. this._maxDistance = 200.0;
  10804. this._ratioOfDistance = 1.0 / this._shadowMapCount;
  10805. this._globalParallelLightDir = new Vector3(0, -1, 0);
  10806. this._statesDirty = true;
  10807. this._shadowMapTextureSize = 1024;
  10808. this._scene = null;
  10809. this._boundingSphere = new Array(ParallelSplitShadowMap.MAX_PSSM_COUNT + 1);
  10810. this._boundingBox = new Array(ParallelSplitShadowMap.MAX_PSSM_COUNT + 1);
  10811. this._frustumPos = new Array((ParallelSplitShadowMap.MAX_PSSM_COUNT + 1) * 4);
  10812. this._uniformDistance = new Array(ParallelSplitShadowMap.MAX_PSSM_COUNT + 1);
  10813. this._logDistance = new Array(ParallelSplitShadowMap.MAX_PSSM_COUNT + 1);
  10814. this._dimension = new Array(ParallelSplitShadowMap.MAX_PSSM_COUNT + 1);
  10815. this._PCFType = 0;
  10816. this._tempLookAt3 = new Vector3();
  10817. this._tempLookAt4 = new Vector4();
  10818. this._tempValue = new Vector4();
  10819. this._tempPos = new Vector3();
  10820. this._tempLightUp = new Vector3();
  10821. this._tempMin = new Vector4();
  10822. this._tempMax = new Vector4();
  10823. this._tempMatrix44 = new Matrix4x4;
  10824. this._splitFrustumCulling = new BoundFrustum(Matrix4x4.DEFAULT);
  10825. this._tempScaleMatrix44 = new Matrix4x4();
  10826. this._shadowPCFOffset = new Vector2(1.0 / 1024.0, 1.0 / 1024.0);
  10827. this._shaderValueDistance = new Vector4();
  10828. this._shaderValueLightVP = null;
  10829. this.cameras = [];
  10830. this._shaderValueVPs = [];
  10831. var i;
  10832. for (i = 0; i < this._spiltDistance.length; i++) {
  10833. this._spiltDistance[i] = 0.0;
  10834. }
  10835. for (i = 0; i < this._dimension.length; i++) {
  10836. this._dimension[i] = new Vector2();
  10837. }
  10838. for (i = 0; i < this._frustumPos.length; i++) {
  10839. this._frustumPos[i] = new Vector3();
  10840. }
  10841. for (i = 0; i < this._boundingBox.length; i++) {
  10842. this._boundingBox[i] = new BoundBox(new Vector3(), new Vector3());
  10843. }
  10844. for (i = 0; i < this._boundingSphere.length; i++) {
  10845. this._boundingSphere[i] = new BoundSphere(new Vector3(), 0.0);
  10846. }
  10847. Matrix4x4.createScaling(new Vector3(0.5, 0.5, 1.0), this._tempScaleMatrix44);
  10848. this._tempScaleMatrix44.elements[12] = 0.5;
  10849. this._tempScaleMatrix44.elements[13] = 0.5;
  10850. }
  10851. setInfo(scene, maxDistance, globalParallelDir, shadowMapTextureSize, numberOfPSSM, PCFType) {
  10852. if (numberOfPSSM > ParallelSplitShadowMap.MAX_PSSM_COUNT) {
  10853. this._shadowMapCount = ParallelSplitShadowMap.MAX_PSSM_COUNT;
  10854. }
  10855. this._scene = scene;
  10856. this._maxDistance = maxDistance;
  10857. this.shadowMapCount = numberOfPSSM;
  10858. this._globalParallelLightDir = globalParallelDir;
  10859. this._ratioOfDistance = 1.0 / this._shadowMapCount;
  10860. for (var i = 0; i < this._spiltDistance.length; i++) {
  10861. this._spiltDistance[i] = 0.0;
  10862. }
  10863. this._shadowMapTextureSize = shadowMapTextureSize;
  10864. this._shadowPCFOffset.x = 1.0 / this._shadowMapTextureSize;
  10865. this._shadowPCFOffset.y = 1.0 / this._shadowMapTextureSize;
  10866. this.setPCFType(PCFType);
  10867. this._statesDirty = true;
  10868. }
  10869. setPCFType(PCFtype) {
  10870. this._PCFType = PCFtype;
  10871. var defineData = this._scene._shaderValues;
  10872. switch (this._PCFType) {
  10873. case 0:
  10874. defineData.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF_NO);
  10875. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF1);
  10876. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF2);
  10877. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF3);
  10878. break;
  10879. case 1:
  10880. defineData.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF1);
  10881. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF_NO);
  10882. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF2);
  10883. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF3);
  10884. break;
  10885. case 2:
  10886. defineData.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF2);
  10887. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF_NO);
  10888. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF1);
  10889. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF3);
  10890. break;
  10891. case 3:
  10892. defineData.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF3);
  10893. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF_NO);
  10894. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF1);
  10895. defineData.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF2);
  10896. break;
  10897. }
  10898. }
  10899. getPCFType() {
  10900. return this._PCFType;
  10901. }
  10902. setFarDistance(value) {
  10903. if (this._maxDistance != value) {
  10904. this._maxDistance = value;
  10905. this._statesDirty = true;
  10906. }
  10907. }
  10908. getFarDistance() {
  10909. return this._maxDistance;
  10910. }
  10911. set shadowMapCount(value) {
  10912. value = value > 0 ? value : 1;
  10913. value = value <= ParallelSplitShadowMap.MAX_PSSM_COUNT ? value : ParallelSplitShadowMap.MAX_PSSM_COUNT;
  10914. if (this._shadowMapCount != value) {
  10915. this._shadowMapCount = value;
  10916. this._ratioOfDistance = 1.0 / this._shadowMapCount;
  10917. this._statesDirty = true;
  10918. this._shaderValueLightVP = new Float32Array(value * 16);
  10919. this._shaderValueVPs.length = value;
  10920. for (var i = 0; i < value; i++)
  10921. this._shaderValueVPs[i] = new Float32Array(this._shaderValueLightVP.buffer, i * 64);
  10922. }
  10923. }
  10924. get shadowMapCount() {
  10925. return this._shadowMapCount;
  10926. }
  10927. _beginSampler(index, sceneCamera) {
  10928. if (index < 0 || index > this._shadowMapCount)
  10929. throw new Error("ParallelSplitShadowMap: beginSample invalid index");
  10930. this._currentPSSM = index;
  10931. this._update(sceneCamera);
  10932. }
  10933. endSampler(sceneCamera) {
  10934. this._currentPSSM = -1;
  10935. }
  10936. _calcAllLightCameraInfo(sceneCamera) {
  10937. if (this._shadowMapCount === 1) {
  10938. this._beginSampler(0, sceneCamera);
  10939. this.endSampler(sceneCamera);
  10940. }
  10941. else {
  10942. for (var i = 0, n = this._shadowMapCount + 1; i < n; i++) {
  10943. this._beginSampler(i, sceneCamera);
  10944. this.endSampler(sceneCamera);
  10945. }
  10946. }
  10947. }
  10948. _recalculate(nearPlane, fieldOfView, aspectRatio) {
  10949. this._calcSplitDistance(nearPlane);
  10950. this._calcBoundingBox(fieldOfView, aspectRatio);
  10951. this._rebuildRenderInfo();
  10952. }
  10953. _update(sceneCamera) {
  10954. var nearPlane = sceneCamera.nearPlane;
  10955. var fieldOfView = sceneCamera.fieldOfView;
  10956. var aspectRatio = sceneCamera.aspectRatio;
  10957. if (this._statesDirty || this.lastNearPlane !== nearPlane || this.lastFieldOfView !== fieldOfView || this.lastAspectRatio !== aspectRatio) {
  10958. this._recalculate(nearPlane, fieldOfView, aspectRatio);
  10959. this._uploadShaderValue();
  10960. this._statesDirty = false;
  10961. this.lastNearPlane = nearPlane;
  10962. this.lastFieldOfView = fieldOfView;
  10963. this.lastAspectRatio = aspectRatio;
  10964. }
  10965. this._calcLightViewProject(sceneCamera);
  10966. }
  10967. _uploadShaderValue() {
  10968. var sceneSV = this._scene._shaderValues;
  10969. switch (this._shadowMapCount) {
  10970. case 1:
  10971. sceneSV.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM1);
  10972. sceneSV.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM2);
  10973. sceneSV.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM3);
  10974. break;
  10975. case 2:
  10976. sceneSV.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM2);
  10977. sceneSV.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM1);
  10978. sceneSV.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM3);
  10979. break;
  10980. case 3:
  10981. sceneSV.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM3);
  10982. sceneSV.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM1);
  10983. sceneSV.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM2);
  10984. break;
  10985. }
  10986. sceneSV.setVector(ILaya3D.Scene3D.SHADOWDISTANCE, this._shaderValueDistance);
  10987. sceneSV.setBuffer(ILaya3D.Scene3D.SHADOWLIGHTVIEWPROJECT, this._shaderValueLightVP);
  10988. sceneSV.setVector2(ILaya3D.Scene3D.SHADOWMAPPCFOFFSET, this._shadowPCFOffset);
  10989. switch (this._shadowMapCount) {
  10990. case 3:
  10991. sceneSV.setTexture(ILaya3D.Scene3D.SHADOWMAPTEXTURE1, this.cameras[1].renderTarget);
  10992. sceneSV.setTexture(ILaya3D.Scene3D.SHADOWMAPTEXTURE2, this.cameras[2].renderTarget);
  10993. sceneSV.setTexture(ILaya3D.Scene3D.SHADOWMAPTEXTURE3, this.cameras[3].renderTarget);
  10994. break;
  10995. case 2:
  10996. sceneSV.setTexture(ILaya3D.Scene3D.SHADOWMAPTEXTURE1, this.cameras[1].renderTarget);
  10997. sceneSV.setTexture(ILaya3D.Scene3D.SHADOWMAPTEXTURE2, this.cameras[2].renderTarget);
  10998. break;
  10999. case 1:
  11000. sceneSV.setTexture(ILaya3D.Scene3D.SHADOWMAPTEXTURE1, this.cameras[1].renderTarget);
  11001. break;
  11002. }
  11003. }
  11004. _calcSplitDistance(nearPlane) {
  11005. var far = this._maxDistance;
  11006. var invNumberOfPSSM = 1.0 / this._shadowMapCount;
  11007. var i;
  11008. for (i = 0; i <= this._shadowMapCount; i++) {
  11009. this._uniformDistance[i] = nearPlane + (far - nearPlane) * i * invNumberOfPSSM;
  11010. }
  11011. var farDivNear = far / nearPlane;
  11012. for (i = 0; i <= this._shadowMapCount; i++) {
  11013. var n = Math.pow(farDivNear, i * invNumberOfPSSM);
  11014. this._logDistance[i] = nearPlane * n;
  11015. }
  11016. for (i = 0; i <= this._shadowMapCount; i++) {
  11017. this._spiltDistance[i] = this._uniformDistance[i] * this._ratioOfDistance + this._logDistance[i] * (1.0 - this._ratioOfDistance);
  11018. }
  11019. this._shaderValueDistance.x = (this._spiltDistance[1] != undefined) && (this._spiltDistance[1]);
  11020. this._shaderValueDistance.y = (this._spiltDistance[2] != undefined) && (this._spiltDistance[2]);
  11021. this._shaderValueDistance.z = (this._spiltDistance[3] != undefined) && (this._spiltDistance[3]);
  11022. this._shaderValueDistance.w = (this._spiltDistance[4] != undefined) && (this._spiltDistance[4]);
  11023. }
  11024. _calcBoundingBox(fieldOfView, aspectRatio) {
  11025. var fov = 3.1415926 * fieldOfView / 180.0;
  11026. var halfTanValue = Math.tan(fov / 2.0);
  11027. var height;
  11028. var width;
  11029. var distance;
  11030. var i;
  11031. for (i = 0; i <= this._shadowMapCount; i++) {
  11032. distance = this._spiltDistance[i];
  11033. height = distance * halfTanValue;
  11034. width = height * aspectRatio;
  11035. var temp = this._frustumPos[i * 4 + 0];
  11036. temp.x = -width;
  11037. temp.y = -height;
  11038. temp.z = -distance;
  11039. temp = this._frustumPos[i * 4 + 1];
  11040. temp.x = width;
  11041. temp.y = -height;
  11042. temp.z = -distance;
  11043. temp = this._frustumPos[i * 4 + 2];
  11044. temp.x = -width;
  11045. temp.y = height;
  11046. temp.z = -distance;
  11047. temp = this._frustumPos[i * 4 + 3];
  11048. temp.x = width;
  11049. temp.y = height;
  11050. temp.z = -distance;
  11051. temp = this._dimension[i];
  11052. temp.x = width;
  11053. temp.y = height;
  11054. }
  11055. var d;
  11056. var min;
  11057. var max;
  11058. var center;
  11059. for (i = 1; i <= this._shadowMapCount; i++) {
  11060. d = this._dimension[i];
  11061. min = this._boundingBox[i].min;
  11062. min.x = -d.x;
  11063. min.y = -d.y;
  11064. min.z = -this._spiltDistance[i];
  11065. max = this._boundingBox[i].max;
  11066. max.x = d.x;
  11067. max.y = d.y;
  11068. max.z = -this._spiltDistance[i - 1];
  11069. center = this._boundingSphere[i].center;
  11070. center.x = (min.x + max.x) * 0.5;
  11071. center.y = (min.y + max.y) * 0.5;
  11072. center.z = (min.z + max.z) * 0.5;
  11073. this._boundingSphere[i].radius = Math.sqrt(Math.pow(max.x - min.x, 2) + Math.pow(max.y - min.y, 2) + Math.pow(max.z - min.z, 2)) * 0.5;
  11074. }
  11075. min = this._boundingBox[0].min;
  11076. d = this._dimension[this._shadowMapCount];
  11077. min.x = -d.x;
  11078. min.y = -d.y;
  11079. min.z = -this._spiltDistance[this._shadowMapCount];
  11080. max = this._boundingBox[0].max;
  11081. max.x = d.x;
  11082. max.y = d.y;
  11083. max.z = -this._spiltDistance[0];
  11084. center = this._boundingSphere[0].center;
  11085. center.x = (min.x + max.x) * 0.5;
  11086. center.y = (min.y + max.y) * 0.5;
  11087. center.z = (min.z + max.z) * 0.5;
  11088. this._boundingSphere[0].radius = Math.sqrt(Math.pow(max.x - min.x, 2) + Math.pow(max.y - min.y, 2) + Math.pow(max.z - min.z, 2)) * 0.5;
  11089. }
  11090. calcSplitFrustum(sceneCamera) {
  11091. if (this._currentPSSM > 0) {
  11092. Matrix4x4.createPerspective(3.1416 * sceneCamera.fieldOfView / 180.0, sceneCamera.aspectRatio, this._spiltDistance[this._currentPSSM - 1], this._spiltDistance[this._currentPSSM], this._tempMatrix44);
  11093. }
  11094. else {
  11095. Matrix4x4.createPerspective(3.1416 * sceneCamera.fieldOfView / 180.0, sceneCamera.aspectRatio, this._spiltDistance[0], this._spiltDistance[this._shadowMapCount], this._tempMatrix44);
  11096. }
  11097. Matrix4x4.multiply(this._tempMatrix44, sceneCamera.viewMatrix, this._tempMatrix44);
  11098. this._splitFrustumCulling.matrix = this._tempMatrix44;
  11099. }
  11100. _rebuildRenderInfo() {
  11101. var nNum = this._shadowMapCount + 1;
  11102. var i;
  11103. this.cameras.length = nNum;
  11104. for (i = 0; i < nNum; i++) {
  11105. if (!this.cameras[i]) {
  11106. var camera = new Camera();
  11107. camera.name = "lightCamera" + i;
  11108. camera.clearColor = new Vector4(1.0, 1.0, 1.0, 1.0);
  11109. this.cameras[i] = camera;
  11110. }
  11111. var shadowMap = this.cameras[i].renderTarget;
  11112. if (shadowMap == null || shadowMap.width != this._shadowMapTextureSize || shadowMap.height != this._shadowMapTextureSize) {
  11113. (shadowMap) && (shadowMap.destroy());
  11114. shadowMap = new RenderTexture(this._shadowMapTextureSize, this._shadowMapTextureSize, Laya.BaseTexture.FORMAT_R8G8B8A8, Laya.BaseTexture.FORMAT_DEPTH_16);
  11115. shadowMap.filterMode = Laya.BaseTexture.FILTERMODE_POINT;
  11116. this.cameras[i].renderTarget = shadowMap;
  11117. }
  11118. }
  11119. }
  11120. _calcLightViewProject(sceneCamera) {
  11121. var boundSphere = this._boundingSphere[this._currentPSSM];
  11122. var cameraMatViewInv = sceneCamera.transform.worldMatrix;
  11123. var radius = boundSphere.radius;
  11124. boundSphere.center.cloneTo(this._tempLookAt3);
  11125. Vector3.transformV3ToV4(this._tempLookAt3, cameraMatViewInv, this._tempLookAt4);
  11126. var lookAt3Element = this._tempLookAt3;
  11127. var lookAt4Element = this._tempLookAt4;
  11128. lookAt3Element.x = lookAt4Element.x;
  11129. lookAt3Element.y = lookAt4Element.y;
  11130. lookAt3Element.z = lookAt4Element.z;
  11131. var lightUpElement = this._tempLightUp;
  11132. sceneCamera.transform.worldMatrix.getForward(ParallelSplitShadowMap._tempVector30);
  11133. var sceneCameraDir = ParallelSplitShadowMap._tempVector30;
  11134. lightUpElement.x = sceneCameraDir.x;
  11135. lightUpElement.y = 1.0;
  11136. lightUpElement.z = sceneCameraDir.z;
  11137. Vector3.normalize(this._tempLightUp, this._tempLightUp);
  11138. Vector3.scale(this._globalParallelLightDir, boundSphere.radius * 4, this._tempPos);
  11139. Vector3.subtract(this._tempLookAt3, this._tempPos, this._tempPos);
  11140. var curLightCamera = this.cameras[this._currentPSSM];
  11141. curLightCamera.transform.position = this._tempPos;
  11142. curLightCamera.transform.lookAt(this._tempLookAt3, this._tempLightUp, false);
  11143. var tempMax = this._tempMax;
  11144. var tempMin = this._tempMin;
  11145. tempMax.x = tempMax.y = tempMax.z = -100000.0;
  11146. tempMax.w = 1.0;
  11147. tempMin.x = tempMin.y = tempMin.z = 100000.0;
  11148. tempMin.w = 1.0;
  11149. Matrix4x4.multiply(curLightCamera.viewMatrix, cameraMatViewInv, this._tempMatrix44);
  11150. var tempValueElement = this._tempValue;
  11151. var corners = [];
  11152. corners.length = 8;
  11153. this._boundingBox[this._currentPSSM].getCorners(corners);
  11154. for (var i = 0; i < 8; i++) {
  11155. var frustumPosElements = corners[i];
  11156. tempValueElement.x = frustumPosElements.x;
  11157. tempValueElement.y = frustumPosElements.y;
  11158. tempValueElement.z = frustumPosElements.z;
  11159. tempValueElement.w = 1.0;
  11160. Vector4.transformByM4x4(this._tempValue, this._tempMatrix44, this._tempValue);
  11161. tempMin.x = (tempValueElement.x < tempMin.x) ? tempValueElement.x : tempMin.x;
  11162. tempMin.y = (tempValueElement.y < tempMin.y) ? tempValueElement.y : tempMin.y;
  11163. tempMin.z = (tempValueElement.z < tempMin.z) ? tempValueElement.z : tempMin.z;
  11164. tempMax.x = (tempValueElement.x > tempMax.x) ? tempValueElement.x : tempMax.x;
  11165. tempMax.y = (tempValueElement.y > tempMax.y) ? tempValueElement.y : tempMax.y;
  11166. tempMax.z = (tempValueElement.z > tempMax.z) ? tempValueElement.z : tempMax.z;
  11167. }
  11168. Vector4.add(this._tempMax, this._tempMin, this._tempValue);
  11169. tempValueElement.x *= 0.5;
  11170. tempValueElement.y *= 0.5;
  11171. tempValueElement.z *= 0.5;
  11172. tempValueElement.w = 1;
  11173. Vector4.transformByM4x4(this._tempValue, curLightCamera.transform.worldMatrix, this._tempValue);
  11174. var distance = Math.abs(-this._tempMax.z);
  11175. var farPlane = distance > this._maxDistance ? distance : this._maxDistance;
  11176. Vector3.scale(this._globalParallelLightDir, farPlane, this._tempPos);
  11177. var tempPosElement = this._tempPos;
  11178. tempPosElement.x = tempValueElement.x - tempPosElement.x;
  11179. tempPosElement.y = tempValueElement.y - tempPosElement.y;
  11180. tempPosElement.z = tempValueElement.z - tempPosElement.z;
  11181. curLightCamera.transform.position = this._tempPos;
  11182. curLightCamera.transform.lookAt(this._tempLookAt3, this._tempLightUp, false);
  11183. Matrix4x4.createOrthoOffCenter(tempMin.x, tempMax.x, tempMin.y, tempMax.y, 1.0, farPlane + 0.5 * (tempMax.z - tempMin.z), curLightCamera.projectionMatrix);
  11184. var projectView = curLightCamera.projectionViewMatrix;
  11185. ParallelSplitShadowMap.multiplyMatrixOutFloat32Array(this._tempScaleMatrix44, projectView, this._shaderValueVPs[this._currentPSSM]);
  11186. this._scene._shaderValues.setBuffer(ILaya3D.Scene3D.SHADOWLIGHTVIEWPROJECT, this._shaderValueLightVP);
  11187. }
  11188. static multiplyMatrixOutFloat32Array(left, right, out) {
  11189. var i, a, b, ai0, ai1, ai2, ai3;
  11190. a = left.elements;
  11191. b = right.elements;
  11192. for (i = 0; i < 4; i++) {
  11193. ai0 = a[i];
  11194. ai1 = a[i + 4];
  11195. ai2 = a[i + 8];
  11196. ai3 = a[i + 12];
  11197. out[i] = ai0 * b[0] + ai1 * b[1] + ai2 * b[2] + ai3 * b[3];
  11198. out[i + 4] = ai0 * b[4] + ai1 * b[5] + ai2 * b[6] + ai3 * b[7];
  11199. out[i + 8] = ai0 * b[8] + ai1 * b[9] + ai2 * b[10] + ai3 * b[11];
  11200. out[i + 12] = ai0 * b[12] + ai1 * b[13] + ai2 * b[14] + ai3 * b[15];
  11201. }
  11202. }
  11203. setShadowMapTextureSize(size) {
  11204. if (size !== this._shadowMapTextureSize) {
  11205. this._shadowMapTextureSize = size;
  11206. this._shadowPCFOffset.x = 1 / this._shadowMapTextureSize;
  11207. this._shadowPCFOffset.y = 1 / this._shadowMapTextureSize;
  11208. this._statesDirty = true;
  11209. }
  11210. }
  11211. disposeAllRenderTarget() {
  11212. for (var i = 0, n = this._shadowMapCount + 1; i < n; i++) {
  11213. if (this.cameras[i].renderTarget) {
  11214. this.cameras[i].renderTarget.destroy();
  11215. this.cameras[i].renderTarget = null;
  11216. }
  11217. }
  11218. }
  11219. }
  11220. ParallelSplitShadowMap.MAX_PSSM_COUNT = 3;
  11221. ParallelSplitShadowMap._tempVector30 = new Vector3();
  11222. class LightSprite extends Sprite3D {
  11223. constructor() {
  11224. super();
  11225. this._intensity = 1.0;
  11226. this._intensityColor = new Vector3();
  11227. this.color = new Vector3(1.0, 1.0, 1.0);
  11228. this._shadow = false;
  11229. this._shadowFarPlane = 8;
  11230. this._shadowMapSize = 512;
  11231. this._shadowMapCount = 1;
  11232. this._shadowMapPCFType = 0;
  11233. this._lightmapBakedType = LightSprite.LIGHTMAPBAKEDTYPE_REALTIME;
  11234. }
  11235. get intensity() {
  11236. return this._intensity;
  11237. }
  11238. set intensity(value) {
  11239. this._intensity = value;
  11240. }
  11241. get shadow() {
  11242. return this._shadow;
  11243. }
  11244. set shadow(value) {
  11245. throw new Error("LightSprite: must override it.");
  11246. }
  11247. get shadowDistance() {
  11248. return this._shadowFarPlane;
  11249. }
  11250. set shadowDistance(value) {
  11251. this._shadowFarPlane = value;
  11252. (this._parallelSplitShadowMap) && (this._parallelSplitShadowMap.setFarDistance(value));
  11253. }
  11254. get shadowResolution() {
  11255. return this._shadowMapSize;
  11256. }
  11257. set shadowResolution(value) {
  11258. this._shadowMapSize = value;
  11259. (this._parallelSplitShadowMap) && (this._parallelSplitShadowMap.setShadowMapTextureSize(value));
  11260. }
  11261. get shadowPSSMCount() {
  11262. return this._shadowMapCount;
  11263. }
  11264. set shadowPSSMCount(value) {
  11265. this._shadowMapCount = value;
  11266. (this._parallelSplitShadowMap) && (this._parallelSplitShadowMap.shadowMapCount = value);
  11267. }
  11268. get shadowPCFType() {
  11269. return this._shadowMapPCFType;
  11270. }
  11271. set shadowPCFType(value) {
  11272. this._shadowMapPCFType = value;
  11273. (this._parallelSplitShadowMap) && (this._parallelSplitShadowMap.setPCFType(value));
  11274. }
  11275. get lightmapBakedType() {
  11276. return this._lightmapBakedType;
  11277. }
  11278. set lightmapBakedType(value) {
  11279. if (this._lightmapBakedType !== value) {
  11280. this._lightmapBakedType = value;
  11281. if (this.activeInHierarchy) {
  11282. if (value !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED)
  11283. this._scene._addLight(this);
  11284. else
  11285. this._scene._removeLight(this);
  11286. }
  11287. }
  11288. }
  11289. _parse(data, spriteMap) {
  11290. super._parse(data, spriteMap);
  11291. var colorData = data.color;
  11292. this.color.fromArray(colorData);
  11293. this.intensity = data.intensity;
  11294. this.lightmapBakedType = data.lightmapBakedType;
  11295. }
  11296. _onActive() {
  11297. super._onActive();
  11298. (this.lightmapBakedType !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED) && (this._scene._addLight(this));
  11299. }
  11300. _onInActive() {
  11301. super._onInActive();
  11302. (this.lightmapBakedType !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED) && (this._scene._removeLight(this));
  11303. }
  11304. _prepareToScene() {
  11305. return false;
  11306. }
  11307. _create() {
  11308. return new LightSprite();
  11309. }
  11310. get diffuseColor() {
  11311. console.log("LightSprite: discard property,please use color property instead.");
  11312. return this.color;
  11313. }
  11314. set diffuseColor(value) {
  11315. console.log("LightSprite: discard property,please use color property instead.");
  11316. this.color = value;
  11317. }
  11318. }
  11319. LightSprite.LIGHTMAPBAKEDTYPE_REALTIME = 0;
  11320. LightSprite.LIGHTMAPBAKEDTYPE_MIXED = 1;
  11321. LightSprite.LIGHTMAPBAKEDTYPE_BAKED = 2;
  11322. class DirectionLight extends LightSprite {
  11323. set shadow(value) {
  11324. if (this._shadow !== value) {
  11325. this._shadow = value;
  11326. (this.scene) && (this._initShadow());
  11327. }
  11328. }
  11329. constructor() {
  11330. super();
  11331. this._direction = new Vector3();
  11332. }
  11333. _initShadow() {
  11334. if (this._shadow) {
  11335. this._parallelSplitShadowMap = new ParallelSplitShadowMap();
  11336. this.scene.parallelSplitShadowMaps.push(this._parallelSplitShadowMap);
  11337. this.transform.worldMatrix.getForward(this._direction);
  11338. Vector3.normalize(this._direction, this._direction);
  11339. this._parallelSplitShadowMap.setInfo(this.scene, this._shadowFarPlane, this._direction, this._shadowMapSize, this._shadowMapCount, this._shadowMapPCFType);
  11340. }
  11341. else {
  11342. var defineDatas = this._scene._shaderValues;
  11343. var parallelSplitShadowMaps = this.scene.parallelSplitShadowMaps;
  11344. parallelSplitShadowMaps.splice(parallelSplitShadowMaps.indexOf(this._parallelSplitShadowMap), 1);
  11345. this._parallelSplitShadowMap.disposeAllRenderTarget();
  11346. this._parallelSplitShadowMap = null;
  11347. defineDatas.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM1);
  11348. defineDatas.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM2);
  11349. defineDatas.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM3);
  11350. }
  11351. }
  11352. _onActive() {
  11353. super._onActive();
  11354. this._shadow && (this._initShadow());
  11355. (this._lightmapBakedType !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED) && (this._scene._shaderValues.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT));
  11356. }
  11357. _onInActive() {
  11358. super._onInActive();
  11359. (this._lightmapBakedType !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED) && (this._scene._shaderValues.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT));
  11360. }
  11361. _prepareToScene() {
  11362. var scene = this._scene;
  11363. if (scene.enableLight && this.activeInHierarchy) {
  11364. var shaderValue = scene._shaderValues;
  11365. Vector3.scale(this.color, this._intensity, this._intensityColor);
  11366. shaderValue.setVector3(ILaya3D.Scene3D.LIGHTDIRCOLOR, this._intensityColor);
  11367. this.transform.worldMatrix.getForward(this._direction);
  11368. Vector3.normalize(this._direction, this._direction);
  11369. shaderValue.setVector3(ILaya3D.Scene3D.LIGHTDIRECTION, this._direction);
  11370. return true;
  11371. }
  11372. else {
  11373. return false;
  11374. }
  11375. }
  11376. }
  11377. class PointLight extends LightSprite {
  11378. constructor() {
  11379. super();
  11380. this._lightMatrix = new Matrix4x4();
  11381. this._range = 6.0;
  11382. }
  11383. get range() {
  11384. return this._range;
  11385. }
  11386. set range(value) {
  11387. this._range = value;
  11388. }
  11389. _onActive() {
  11390. super._onActive();
  11391. (this._lightmapBakedType !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED) && (this._scene._shaderValues.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT));
  11392. }
  11393. _onInActive() {
  11394. super._onInActive();
  11395. (this._lightmapBakedType !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED) && (this._scene._shaderValues.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT));
  11396. }
  11397. _prepareToScene() {
  11398. var scene = this._scene;
  11399. if (scene.enableLight && this.activeInHierarchy) {
  11400. var shaderValue = scene._shaderValues;
  11401. Vector3.scale(this.color, this._intensity, this._intensityColor);
  11402. shaderValue.setVector3(ILaya3D.Scene3D.POINTLIGHTCOLOR, this._intensityColor);
  11403. shaderValue.setVector3(ILaya3D.Scene3D.POINTLIGHTPOS, this.transform.position);
  11404. shaderValue.setNumber(ILaya3D.Scene3D.POINTLIGHTRANGE, this.range);
  11405. var lightMatrix = this._lightMatrix;
  11406. var lightMatrixE = lightMatrix.elements;
  11407. lightMatrix.identity();
  11408. lightMatrixE[0] = lightMatrixE[5] = lightMatrixE[10] = 1.0 / this._range;
  11409. var toLightMatrix = PointLight._tempMatrix0;
  11410. this.transform.worldMatrix.invert(toLightMatrix);
  11411. Matrix4x4.multiply(lightMatrix, toLightMatrix, lightMatrix);
  11412. shaderValue.setMatrix4x4(ILaya3D.Scene3D.POINTLIGHTMATRIX, lightMatrix);
  11413. return true;
  11414. }
  11415. else {
  11416. return false;
  11417. }
  11418. }
  11419. _parse(data, spriteMap) {
  11420. super._parse(data, spriteMap);
  11421. this.range = data.range;
  11422. }
  11423. }
  11424. PointLight._tempMatrix0 = new Matrix4x4();
  11425. class SpotLight extends LightSprite {
  11426. constructor() {
  11427. super();
  11428. this._spotAngle = 30.0;
  11429. this._range = 10.0;
  11430. this._direction = new Vector3();
  11431. }
  11432. get spotAngle() {
  11433. return this._spotAngle;
  11434. }
  11435. set spotAngle(value) {
  11436. this._spotAngle = Math.max(Math.min(value, 180), 0);
  11437. }
  11438. get range() {
  11439. return this._range;
  11440. }
  11441. set range(value) {
  11442. this._range = value;
  11443. }
  11444. _onActive() {
  11445. super._onActive();
  11446. (this._lightmapBakedType !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED) && (this.scene._shaderValues.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT));
  11447. }
  11448. _onInActive() {
  11449. super._onInActive();
  11450. (this._lightmapBakedType !== LightSprite.LIGHTMAPBAKEDTYPE_BAKED) && (this.scene._shaderValues.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT));
  11451. }
  11452. _prepareToScene() {
  11453. var scene = this._scene;
  11454. if (scene.enableLight && this.activeInHierarchy) {
  11455. var shaderValue = scene._shaderValues;
  11456. Vector3.scale(this.color, this._intensity, this._intensityColor);
  11457. shaderValue.setVector3(ILaya3D.Scene3D.SPOTLIGHTCOLOR, this._intensityColor);
  11458. shaderValue.setVector3(ILaya3D.Scene3D.SPOTLIGHTPOS, this.transform.position);
  11459. this.transform.worldMatrix.getForward(this._direction);
  11460. Vector3.normalize(this._direction, this._direction);
  11461. shaderValue.setVector3(ILaya3D.Scene3D.SPOTLIGHTDIRECTION, this._direction);
  11462. shaderValue.setNumber(ILaya3D.Scene3D.SPOTLIGHTRANGE, this.range);
  11463. shaderValue.setNumber(ILaya3D.Scene3D.SPOTLIGHTSPOTANGLE, this.spotAngle * Math.PI / 180);
  11464. return true;
  11465. }
  11466. else {
  11467. return false;
  11468. }
  11469. }
  11470. _parse(data, spriteMap) {
  11471. super._parse(data, spriteMap);
  11472. this.range = data.range;
  11473. this.spotAngle = data.spotAngle;
  11474. }
  11475. }
  11476. SpotLight._tempMatrix0 = new Matrix4x4();
  11477. SpotLight._tempMatrix1 = new Matrix4x4();
  11478. class MeshSprite3DShaderDeclaration {
  11479. }
  11480. class MeshFilter {
  11481. get sharedMesh() {
  11482. return this._sharedMesh;
  11483. }
  11484. set sharedMesh(value) {
  11485. if (this._sharedMesh !== value) {
  11486. var defineDatas = this._owner._render._shaderValues;
  11487. var lastValue = this._sharedMesh;
  11488. if (lastValue) {
  11489. lastValue._removeReference();
  11490. defineDatas.removeDefine(this._getMeshDefine(lastValue));
  11491. }
  11492. if (value) {
  11493. value._addReference();
  11494. defineDatas.addDefine(this._getMeshDefine(value));
  11495. }
  11496. this._owner._render._onMeshChange(value);
  11497. this._sharedMesh = value;
  11498. }
  11499. }
  11500. constructor(owner) {
  11501. this._owner = owner;
  11502. }
  11503. _getMeshDefine(mesh) {
  11504. var define;
  11505. for (var i = 0, n = mesh._subMeshes.length; i < n; i++) {
  11506. var subMesh = mesh.getSubMesh(i);
  11507. var vertexElements = subMesh._vertexBuffer._vertexDeclaration._vertexElements;
  11508. for (var j = 0, m = vertexElements.length; j < m; j++) {
  11509. var vertexElement = vertexElements[j];
  11510. var name = vertexElement._elementUsage;
  11511. switch (name) {
  11512. case VertexMesh.MESH_COLOR0:
  11513. define |= MeshSprite3DShaderDeclaration.SHADERDEFINE_COLOR;
  11514. break;
  11515. case VertexMesh.MESH_TEXTURECOORDINATE0:
  11516. define |= MeshSprite3DShaderDeclaration.SHADERDEFINE_UV0;
  11517. break;
  11518. case VertexMesh.MESH_TEXTURECOORDINATE1:
  11519. define |= MeshSprite3DShaderDeclaration.SHADERDEFINE_UV1;
  11520. break;
  11521. }
  11522. }
  11523. }
  11524. return define;
  11525. }
  11526. destroy() {
  11527. this._owner = null;
  11528. (this._sharedMesh) && (this._sharedMesh._removeReference(), this._sharedMesh = null);
  11529. }
  11530. }
  11531. class BaseMaterial extends Laya.Resource {
  11532. constructor() {
  11533. super();
  11534. this._shaderValues = null;
  11535. this._disablePublicDefineDatas = new DefineDatas();
  11536. this._shaderValues = new ShaderData(this);
  11537. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  11538. this._alphaTest = false;
  11539. }
  11540. static load(url, complete) {
  11541. Laya.Laya.loader.create(url, complete, null, BaseMaterial.MATERIAL);
  11542. }
  11543. static __initDefine__() {
  11544. BaseMaterial.shaderDefines = new ShaderDefines();
  11545. BaseMaterial.SHADERDEFINE_ALPHATEST = BaseMaterial.shaderDefines.registerDefine("ALPHATEST");
  11546. }
  11547. static _parse(data, propertyParams = null, constructParams = null) {
  11548. var jsonData = data;
  11549. var props = jsonData.props;
  11550. var material;
  11551. var classType = props.type;
  11552. var clas = Laya.ClassUtils.getRegClass(classType);
  11553. if (clas)
  11554. material = new clas();
  11555. else
  11556. throw ('_getSprite3DHierarchyInnerUrls 错误: ' + data.type + ' 不是类');
  11557. switch (jsonData.version) {
  11558. case "LAYAMATERIAL:01":
  11559. case "LAYAMATERIAL:02":
  11560. var i, n;
  11561. for (var key in props) {
  11562. switch (key) {
  11563. case "vectors":
  11564. var vectors = props[key];
  11565. for (i = 0, n = vectors.length; i < n; i++) {
  11566. var vector = vectors[i];
  11567. var vectorValue = vector.value;
  11568. switch (vectorValue.length) {
  11569. case 2:
  11570. material[vector.name] = new Vector2(vectorValue[0], vectorValue[1]);
  11571. break;
  11572. case 3:
  11573. material[vector.name] = new Vector3(vectorValue[0], vectorValue[1], vectorValue[2]);
  11574. break;
  11575. case 4:
  11576. material[vector.name] = new Vector4(vectorValue[0], vectorValue[1], vectorValue[2], vectorValue[3]);
  11577. break;
  11578. default:
  11579. throw new Error("BaseMaterial:unkonwn color length.");
  11580. }
  11581. }
  11582. break;
  11583. case "textures":
  11584. var textures = props[key];
  11585. for (i = 0, n = textures.length; i < n; i++) {
  11586. var texture = textures[i];
  11587. var path = texture.path;
  11588. (path) && (material[texture.name] = Laya.Loader.getRes(path));
  11589. }
  11590. break;
  11591. case "defines":
  11592. var defineNames = props[key];
  11593. for (i = 0, n = defineNames.length; i < n; i++) {
  11594. var define = material._shader.getSubShaderAt(0).getMaterialDefineByName(defineNames[i]);
  11595. material._shaderValues.addDefine(define);
  11596. }
  11597. break;
  11598. case "renderStates":
  11599. var renderStatesData = props[key];
  11600. var renderStateData = renderStatesData[0];
  11601. var mat = material;
  11602. mat.blend = renderStateData.blend;
  11603. mat.cull = renderStateData.cull;
  11604. mat.depthTest = renderStateData.depthTest;
  11605. mat.depthWrite = renderStateData.depthWrite;
  11606. mat.blendSrc = renderStateData.srcBlend;
  11607. mat.blendDst = renderStateData.dstBlend;
  11608. break;
  11609. case "cull":
  11610. material.cull = props[key];
  11611. break;
  11612. case "blend":
  11613. material.blend = props[key];
  11614. break;
  11615. case "depthWrite":
  11616. material.depthWrite = props[key];
  11617. break;
  11618. case "srcBlend":
  11619. material.blendSrc = props[key];
  11620. break;
  11621. case "dstBlend":
  11622. material.blendDst = props[key];
  11623. break;
  11624. default:
  11625. material[key] = props[key];
  11626. }
  11627. }
  11628. break;
  11629. default:
  11630. throw new Error("BaseMaterial:unkonwn version.");
  11631. }
  11632. return material;
  11633. }
  11634. get alphaTestValue() {
  11635. return this._shaderValues.getNumber(BaseMaterial.ALPHATESTVALUE);
  11636. }
  11637. set alphaTestValue(value) {
  11638. this._shaderValues.setNumber(BaseMaterial.ALPHATESTVALUE, value);
  11639. }
  11640. get alphaTest() {
  11641. return this._alphaTest;
  11642. }
  11643. set alphaTest(value) {
  11644. this._alphaTest = value;
  11645. if (value)
  11646. this._shaderValues.addDefine(BaseMaterial.SHADERDEFINE_ALPHATEST);
  11647. else
  11648. this._shaderValues.removeDefine(BaseMaterial.SHADERDEFINE_ALPHATEST);
  11649. }
  11650. _removeTetxureReference() {
  11651. var data = this._shaderValues.getData();
  11652. for (var k in data) {
  11653. var value = data[k];
  11654. if (value && value instanceof Laya.BaseTexture)
  11655. value._removeReference();
  11656. }
  11657. }
  11658. _addReference(count = 1) {
  11659. super._addReference(count);
  11660. var data = this._shaderValues.getData();
  11661. for (var k in data) {
  11662. var value = data[k];
  11663. if (value && value instanceof Laya.BaseTexture)
  11664. value._addReference();
  11665. }
  11666. }
  11667. _removeReference(count = 1) {
  11668. super._removeReference(count);
  11669. this._removeTetxureReference();
  11670. }
  11671. _disposeResource() {
  11672. if (this._referenceCount > 0)
  11673. this._removeTetxureReference();
  11674. this._shaderValues = null;
  11675. }
  11676. setShaderName(name) {
  11677. this._shader = Shader3D.find(name);
  11678. if (!this._shader)
  11679. throw new Error("BaseMaterial: unknown shader name.");
  11680. }
  11681. cloneTo(destObject) {
  11682. var destBaseMaterial = destObject;
  11683. destBaseMaterial.name = this.name;
  11684. destBaseMaterial.renderQueue = this.renderQueue;
  11685. this._disablePublicDefineDatas.cloneTo(destBaseMaterial._disablePublicDefineDatas);
  11686. this._shaderValues.cloneTo(destBaseMaterial._shaderValues);
  11687. }
  11688. clone() {
  11689. var dest = new BaseMaterial();
  11690. this.cloneTo(dest);
  11691. return dest;
  11692. }
  11693. get _defineDatas() {
  11694. return this._shaderValues._defineDatas;
  11695. }
  11696. }
  11697. BaseMaterial.MATERIAL = "MATERIAL";
  11698. BaseMaterial.RENDERQUEUE_OPAQUE = 2000;
  11699. BaseMaterial.RENDERQUEUE_ALPHATEST = 2450;
  11700. BaseMaterial.RENDERQUEUE_TRANSPARENT = 3000;
  11701. BaseMaterial.ALPHATESTVALUE = Shader3D.propertyNameToID("u_AlphaTestValue");
  11702. BaseMaterial.shaderDefines = null;
  11703. class RenderState {
  11704. constructor() {
  11705. this.cull = RenderState.CULL_BACK;
  11706. this.blend = RenderState.BLEND_DISABLE;
  11707. this.srcBlend = RenderState.BLENDPARAM_ONE;
  11708. this.dstBlend = RenderState.BLENDPARAM_ZERO;
  11709. this.srcBlendRGB = RenderState.BLENDPARAM_ONE;
  11710. this.dstBlendRGB = RenderState.BLENDPARAM_ZERO;
  11711. this.srcBlendAlpha = RenderState.BLENDPARAM_ONE;
  11712. this.dstBlendAlpha = RenderState.BLENDPARAM_ZERO;
  11713. this.blendConstColor = new Vector4(1, 1, 1, 1);
  11714. this.blendEquation = RenderState.BLENDEQUATION_ADD;
  11715. this.blendEquationRGB = RenderState.BLENDEQUATION_ADD;
  11716. this.blendEquationAlpha = RenderState.BLENDEQUATION_ADD;
  11717. this.depthTest = RenderState.DEPTHTEST_LEQUAL;
  11718. this.depthWrite = true;
  11719. }
  11720. cloneTo(dest) {
  11721. var destState = dest;
  11722. destState.cull = this.cull;
  11723. destState.blend = this.blend;
  11724. destState.srcBlend = this.srcBlend;
  11725. destState.dstBlend = this.dstBlend;
  11726. destState.srcBlendRGB = this.srcBlendRGB;
  11727. destState.dstBlendRGB = this.dstBlendRGB;
  11728. destState.srcBlendAlpha = this.srcBlendAlpha;
  11729. destState.dstBlendAlpha = this.dstBlendAlpha;
  11730. this.blendConstColor.cloneTo(destState.blendConstColor);
  11731. destState.blendEquation = this.blendEquation;
  11732. destState.blendEquationRGB = this.blendEquationRGB;
  11733. destState.blendEquationAlpha = this.blendEquationAlpha;
  11734. destState.depthTest = this.depthTest;
  11735. destState.depthWrite = this.depthWrite;
  11736. }
  11737. clone() {
  11738. var dest = new RenderState();
  11739. this.cloneTo(dest);
  11740. return dest;
  11741. }
  11742. }
  11743. RenderState.CULL_NONE = 0;
  11744. RenderState.CULL_FRONT = 1;
  11745. RenderState.CULL_BACK = 2;
  11746. RenderState.BLEND_DISABLE = 0;
  11747. RenderState.BLEND_ENABLE_ALL = 1;
  11748. RenderState.BLEND_ENABLE_SEPERATE = 2;
  11749. RenderState.BLENDPARAM_ZERO = 0;
  11750. RenderState.BLENDPARAM_ONE = 1;
  11751. RenderState.BLENDPARAM_SRC_COLOR = 0x0300;
  11752. RenderState.BLENDPARAM_ONE_MINUS_SRC_COLOR = 0x0301;
  11753. RenderState.BLENDPARAM_DST_COLOR = 0x0306;
  11754. RenderState.BLENDPARAM_ONE_MINUS_DST_COLOR = 0x0307;
  11755. RenderState.BLENDPARAM_SRC_ALPHA = 0x0302;
  11756. RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA = 0x0303;
  11757. RenderState.BLENDPARAM_DST_ALPHA = 0x0304;
  11758. RenderState.BLENDPARAM_ONE_MINUS_DST_ALPHA = 0x0305;
  11759. RenderState.BLENDPARAM_SRC_ALPHA_SATURATE = 0x0308;
  11760. RenderState.BLENDEQUATION_ADD = 0;
  11761. RenderState.BLENDEQUATION_SUBTRACT = 1;
  11762. RenderState.BLENDEQUATION_REVERSE_SUBTRACT = 2;
  11763. RenderState.DEPTHTEST_OFF = 0;
  11764. RenderState.DEPTHTEST_NEVER = 0x0200;
  11765. RenderState.DEPTHTEST_LESS = 0x0201;
  11766. RenderState.DEPTHTEST_EQUAL = 0x0202;
  11767. RenderState.DEPTHTEST_LEQUAL = 0x0203;
  11768. RenderState.DEPTHTEST_GREATER = 0x0204;
  11769. RenderState.DEPTHTEST_NOTEQUAL = 0x0205;
  11770. RenderState.DEPTHTEST_GEQUAL = 0x0206;
  11771. RenderState.DEPTHTEST_ALWAYS = 0x0207;
  11772. class BlinnPhongMaterial extends BaseMaterial {
  11773. constructor() {
  11774. super();
  11775. this._enableVertexColor = false;
  11776. this.setShaderName("BLINNPHONG");
  11777. this._albedoIntensity = 1.0;
  11778. this._albedoColor = new Vector4(1.0, 1.0, 1.0, 1.0);
  11779. var sv = this._shaderValues;
  11780. sv.setVector(BlinnPhongMaterial.ALBEDOCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  11781. sv.setVector(BlinnPhongMaterial.MATERIALSPECULAR, new Vector4(1.0, 1.0, 1.0, 1.0));
  11782. sv.setNumber(BlinnPhongMaterial.SHININESS, 0.078125);
  11783. sv.setNumber(BaseMaterial.ALPHATESTVALUE, 0.5);
  11784. sv.setVector(BlinnPhongMaterial.TILINGOFFSET, new Vector4(1.0, 1.0, 0.0, 0.0));
  11785. this._enableLighting = true;
  11786. this.renderMode = BlinnPhongMaterial.RENDERMODE_OPAQUE;
  11787. }
  11788. static __initDefine__() {
  11789. BlinnPhongMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  11790. BlinnPhongMaterial.SHADERDEFINE_DIFFUSEMAP = BlinnPhongMaterial.shaderDefines.registerDefine("DIFFUSEMAP");
  11791. BlinnPhongMaterial.SHADERDEFINE_NORMALMAP = BlinnPhongMaterial.shaderDefines.registerDefine("NORMALMAP");
  11792. BlinnPhongMaterial.SHADERDEFINE_SPECULARMAP = BlinnPhongMaterial.shaderDefines.registerDefine("SPECULARMAP");
  11793. BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET = BlinnPhongMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  11794. BlinnPhongMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR = BlinnPhongMaterial.shaderDefines.registerDefine("ENABLEVERTEXCOLOR");
  11795. }
  11796. get _ColorR() {
  11797. return this._albedoColor.x;
  11798. }
  11799. set _ColorR(value) {
  11800. this._albedoColor.x = value;
  11801. this.albedoColor = this._albedoColor;
  11802. }
  11803. get _ColorG() {
  11804. return this._albedoColor.y;
  11805. }
  11806. set _ColorG(value) {
  11807. this._albedoColor.y = value;
  11808. this.albedoColor = this._albedoColor;
  11809. }
  11810. get _ColorB() {
  11811. return this._albedoColor.z;
  11812. }
  11813. set _ColorB(value) {
  11814. this._albedoColor.z = value;
  11815. this.albedoColor = this._albedoColor;
  11816. }
  11817. get _ColorA() {
  11818. return this._albedoColor.w;
  11819. }
  11820. set _ColorA(value) {
  11821. this._albedoColor.w = value;
  11822. this.albedoColor = this._albedoColor;
  11823. }
  11824. get _SpecColorR() {
  11825. return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).x;
  11826. }
  11827. set _SpecColorR(value) {
  11828. this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).x = value;
  11829. }
  11830. get _SpecColorG() {
  11831. return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).y;
  11832. }
  11833. set _SpecColorG(value) {
  11834. this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).y = value;
  11835. }
  11836. get _SpecColorB() {
  11837. return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).z;
  11838. }
  11839. set _SpecColorB(value) {
  11840. this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).z = value;
  11841. }
  11842. get _SpecColorA() {
  11843. return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).w;
  11844. }
  11845. set _SpecColorA(value) {
  11846. this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).w = value;
  11847. }
  11848. get _AlbedoIntensity() {
  11849. return this._albedoIntensity;
  11850. }
  11851. set _AlbedoIntensity(value) {
  11852. if (this._albedoIntensity !== value) {
  11853. var finalAlbedo = this._shaderValues.getVector(BlinnPhongMaterial.ALBEDOCOLOR);
  11854. Vector4.scale(this._albedoColor, value, finalAlbedo);
  11855. this._albedoIntensity = value;
  11856. this._shaderValues.setVector(BlinnPhongMaterial.ALBEDOCOLOR, finalAlbedo);
  11857. }
  11858. }
  11859. get _Shininess() {
  11860. return this._shaderValues.getNumber(BlinnPhongMaterial.SHININESS);
  11861. }
  11862. set _Shininess(value) {
  11863. value = Math.max(0.0, Math.min(1.0, value));
  11864. this._shaderValues.setNumber(BlinnPhongMaterial.SHININESS, value);
  11865. }
  11866. get _MainTex_STX() {
  11867. return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET).x;
  11868. }
  11869. set _MainTex_STX(x) {
  11870. var tilOff = this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
  11871. tilOff.x = x;
  11872. this.tilingOffset = tilOff;
  11873. }
  11874. get _MainTex_STY() {
  11875. return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET).y;
  11876. }
  11877. set _MainTex_STY(y) {
  11878. var tilOff = this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
  11879. tilOff.y = y;
  11880. this.tilingOffset = tilOff;
  11881. }
  11882. get _MainTex_STZ() {
  11883. return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET).z;
  11884. }
  11885. set _MainTex_STZ(z) {
  11886. var tilOff = this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
  11887. tilOff.z = z;
  11888. this.tilingOffset = tilOff;
  11889. }
  11890. get _MainTex_STW() {
  11891. return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET).w;
  11892. }
  11893. set _MainTex_STW(w) {
  11894. var tilOff = this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
  11895. tilOff.w = w;
  11896. this.tilingOffset = tilOff;
  11897. }
  11898. get _Cutoff() {
  11899. return this.alphaTestValue;
  11900. }
  11901. set _Cutoff(value) {
  11902. this.alphaTestValue = value;
  11903. }
  11904. set renderMode(value) {
  11905. switch (value) {
  11906. case BlinnPhongMaterial.RENDERMODE_OPAQUE:
  11907. this.alphaTest = false;
  11908. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  11909. this.depthWrite = true;
  11910. this.cull = RenderState.CULL_BACK;
  11911. this.blend = RenderState.BLEND_DISABLE;
  11912. this.depthTest = RenderState.DEPTHTEST_LESS;
  11913. break;
  11914. case BlinnPhongMaterial.RENDERMODE_CUTOUT:
  11915. this.renderQueue = BaseMaterial.RENDERQUEUE_ALPHATEST;
  11916. this.alphaTest = true;
  11917. this.depthWrite = true;
  11918. this.cull = RenderState.CULL_BACK;
  11919. this.blend = RenderState.BLEND_DISABLE;
  11920. this.depthTest = RenderState.DEPTHTEST_LESS;
  11921. break;
  11922. case BlinnPhongMaterial.RENDERMODE_TRANSPARENT:
  11923. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  11924. this.alphaTest = false;
  11925. this.depthWrite = false;
  11926. this.cull = RenderState.CULL_BACK;
  11927. this.blend = RenderState.BLEND_ENABLE_ALL;
  11928. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  11929. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  11930. this.depthTest = RenderState.DEPTHTEST_LESS;
  11931. break;
  11932. default:
  11933. throw new Error("Material:renderMode value error.");
  11934. }
  11935. }
  11936. get enableVertexColor() {
  11937. return this._enableVertexColor;
  11938. }
  11939. set enableVertexColor(value) {
  11940. this._enableVertexColor = value;
  11941. if (value)
  11942. this._shaderValues.addDefine(BlinnPhongMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
  11943. else
  11944. this._shaderValues.removeDefine(BlinnPhongMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
  11945. }
  11946. get tilingOffsetX() {
  11947. return this._MainTex_STX;
  11948. }
  11949. set tilingOffsetX(x) {
  11950. this._MainTex_STX = x;
  11951. }
  11952. get tilingOffsetY() {
  11953. return this._MainTex_STY;
  11954. }
  11955. set tilingOffsetY(y) {
  11956. this._MainTex_STY = y;
  11957. }
  11958. get tilingOffsetZ() {
  11959. return this._MainTex_STZ;
  11960. }
  11961. set tilingOffsetZ(z) {
  11962. this._MainTex_STZ = z;
  11963. }
  11964. get tilingOffsetW() {
  11965. return this._MainTex_STW;
  11966. }
  11967. set tilingOffsetW(w) {
  11968. this._MainTex_STW = w;
  11969. }
  11970. get tilingOffset() {
  11971. return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
  11972. }
  11973. set tilingOffset(value) {
  11974. if (value) {
  11975. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  11976. this._shaderValues.addDefine(BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET);
  11977. else
  11978. this._shaderValues.removeDefine(BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET);
  11979. }
  11980. else {
  11981. this._shaderValues.removeDefine(BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET);
  11982. }
  11983. this._shaderValues.setVector(BlinnPhongMaterial.TILINGOFFSET, value);
  11984. }
  11985. get albedoColorR() {
  11986. return this._ColorR;
  11987. }
  11988. set albedoColorR(value) {
  11989. this._ColorR = value;
  11990. }
  11991. get albedoColorG() {
  11992. return this._ColorG;
  11993. }
  11994. set albedoColorG(value) {
  11995. this._ColorG = value;
  11996. }
  11997. get albedoColorB() {
  11998. return this._ColorB;
  11999. }
  12000. set albedoColorB(value) {
  12001. this._ColorB = value;
  12002. }
  12003. get albedoColorA() {
  12004. return this._ColorA;
  12005. }
  12006. set albedoColorA(value) {
  12007. this._ColorA = value;
  12008. }
  12009. get albedoColor() {
  12010. return this._albedoColor;
  12011. }
  12012. set albedoColor(value) {
  12013. var finalAlbedo = this._shaderValues.getVector(BlinnPhongMaterial.ALBEDOCOLOR);
  12014. Vector4.scale(value, this._albedoIntensity, finalAlbedo);
  12015. this._albedoColor = value;
  12016. this._shaderValues.setVector(BlinnPhongMaterial.ALBEDOCOLOR, finalAlbedo);
  12017. }
  12018. get albedoIntensity() {
  12019. return this._albedoIntensity;
  12020. }
  12021. set albedoIntensity(value) {
  12022. this._AlbedoIntensity = value;
  12023. }
  12024. get specularColorR() {
  12025. return this._SpecColorR;
  12026. }
  12027. set specularColorR(value) {
  12028. this._SpecColorR = value;
  12029. }
  12030. get specularColorG() {
  12031. return this._SpecColorG;
  12032. }
  12033. set specularColorG(value) {
  12034. this._SpecColorG = value;
  12035. }
  12036. get specularColorB() {
  12037. return this._SpecColorB;
  12038. }
  12039. set specularColorB(value) {
  12040. this._SpecColorB = value;
  12041. }
  12042. get specularColorA() {
  12043. return this._SpecColorA;
  12044. }
  12045. set specularColorA(value) {
  12046. this._SpecColorA = value;
  12047. }
  12048. get specularColor() {
  12049. return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR);
  12050. }
  12051. set specularColor(value) {
  12052. this._shaderValues.setVector(BlinnPhongMaterial.MATERIALSPECULAR, value);
  12053. }
  12054. get shininess() {
  12055. return this._Shininess;
  12056. }
  12057. set shininess(value) {
  12058. this._Shininess = value;
  12059. }
  12060. get albedoTexture() {
  12061. return this._shaderValues.getTexture(BlinnPhongMaterial.ALBEDOTEXTURE);
  12062. }
  12063. set albedoTexture(value) {
  12064. if (value)
  12065. this._shaderValues.addDefine(BlinnPhongMaterial.SHADERDEFINE_DIFFUSEMAP);
  12066. else
  12067. this._shaderValues.removeDefine(BlinnPhongMaterial.SHADERDEFINE_DIFFUSEMAP);
  12068. this._shaderValues.setTexture(BlinnPhongMaterial.ALBEDOTEXTURE, value);
  12069. }
  12070. get normalTexture() {
  12071. return this._shaderValues.getTexture(BlinnPhongMaterial.NORMALTEXTURE);
  12072. }
  12073. set normalTexture(value) {
  12074. if (value)
  12075. this._shaderValues.addDefine(BlinnPhongMaterial.SHADERDEFINE_NORMALMAP);
  12076. else
  12077. this._shaderValues.removeDefine(BlinnPhongMaterial.SHADERDEFINE_NORMALMAP);
  12078. this._shaderValues.setTexture(BlinnPhongMaterial.NORMALTEXTURE, value);
  12079. }
  12080. get specularTexture() {
  12081. return this._shaderValues.getTexture(BlinnPhongMaterial.SPECULARTEXTURE);
  12082. }
  12083. set specularTexture(value) {
  12084. if (value)
  12085. this._shaderValues.addDefine(BlinnPhongMaterial.SHADERDEFINE_SPECULARMAP);
  12086. else
  12087. this._shaderValues.removeDefine(BlinnPhongMaterial.SHADERDEFINE_SPECULARMAP);
  12088. this._shaderValues.setTexture(BlinnPhongMaterial.SPECULARTEXTURE, value);
  12089. }
  12090. get enableLighting() {
  12091. return this._enableLighting;
  12092. }
  12093. set enableLighting(value) {
  12094. if (this._enableLighting !== value) {
  12095. if (value)
  12096. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT);
  12097. else
  12098. this._disablePublicDefineDatas.add(Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT);
  12099. this._enableLighting = value;
  12100. }
  12101. }
  12102. set depthWrite(value) {
  12103. this._shaderValues.setBool(BlinnPhongMaterial.DEPTH_WRITE, value);
  12104. }
  12105. get depthWrite() {
  12106. return this._shaderValues.getBool(BlinnPhongMaterial.DEPTH_WRITE);
  12107. }
  12108. set cull(value) {
  12109. this._shaderValues.setInt(BlinnPhongMaterial.CULL, value);
  12110. }
  12111. get cull() {
  12112. return this._shaderValues.getInt(BlinnPhongMaterial.CULL);
  12113. }
  12114. set blend(value) {
  12115. this._shaderValues.setInt(BlinnPhongMaterial.BLEND, value);
  12116. }
  12117. get blend() {
  12118. return this._shaderValues.getInt(BlinnPhongMaterial.BLEND);
  12119. }
  12120. set blendSrc(value) {
  12121. this._shaderValues.setInt(BlinnPhongMaterial.BLEND_SRC, value);
  12122. }
  12123. get blendSrc() {
  12124. return this._shaderValues.getInt(BlinnPhongMaterial.BLEND_SRC);
  12125. }
  12126. set blendDst(value) {
  12127. this._shaderValues.setInt(BlinnPhongMaterial.BLEND_DST, value);
  12128. }
  12129. get blendDst() {
  12130. return this._shaderValues.getInt(BlinnPhongMaterial.BLEND_DST);
  12131. }
  12132. set depthTest(value) {
  12133. this._shaderValues.setInt(BlinnPhongMaterial.DEPTH_TEST, value);
  12134. }
  12135. get depthTest() {
  12136. return this._shaderValues.getInt(BlinnPhongMaterial.DEPTH_TEST);
  12137. }
  12138. clone() {
  12139. var dest = new BlinnPhongMaterial();
  12140. this.cloneTo(dest);
  12141. return dest;
  12142. }
  12143. cloneTo(destObject) {
  12144. super.cloneTo(destObject);
  12145. var destMaterial = destObject;
  12146. destMaterial._enableLighting = this._enableLighting;
  12147. destMaterial._albedoIntensity = this._albedoIntensity;
  12148. destMaterial._enableVertexColor = this._enableVertexColor;
  12149. this._albedoColor.cloneTo(destMaterial._albedoColor);
  12150. }
  12151. }
  12152. BlinnPhongMaterial.RENDERMODE_OPAQUE = 0;
  12153. BlinnPhongMaterial.RENDERMODE_CUTOUT = 1;
  12154. BlinnPhongMaterial.RENDERMODE_TRANSPARENT = 2;
  12155. BlinnPhongMaterial.ALBEDOTEXTURE = Shader3D.propertyNameToID("u_DiffuseTexture");
  12156. BlinnPhongMaterial.NORMALTEXTURE = Shader3D.propertyNameToID("u_NormalTexture");
  12157. BlinnPhongMaterial.SPECULARTEXTURE = Shader3D.propertyNameToID("u_SpecularTexture");
  12158. BlinnPhongMaterial.ALBEDOCOLOR = Shader3D.propertyNameToID("u_DiffuseColor");
  12159. BlinnPhongMaterial.MATERIALSPECULAR = Shader3D.propertyNameToID("u_MaterialSpecular");
  12160. BlinnPhongMaterial.SHININESS = Shader3D.propertyNameToID("u_Shininess");
  12161. BlinnPhongMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  12162. BlinnPhongMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  12163. BlinnPhongMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  12164. BlinnPhongMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  12165. BlinnPhongMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  12166. BlinnPhongMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  12167. BlinnPhongMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  12168. BlinnPhongMaterial.shaderDefines = null;
  12169. class Bounds {
  12170. constructor(min, max) {
  12171. this._updateFlag = 0;
  12172. this._center = new Vector3();
  12173. this._extent = new Vector3();
  12174. this._boundBox = new BoundBox(new Vector3(), new Vector3());
  12175. min.cloneTo(this._boundBox.min);
  12176. max.cloneTo(this._boundBox.max);
  12177. this._setUpdateFlag(Bounds._UPDATE_CENTER | Bounds._UPDATE_EXTENT, true);
  12178. }
  12179. setMin(value) {
  12180. var min = this._boundBox.min;
  12181. if (value !== min)
  12182. value.cloneTo(min);
  12183. this._setUpdateFlag(Bounds._UPDATE_CENTER | Bounds._UPDATE_EXTENT, true);
  12184. this._setUpdateFlag(Bounds._UPDATE_MIN, false);
  12185. }
  12186. getMin() {
  12187. var min = this._boundBox.min;
  12188. if (this._getUpdateFlag(Bounds._UPDATE_MIN)) {
  12189. this._getMin(this.getCenter(), this.getExtent(), min);
  12190. this._setUpdateFlag(Bounds._UPDATE_MIN, false);
  12191. }
  12192. return min;
  12193. }
  12194. setMax(value) {
  12195. var max = this._boundBox.max;
  12196. if (value !== max)
  12197. value.cloneTo(max);
  12198. this._setUpdateFlag(Bounds._UPDATE_CENTER | Bounds._UPDATE_EXTENT, true);
  12199. this._setUpdateFlag(Bounds._UPDATE_MAX, false);
  12200. }
  12201. getMax() {
  12202. var max = this._boundBox.max;
  12203. if (this._getUpdateFlag(Bounds._UPDATE_MAX)) {
  12204. this._getMax(this.getCenter(), this.getExtent(), max);
  12205. this._setUpdateFlag(Bounds._UPDATE_MAX, false);
  12206. }
  12207. return max;
  12208. }
  12209. setCenter(value) {
  12210. if (value !== this._center)
  12211. value.cloneTo(this._center);
  12212. this._setUpdateFlag(Bounds._UPDATE_MIN | Bounds._UPDATE_MAX, true);
  12213. this._setUpdateFlag(Bounds._UPDATE_CENTER, false);
  12214. }
  12215. getCenter() {
  12216. if (this._getUpdateFlag(Bounds._UPDATE_CENTER)) {
  12217. this._getCenter(this.getMin(), this.getMax(), this._center);
  12218. this._setUpdateFlag(Bounds._UPDATE_CENTER, false);
  12219. }
  12220. return this._center;
  12221. }
  12222. setExtent(value) {
  12223. if (value !== this._extent)
  12224. value.cloneTo(this._extent);
  12225. this._setUpdateFlag(Bounds._UPDATE_MIN | Bounds._UPDATE_MAX, true);
  12226. this._setUpdateFlag(Bounds._UPDATE_EXTENT, false);
  12227. }
  12228. getExtent() {
  12229. if (this._getUpdateFlag(Bounds._UPDATE_EXTENT)) {
  12230. this._getExtent(this.getMin(), this.getMax(), this._extent);
  12231. this._setUpdateFlag(Bounds._UPDATE_EXTENT, false);
  12232. }
  12233. return this._extent;
  12234. }
  12235. _getUpdateFlag(type) {
  12236. return (this._updateFlag & type) != 0;
  12237. }
  12238. _setUpdateFlag(type, value) {
  12239. if (value)
  12240. this._updateFlag |= type;
  12241. else
  12242. this._updateFlag &= ~type;
  12243. }
  12244. _getCenter(min, max, out) {
  12245. Vector3.add(min, max, out);
  12246. Vector3.scale(out, 0.5, out);
  12247. }
  12248. _getExtent(min, max, out) {
  12249. Vector3.subtract(max, min, out);
  12250. Vector3.scale(out, 0.5, out);
  12251. }
  12252. _getMin(center, extent, out) {
  12253. Vector3.subtract(center, extent, out);
  12254. }
  12255. _getMax(center, extent, out) {
  12256. Vector3.add(center, extent, out);
  12257. }
  12258. _rotateExtents(extents, rotation, out) {
  12259. var extentsX = extents.x;
  12260. var extentsY = extents.y;
  12261. var extentsZ = extents.z;
  12262. var matE = rotation.elements;
  12263. out.x = Math.abs(matE[0] * extentsX) + Math.abs(matE[4] * extentsY) + Math.abs(matE[8] * extentsZ);
  12264. out.y = Math.abs(matE[1] * extentsX) + Math.abs(matE[5] * extentsY) + Math.abs(matE[9] * extentsZ);
  12265. out.z = Math.abs(matE[2] * extentsX) + Math.abs(matE[6] * extentsY) + Math.abs(matE[10] * extentsZ);
  12266. }
  12267. _tranform(matrix, out) {
  12268. var outCen = out._center;
  12269. var outExt = out._extent;
  12270. Vector3.transformCoordinate(this.getCenter(), matrix, outCen);
  12271. this._rotateExtents(this.getExtent(), matrix, outExt);
  12272. out._boundBox.setCenterAndExtent(outCen, outExt);
  12273. out._updateFlag = 0;
  12274. }
  12275. _getBoundBox() {
  12276. if (this._updateFlag & Bounds._UPDATE_MIN) {
  12277. var min = this._boundBox.min;
  12278. this._getMin(this.getCenter(), this.getExtent(), min);
  12279. this._setUpdateFlag(Bounds._UPDATE_MIN, false);
  12280. }
  12281. if (this._updateFlag & Bounds._UPDATE_MAX) {
  12282. var max = this._boundBox.max;
  12283. this._getMax(this.getCenter(), this.getExtent(), max);
  12284. this._setUpdateFlag(Bounds._UPDATE_MAX, false);
  12285. }
  12286. return this._boundBox;
  12287. }
  12288. cloneTo(destObject) {
  12289. var destBounds = destObject;
  12290. this.getMin().cloneTo(destBounds._boundBox.min);
  12291. this.getMax().cloneTo(destBounds._boundBox.max);
  12292. this.getCenter().cloneTo(destBounds._center);
  12293. this.getExtent().cloneTo(destBounds._extent);
  12294. destBounds._updateFlag = 0;
  12295. }
  12296. clone() {
  12297. var dest = new Bounds(new Vector3(), new Vector3());
  12298. this.cloneTo(dest);
  12299. return dest;
  12300. }
  12301. }
  12302. Bounds._UPDATE_MIN = 0x01;
  12303. Bounds._UPDATE_MAX = 0x02;
  12304. Bounds._UPDATE_CENTER = 0x04;
  12305. Bounds._UPDATE_EXTENT = 0x08;
  12306. class BaseRender extends Laya.EventDispatcher {
  12307. constructor(owner) {
  12308. super();
  12309. this._indexInList = -1;
  12310. this._indexInCastShadowList = -1;
  12311. this._boundsChange = true;
  12312. this._supportOctree = true;
  12313. this._sharedMaterials = [];
  12314. this._visible = true;
  12315. this._indexInOctreeMotionList = -1;
  12316. this._updateMark = -1;
  12317. this._updateRenderType = -1;
  12318. this._isPartOfStaticBatch = false;
  12319. this._staticBatch = null;
  12320. this._id = ++BaseRender._uniqueIDCounter;
  12321. this._indexInCastShadowList = -1;
  12322. this._bounds = new Bounds(Vector3._ZERO, Vector3._ZERO);
  12323. if (Laya.Render.supportWebGLPlusCulling) {
  12324. var length = FrustumCulling._cullingBufferLength;
  12325. this._cullingBufferIndex = length;
  12326. var cullingBuffer = FrustumCulling._cullingBuffer;
  12327. var resizeLength = length + 7;
  12328. if (resizeLength >= cullingBuffer.length) {
  12329. var temp = cullingBuffer;
  12330. cullingBuffer = FrustumCulling._cullingBuffer = new Float32Array(cullingBuffer.length + 4096);
  12331. cullingBuffer.set(temp, 0);
  12332. }
  12333. cullingBuffer[length] = 2;
  12334. FrustumCulling._cullingBufferLength = resizeLength;
  12335. }
  12336. this._renderElements = [];
  12337. this._owner = owner;
  12338. this._enable = true;
  12339. this._materialsInstance = [];
  12340. this._shaderValues = new ShaderData(null);
  12341. this.lightmapIndex = -1;
  12342. this._castShadow = false;
  12343. this.receiveShadow = false;
  12344. this.sortingFudge = 0.0;
  12345. (owner) && (this._owner.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange));
  12346. }
  12347. get id() {
  12348. return this._id;
  12349. }
  12350. get lightmapIndex() {
  12351. return this._lightmapIndex;
  12352. }
  12353. set lightmapIndex(value) {
  12354. if (this._lightmapIndex !== value) {
  12355. this._lightmapIndex = value;
  12356. this._applyLightMapParams();
  12357. }
  12358. }
  12359. get lightmapScaleOffset() {
  12360. return this._lightmapScaleOffset;
  12361. }
  12362. set lightmapScaleOffset(value) {
  12363. this._lightmapScaleOffset = value;
  12364. this._shaderValues.setVector(RenderableSprite3D.LIGHTMAPSCALEOFFSET, value);
  12365. this._shaderValues.addDefine(RenderableSprite3D.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV);
  12366. }
  12367. get enable() {
  12368. return this._enable;
  12369. }
  12370. set enable(value) {
  12371. this._enable = !!value;
  12372. }
  12373. get material() {
  12374. var material = this._sharedMaterials[0];
  12375. if (material && !this._materialsInstance[0]) {
  12376. var insMat = this._getInstanceMaterial(material, 0);
  12377. var renderElement = this._renderElements[0];
  12378. (renderElement) && (renderElement.material = insMat);
  12379. }
  12380. return this._sharedMaterials[0];
  12381. }
  12382. set material(value) {
  12383. this.sharedMaterial = value;
  12384. }
  12385. get materials() {
  12386. for (var i = 0, n = this._sharedMaterials.length; i < n; i++) {
  12387. if (!this._materialsInstance[i]) {
  12388. var insMat = this._getInstanceMaterial(this._sharedMaterials[i], i);
  12389. var renderElement = this._renderElements[i];
  12390. (renderElement) && (renderElement.material = insMat);
  12391. }
  12392. }
  12393. return this._sharedMaterials.slice();
  12394. }
  12395. set materials(value) {
  12396. this.sharedMaterials = value;
  12397. }
  12398. get sharedMaterial() {
  12399. return this._sharedMaterials[0];
  12400. }
  12401. set sharedMaterial(value) {
  12402. var lastValue = this._sharedMaterials[0];
  12403. if (lastValue !== value) {
  12404. this._sharedMaterials[0] = value;
  12405. this._materialsInstance[0] = false;
  12406. this._changeMaterialReference(lastValue, value);
  12407. var renderElement = this._renderElements[0];
  12408. (renderElement) && (renderElement.material = value);
  12409. }
  12410. }
  12411. get sharedMaterials() {
  12412. return this._sharedMaterials.slice();
  12413. }
  12414. set sharedMaterials(value) {
  12415. var materialsInstance = this._materialsInstance;
  12416. var sharedMats = this._sharedMaterials;
  12417. for (var i = 0, n = sharedMats.length; i < n; i++) {
  12418. var lastMat = sharedMats[i];
  12419. (lastMat) && (lastMat._removeReference());
  12420. }
  12421. if (value) {
  12422. var count = value.length;
  12423. materialsInstance.length = count;
  12424. sharedMats.length = count;
  12425. for (i = 0; i < count; i++) {
  12426. lastMat = sharedMats[i];
  12427. var mat = value[i];
  12428. if (lastMat !== mat) {
  12429. materialsInstance[i] = false;
  12430. var renderElement = this._renderElements[i];
  12431. (renderElement) && (renderElement.material = mat);
  12432. }
  12433. if (mat) {
  12434. mat._addReference();
  12435. }
  12436. sharedMats[i] = mat;
  12437. }
  12438. }
  12439. else {
  12440. throw new Error("BaseRender: shadredMaterials value can't be null.");
  12441. }
  12442. }
  12443. get bounds() {
  12444. if (this._boundsChange) {
  12445. this._calculateBoundingBox();
  12446. this._boundsChange = false;
  12447. }
  12448. return this._bounds;
  12449. }
  12450. set receiveShadow(value) {
  12451. if (this._receiveShadow !== value) {
  12452. this._receiveShadow = value;
  12453. if (value)
  12454. this._shaderValues.addDefine(RenderableSprite3D.SHADERDEFINE_RECEIVE_SHADOW);
  12455. else
  12456. this._shaderValues.removeDefine(RenderableSprite3D.SHADERDEFINE_RECEIVE_SHADOW);
  12457. }
  12458. }
  12459. get receiveShadow() {
  12460. return this._receiveShadow;
  12461. }
  12462. get castShadow() {
  12463. return this._castShadow;
  12464. }
  12465. set castShadow(value) {
  12466. if (this._castShadow !== value) {
  12467. if (this._owner.activeInHierarchy) {
  12468. if (value)
  12469. this._scene._addShadowCastRenderObject(this);
  12470. else
  12471. this._scene._removeShadowCastRenderObject(this);
  12472. }
  12473. this._castShadow = value;
  12474. }
  12475. }
  12476. get isPartOfStaticBatch() {
  12477. return this._isPartOfStaticBatch;
  12478. }
  12479. _getOctreeNode() {
  12480. return this._octreeNode;
  12481. }
  12482. _setOctreeNode(value) {
  12483. this._octreeNode = value;
  12484. }
  12485. _getIndexInMotionList() {
  12486. return this._indexInOctreeMotionList;
  12487. }
  12488. _setIndexInMotionList(value) {
  12489. this._indexInOctreeMotionList = value;
  12490. }
  12491. _changeMaterialReference(lastValue, value) {
  12492. (lastValue) && (lastValue._removeReference());
  12493. value._addReference();
  12494. }
  12495. _getInstanceMaterial(material, index) {
  12496. var insMat = material.clone();
  12497. insMat.name = insMat.name + "(Instance)";
  12498. this._materialsInstance[index] = true;
  12499. this._changeMaterialReference(this._sharedMaterials[index], insMat);
  12500. this._sharedMaterials[index] = insMat;
  12501. return insMat;
  12502. }
  12503. _applyLightMapParams() {
  12504. if (this._scene && this._lightmapIndex >= 0) {
  12505. var lightMaps = this._scene.getlightmaps();
  12506. if (this._lightmapIndex < lightMaps.length) {
  12507. this._shaderValues.addDefine(RenderableSprite3D.SAHDERDEFINE_LIGHTMAP);
  12508. this._shaderValues.setTexture(RenderableSprite3D.LIGHTMAP, lightMaps[this._lightmapIndex]);
  12509. }
  12510. else {
  12511. this._shaderValues.removeDefine(RenderableSprite3D.SAHDERDEFINE_LIGHTMAP);
  12512. }
  12513. }
  12514. else {
  12515. this._shaderValues.removeDefine(RenderableSprite3D.SAHDERDEFINE_LIGHTMAP);
  12516. }
  12517. }
  12518. _onWorldMatNeedChange(flag) {
  12519. this._boundsChange = true;
  12520. if (this._octreeNode) {
  12521. flag &= Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE;
  12522. if (flag) {
  12523. if (this._indexInOctreeMotionList === -1)
  12524. this._octreeNode._octree.addMotionObject(this);
  12525. }
  12526. }
  12527. }
  12528. _calculateBoundingBox() {
  12529. throw ("BaseRender: must override it.");
  12530. }
  12531. _getIndexInList() {
  12532. return this._indexInList;
  12533. }
  12534. _setIndexInList(index) {
  12535. this._indexInList = index;
  12536. }
  12537. _setBelongScene(scene) {
  12538. if (this._scene !== scene) {
  12539. this._scene = scene;
  12540. this._applyLightMapParams();
  12541. }
  12542. }
  12543. _needRender(boundFrustum, context) {
  12544. return true;
  12545. }
  12546. _renderUpdate(context, transform) {
  12547. }
  12548. _renderUpdateWithCamera(context, transform) {
  12549. }
  12550. _revertBatchRenderUpdate(context) {
  12551. }
  12552. _destroy() {
  12553. (this._indexInOctreeMotionList !== -1) && (this._octreeNode._octree.removeMotionObject(this));
  12554. this.offAll();
  12555. var i = 0, n = 0;
  12556. for (i = 0, n = this._renderElements.length; i < n; i++)
  12557. this._renderElements[i].destroy();
  12558. for (i = 0, n = this._sharedMaterials.length; i < n; i++)
  12559. (this._sharedMaterials[i].destroyed) || (this._sharedMaterials[i]._removeReference());
  12560. this._renderElements = null;
  12561. this._owner = null;
  12562. this._sharedMaterials = null;
  12563. this._bounds = null;
  12564. this._lightmapScaleOffset = null;
  12565. }
  12566. }
  12567. BaseRender._tempBoundBoxCorners = [new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3()];
  12568. BaseRender._uniqueIDCounter = 0;
  12569. class MeshRenderer extends BaseRender {
  12570. constructor(owner) {
  12571. super(owner);
  12572. this._projectionViewWorldMatrix = new Matrix4x4();
  12573. }
  12574. _createRenderElement() {
  12575. return new SubMeshRenderElement();
  12576. }
  12577. _onMeshChange(mesh) {
  12578. if (mesh) {
  12579. var count = mesh.subMeshCount;
  12580. this._renderElements.length = count;
  12581. for (var i = 0; i < count; i++) {
  12582. var renderElement = this._renderElements[i];
  12583. if (!renderElement) {
  12584. var material = this.sharedMaterials[i];
  12585. renderElement = this._renderElements[i] = this._createRenderElement();
  12586. renderElement.setTransform(this._owner._transform);
  12587. renderElement.render = this;
  12588. renderElement.material = material ? material : BlinnPhongMaterial.defaultMaterial;
  12589. }
  12590. renderElement.setGeometry(mesh.getSubMesh(i));
  12591. }
  12592. }
  12593. else {
  12594. this._renderElements.length = 0;
  12595. }
  12596. this._boundsChange = true;
  12597. }
  12598. _calculateBoundingBox() {
  12599. var sharedMesh = this._owner.meshFilter.sharedMesh;
  12600. if (sharedMesh) {
  12601. var worldMat = this._owner.transform.worldMatrix;
  12602. sharedMesh.bounds._tranform(worldMat, this._bounds);
  12603. }
  12604. if (Laya.Render.supportWebGLPlusCulling) {
  12605. var min = this._bounds.getMin();
  12606. var max = this._bounds.getMax();
  12607. var buffer = FrustumCulling._cullingBuffer;
  12608. buffer[this._cullingBufferIndex + 1] = min.x;
  12609. buffer[this._cullingBufferIndex + 2] = min.y;
  12610. buffer[this._cullingBufferIndex + 3] = min.z;
  12611. buffer[this._cullingBufferIndex + 4] = max.x;
  12612. buffer[this._cullingBufferIndex + 5] = max.y;
  12613. buffer[this._cullingBufferIndex + 6] = max.z;
  12614. }
  12615. }
  12616. _needRender(boundFrustum, context) {
  12617. if (boundFrustum)
  12618. return boundFrustum.intersects(this.bounds._getBoundBox());
  12619. else
  12620. return true;
  12621. }
  12622. _renderUpdate(context, transform) {
  12623. var element = context.renderElement;
  12624. switch (element.renderType) {
  12625. case RenderElement.RENDERTYPE_NORMAL:
  12626. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, transform.worldMatrix);
  12627. break;
  12628. case RenderElement.RENDERTYPE_STATICBATCH:
  12629. this._oriDefineValue = this._shaderValues._defineDatas.value;
  12630. if (transform)
  12631. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, transform.worldMatrix);
  12632. else
  12633. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, Matrix4x4.DEFAULT);
  12634. this._shaderValues.addDefine(MeshSprite3DShaderDeclaration.SHADERDEFINE_UV1);
  12635. this._shaderValues.removeDefine(RenderableSprite3D.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV);
  12636. break;
  12637. case RenderElement.RENDERTYPE_VERTEXBATCH:
  12638. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, Matrix4x4.DEFAULT);
  12639. break;
  12640. case RenderElement.RENDERTYPE_INSTANCEBATCH:
  12641. var worldMatrixData = SubMeshInstanceBatch.instance.instanceWorldMatrixData;
  12642. var insBatches = element.instanceBatchElementList;
  12643. var elements = insBatches.elements;
  12644. var count = insBatches.length;
  12645. for (var i = 0; i < count; i++)
  12646. worldMatrixData.set(elements[i]._transform.worldMatrix.elements, i * 16);
  12647. SubMeshInstanceBatch.instance.instanceWorldMatrixBuffer.setData(worldMatrixData.buffer, 0, 0, count * 16 * 4);
  12648. this._shaderValues.addDefine(MeshSprite3DShaderDeclaration.SHADERDEFINE_GPU_INSTANCE);
  12649. break;
  12650. }
  12651. }
  12652. _renderUpdateWithCamera(context, transform) {
  12653. var projectionView = context.projectionViewMatrix;
  12654. var element = context.renderElement;
  12655. switch (element.renderType) {
  12656. case RenderElement.RENDERTYPE_NORMAL:
  12657. case RenderElement.RENDERTYPE_STATICBATCH:
  12658. case RenderElement.RENDERTYPE_VERTEXBATCH:
  12659. if (transform) {
  12660. Matrix4x4.multiply(projectionView, transform.worldMatrix, this._projectionViewWorldMatrix);
  12661. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  12662. }
  12663. else {
  12664. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, projectionView);
  12665. }
  12666. break;
  12667. case RenderElement.RENDERTYPE_INSTANCEBATCH:
  12668. var mvpMatrixData = SubMeshInstanceBatch.instance.instanceMVPMatrixData;
  12669. var insBatches = element.instanceBatchElementList;
  12670. var elements = insBatches.elements;
  12671. var count = insBatches.length;
  12672. for (var i = 0; i < count; i++) {
  12673. var worldMat = elements[i]._transform.worldMatrix;
  12674. Utils3D.mulMatrixByArray(projectionView.elements, 0, worldMat.elements, 0, mvpMatrixData, i * 16);
  12675. }
  12676. SubMeshInstanceBatch.instance.instanceMVPMatrixBuffer.setData(mvpMatrixData.buffer, 0, 0, count * 16 * 4);
  12677. break;
  12678. }
  12679. }
  12680. _revertBatchRenderUpdate(context) {
  12681. var element = context.renderElement;
  12682. switch (element.renderType) {
  12683. case RenderElement.RENDERTYPE_STATICBATCH:
  12684. this._shaderValues._defineDatas.value = this._oriDefineValue;
  12685. break;
  12686. case RenderElement.RENDERTYPE_INSTANCEBATCH:
  12687. this._shaderValues.removeDefine(MeshSprite3DShaderDeclaration.SHADERDEFINE_GPU_INSTANCE);
  12688. break;
  12689. }
  12690. }
  12691. _destroy() {
  12692. (this._isPartOfStaticBatch) && (MeshRenderStaticBatchManager.instance._destroyRenderSprite(this._owner));
  12693. super._destroy();
  12694. }
  12695. }
  12696. class MeshSprite3D extends RenderableSprite3D {
  12697. static __init__() {
  12698. MeshSprite3D.shaderDefines = new ShaderDefines(RenderableSprite3D.shaderDefines);
  12699. MeshSprite3DShaderDeclaration.SHADERDEFINE_UV0 = MeshSprite3D.shaderDefines.registerDefine("UV");
  12700. MeshSprite3DShaderDeclaration.SHADERDEFINE_COLOR = MeshSprite3D.shaderDefines.registerDefine("COLOR");
  12701. MeshSprite3DShaderDeclaration.SHADERDEFINE_UV1 = MeshSprite3D.shaderDefines.registerDefine("UV1");
  12702. MeshSprite3DShaderDeclaration.SHADERDEFINE_GPU_INSTANCE = MeshSprite3D.shaderDefines.registerDefine("GPU_INSTANCE");
  12703. StaticBatchManager._registerManager(MeshRenderStaticBatchManager.instance);
  12704. DynamicBatchManager._registerManager(MeshRenderDynamicBatchManager.instance);
  12705. }
  12706. get meshFilter() {
  12707. return this._meshFilter;
  12708. }
  12709. get meshRenderer() {
  12710. return this._render;
  12711. }
  12712. constructor(mesh = null, name = null) {
  12713. super(name);
  12714. this._meshFilter = new MeshFilter(this);
  12715. this._render = new MeshRenderer(this);
  12716. (mesh) && (this._meshFilter.sharedMesh = mesh);
  12717. }
  12718. _parse(data, spriteMap) {
  12719. super._parse(data, spriteMap);
  12720. var render = this.meshRenderer;
  12721. var lightmapIndex = data.lightmapIndex;
  12722. (lightmapIndex != null) && (render.lightmapIndex = lightmapIndex);
  12723. var lightmapScaleOffsetArray = data.lightmapScaleOffset;
  12724. (lightmapScaleOffsetArray) && (render.lightmapScaleOffset = new Vector4(lightmapScaleOffsetArray[0], lightmapScaleOffsetArray[1], lightmapScaleOffsetArray[2], lightmapScaleOffsetArray[3]));
  12725. (data.meshPath != undefined) && (this.meshFilter.sharedMesh = Laya.Loader.getRes(data.meshPath));
  12726. (data.enableRender != undefined) && (this.meshRenderer.enable = data.enableRender);
  12727. var materials = data.materials;
  12728. if (materials) {
  12729. var sharedMaterials = render.sharedMaterials;
  12730. var materialCount = materials.length;
  12731. sharedMaterials.length = materialCount;
  12732. for (var i = 0; i < materialCount; i++) {
  12733. sharedMaterials[i] = Laya.Loader.getRes(materials[i].path);
  12734. }
  12735. render.sharedMaterials = sharedMaterials;
  12736. }
  12737. }
  12738. _addToInitStaticBatchManager() {
  12739. if (this.meshFilter.sharedMesh)
  12740. MeshRenderStaticBatchManager.instance._addBatchSprite(this);
  12741. }
  12742. _cloneTo(destObject, rootSprite, dstSprite) {
  12743. var meshSprite3D = destObject;
  12744. meshSprite3D._meshFilter.sharedMesh = this._meshFilter.sharedMesh;
  12745. var meshRender = this._render;
  12746. var destMeshRender = meshSprite3D._render;
  12747. destMeshRender.enable = meshRender.enable;
  12748. destMeshRender.sharedMaterials = meshRender.sharedMaterials;
  12749. destMeshRender.castShadow = meshRender.castShadow;
  12750. var lightmapScaleOffset = meshRender.lightmapScaleOffset;
  12751. lightmapScaleOffset && (destMeshRender.lightmapScaleOffset = lightmapScaleOffset.clone());
  12752. destMeshRender.lightmapIndex = meshRender.lightmapIndex;
  12753. destMeshRender.receiveShadow = meshRender.receiveShadow;
  12754. destMeshRender.sortingFudge = meshRender.sortingFudge;
  12755. super._cloneTo(destObject, rootSprite, dstSprite);
  12756. }
  12757. destroy(destroyChild = true) {
  12758. if (this.destroyed)
  12759. return;
  12760. super.destroy(destroyChild);
  12761. this._meshFilter.destroy();
  12762. }
  12763. _create() {
  12764. return new MeshSprite3D();
  12765. }
  12766. }
  12767. class GradientMode {
  12768. }
  12769. GradientMode.Blend = 0;
  12770. GradientMode.Fixed = 1;
  12771. class Gradient {
  12772. constructor(maxColorRGBKeyCount, maxColorAlphaKeyCount) {
  12773. this._mode = 0;
  12774. this._maxColorRGBKeysCount = 0;
  12775. this._maxColorAlphaKeysCount = 0;
  12776. this._colorRGBKeysCount = 0;
  12777. this._colorAlphaKeysCount = 0;
  12778. this._alphaElements = null;
  12779. this._rgbElements = null;
  12780. this._maxColorRGBKeysCount = maxColorRGBKeyCount;
  12781. this._maxColorAlphaKeysCount = maxColorAlphaKeyCount;
  12782. this._rgbElements = new Float32Array(maxColorRGBKeyCount * 4);
  12783. this._alphaElements = new Float32Array(maxColorAlphaKeyCount * 2);
  12784. }
  12785. get mode() {
  12786. return this._mode;
  12787. }
  12788. set mode(value) {
  12789. this._mode = value;
  12790. }
  12791. get colorRGBKeysCount() {
  12792. return this._colorRGBKeysCount;
  12793. }
  12794. get colorAlphaKeysCount() {
  12795. return this._colorAlphaKeysCount;
  12796. }
  12797. get maxColorRGBKeysCount() {
  12798. return this._maxColorRGBKeysCount;
  12799. }
  12800. get maxColorAlphaKeysCount() {
  12801. return this._maxColorAlphaKeysCount;
  12802. }
  12803. addColorRGB(key, value) {
  12804. if (this._colorRGBKeysCount < this._maxColorRGBKeysCount) {
  12805. var offset = this._colorRGBKeysCount * 4;
  12806. this._rgbElements[offset] = key;
  12807. this._rgbElements[offset + 1] = value.r;
  12808. this._rgbElements[offset + 2] = value.g;
  12809. this._rgbElements[offset + 3] = value.b;
  12810. this._colorRGBKeysCount++;
  12811. }
  12812. else {
  12813. console.warn("Gradient:warning:data count must lessEqual than " + this._maxColorRGBKeysCount);
  12814. }
  12815. }
  12816. addColorAlpha(key, value) {
  12817. if (this._colorAlphaKeysCount < this._maxColorAlphaKeysCount) {
  12818. var offset = this._colorAlphaKeysCount * 2;
  12819. this._alphaElements[offset] = key;
  12820. this._alphaElements[offset + 1] = value;
  12821. this._colorAlphaKeysCount++;
  12822. }
  12823. else {
  12824. console.warn("Gradient:warning:data count must lessEqual than " + this._maxColorAlphaKeysCount);
  12825. }
  12826. }
  12827. updateColorRGB(index, key, value) {
  12828. if (index < this._colorRGBKeysCount) {
  12829. var offset = index * 4;
  12830. this._rgbElements[offset] = key;
  12831. this._rgbElements[offset + 1] = value.r;
  12832. this._rgbElements[offset + 2] = value.g;
  12833. this._rgbElements[offset + 3] = value.b;
  12834. }
  12835. else {
  12836. console.warn("Gradient:warning:index must lessEqual than colorRGBKeysCount:" + this._colorRGBKeysCount);
  12837. }
  12838. }
  12839. updateColorAlpha(index, key, value) {
  12840. if (index < this._colorAlphaKeysCount) {
  12841. var offset = index * 2;
  12842. this._alphaElements[offset] = key;
  12843. this._alphaElements[offset + 1] = value;
  12844. }
  12845. else {
  12846. console.warn("Gradient:warning:index must lessEqual than colorAlphaKeysCount:" + this._colorAlphaKeysCount);
  12847. }
  12848. }
  12849. evaluateColorRGB(lerpFactor, out, startSearchIndex = 0, reverseSearch = false) {
  12850. lerpFactor = Math.min(Math.max(lerpFactor, 0.0), 1.0);
  12851. var rgbElements = this._rgbElements;
  12852. var curIndex = startSearchIndex;
  12853. if (reverseSearch) {
  12854. for (var i = curIndex; i >= 0; i--) {
  12855. var offset = i * 4;
  12856. var left = rgbElements[offset];
  12857. if (lerpFactor === left) {
  12858. out.r = rgbElements[offset + 1];
  12859. out.g = rgbElements[offset + 2];
  12860. out.b = rgbElements[offset + 3];
  12861. return curIndex;
  12862. }
  12863. switch (this._mode) {
  12864. case GradientMode.Blend:
  12865. if (lerpFactor > left) {
  12866. var right = rgbElements[offset + 4];
  12867. if (lerpFactor > right)
  12868. throw "Gradient:wrong startSearchIndex.";
  12869. var diff = right - left;
  12870. var y1 = right - lerpFactor;
  12871. var y2 = lerpFactor - left;
  12872. out.r = (y1 * rgbElements[offset + 1] + y2 * rgbElements[offset + 5]) / diff;
  12873. out.g = (y1 * rgbElements[offset + 2] + y2 * rgbElements[offset + 6]) / diff;
  12874. out.b = (y1 * rgbElements[offset + 3] + y2 * rgbElements[offset + 7]) / diff;
  12875. return curIndex;
  12876. }
  12877. else {
  12878. curIndex--;
  12879. continue;
  12880. }
  12881. case GradientMode.Fixed:
  12882. if (lerpFactor > left) {
  12883. if (lerpFactor > rgbElements[offset + 4])
  12884. throw "Gradient:wrong startSearchIndex.";
  12885. out.r = rgbElements[offset + 5];
  12886. out.g = rgbElements[offset + 6];
  12887. out.b = rgbElements[offset + 7];
  12888. return curIndex;
  12889. }
  12890. else {
  12891. curIndex--;
  12892. continue;
  12893. }
  12894. default:
  12895. throw "Gradient:unknown mode.";
  12896. }
  12897. }
  12898. }
  12899. else {
  12900. for (var i = 0, n = this._rgbElements.length; i < n; i++) {
  12901. offset = i * 4;
  12902. var right = rgbElements[offset];
  12903. if (lerpFactor === right) {
  12904. out.r = rgbElements[offset + 1];
  12905. out.g = rgbElements[offset + 2];
  12906. out.b = rgbElements[offset + 3];
  12907. return curIndex;
  12908. }
  12909. switch (this._mode) {
  12910. case GradientMode.Blend:
  12911. if (lerpFactor < right) {
  12912. var left = rgbElements[offset - 4];
  12913. if (lerpFactor < left)
  12914. throw "Gradient:wrong startSearchIndex.";
  12915. var diff = right - left;
  12916. var y1 = right - lerpFactor;
  12917. var y2 = lerpFactor - left;
  12918. out.r = (y1 * rgbElements[offset - 3] + y2 * rgbElements[offset + 1]) / diff;
  12919. out.g = (y1 * rgbElements[offset - 2] + y2 * rgbElements[offset + 2]) / diff;
  12920. out.b = (y1 * rgbElements[offset - 1] + y2 * rgbElements[offset + 3]) / diff;
  12921. return curIndex;
  12922. }
  12923. else {
  12924. curIndex++;
  12925. continue;
  12926. }
  12927. case GradientMode.Fixed:
  12928. if (lerpFactor < right) {
  12929. if (lerpFactor < rgbElements[offset - 4])
  12930. throw "Gradient:wrong startSearchIndex.";
  12931. out.r = rgbElements[offset + 1];
  12932. out.g = rgbElements[offset + 2];
  12933. out.b = rgbElements[offset + 3];
  12934. return curIndex;
  12935. }
  12936. else {
  12937. curIndex++;
  12938. continue;
  12939. }
  12940. default:
  12941. throw "Gradient:unknown mode.";
  12942. }
  12943. }
  12944. }
  12945. return curIndex;
  12946. }
  12947. evaluateColorAlpha(lerpFactor, outColor, startSearchIndex = 0, reverseSearch = false) {
  12948. lerpFactor = Math.min(Math.max(lerpFactor, 0.0), 1.0);
  12949. var alphaElements = this._alphaElements;
  12950. var curIndex = startSearchIndex;
  12951. if (reverseSearch) {
  12952. for (var i = curIndex; i >= 0; i--) {
  12953. var offset = i * 2;
  12954. var left = alphaElements[offset];
  12955. if (lerpFactor === left) {
  12956. outColor.a = alphaElements[offset + 1];
  12957. return curIndex;
  12958. }
  12959. switch (this._mode) {
  12960. case GradientMode.Blend:
  12961. if (lerpFactor > left) {
  12962. var right = alphaElements[offset + 2];
  12963. if (lerpFactor > right)
  12964. throw "Gradient:wrong startSearchIndex.";
  12965. var diff = right - left;
  12966. var x1 = right - lerpFactor;
  12967. var x2 = lerpFactor - left;
  12968. outColor.a = (x1 * alphaElements[offset + 1] + x2 * alphaElements[offset + 3]) / diff;
  12969. return curIndex;
  12970. }
  12971. else {
  12972. curIndex--;
  12973. continue;
  12974. }
  12975. case GradientMode.Fixed:
  12976. if (lerpFactor > left) {
  12977. if (lerpFactor > alphaElements[offset + 2])
  12978. throw "Gradient:wrong startSearchIndex.";
  12979. outColor.a = alphaElements[offset + 3];
  12980. return curIndex;
  12981. }
  12982. else {
  12983. curIndex--;
  12984. continue;
  12985. }
  12986. default:
  12987. throw "Gradient:unknown mode.";
  12988. }
  12989. }
  12990. }
  12991. else {
  12992. for (var i = curIndex, n = this._alphaElements.length; i < n; i++) {
  12993. var offset = i * 2;
  12994. var right = alphaElements[offset];
  12995. if (lerpFactor === right) {
  12996. outColor.a = alphaElements[offset + 1];
  12997. return curIndex;
  12998. }
  12999. switch (this._mode) {
  13000. case GradientMode.Blend:
  13001. if (lerpFactor < right) {
  13002. var left = alphaElements[offset - 2];
  13003. if (lerpFactor < left)
  13004. throw "Gradient:wrong startSearchIndex.";
  13005. var diff = right - left;
  13006. var x1 = right - lerpFactor;
  13007. var x2 = lerpFactor - left;
  13008. outColor.a = (x1 * alphaElements[offset - 1] + x2 * alphaElements[offset + 1]) / diff;
  13009. return curIndex;
  13010. }
  13011. else {
  13012. curIndex++;
  13013. continue;
  13014. }
  13015. case GradientMode.Fixed:
  13016. if (lerpFactor < right) {
  13017. if (lerpFactor < alphaElements[offset - 2])
  13018. throw "Gradient:wrong startSearchIndex.";
  13019. outColor.a = alphaElements[offset + 1];
  13020. return curIndex;
  13021. }
  13022. else {
  13023. curIndex++;
  13024. continue;
  13025. }
  13026. default:
  13027. throw "Gradient:unknown mode.";
  13028. }
  13029. }
  13030. }
  13031. return curIndex;
  13032. }
  13033. cloneTo(destObject) {
  13034. var destGradientDataColor = destObject;
  13035. var i, n;
  13036. destGradientDataColor._colorAlphaKeysCount = this._colorAlphaKeysCount;
  13037. var destAlphaElements = destGradientDataColor._alphaElements;
  13038. for (i = 0, n = this._alphaElements.length; i < n; i++)
  13039. destAlphaElements[i] = this._alphaElements[i];
  13040. destGradientDataColor._colorRGBKeysCount = this._colorRGBKeysCount;
  13041. var destRGBElements = destGradientDataColor._rgbElements;
  13042. for (i = 0, n = this._rgbElements.length; i < n; i++)
  13043. destRGBElements[i] = this._rgbElements[i];
  13044. }
  13045. clone() {
  13046. var destGradientDataColor = new Gradient(this._maxColorRGBKeysCount, this._maxColorAlphaKeysCount);
  13047. this.cloneTo(destGradientDataColor);
  13048. return destGradientDataColor;
  13049. }
  13050. }
  13051. class ShurikenParticleMaterial extends BaseMaterial {
  13052. constructor() {
  13053. super();
  13054. this.setShaderName("PARTICLESHURIKEN");
  13055. this._color = new Vector4(1.0, 1.0, 1.0, 1.0);
  13056. this.renderMode = ShurikenParticleMaterial.RENDERMODE_ALPHABLENDED;
  13057. }
  13058. static __initDefine__() {
  13059. ShurikenParticleMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  13060. ShurikenParticleMaterial.SHADERDEFINE_DIFFUSEMAP = ShurikenParticleMaterial.shaderDefines.registerDefine("DIFFUSEMAP");
  13061. ShurikenParticleMaterial.SHADERDEFINE_TINTCOLOR = ShurikenParticleMaterial.shaderDefines.registerDefine("TINTCOLOR");
  13062. ShurikenParticleMaterial.SHADERDEFINE_ADDTIVEFOG = ShurikenParticleMaterial.shaderDefines.registerDefine("ADDTIVEFOG");
  13063. ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET = ShurikenParticleMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  13064. }
  13065. get _TintColorR() {
  13066. return this._color.x;
  13067. }
  13068. set _TintColorR(value) {
  13069. this._color.x = value;
  13070. this.color = this._color;
  13071. }
  13072. get _TintColorG() {
  13073. return this._color.y;
  13074. }
  13075. set _TintColorG(value) {
  13076. this._color.y = value;
  13077. this.color = this._color;
  13078. }
  13079. get _TintColorB() {
  13080. return this._color.z;
  13081. }
  13082. set _TintColorB(value) {
  13083. this._color.z = value;
  13084. this.color = this._color;
  13085. }
  13086. get _TintColorA() {
  13087. return this._color.w;
  13088. }
  13089. set _TintColorA(value) {
  13090. this._color.w = value;
  13091. this.color = this._color;
  13092. }
  13093. get _MainTex_STX() {
  13094. return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET).x;
  13095. }
  13096. set _MainTex_STX(x) {
  13097. var tilOff = this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
  13098. tilOff.x = x;
  13099. this.tilingOffset = tilOff;
  13100. }
  13101. get _MainTex_STY() {
  13102. return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET).y;
  13103. }
  13104. set _MainTex_STY(y) {
  13105. var tilOff = this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
  13106. tilOff.y = y;
  13107. this.tilingOffset = tilOff;
  13108. }
  13109. get _MainTex_STZ() {
  13110. return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET).z;
  13111. }
  13112. set _MainTex_STZ(z) {
  13113. var tilOff = this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
  13114. tilOff.z = z;
  13115. this.tilingOffset = tilOff;
  13116. }
  13117. get _MainTex_STW() {
  13118. return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET).w;
  13119. }
  13120. set _MainTex_STW(w) {
  13121. var tilOff = this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
  13122. tilOff.w = w;
  13123. this.tilingOffset = tilOff;
  13124. }
  13125. set renderMode(value) {
  13126. switch (value) {
  13127. case ShurikenParticleMaterial.RENDERMODE_ADDTIVE:
  13128. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  13129. this.depthWrite = false;
  13130. this.cull = RenderState.CULL_NONE;
  13131. this.blend = RenderState.BLEND_ENABLE_ALL;
  13132. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  13133. this.blendDst = RenderState.BLENDPARAM_ONE;
  13134. this.alphaTest = false;
  13135. this._shaderValues.addDefine(ShurikenParticleMaterial.SHADERDEFINE_ADDTIVEFOG);
  13136. break;
  13137. case ShurikenParticleMaterial.RENDERMODE_ALPHABLENDED:
  13138. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  13139. this.depthWrite = false;
  13140. this.cull = RenderState.CULL_NONE;
  13141. this.blend = RenderState.BLEND_ENABLE_ALL;
  13142. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  13143. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  13144. this.alphaTest = false;
  13145. this._shaderValues.removeDefine(ShurikenParticleMaterial.SHADERDEFINE_ADDTIVEFOG);
  13146. break;
  13147. default:
  13148. throw new Error("ShurikenParticleMaterial : renderMode value error.");
  13149. }
  13150. }
  13151. get colorR() {
  13152. return this._TintColorR;
  13153. }
  13154. set colorR(value) {
  13155. this._TintColorR = value;
  13156. }
  13157. get colorG() {
  13158. return this._TintColorG;
  13159. }
  13160. set colorG(value) {
  13161. this._TintColorG = value;
  13162. }
  13163. get colorB() {
  13164. return this._TintColorB;
  13165. }
  13166. set colorB(value) {
  13167. this._TintColorB = value;
  13168. }
  13169. get colorA() {
  13170. return this._TintColorA;
  13171. }
  13172. set colorA(value) {
  13173. this._TintColorA = value;
  13174. }
  13175. get color() {
  13176. return this._shaderValues.getVector(ShurikenParticleMaterial.TINTCOLOR);
  13177. }
  13178. set color(value) {
  13179. if (value)
  13180. this._shaderValues.addDefine(ShurikenParticleMaterial.SHADERDEFINE_TINTCOLOR);
  13181. else
  13182. this._shaderValues.removeDefine(ShurikenParticleMaterial.SHADERDEFINE_TINTCOLOR);
  13183. this._shaderValues.setVector(ShurikenParticleMaterial.TINTCOLOR, value);
  13184. }
  13185. get tilingOffsetX() {
  13186. return this._MainTex_STX;
  13187. }
  13188. set tilingOffsetX(x) {
  13189. this._MainTex_STX = x;
  13190. }
  13191. get tilingOffsetY() {
  13192. return this._MainTex_STY;
  13193. }
  13194. set tilingOffsetY(y) {
  13195. this._MainTex_STY = y;
  13196. }
  13197. get tilingOffsetZ() {
  13198. return this._MainTex_STZ;
  13199. }
  13200. set tilingOffsetZ(z) {
  13201. this._MainTex_STZ = z;
  13202. }
  13203. get tilingOffsetW() {
  13204. return this._MainTex_STW;
  13205. }
  13206. set tilingOffsetW(w) {
  13207. this._MainTex_STW = w;
  13208. }
  13209. get tilingOffset() {
  13210. return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
  13211. }
  13212. set tilingOffset(value) {
  13213. if (value) {
  13214. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  13215. this._shaderValues.addDefine(ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET);
  13216. else
  13217. this._shaderValues.removeDefine(ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET);
  13218. }
  13219. else {
  13220. this._shaderValues.removeDefine(ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET);
  13221. }
  13222. this._shaderValues.setVector(ShurikenParticleMaterial.TILINGOFFSET, value);
  13223. }
  13224. get texture() {
  13225. return this._shaderValues.getTexture(ShurikenParticleMaterial.DIFFUSETEXTURE);
  13226. }
  13227. set texture(value) {
  13228. if (value)
  13229. this._shaderValues.addDefine(ShurikenParticleMaterial.SHADERDEFINE_DIFFUSEMAP);
  13230. else
  13231. this._shaderValues.removeDefine(ShurikenParticleMaterial.SHADERDEFINE_DIFFUSEMAP);
  13232. this._shaderValues.setTexture(ShurikenParticleMaterial.DIFFUSETEXTURE, value);
  13233. }
  13234. set depthWrite(value) {
  13235. this._shaderValues.setBool(ShurikenParticleMaterial.DEPTH_WRITE, value);
  13236. }
  13237. get depthWrite() {
  13238. return this._shaderValues.getBool(ShurikenParticleMaterial.DEPTH_WRITE);
  13239. }
  13240. set cull(value) {
  13241. this._shaderValues.setInt(ShurikenParticleMaterial.CULL, value);
  13242. }
  13243. get cull() {
  13244. return this._shaderValues.getInt(ShurikenParticleMaterial.CULL);
  13245. }
  13246. set blend(value) {
  13247. this._shaderValues.setInt(ShurikenParticleMaterial.BLEND, value);
  13248. }
  13249. get blend() {
  13250. return this._shaderValues.getInt(ShurikenParticleMaterial.BLEND);
  13251. }
  13252. set blendSrc(value) {
  13253. this._shaderValues.setInt(ShurikenParticleMaterial.BLEND_SRC, value);
  13254. }
  13255. get blendSrc() {
  13256. return this._shaderValues.getInt(ShurikenParticleMaterial.BLEND_SRC);
  13257. }
  13258. set blendDst(value) {
  13259. this._shaderValues.setInt(ShurikenParticleMaterial.BLEND_DST, value);
  13260. }
  13261. get blendDst() {
  13262. return this._shaderValues.getInt(ShurikenParticleMaterial.BLEND_DST);
  13263. }
  13264. set depthTest(value) {
  13265. this._shaderValues.setInt(ShurikenParticleMaterial.DEPTH_TEST, value);
  13266. }
  13267. get depthTest() {
  13268. return this._shaderValues.getInt(ShurikenParticleMaterial.DEPTH_TEST);
  13269. }
  13270. clone() {
  13271. var dest = new ShurikenParticleMaterial();
  13272. this.cloneTo(dest);
  13273. return dest;
  13274. }
  13275. }
  13276. ShurikenParticleMaterial.RENDERMODE_ALPHABLENDED = 0;
  13277. ShurikenParticleMaterial.RENDERMODE_ADDTIVE = 1;
  13278. ShurikenParticleMaterial.DIFFUSETEXTURE = Shader3D.propertyNameToID("u_texture");
  13279. ShurikenParticleMaterial.TINTCOLOR = Shader3D.propertyNameToID("u_Tintcolor");
  13280. ShurikenParticleMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  13281. ShurikenParticleMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  13282. ShurikenParticleMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  13283. ShurikenParticleMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  13284. ShurikenParticleMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  13285. ShurikenParticleMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  13286. ShurikenParticleMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  13287. ShurikenParticleMaterial.shaderDefines = null;
  13288. class ShuriKenParticle3DShaderDeclaration {
  13289. }
  13290. ShuriKenParticle3DShaderDeclaration.WORLDPOSITION = Shader3D.propertyNameToID("u_WorldPosition");
  13291. ShuriKenParticle3DShaderDeclaration.WORLDROTATION = Shader3D.propertyNameToID("u_WorldRotation");
  13292. ShuriKenParticle3DShaderDeclaration.POSITIONSCALE = Shader3D.propertyNameToID("u_PositionScale");
  13293. ShuriKenParticle3DShaderDeclaration.SIZESCALE = Shader3D.propertyNameToID("u_SizeScale");
  13294. ShuriKenParticle3DShaderDeclaration.SCALINGMODE = Shader3D.propertyNameToID("u_ScalingMode");
  13295. ShuriKenParticle3DShaderDeclaration.GRAVITY = Shader3D.propertyNameToID("u_Gravity");
  13296. ShuriKenParticle3DShaderDeclaration.THREEDSTARTROTATION = Shader3D.propertyNameToID("u_ThreeDStartRotation");
  13297. ShuriKenParticle3DShaderDeclaration.STRETCHEDBILLBOARDLENGTHSCALE = Shader3D.propertyNameToID("u_StretchedBillboardLengthScale");
  13298. ShuriKenParticle3DShaderDeclaration.STRETCHEDBILLBOARDSPEEDSCALE = Shader3D.propertyNameToID("u_StretchedBillboardSpeedScale");
  13299. ShuriKenParticle3DShaderDeclaration.SIMULATIONSPACE = Shader3D.propertyNameToID("u_SimulationSpace");
  13300. ShuriKenParticle3DShaderDeclaration.CURRENTTIME = Shader3D.propertyNameToID("u_CurrentTime");
  13301. ShuriKenParticle3DShaderDeclaration.VOLVELOCITYCONST = Shader3D.propertyNameToID("u_VOLVelocityConst");
  13302. ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTX = Shader3D.propertyNameToID("u_VOLVelocityGradientX");
  13303. ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTY = Shader3D.propertyNameToID("u_VOLVelocityGradientY");
  13304. ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTZ = Shader3D.propertyNameToID("u_VOLVelocityGradientZ");
  13305. ShuriKenParticle3DShaderDeclaration.VOLVELOCITYCONSTMAX = Shader3D.propertyNameToID("u_VOLVelocityConstMax");
  13306. ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTXMAX = Shader3D.propertyNameToID("u_VOLVelocityGradientMaxX");
  13307. ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTYMAX = Shader3D.propertyNameToID("u_VOLVelocityGradientMaxY");
  13308. ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTZMAX = Shader3D.propertyNameToID("u_VOLVelocityGradientMaxZ");
  13309. ShuriKenParticle3DShaderDeclaration.VOLSPACETYPE = Shader3D.propertyNameToID("u_VOLSpaceType");
  13310. ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTALPHAS = Shader3D.propertyNameToID("u_ColorOverLifeGradientAlphas");
  13311. ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTCOLORS = Shader3D.propertyNameToID("u_ColorOverLifeGradientColors");
  13312. ShuriKenParticle3DShaderDeclaration.MAXCOLOROVERLIFEGRADIENTALPHAS = Shader3D.propertyNameToID("u_MaxColorOverLifeGradientAlphas");
  13313. ShuriKenParticle3DShaderDeclaration.MAXCOLOROVERLIFEGRADIENTCOLORS = Shader3D.propertyNameToID("u_MaxColorOverLifeGradientColors");
  13314. ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENT = Shader3D.propertyNameToID("u_SOLSizeGradient");
  13315. ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTX = Shader3D.propertyNameToID("u_SOLSizeGradientX");
  13316. ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTY = Shader3D.propertyNameToID("u_SOLSizeGradientY");
  13317. ShuriKenParticle3DShaderDeclaration.SOLSizeGradientZ = Shader3D.propertyNameToID("u_SOLSizeGradientZ");
  13318. ShuriKenParticle3DShaderDeclaration.SOLSizeGradientMax = Shader3D.propertyNameToID("u_SOLSizeGradientMax");
  13319. ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTXMAX = Shader3D.propertyNameToID("u_SOLSizeGradientMaxX");
  13320. ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTYMAX = Shader3D.propertyNameToID("u_SOLSizeGradientMaxY");
  13321. ShuriKenParticle3DShaderDeclaration.SOLSizeGradientZMAX = Shader3D.propertyNameToID("u_SOLSizeGradientMaxZ");
  13322. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONST = Shader3D.propertyNameToID("u_ROLAngularVelocityConst");
  13323. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTSEPRARATE = Shader3D.propertyNameToID("u_ROLAngularVelocityConstSeprarate");
  13324. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENT = Shader3D.propertyNameToID("u_ROLAngularVelocityGradient");
  13325. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTX = Shader3D.propertyNameToID("u_ROLAngularVelocityGradientX");
  13326. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTY = Shader3D.propertyNameToID("u_ROLAngularVelocityGradientY");
  13327. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTZ = Shader3D.propertyNameToID("u_ROLAngularVelocityGradientZ");
  13328. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTMAX = Shader3D.propertyNameToID("u_ROLAngularVelocityConstMax");
  13329. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTMAXSEPRARATE = Shader3D.propertyNameToID("u_ROLAngularVelocityConstMaxSeprarate");
  13330. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTMAX = Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMax");
  13331. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTXMAX = Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMaxX");
  13332. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTYMAX = Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMaxY");
  13333. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTZMAX = Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMaxZ");
  13334. ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTWMAX = Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMaxW");
  13335. ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONCYCLES = Shader3D.propertyNameToID("u_TSACycles");
  13336. ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONSUBUVLENGTH = Shader3D.propertyNameToID("u_TSASubUVLength");
  13337. ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONGRADIENTUVS = Shader3D.propertyNameToID("u_TSAGradientUVs");
  13338. ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONGRADIENTMAXUVS = Shader3D.propertyNameToID("u_TSAMaxGradientUVs");
  13339. class ShurikenParticleRenderer extends BaseRender {
  13340. constructor(owner) {
  13341. super(owner);
  13342. this._finalGravity = new Vector3();
  13343. this._tempRotationMatrix = new Matrix4x4();
  13344. this._renderMode = 0;
  13345. this._mesh = null;
  13346. this.stretchedBillboardCameraSpeedScale = 0;
  13347. this.stretchedBillboardSpeedScale = 0;
  13348. this.stretchedBillboardLengthScale = 0;
  13349. this._defaultBoundBox = new BoundBox(new Vector3(), new Vector3());
  13350. this._renderMode = -1;
  13351. this.stretchedBillboardCameraSpeedScale = 0.0;
  13352. this.stretchedBillboardSpeedScale = 0.0;
  13353. this.stretchedBillboardLengthScale = 1.0;
  13354. this._supportOctree = false;
  13355. }
  13356. get renderMode() {
  13357. return this._renderMode;
  13358. }
  13359. get mesh() {
  13360. return this._mesh;
  13361. }
  13362. set mesh(value) {
  13363. if (this._mesh !== value) {
  13364. (this._mesh) && (this._mesh._removeReference());
  13365. this._mesh = value;
  13366. (value) && (value._addReference());
  13367. this._owner.particleSystem._initBufferDatas();
  13368. }
  13369. }
  13370. set renderMode(value) {
  13371. if (this._renderMode !== value) {
  13372. var defineDatas = this._shaderValues;
  13373. switch (this._renderMode) {
  13374. case 0:
  13375. defineDatas.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_BILLBOARD);
  13376. break;
  13377. case 1:
  13378. defineDatas.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD);
  13379. break;
  13380. case 2:
  13381. defineDatas.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD);
  13382. break;
  13383. case 3:
  13384. defineDatas.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD);
  13385. break;
  13386. case 4:
  13387. defineDatas.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_MESH);
  13388. break;
  13389. }
  13390. this._renderMode = value;
  13391. switch (value) {
  13392. case 0:
  13393. defineDatas.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_BILLBOARD);
  13394. break;
  13395. case 1:
  13396. defineDatas.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD);
  13397. break;
  13398. case 2:
  13399. defineDatas.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD);
  13400. break;
  13401. case 3:
  13402. defineDatas.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD);
  13403. break;
  13404. case 4:
  13405. defineDatas.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_MESH);
  13406. break;
  13407. default:
  13408. throw new Error("ShurikenParticleRender: unknown renderMode Value.");
  13409. }
  13410. this._owner.particleSystem._initBufferDatas();
  13411. }
  13412. }
  13413. _calculateBoundingBox() {
  13414. var min = this._bounds.getMin();
  13415. min.x = -Number.MAX_VALUE;
  13416. min.y = -Number.MAX_VALUE;
  13417. min.z = -Number.MAX_VALUE;
  13418. this._bounds.setMin(min);
  13419. var max = this._bounds.getMax();
  13420. max.x = Number.MAX_VALUE;
  13421. max.y = Number.MAX_VALUE;
  13422. max.z = Number.MAX_VALUE;
  13423. this._bounds.setMax(max);
  13424. if (Laya.Render.supportWebGLPlusCulling) {
  13425. var min = this._bounds.getMin();
  13426. var max = this._bounds.getMax();
  13427. var buffer = FrustumCulling._cullingBuffer;
  13428. buffer[this._cullingBufferIndex + 1] = min.x;
  13429. buffer[this._cullingBufferIndex + 2] = min.y;
  13430. buffer[this._cullingBufferIndex + 3] = min.z;
  13431. buffer[this._cullingBufferIndex + 4] = max.x;
  13432. buffer[this._cullingBufferIndex + 5] = max.y;
  13433. buffer[this._cullingBufferIndex + 6] = max.z;
  13434. }
  13435. }
  13436. _needRender(boundFrustum, context) {
  13437. if (boundFrustum) {
  13438. if (boundFrustum.intersects(this.bounds._getBoundBox())) {
  13439. if (this._owner.particleSystem.isAlive)
  13440. return true;
  13441. else
  13442. return false;
  13443. }
  13444. else {
  13445. return false;
  13446. }
  13447. }
  13448. else {
  13449. return true;
  13450. }
  13451. }
  13452. _renderUpdate(context, transfrom) {
  13453. var particleSystem = this._owner.particleSystem;
  13454. var sv = this._shaderValues;
  13455. var transform = this._owner.transform;
  13456. switch (particleSystem.simulationSpace) {
  13457. case 0:
  13458. break;
  13459. case 1:
  13460. sv.setVector3(ShuriKenParticle3DShaderDeclaration.WORLDPOSITION, transform.position);
  13461. sv.setQuaternion(ShuriKenParticle3DShaderDeclaration.WORLDROTATION, transform.rotation);
  13462. break;
  13463. default:
  13464. throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.");
  13465. }
  13466. switch (particleSystem.scaleMode) {
  13467. case 0:
  13468. var scale = transform.getWorldLossyScale();
  13469. sv.setVector3(ShuriKenParticle3DShaderDeclaration.POSITIONSCALE, scale);
  13470. sv.setVector3(ShuriKenParticle3DShaderDeclaration.SIZESCALE, scale);
  13471. break;
  13472. case 1:
  13473. var localScale = transform.localScale;
  13474. sv.setVector3(ShuriKenParticle3DShaderDeclaration.POSITIONSCALE, localScale);
  13475. sv.setVector3(ShuriKenParticle3DShaderDeclaration.SIZESCALE, localScale);
  13476. break;
  13477. case 2:
  13478. sv.setVector3(ShuriKenParticle3DShaderDeclaration.POSITIONSCALE, transform.getWorldLossyScale());
  13479. sv.setVector3(ShuriKenParticle3DShaderDeclaration.SIZESCALE, Vector3._ONE);
  13480. break;
  13481. }
  13482. Vector3.scale(Physics3DUtils.gravity, particleSystem.gravityModifier, this._finalGravity);
  13483. sv.setVector3(ShuriKenParticle3DShaderDeclaration.GRAVITY, this._finalGravity);
  13484. sv.setInt(ShuriKenParticle3DShaderDeclaration.SIMULATIONSPACE, particleSystem.simulationSpace);
  13485. sv.setBool(ShuriKenParticle3DShaderDeclaration.THREEDSTARTROTATION, particleSystem.threeDStartRotation);
  13486. sv.setInt(ShuriKenParticle3DShaderDeclaration.SCALINGMODE, particleSystem.scaleMode);
  13487. sv.setNumber(ShuriKenParticle3DShaderDeclaration.STRETCHEDBILLBOARDLENGTHSCALE, this.stretchedBillboardLengthScale);
  13488. sv.setNumber(ShuriKenParticle3DShaderDeclaration.STRETCHEDBILLBOARDSPEEDSCALE, this.stretchedBillboardSpeedScale);
  13489. sv.setNumber(ShuriKenParticle3DShaderDeclaration.CURRENTTIME, particleSystem._currentTime);
  13490. }
  13491. get bounds() {
  13492. if (this._boundsChange) {
  13493. this._calculateBoundingBox();
  13494. this._boundsChange = false;
  13495. }
  13496. return this._bounds;
  13497. }
  13498. _destroy() {
  13499. super._destroy();
  13500. (this._mesh) && (this._mesh._removeReference(), this._mesh = null);
  13501. }
  13502. }
  13503. class ShurikenParticleData {
  13504. constructor() {
  13505. }
  13506. static _getStartLifetimeFromGradient(startLifeTimeGradient, emissionTime) {
  13507. for (var i = 1, n = startLifeTimeGradient.gradientCount; i < n; i++) {
  13508. var key = startLifeTimeGradient.getKeyByIndex(i);
  13509. if (key >= emissionTime) {
  13510. var lastKey = startLifeTimeGradient.getKeyByIndex(i - 1);
  13511. var age = (emissionTime - lastKey) / (key - lastKey);
  13512. return Laya.MathUtil.lerp(startLifeTimeGradient.getValueByIndex(i - 1), startLifeTimeGradient.getValueByIndex(i), age);
  13513. }
  13514. }
  13515. throw new Error("ShurikenParticleData: can't get value foam startLifeTimeGradient.");
  13516. }
  13517. static _randomInvertRoationArray(rotatonE, outE, randomizeRotationDirection, rand, randomSeeds) {
  13518. var randDic;
  13519. if (rand) {
  13520. rand.seed = randomSeeds[6];
  13521. randDic = rand.getFloat();
  13522. randomSeeds[6] = rand.seed;
  13523. }
  13524. else {
  13525. randDic = Math.random();
  13526. }
  13527. if (randDic < randomizeRotationDirection) {
  13528. outE.x = -rotatonE.x;
  13529. outE.y = -rotatonE.y;
  13530. outE.z = -rotatonE.z;
  13531. }
  13532. else {
  13533. outE.x = rotatonE.x;
  13534. outE.y = rotatonE.y;
  13535. outE.z = rotatonE.z;
  13536. }
  13537. }
  13538. static _randomInvertRoation(rotaton, randomizeRotationDirection, rand, randomSeeds) {
  13539. var randDic;
  13540. if (rand) {
  13541. rand.seed = randomSeeds[6];
  13542. randDic = rand.getFloat();
  13543. randomSeeds[6] = rand.seed;
  13544. }
  13545. else {
  13546. randDic = Math.random();
  13547. }
  13548. if (randDic < randomizeRotationDirection)
  13549. rotaton = -rotaton;
  13550. return rotaton;
  13551. }
  13552. static create(particleSystem, particleRender, transform) {
  13553. var autoRandomSeed = particleSystem.autoRandomSeed;
  13554. var rand = particleSystem._rand;
  13555. var randomSeeds = particleSystem._randomSeeds;
  13556. switch (particleSystem.startColorType) {
  13557. case 0:
  13558. var constantStartColor = particleSystem.startColorConstant;
  13559. ShurikenParticleData.startColor.x = constantStartColor.x;
  13560. ShurikenParticleData.startColor.y = constantStartColor.y;
  13561. ShurikenParticleData.startColor.z = constantStartColor.z;
  13562. ShurikenParticleData.startColor.w = constantStartColor.w;
  13563. break;
  13564. case 2:
  13565. if (autoRandomSeed) {
  13566. Vector4.lerp(particleSystem.startColorConstantMin, particleSystem.startColorConstantMax, Math.random(), ShurikenParticleData.startColor);
  13567. }
  13568. else {
  13569. rand.seed = randomSeeds[3];
  13570. Vector4.lerp(particleSystem.startColorConstantMin, particleSystem.startColorConstantMax, rand.getFloat(), ShurikenParticleData.startColor);
  13571. randomSeeds[3] = rand.seed;
  13572. }
  13573. break;
  13574. }
  13575. var colorOverLifetime = particleSystem.colorOverLifetime;
  13576. if (colorOverLifetime && colorOverLifetime.enbale) {
  13577. var color = colorOverLifetime.color;
  13578. switch (color.type) {
  13579. case 0:
  13580. ShurikenParticleData.startColor.x = ShurikenParticleData.startColor.x * color.constant.x;
  13581. ShurikenParticleData.startColor.y = ShurikenParticleData.startColor.y * color.constant.y;
  13582. ShurikenParticleData.startColor.z = ShurikenParticleData.startColor.z * color.constant.z;
  13583. ShurikenParticleData.startColor.w = ShurikenParticleData.startColor.w * color.constant.w;
  13584. break;
  13585. case 2:
  13586. var colorRandom;
  13587. if (autoRandomSeed) {
  13588. colorRandom = Math.random();
  13589. }
  13590. else {
  13591. rand.seed = randomSeeds[10];
  13592. colorRandom = rand.getFloat();
  13593. randomSeeds[10] = rand.seed;
  13594. }
  13595. var minConstantColor = color.constantMin;
  13596. var maxConstantColor = color.constantMax;
  13597. ShurikenParticleData.startColor.x = ShurikenParticleData.startColor.x * Laya.MathUtil.lerp(minConstantColor.x, maxConstantColor.x, colorRandom);
  13598. ShurikenParticleData.startColor.y = ShurikenParticleData.startColor.y * Laya.MathUtil.lerp(minConstantColor.y, maxConstantColor.y, colorRandom);
  13599. ShurikenParticleData.startColor.z = ShurikenParticleData.startColor.z * Laya.MathUtil.lerp(minConstantColor.z, maxConstantColor.z, colorRandom);
  13600. ShurikenParticleData.startColor.w = ShurikenParticleData.startColor.w * Laya.MathUtil.lerp(minConstantColor.w, maxConstantColor.w, colorRandom);
  13601. break;
  13602. }
  13603. }
  13604. var particleSize = ShurikenParticleData.startSize;
  13605. switch (particleSystem.startSizeType) {
  13606. case 0:
  13607. if (particleSystem.threeDStartSize) {
  13608. var startSizeConstantSeparate = particleSystem.startSizeConstantSeparate;
  13609. particleSize[0] = startSizeConstantSeparate.x;
  13610. particleSize[1] = startSizeConstantSeparate.y;
  13611. particleSize[2] = startSizeConstantSeparate.z;
  13612. }
  13613. else {
  13614. particleSize[0] = particleSize[1] = particleSize[2] = particleSystem.startSizeConstant;
  13615. }
  13616. break;
  13617. case 2:
  13618. if (particleSystem.threeDStartSize) {
  13619. var startSizeConstantMinSeparate = particleSystem.startSizeConstantMinSeparate;
  13620. var startSizeConstantMaxSeparate = particleSystem.startSizeConstantMaxSeparate;
  13621. if (autoRandomSeed) {
  13622. particleSize[0] = Laya.MathUtil.lerp(startSizeConstantMinSeparate.x, startSizeConstantMaxSeparate.x, Math.random());
  13623. particleSize[1] = Laya.MathUtil.lerp(startSizeConstantMinSeparate.y, startSizeConstantMaxSeparate.y, Math.random());
  13624. particleSize[2] = Laya.MathUtil.lerp(startSizeConstantMinSeparate.z, startSizeConstantMaxSeparate.z, Math.random());
  13625. }
  13626. else {
  13627. rand.seed = randomSeeds[4];
  13628. particleSize[0] = Laya.MathUtil.lerp(startSizeConstantMinSeparate.x, startSizeConstantMaxSeparate.x, rand.getFloat());
  13629. particleSize[1] = Laya.MathUtil.lerp(startSizeConstantMinSeparate.y, startSizeConstantMaxSeparate.y, rand.getFloat());
  13630. particleSize[2] = Laya.MathUtil.lerp(startSizeConstantMinSeparate.z, startSizeConstantMaxSeparate.z, rand.getFloat());
  13631. randomSeeds[4] = rand.seed;
  13632. }
  13633. }
  13634. else {
  13635. if (autoRandomSeed) {
  13636. particleSize[0] = particleSize[1] = particleSize[2] = Laya.MathUtil.lerp(particleSystem.startSizeConstantMin, particleSystem.startSizeConstantMax, Math.random());
  13637. }
  13638. else {
  13639. rand.seed = randomSeeds[4];
  13640. particleSize[0] = particleSize[1] = particleSize[2] = Laya.MathUtil.lerp(particleSystem.startSizeConstantMin, particleSystem.startSizeConstantMax, rand.getFloat());
  13641. randomSeeds[4] = rand.seed;
  13642. }
  13643. }
  13644. break;
  13645. }
  13646. var sizeOverLifetime = particleSystem.sizeOverLifetime;
  13647. if (sizeOverLifetime && sizeOverLifetime.enbale && sizeOverLifetime.size.type === 1) {
  13648. var size = sizeOverLifetime.size;
  13649. if (size.separateAxes) {
  13650. if (autoRandomSeed) {
  13651. particleSize[0] = particleSize[0] * Laya.MathUtil.lerp(size.constantMinSeparate.x, size.constantMaxSeparate.x, Math.random());
  13652. particleSize[1] = particleSize[1] * Laya.MathUtil.lerp(size.constantMinSeparate.y, size.constantMaxSeparate.y, Math.random());
  13653. particleSize[2] = particleSize[2] * Laya.MathUtil.lerp(size.constantMinSeparate.z, size.constantMaxSeparate.z, Math.random());
  13654. }
  13655. else {
  13656. rand.seed = randomSeeds[11];
  13657. particleSize[0] = particleSize[0] * Laya.MathUtil.lerp(size.constantMinSeparate.x, size.constantMaxSeparate.x, rand.getFloat());
  13658. particleSize[1] = particleSize[1] * Laya.MathUtil.lerp(size.constantMinSeparate.y, size.constantMaxSeparate.y, rand.getFloat());
  13659. particleSize[2] = particleSize[2] * Laya.MathUtil.lerp(size.constantMinSeparate.z, size.constantMaxSeparate.z, rand.getFloat());
  13660. randomSeeds[11] = rand.seed;
  13661. }
  13662. }
  13663. else {
  13664. var randomSize;
  13665. if (autoRandomSeed) {
  13666. randomSize = Laya.MathUtil.lerp(size.constantMin, size.constantMax, Math.random());
  13667. }
  13668. else {
  13669. rand.seed = randomSeeds[11];
  13670. randomSize = Laya.MathUtil.lerp(size.constantMin, size.constantMax, rand.getFloat());
  13671. randomSeeds[11] = rand.seed;
  13672. }
  13673. particleSize[0] = particleSize[0] * randomSize;
  13674. particleSize[1] = particleSize[1] * randomSize;
  13675. particleSize[2] = particleSize[2] * randomSize;
  13676. }
  13677. }
  13678. var renderMode = particleRender.renderMode;
  13679. if (renderMode !== 1) {
  13680. switch (particleSystem.startRotationType) {
  13681. case 0:
  13682. if (particleSystem.threeDStartRotation) {
  13683. var startRotationConstantSeparate = particleSystem.startRotationConstantSeparate;
  13684. var randomRotationE = ShurikenParticleData._tempVector30;
  13685. ShurikenParticleData._randomInvertRoationArray(startRotationConstantSeparate, randomRotationE, particleSystem.randomizeRotationDirection, autoRandomSeed ? null : rand, randomSeeds);
  13686. ShurikenParticleData.startRotation[0] = randomRotationE.x;
  13687. ShurikenParticleData.startRotation[1] = randomRotationE.y;
  13688. if (renderMode !== 4)
  13689. ShurikenParticleData.startRotation[2] = -randomRotationE.z;
  13690. else
  13691. ShurikenParticleData.startRotation[2] = randomRotationE.z;
  13692. }
  13693. else {
  13694. ShurikenParticleData.startRotation[0] = ShurikenParticleData._randomInvertRoation(particleSystem.startRotationConstant, particleSystem.randomizeRotationDirection, autoRandomSeed ? null : rand, randomSeeds);
  13695. ShurikenParticleData.startRotation[1] = 0;
  13696. ShurikenParticleData.startRotation[2] = 0;
  13697. }
  13698. break;
  13699. case 2:
  13700. if (particleSystem.threeDStartRotation) {
  13701. var startRotationConstantMinSeparate = particleSystem.startRotationConstantMinSeparate;
  13702. var startRotationConstantMaxSeparate = particleSystem.startRotationConstantMaxSeparate;
  13703. var lerpRoationE = ShurikenParticleData._tempVector30;
  13704. if (autoRandomSeed) {
  13705. lerpRoationE.x = Laya.MathUtil.lerp(startRotationConstantMinSeparate.x, startRotationConstantMaxSeparate.x, Math.random());
  13706. lerpRoationE.y = Laya.MathUtil.lerp(startRotationConstantMinSeparate.y, startRotationConstantMaxSeparate.y, Math.random());
  13707. lerpRoationE.z = Laya.MathUtil.lerp(startRotationConstantMinSeparate.z, startRotationConstantMaxSeparate.z, Math.random());
  13708. }
  13709. else {
  13710. rand.seed = randomSeeds[5];
  13711. lerpRoationE.x = Laya.MathUtil.lerp(startRotationConstantMinSeparate.x, startRotationConstantMaxSeparate.x, rand.getFloat());
  13712. lerpRoationE.y = Laya.MathUtil.lerp(startRotationConstantMinSeparate.y, startRotationConstantMaxSeparate.y, rand.getFloat());
  13713. lerpRoationE.z = Laya.MathUtil.lerp(startRotationConstantMinSeparate.z, startRotationConstantMaxSeparate.z, rand.getFloat());
  13714. randomSeeds[5] = rand.seed;
  13715. }
  13716. ShurikenParticleData._randomInvertRoationArray(lerpRoationE, lerpRoationE, particleSystem.randomizeRotationDirection, autoRandomSeed ? null : rand, randomSeeds);
  13717. ShurikenParticleData.startRotation[0] = lerpRoationE.x;
  13718. ShurikenParticleData.startRotation[1] = lerpRoationE.y;
  13719. if (renderMode !== 4)
  13720. ShurikenParticleData.startRotation[2] = -lerpRoationE.z;
  13721. else
  13722. ShurikenParticleData.startRotation[2] = lerpRoationE.z;
  13723. }
  13724. else {
  13725. if (autoRandomSeed) {
  13726. ShurikenParticleData.startRotation[0] = ShurikenParticleData._randomInvertRoation(Laya.MathUtil.lerp(particleSystem.startRotationConstantMin, particleSystem.startRotationConstantMax, Math.random()), particleSystem.randomizeRotationDirection, autoRandomSeed ? null : rand, randomSeeds);
  13727. }
  13728. else {
  13729. rand.seed = randomSeeds[5];
  13730. ShurikenParticleData.startRotation[0] = ShurikenParticleData._randomInvertRoation(Laya.MathUtil.lerp(particleSystem.startRotationConstantMin, particleSystem.startRotationConstantMax, rand.getFloat()), particleSystem.randomizeRotationDirection, autoRandomSeed ? null : rand, randomSeeds);
  13731. randomSeeds[5] = rand.seed;
  13732. }
  13733. }
  13734. break;
  13735. }
  13736. }
  13737. switch (particleSystem.startLifetimeType) {
  13738. case 0:
  13739. ShurikenParticleData.startLifeTime = particleSystem.startLifetimeConstant;
  13740. break;
  13741. case 1:
  13742. ShurikenParticleData.startLifeTime = ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradient, particleSystem.emissionTime);
  13743. break;
  13744. case 2:
  13745. if (autoRandomSeed) {
  13746. ShurikenParticleData.startLifeTime = Laya.MathUtil.lerp(particleSystem.startLifetimeConstantMin, particleSystem.startLifetimeConstantMax, Math.random());
  13747. }
  13748. else {
  13749. rand.seed = randomSeeds[7];
  13750. ShurikenParticleData.startLifeTime = Laya.MathUtil.lerp(particleSystem.startLifetimeConstantMin, particleSystem.startLifetimeConstantMax, rand.getFloat());
  13751. randomSeeds[7] = rand.seed;
  13752. }
  13753. break;
  13754. case 3:
  13755. var emissionTime = particleSystem.emissionTime;
  13756. if (autoRandomSeed) {
  13757. ShurikenParticleData.startLifeTime = Laya.MathUtil.lerp(ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradientMin, emissionTime), ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradientMax, emissionTime), Math.random());
  13758. }
  13759. else {
  13760. rand.seed = randomSeeds[7];
  13761. ShurikenParticleData.startLifeTime = Laya.MathUtil.lerp(ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradientMin, emissionTime), ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradientMax, emissionTime), rand.getFloat());
  13762. randomSeeds[7] = rand.seed;
  13763. }
  13764. break;
  13765. }
  13766. switch (particleSystem.startSpeedType) {
  13767. case 0:
  13768. ShurikenParticleData.startSpeed = particleSystem.startSpeedConstant;
  13769. break;
  13770. case 2:
  13771. if (autoRandomSeed) {
  13772. ShurikenParticleData.startSpeed = Laya.MathUtil.lerp(particleSystem.startSpeedConstantMin, particleSystem.startSpeedConstantMax, Math.random());
  13773. }
  13774. else {
  13775. rand.seed = randomSeeds[8];
  13776. ShurikenParticleData.startSpeed = Laya.MathUtil.lerp(particleSystem.startSpeedConstantMin, particleSystem.startSpeedConstantMax, rand.getFloat());
  13777. randomSeeds[8] = rand.seed;
  13778. }
  13779. break;
  13780. }
  13781. var textureSheetAnimation = particleSystem.textureSheetAnimation;
  13782. var enableSheetAnimation = textureSheetAnimation && textureSheetAnimation.enable;
  13783. if (enableSheetAnimation) {
  13784. var title = textureSheetAnimation.tiles;
  13785. var titleX = title.x, titleY = title.y;
  13786. var subU = 1.0 / titleX, subV = 1.0 / titleY;
  13787. var startFrameCount;
  13788. var startFrame = textureSheetAnimation.startFrame;
  13789. switch (startFrame.type) {
  13790. case 0:
  13791. startFrameCount = startFrame.constant;
  13792. break;
  13793. case 1:
  13794. if (autoRandomSeed) {
  13795. startFrameCount = Laya.MathUtil.lerp(startFrame.constantMin, startFrame.constantMax, Math.random());
  13796. }
  13797. else {
  13798. rand.seed = randomSeeds[14];
  13799. startFrameCount = Laya.MathUtil.lerp(startFrame.constantMin, startFrame.constantMax, rand.getFloat());
  13800. randomSeeds[14] = rand.seed;
  13801. }
  13802. break;
  13803. }
  13804. var frame = textureSheetAnimation.frame;
  13805. switch (frame.type) {
  13806. case 0:
  13807. startFrameCount += frame.constant;
  13808. break;
  13809. case 2:
  13810. if (autoRandomSeed) {
  13811. startFrameCount += Laya.MathUtil.lerp(frame.constantMin, frame.constantMax, Math.random());
  13812. }
  13813. else {
  13814. rand.seed = randomSeeds[15];
  13815. startFrameCount += Laya.MathUtil.lerp(frame.constantMin, frame.constantMax, rand.getFloat());
  13816. randomSeeds[15] = rand.seed;
  13817. }
  13818. break;
  13819. }
  13820. var startRow = 0;
  13821. switch (textureSheetAnimation.type) {
  13822. case 0:
  13823. startRow = Math.floor(startFrameCount / titleX);
  13824. break;
  13825. case 1:
  13826. if (textureSheetAnimation.randomRow) {
  13827. if (autoRandomSeed) {
  13828. startRow = Math.floor(Math.random() * titleY);
  13829. }
  13830. else {
  13831. rand.seed = randomSeeds[13];
  13832. startRow = Math.floor(rand.getFloat() * titleY);
  13833. randomSeeds[13] = rand.seed;
  13834. }
  13835. }
  13836. else {
  13837. startRow = textureSheetAnimation.rowIndex;
  13838. }
  13839. break;
  13840. }
  13841. var startCol = Math.floor(startFrameCount % titleX);
  13842. ShurikenParticleData.startUVInfo = ShurikenParticleData.startUVInfo;
  13843. ShurikenParticleData.startUVInfo[0] = subU;
  13844. ShurikenParticleData.startUVInfo[1] = subV;
  13845. ShurikenParticleData.startUVInfo[2] = startCol * subU;
  13846. ShurikenParticleData.startUVInfo[3] = startRow * subV;
  13847. }
  13848. else {
  13849. ShurikenParticleData.startUVInfo = ShurikenParticleData.startUVInfo;
  13850. ShurikenParticleData.startUVInfo[0] = 1.0;
  13851. ShurikenParticleData.startUVInfo[1] = 1.0;
  13852. ShurikenParticleData.startUVInfo[2] = 0.0;
  13853. ShurikenParticleData.startUVInfo[3] = 0.0;
  13854. }
  13855. switch (particleSystem.simulationSpace) {
  13856. case 0:
  13857. var position = transform.position;
  13858. ShurikenParticleData.simulationWorldPostion[0] = position.x;
  13859. ShurikenParticleData.simulationWorldPostion[1] = position.y;
  13860. ShurikenParticleData.simulationWorldPostion[2] = position.z;
  13861. var rotation = transform.rotation;
  13862. ShurikenParticleData.simulationWorldRotation[0] = rotation.x;
  13863. ShurikenParticleData.simulationWorldRotation[1] = rotation.y;
  13864. ShurikenParticleData.simulationWorldRotation[2] = rotation.z;
  13865. ShurikenParticleData.simulationWorldRotation[3] = rotation.w;
  13866. break;
  13867. case 1:
  13868. break;
  13869. default:
  13870. throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.");
  13871. break;
  13872. }
  13873. }
  13874. }
  13875. ShurikenParticleData._tempVector30 = new Vector3();
  13876. ShurikenParticleData._tempQuaternion = new Quaternion();
  13877. ShurikenParticleData.startColor = new Vector4();
  13878. ShurikenParticleData.startSize = new Float32Array(3);
  13879. ShurikenParticleData.startRotation = new Float32Array(3);
  13880. ShurikenParticleData.startUVInfo = new Float32Array(4);
  13881. ShurikenParticleData.simulationWorldPostion = new Float32Array(3);
  13882. ShurikenParticleData.simulationWorldRotation = new Float32Array(4);
  13883. class Emission {
  13884. set emissionRate(value) {
  13885. if (value < 0)
  13886. throw new Error("ParticleBaseShape:emissionRate value must large or equal than 0.");
  13887. this._emissionRate = value;
  13888. }
  13889. get emissionRate() {
  13890. return this._emissionRate;
  13891. }
  13892. get destroyed() {
  13893. return this._destroyed;
  13894. }
  13895. constructor() {
  13896. this._destroyed = false;
  13897. this.emissionRate = 10;
  13898. this._bursts = [];
  13899. }
  13900. destroy() {
  13901. this._bursts = null;
  13902. this._destroyed = true;
  13903. }
  13904. getBurstsCount() {
  13905. return this._bursts.length;
  13906. }
  13907. getBurstByIndex(index) {
  13908. return this._bursts[index];
  13909. }
  13910. addBurst(burst) {
  13911. var burstsCount = this._bursts.length;
  13912. if (burstsCount > 0)
  13913. for (var i = 0; i < burstsCount; i++) {
  13914. if (this._bursts[i].time > burst.time)
  13915. this._bursts.splice(i, 0, burst);
  13916. }
  13917. this._bursts.push(burst);
  13918. }
  13919. removeBurst(burst) {
  13920. var index = this._bursts.indexOf(burst);
  13921. if (index !== -1) {
  13922. this._bursts.splice(index, 1);
  13923. }
  13924. }
  13925. removeBurstByIndex(index) {
  13926. this._bursts.splice(index, 1);
  13927. }
  13928. clearBurst() {
  13929. this._bursts.length = 0;
  13930. }
  13931. cloneTo(destObject) {
  13932. var destEmission = destObject;
  13933. var destBursts = destEmission._bursts;
  13934. destBursts.length = this._bursts.length;
  13935. for (var i = 0, n = this._bursts.length; i < n; i++) {
  13936. var destBurst = destBursts[i];
  13937. if (destBurst)
  13938. this._bursts[i].cloneTo(destBurst);
  13939. else
  13940. destBursts[i] = this._bursts[i].clone();
  13941. }
  13942. destEmission._emissionRate = this._emissionRate;
  13943. destEmission.enbale = this.enbale;
  13944. }
  13945. clone() {
  13946. var destEmission = new Emission();
  13947. this.cloneTo(destEmission);
  13948. return destEmission;
  13949. }
  13950. }
  13951. class GradientDataNumber {
  13952. constructor() {
  13953. this._currentLength = 0;
  13954. this._elements = new Float32Array(8);
  13955. }
  13956. get gradientCount() {
  13957. return this._currentLength / 2;
  13958. }
  13959. add(key, value) {
  13960. if (this._currentLength < 8) {
  13961. if ((this._currentLength === 6) && ((key !== 1))) {
  13962. key = 1;
  13963. console.log("GradientDataNumber warning:the forth key is be force set to 1.");
  13964. }
  13965. this._elements[this._currentLength++] = key;
  13966. this._elements[this._currentLength++] = value;
  13967. }
  13968. else {
  13969. console.log("GradientDataNumber warning:data count must lessEqual than 4");
  13970. }
  13971. }
  13972. getKeyByIndex(index) {
  13973. return this._elements[index * 2];
  13974. }
  13975. getValueByIndex(index) {
  13976. return this._elements[index * 2 + 1];
  13977. }
  13978. getAverageValue() {
  13979. var total = 0;
  13980. for (var i = 0, n = this._currentLength - 2; i < n; i += 2) {
  13981. var subValue = this._elements[i + 1];
  13982. subValue += this._elements[i + 3];
  13983. subValue = subValue * (this._elements[i + 2] - this._elements[i]);
  13984. }
  13985. return total / 2;
  13986. }
  13987. cloneTo(destObject) {
  13988. var destGradientDataNumber = destObject;
  13989. destGradientDataNumber._currentLength = this._currentLength;
  13990. var destElements = destGradientDataNumber._elements;
  13991. for (var i = 0, n = this._elements.length; i < n; i++)
  13992. destElements[i] = this._elements[i];
  13993. }
  13994. clone() {
  13995. var destGradientDataNumber = new GradientDataNumber();
  13996. this.cloneTo(destGradientDataNumber);
  13997. return destGradientDataNumber;
  13998. }
  13999. }
  14000. class VertexShuriKenParticle {
  14001. constructor() {
  14002. }
  14003. }
  14004. VertexShuriKenParticle.PARTICLE_CORNERTEXTURECOORDINATE0 = 0;
  14005. VertexShuriKenParticle.PARTICLE_POSITION0 = 1;
  14006. VertexShuriKenParticle.PARTICLE_COLOR0 = 2;
  14007. VertexShuriKenParticle.PARTICLE_TEXTURECOORDINATE0 = 3;
  14008. VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME = 4;
  14009. VertexShuriKenParticle.PARTICLE_DIRECTIONTIME = 5;
  14010. VertexShuriKenParticle.PARTICLE_STARTCOLOR0 = 6;
  14011. VertexShuriKenParticle.PARTICLE_ENDCOLOR0 = 7;
  14012. VertexShuriKenParticle.PARTICLE_STARTSIZE = 8;
  14013. VertexShuriKenParticle.PARTICLE_STARTROTATION = 9;
  14014. VertexShuriKenParticle.PARTICLE_STARTSPEED = 10;
  14015. VertexShuriKenParticle.PARTICLE_RANDOM0 = 11;
  14016. VertexShuriKenParticle.PARTICLE_RANDOM1 = 12;
  14017. VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION = 13;
  14018. VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION = 14;
  14019. class VertexShurikenParticleBillboard extends VertexShuriKenParticle {
  14020. static get vertexDeclaration() {
  14021. return VertexShurikenParticleBillboard._vertexDeclaration;
  14022. }
  14023. static __init__() {
  14024. VertexShurikenParticleBillboard._vertexDeclaration = new VertexDeclaration(152, [new VertexElement(0, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_CORNERTEXTURECOORDINATE0),
  14025. new VertexElement(16, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME),
  14026. new VertexElement(32, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_DIRECTIONTIME),
  14027. new VertexElement(48, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_STARTCOLOR0),
  14028. new VertexElement(64, VertexElementFormat.Vector3, VertexShuriKenParticle.PARTICLE_STARTSIZE),
  14029. new VertexElement(76, VertexElementFormat.Vector3, VertexShuriKenParticle.PARTICLE_STARTROTATION),
  14030. new VertexElement(88, VertexElementFormat.Single, VertexShuriKenParticle.PARTICLE_STARTSPEED),
  14031. new VertexElement(92, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_RANDOM0),
  14032. new VertexElement(108, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_RANDOM1),
  14033. new VertexElement(124, VertexElementFormat.Vector3, VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION),
  14034. new VertexElement(136, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION)]);
  14035. }
  14036. get cornerTextureCoordinate() {
  14037. return this._cornerTextureCoordinate;
  14038. }
  14039. get positionStartLifeTime() {
  14040. return this._positionStartLifeTime;
  14041. }
  14042. get velocity() {
  14043. return this._velocity;
  14044. }
  14045. get startColor() {
  14046. return this._startColor;
  14047. }
  14048. get startSize() {
  14049. return this._startSize;
  14050. }
  14051. get startRotation0() {
  14052. return this._startRotation0;
  14053. }
  14054. get startRotation1() {
  14055. return this._startRotation1;
  14056. }
  14057. get startRotation2() {
  14058. return this._startRotation2;
  14059. }
  14060. get startLifeTime() {
  14061. return this._startLifeTime;
  14062. }
  14063. get time() {
  14064. return this._time;
  14065. }
  14066. get startSpeed() {
  14067. return this._startSpeed;
  14068. }
  14069. get random0() {
  14070. return this._randoms0;
  14071. }
  14072. get random1() {
  14073. return this._randoms1;
  14074. }
  14075. get simulationWorldPostion() {
  14076. return this._simulationWorldPostion;
  14077. }
  14078. constructor(cornerTextureCoordinate, positionStartLifeTime, velocity, startColor, startSize, startRotation0, startRotation1, startRotation2, ageAddScale, time, startSpeed, randoms0, randoms1, simulationWorldPostion) {
  14079. super();
  14080. this._cornerTextureCoordinate = cornerTextureCoordinate;
  14081. this._positionStartLifeTime = positionStartLifeTime;
  14082. this._velocity = velocity;
  14083. this._startColor = startColor;
  14084. this._startSize = startSize;
  14085. this._startRotation0 = startRotation0;
  14086. this._startRotation1 = startRotation1;
  14087. this._startRotation2 = startRotation2;
  14088. this._startLifeTime = ageAddScale;
  14089. this._time = time;
  14090. this._startSpeed = startSpeed;
  14091. this._randoms0 = this.random0;
  14092. this._randoms1 = this.random1;
  14093. this._simulationWorldPostion = simulationWorldPostion;
  14094. }
  14095. }
  14096. class VertexShurikenParticleMesh extends VertexShuriKenParticle {
  14097. static __init__() {
  14098. VertexShurikenParticleMesh._vertexDeclaration = new VertexDeclaration(172, [new VertexElement(0, VertexElementFormat.Vector3, VertexShuriKenParticle.PARTICLE_POSITION0),
  14099. new VertexElement(12, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_COLOR0),
  14100. new VertexElement(28, VertexElementFormat.Vector2, VertexShuriKenParticle.PARTICLE_TEXTURECOORDINATE0),
  14101. new VertexElement(36, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME),
  14102. new VertexElement(52, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_DIRECTIONTIME),
  14103. new VertexElement(68, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_STARTCOLOR0),
  14104. new VertexElement(84, VertexElementFormat.Vector3, VertexShuriKenParticle.PARTICLE_STARTSIZE),
  14105. new VertexElement(96, VertexElementFormat.Vector3, VertexShuriKenParticle.PARTICLE_STARTROTATION),
  14106. new VertexElement(108, VertexElementFormat.Single, VertexShuriKenParticle.PARTICLE_STARTSPEED),
  14107. new VertexElement(112, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_RANDOM0),
  14108. new VertexElement(128, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_RANDOM1),
  14109. new VertexElement(144, VertexElementFormat.Vector3, VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION),
  14110. new VertexElement(156, VertexElementFormat.Vector4, VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION)]);
  14111. }
  14112. static get vertexDeclaration() {
  14113. return VertexShurikenParticleMesh._vertexDeclaration;
  14114. }
  14115. get cornerTextureCoordinate() {
  14116. return this._cornerTextureCoordinate;
  14117. }
  14118. get position() {
  14119. return this._positionStartLifeTime;
  14120. }
  14121. get velocity() {
  14122. return this._velocity;
  14123. }
  14124. get startColor() {
  14125. return this._startColor;
  14126. }
  14127. get startSize() {
  14128. return this._startSize;
  14129. }
  14130. get startRotation0() {
  14131. return this._startRotation0;
  14132. }
  14133. get startRotation1() {
  14134. return this._startRotation1;
  14135. }
  14136. get startRotation2() {
  14137. return this._startRotation2;
  14138. }
  14139. get startLifeTime() {
  14140. return this._startLifeTime;
  14141. }
  14142. get time() {
  14143. return this._time;
  14144. }
  14145. get startSpeed() {
  14146. return this._startSpeed;
  14147. }
  14148. get random0() {
  14149. return this._randoms0;
  14150. }
  14151. get random1() {
  14152. return this._randoms1;
  14153. }
  14154. get simulationWorldPostion() {
  14155. return this._simulationWorldPostion;
  14156. }
  14157. constructor(cornerTextureCoordinate, positionStartLifeTime, velocity, startColor, startSize, startRotation0, startRotation1, startRotation2, ageAddScale, time, startSpeed, randoms0, randoms1, simulationWorldPostion) {
  14158. super();
  14159. this._cornerTextureCoordinate = cornerTextureCoordinate;
  14160. this._positionStartLifeTime = positionStartLifeTime;
  14161. this._velocity = velocity;
  14162. this._startColor = startColor;
  14163. this._startSize = startSize;
  14164. this._startRotation0 = startRotation0;
  14165. this._startRotation1 = startRotation1;
  14166. this._startRotation2 = startRotation2;
  14167. this._startLifeTime = ageAddScale;
  14168. this._time = time;
  14169. this._startSpeed = startSpeed;
  14170. this._randoms0 = this.random0;
  14171. this._randoms1 = this.random1;
  14172. this._simulationWorldPostion = simulationWorldPostion;
  14173. }
  14174. }
  14175. class Rand {
  14176. constructor(seed) {
  14177. this._temp = new Uint32Array(1);
  14178. this.seeds = new Uint32Array(4);
  14179. this.seeds[0] = seed;
  14180. this.seeds[1] = this.seeds[0] * 0x6C078965 + 1;
  14181. this.seeds[2] = this.seeds[1] * 0x6C078965 + 1;
  14182. this.seeds[3] = this.seeds[2] * 0x6C078965 + 1;
  14183. }
  14184. static getFloatFromInt(v) {
  14185. return (v & 0x007FFFFF) * (1.0 / 8388607.0);
  14186. }
  14187. static getByteFromInt(v) {
  14188. return (v & 0x007FFFFF) >>> 15;
  14189. }
  14190. get seed() {
  14191. return this.seeds[0];
  14192. }
  14193. set seed(seed) {
  14194. this.seeds[0] = seed;
  14195. this.seeds[1] = this.seeds[0] * 0x6C078965 + 1;
  14196. this.seeds[2] = this.seeds[1] * 0x6C078965 + 1;
  14197. this.seeds[3] = this.seeds[2] * 0x6C078965 + 1;
  14198. }
  14199. getUint() {
  14200. this._temp[0] = this.seeds[0] ^ (this.seeds[0] << 11);
  14201. this.seeds[0] = this.seeds[1];
  14202. this.seeds[1] = this.seeds[2];
  14203. this.seeds[2] = this.seeds[3];
  14204. this.seeds[3] = (this.seeds[3] ^ (this.seeds[3] >>> 19)) ^ (this._temp[0] ^ (this._temp[0] >>> 8));
  14205. return this.seeds[3];
  14206. }
  14207. getFloat() {
  14208. this.getUint();
  14209. return (this.seeds[3] & 0x007FFFFF) * (1.0 / 8388607.0);
  14210. }
  14211. getSignedFloat() {
  14212. return this.getFloat() * 2.0 - 1.0;
  14213. }
  14214. }
  14215. class ShurikenParticleSystem extends GeometryElement {
  14216. constructor(owner) {
  14217. super();
  14218. this._tempRotationMatrix = new Matrix4x4();
  14219. this._boundingSphere = null;
  14220. this._boundingBox = null;
  14221. this._boundingBoxCorners = null;
  14222. this._owner = null;
  14223. this._ownerRender = null;
  14224. this._vertices = null;
  14225. this._floatCountPerVertex = 0;
  14226. this._startLifeTimeIndex = 0;
  14227. this._timeIndex = 0;
  14228. this._simulateUpdate = false;
  14229. this._firstActiveElement = 0;
  14230. this._firstNewElement = 0;
  14231. this._firstFreeElement = 0;
  14232. this._firstRetiredElement = 0;
  14233. this._drawCounter = 0;
  14234. this._bufferMaxParticles = 0;
  14235. this._emission = null;
  14236. this._shape = null;
  14237. this._isEmitting = false;
  14238. this._isPlaying = false;
  14239. this._isPaused = false;
  14240. this._playStartDelay = 0;
  14241. this._frameRateTime = 0;
  14242. this._emissionTime = 0;
  14243. this._totalDelayTime = 0;
  14244. this._burstsIndex = 0;
  14245. this._velocityOverLifetime = null;
  14246. this._colorOverLifetime = null;
  14247. this._sizeOverLifetime = null;
  14248. this._rotationOverLifetime = null;
  14249. this._textureSheetAnimation = null;
  14250. this._startLifetimeType = 0;
  14251. this._startLifetimeConstant = 0;
  14252. this._startLifeTimeGradient = null;
  14253. this._startLifetimeConstantMin = 0;
  14254. this._startLifetimeConstantMax = 0;
  14255. this._startLifeTimeGradientMin = null;
  14256. this._startLifeTimeGradientMax = null;
  14257. this._maxStartLifetime = 0;
  14258. this._uvLength = new Vector2();
  14259. this._vertexStride = 0;
  14260. this._indexStride = 0;
  14261. this._vertexBuffer = null;
  14262. this._indexBuffer = null;
  14263. this._bufferState = new BufferState();
  14264. this._currentTime = 0;
  14265. this._startUpdateLoopCount = 0;
  14266. this._rand = null;
  14267. this._randomSeeds = null;
  14268. this.duration = 0;
  14269. this.looping = false;
  14270. this.prewarm = false;
  14271. this.startDelayType = 0;
  14272. this.startDelay = 0;
  14273. this.startDelayMin = 0;
  14274. this.startDelayMax = 0;
  14275. this.startSpeedType = 0;
  14276. this.startSpeedConstant = 0;
  14277. this.startSpeedConstantMin = 0;
  14278. this.startSpeedConstantMax = 0;
  14279. this.threeDStartSize = false;
  14280. this.startSizeType = 0;
  14281. this.startSizeConstant = 0;
  14282. this.startSizeConstantSeparate = null;
  14283. this.startSizeConstantMin = 0;
  14284. this.startSizeConstantMax = 0;
  14285. this.startSizeConstantMinSeparate = null;
  14286. this.startSizeConstantMaxSeparate = null;
  14287. this.threeDStartRotation = false;
  14288. this.startRotationType = 0;
  14289. this.startRotationConstant = 0;
  14290. this.startRotationConstantSeparate = null;
  14291. this.startRotationConstantMin = 0;
  14292. this.startRotationConstantMax = 0;
  14293. this.startRotationConstantMinSeparate = null;
  14294. this.startRotationConstantMaxSeparate = null;
  14295. this.randomizeRotationDirection = 0;
  14296. this.startColorType = 0;
  14297. this.startColorConstant = null;
  14298. this.startColorConstantMin = null;
  14299. this.startColorConstantMax = null;
  14300. this.gravityModifier = 0;
  14301. this.simulationSpace = 0;
  14302. this.scaleMode = 0;
  14303. this.playOnAwake = false;
  14304. this.randomSeed = null;
  14305. this.autoRandomSeed = false;
  14306. this.isPerformanceMode = false;
  14307. this._firstActiveElement = 0;
  14308. this._firstNewElement = 0;
  14309. this._firstFreeElement = 0;
  14310. this._firstRetiredElement = 0;
  14311. this._owner = owner;
  14312. this._ownerRender = owner.particleRenderer;
  14313. this._boundingBoxCorners = [];
  14314. this._boundingSphere = new BoundSphere(new Vector3(), Number.MAX_VALUE);
  14315. this._boundingBox = new BoundBox(new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE), new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE));
  14316. this._currentTime = 0;
  14317. this._isEmitting = false;
  14318. this._isPlaying = false;
  14319. this._isPaused = false;
  14320. this._burstsIndex = 0;
  14321. this._frameRateTime = 0;
  14322. this._emissionTime = 0;
  14323. this._totalDelayTime = 0;
  14324. this._simulateUpdate = false;
  14325. this._bufferMaxParticles = 1;
  14326. this.duration = 5.0;
  14327. this.looping = true;
  14328. this.prewarm = false;
  14329. this.startDelayType = 0;
  14330. this.startDelay = 0.0;
  14331. this.startDelayMin = 0.0;
  14332. this.startDelayMax = 0.0;
  14333. this._startLifetimeType = 0;
  14334. this._startLifetimeConstant = 5.0;
  14335. this._startLifeTimeGradient = new GradientDataNumber();
  14336. this._startLifetimeConstantMin = 0.0;
  14337. this._startLifetimeConstantMax = 5.0;
  14338. this._startLifeTimeGradientMin = new GradientDataNumber();
  14339. this._startLifeTimeGradientMax = new GradientDataNumber();
  14340. this._maxStartLifetime = 5.0;
  14341. this.startSpeedType = 0;
  14342. this.startSpeedConstant = 5.0;
  14343. this.startSpeedConstantMin = 0.0;
  14344. this.startSpeedConstantMax = 5.0;
  14345. this.threeDStartSize = false;
  14346. this.startSizeType = 0;
  14347. this.startSizeConstant = 1;
  14348. this.startSizeConstantSeparate = new Vector3(1, 1, 1);
  14349. this.startSizeConstantMin = 0;
  14350. this.startSizeConstantMax = 1;
  14351. this.startSizeConstantMinSeparate = new Vector3(0, 0, 0);
  14352. this.startSizeConstantMaxSeparate = new Vector3(1, 1, 1);
  14353. this.threeDStartRotation = false;
  14354. this.startRotationType = 0;
  14355. this.startRotationConstant = 0;
  14356. this.startRotationConstantSeparate = new Vector3(0, 0, 0);
  14357. this.startRotationConstantMin = 0.0;
  14358. this.startRotationConstantMax = 0.0;
  14359. this.startRotationConstantMinSeparate = new Vector3(0, 0, 0);
  14360. this.startRotationConstantMaxSeparate = new Vector3(0, 0, 0);
  14361. this.randomizeRotationDirection = 0.0;
  14362. this.startColorType = 0;
  14363. this.startColorConstant = new Vector4(1, 1, 1, 1);
  14364. this.startColorConstantMin = new Vector4(1, 1, 1, 1);
  14365. this.startColorConstantMax = new Vector4(1, 1, 1, 1);
  14366. this.gravityModifier = 0.0;
  14367. this.simulationSpace = 1;
  14368. this.scaleMode = 0;
  14369. this.playOnAwake = true;
  14370. this._rand = new Rand(0);
  14371. this.autoRandomSeed = true;
  14372. this.randomSeed = new Uint32Array(1);
  14373. this._randomSeeds = new Uint32Array(ShurikenParticleSystem._RANDOMOFFSET.length);
  14374. this.isPerformanceMode = true;
  14375. this._emission = new Emission();
  14376. this._emission.enbale = true;
  14377. }
  14378. get maxParticles() {
  14379. return this._bufferMaxParticles - 1;
  14380. }
  14381. set maxParticles(value) {
  14382. var newMaxParticles = value + 1;
  14383. if (newMaxParticles !== this._bufferMaxParticles) {
  14384. this._bufferMaxParticles = newMaxParticles;
  14385. this._initBufferDatas();
  14386. }
  14387. }
  14388. get emission() {
  14389. return this._emission;
  14390. }
  14391. get aliveParticleCount() {
  14392. if (this._firstNewElement >= this._firstRetiredElement)
  14393. return this._firstNewElement - this._firstRetiredElement;
  14394. else
  14395. return this._bufferMaxParticles - this._firstRetiredElement + this._firstNewElement;
  14396. }
  14397. get emissionTime() {
  14398. return this._emissionTime > this.duration ? this.duration : this._emissionTime;
  14399. }
  14400. get shape() {
  14401. return this._shape;
  14402. }
  14403. set shape(value) {
  14404. if (this._shape !== value) {
  14405. if (value && value.enable)
  14406. this._owner._render._shaderValues.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SHAPE);
  14407. else
  14408. this._owner._render._shaderValues.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SHAPE);
  14409. this._shape = value;
  14410. }
  14411. }
  14412. get isAlive() {
  14413. if (this._isPlaying || this.aliveParticleCount > 0)
  14414. return true;
  14415. return false;
  14416. }
  14417. get isEmitting() {
  14418. return this._isEmitting;
  14419. }
  14420. get isPlaying() {
  14421. return this._isPlaying;
  14422. }
  14423. get isPaused() {
  14424. return this._isPaused;
  14425. }
  14426. get startLifetimeType() {
  14427. return this._startLifetimeType;
  14428. }
  14429. set startLifetimeType(value) {
  14430. var i, n;
  14431. switch (this.startLifetimeType) {
  14432. case 0:
  14433. this._maxStartLifetime = this.startLifetimeConstant;
  14434. break;
  14435. case 1:
  14436. this._maxStartLifetime = -Number.MAX_VALUE;
  14437. var startLifeTimeGradient = startLifeTimeGradient;
  14438. for (i = 0, n = startLifeTimeGradient.gradientCount; i < n; i++)
  14439. this._maxStartLifetime = Math.max(this._maxStartLifetime, startLifeTimeGradient.getValueByIndex(i));
  14440. break;
  14441. case 2:
  14442. this._maxStartLifetime = Math.max(this.startLifetimeConstantMin, this.startLifetimeConstantMax);
  14443. break;
  14444. case 3:
  14445. this._maxStartLifetime = -Number.MAX_VALUE;
  14446. var startLifeTimeGradientMin = startLifeTimeGradientMin;
  14447. for (i = 0, n = startLifeTimeGradientMin.gradientCount; i < n; i++)
  14448. this._maxStartLifetime = Math.max(this._maxStartLifetime, startLifeTimeGradientMin.getValueByIndex(i));
  14449. var startLifeTimeGradientMax = startLifeTimeGradientMax;
  14450. for (i = 0, n = startLifeTimeGradientMax.gradientCount; i < n; i++)
  14451. this._maxStartLifetime = Math.max(this._maxStartLifetime, startLifeTimeGradientMax.getValueByIndex(i));
  14452. break;
  14453. }
  14454. this._startLifetimeType = value;
  14455. }
  14456. get startLifetimeConstant() {
  14457. return this._startLifetimeConstant;
  14458. }
  14459. set startLifetimeConstant(value) {
  14460. if (this._startLifetimeType === 0)
  14461. this._maxStartLifetime = value;
  14462. this._startLifetimeConstant = value;
  14463. }
  14464. get startLifeTimeGradient() {
  14465. return this._startLifeTimeGradient;
  14466. }
  14467. set startLifeTimeGradient(value) {
  14468. if (this._startLifetimeType === 1) {
  14469. this._maxStartLifetime = -Number.MAX_VALUE;
  14470. for (var i = 0, n = value.gradientCount; i < n; i++)
  14471. this._maxStartLifetime = Math.max(this._maxStartLifetime, value.getValueByIndex(i));
  14472. }
  14473. this._startLifeTimeGradient = value;
  14474. }
  14475. get startLifetimeConstantMin() {
  14476. return this._startLifetimeConstantMin;
  14477. }
  14478. set startLifetimeConstantMin(value) {
  14479. if (this._startLifetimeType === 2)
  14480. this._maxStartLifetime = Math.max(value, this._startLifetimeConstantMax);
  14481. this._startLifetimeConstantMin = value;
  14482. }
  14483. get startLifetimeConstantMax() {
  14484. return this._startLifetimeConstantMax;
  14485. }
  14486. set startLifetimeConstantMax(value) {
  14487. if (this._startLifetimeType === 2)
  14488. this._maxStartLifetime = Math.max(this._startLifetimeConstantMin, value);
  14489. this._startLifetimeConstantMax = value;
  14490. }
  14491. get startLifeTimeGradientMin() {
  14492. return this._startLifeTimeGradientMin;
  14493. }
  14494. set startLifeTimeGradientMin(value) {
  14495. if (this._startLifetimeType === 3) {
  14496. var i, n;
  14497. this._maxStartLifetime = -Number.MAX_VALUE;
  14498. for (i = 0, n = value.gradientCount; i < n; i++)
  14499. this._maxStartLifetime = Math.max(this._maxStartLifetime, value.getValueByIndex(i));
  14500. for (i = 0, n = this._startLifeTimeGradientMax.gradientCount; i < n; i++)
  14501. this._maxStartLifetime = Math.max(this._maxStartLifetime, this._startLifeTimeGradientMax.getValueByIndex(i));
  14502. }
  14503. this._startLifeTimeGradientMin = value;
  14504. }
  14505. get startLifeTimeGradientMax() {
  14506. return this._startLifeTimeGradientMax;
  14507. }
  14508. set startLifeTimeGradientMax(value) {
  14509. if (this._startLifetimeType === 3) {
  14510. var i, n;
  14511. this._maxStartLifetime = -Number.MAX_VALUE;
  14512. for (i = 0, n = this._startLifeTimeGradientMin.gradientCount; i < n; i++)
  14513. this._maxStartLifetime = Math.max(this._maxStartLifetime, this._startLifeTimeGradientMin.getValueByIndex(i));
  14514. for (i = 0, n = value.gradientCount; i < n; i++)
  14515. this._maxStartLifetime = Math.max(this._maxStartLifetime, value.getValueByIndex(i));
  14516. }
  14517. this._startLifeTimeGradientMax = value;
  14518. }
  14519. get velocityOverLifetime() {
  14520. return this._velocityOverLifetime;
  14521. }
  14522. set velocityOverLifetime(value) {
  14523. var shaDat = this._owner._render._shaderValues;
  14524. if (value) {
  14525. var velocity = value.velocity;
  14526. var velocityType = velocity.type;
  14527. if (value.enbale) {
  14528. switch (velocityType) {
  14529. case 0:
  14530. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT);
  14531. break;
  14532. case 1:
  14533. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE);
  14534. break;
  14535. case 2:
  14536. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT);
  14537. break;
  14538. case 3:
  14539. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE);
  14540. break;
  14541. }
  14542. }
  14543. else {
  14544. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT);
  14545. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE);
  14546. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT);
  14547. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE);
  14548. }
  14549. switch (velocityType) {
  14550. case 0:
  14551. shaDat.setVector3(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYCONST, velocity.constant);
  14552. break;
  14553. case 1:
  14554. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTX, velocity.gradientX._elements);
  14555. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTY, velocity.gradientY._elements);
  14556. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTZ, velocity.gradientZ._elements);
  14557. break;
  14558. case 2:
  14559. shaDat.setVector3(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYCONST, velocity.constantMin);
  14560. shaDat.setVector3(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYCONSTMAX, velocity.constantMax);
  14561. break;
  14562. case 3:
  14563. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTX, velocity.gradientXMin._elements);
  14564. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTXMAX, velocity.gradientXMax._elements);
  14565. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTY, velocity.gradientYMin._elements);
  14566. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTYMAX, velocity.gradientYMax._elements);
  14567. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTZ, velocity.gradientZMin._elements);
  14568. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTZMAX, velocity.gradientZMax._elements);
  14569. break;
  14570. }
  14571. shaDat.setInt(ShuriKenParticle3DShaderDeclaration.VOLSPACETYPE, value.space);
  14572. }
  14573. else {
  14574. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT);
  14575. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE);
  14576. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT);
  14577. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE);
  14578. shaDat.setVector(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYCONST, null);
  14579. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTX, null);
  14580. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTY, null);
  14581. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTZ, null);
  14582. shaDat.setVector(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYCONST, null);
  14583. shaDat.setVector(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYCONSTMAX, null);
  14584. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTX, null);
  14585. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTXMAX, null);
  14586. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTY, null);
  14587. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTYMAX, null);
  14588. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTZ, null);
  14589. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.VOLVELOCITYGRADIENTZMAX, null);
  14590. shaDat.setInt(ShuriKenParticle3DShaderDeclaration.VOLSPACETYPE, undefined);
  14591. }
  14592. this._velocityOverLifetime = value;
  14593. }
  14594. get colorOverLifetime() {
  14595. return this._colorOverLifetime;
  14596. }
  14597. set colorOverLifetime(value) {
  14598. var shaDat = this._owner._render._shaderValues;
  14599. if (value) {
  14600. var color = value.color;
  14601. if (value.enbale) {
  14602. switch (color.type) {
  14603. case 1:
  14604. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_COLOROVERLIFETIME);
  14605. break;
  14606. case 3:
  14607. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RANDOMCOLOROVERLIFETIME);
  14608. break;
  14609. }
  14610. }
  14611. else {
  14612. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_COLOROVERLIFETIME);
  14613. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RANDOMCOLOROVERLIFETIME);
  14614. }
  14615. switch (color.type) {
  14616. case 1:
  14617. var gradientColor = color.gradient;
  14618. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTALPHAS, gradientColor._alphaElements);
  14619. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTCOLORS, gradientColor._rgbElements);
  14620. break;
  14621. case 3:
  14622. var minGradientColor = color.gradientMin;
  14623. var maxGradientColor = color.gradientMax;
  14624. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTALPHAS, minGradientColor._alphaElements);
  14625. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTCOLORS, minGradientColor._rgbElements);
  14626. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.MAXCOLOROVERLIFEGRADIENTALPHAS, maxGradientColor._alphaElements);
  14627. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.MAXCOLOROVERLIFEGRADIENTCOLORS, maxGradientColor._rgbElements);
  14628. break;
  14629. }
  14630. }
  14631. else {
  14632. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_COLOROVERLIFETIME);
  14633. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RANDOMCOLOROVERLIFETIME);
  14634. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTALPHAS, gradientColor._alphaElements);
  14635. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTCOLORS, gradientColor._rgbElements);
  14636. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTALPHAS, minGradientColor._alphaElements);
  14637. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.COLOROVERLIFEGRADIENTCOLORS, minGradientColor._rgbElements);
  14638. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.MAXCOLOROVERLIFEGRADIENTALPHAS, maxGradientColor._alphaElements);
  14639. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.MAXCOLOROVERLIFEGRADIENTCOLORS, maxGradientColor._rgbElements);
  14640. }
  14641. this._colorOverLifetime = value;
  14642. }
  14643. get sizeOverLifetime() {
  14644. return this._sizeOverLifetime;
  14645. }
  14646. set sizeOverLifetime(value) {
  14647. var shaDat = this._owner._render._shaderValues;
  14648. if (value) {
  14649. var size = value.size;
  14650. var sizeSeparate = size.separateAxes;
  14651. var sizeType = size.type;
  14652. if (value.enbale) {
  14653. switch (sizeType) {
  14654. case 0:
  14655. if (sizeSeparate)
  14656. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE);
  14657. else
  14658. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMECURVE);
  14659. break;
  14660. case 2:
  14661. if (sizeSeparate)
  14662. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE);
  14663. else
  14664. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES);
  14665. break;
  14666. }
  14667. }
  14668. else {
  14669. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMECURVE);
  14670. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE);
  14671. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES);
  14672. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE);
  14673. }
  14674. switch (sizeType) {
  14675. case 0:
  14676. if (sizeSeparate) {
  14677. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTX, size.gradientX._elements);
  14678. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTY, size.gradientY._elements);
  14679. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSizeGradientZ, size.gradientZ._elements);
  14680. }
  14681. else {
  14682. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENT, size.gradient._elements);
  14683. }
  14684. break;
  14685. case 2:
  14686. if (sizeSeparate) {
  14687. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTX, size.gradientXMin._elements);
  14688. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTXMAX, size.gradientXMax._elements);
  14689. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTY, size.gradientYMin._elements);
  14690. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTYMAX, size.gradientYMax._elements);
  14691. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSizeGradientZ, size.gradientZMin._elements);
  14692. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSizeGradientZMAX, size.gradientZMax._elements);
  14693. }
  14694. else {
  14695. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENT, size.gradientMin._elements);
  14696. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSizeGradientMax, size.gradientMax._elements);
  14697. }
  14698. break;
  14699. }
  14700. }
  14701. else {
  14702. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMECURVE);
  14703. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE);
  14704. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES);
  14705. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE);
  14706. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTX, null);
  14707. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTXMAX, null);
  14708. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTY, null);
  14709. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENTYMAX, null);
  14710. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSizeGradientZ, null);
  14711. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSizeGradientZMAX, null);
  14712. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSIZEGRADIENT, null);
  14713. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.SOLSizeGradientMax, null);
  14714. }
  14715. this._sizeOverLifetime = value;
  14716. }
  14717. get rotationOverLifetime() {
  14718. return this._rotationOverLifetime;
  14719. }
  14720. set rotationOverLifetime(value) {
  14721. var shaDat = this._owner._render._shaderValues;
  14722. if (value) {
  14723. var rotation = value.angularVelocity;
  14724. if (!rotation)
  14725. return;
  14726. var rotationSeparate = rotation.separateAxes;
  14727. var rotationType = rotation.type;
  14728. if (value.enbale) {
  14729. if (rotationSeparate)
  14730. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE);
  14731. else
  14732. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIME);
  14733. switch (rotationType) {
  14734. case 0:
  14735. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT);
  14736. break;
  14737. case 1:
  14738. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE);
  14739. break;
  14740. case 2:
  14741. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS);
  14742. break;
  14743. case 3:
  14744. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);
  14745. break;
  14746. }
  14747. }
  14748. else {
  14749. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIME);
  14750. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE);
  14751. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT);
  14752. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE);
  14753. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS);
  14754. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);
  14755. }
  14756. switch (rotationType) {
  14757. case 0:
  14758. if (rotationSeparate) {
  14759. shaDat.setVector3(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTSEPRARATE, rotation.constantSeparate);
  14760. }
  14761. else {
  14762. shaDat.setNumber(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONST, rotation.constant);
  14763. }
  14764. break;
  14765. case 1:
  14766. if (rotationSeparate) {
  14767. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTX, rotation.gradientX._elements);
  14768. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTY, rotation.gradientY._elements);
  14769. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTZ, rotation.gradientZ._elements);
  14770. }
  14771. else {
  14772. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENT, rotation.gradient._elements);
  14773. }
  14774. break;
  14775. case 2:
  14776. if (rotationSeparate) {
  14777. shaDat.setVector3(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTSEPRARATE, rotation.constantMinSeparate);
  14778. shaDat.setVector3(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTMAXSEPRARATE, rotation.constantMaxSeparate);
  14779. }
  14780. else {
  14781. shaDat.setNumber(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONST, rotation.constantMin);
  14782. shaDat.setNumber(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTMAX, rotation.constantMax);
  14783. }
  14784. break;
  14785. case 3:
  14786. if (rotationSeparate) {
  14787. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTX, rotation.gradientXMin._elements);
  14788. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTXMAX, rotation.gradientXMax._elements);
  14789. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTY, rotation.gradientYMin._elements);
  14790. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTYMAX, rotation.gradientYMax._elements);
  14791. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTZ, rotation.gradientZMin._elements);
  14792. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTZMAX, rotation.gradientZMax._elements);
  14793. }
  14794. else {
  14795. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENT, rotation.gradientMin._elements);
  14796. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTMAX, rotation.gradientMax._elements);
  14797. }
  14798. break;
  14799. }
  14800. }
  14801. else {
  14802. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIME);
  14803. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE);
  14804. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT);
  14805. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE);
  14806. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS);
  14807. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);
  14808. shaDat.setVector(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTSEPRARATE, null);
  14809. shaDat.setVector(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTMAXSEPRARATE, null);
  14810. shaDat.setNumber(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONST, undefined);
  14811. shaDat.setNumber(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYCONSTMAX, undefined);
  14812. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTX, null);
  14813. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTXMAX, null);
  14814. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTY, null);
  14815. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTYMAX, null);
  14816. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTZ, null);
  14817. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTZMAX, null);
  14818. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTWMAX, null);
  14819. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENT, null);
  14820. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.ROLANGULARVELOCITYGRADIENTMAX, null);
  14821. }
  14822. this._rotationOverLifetime = value;
  14823. }
  14824. get textureSheetAnimation() {
  14825. return this._textureSheetAnimation;
  14826. }
  14827. set textureSheetAnimation(value) {
  14828. var shaDat = this._owner._render._shaderValues;
  14829. if (value) {
  14830. var frameOverTime = value.frame;
  14831. var textureAniType = frameOverTime.type;
  14832. if (value.enable) {
  14833. switch (textureAniType) {
  14834. case 1:
  14835. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE);
  14836. break;
  14837. case 3:
  14838. shaDat.addDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE);
  14839. break;
  14840. }
  14841. }
  14842. else {
  14843. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE);
  14844. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE);
  14845. }
  14846. if (textureAniType === 1 || textureAniType === 3) {
  14847. shaDat.setNumber(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONCYCLES, value.cycles);
  14848. var title = value.tiles;
  14849. var _uvLengthE = this._uvLength;
  14850. _uvLengthE.x = 1.0 / title.x;
  14851. _uvLengthE.y = 1.0 / title.y;
  14852. shaDat.setVector2(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONSUBUVLENGTH, this._uvLength);
  14853. }
  14854. switch (textureAniType) {
  14855. case 1:
  14856. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONGRADIENTUVS, frameOverTime.frameOverTimeData._elements);
  14857. break;
  14858. case 3:
  14859. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONGRADIENTUVS, frameOverTime.frameOverTimeDataMin._elements);
  14860. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONGRADIENTMAXUVS, frameOverTime.frameOverTimeDataMax._elements);
  14861. break;
  14862. }
  14863. }
  14864. else {
  14865. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE);
  14866. shaDat.removeDefine(ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE);
  14867. shaDat.setNumber(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONCYCLES, undefined);
  14868. shaDat.setVector(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONSUBUVLENGTH, null);
  14869. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONGRADIENTUVS, null);
  14870. shaDat.setBuffer(ShuriKenParticle3DShaderDeclaration.TEXTURESHEETANIMATIONGRADIENTMAXUVS, null);
  14871. }
  14872. this._textureSheetAnimation = value;
  14873. }
  14874. _getVertexBuffer(index = 0) {
  14875. if (index === 0)
  14876. return this._vertexBuffer;
  14877. else
  14878. return null;
  14879. }
  14880. _getIndexBuffer() {
  14881. return this._indexBuffer;
  14882. }
  14883. _generateBoundingSphere() {
  14884. var centerE = this._boundingSphere.center;
  14885. centerE.x = 0;
  14886. centerE.y = 0;
  14887. centerE.z = 0;
  14888. this._boundingSphere.radius = Number.MAX_VALUE;
  14889. }
  14890. _generateBoundingBox() {
  14891. var particle = this._owner;
  14892. var particleRender = particle.particleRenderer;
  14893. var boundMin = this._boundingBox.min;
  14894. var boundMax = this._boundingBox.max;
  14895. var i, n;
  14896. var maxStartLifeTime;
  14897. switch (this.startLifetimeType) {
  14898. case 0:
  14899. maxStartLifeTime = this.startLifetimeConstant;
  14900. break;
  14901. case 1:
  14902. maxStartLifeTime = -Number.MAX_VALUE;
  14903. var startLifeTimeGradient = startLifeTimeGradient;
  14904. for (i = 0, n = startLifeTimeGradient.gradientCount; i < n; i++)
  14905. maxStartLifeTime = Math.max(maxStartLifeTime, startLifeTimeGradient.getValueByIndex(i));
  14906. break;
  14907. case 2:
  14908. maxStartLifeTime = Math.max(this.startLifetimeConstantMin, this.startLifetimeConstantMax);
  14909. break;
  14910. case 3:
  14911. maxStartLifeTime = -Number.MAX_VALUE;
  14912. var startLifeTimeGradientMin = startLifeTimeGradientMin;
  14913. for (i = 0, n = startLifeTimeGradientMin.gradientCount; i < n; i++)
  14914. maxStartLifeTime = Math.max(maxStartLifeTime, startLifeTimeGradientMin.getValueByIndex(i));
  14915. var startLifeTimeGradientMax = startLifeTimeGradientMax;
  14916. for (i = 0, n = startLifeTimeGradientMax.gradientCount; i < n; i++)
  14917. maxStartLifeTime = Math.max(maxStartLifeTime, startLifeTimeGradientMax.getValueByIndex(i));
  14918. break;
  14919. }
  14920. var minStartSpeed, maxStartSpeed;
  14921. switch (this.startSpeedType) {
  14922. case 0:
  14923. minStartSpeed = maxStartSpeed = this.startSpeedConstant;
  14924. break;
  14925. case 1:
  14926. break;
  14927. case 2:
  14928. minStartSpeed = this.startLifetimeConstantMin;
  14929. maxStartSpeed = this.startLifetimeConstantMax;
  14930. break;
  14931. case 3:
  14932. break;
  14933. }
  14934. var minPosition, maxPosition, minDirection, maxDirection;
  14935. if (this._shape && this._shape.enable) ;
  14936. else {
  14937. minPosition = maxPosition = Vector3._ZERO;
  14938. minDirection = Vector3._ZERO;
  14939. maxDirection = Vector3._UnitZ;
  14940. }
  14941. var startMinVelocity = new Vector3(minDirection.x * minStartSpeed, minDirection.y * minStartSpeed, minDirection.z * minStartSpeed);
  14942. var startMaxVelocity = new Vector3(maxDirection.x * maxStartSpeed, maxDirection.y * maxStartSpeed, maxDirection.z * maxStartSpeed);
  14943. if (this._velocityOverLifetime && this._velocityOverLifetime.enbale) {
  14944. var lifeMinVelocity;
  14945. var lifeMaxVelocity;
  14946. var velocity = this._velocityOverLifetime.velocity;
  14947. switch (velocity.type) {
  14948. case 0:
  14949. lifeMinVelocity = lifeMaxVelocity = velocity.constant;
  14950. break;
  14951. case 1:
  14952. lifeMinVelocity = lifeMaxVelocity = new Vector3(velocity.gradientX.getAverageValue(), velocity.gradientY.getAverageValue(), velocity.gradientZ.getAverageValue());
  14953. break;
  14954. case 2:
  14955. lifeMinVelocity = velocity.constantMin;
  14956. lifeMaxVelocity = velocity.constantMax;
  14957. break;
  14958. case 3:
  14959. lifeMinVelocity = new Vector3(velocity.gradientXMin.getAverageValue(), velocity.gradientYMin.getAverageValue(), velocity.gradientZMin.getAverageValue());
  14960. lifeMaxVelocity = new Vector3(velocity.gradientXMax.getAverageValue(), velocity.gradientYMax.getAverageValue(), velocity.gradientZMax.getAverageValue());
  14961. break;
  14962. }
  14963. }
  14964. var positionScale, velocityScale;
  14965. var transform = this._owner.transform;
  14966. var worldPosition = transform.position;
  14967. var sizeScale = ShurikenParticleSystem._tempVector39;
  14968. var renderMode = particleRender.renderMode;
  14969. switch (this.scaleMode) {
  14970. case 0:
  14971. var scale = transform.getWorldLossyScale();
  14972. positionScale = scale;
  14973. sizeScale.x = scale.x;
  14974. sizeScale.y = scale.z;
  14975. sizeScale.z = scale.y;
  14976. (renderMode === 1) && (velocityScale = scale);
  14977. break;
  14978. case 1:
  14979. var localScale = transform.localScale;
  14980. positionScale = localScale;
  14981. sizeScale.x = localScale.x;
  14982. sizeScale.y = localScale.z;
  14983. sizeScale.z = localScale.y;
  14984. (renderMode === 1) && (velocityScale = localScale);
  14985. break;
  14986. case 2:
  14987. positionScale = transform.getWorldLossyScale();
  14988. sizeScale.x = sizeScale.y = sizeScale.z = 1;
  14989. (renderMode === 1) && (velocityScale = Vector3._ONE);
  14990. break;
  14991. }
  14992. var minStratPosition, maxStratPosition;
  14993. if (this._velocityOverLifetime && this._velocityOverLifetime.enbale) ;
  14994. else {
  14995. minStratPosition = new Vector3(startMinVelocity.x * maxStartLifeTime, startMinVelocity.y * maxStartLifeTime, startMinVelocity.z * maxStartLifeTime);
  14996. maxStratPosition = new Vector3(startMaxVelocity.x * maxStartLifeTime, startMaxVelocity.y * maxStartLifeTime, startMaxVelocity.z * maxStartLifeTime);
  14997. if (this.scaleMode != 2) {
  14998. Vector3.add(minPosition, minStratPosition, boundMin);
  14999. Vector3.multiply(positionScale, boundMin, boundMin);
  15000. Vector3.add(maxPosition, maxStratPosition, boundMax);
  15001. Vector3.multiply(positionScale, boundMax, boundMax);
  15002. }
  15003. else {
  15004. Vector3.multiply(positionScale, minPosition, boundMin);
  15005. Vector3.add(boundMin, minStratPosition, boundMin);
  15006. Vector3.multiply(positionScale, maxPosition, boundMax);
  15007. Vector3.add(boundMax, maxStratPosition, boundMax);
  15008. }
  15009. }
  15010. switch (this.simulationSpace) {
  15011. case 0:
  15012. break;
  15013. case 1:
  15014. Vector3.add(boundMin, worldPosition, boundMin);
  15015. Vector3.add(boundMax, worldPosition, boundMax);
  15016. break;
  15017. }
  15018. var maxSize, maxSizeY;
  15019. switch (this.startSizeType) {
  15020. case 0:
  15021. if (this.threeDStartSize) {
  15022. var startSizeConstantSeparate = startSizeConstantSeparate;
  15023. maxSize = Math.max(startSizeConstantSeparate.x, startSizeConstantSeparate.y);
  15024. if (renderMode === 1)
  15025. maxSizeY = startSizeConstantSeparate.y;
  15026. }
  15027. else {
  15028. maxSize = this.startSizeConstant;
  15029. if (renderMode === 1)
  15030. maxSizeY = this.startSizeConstant;
  15031. }
  15032. break;
  15033. case 1:
  15034. break;
  15035. case 2:
  15036. if (this.threeDStartSize) {
  15037. var startSizeConstantMaxSeparate = startSizeConstantMaxSeparate;
  15038. maxSize = Math.max(startSizeConstantMaxSeparate.x, startSizeConstantMaxSeparate.y);
  15039. if (renderMode === 1)
  15040. maxSizeY = startSizeConstantMaxSeparate.y;
  15041. }
  15042. else {
  15043. maxSize = this.startSizeConstantMax;
  15044. if (renderMode === 1)
  15045. maxSizeY = this.startSizeConstantMax;
  15046. }
  15047. break;
  15048. case 3:
  15049. break;
  15050. }
  15051. if (this._sizeOverLifetime && this._sizeOverLifetime.enbale) {
  15052. var size = this._sizeOverLifetime.size;
  15053. maxSize *= this._sizeOverLifetime.size.getMaxSizeInGradient();
  15054. }
  15055. var threeDMaxSize = ShurikenParticleSystem._tempVector30;
  15056. var rotSize, nonRotSize;
  15057. switch (renderMode) {
  15058. case 0:
  15059. rotSize = maxSize * ShurikenParticleSystem.halfKSqrtOf2;
  15060. Vector3.scale(sizeScale, maxSize, threeDMaxSize);
  15061. Vector3.subtract(boundMin, threeDMaxSize, boundMin);
  15062. Vector3.add(boundMax, threeDMaxSize, boundMax);
  15063. break;
  15064. case 1:
  15065. var maxStretchPosition = ShurikenParticleSystem._tempVector31;
  15066. var maxStretchVelocity = ShurikenParticleSystem._tempVector32;
  15067. var minStretchVelocity = ShurikenParticleSystem._tempVector33;
  15068. var minStretchPosition = ShurikenParticleSystem._tempVector34;
  15069. if (this._velocityOverLifetime && this._velocityOverLifetime.enbale) ;
  15070. else {
  15071. Vector3.multiply(velocityScale, startMaxVelocity, maxStretchVelocity);
  15072. Vector3.multiply(velocityScale, startMinVelocity, minStretchVelocity);
  15073. }
  15074. var sizeStretch = maxSizeY * particleRender.stretchedBillboardLengthScale;
  15075. var maxStretchLength = Vector3.scalarLength(maxStretchVelocity) * particleRender.stretchedBillboardSpeedScale + sizeStretch;
  15076. var minStretchLength = Vector3.scalarLength(minStretchVelocity) * particleRender.stretchedBillboardSpeedScale + sizeStretch;
  15077. var norMaxStretchVelocity = ShurikenParticleSystem._tempVector35;
  15078. var norMinStretchVelocity = ShurikenParticleSystem._tempVector36;
  15079. Vector3.normalize(maxStretchVelocity, norMaxStretchVelocity);
  15080. Vector3.scale(norMaxStretchVelocity, maxStretchLength, minStretchPosition);
  15081. Vector3.subtract(maxStratPosition, minStretchPosition, minStretchPosition);
  15082. Vector3.normalize(minStretchVelocity, norMinStretchVelocity);
  15083. Vector3.scale(norMinStretchVelocity, minStretchLength, maxStretchPosition);
  15084. Vector3.add(minStratPosition, maxStretchPosition, maxStretchPosition);
  15085. rotSize = maxSize * ShurikenParticleSystem.halfKSqrtOf2;
  15086. Vector3.scale(sizeScale, rotSize, threeDMaxSize);
  15087. var halfNorMaxStretchVelocity = ShurikenParticleSystem._tempVector37;
  15088. var halfNorMinStretchVelocity = ShurikenParticleSystem._tempVector38;
  15089. Vector3.scale(norMaxStretchVelocity, 0.5, halfNorMaxStretchVelocity);
  15090. Vector3.scale(norMinStretchVelocity, 0.5, halfNorMinStretchVelocity);
  15091. Vector3.multiply(halfNorMaxStretchVelocity, sizeScale, halfNorMaxStretchVelocity);
  15092. Vector3.multiply(halfNorMinStretchVelocity, sizeScale, halfNorMinStretchVelocity);
  15093. Vector3.add(boundMin, halfNorMinStretchVelocity, boundMin);
  15094. Vector3.min(boundMin, minStretchPosition, boundMin);
  15095. Vector3.subtract(boundMin, threeDMaxSize, boundMin);
  15096. Vector3.subtract(boundMax, halfNorMaxStretchVelocity, boundMax);
  15097. Vector3.max(boundMax, maxStretchPosition, boundMax);
  15098. Vector3.add(boundMax, threeDMaxSize, boundMax);
  15099. break;
  15100. case 2:
  15101. maxSize *= Math.cos(0.78539816339744830961566084581988);
  15102. nonRotSize = maxSize * 0.5;
  15103. threeDMaxSize.x = sizeScale.x * nonRotSize;
  15104. threeDMaxSize.y = sizeScale.z * nonRotSize;
  15105. Vector3.subtract(boundMin, threeDMaxSize, boundMin);
  15106. Vector3.add(boundMax, threeDMaxSize, boundMax);
  15107. break;
  15108. case 3:
  15109. maxSize *= Math.cos(0.78539816339744830961566084581988);
  15110. nonRotSize = maxSize * 0.5;
  15111. Vector3.scale(sizeScale, nonRotSize, threeDMaxSize);
  15112. Vector3.subtract(boundMin, threeDMaxSize, boundMin);
  15113. Vector3.add(boundMax, threeDMaxSize, boundMax);
  15114. break;
  15115. }
  15116. this._boundingBox.getCorners(this._boundingBoxCorners);
  15117. }
  15118. _updateEmission() {
  15119. if (!this.isAlive)
  15120. return;
  15121. if (this._simulateUpdate) {
  15122. this._simulateUpdate = false;
  15123. }
  15124. else {
  15125. var elapsedTime = (this._startUpdateLoopCount !== Laya.Stat.loopCount && !this._isPaused) ? this._owner._scene.timer._delta / 1000.0 : 0;
  15126. elapsedTime = Math.min(ShurikenParticleSystem._maxElapsedTime, elapsedTime);
  15127. this._updateParticles(elapsedTime);
  15128. }
  15129. }
  15130. _updateParticles(elapsedTime) {
  15131. if (this._ownerRender.renderMode === 4 && !this._ownerRender.mesh)
  15132. return;
  15133. this._currentTime += elapsedTime;
  15134. this._retireActiveParticles();
  15135. this._freeRetiredParticles();
  15136. this._totalDelayTime += elapsedTime;
  15137. if (this._totalDelayTime < this._playStartDelay) {
  15138. return;
  15139. }
  15140. if (this._emission.enbale && this._isEmitting && !this._isPaused)
  15141. this._advanceTime(elapsedTime, this._currentTime);
  15142. }
  15143. _updateParticlesSimulationRestart(time) {
  15144. this._firstActiveElement = 0;
  15145. this._firstNewElement = 0;
  15146. this._firstFreeElement = 0;
  15147. this._firstRetiredElement = 0;
  15148. this._burstsIndex = 0;
  15149. this._frameRateTime = time;
  15150. this._emissionTime = 0;
  15151. this._totalDelayTime = 0;
  15152. this._currentTime = time;
  15153. var delayTime = time;
  15154. if (delayTime < this._playStartDelay) {
  15155. this._totalDelayTime = delayTime;
  15156. return;
  15157. }
  15158. if (this._emission.enbale)
  15159. this._advanceTime(time, time);
  15160. }
  15161. _retireActiveParticles() {
  15162. const epsilon = 0.0001;
  15163. while (this._firstActiveElement != this._firstNewElement) {
  15164. var index = this._firstActiveElement * this._floatCountPerVertex * this._vertexStride;
  15165. var timeIndex = index + this._timeIndex;
  15166. var particleAge = this._currentTime - this._vertices[timeIndex];
  15167. if (particleAge + epsilon < this._vertices[index + this._startLifeTimeIndex])
  15168. break;
  15169. this._vertices[timeIndex] = this._drawCounter;
  15170. this._firstActiveElement++;
  15171. if (this._firstActiveElement >= this._bufferMaxParticles)
  15172. this._firstActiveElement = 0;
  15173. }
  15174. }
  15175. _freeRetiredParticles() {
  15176. while (this._firstRetiredElement != this._firstActiveElement) {
  15177. var age = this._drawCounter - this._vertices[this._firstRetiredElement * this._floatCountPerVertex * this._vertexStride + this._timeIndex];
  15178. if (this.isPerformanceMode)
  15179. if (age < 3)
  15180. break;
  15181. this._firstRetiredElement++;
  15182. if (this._firstRetiredElement >= this._bufferMaxParticles)
  15183. this._firstRetiredElement = 0;
  15184. }
  15185. }
  15186. _burst(fromTime, toTime) {
  15187. var totalEmitCount = 0;
  15188. var bursts = this._emission._bursts;
  15189. for (var n = bursts.length; this._burstsIndex < n; this._burstsIndex++) {
  15190. var burst = bursts[this._burstsIndex];
  15191. var burstTime = burst.time;
  15192. if (fromTime <= burstTime && burstTime < toTime) {
  15193. var emitCount;
  15194. if (this.autoRandomSeed) {
  15195. emitCount = Laya.MathUtil.lerp(burst.minCount, burst.maxCount, Math.random());
  15196. }
  15197. else {
  15198. this._rand.seed = this._randomSeeds[0];
  15199. emitCount = Laya.MathUtil.lerp(burst.minCount, burst.maxCount, this._rand.getFloat());
  15200. this._randomSeeds[0] = this._rand.seed;
  15201. }
  15202. totalEmitCount += emitCount;
  15203. }
  15204. else {
  15205. break;
  15206. }
  15207. }
  15208. return totalEmitCount;
  15209. }
  15210. _advanceTime(elapsedTime, emitTime) {
  15211. var i;
  15212. var lastEmissionTime = this._emissionTime;
  15213. this._emissionTime += elapsedTime;
  15214. var totalEmitCount = 0;
  15215. if (this._emissionTime > this.duration) {
  15216. if (this.looping) {
  15217. totalEmitCount += this._burst(lastEmissionTime, this._emissionTime);
  15218. this._emissionTime -= this.duration;
  15219. this._burstsIndex = 0;
  15220. totalEmitCount += this._burst(0, this._emissionTime);
  15221. }
  15222. else {
  15223. totalEmitCount = Math.min(this.maxParticles - this.aliveParticleCount, totalEmitCount);
  15224. for (i = 0; i < totalEmitCount; i++)
  15225. this.emit(emitTime);
  15226. this._isPlaying = false;
  15227. this.stop();
  15228. return;
  15229. }
  15230. }
  15231. else {
  15232. totalEmitCount += this._burst(lastEmissionTime, this._emissionTime);
  15233. }
  15234. totalEmitCount = Math.min(this.maxParticles - this.aliveParticleCount, totalEmitCount);
  15235. for (i = 0; i < totalEmitCount; i++)
  15236. this.emit(emitTime);
  15237. var emissionRate = this.emission.emissionRate;
  15238. if (emissionRate > 0) {
  15239. var minEmissionTime = 1 / emissionRate;
  15240. this._frameRateTime += minEmissionTime;
  15241. this._frameRateTime = this._currentTime - (this._currentTime - this._frameRateTime) % this._maxStartLifetime;
  15242. while (this._frameRateTime <= emitTime) {
  15243. if (this.emit(this._frameRateTime))
  15244. this._frameRateTime += minEmissionTime;
  15245. else
  15246. break;
  15247. }
  15248. this._frameRateTime = Math.floor(emitTime / minEmissionTime) * minEmissionTime;
  15249. }
  15250. }
  15251. _initBufferDatas() {
  15252. if (this._vertexBuffer) {
  15253. this._vertexBuffer.destroy();
  15254. this._indexBuffer.destroy();
  15255. }
  15256. var gl = Laya.LayaGL.instance;
  15257. var render = this._ownerRender;
  15258. var renderMode = render.renderMode;
  15259. if (renderMode !== -1 && this.maxParticles > 0) {
  15260. var indices, i, j, m, indexOffset, perPartOffset, vertexDeclaration;
  15261. var vbMemorySize = 0, memorySize = 0;
  15262. var mesh = render.mesh;
  15263. if (renderMode === 4) {
  15264. if (mesh) {
  15265. vertexDeclaration = VertexShurikenParticleMesh.vertexDeclaration;
  15266. this._floatCountPerVertex = vertexDeclaration.vertexStride / 4;
  15267. this._startLifeTimeIndex = 12;
  15268. this._timeIndex = 16;
  15269. this._vertexStride = mesh._vertexBuffer.vertexCount;
  15270. var totalVertexCount = this._bufferMaxParticles * this._vertexStride;
  15271. var vbCount = Math.floor(totalVertexCount / 65535) + 1;
  15272. var lastVBVertexCount = totalVertexCount % 65535;
  15273. if (vbCount > 1) {
  15274. throw new Error("ShurikenParticleSystem:the maxParticleCount multiply mesh vertexCount is large than 65535.");
  15275. }
  15276. vbMemorySize = vertexDeclaration.vertexStride * lastVBVertexCount;
  15277. this._vertexBuffer = new VertexBuffer3D(vbMemorySize, gl.DYNAMIC_DRAW);
  15278. this._vertexBuffer.vertexDeclaration = vertexDeclaration;
  15279. this._vertices = new Float32Array(this._floatCountPerVertex * lastVBVertexCount);
  15280. this._indexStride = mesh._indexBuffer.indexCount;
  15281. var indexDatas = mesh._indexBuffer.getData();
  15282. var indexCount = this._bufferMaxParticles * this._indexStride;
  15283. this._indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, indexCount, gl.STATIC_DRAW);
  15284. indices = new Uint16Array(indexCount);
  15285. memorySize = vbMemorySize + indexCount * 2;
  15286. indexOffset = 0;
  15287. for (i = 0; i < this._bufferMaxParticles; i++) {
  15288. var indexValueOffset = i * this._vertexStride;
  15289. for (j = 0, m = indexDatas.length; j < m; j++)
  15290. indices[indexOffset++] = indexValueOffset + indexDatas[j];
  15291. }
  15292. this._indexBuffer.setData(indices);
  15293. this._bufferState.bind();
  15294. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  15295. this._bufferState.applyIndexBuffer(this._indexBuffer);
  15296. this._bufferState.unBind();
  15297. }
  15298. }
  15299. else {
  15300. vertexDeclaration = VertexShurikenParticleBillboard.vertexDeclaration;
  15301. this._floatCountPerVertex = vertexDeclaration.vertexStride / 4;
  15302. this._startLifeTimeIndex = 7;
  15303. this._timeIndex = 11;
  15304. this._vertexStride = 4;
  15305. vbMemorySize = vertexDeclaration.vertexStride * this._bufferMaxParticles * this._vertexStride;
  15306. this._vertexBuffer = new VertexBuffer3D(vbMemorySize, gl.DYNAMIC_DRAW);
  15307. this._vertexBuffer.vertexDeclaration = vertexDeclaration;
  15308. this._vertices = new Float32Array(this._floatCountPerVertex * this._bufferMaxParticles * this._vertexStride);
  15309. for (i = 0; i < this._bufferMaxParticles; i++) {
  15310. perPartOffset = i * this._floatCountPerVertex * this._vertexStride;
  15311. this._vertices[perPartOffset] = -0.5;
  15312. this._vertices[perPartOffset + 1] = -0.5;
  15313. this._vertices[perPartOffset + 2] = 0;
  15314. this._vertices[perPartOffset + 3] = 1;
  15315. perPartOffset += this._floatCountPerVertex;
  15316. this._vertices[perPartOffset] = 0.5;
  15317. this._vertices[perPartOffset + 1] = -0.5;
  15318. this._vertices[perPartOffset + 2] = 1;
  15319. this._vertices[perPartOffset + 3] = 1;
  15320. perPartOffset += this._floatCountPerVertex;
  15321. this._vertices[perPartOffset] = 0.5;
  15322. this._vertices[perPartOffset + 1] = 0.5;
  15323. this._vertices[perPartOffset + 2] = 1;
  15324. this._vertices[perPartOffset + 3] = 0;
  15325. perPartOffset += this._floatCountPerVertex;
  15326. this._vertices[perPartOffset] = -0.5;
  15327. this._vertices[perPartOffset + 1] = 0.5;
  15328. this._vertices[perPartOffset + 2] = 0;
  15329. this._vertices[perPartOffset + 3] = 0;
  15330. }
  15331. this._indexStride = 6;
  15332. this._indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, this._bufferMaxParticles * 6, gl.STATIC_DRAW);
  15333. indices = new Uint16Array(this._bufferMaxParticles * 6);
  15334. for (i = 0; i < this._bufferMaxParticles; i++) {
  15335. indexOffset = i * 6;
  15336. var firstVertex = i * this._vertexStride, secondVertex = firstVertex + 2;
  15337. indices[indexOffset++] = firstVertex;
  15338. indices[indexOffset++] = secondVertex;
  15339. indices[indexOffset++] = firstVertex + 1;
  15340. indices[indexOffset++] = firstVertex;
  15341. indices[indexOffset++] = firstVertex + 3;
  15342. indices[indexOffset++] = secondVertex;
  15343. }
  15344. this._indexBuffer.setData(indices);
  15345. memorySize = vbMemorySize + this._bufferMaxParticles * 6 * 2;
  15346. this._bufferState.bind();
  15347. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  15348. this._bufferState.applyIndexBuffer(this._indexBuffer);
  15349. this._bufferState.unBind();
  15350. }
  15351. Laya.Resource._addMemory(memorySize, memorySize);
  15352. }
  15353. }
  15354. destroy() {
  15355. super.destroy();
  15356. var memorySize = this._vertexBuffer._byteLength + this._indexBuffer.indexCount * 2;
  15357. Laya.Resource._addMemory(-memorySize, -memorySize);
  15358. this._bufferState.destroy();
  15359. this._vertexBuffer.destroy();
  15360. this._indexBuffer.destroy();
  15361. this._emission.destroy();
  15362. this._bufferState = null;
  15363. this._vertexBuffer = null;
  15364. this._indexBuffer = null;
  15365. this._owner = null;
  15366. this._vertices = null;
  15367. this._indexBuffer = null;
  15368. this._emission = null;
  15369. this._shape = null;
  15370. this.startLifeTimeGradient = null;
  15371. this.startLifeTimeGradientMin = null;
  15372. this.startLifeTimeGradientMax = null;
  15373. this.startSizeConstantSeparate = null;
  15374. this.startSizeConstantMinSeparate = null;
  15375. this.startSizeConstantMaxSeparate = null;
  15376. this.startRotationConstantSeparate = null;
  15377. this.startRotationConstantMinSeparate = null;
  15378. this.startRotationConstantMaxSeparate = null;
  15379. this.startColorConstant = null;
  15380. this.startColorConstantMin = null;
  15381. this.startColorConstantMax = null;
  15382. this._velocityOverLifetime = null;
  15383. this._colorOverLifetime = null;
  15384. this._sizeOverLifetime = null;
  15385. this._rotationOverLifetime = null;
  15386. this._textureSheetAnimation = null;
  15387. }
  15388. emit(time) {
  15389. var position = ShurikenParticleSystem._tempPosition;
  15390. var direction = ShurikenParticleSystem._tempDirection;
  15391. if (this._shape && this._shape.enable) {
  15392. if (this.autoRandomSeed)
  15393. this._shape.generatePositionAndDirection(position, direction);
  15394. else
  15395. this._shape.generatePositionAndDirection(position, direction, this._rand, this._randomSeeds);
  15396. }
  15397. else {
  15398. position.x = position.y = position.z = 0;
  15399. direction.x = direction.y = 0;
  15400. direction.z = 1;
  15401. }
  15402. return this.addParticle(position, direction, time);
  15403. }
  15404. addParticle(position, direction, time) {
  15405. Vector3.normalize(direction, direction);
  15406. var nextFreeParticle = this._firstFreeElement + 1;
  15407. if (nextFreeParticle >= this._bufferMaxParticles)
  15408. nextFreeParticle = 0;
  15409. if (nextFreeParticle === this._firstRetiredElement)
  15410. return false;
  15411. ShurikenParticleData.create(this, this._ownerRender, this._owner.transform);
  15412. var particleAge = this._currentTime - time;
  15413. if (particleAge >= ShurikenParticleData.startLifeTime)
  15414. return true;
  15415. var randomVelocityX, randomVelocityY, randomVelocityZ, randomColor, randomSize, randomRotation, randomTextureAnimation;
  15416. var needRandomVelocity = this._velocityOverLifetime && this._velocityOverLifetime.enbale;
  15417. if (needRandomVelocity) {
  15418. var velocityType = this._velocityOverLifetime.velocity.type;
  15419. if (velocityType === 2 || velocityType === 3) {
  15420. if (this.autoRandomSeed) {
  15421. randomVelocityX = Math.random();
  15422. randomVelocityY = Math.random();
  15423. randomVelocityZ = Math.random();
  15424. }
  15425. else {
  15426. this._rand.seed = this._randomSeeds[9];
  15427. randomVelocityX = this._rand.getFloat();
  15428. randomVelocityY = this._rand.getFloat();
  15429. randomVelocityZ = this._rand.getFloat();
  15430. this._randomSeeds[9] = this._rand.seed;
  15431. }
  15432. }
  15433. else {
  15434. needRandomVelocity = false;
  15435. }
  15436. }
  15437. else {
  15438. needRandomVelocity = false;
  15439. }
  15440. var needRandomColor = this._colorOverLifetime && this._colorOverLifetime.enbale;
  15441. if (needRandomColor) {
  15442. var colorType = this._colorOverLifetime.color.type;
  15443. if (colorType === 3) {
  15444. if (this.autoRandomSeed) {
  15445. randomColor = Math.random();
  15446. }
  15447. else {
  15448. this._rand.seed = this._randomSeeds[10];
  15449. randomColor = this._rand.getFloat();
  15450. this._randomSeeds[10] = this._rand.seed;
  15451. }
  15452. }
  15453. else {
  15454. needRandomColor = false;
  15455. }
  15456. }
  15457. else {
  15458. needRandomColor = false;
  15459. }
  15460. var needRandomSize = this._sizeOverLifetime && this._sizeOverLifetime.enbale;
  15461. if (needRandomSize) {
  15462. var sizeType = this._sizeOverLifetime.size.type;
  15463. if (sizeType === 3) {
  15464. if (this.autoRandomSeed) {
  15465. randomSize = Math.random();
  15466. }
  15467. else {
  15468. this._rand.seed = this._randomSeeds[11];
  15469. randomSize = this._rand.getFloat();
  15470. this._randomSeeds[11] = this._rand.seed;
  15471. }
  15472. }
  15473. else {
  15474. needRandomSize = false;
  15475. }
  15476. }
  15477. else {
  15478. needRandomSize = false;
  15479. }
  15480. var needRandomRotation = this._rotationOverLifetime && this._rotationOverLifetime.enbale;
  15481. if (needRandomRotation) {
  15482. var rotationType = this._rotationOverLifetime.angularVelocity.type;
  15483. if (rotationType === 2 || rotationType === 3) {
  15484. if (this.autoRandomSeed) {
  15485. randomRotation = Math.random();
  15486. }
  15487. else {
  15488. this._rand.seed = this._randomSeeds[12];
  15489. randomRotation = this._rand.getFloat();
  15490. this._randomSeeds[12] = this._rand.seed;
  15491. }
  15492. }
  15493. else {
  15494. needRandomRotation = false;
  15495. }
  15496. }
  15497. else {
  15498. needRandomRotation = false;
  15499. }
  15500. var needRandomTextureAnimation = this._textureSheetAnimation && this._textureSheetAnimation.enable;
  15501. if (needRandomTextureAnimation) {
  15502. var textureAnimationType = this._textureSheetAnimation.frame.type;
  15503. if (textureAnimationType === 3) {
  15504. if (this.autoRandomSeed) {
  15505. randomTextureAnimation = Math.random();
  15506. }
  15507. else {
  15508. this._rand.seed = this._randomSeeds[15];
  15509. randomTextureAnimation = this._rand.getFloat();
  15510. this._randomSeeds[15] = this._rand.seed;
  15511. }
  15512. }
  15513. else {
  15514. needRandomTextureAnimation = false;
  15515. }
  15516. }
  15517. else {
  15518. needRandomTextureAnimation = false;
  15519. }
  15520. var startIndex = this._firstFreeElement * this._floatCountPerVertex * this._vertexStride;
  15521. var subU = ShurikenParticleData.startUVInfo[0];
  15522. var subV = ShurikenParticleData.startUVInfo[1];
  15523. var startU = ShurikenParticleData.startUVInfo[2];
  15524. var startV = ShurikenParticleData.startUVInfo[3];
  15525. var meshVertices, meshVertexStride, meshPosOffset, meshCorOffset, meshUVOffset, meshVertexIndex;
  15526. var render = this._ownerRender;
  15527. if (render.renderMode === 4) {
  15528. var meshVB = render.mesh._vertexBuffer;
  15529. meshVertices = meshVB.getFloat32Data();
  15530. var meshVertexDeclaration = meshVB.vertexDeclaration;
  15531. meshPosOffset = meshVertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_POSITION0)._offset / 4;
  15532. var colorElement = meshVertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_COLOR0);
  15533. meshCorOffset = colorElement ? colorElement._offset / 4 : -1;
  15534. var uvElement = meshVertexDeclaration.getVertexElementByUsage(VertexMesh.MESH_TEXTURECOORDINATE0);
  15535. meshUVOffset = uvElement ? uvElement._offset / 4 : -1;
  15536. meshVertexStride = meshVertexDeclaration.vertexStride / 4;
  15537. meshVertexIndex = 0;
  15538. }
  15539. else {
  15540. this._vertices[startIndex + 2] = startU;
  15541. this._vertices[startIndex + 3] = startV + subV;
  15542. var secondOffset = startIndex + this._floatCountPerVertex;
  15543. this._vertices[secondOffset + 2] = startU + subU;
  15544. this._vertices[secondOffset + 3] = startV + subV;
  15545. var thirdOffset = secondOffset + this._floatCountPerVertex;
  15546. this._vertices[thirdOffset + 2] = startU + subU;
  15547. this._vertices[thirdOffset + 3] = startV;
  15548. var fourthOffset = thirdOffset + this._floatCountPerVertex;
  15549. this._vertices[fourthOffset + 2] = startU;
  15550. this._vertices[fourthOffset + 3] = startV;
  15551. }
  15552. for (var i = startIndex, n = startIndex + this._floatCountPerVertex * this._vertexStride; i < n; i += this._floatCountPerVertex) {
  15553. var offset;
  15554. if (render.renderMode === 4) {
  15555. offset = i;
  15556. var vertexOffset = meshVertexStride * (meshVertexIndex++);
  15557. var meshOffset = vertexOffset + meshPosOffset;
  15558. this._vertices[offset++] = meshVertices[meshOffset++];
  15559. this._vertices[offset++] = meshVertices[meshOffset++];
  15560. this._vertices[offset++] = meshVertices[meshOffset];
  15561. if (meshCorOffset === -1) {
  15562. this._vertices[offset++] = 1.0;
  15563. this._vertices[offset++] = 1.0;
  15564. this._vertices[offset++] = 1.0;
  15565. this._vertices[offset++] = 1.0;
  15566. }
  15567. else {
  15568. meshOffset = vertexOffset + meshCorOffset;
  15569. this._vertices[offset++] = meshVertices[meshOffset++];
  15570. this._vertices[offset++] = meshVertices[meshOffset++];
  15571. this._vertices[offset++] = meshVertices[meshOffset++];
  15572. this._vertices[offset++] = meshVertices[meshOffset];
  15573. }
  15574. if (meshUVOffset === -1) {
  15575. this._vertices[offset++] = 0.0;
  15576. this._vertices[offset++] = 0.0;
  15577. }
  15578. else {
  15579. meshOffset = vertexOffset + meshUVOffset;
  15580. this._vertices[offset++] = startU + meshVertices[meshOffset++] * subU;
  15581. this._vertices[offset++] = startV + meshVertices[meshOffset] * subV;
  15582. }
  15583. }
  15584. else {
  15585. offset = i + 4;
  15586. }
  15587. this._vertices[offset++] = position.x;
  15588. this._vertices[offset++] = position.y;
  15589. this._vertices[offset++] = position.z;
  15590. this._vertices[offset++] = ShurikenParticleData.startLifeTime;
  15591. this._vertices[offset++] = direction.x;
  15592. this._vertices[offset++] = direction.y;
  15593. this._vertices[offset++] = direction.z;
  15594. this._vertices[offset++] = time;
  15595. this._vertices[offset++] = ShurikenParticleData.startColor.x;
  15596. this._vertices[offset++] = ShurikenParticleData.startColor.y;
  15597. this._vertices[offset++] = ShurikenParticleData.startColor.z;
  15598. this._vertices[offset++] = ShurikenParticleData.startColor.w;
  15599. this._vertices[offset++] = ShurikenParticleData.startSize[0];
  15600. this._vertices[offset++] = ShurikenParticleData.startSize[1];
  15601. this._vertices[offset++] = ShurikenParticleData.startSize[2];
  15602. this._vertices[offset++] = ShurikenParticleData.startRotation[0];
  15603. this._vertices[offset++] = ShurikenParticleData.startRotation[1];
  15604. this._vertices[offset++] = ShurikenParticleData.startRotation[2];
  15605. this._vertices[offset++] = ShurikenParticleData.startSpeed;
  15606. needRandomColor && (this._vertices[offset + 1] = randomColor);
  15607. needRandomSize && (this._vertices[offset + 2] = randomSize);
  15608. needRandomRotation && (this._vertices[offset + 3] = randomRotation);
  15609. needRandomTextureAnimation && (this._vertices[offset + 4] = randomTextureAnimation);
  15610. if (needRandomVelocity) {
  15611. this._vertices[offset + 5] = randomVelocityX;
  15612. this._vertices[offset + 6] = randomVelocityY;
  15613. this._vertices[offset + 7] = randomVelocityZ;
  15614. }
  15615. switch (this.simulationSpace) {
  15616. case 0:
  15617. offset += 8;
  15618. this._vertices[offset++] = ShurikenParticleData.simulationWorldPostion[0];
  15619. this._vertices[offset++] = ShurikenParticleData.simulationWorldPostion[1];
  15620. this._vertices[offset++] = ShurikenParticleData.simulationWorldPostion[2];
  15621. this._vertices[offset++] = ShurikenParticleData.simulationWorldRotation[0];
  15622. this._vertices[offset++] = ShurikenParticleData.simulationWorldRotation[1];
  15623. this._vertices[offset++] = ShurikenParticleData.simulationWorldRotation[2];
  15624. this._vertices[offset++] = ShurikenParticleData.simulationWorldRotation[3];
  15625. break;
  15626. case 1:
  15627. break;
  15628. default:
  15629. throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.");
  15630. }
  15631. }
  15632. this._firstFreeElement = nextFreeParticle;
  15633. return true;
  15634. }
  15635. addNewParticlesToVertexBuffer() {
  15636. var start;
  15637. var byteStride = this._vertexStride * this._floatCountPerVertex * 4;
  15638. if (this._firstNewElement < this._firstFreeElement) {
  15639. start = this._firstNewElement * byteStride;
  15640. this._vertexBuffer.setData(this._vertices.buffer, start, start, (this._firstFreeElement - this._firstNewElement) * byteStride);
  15641. }
  15642. else {
  15643. start = this._firstNewElement * byteStride;
  15644. this._vertexBuffer.setData(this._vertices.buffer, start, start, (this._bufferMaxParticles - this._firstNewElement) * byteStride);
  15645. if (this._firstFreeElement > 0) {
  15646. this._vertexBuffer.setData(this._vertices.buffer, 0, 0, this._firstFreeElement * byteStride);
  15647. }
  15648. }
  15649. this._firstNewElement = this._firstFreeElement;
  15650. }
  15651. _getType() {
  15652. return ShurikenParticleSystem._type;
  15653. }
  15654. _prepareRender(state) {
  15655. this._updateEmission();
  15656. if (this._firstNewElement != this._firstFreeElement)
  15657. this.addNewParticlesToVertexBuffer();
  15658. this._drawCounter++;
  15659. if (this._firstActiveElement != this._firstFreeElement)
  15660. return true;
  15661. else
  15662. return false;
  15663. }
  15664. _render(state) {
  15665. this._bufferState.bind();
  15666. var indexCount;
  15667. var gl = Laya.LayaGL.instance;
  15668. if (this._firstActiveElement < this._firstFreeElement) {
  15669. indexCount = (this._firstFreeElement - this._firstActiveElement) * this._indexStride;
  15670. gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, 2 * this._firstActiveElement * this._indexStride);
  15671. Laya.Stat.trianglesFaces += indexCount / 3;
  15672. Laya.Stat.renderBatches++;
  15673. }
  15674. else {
  15675. indexCount = (this._bufferMaxParticles - this._firstActiveElement) * this._indexStride;
  15676. gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, 2 * this._firstActiveElement * this._indexStride);
  15677. Laya.Stat.trianglesFaces += indexCount / 3;
  15678. Laya.Stat.renderBatches++;
  15679. if (this._firstFreeElement > 0) {
  15680. indexCount = this._firstFreeElement * this._indexStride;
  15681. gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, 0);
  15682. Laya.Stat.trianglesFaces += indexCount / 3;
  15683. Laya.Stat.renderBatches++;
  15684. }
  15685. }
  15686. }
  15687. play() {
  15688. this._burstsIndex = 0;
  15689. this._isEmitting = true;
  15690. this._isPlaying = true;
  15691. this._isPaused = false;
  15692. this._emissionTime = 0;
  15693. this._totalDelayTime = 0;
  15694. if (!this.autoRandomSeed) {
  15695. for (var i = 0, n = this._randomSeeds.length; i < n; i++)
  15696. this._randomSeeds[i] = this.randomSeed[0] + ShurikenParticleSystem._RANDOMOFFSET[i];
  15697. }
  15698. switch (this.startDelayType) {
  15699. case 0:
  15700. this._playStartDelay = this.startDelay;
  15701. break;
  15702. case 1:
  15703. if (this.autoRandomSeed) {
  15704. this._playStartDelay = Laya.MathUtil.lerp(this.startDelayMin, this.startDelayMax, Math.random());
  15705. }
  15706. else {
  15707. this._rand.seed = this._randomSeeds[2];
  15708. this._playStartDelay = Laya.MathUtil.lerp(this.startDelayMin, this.startDelayMax, this._rand.getFloat());
  15709. this._randomSeeds[2] = this._rand.seed;
  15710. }
  15711. break;
  15712. default:
  15713. throw new Error("Utils3D: startDelayType is invalid.");
  15714. }
  15715. this._frameRateTime = this._currentTime + this._playStartDelay;
  15716. this._startUpdateLoopCount = Laya.Stat.loopCount;
  15717. }
  15718. pause() {
  15719. this._isPaused = true;
  15720. }
  15721. simulate(time, restart = true) {
  15722. this._simulateUpdate = true;
  15723. if (restart) {
  15724. this._updateParticlesSimulationRestart(time);
  15725. }
  15726. else {
  15727. this._isPaused = false;
  15728. this._updateParticles(time);
  15729. }
  15730. this.pause();
  15731. }
  15732. stop() {
  15733. this._burstsIndex = 0;
  15734. this._isEmitting = false;
  15735. this._emissionTime = 0;
  15736. }
  15737. cloneTo(destObject) {
  15738. var dest = destObject;
  15739. dest.duration = this.duration;
  15740. dest.looping = this.looping;
  15741. dest.prewarm = this.prewarm;
  15742. dest.startDelayType = this.startDelayType;
  15743. dest.startDelay = this.startDelay;
  15744. dest.startDelayMin = this.startDelayMin;
  15745. dest.startDelayMax = this.startDelayMax;
  15746. dest._maxStartLifetime = this._maxStartLifetime;
  15747. dest.startLifetimeType = this.startLifetimeType;
  15748. dest.startLifetimeConstant = this.startLifetimeConstant;
  15749. this.startLifeTimeGradient.cloneTo(dest.startLifeTimeGradient);
  15750. dest.startLifetimeConstantMin = this.startLifetimeConstantMin;
  15751. dest.startLifetimeConstantMax = this.startLifetimeConstantMax;
  15752. this.startLifeTimeGradientMin.cloneTo(dest.startLifeTimeGradientMin);
  15753. this.startLifeTimeGradientMax.cloneTo(dest.startLifeTimeGradientMax);
  15754. dest.startSpeedType = this.startSpeedType;
  15755. dest.startSpeedConstant = this.startSpeedConstant;
  15756. dest.startSpeedConstantMin = this.startSpeedConstantMin;
  15757. dest.startSpeedConstantMax = this.startSpeedConstantMax;
  15758. dest.threeDStartSize = this.threeDStartSize;
  15759. dest.startSizeType = this.startSizeType;
  15760. dest.startSizeConstant = this.startSizeConstant;
  15761. this.startSizeConstantSeparate.cloneTo(dest.startSizeConstantSeparate);
  15762. dest.startSizeConstantMin = this.startSizeConstantMin;
  15763. dest.startSizeConstantMax = this.startSizeConstantMax;
  15764. this.startSizeConstantMinSeparate.cloneTo(dest.startSizeConstantMinSeparate);
  15765. this.startSizeConstantMaxSeparate.cloneTo(dest.startSizeConstantMaxSeparate);
  15766. dest.threeDStartRotation = this.threeDStartRotation;
  15767. dest.startRotationType = this.startRotationType;
  15768. dest.startRotationConstant = this.startRotationConstant;
  15769. this.startRotationConstantSeparate.cloneTo(dest.startRotationConstantSeparate);
  15770. dest.startRotationConstantMin = this.startRotationConstantMin;
  15771. dest.startRotationConstantMax = this.startRotationConstantMax;
  15772. this.startRotationConstantMinSeparate.cloneTo(dest.startRotationConstantMinSeparate);
  15773. this.startRotationConstantMaxSeparate.cloneTo(dest.startRotationConstantMaxSeparate);
  15774. dest.randomizeRotationDirection = this.randomizeRotationDirection;
  15775. dest.startColorType = this.startColorType;
  15776. this.startColorConstant.cloneTo(dest.startColorConstant);
  15777. this.startColorConstantMin.cloneTo(dest.startColorConstantMin);
  15778. this.startColorConstantMax.cloneTo(dest.startColorConstantMax);
  15779. dest.gravityModifier = this.gravityModifier;
  15780. dest.simulationSpace = this.simulationSpace;
  15781. dest.scaleMode = this.scaleMode;
  15782. dest.playOnAwake = this.playOnAwake;
  15783. dest.autoRandomSeed = this.autoRandomSeed;
  15784. dest.randomSeed[0] = this.randomSeed[0];
  15785. dest.maxParticles = this.maxParticles;
  15786. (this._emission) && (dest._emission = this._emission.clone());
  15787. (this.shape) && (dest.shape = this.shape.clone());
  15788. (this.velocityOverLifetime) && (dest.velocityOverLifetime = this.velocityOverLifetime.clone());
  15789. (this.colorOverLifetime) && (dest.colorOverLifetime = this.colorOverLifetime.clone());
  15790. (this.sizeOverLifetime) && (dest.sizeOverLifetime = this.sizeOverLifetime.clone());
  15791. (this.rotationOverLifetime) && (dest.rotationOverLifetime = this.rotationOverLifetime.clone());
  15792. (this.textureSheetAnimation) && (dest.textureSheetAnimation = this.textureSheetAnimation.clone());
  15793. dest.isPerformanceMode = this.isPerformanceMode;
  15794. dest._isEmitting = this._isEmitting;
  15795. dest._isPlaying = this._isPlaying;
  15796. dest._isPaused = this._isPaused;
  15797. dest._playStartDelay = this._playStartDelay;
  15798. dest._frameRateTime = this._frameRateTime;
  15799. dest._emissionTime = this._emissionTime;
  15800. dest._totalDelayTime = this._totalDelayTime;
  15801. dest._burstsIndex = this._burstsIndex;
  15802. }
  15803. clone() {
  15804. var dest = new ShurikenParticleSystem(null);
  15805. this.cloneTo(dest);
  15806. return dest;
  15807. }
  15808. }
  15809. ShurikenParticleSystem._RANDOMOFFSET = new Uint32Array([0x23571a3e, 0xc34f56fe, 0x13371337, 0x12460f3b, 0x6aed452e, 0xdec4aea1, 0x96aa4de3, 0x8d2c8431, 0xf3857f6f, 0xe0fbd834, 0x13740583, 0x591bc05c, 0x40eb95e4, 0xbc524e5f, 0xaf502044, 0xa614b381, 0x1034e524, 0xfc524e5f]);
  15810. ShurikenParticleSystem.halfKSqrtOf2 = 1.42 * 0.5;
  15811. ShurikenParticleSystem._maxElapsedTime = 1.0 / 3.0;
  15812. ShurikenParticleSystem._tempVector30 = new Vector3();
  15813. ShurikenParticleSystem._tempVector31 = new Vector3();
  15814. ShurikenParticleSystem._tempVector32 = new Vector3();
  15815. ShurikenParticleSystem._tempVector33 = new Vector3();
  15816. ShurikenParticleSystem._tempVector34 = new Vector3();
  15817. ShurikenParticleSystem._tempVector35 = new Vector3();
  15818. ShurikenParticleSystem._tempVector36 = new Vector3();
  15819. ShurikenParticleSystem._tempVector37 = new Vector3();
  15820. ShurikenParticleSystem._tempVector38 = new Vector3();
  15821. ShurikenParticleSystem._tempVector39 = new Vector3();
  15822. ShurikenParticleSystem._tempPosition = new Vector3();
  15823. ShurikenParticleSystem._tempDirection = new Vector3();
  15824. ShurikenParticleSystem._type = GeometryElement._typeCounter++;
  15825. class Burst {
  15826. get time() {
  15827. return this._time;
  15828. }
  15829. get minCount() {
  15830. return this._minCount;
  15831. }
  15832. get maxCount() {
  15833. return this._maxCount;
  15834. }
  15835. constructor(time, minCount, maxCount) {
  15836. this._time = time;
  15837. this._minCount = minCount;
  15838. this._maxCount = maxCount;
  15839. }
  15840. cloneTo(destObject) {
  15841. var destBurst = destObject;
  15842. destBurst._time = this._time;
  15843. destBurst._minCount = this._minCount;
  15844. destBurst._maxCount = this._maxCount;
  15845. }
  15846. clone() {
  15847. var destBurst = new Burst(this._time, this._minCount, this._maxCount);
  15848. this.cloneTo(destBurst);
  15849. return destBurst;
  15850. }
  15851. }
  15852. class GradientColor {
  15853. constructor() {
  15854. this._type = 0;
  15855. this._constant = null;
  15856. this._constantMin = null;
  15857. this._constantMax = null;
  15858. this._gradient = null;
  15859. this._gradientMin = null;
  15860. this._gradientMax = null;
  15861. }
  15862. static createByConstant(constant) {
  15863. var gradientColor = new GradientColor();
  15864. gradientColor._type = 0;
  15865. gradientColor._constant = constant;
  15866. return gradientColor;
  15867. }
  15868. static createByGradient(gradient) {
  15869. var gradientColor = new GradientColor();
  15870. gradientColor._type = 1;
  15871. gradientColor._gradient = gradient;
  15872. return gradientColor;
  15873. }
  15874. static createByRandomTwoConstant(minConstant, maxConstant) {
  15875. var gradientColor = new GradientColor();
  15876. gradientColor._type = 2;
  15877. gradientColor._constantMin = minConstant;
  15878. gradientColor._constantMax = maxConstant;
  15879. return gradientColor;
  15880. }
  15881. static createByRandomTwoGradient(minGradient, maxGradient) {
  15882. var gradientColor = new GradientColor();
  15883. gradientColor._type = 3;
  15884. gradientColor._gradientMin = minGradient;
  15885. gradientColor._gradientMax = maxGradient;
  15886. return gradientColor;
  15887. }
  15888. get type() {
  15889. return this._type;
  15890. }
  15891. get constant() {
  15892. return this._constant;
  15893. }
  15894. get constantMin() {
  15895. return this._constantMin;
  15896. }
  15897. get constantMax() {
  15898. return this._constantMax;
  15899. }
  15900. get gradient() {
  15901. return this._gradient;
  15902. }
  15903. get gradientMin() {
  15904. return this._gradientMin;
  15905. }
  15906. get gradientMax() {
  15907. return this._gradientMax;
  15908. }
  15909. cloneTo(destObject) {
  15910. var destGradientColor = destObject;
  15911. destGradientColor._type = this._type;
  15912. this._constant.cloneTo(destGradientColor._constant);
  15913. this._constantMin.cloneTo(destGradientColor._constantMin);
  15914. this._constantMax.cloneTo(destGradientColor._constantMax);
  15915. this._gradient.cloneTo(destGradientColor._gradient);
  15916. this._gradientMin.cloneTo(destGradientColor._gradientMin);
  15917. this._gradientMax.cloneTo(destGradientColor._gradientMax);
  15918. }
  15919. clone() {
  15920. var destGradientColor = new GradientColor();
  15921. this.cloneTo(destGradientColor);
  15922. return destGradientColor;
  15923. }
  15924. }
  15925. class ColorOverLifetime {
  15926. get color() {
  15927. return this._color;
  15928. }
  15929. constructor(color) {
  15930. this._color = color;
  15931. }
  15932. cloneTo(destObject) {
  15933. var destColorOverLifetime = destObject;
  15934. this._color.cloneTo(destColorOverLifetime._color);
  15935. destColorOverLifetime.enbale = this.enbale;
  15936. }
  15937. clone() {
  15938. var destColor;
  15939. switch (this._color.type) {
  15940. case 0:
  15941. destColor = GradientColor.createByConstant(this._color.constant.clone());
  15942. break;
  15943. case 1:
  15944. destColor = GradientColor.createByGradient(this._color.gradient.clone());
  15945. break;
  15946. case 2:
  15947. destColor = GradientColor.createByRandomTwoConstant(this._color.constantMin.clone(), this._color.constantMax.clone());
  15948. break;
  15949. case 3:
  15950. destColor = GradientColor.createByRandomTwoGradient(this._color.gradientMin.clone(), this._color.gradientMax.clone());
  15951. break;
  15952. }
  15953. var destColorOverLifetime = new ColorOverLifetime(destColor);
  15954. destColorOverLifetime.enbale = this.enbale;
  15955. return destColorOverLifetime;
  15956. }
  15957. }
  15958. class FrameOverTime {
  15959. constructor() {
  15960. this._type = 0;
  15961. this._constant = 0;
  15962. this._overTime = null;
  15963. this._constantMin = 0;
  15964. this._constantMax = 0;
  15965. this._overTimeMin = null;
  15966. this._overTimeMax = null;
  15967. }
  15968. static createByConstant(constant) {
  15969. var rotationOverLifetime = new FrameOverTime();
  15970. rotationOverLifetime._type = 0;
  15971. rotationOverLifetime._constant = constant;
  15972. return rotationOverLifetime;
  15973. }
  15974. static createByOverTime(overTime) {
  15975. var rotationOverLifetime = new FrameOverTime();
  15976. rotationOverLifetime._type = 1;
  15977. rotationOverLifetime._overTime = overTime;
  15978. return rotationOverLifetime;
  15979. }
  15980. static createByRandomTwoConstant(constantMin, constantMax) {
  15981. var rotationOverLifetime = new FrameOverTime();
  15982. rotationOverLifetime._type = 2;
  15983. rotationOverLifetime._constantMin = constantMin;
  15984. rotationOverLifetime._constantMax = constantMax;
  15985. return rotationOverLifetime;
  15986. }
  15987. static createByRandomTwoOverTime(gradientFrameMin, gradientFrameMax) {
  15988. var rotationOverLifetime = new FrameOverTime();
  15989. rotationOverLifetime._type = 3;
  15990. rotationOverLifetime._overTimeMin = gradientFrameMin;
  15991. rotationOverLifetime._overTimeMax = gradientFrameMax;
  15992. return rotationOverLifetime;
  15993. }
  15994. get type() {
  15995. return this._type;
  15996. }
  15997. get constant() {
  15998. return this._constant;
  15999. }
  16000. get frameOverTimeData() {
  16001. return this._overTime;
  16002. }
  16003. get constantMin() {
  16004. return this._constantMin;
  16005. }
  16006. get constantMax() {
  16007. return this._constantMax;
  16008. }
  16009. get frameOverTimeDataMin() {
  16010. return this._overTimeMin;
  16011. }
  16012. get frameOverTimeDataMax() {
  16013. return this._overTimeMax;
  16014. }
  16015. cloneTo(destObject) {
  16016. var destFrameOverTime = destObject;
  16017. destFrameOverTime._type = this._type;
  16018. destFrameOverTime._constant = this._constant;
  16019. (this._overTime) && (this._overTime.cloneTo(destFrameOverTime._overTime));
  16020. destFrameOverTime._constantMin = this._constantMin;
  16021. destFrameOverTime._constantMax = this._constantMax;
  16022. (this._overTimeMin) && (this._overTimeMin.cloneTo(destFrameOverTime._overTimeMin));
  16023. (this._overTimeMax) && (this._overTimeMax.cloneTo(destFrameOverTime._overTimeMax));
  16024. }
  16025. clone() {
  16026. var destFrameOverTime = new FrameOverTime();
  16027. this.cloneTo(destFrameOverTime);
  16028. return destFrameOverTime;
  16029. }
  16030. }
  16031. class GradientAngularVelocity {
  16032. constructor() {
  16033. this._type = 0;
  16034. this._separateAxes = false;
  16035. this._constant = 0;
  16036. this._constantSeparate = null;
  16037. this._gradient = null;
  16038. this._gradientX = null;
  16039. this._gradientY = null;
  16040. this._gradientZ = null;
  16041. this._gradientW = null;
  16042. this._constantMin = 0;
  16043. this._constantMax = 0;
  16044. this._constantMinSeparate = null;
  16045. this._constantMaxSeparate = null;
  16046. this._gradientMin = null;
  16047. this._gradientMax = null;
  16048. this._gradientXMin = null;
  16049. this._gradientXMax = null;
  16050. this._gradientYMin = null;
  16051. this._gradientYMax = null;
  16052. this._gradientZMin = null;
  16053. this._gradientZMax = null;
  16054. this._gradientWMin = null;
  16055. this._gradientWMax = null;
  16056. }
  16057. static createByConstant(constant) {
  16058. var gradientAngularVelocity = new GradientAngularVelocity();
  16059. gradientAngularVelocity._type = 0;
  16060. gradientAngularVelocity._separateAxes = false;
  16061. gradientAngularVelocity._constant = constant;
  16062. return gradientAngularVelocity;
  16063. }
  16064. static createByConstantSeparate(separateConstant) {
  16065. var gradientAngularVelocity = new GradientAngularVelocity();
  16066. gradientAngularVelocity._type = 0;
  16067. gradientAngularVelocity._separateAxes = true;
  16068. gradientAngularVelocity._constantSeparate = separateConstant;
  16069. return gradientAngularVelocity;
  16070. }
  16071. static createByGradient(gradient) {
  16072. var gradientAngularVelocity = new GradientAngularVelocity();
  16073. gradientAngularVelocity._type = 1;
  16074. gradientAngularVelocity._separateAxes = false;
  16075. gradientAngularVelocity._gradient = gradient;
  16076. return gradientAngularVelocity;
  16077. }
  16078. static createByGradientSeparate(gradientX, gradientY, gradientZ) {
  16079. var gradientAngularVelocity = new GradientAngularVelocity();
  16080. gradientAngularVelocity._type = 1;
  16081. gradientAngularVelocity._separateAxes = true;
  16082. gradientAngularVelocity._gradientX = gradientX;
  16083. gradientAngularVelocity._gradientY = gradientY;
  16084. gradientAngularVelocity._gradientZ = gradientZ;
  16085. return gradientAngularVelocity;
  16086. }
  16087. static createByRandomTwoConstant(constantMin, constantMax) {
  16088. var gradientAngularVelocity = new GradientAngularVelocity();
  16089. gradientAngularVelocity._type = 2;
  16090. gradientAngularVelocity._separateAxes = false;
  16091. gradientAngularVelocity._constantMin = constantMin;
  16092. gradientAngularVelocity._constantMax = constantMax;
  16093. return gradientAngularVelocity;
  16094. }
  16095. static createByRandomTwoConstantSeparate(separateConstantMin, separateConstantMax) {
  16096. var gradientAngularVelocity = new GradientAngularVelocity();
  16097. gradientAngularVelocity._type = 2;
  16098. gradientAngularVelocity._separateAxes = true;
  16099. gradientAngularVelocity._constantMinSeparate = separateConstantMin;
  16100. gradientAngularVelocity._constantMaxSeparate = separateConstantMax;
  16101. return gradientAngularVelocity;
  16102. }
  16103. static createByRandomTwoGradient(gradientMin, gradientMax) {
  16104. var gradientAngularVelocity = new GradientAngularVelocity();
  16105. gradientAngularVelocity._type = 3;
  16106. gradientAngularVelocity._separateAxes = false;
  16107. gradientAngularVelocity._gradientMin = gradientMin;
  16108. gradientAngularVelocity._gradientMax = gradientMax;
  16109. return gradientAngularVelocity;
  16110. }
  16111. static createByRandomTwoGradientSeparate(gradientXMin, gradientXMax, gradientYMin, gradientYMax, gradientZMin, gradientZMax, gradientWMin, gradientWMax) {
  16112. var gradientAngularVelocity = new GradientAngularVelocity();
  16113. gradientAngularVelocity._type = 3;
  16114. gradientAngularVelocity._separateAxes = true;
  16115. gradientAngularVelocity._gradientXMin = gradientXMin;
  16116. gradientAngularVelocity._gradientXMax = gradientXMax;
  16117. gradientAngularVelocity._gradientYMin = gradientYMin;
  16118. gradientAngularVelocity._gradientYMax = gradientYMax;
  16119. gradientAngularVelocity._gradientZMin = gradientZMin;
  16120. gradientAngularVelocity._gradientZMax = gradientZMax;
  16121. gradientAngularVelocity._gradientWMin = gradientWMin;
  16122. gradientAngularVelocity._gradientWMax = gradientWMax;
  16123. return gradientAngularVelocity;
  16124. }
  16125. get type() {
  16126. return this._type;
  16127. }
  16128. get separateAxes() {
  16129. return this._separateAxes;
  16130. }
  16131. get constant() {
  16132. return this._constant;
  16133. }
  16134. get constantSeparate() {
  16135. return this._constantSeparate;
  16136. }
  16137. get gradient() {
  16138. return this._gradient;
  16139. }
  16140. get gradientX() {
  16141. return this._gradientX;
  16142. }
  16143. get gradientY() {
  16144. return this._gradientY;
  16145. }
  16146. get gradientZ() {
  16147. return this._gradientZ;
  16148. }
  16149. get gradientW() {
  16150. return this._gradientW;
  16151. }
  16152. get constantMin() {
  16153. return this._constantMin;
  16154. }
  16155. get constantMax() {
  16156. return this._constantMax;
  16157. }
  16158. get constantMinSeparate() {
  16159. return this._constantMinSeparate;
  16160. }
  16161. get constantMaxSeparate() {
  16162. return this._constantMaxSeparate;
  16163. }
  16164. get gradientMin() {
  16165. return this._gradientMin;
  16166. }
  16167. get gradientMax() {
  16168. return this._gradientMax;
  16169. }
  16170. get gradientXMin() {
  16171. return this._gradientXMin;
  16172. }
  16173. get gradientXMax() {
  16174. return this._gradientXMax;
  16175. }
  16176. get gradientYMin() {
  16177. return this._gradientYMin;
  16178. }
  16179. get gradientYMax() {
  16180. return this._gradientYMax;
  16181. }
  16182. get gradientZMin() {
  16183. return this._gradientZMin;
  16184. }
  16185. get gradientZMax() {
  16186. return this._gradientZMax;
  16187. }
  16188. get gradientWMin() {
  16189. return this._gradientWMin;
  16190. }
  16191. get gradientWMax() {
  16192. return this._gradientWMax;
  16193. }
  16194. cloneTo(destObject) {
  16195. var destGradientAngularVelocity = destObject;
  16196. destGradientAngularVelocity._type = this._type;
  16197. destGradientAngularVelocity._separateAxes = this._separateAxes;
  16198. destGradientAngularVelocity._constant = this._constant;
  16199. this._constantSeparate.cloneTo(destGradientAngularVelocity._constantSeparate);
  16200. this._gradient.cloneTo(destGradientAngularVelocity._gradient);
  16201. this._gradientX.cloneTo(destGradientAngularVelocity._gradientX);
  16202. this._gradientY.cloneTo(destGradientAngularVelocity._gradientY);
  16203. this._gradientZ.cloneTo(destGradientAngularVelocity._gradientZ);
  16204. destGradientAngularVelocity._constantMin = this._constantMin;
  16205. destGradientAngularVelocity._constantMax = this._constantMax;
  16206. this._constantMinSeparate.cloneTo(destGradientAngularVelocity._constantMinSeparate);
  16207. this._constantMaxSeparate.cloneTo(destGradientAngularVelocity._constantMaxSeparate);
  16208. this._gradientMin.cloneTo(destGradientAngularVelocity._gradientMin);
  16209. this._gradientMax.cloneTo(destGradientAngularVelocity._gradientMax);
  16210. this._gradientXMin.cloneTo(destGradientAngularVelocity._gradientXMin);
  16211. this._gradientXMax.cloneTo(destGradientAngularVelocity._gradientXMax);
  16212. this._gradientYMin.cloneTo(destGradientAngularVelocity._gradientYMin);
  16213. this._gradientYMax.cloneTo(destGradientAngularVelocity._gradientYMax);
  16214. this._gradientZMin.cloneTo(destGradientAngularVelocity._gradientZMin);
  16215. this._gradientZMax.cloneTo(destGradientAngularVelocity._gradientZMax);
  16216. }
  16217. clone() {
  16218. var destGradientAngularVelocity = new GradientAngularVelocity();
  16219. this.cloneTo(destGradientAngularVelocity);
  16220. return destGradientAngularVelocity;
  16221. }
  16222. }
  16223. class GradientDataInt {
  16224. constructor() {
  16225. this._currentLength = 0;
  16226. this._elements = new Float32Array(8);
  16227. }
  16228. get gradientCount() {
  16229. return this._currentLength / 2;
  16230. }
  16231. add(key, value) {
  16232. if (this._currentLength < 8) {
  16233. if ((this._currentLength === 6) && ((key !== 1))) {
  16234. key = 1;
  16235. console.log("Warning:the forth key is be force set to 1.");
  16236. }
  16237. this._elements[this._currentLength++] = key;
  16238. this._elements[this._currentLength++] = value;
  16239. }
  16240. else {
  16241. console.log("Warning:data count must lessEqual than 4");
  16242. }
  16243. }
  16244. cloneTo(destObject) {
  16245. var destGradientDataInt = destObject;
  16246. destGradientDataInt._currentLength = this._currentLength;
  16247. var destElements = destGradientDataInt._elements;
  16248. for (var i = 0, n = this._elements.length; i < n; i++) {
  16249. destElements[i] = this._elements[i];
  16250. }
  16251. }
  16252. clone() {
  16253. var destGradientDataInt = new GradientDataInt();
  16254. this.cloneTo(destGradientDataInt);
  16255. return destGradientDataInt;
  16256. }
  16257. }
  16258. class GradientSize {
  16259. constructor() {
  16260. this._type = 0;
  16261. this._separateAxes = false;
  16262. this._gradient = null;
  16263. this._gradientX = null;
  16264. this._gradientY = null;
  16265. this._gradientZ = null;
  16266. this._constantMin = 0;
  16267. this._constantMax = 0;
  16268. this._constantMinSeparate = null;
  16269. this._constantMaxSeparate = null;
  16270. this._gradientMin = null;
  16271. this._gradientMax = null;
  16272. this._gradientXMin = null;
  16273. this._gradientXMax = null;
  16274. this._gradientYMin = null;
  16275. this._gradientYMax = null;
  16276. this._gradientZMin = null;
  16277. this._gradientZMax = null;
  16278. }
  16279. static createByGradient(gradient) {
  16280. var gradientSize = new GradientSize();
  16281. gradientSize._type = 0;
  16282. gradientSize._separateAxes = false;
  16283. gradientSize._gradient = gradient;
  16284. return gradientSize;
  16285. }
  16286. static createByGradientSeparate(gradientX, gradientY, gradientZ) {
  16287. var gradientSize = new GradientSize();
  16288. gradientSize._type = 0;
  16289. gradientSize._separateAxes = true;
  16290. gradientSize._gradientX = gradientX;
  16291. gradientSize._gradientY = gradientY;
  16292. gradientSize._gradientZ = gradientZ;
  16293. return gradientSize;
  16294. }
  16295. static createByRandomTwoConstant(constantMin, constantMax) {
  16296. var gradientSize = new GradientSize();
  16297. gradientSize._type = 1;
  16298. gradientSize._separateAxes = false;
  16299. gradientSize._constantMin = constantMin;
  16300. gradientSize._constantMax = constantMax;
  16301. return gradientSize;
  16302. }
  16303. static createByRandomTwoConstantSeparate(constantMinSeparate, constantMaxSeparate) {
  16304. var gradientSize = new GradientSize();
  16305. gradientSize._type = 1;
  16306. gradientSize._separateAxes = true;
  16307. gradientSize._constantMinSeparate = constantMinSeparate;
  16308. gradientSize._constantMaxSeparate = constantMaxSeparate;
  16309. return gradientSize;
  16310. }
  16311. static createByRandomTwoGradient(gradientMin, gradientMax) {
  16312. var gradientSize = new GradientSize();
  16313. gradientSize._type = 2;
  16314. gradientSize._separateAxes = false;
  16315. gradientSize._gradientMin = gradientMin;
  16316. gradientSize._gradientMax = gradientMax;
  16317. return gradientSize;
  16318. }
  16319. static createByRandomTwoGradientSeparate(gradientXMin, gradientXMax, gradientYMin, gradientYMax, gradientZMin, gradientZMax) {
  16320. var gradientSize = new GradientSize();
  16321. gradientSize._type = 2;
  16322. gradientSize._separateAxes = true;
  16323. gradientSize._gradientXMin = gradientXMin;
  16324. gradientSize._gradientXMax = gradientXMax;
  16325. gradientSize._gradientYMin = gradientYMin;
  16326. gradientSize._gradientYMax = gradientYMax;
  16327. gradientSize._gradientZMin = gradientZMin;
  16328. gradientSize._gradientZMax = gradientZMax;
  16329. return gradientSize;
  16330. }
  16331. get type() {
  16332. return this._type;
  16333. }
  16334. get separateAxes() {
  16335. return this._separateAxes;
  16336. }
  16337. get gradient() {
  16338. return this._gradient;
  16339. }
  16340. get gradientX() {
  16341. return this._gradientX;
  16342. }
  16343. get gradientY() {
  16344. return this._gradientY;
  16345. }
  16346. get gradientZ() {
  16347. return this._gradientZ;
  16348. }
  16349. get constantMin() {
  16350. return this._constantMin;
  16351. }
  16352. get constantMax() {
  16353. return this._constantMax;
  16354. }
  16355. get constantMinSeparate() {
  16356. return this._constantMinSeparate;
  16357. }
  16358. get constantMaxSeparate() {
  16359. return this._constantMaxSeparate;
  16360. }
  16361. get gradientMin() {
  16362. return this._gradientMin;
  16363. }
  16364. get gradientMax() {
  16365. return this._gradientMax;
  16366. }
  16367. get gradientXMin() {
  16368. return this._gradientXMin;
  16369. }
  16370. get gradientXMax() {
  16371. return this._gradientXMax;
  16372. }
  16373. get gradientYMin() {
  16374. return this._gradientYMin;
  16375. }
  16376. get gradientYMax() {
  16377. return this._gradientYMax;
  16378. }
  16379. get gradientZMin() {
  16380. return this._gradientZMin;
  16381. }
  16382. get gradientZMax() {
  16383. return this._gradientZMax;
  16384. }
  16385. getMaxSizeInGradient() {
  16386. var i, n;
  16387. var maxSize = -Number.MAX_VALUE;
  16388. switch (this._type) {
  16389. case 0:
  16390. if (this._separateAxes) {
  16391. for (i = 0, n = this._gradientX.gradientCount; i < n; i++)
  16392. maxSize = Math.max(maxSize, this._gradientX.getValueByIndex(i));
  16393. for (i = 0, n = this._gradientY.gradientCount; i < n; i++)
  16394. maxSize = Math.max(maxSize, this._gradientY.getValueByIndex(i));
  16395. }
  16396. else {
  16397. for (i = 0, n = this._gradient.gradientCount; i < n; i++)
  16398. maxSize = Math.max(maxSize, this._gradient.getValueByIndex(i));
  16399. }
  16400. break;
  16401. case 1:
  16402. if (this._separateAxes) {
  16403. maxSize = Math.max(this._constantMinSeparate.x, this._constantMaxSeparate.x);
  16404. maxSize = Math.max(maxSize, this._constantMinSeparate.y);
  16405. maxSize = Math.max(maxSize, this._constantMaxSeparate.y);
  16406. }
  16407. else {
  16408. maxSize = Math.max(this._constantMin, this._constantMax);
  16409. }
  16410. break;
  16411. case 2:
  16412. if (this._separateAxes) {
  16413. for (i = 0, n = this._gradientXMin.gradientCount; i < n; i++)
  16414. maxSize = Math.max(maxSize, this._gradientXMin.getValueByIndex(i));
  16415. for (i = 0, n = this._gradientXMax.gradientCount; i < n; i++)
  16416. maxSize = Math.max(maxSize, this._gradientXMax.getValueByIndex(i));
  16417. for (i = 0, n = this._gradientYMin.gradientCount; i < n; i++)
  16418. maxSize = Math.max(maxSize, this._gradientYMin.getValueByIndex(i));
  16419. for (i = 0, n = this._gradientZMax.gradientCount; i < n; i++)
  16420. maxSize = Math.max(maxSize, this._gradientZMax.getValueByIndex(i));
  16421. }
  16422. else {
  16423. for (i = 0, n = this._gradientMin.gradientCount; i < n; i++)
  16424. maxSize = Math.max(maxSize, this._gradientMin.getValueByIndex(i));
  16425. for (i = 0, n = this._gradientMax.gradientCount; i < n; i++)
  16426. maxSize = Math.max(maxSize, this._gradientMax.getValueByIndex(i));
  16427. }
  16428. break;
  16429. }
  16430. return maxSize;
  16431. }
  16432. cloneTo(destObject) {
  16433. var destGradientSize = destObject;
  16434. destGradientSize._type = this._type;
  16435. destGradientSize._separateAxes = this._separateAxes;
  16436. this._gradient.cloneTo(destGradientSize._gradient);
  16437. this._gradientX.cloneTo(destGradientSize._gradientX);
  16438. this._gradientY.cloneTo(destGradientSize._gradientY);
  16439. this._gradientZ.cloneTo(destGradientSize._gradientZ);
  16440. destGradientSize._constantMin = this._constantMin;
  16441. destGradientSize._constantMax = this._constantMax;
  16442. this._constantMinSeparate.cloneTo(destGradientSize._constantMinSeparate);
  16443. this._constantMaxSeparate.cloneTo(destGradientSize._constantMaxSeparate);
  16444. this._gradientMin.cloneTo(destGradientSize._gradientMin);
  16445. this._gradientMax.cloneTo(destGradientSize._gradientMax);
  16446. this._gradientXMin.cloneTo(destGradientSize._gradientXMin);
  16447. this._gradientXMax.cloneTo(destGradientSize._gradientXMax);
  16448. this._gradientYMin.cloneTo(destGradientSize._gradientYMin);
  16449. this._gradientYMax.cloneTo(destGradientSize._gradientYMax);
  16450. this._gradientZMin.cloneTo(destGradientSize._gradientZMin);
  16451. this._gradientZMax.cloneTo(destGradientSize._gradientZMax);
  16452. }
  16453. clone() {
  16454. var destGradientSize = new GradientSize();
  16455. this.cloneTo(destGradientSize);
  16456. return destGradientSize;
  16457. }
  16458. }
  16459. class GradientVelocity {
  16460. constructor() {
  16461. this._type = 0;
  16462. this._constant = null;
  16463. this._gradientX = null;
  16464. this._gradientY = null;
  16465. this._gradientZ = null;
  16466. this._constantMin = null;
  16467. this._constantMax = null;
  16468. this._gradientXMin = null;
  16469. this._gradientXMax = null;
  16470. this._gradientYMin = null;
  16471. this._gradientYMax = null;
  16472. this._gradientZMin = null;
  16473. this._gradientZMax = null;
  16474. }
  16475. static createByConstant(constant) {
  16476. var gradientVelocity = new GradientVelocity();
  16477. gradientVelocity._type = 0;
  16478. gradientVelocity._constant = constant;
  16479. return gradientVelocity;
  16480. }
  16481. static createByGradient(gradientX, gradientY, gradientZ) {
  16482. var gradientVelocity = new GradientVelocity();
  16483. gradientVelocity._type = 1;
  16484. gradientVelocity._gradientX = gradientX;
  16485. gradientVelocity._gradientY = gradientY;
  16486. gradientVelocity._gradientZ = gradientZ;
  16487. return gradientVelocity;
  16488. }
  16489. static createByRandomTwoConstant(constantMin, constantMax) {
  16490. var gradientVelocity = new GradientVelocity();
  16491. gradientVelocity._type = 2;
  16492. gradientVelocity._constantMin = constantMin;
  16493. gradientVelocity._constantMax = constantMax;
  16494. return gradientVelocity;
  16495. }
  16496. static createByRandomTwoGradient(gradientXMin, gradientXMax, gradientYMin, gradientYMax, gradientZMin, gradientZMax) {
  16497. var gradientVelocity = new GradientVelocity();
  16498. gradientVelocity._type = 3;
  16499. gradientVelocity._gradientXMin = gradientXMin;
  16500. gradientVelocity._gradientXMax = gradientXMax;
  16501. gradientVelocity._gradientYMin = gradientYMin;
  16502. gradientVelocity._gradientYMax = gradientYMax;
  16503. gradientVelocity._gradientZMin = gradientZMin;
  16504. gradientVelocity._gradientZMax = gradientZMax;
  16505. return gradientVelocity;
  16506. }
  16507. get type() {
  16508. return this._type;
  16509. }
  16510. get constant() {
  16511. return this._constant;
  16512. }
  16513. get gradientX() {
  16514. return this._gradientX;
  16515. }
  16516. get gradientY() {
  16517. return this._gradientY;
  16518. }
  16519. get gradientZ() {
  16520. return this._gradientZ;
  16521. }
  16522. get constantMin() {
  16523. return this._constantMin;
  16524. }
  16525. get constantMax() {
  16526. return this._constantMax;
  16527. }
  16528. get gradientXMin() {
  16529. return this._gradientXMin;
  16530. }
  16531. get gradientXMax() {
  16532. return this._gradientXMax;
  16533. }
  16534. get gradientYMin() {
  16535. return this._gradientYMin;
  16536. }
  16537. get gradientYMax() {
  16538. return this._gradientYMax;
  16539. }
  16540. get gradientZMin() {
  16541. return this._gradientZMin;
  16542. }
  16543. get gradientZMax() {
  16544. return this._gradientZMax;
  16545. }
  16546. cloneTo(destObject) {
  16547. var destGradientVelocity = destObject;
  16548. destGradientVelocity._type = this._type;
  16549. this._constant.cloneTo(destGradientVelocity._constant);
  16550. this._gradientX.cloneTo(destGradientVelocity._gradientX);
  16551. this._gradientY.cloneTo(destGradientVelocity._gradientY);
  16552. this._gradientZ.cloneTo(destGradientVelocity._gradientZ);
  16553. this._constantMin.cloneTo(destGradientVelocity._constantMin);
  16554. this._constantMax.cloneTo(destGradientVelocity._constantMax);
  16555. this._gradientXMin.cloneTo(destGradientVelocity._gradientXMin);
  16556. this._gradientXMax.cloneTo(destGradientVelocity._gradientXMax);
  16557. this._gradientYMin.cloneTo(destGradientVelocity._gradientYMin);
  16558. this._gradientYMax.cloneTo(destGradientVelocity._gradientYMax);
  16559. this._gradientZMin.cloneTo(destGradientVelocity._gradientZMin);
  16560. this._gradientZMax.cloneTo(destGradientVelocity._gradientZMax);
  16561. }
  16562. clone() {
  16563. var destGradientVelocity = new GradientVelocity();
  16564. this.cloneTo(destGradientVelocity);
  16565. return destGradientVelocity;
  16566. }
  16567. }
  16568. class RotationOverLifetime {
  16569. get angularVelocity() {
  16570. return this._angularVelocity;
  16571. }
  16572. constructor(angularVelocity) {
  16573. this._angularVelocity = angularVelocity;
  16574. }
  16575. cloneTo(destObject) {
  16576. var destRotationOverLifetime = destObject;
  16577. this._angularVelocity.cloneTo(destRotationOverLifetime._angularVelocity);
  16578. destRotationOverLifetime.enbale = this.enbale;
  16579. }
  16580. clone() {
  16581. var destAngularVelocity;
  16582. switch (this._angularVelocity.type) {
  16583. case 0:
  16584. if (this._angularVelocity.separateAxes)
  16585. destAngularVelocity = GradientAngularVelocity.createByConstantSeparate(this._angularVelocity.constantSeparate.clone());
  16586. else
  16587. destAngularVelocity = GradientAngularVelocity.createByConstant(this._angularVelocity.constant);
  16588. break;
  16589. case 1:
  16590. if (this._angularVelocity.separateAxes)
  16591. destAngularVelocity = GradientAngularVelocity.createByGradientSeparate(this._angularVelocity.gradientX.clone(), this._angularVelocity.gradientY.clone(), this._angularVelocity.gradientZ.clone());
  16592. else
  16593. destAngularVelocity = GradientAngularVelocity.createByGradient(this._angularVelocity.gradient.clone());
  16594. break;
  16595. case 2:
  16596. if (this._angularVelocity.separateAxes)
  16597. destAngularVelocity = GradientAngularVelocity.createByRandomTwoConstantSeparate(this._angularVelocity.constantMinSeparate.clone(), this._angularVelocity.constantMaxSeparate.clone());
  16598. else
  16599. destAngularVelocity = GradientAngularVelocity.createByRandomTwoConstant(this._angularVelocity.constantMin, this._angularVelocity.constantMax);
  16600. break;
  16601. case 3:
  16602. if (this._angularVelocity.separateAxes)
  16603. destAngularVelocity = GradientAngularVelocity.createByRandomTwoGradientSeparate(this._angularVelocity.gradientXMin.clone(), this._angularVelocity.gradientYMin.clone(), this._angularVelocity.gradientZMin.clone(), this._angularVelocity.gradientWMin.clone(), this._angularVelocity.gradientXMax.clone(), this._angularVelocity.gradientYMax.clone(), this._angularVelocity.gradientZMax.clone(), this._angularVelocity.gradientWMax.clone());
  16604. else
  16605. destAngularVelocity = GradientAngularVelocity.createByRandomTwoGradient(this._angularVelocity.gradientMin.clone(), this._angularVelocity.gradientMax.clone());
  16606. break;
  16607. }
  16608. var destRotationOverLifetime = new RotationOverLifetime(destAngularVelocity);
  16609. destRotationOverLifetime.enbale = this.enbale;
  16610. return destRotationOverLifetime;
  16611. }
  16612. }
  16613. class BaseShape {
  16614. constructor() {
  16615. }
  16616. _getShapeBoundBox(boundBox) {
  16617. throw new Error("BaseShape: must override it.");
  16618. }
  16619. _getSpeedBoundBox(boundBox) {
  16620. throw new Error("BaseShape: must override it.");
  16621. }
  16622. generatePositionAndDirection(position, direction, rand = null, randomSeeds = null) {
  16623. throw new Error("BaseShape: must override it.");
  16624. }
  16625. _calculateProceduralBounds(boundBox, emitterPosScale, minMaxBounds) {
  16626. this._getShapeBoundBox(boundBox);
  16627. var min = boundBox.min;
  16628. var max = boundBox.max;
  16629. Vector3.multiply(min, emitterPosScale, min);
  16630. Vector3.multiply(max, emitterPosScale, max);
  16631. var speedBounds = new BoundBox(new Vector3(), new Vector3());
  16632. if (this.randomDirection) {
  16633. speedBounds.min = new Vector3(-1, -1, -1);
  16634. speedBounds.max = new Vector3(1, 1, 1);
  16635. }
  16636. else {
  16637. this._getSpeedBoundBox(speedBounds);
  16638. }
  16639. var maxSpeedBound = new BoundBox(new Vector3(), new Vector3());
  16640. var maxSpeedMin = maxSpeedBound.min;
  16641. var maxSpeedMax = maxSpeedBound.max;
  16642. Vector3.scale(speedBounds.min, minMaxBounds.y, maxSpeedMin);
  16643. Vector3.scale(speedBounds.max, minMaxBounds.y, maxSpeedMax);
  16644. Vector3.add(boundBox.min, maxSpeedMin, maxSpeedMin);
  16645. Vector3.add(boundBox.max, maxSpeedMax, maxSpeedMax);
  16646. Vector3.min(boundBox.min, maxSpeedMin, boundBox.min);
  16647. Vector3.max(boundBox.max, maxSpeedMin, boundBox.max);
  16648. var minSpeedBound = new BoundBox(new Vector3(), new Vector3());
  16649. var minSpeedMin = minSpeedBound.min;
  16650. var minSpeedMax = minSpeedBound.max;
  16651. Vector3.scale(speedBounds.min, minMaxBounds.x, minSpeedMin);
  16652. Vector3.scale(speedBounds.max, minMaxBounds.x, minSpeedMax);
  16653. Vector3.min(minSpeedBound.min, minSpeedMax, maxSpeedMin);
  16654. Vector3.max(minSpeedBound.min, minSpeedMax, maxSpeedMax);
  16655. Vector3.min(boundBox.min, maxSpeedMin, boundBox.min);
  16656. Vector3.max(boundBox.max, maxSpeedMin, boundBox.max);
  16657. }
  16658. cloneTo(destObject) {
  16659. var destShape = destObject;
  16660. destShape.enable = this.enable;
  16661. }
  16662. clone() {
  16663. var destShape = new BaseShape();
  16664. this.cloneTo(destShape);
  16665. return destShape;
  16666. }
  16667. }
  16668. class ShapeUtils {
  16669. static _randomPointUnitArcCircle(arc, out, rand = null) {
  16670. var angle;
  16671. if (rand)
  16672. angle = rand.getFloat() * arc;
  16673. else
  16674. angle = Math.random() * arc;
  16675. out.x = Math.cos(angle);
  16676. out.y = Math.sin(angle);
  16677. }
  16678. static _randomPointInsideUnitArcCircle(arc, out, rand = null) {
  16679. ShapeUtils._randomPointUnitArcCircle(arc, out, rand);
  16680. var range;
  16681. if (rand)
  16682. range = Math.pow(rand.getFloat(), 1.0 / 2.0);
  16683. else
  16684. range = Math.pow(Math.random(), 1.0 / 2.0);
  16685. out.x = out.x * range;
  16686. out.y = out.y * range;
  16687. }
  16688. static _randomPointUnitCircle(out, rand = null) {
  16689. var angle;
  16690. if (rand)
  16691. angle = rand.getFloat() * Math.PI * 2;
  16692. else
  16693. angle = Math.random() * Math.PI * 2;
  16694. out.x = Math.cos(angle);
  16695. out.y = Math.sin(angle);
  16696. }
  16697. static _randomPointInsideUnitCircle(out, rand = null) {
  16698. ShapeUtils._randomPointUnitCircle(out);
  16699. var range;
  16700. if (rand)
  16701. range = Math.pow(rand.getFloat(), 1.0 / 2.0);
  16702. else
  16703. range = Math.pow(Math.random(), 1.0 / 2.0);
  16704. out.x = out.x * range;
  16705. out.y = out.y * range;
  16706. }
  16707. static _randomPointUnitSphere(out, rand = null) {
  16708. var z;
  16709. var a;
  16710. if (rand) {
  16711. z = out.z = rand.getFloat() * 2 - 1.0;
  16712. a = rand.getFloat() * Math.PI * 2;
  16713. }
  16714. else {
  16715. z = out.z = Math.random() * 2 - 1.0;
  16716. a = Math.random() * Math.PI * 2;
  16717. }
  16718. var r = Math.sqrt(1.0 - z * z);
  16719. out.x = r * Math.cos(a);
  16720. out.y = r * Math.sin(a);
  16721. }
  16722. static _randomPointInsideUnitSphere(out, rand = null) {
  16723. ShapeUtils._randomPointUnitSphere(out);
  16724. var range;
  16725. if (rand)
  16726. range = Math.pow(rand.getFloat(), 1.0 / 3.0);
  16727. else
  16728. range = Math.pow(Math.random(), 1.0 / 3.0);
  16729. out.x = out.x * range;
  16730. out.y = out.y * range;
  16731. out.z = out.z * range;
  16732. }
  16733. static _randomPointInsideHalfUnitBox(out, rand = null) {
  16734. if (rand) {
  16735. out.x = (rand.getFloat() - 0.5);
  16736. out.y = (rand.getFloat() - 0.5);
  16737. out.z = (rand.getFloat() - 0.5);
  16738. }
  16739. else {
  16740. out.x = (Math.random() - 0.5);
  16741. out.y = (Math.random() - 0.5);
  16742. out.z = (Math.random() - 0.5);
  16743. }
  16744. }
  16745. constructor() {
  16746. }
  16747. }
  16748. class BoxShape extends BaseShape {
  16749. constructor() {
  16750. super();
  16751. this.x = 1.0;
  16752. this.y = 1.0;
  16753. this.z = 1.0;
  16754. this.randomDirection = false;
  16755. }
  16756. _getShapeBoundBox(boundBox) {
  16757. var min = boundBox.min;
  16758. min.x = -this.x * 0.5;
  16759. min.y = -this.y * 0.5;
  16760. min.z = -this.z * 0.5;
  16761. var max = boundBox.max;
  16762. max.x = this.x * 0.5;
  16763. max.y = this.y * 0.5;
  16764. max.z = this.z * 0.5;
  16765. }
  16766. _getSpeedBoundBox(boundBox) {
  16767. var min = boundBox.min;
  16768. min.x = 0.0;
  16769. min.y = 0.0;
  16770. min.z = 0.0;
  16771. var max = boundBox.max;
  16772. max.x = 0.0;
  16773. max.y = 1.0;
  16774. max.z = 0.0;
  16775. }
  16776. generatePositionAndDirection(position, direction, rand = null, randomSeeds = null) {
  16777. if (rand) {
  16778. rand.seed = randomSeeds[16];
  16779. ShapeUtils._randomPointInsideHalfUnitBox(position, rand);
  16780. randomSeeds[16] = rand.seed;
  16781. }
  16782. else {
  16783. ShapeUtils._randomPointInsideHalfUnitBox(position);
  16784. }
  16785. position.x = this.x * position.x;
  16786. position.y = this.y * position.y;
  16787. position.z = this.z * position.z;
  16788. if (this.randomDirection) {
  16789. if (rand) {
  16790. rand.seed = randomSeeds[17];
  16791. ShapeUtils._randomPointUnitSphere(direction, rand);
  16792. randomSeeds[17] = rand.seed;
  16793. }
  16794. else {
  16795. ShapeUtils._randomPointUnitSphere(direction);
  16796. }
  16797. }
  16798. else {
  16799. direction.x = 0.0;
  16800. direction.y = 0.0;
  16801. direction.z = 1.0;
  16802. }
  16803. }
  16804. cloneTo(destObject) {
  16805. super.cloneTo(destObject);
  16806. var destShape = destObject;
  16807. destShape.x = this.x;
  16808. destShape.y = this.y;
  16809. destShape.z = this.z;
  16810. destShape.randomDirection = this.randomDirection;
  16811. }
  16812. clone() {
  16813. var destShape = new BoxShape();
  16814. this.cloneTo(destShape);
  16815. return destShape;
  16816. }
  16817. }
  16818. class CircleShape extends BaseShape {
  16819. constructor() {
  16820. super();
  16821. this.radius = 1.0;
  16822. this.arc = 360.0 / 180.0 * Math.PI;
  16823. this.emitFromEdge = false;
  16824. this.randomDirection = false;
  16825. }
  16826. _getShapeBoundBox(boundBox) {
  16827. var min = boundBox.min;
  16828. min.x = min.z = -this.radius;
  16829. min.y = 0;
  16830. var max = boundBox.max;
  16831. max.x = max.z = this.radius;
  16832. max.y = 0;
  16833. }
  16834. _getSpeedBoundBox(boundBox) {
  16835. var min = boundBox.min;
  16836. min.x = min.y = -1;
  16837. min.z = 0;
  16838. var max = boundBox.max;
  16839. max.x = max.y = 1;
  16840. max.z = 0;
  16841. }
  16842. generatePositionAndDirection(position, direction, rand = null, randomSeeds = null) {
  16843. var positionPoint = CircleShape._tempPositionPoint;
  16844. if (rand) {
  16845. rand.seed = randomSeeds[16];
  16846. if (this.emitFromEdge)
  16847. ShapeUtils._randomPointUnitArcCircle(this.arc, CircleShape._tempPositionPoint, rand);
  16848. else
  16849. ShapeUtils._randomPointInsideUnitArcCircle(this.arc, CircleShape._tempPositionPoint, rand);
  16850. randomSeeds[16] = rand.seed;
  16851. }
  16852. else {
  16853. if (this.emitFromEdge)
  16854. ShapeUtils._randomPointUnitArcCircle(this.arc, CircleShape._tempPositionPoint);
  16855. else
  16856. ShapeUtils._randomPointInsideUnitArcCircle(this.arc, CircleShape._tempPositionPoint);
  16857. }
  16858. position.x = -positionPoint.x;
  16859. position.y = positionPoint.y;
  16860. position.z = 0;
  16861. Vector3.scale(position, this.radius, position);
  16862. if (this.randomDirection) {
  16863. if (rand) {
  16864. rand.seed = randomSeeds[17];
  16865. ShapeUtils._randomPointUnitSphere(direction, rand);
  16866. randomSeeds[17] = rand.seed;
  16867. }
  16868. else {
  16869. ShapeUtils._randomPointUnitSphere(direction);
  16870. }
  16871. }
  16872. else {
  16873. position.cloneTo(direction);
  16874. }
  16875. }
  16876. cloneTo(destObject) {
  16877. super.cloneTo(destObject);
  16878. var destShape = destObject;
  16879. destShape.radius = this.radius;
  16880. destShape.arc = this.arc;
  16881. destShape.emitFromEdge = this.emitFromEdge;
  16882. destShape.randomDirection = this.randomDirection;
  16883. }
  16884. clone() {
  16885. var destShape = new CircleShape();
  16886. this.cloneTo(destShape);
  16887. return destShape;
  16888. }
  16889. }
  16890. CircleShape._tempPositionPoint = new Vector2();
  16891. class ConeShape extends BaseShape {
  16892. constructor() {
  16893. super();
  16894. this.angle = 25.0 / 180.0 * Math.PI;
  16895. this.radius = 1.0;
  16896. this.length = 5.0;
  16897. this.emitType = 0;
  16898. this.randomDirection = false;
  16899. }
  16900. _getShapeBoundBox(boundBox) {
  16901. const coneRadius2 = this.radius + this.length * Math.sin(this.angle);
  16902. const coneLength = this.length * Math.cos(this.angle);
  16903. var min = boundBox.min;
  16904. min.x = min.y = -coneRadius2;
  16905. min.z = 0;
  16906. var max = boundBox.max;
  16907. max.x = max.y = coneRadius2;
  16908. max.z = coneLength;
  16909. }
  16910. _getSpeedBoundBox(boundBox) {
  16911. const sinA = Math.sin(this.angle);
  16912. var min = boundBox.min;
  16913. min.x = min.y = -sinA;
  16914. min.z = 0;
  16915. var max = boundBox.max;
  16916. max.x = max.y = sinA;
  16917. max.z = 1;
  16918. }
  16919. generatePositionAndDirection(position, direction, rand = null, randomSeeds = null) {
  16920. var positionPointE = ConeShape._tempPositionPoint;
  16921. var positionX;
  16922. var positionY;
  16923. var directionPointE;
  16924. var dirCosA = Math.cos(this.angle);
  16925. var dirSinA = Math.sin(this.angle);
  16926. switch (this.emitType) {
  16927. case 0:
  16928. if (rand) {
  16929. rand.seed = randomSeeds[16];
  16930. ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempPositionPoint, rand);
  16931. randomSeeds[16] = rand.seed;
  16932. }
  16933. else {
  16934. ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempPositionPoint);
  16935. }
  16936. positionX = positionPointE.x;
  16937. positionY = positionPointE.y;
  16938. position.x = positionX * this.radius;
  16939. position.y = positionY * this.radius;
  16940. position.z = 0;
  16941. if (this.randomDirection) {
  16942. if (rand) {
  16943. rand.seed = randomSeeds[17];
  16944. ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempDirectionPoint, rand);
  16945. randomSeeds[17] = rand.seed;
  16946. }
  16947. else {
  16948. ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempDirectionPoint);
  16949. }
  16950. directionPointE = ConeShape._tempDirectionPoint;
  16951. direction.x = directionPointE.x * dirSinA;
  16952. direction.y = directionPointE.y * dirSinA;
  16953. }
  16954. else {
  16955. direction.x = positionX * dirSinA;
  16956. direction.y = positionY * dirSinA;
  16957. }
  16958. direction.z = dirCosA;
  16959. break;
  16960. case 1:
  16961. if (rand) {
  16962. rand.seed = randomSeeds[16];
  16963. ShapeUtils._randomPointUnitCircle(ConeShape._tempPositionPoint, rand);
  16964. randomSeeds[16] = rand.seed;
  16965. }
  16966. else {
  16967. ShapeUtils._randomPointUnitCircle(ConeShape._tempPositionPoint);
  16968. }
  16969. positionX = positionPointE.x;
  16970. positionY = positionPointE.y;
  16971. position.x = positionX * this.radius;
  16972. position.y = positionY * this.radius;
  16973. position.z = 0;
  16974. if (this.randomDirection) {
  16975. if (rand) {
  16976. rand.seed = randomSeeds[17];
  16977. ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempDirectionPoint, rand);
  16978. randomSeeds[17] = rand.seed;
  16979. }
  16980. else {
  16981. ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempDirectionPoint);
  16982. }
  16983. directionPointE = ConeShape._tempDirectionPoint;
  16984. direction.x = directionPointE.x * dirSinA;
  16985. direction.y = directionPointE.y * dirSinA;
  16986. }
  16987. else {
  16988. direction.x = positionX * dirSinA;
  16989. direction.y = positionY * dirSinA;
  16990. }
  16991. direction.z = dirCosA;
  16992. break;
  16993. case 2:
  16994. if (rand) {
  16995. rand.seed = randomSeeds[16];
  16996. ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempPositionPoint, rand);
  16997. }
  16998. else {
  16999. ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempPositionPoint);
  17000. }
  17001. positionX = positionPointE.x;
  17002. positionY = positionPointE.y;
  17003. position.x = positionX * this.radius;
  17004. position.y = positionY * this.radius;
  17005. position.z = 0;
  17006. direction.x = positionX * dirSinA;
  17007. direction.y = positionY * dirSinA;
  17008. direction.z = dirCosA;
  17009. Vector3.normalize(direction, direction);
  17010. if (rand) {
  17011. Vector3.scale(direction, this.length * rand.getFloat(), direction);
  17012. randomSeeds[16] = rand.seed;
  17013. }
  17014. else {
  17015. Vector3.scale(direction, this.length * Math.random(), direction);
  17016. }
  17017. Vector3.add(position, direction, position);
  17018. if (this.randomDirection) {
  17019. if (rand) {
  17020. rand.seed = randomSeeds[17];
  17021. ShapeUtils._randomPointUnitSphere(direction, rand);
  17022. randomSeeds[17] = rand.seed;
  17023. }
  17024. else {
  17025. ShapeUtils._randomPointUnitSphere(direction);
  17026. }
  17027. }
  17028. break;
  17029. case 3:
  17030. if (rand) {
  17031. rand.seed = randomSeeds[16];
  17032. ShapeUtils._randomPointUnitCircle(ConeShape._tempPositionPoint, rand);
  17033. }
  17034. else {
  17035. ShapeUtils._randomPointUnitCircle(ConeShape._tempPositionPoint);
  17036. }
  17037. positionX = positionPointE.x;
  17038. positionY = positionPointE.y;
  17039. position.x = positionX * this.radius;
  17040. position.y = positionY * this.radius;
  17041. position.z = 0;
  17042. direction.x = positionX * dirSinA;
  17043. direction.y = positionY * dirSinA;
  17044. direction.z = dirCosA;
  17045. Vector3.normalize(direction, direction);
  17046. if (rand) {
  17047. Vector3.scale(direction, this.length * rand.getFloat(), direction);
  17048. randomSeeds[16] = rand.seed;
  17049. }
  17050. else {
  17051. Vector3.scale(direction, this.length * Math.random(), direction);
  17052. }
  17053. Vector3.add(position, direction, position);
  17054. if (this.randomDirection) {
  17055. if (rand) {
  17056. rand.seed = randomSeeds[17];
  17057. ShapeUtils._randomPointUnitSphere(direction, rand);
  17058. randomSeeds[17] = rand.seed;
  17059. }
  17060. else {
  17061. ShapeUtils._randomPointUnitSphere(direction);
  17062. }
  17063. }
  17064. break;
  17065. default:
  17066. throw new Error("ConeShape:emitType is invalid.");
  17067. }
  17068. }
  17069. cloneTo(destObject) {
  17070. super.cloneTo(destObject);
  17071. var destShape = destObject;
  17072. destShape.angle = this.angle;
  17073. destShape.radius = this.radius;
  17074. destShape.length = this.length;
  17075. destShape.emitType = this.emitType;
  17076. destShape.randomDirection = this.randomDirection;
  17077. }
  17078. clone() {
  17079. var destShape = new ConeShape();
  17080. this.cloneTo(destShape);
  17081. return destShape;
  17082. }
  17083. }
  17084. ConeShape._tempPositionPoint = new Vector2();
  17085. ConeShape._tempDirectionPoint = new Vector2();
  17086. class HemisphereShape extends BaseShape {
  17087. constructor() {
  17088. super();
  17089. this.radius = 1.0;
  17090. this.emitFromShell = false;
  17091. this.randomDirection = false;
  17092. }
  17093. _getShapeBoundBox(boundBox) {
  17094. var min = boundBox.min;
  17095. min.x = min.y = min.z = -this.radius;
  17096. var max = boundBox.max;
  17097. max.x = max.y = this.radius;
  17098. max.z = 0;
  17099. }
  17100. _getSpeedBoundBox(boundBox) {
  17101. var min = boundBox.min;
  17102. min.x = min.y = -1;
  17103. min.z = 0;
  17104. var max = boundBox.max;
  17105. max.x = max.y = max.z = 1;
  17106. }
  17107. generatePositionAndDirection(position, direction, rand = null, randomSeeds = null) {
  17108. if (rand) {
  17109. rand.seed = randomSeeds[16];
  17110. if (this.emitFromShell)
  17111. ShapeUtils._randomPointUnitSphere(position, rand);
  17112. else
  17113. ShapeUtils._randomPointInsideUnitSphere(position, rand);
  17114. randomSeeds[16] = rand.seed;
  17115. }
  17116. else {
  17117. if (this.emitFromShell)
  17118. ShapeUtils._randomPointUnitSphere(position);
  17119. else
  17120. ShapeUtils._randomPointInsideUnitSphere(position);
  17121. }
  17122. Vector3.scale(position, this.radius, position);
  17123. var z = position.z;
  17124. (z < 0.0) && (position.z = z * -1.0);
  17125. if (this.randomDirection) {
  17126. if (rand) {
  17127. rand.seed = randomSeeds[17];
  17128. ShapeUtils._randomPointUnitSphere(direction, rand);
  17129. randomSeeds[17] = rand.seed;
  17130. }
  17131. else {
  17132. ShapeUtils._randomPointUnitSphere(direction);
  17133. }
  17134. }
  17135. else {
  17136. position.cloneTo(direction);
  17137. }
  17138. }
  17139. cloneTo(destObject) {
  17140. super.cloneTo(destObject);
  17141. var destShape = destObject;
  17142. destShape.radius = this.radius;
  17143. destShape.emitFromShell = this.emitFromShell;
  17144. destShape.randomDirection = this.randomDirection;
  17145. }
  17146. clone() {
  17147. var destShape = new HemisphereShape();
  17148. this.cloneTo(destShape);
  17149. return destShape;
  17150. }
  17151. }
  17152. class SphereShape extends BaseShape {
  17153. constructor() {
  17154. super();
  17155. this.radius = 1.0;
  17156. this.emitFromShell = false;
  17157. this.randomDirection = false;
  17158. }
  17159. _getShapeBoundBox(boundBox) {
  17160. var min = boundBox.min;
  17161. min.x = min.y = min.z = -this.radius;
  17162. var max = boundBox.max;
  17163. max.x = max.y = max.z = this.radius;
  17164. }
  17165. _getSpeedBoundBox(boundBox) {
  17166. var min = boundBox.min;
  17167. min.x = min.y = min.z = -1;
  17168. var max = boundBox.max;
  17169. max.x = max.y = max.z = 1;
  17170. }
  17171. generatePositionAndDirection(position, direction, rand = null, randomSeeds = null) {
  17172. if (rand) {
  17173. rand.seed = randomSeeds[16];
  17174. if (this.emitFromShell)
  17175. ShapeUtils._randomPointUnitSphere(position, rand);
  17176. else
  17177. ShapeUtils._randomPointInsideUnitSphere(position, rand);
  17178. randomSeeds[16] = rand.seed;
  17179. }
  17180. else {
  17181. if (this.emitFromShell)
  17182. ShapeUtils._randomPointUnitSphere(position);
  17183. else
  17184. ShapeUtils._randomPointInsideUnitSphere(position);
  17185. }
  17186. Vector3.scale(position, this.radius, position);
  17187. if (this.randomDirection) {
  17188. if (rand) {
  17189. rand.seed = randomSeeds[17];
  17190. ShapeUtils._randomPointUnitSphere(direction, rand);
  17191. randomSeeds[17] = rand.seed;
  17192. }
  17193. else {
  17194. ShapeUtils._randomPointUnitSphere(direction);
  17195. }
  17196. }
  17197. else {
  17198. position.cloneTo(direction);
  17199. }
  17200. }
  17201. cloneTo(destObject) {
  17202. super.cloneTo(destObject);
  17203. var destShape = destObject;
  17204. destShape.radius = this.radius;
  17205. destShape.emitFromShell = this.emitFromShell;
  17206. destShape.randomDirection = this.randomDirection;
  17207. }
  17208. clone() {
  17209. var destShape = new SphereShape();
  17210. this.cloneTo(destShape);
  17211. return destShape;
  17212. }
  17213. }
  17214. class SizeOverLifetime {
  17215. get size() {
  17216. return this._size;
  17217. }
  17218. constructor(size) {
  17219. this._size = size;
  17220. }
  17221. cloneTo(destObject) {
  17222. var destSizeOverLifetime = destObject;
  17223. this._size.cloneTo(destSizeOverLifetime._size);
  17224. destSizeOverLifetime.enbale = this.enbale;
  17225. }
  17226. clone() {
  17227. var destSize;
  17228. switch (this._size.type) {
  17229. case 0:
  17230. if (this._size.separateAxes)
  17231. destSize = GradientSize.createByGradientSeparate(this._size.gradientX.clone(), this._size.gradientY.clone(), this._size.gradientZ.clone());
  17232. else
  17233. destSize = GradientSize.createByGradient(this._size.gradient.clone());
  17234. break;
  17235. case 1:
  17236. if (this._size.separateAxes)
  17237. destSize = GradientSize.createByRandomTwoConstantSeparate(this._size.constantMinSeparate.clone(), this._size.constantMaxSeparate.clone());
  17238. else
  17239. destSize = GradientSize.createByRandomTwoConstant(this._size.constantMin, this._size.constantMax);
  17240. break;
  17241. case 2:
  17242. if (this._size.separateAxes)
  17243. destSize = GradientSize.createByRandomTwoGradientSeparate(this._size.gradientXMin.clone(), this._size.gradientYMin.clone(), this._size.gradientZMin.clone(), this._size.gradientXMax.clone(), this._size.gradientYMax.clone(), this._size.gradientZMax.clone());
  17244. else
  17245. destSize = GradientSize.createByRandomTwoGradient(this._size.gradientMin.clone(), this._size.gradientMax.clone());
  17246. break;
  17247. }
  17248. var destSizeOverLifetime = new SizeOverLifetime(destSize);
  17249. destSizeOverLifetime.enbale = this.enbale;
  17250. return destSizeOverLifetime;
  17251. }
  17252. }
  17253. class StartFrame {
  17254. constructor() {
  17255. this._type = 0;
  17256. this._constant = 0;
  17257. this._constantMin = 0;
  17258. this._constantMax = 0;
  17259. }
  17260. static createByConstant(constant) {
  17261. var rotationOverLifetime = new StartFrame();
  17262. rotationOverLifetime._type = 0;
  17263. rotationOverLifetime._constant = constant;
  17264. return rotationOverLifetime;
  17265. }
  17266. static createByRandomTwoConstant(constantMin, constantMax) {
  17267. var rotationOverLifetime = new StartFrame();
  17268. rotationOverLifetime._type = 1;
  17269. rotationOverLifetime._constantMin = constantMin;
  17270. rotationOverLifetime._constantMax = constantMax;
  17271. return rotationOverLifetime;
  17272. }
  17273. get type() {
  17274. return this._type;
  17275. }
  17276. get constant() {
  17277. return this._constant;
  17278. }
  17279. get constantMin() {
  17280. return this._constantMin;
  17281. }
  17282. get constantMax() {
  17283. return this._constantMax;
  17284. }
  17285. cloneTo(destObject) {
  17286. var destStartFrame = destObject;
  17287. destStartFrame._type = this._type;
  17288. destStartFrame._constant = this._constant;
  17289. destStartFrame._constantMin = this._constantMin;
  17290. destStartFrame._constantMax = this._constantMax;
  17291. }
  17292. clone() {
  17293. var destStartFrame = new StartFrame();
  17294. this.cloneTo(destStartFrame);
  17295. return destStartFrame;
  17296. }
  17297. }
  17298. class TextureSheetAnimation {
  17299. constructor(frame, startFrame) {
  17300. this.type = 0;
  17301. this.randomRow = false;
  17302. this.rowIndex = 0;
  17303. this.cycles = 0;
  17304. this.enableUVChannels = 0;
  17305. this.enable = false;
  17306. this.tiles = new Vector2(1, 1);
  17307. this.type = 0;
  17308. this.randomRow = true;
  17309. this.rowIndex = 0;
  17310. this.cycles = 1;
  17311. this.enableUVChannels = 1;
  17312. this._frame = frame;
  17313. this._startFrame = startFrame;
  17314. }
  17315. get frame() {
  17316. return this._frame;
  17317. }
  17318. get startFrame() {
  17319. return this._startFrame;
  17320. }
  17321. cloneTo(destObject) {
  17322. var destTextureSheetAnimation = destObject;
  17323. this.tiles.cloneTo(destTextureSheetAnimation.tiles);
  17324. destTextureSheetAnimation.type = this.type;
  17325. destTextureSheetAnimation.randomRow = this.randomRow;
  17326. destTextureSheetAnimation.rowIndex = this.rowIndex;
  17327. destTextureSheetAnimation.cycles = this.cycles;
  17328. destTextureSheetAnimation.enableUVChannels = this.enableUVChannels;
  17329. destTextureSheetAnimation.enable = this.enable;
  17330. this._frame.cloneTo(destTextureSheetAnimation._frame);
  17331. this._startFrame.cloneTo(destTextureSheetAnimation._startFrame);
  17332. }
  17333. clone() {
  17334. var destFrame;
  17335. switch (this._frame.type) {
  17336. case 0:
  17337. destFrame = FrameOverTime.createByConstant(this._frame.constant);
  17338. break;
  17339. case 1:
  17340. destFrame = FrameOverTime.createByOverTime(this._frame.frameOverTimeData.clone());
  17341. break;
  17342. case 2:
  17343. destFrame = FrameOverTime.createByRandomTwoConstant(this._frame.constantMin, this._frame.constantMax);
  17344. break;
  17345. case 3:
  17346. destFrame = FrameOverTime.createByRandomTwoOverTime(this._frame.frameOverTimeDataMin.clone(), this._frame.frameOverTimeDataMax.clone());
  17347. break;
  17348. }
  17349. var destStartFrame;
  17350. switch (this._startFrame.type) {
  17351. case 0:
  17352. destStartFrame = StartFrame.createByConstant(this._startFrame.constant);
  17353. break;
  17354. case 1:
  17355. destStartFrame = StartFrame.createByRandomTwoConstant(this._startFrame.constantMin, this._startFrame.constantMax);
  17356. break;
  17357. }
  17358. var destTextureSheetAnimation = new TextureSheetAnimation(destFrame, destStartFrame);
  17359. this.cloneTo(destTextureSheetAnimation);
  17360. return destTextureSheetAnimation;
  17361. }
  17362. }
  17363. class VelocityOverLifetime {
  17364. constructor(velocity) {
  17365. this.enbale = false;
  17366. this.space = 0;
  17367. this._velocity = velocity;
  17368. }
  17369. get velocity() {
  17370. return this._velocity;
  17371. }
  17372. cloneTo(destObject) {
  17373. var destVelocityOverLifetime = destObject;
  17374. this._velocity.cloneTo(destVelocityOverLifetime._velocity);
  17375. destVelocityOverLifetime.enbale = this.enbale;
  17376. destVelocityOverLifetime.space = this.space;
  17377. }
  17378. clone() {
  17379. var destVelocity;
  17380. switch (this._velocity.type) {
  17381. case 0:
  17382. destVelocity = GradientVelocity.createByConstant(this._velocity.constant.clone());
  17383. break;
  17384. case 1:
  17385. destVelocity = GradientVelocity.createByGradient(this._velocity.gradientX.clone(), this._velocity.gradientY.clone(), this._velocity.gradientZ.clone());
  17386. break;
  17387. case 2:
  17388. destVelocity = GradientVelocity.createByRandomTwoConstant(this._velocity.constantMin.clone(), this._velocity.constantMax.clone());
  17389. break;
  17390. case 3:
  17391. destVelocity = GradientVelocity.createByRandomTwoGradient(this._velocity.gradientXMin.clone(), this._velocity.gradientYMin.clone(), this._velocity.gradientZMin.clone(), this._velocity.gradientXMax.clone(), this._velocity.gradientYMax.clone(), this._velocity.gradientZMax.clone());
  17392. break;
  17393. }
  17394. var destVelocityOverLifetime = new VelocityOverLifetime(destVelocity);
  17395. destVelocityOverLifetime.enbale = this.enbale;
  17396. destVelocityOverLifetime.space = this.space;
  17397. return destVelocityOverLifetime;
  17398. }
  17399. }
  17400. class ShuriKenParticle3D extends RenderableSprite3D {
  17401. static __init__() {
  17402. ShuriKenParticle3D.shaderDefines = new ShaderDefines(RenderableSprite3D.shaderDefines);
  17403. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_BILLBOARD = ShuriKenParticle3D.shaderDefines.registerDefine("SPHERHBILLBOARD");
  17404. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD = ShuriKenParticle3D.shaderDefines.registerDefine("STRETCHEDBILLBOARD");
  17405. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD = ShuriKenParticle3D.shaderDefines.registerDefine("HORIZONTALBILLBOARD");
  17406. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD = ShuriKenParticle3D.shaderDefines.registerDefine("VERTICALBILLBOARD");
  17407. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_COLOROVERLIFETIME = ShuriKenParticle3D.shaderDefines.registerDefine("COLOROVERLIFETIME");
  17408. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RANDOMCOLOROVERLIFETIME = ShuriKenParticle3D.shaderDefines.registerDefine("RANDOMCOLOROVERLIFETIME");
  17409. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT = ShuriKenParticle3D.shaderDefines.registerDefine("VELOCITYOVERLIFETIMECONSTANT");
  17410. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE = ShuriKenParticle3D.shaderDefines.registerDefine("VELOCITYOVERLIFETIMECURVE");
  17411. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT = ShuriKenParticle3D.shaderDefines.registerDefine("VELOCITYOVERLIFETIMERANDOMCONSTANT");
  17412. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE = ShuriKenParticle3D.shaderDefines.registerDefine("VELOCITYOVERLIFETIMERANDOMCURVE");
  17413. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE = ShuriKenParticle3D.shaderDefines.registerDefine("TEXTURESHEETANIMATIONCURVE");
  17414. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE = ShuriKenParticle3D.shaderDefines.registerDefine("TEXTURESHEETANIMATIONRANDOMCURVE");
  17415. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIME = ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIME");
  17416. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE = ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMESEPERATE");
  17417. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT = ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMECONSTANT");
  17418. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE = ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMECURVE");
  17419. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS = ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMERANDOMCONSTANTS");
  17420. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES = ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMERANDOMCURVES");
  17421. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMECURVE = ShuriKenParticle3D.shaderDefines.registerDefine("SIZEOVERLIFETIMECURVE");
  17422. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE = ShuriKenParticle3D.shaderDefines.registerDefine("SIZEOVERLIFETIMECURVESEPERATE");
  17423. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES = ShuriKenParticle3D.shaderDefines.registerDefine("SIZEOVERLIFETIMERANDOMCURVES");
  17424. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE = ShuriKenParticle3D.shaderDefines.registerDefine("SIZEOVERLIFETIMERANDOMCURVESSEPERATE");
  17425. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_RENDERMODE_MESH = ShuriKenParticle3D.shaderDefines.registerDefine("RENDERMODE_MESH");
  17426. ShuriKenParticle3DShaderDeclaration.SHADERDEFINE_SHAPE = ShuriKenParticle3D.shaderDefines.registerDefine("SHAPE");
  17427. }
  17428. get particleSystem() {
  17429. return this._particleSystem;
  17430. }
  17431. get particleRenderer() {
  17432. return this._render;
  17433. }
  17434. constructor() {
  17435. super(null);
  17436. this._render = new ShurikenParticleRenderer(this);
  17437. this._particleSystem = new ShurikenParticleSystem(this);
  17438. var elements = this._render._renderElements;
  17439. var element = elements[0] = new RenderElement();
  17440. element.setTransform(this._transform);
  17441. element.render = this._render;
  17442. element.setGeometry(this._particleSystem);
  17443. element.material = ShurikenParticleMaterial.defaultMaterial;
  17444. }
  17445. static _initStartLife(gradientData) {
  17446. var gradient = new GradientDataNumber();
  17447. var startLifetimesData = gradientData.startLifetimes;
  17448. for (var i = 0, n = startLifetimesData.length; i < n; i++) {
  17449. var valueData = startLifetimesData[i];
  17450. gradient.add(valueData.key, valueData.value);
  17451. }
  17452. return gradient;
  17453. }
  17454. _initParticleVelocity(gradientData) {
  17455. var gradient = new GradientDataNumber();
  17456. var velocitysData = gradientData.velocitys;
  17457. for (var i = 0, n = velocitysData.length; i < n; i++) {
  17458. var valueData = velocitysData[i];
  17459. gradient.add(valueData.key, valueData.value);
  17460. }
  17461. return gradient;
  17462. }
  17463. _initParticleColor(gradientColorData) {
  17464. var gradientColor = new Gradient(4, 4);
  17465. var alphasData = gradientColorData.alphas;
  17466. var i, n;
  17467. for (i = 0, n = alphasData.length; i < n; i++) {
  17468. var alphaData = alphasData[i];
  17469. if ((i === 3) && ((alphaData.key !== 1))) {
  17470. alphaData.key = 1;
  17471. console.log("GradientDataColor warning:the forth key is be force set to 1.");
  17472. }
  17473. gradientColor.addColorAlpha(alphaData.key, alphaData.value);
  17474. }
  17475. var rgbsData = gradientColorData.rgbs;
  17476. for (i = 0, n = rgbsData.length; i < n; i++) {
  17477. var rgbData = rgbsData[i];
  17478. var rgbValue = rgbData.value;
  17479. if ((i === 3) && ((rgbData.key !== 1))) {
  17480. rgbData.key = 1;
  17481. console.log("GradientDataColor warning:the forth key is be force set to 1.");
  17482. }
  17483. gradientColor.addColorRGB(rgbData.key, new Color(rgbValue[0], rgbValue[1], rgbValue[2], 1.0));
  17484. }
  17485. return gradientColor;
  17486. }
  17487. _initParticleSize(gradientSizeData) {
  17488. var gradientSize = new GradientDataNumber();
  17489. var sizesData = gradientSizeData.sizes;
  17490. for (var i = 0, n = sizesData.length; i < n; i++) {
  17491. var valueData = sizesData[i];
  17492. gradientSize.add(valueData.key, valueData.value);
  17493. }
  17494. return gradientSize;
  17495. }
  17496. _initParticleRotation(gradientData) {
  17497. var gradient = new GradientDataNumber();
  17498. var angularVelocitysData = gradientData.angularVelocitys;
  17499. for (var i = 0, n = angularVelocitysData.length; i < n; i++) {
  17500. var valueData = angularVelocitysData[i];
  17501. gradient.add(valueData.key, valueData.value / 180.0 * Math.PI);
  17502. }
  17503. return gradient;
  17504. }
  17505. _initParticleFrame(overTimeFramesData) {
  17506. var overTimeFrame = new GradientDataInt();
  17507. var framesData = overTimeFramesData.frames;
  17508. for (var i = 0, n = framesData.length; i < n; i++) {
  17509. var frameData = framesData[i];
  17510. overTimeFrame.add(frameData.key, frameData.value);
  17511. }
  17512. return overTimeFrame;
  17513. }
  17514. _parse(data, spriteMap) {
  17515. super._parse(data, spriteMap);
  17516. const anglelToRad = Math.PI / 180.0;
  17517. var i, n;
  17518. var particleRender = this.particleRenderer;
  17519. var material;
  17520. var materialData = data.material;
  17521. (materialData) && (material = Laya.Loader.getRes(materialData.path));
  17522. particleRender.sharedMaterial = material;
  17523. var meshPath = data.meshPath;
  17524. (meshPath) && (particleRender.mesh = Laya.Loader.getRes(meshPath));
  17525. particleRender.renderMode = data.renderMode;
  17526. particleRender.stretchedBillboardCameraSpeedScale = data.stretchedBillboardCameraSpeedScale;
  17527. particleRender.stretchedBillboardSpeedScale = data.stretchedBillboardSpeedScale;
  17528. particleRender.stretchedBillboardLengthScale = data.stretchedBillboardLengthScale;
  17529. particleRender.sortingFudge = data.sortingFudge ? data.sortingFudge : 0.0;
  17530. var particleSystem = this.particleSystem;
  17531. particleSystem.isPerformanceMode = data.isPerformanceMode;
  17532. particleSystem.duration = data.duration;
  17533. particleSystem.looping = data.looping;
  17534. particleSystem.prewarm = data.prewarm;
  17535. particleSystem.startDelayType = data.startDelayType;
  17536. particleSystem.startDelay = data.startDelay;
  17537. particleSystem.startDelayMin = data.startDelayMin;
  17538. particleSystem.startDelayMax = data.startDelayMax;
  17539. particleSystem.startLifetimeType = data.startLifetimeType;
  17540. particleSystem.startLifetimeConstant = data.startLifetimeConstant;
  17541. particleSystem.startLifeTimeGradient = ShuriKenParticle3D._initStartLife(data.startLifetimeGradient);
  17542. particleSystem.startLifetimeConstantMin = data.startLifetimeConstantMin;
  17543. particleSystem.startLifetimeConstantMax = data.startLifetimeConstantMax;
  17544. particleSystem.startLifeTimeGradientMin = ShuriKenParticle3D._initStartLife(data.startLifetimeGradientMin);
  17545. particleSystem.startLifeTimeGradientMax = ShuriKenParticle3D._initStartLife(data.startLifetimeGradientMax);
  17546. particleSystem.startSpeedType = data.startSpeedType;
  17547. particleSystem.startSpeedConstant = data.startSpeedConstant;
  17548. particleSystem.startSpeedConstantMin = data.startSpeedConstantMin;
  17549. particleSystem.startSpeedConstantMax = data.startSpeedConstantMax;
  17550. particleSystem.threeDStartSize = data.threeDStartSize;
  17551. particleSystem.startSizeType = data.startSizeType;
  17552. particleSystem.startSizeConstant = data.startSizeConstant;
  17553. var startSizeConstantSeparateArray = data.startSizeConstantSeparate;
  17554. var startSizeConstantSeparateElement = particleSystem.startSizeConstantSeparate;
  17555. startSizeConstantSeparateElement.x = startSizeConstantSeparateArray[0];
  17556. startSizeConstantSeparateElement.y = startSizeConstantSeparateArray[1];
  17557. startSizeConstantSeparateElement.z = startSizeConstantSeparateArray[2];
  17558. particleSystem.startSizeConstantMin = data.startSizeConstantMin;
  17559. particleSystem.startSizeConstantMax = data.startSizeConstantMax;
  17560. var startSizeConstantMinSeparateArray = data.startSizeConstantMinSeparate;
  17561. var startSizeConstantMinSeparateElement = particleSystem.startSizeConstantMinSeparate;
  17562. startSizeConstantMinSeparateElement.x = startSizeConstantMinSeparateArray[0];
  17563. startSizeConstantMinSeparateElement.y = startSizeConstantMinSeparateArray[1];
  17564. startSizeConstantMinSeparateElement.z = startSizeConstantMinSeparateArray[2];
  17565. var startSizeConstantMaxSeparateArray = data.startSizeConstantMaxSeparate;
  17566. var startSizeConstantMaxSeparateElement = particleSystem.startSizeConstantMaxSeparate;
  17567. startSizeConstantMaxSeparateElement.x = startSizeConstantMaxSeparateArray[0];
  17568. startSizeConstantMaxSeparateElement.y = startSizeConstantMaxSeparateArray[1];
  17569. startSizeConstantMaxSeparateElement.z = startSizeConstantMaxSeparateArray[2];
  17570. particleSystem.threeDStartRotation = data.threeDStartRotation;
  17571. particleSystem.startRotationType = data.startRotationType;
  17572. particleSystem.startRotationConstant = data.startRotationConstant * anglelToRad;
  17573. var startRotationConstantSeparateArray = data.startRotationConstantSeparate;
  17574. var startRotationConstantSeparateElement = particleSystem.startRotationConstantSeparate;
  17575. startRotationConstantSeparateElement.x = startRotationConstantSeparateArray[0] * anglelToRad;
  17576. startRotationConstantSeparateElement.y = startRotationConstantSeparateArray[1] * anglelToRad;
  17577. startRotationConstantSeparateElement.z = startRotationConstantSeparateArray[2] * anglelToRad;
  17578. particleSystem.startRotationConstantMin = data.startRotationConstantMin * anglelToRad;
  17579. particleSystem.startRotationConstantMax = data.startRotationConstantMax * anglelToRad;
  17580. var startRotationConstantMinSeparateArray = data.startRotationConstantMinSeparate;
  17581. var startRotationConstantMinSeparateElement = particleSystem.startRotationConstantMinSeparate;
  17582. startRotationConstantMinSeparateElement.x = startRotationConstantMinSeparateArray[0] * anglelToRad;
  17583. startRotationConstantMinSeparateElement.y = startRotationConstantMinSeparateArray[1] * anglelToRad;
  17584. startRotationConstantMinSeparateElement.z = startRotationConstantMinSeparateArray[2] * anglelToRad;
  17585. var startRotationConstantMaxSeparateArray = data.startRotationConstantMaxSeparate;
  17586. var startRotationConstantMaxSeparateElement = particleSystem.startRotationConstantMaxSeparate;
  17587. startRotationConstantMaxSeparateElement.x = startRotationConstantMaxSeparateArray[0] * anglelToRad;
  17588. startRotationConstantMaxSeparateElement.y = startRotationConstantMaxSeparateArray[1] * anglelToRad;
  17589. startRotationConstantMaxSeparateElement.z = startRotationConstantMaxSeparateArray[2] * anglelToRad;
  17590. particleSystem.randomizeRotationDirection = data.randomizeRotationDirection;
  17591. particleSystem.startColorType = data.startColorType;
  17592. var startColorConstantArray = data.startColorConstant;
  17593. var startColorConstantElement = particleSystem.startColorConstant;
  17594. startColorConstantElement.x = startColorConstantArray[0];
  17595. startColorConstantElement.y = startColorConstantArray[1];
  17596. startColorConstantElement.z = startColorConstantArray[2];
  17597. startColorConstantElement.w = startColorConstantArray[3];
  17598. var startColorConstantMinArray = data.startColorConstantMin;
  17599. var startColorConstantMinElement = particleSystem.startColorConstantMin;
  17600. startColorConstantMinElement.x = startColorConstantMinArray[0];
  17601. startColorConstantMinElement.y = startColorConstantMinArray[1];
  17602. startColorConstantMinElement.z = startColorConstantMinArray[2];
  17603. startColorConstantMinElement.w = startColorConstantMinArray[3];
  17604. var startColorConstantMaxArray = data.startColorConstantMax;
  17605. var startColorConstantMaxElement = particleSystem.startColorConstantMax;
  17606. startColorConstantMaxElement.x = startColorConstantMaxArray[0];
  17607. startColorConstantMaxElement.y = startColorConstantMaxArray[1];
  17608. startColorConstantMaxElement.z = startColorConstantMaxArray[2];
  17609. startColorConstantMaxElement.w = startColorConstantMaxArray[3];
  17610. particleSystem.gravityModifier = data.gravityModifier;
  17611. particleSystem.simulationSpace = data.simulationSpace;
  17612. particleSystem.scaleMode = data.scaleMode;
  17613. particleSystem.playOnAwake = data.playOnAwake;
  17614. particleSystem.maxParticles = data.maxParticles;
  17615. var autoRandomSeed = data.autoRandomSeed;
  17616. (autoRandomSeed != null) && (particleSystem.autoRandomSeed = autoRandomSeed);
  17617. var randomSeed = data.randomSeed;
  17618. (randomSeed != null) && (particleSystem.randomSeed[0] = randomSeed);
  17619. var emissionData = data.emission;
  17620. var emission = particleSystem.emission;
  17621. if (emissionData) {
  17622. emission.emissionRate = emissionData.emissionRate;
  17623. var burstsData = emissionData.bursts;
  17624. if (burstsData)
  17625. for (i = 0, n = burstsData.length; i < n; i++) {
  17626. var brust = burstsData[i];
  17627. emission.addBurst(new Burst(brust.time, brust.min, brust.max));
  17628. }
  17629. emission.enbale = emissionData.enable;
  17630. }
  17631. else {
  17632. emission.enbale = false;
  17633. }
  17634. var shapeData = data.shape;
  17635. if (shapeData) {
  17636. var shape;
  17637. switch (shapeData.shapeType) {
  17638. case 0:
  17639. var sphereShape;
  17640. shape = sphereShape = new SphereShape();
  17641. sphereShape.radius = shapeData.sphereRadius;
  17642. sphereShape.emitFromShell = shapeData.sphereEmitFromShell;
  17643. sphereShape.randomDirection = shapeData.sphereRandomDirection;
  17644. break;
  17645. case 1:
  17646. var hemiSphereShape;
  17647. shape = hemiSphereShape = new HemisphereShape();
  17648. hemiSphereShape.radius = shapeData.hemiSphereRadius;
  17649. hemiSphereShape.emitFromShell = shapeData.hemiSphereEmitFromShell;
  17650. hemiSphereShape.randomDirection = shapeData.hemiSphereRandomDirection;
  17651. break;
  17652. case 2:
  17653. var coneShape;
  17654. shape = coneShape = new ConeShape();
  17655. coneShape.angle = shapeData.coneAngle * anglelToRad;
  17656. coneShape.radius = shapeData.coneRadius;
  17657. coneShape.length = shapeData.coneLength;
  17658. coneShape.emitType = shapeData.coneEmitType;
  17659. coneShape.randomDirection = shapeData.coneRandomDirection;
  17660. break;
  17661. case 3:
  17662. var boxShape;
  17663. shape = boxShape = new BoxShape();
  17664. boxShape.x = shapeData.boxX;
  17665. boxShape.y = shapeData.boxY;
  17666. boxShape.z = shapeData.boxZ;
  17667. boxShape.randomDirection = shapeData.boxRandomDirection;
  17668. break;
  17669. case 7:
  17670. var circleShape;
  17671. shape = circleShape = new CircleShape();
  17672. circleShape.radius = shapeData.circleRadius;
  17673. circleShape.arc = shapeData.circleArc * anglelToRad;
  17674. circleShape.emitFromEdge = shapeData.circleEmitFromEdge;
  17675. circleShape.randomDirection = shapeData.circleRandomDirection;
  17676. break;
  17677. default:
  17678. var tempShape;
  17679. shape = tempShape = new CircleShape();
  17680. tempShape.radius = shapeData.circleRadius;
  17681. tempShape.arc = shapeData.circleArc * anglelToRad;
  17682. tempShape.emitFromEdge = shapeData.circleEmitFromEdge;
  17683. tempShape.randomDirection = shapeData.circleRandomDirection;
  17684. break;
  17685. }
  17686. shape.enable = shapeData.enable;
  17687. particleSystem.shape = shape;
  17688. }
  17689. var velocityOverLifetimeData = data.velocityOverLifetime;
  17690. if (velocityOverLifetimeData) {
  17691. var velocityData = velocityOverLifetimeData.velocity;
  17692. var velocity;
  17693. switch (velocityData.type) {
  17694. case 0:
  17695. var constantData = velocityData.constant;
  17696. velocity = GradientVelocity.createByConstant(new Vector3(constantData[0], constantData[1], constantData[2]));
  17697. break;
  17698. case 1:
  17699. velocity = GradientVelocity.createByGradient(this._initParticleVelocity(velocityData.gradientX), this._initParticleVelocity(velocityData.gradientY), this._initParticleVelocity(velocityData.gradientZ));
  17700. break;
  17701. case 2:
  17702. var constantMinData = velocityData.constantMin;
  17703. var constantMaxData = velocityData.constantMax;
  17704. velocity = GradientVelocity.createByRandomTwoConstant(new Vector3(constantMinData[0], constantMinData[1], constantMinData[2]), new Vector3(constantMaxData[0], constantMaxData[1], constantMaxData[2]));
  17705. break;
  17706. case 3:
  17707. velocity = GradientVelocity.createByRandomTwoGradient(this._initParticleVelocity(velocityData.gradientXMin), this._initParticleVelocity(velocityData.gradientXMax), this._initParticleVelocity(velocityData.gradientYMin), this._initParticleVelocity(velocityData.gradientYMax), this._initParticleVelocity(velocityData.gradientZMin), this._initParticleVelocity(velocityData.gradientZMax));
  17708. break;
  17709. }
  17710. var velocityOverLifetime = new VelocityOverLifetime(velocity);
  17711. velocityOverLifetime.space = velocityOverLifetimeData.space;
  17712. velocityOverLifetime.enbale = velocityOverLifetimeData.enable;
  17713. particleSystem.velocityOverLifetime = velocityOverLifetime;
  17714. }
  17715. var colorOverLifetimeData = data.colorOverLifetime;
  17716. if (colorOverLifetimeData) {
  17717. var colorData = colorOverLifetimeData.color;
  17718. var color;
  17719. switch (colorData.type) {
  17720. case 0:
  17721. var constColorData = colorData.constant;
  17722. color = GradientColor.createByConstant(new Vector4(constColorData[0], constColorData[1], constColorData[2], constColorData[3]));
  17723. break;
  17724. case 1:
  17725. color = GradientColor.createByGradient(this._initParticleColor(colorData.gradient));
  17726. break;
  17727. case 2:
  17728. var minConstColorData = colorData.constantMin;
  17729. var maxConstColorData = colorData.constantMax;
  17730. color = GradientColor.createByRandomTwoConstant(new Vector4(minConstColorData[0], minConstColorData[1], minConstColorData[2], minConstColorData[3]), new Vector4(maxConstColorData[0], maxConstColorData[1], maxConstColorData[2], maxConstColorData[3]));
  17731. break;
  17732. case 3:
  17733. color = GradientColor.createByRandomTwoGradient(this._initParticleColor(colorData.gradientMin), this._initParticleColor(colorData.gradientMax));
  17734. break;
  17735. }
  17736. var colorOverLifetime = new ColorOverLifetime(color);
  17737. colorOverLifetime.enbale = colorOverLifetimeData.enable;
  17738. particleSystem.colorOverLifetime = colorOverLifetime;
  17739. }
  17740. var sizeOverLifetimeData = data.sizeOverLifetime;
  17741. if (sizeOverLifetimeData) {
  17742. var sizeData = sizeOverLifetimeData.size;
  17743. var size;
  17744. switch (sizeData.type) {
  17745. case 0:
  17746. if (sizeData.separateAxes) {
  17747. size = GradientSize.createByGradientSeparate(this._initParticleSize(sizeData.gradientX), this._initParticleSize(sizeData.gradientY), this._initParticleSize(sizeData.gradientZ));
  17748. }
  17749. else {
  17750. size = GradientSize.createByGradient(this._initParticleSize(sizeData.gradient));
  17751. }
  17752. break;
  17753. case 1:
  17754. if (sizeData.separateAxes) {
  17755. var constantMinSeparateData = sizeData.constantMinSeparate;
  17756. var constantMaxSeparateData = sizeData.constantMaxSeparate;
  17757. size = GradientSize.createByRandomTwoConstantSeparate(new Vector3(constantMinSeparateData[0], constantMinSeparateData[1], constantMinSeparateData[2]), new Vector3(constantMaxSeparateData[0], constantMaxSeparateData[1], constantMaxSeparateData[2]));
  17758. }
  17759. else {
  17760. size = GradientSize.createByRandomTwoConstant(sizeData.constantMin, sizeData.constantMax);
  17761. }
  17762. break;
  17763. case 2:
  17764. if (sizeData.separateAxes) {
  17765. size = GradientSize.createByRandomTwoGradientSeparate(this._initParticleSize(sizeData.gradientXMin), this._initParticleSize(sizeData.gradientYMin), this._initParticleSize(sizeData.gradientZMin), this._initParticleSize(sizeData.gradientXMax), this._initParticleSize(sizeData.gradientYMax), this._initParticleSize(sizeData.gradientZMax));
  17766. }
  17767. else {
  17768. size = GradientSize.createByRandomTwoGradient(this._initParticleSize(sizeData.gradientMin), this._initParticleSize(sizeData.gradientMax));
  17769. }
  17770. break;
  17771. }
  17772. var sizeOverLifetime = new SizeOverLifetime(size);
  17773. sizeOverLifetime.enbale = sizeOverLifetimeData.enable;
  17774. particleSystem.sizeOverLifetime = sizeOverLifetime;
  17775. }
  17776. var rotationOverLifetimeData = data.rotationOverLifetime;
  17777. if (rotationOverLifetimeData) {
  17778. var angularVelocityData = rotationOverLifetimeData.angularVelocity;
  17779. var angularVelocity;
  17780. switch (angularVelocityData.type) {
  17781. case 0:
  17782. if (angularVelocityData.separateAxes) {
  17783. var conSep = angularVelocityData.constantSeparate;
  17784. angularVelocity = GradientAngularVelocity.createByConstantSeparate(new Vector3(conSep[0] * anglelToRad, conSep[1] * anglelToRad, conSep[2] * anglelToRad));
  17785. }
  17786. else {
  17787. angularVelocity = GradientAngularVelocity.createByConstant(angularVelocityData.constant * anglelToRad);
  17788. }
  17789. break;
  17790. case 1:
  17791. if (angularVelocityData.separateAxes) {
  17792. angularVelocity = GradientAngularVelocity.createByGradientSeparate(this._initParticleRotation(angularVelocityData.gradientX), this._initParticleRotation(angularVelocityData.gradientY), this._initParticleRotation(angularVelocityData.gradientZ));
  17793. }
  17794. else {
  17795. angularVelocity = GradientAngularVelocity.createByGradient(this._initParticleRotation(angularVelocityData.gradient));
  17796. }
  17797. break;
  17798. case 2:
  17799. if (angularVelocityData.separateAxes) {
  17800. var minSep = angularVelocityData.constantMinSeparate;
  17801. var maxSep = angularVelocityData.constantMaxSeparate;
  17802. angularVelocity = GradientAngularVelocity.createByRandomTwoConstantSeparate(new Vector3(minSep[0] * anglelToRad, minSep[1] * anglelToRad, minSep[2] * anglelToRad), new Vector3(maxSep[0] * anglelToRad, maxSep[1] * anglelToRad, maxSep[2] * anglelToRad));
  17803. }
  17804. else {
  17805. angularVelocity = GradientAngularVelocity.createByRandomTwoConstant(angularVelocityData.constantMin * anglelToRad, angularVelocityData.constantMax * anglelToRad);
  17806. }
  17807. break;
  17808. case 3:
  17809. if (angularVelocityData.separateAxes) ;
  17810. else {
  17811. angularVelocity = GradientAngularVelocity.createByRandomTwoGradient(this._initParticleRotation(angularVelocityData.gradientMin), this._initParticleRotation(angularVelocityData.gradientMax));
  17812. }
  17813. break;
  17814. }
  17815. var rotationOverLifetime = new RotationOverLifetime(angularVelocity);
  17816. rotationOverLifetime.enbale = rotationOverLifetimeData.enable;
  17817. particleSystem.rotationOverLifetime = rotationOverLifetime;
  17818. }
  17819. var textureSheetAnimationData = data.textureSheetAnimation;
  17820. if (textureSheetAnimationData) {
  17821. var frameData = textureSheetAnimationData.frame;
  17822. var frameOverTime;
  17823. switch (frameData.type) {
  17824. case 0:
  17825. frameOverTime = FrameOverTime.createByConstant(frameData.constant);
  17826. break;
  17827. case 1:
  17828. frameOverTime = FrameOverTime.createByOverTime(this._initParticleFrame(frameData.overTime));
  17829. break;
  17830. case 2:
  17831. frameOverTime = FrameOverTime.createByRandomTwoConstant(frameData.constantMin, frameData.constantMax);
  17832. break;
  17833. case 3:
  17834. frameOverTime = FrameOverTime.createByRandomTwoOverTime(this._initParticleFrame(frameData.overTimeMin), this._initParticleFrame(frameData.overTimeMax));
  17835. break;
  17836. }
  17837. var startFrameData = textureSheetAnimationData.startFrame;
  17838. var startFrame;
  17839. switch (startFrameData.type) {
  17840. case 0:
  17841. startFrame = StartFrame.createByConstant(startFrameData.constant);
  17842. break;
  17843. case 1:
  17844. startFrame = StartFrame.createByRandomTwoConstant(startFrameData.constantMin, startFrameData.constantMax);
  17845. break;
  17846. }
  17847. var textureSheetAnimation = new TextureSheetAnimation(frameOverTime, startFrame);
  17848. textureSheetAnimation.enable = textureSheetAnimationData.enable;
  17849. var tilesData = textureSheetAnimationData.tiles;
  17850. textureSheetAnimation.tiles = new Vector2(tilesData[0], tilesData[1]);
  17851. textureSheetAnimation.type = textureSheetAnimationData.type;
  17852. textureSheetAnimation.randomRow = textureSheetAnimationData.randomRow;
  17853. var rowIndex = textureSheetAnimationData.rowIndex;
  17854. (rowIndex !== undefined) && (textureSheetAnimation.rowIndex = rowIndex);
  17855. textureSheetAnimation.cycles = textureSheetAnimationData.cycles;
  17856. particleSystem.textureSheetAnimation = textureSheetAnimation;
  17857. }
  17858. }
  17859. _activeHierarchy(activeChangeComponents) {
  17860. super._activeHierarchy(activeChangeComponents);
  17861. (this.particleSystem.playOnAwake) && (this.particleSystem.play());
  17862. }
  17863. _inActiveHierarchy(activeChangeComponents) {
  17864. super._inActiveHierarchy(activeChangeComponents);
  17865. (this.particleSystem.isAlive) && (this.particleSystem.simulate(0, true));
  17866. }
  17867. _cloneTo(destObject, srcSprite, dstSprite) {
  17868. var destShuriKenParticle3D = destObject;
  17869. var destParticleSystem = destShuriKenParticle3D._particleSystem;
  17870. this._particleSystem.cloneTo(destParticleSystem);
  17871. var destParticleRender = destShuriKenParticle3D._render;
  17872. var particleRender = this._render;
  17873. destParticleRender.sharedMaterials = particleRender.sharedMaterials;
  17874. destParticleRender.enable = particleRender.enable;
  17875. destParticleRender.renderMode = particleRender.renderMode;
  17876. destParticleRender.mesh = particleRender.mesh;
  17877. destParticleRender.stretchedBillboardCameraSpeedScale = particleRender.stretchedBillboardCameraSpeedScale;
  17878. destParticleRender.stretchedBillboardSpeedScale = particleRender.stretchedBillboardSpeedScale;
  17879. destParticleRender.stretchedBillboardLengthScale = particleRender.stretchedBillboardLengthScale;
  17880. destParticleRender.sortingFudge = particleRender.sortingFudge;
  17881. super._cloneTo(destObject, srcSprite, dstSprite);
  17882. }
  17883. destroy(destroyChild = true) {
  17884. if (this.destroyed)
  17885. return;
  17886. super.destroy(destroyChild);
  17887. this._particleSystem.destroy();
  17888. this._particleSystem = null;
  17889. }
  17890. _create() {
  17891. return new ShuriKenParticle3D();
  17892. }
  17893. }
  17894. class CastShadowList extends SingletonList {
  17895. constructor() {
  17896. super();
  17897. }
  17898. add(element) {
  17899. var index = element._indexInCastShadowList;
  17900. if (index !== -1)
  17901. throw "CastShadowList:element has in CastShadowList.";
  17902. this._add(element);
  17903. element._indexInCastShadowList = this.length++;
  17904. }
  17905. remove(element) {
  17906. var index = element._indexInCastShadowList;
  17907. this.length--;
  17908. if (index !== this.length) {
  17909. var end = this.elements[this.length];
  17910. this.elements[index] = end;
  17911. end._indexInCastShadowList = index;
  17912. }
  17913. element._indexInCastShadowList = -1;
  17914. }
  17915. }
  17916. class SimpleSingletonList extends SingletonList {
  17917. constructor() {
  17918. super();
  17919. }
  17920. add(element) {
  17921. var index = element._getIndexInList();
  17922. if (index !== -1)
  17923. throw "SimpleSingletonList:" + element + " has in SingletonList.";
  17924. this._add(element);
  17925. element._setIndexInList(this.length++);
  17926. }
  17927. remove(element) {
  17928. var index = element._getIndexInList();
  17929. this.length--;
  17930. if (index !== this.length) {
  17931. var end = this.elements[this.length];
  17932. this.elements[index] = end;
  17933. end._setIndexInList(index);
  17934. }
  17935. element._setIndexInList(-1);
  17936. }
  17937. }
  17938. class MouseTouch {
  17939. constructor() {
  17940. this._pressedSprite = null;
  17941. this._pressedLoopCount = -1;
  17942. this.sprite = null;
  17943. this.mousePositionX = 0;
  17944. this.mousePositionY = 0;
  17945. }
  17946. }
  17947. class Touch {
  17948. constructor() {
  17949. this._indexInList = -1;
  17950. this._identifier = -1;
  17951. this._position = new Vector2();
  17952. }
  17953. get identifier() {
  17954. return this._identifier;
  17955. }
  17956. get position() {
  17957. return this._position;
  17958. }
  17959. _getIndexInList() {
  17960. return this._indexInList;
  17961. }
  17962. _setIndexInList(index) {
  17963. this._indexInList = index;
  17964. }
  17965. }
  17966. class Input3D {
  17967. constructor() {
  17968. this._eventList = [];
  17969. this._mouseTouch = new MouseTouch();
  17970. this._touchPool = [];
  17971. this._touches = new SimpleSingletonList();
  17972. this._multiTouchEnabled = true;
  17973. this._pushEventList = ((e) => {
  17974. e.preventDefault();
  17975. this._eventList.push(e);
  17976. }).bind(this);
  17977. }
  17978. __init__(canvas, scene) {
  17979. this._scene = scene;
  17980. canvas.oncontextmenu = function (e) {
  17981. return false;
  17982. };
  17983. }
  17984. _onCanvasEvent(canvas) {
  17985. canvas.addEventListener('mousedown', this._pushEventList);
  17986. canvas.addEventListener('mouseup', this._pushEventList, true);
  17987. canvas.addEventListener('mousemove', this._pushEventList, true);
  17988. canvas.addEventListener("touchstart", this._pushEventList);
  17989. canvas.addEventListener("touchend", this._pushEventList, true);
  17990. canvas.addEventListener("touchmove", this._pushEventList, true);
  17991. canvas.addEventListener("touchcancel", this._pushEventList, true);
  17992. }
  17993. _offCanvasEvent(canvas) {
  17994. canvas.removeEventListener('mousedown', this._pushEventList);
  17995. canvas.removeEventListener('mouseup', this._pushEventList, true);
  17996. canvas.removeEventListener('mousemove', this._pushEventList, true);
  17997. canvas.removeEventListener("touchstart", this._pushEventList);
  17998. canvas.removeEventListener("touchend", this._pushEventList, true);
  17999. canvas.removeEventListener("touchmove", this._pushEventList, true);
  18000. canvas.removeEventListener("touchcancel", this._pushEventList, true);
  18001. this._eventList.length = 0;
  18002. this._touches.length = 0;
  18003. }
  18004. touchCount() {
  18005. return this._touches.length;
  18006. }
  18007. get multiTouchEnabled() {
  18008. return this._multiTouchEnabled;
  18009. }
  18010. set multiTouchEnabled(value) {
  18011. this._multiTouchEnabled = value;
  18012. }
  18013. _getTouch(touchID) {
  18014. var touch = this._touchPool[touchID];
  18015. if (!touch) {
  18016. touch = new Touch();
  18017. this._touchPool[touchID] = touch;
  18018. touch._identifier = touchID;
  18019. }
  18020. return touch;
  18021. }
  18022. _mouseTouchDown() {
  18023. var touch = this._mouseTouch;
  18024. var sprite = touch.sprite;
  18025. touch._pressedSprite = sprite;
  18026. touch._pressedLoopCount = Laya.Stat.loopCount;
  18027. if (sprite) {
  18028. var scripts = sprite._scripts;
  18029. if (scripts) {
  18030. for (var i = 0, n = scripts.length; i < n; i++)
  18031. scripts[i].onMouseDown();
  18032. }
  18033. }
  18034. }
  18035. _mouseTouchUp() {
  18036. var i, n;
  18037. var touch = this._mouseTouch;
  18038. var lastPressedSprite = touch._pressedSprite;
  18039. touch._pressedSprite = null;
  18040. touch._pressedLoopCount = -1;
  18041. var sprite = touch.sprite;
  18042. if (sprite) {
  18043. if (sprite === lastPressedSprite) {
  18044. var scripts = sprite._scripts;
  18045. if (scripts) {
  18046. for (i = 0, n = scripts.length; i < n; i++)
  18047. scripts[i].onMouseClick();
  18048. }
  18049. }
  18050. }
  18051. if (lastPressedSprite) {
  18052. var lastScripts = lastPressedSprite._scripts;
  18053. if (lastScripts) {
  18054. for (i = 0, n = lastScripts.length; i < n; i++)
  18055. lastScripts[i].onMouseUp();
  18056. }
  18057. }
  18058. }
  18059. _mouseTouchRayCast(cameras) {
  18060. var touchHitResult = Input3D._tempHitResult0;
  18061. var touchPos = Input3D._tempVector20;
  18062. var touchRay = Input3D._tempRay0;
  18063. touchHitResult.succeeded = false;
  18064. var x = this._mouseTouch.mousePositionX;
  18065. var y = this._mouseTouch.mousePositionY;
  18066. touchPos.x = x;
  18067. touchPos.y = y;
  18068. for (var i = cameras.length - 1; i >= 0; i--) {
  18069. var camera = cameras[i];
  18070. var viewport = camera.viewport;
  18071. if (touchPos.x >= viewport.x && touchPos.y >= viewport.y && touchPos.x <= viewport.width && touchPos.y <= viewport.height) {
  18072. camera.viewportPointToRay(touchPos, touchRay);
  18073. var sucess = this._scene._physicsSimulation.rayCast(touchRay, touchHitResult);
  18074. if (sucess || (camera.clearFlag === BaseCamera.CLEARFLAG_SOLIDCOLOR || camera.clearFlag === BaseCamera.CLEARFLAG_SKY))
  18075. break;
  18076. }
  18077. }
  18078. var touch = this._mouseTouch;
  18079. var lastSprite = touch.sprite;
  18080. if (touchHitResult.succeeded) {
  18081. var touchSprite = touchHitResult.collider.owner;
  18082. touch.sprite = touchSprite;
  18083. var scripts = touchSprite._scripts;
  18084. if (lastSprite !== touchSprite) {
  18085. if (scripts) {
  18086. for (var j = 0, m = scripts.length; j < m; j++)
  18087. scripts[j].onMouseEnter();
  18088. }
  18089. }
  18090. }
  18091. else {
  18092. touch.sprite = null;
  18093. }
  18094. if (lastSprite && (lastSprite !== touchSprite)) {
  18095. var outScripts = lastSprite._scripts;
  18096. if (outScripts) {
  18097. for (j = 0, m = outScripts.length; j < m; j++)
  18098. outScripts[j].onMouseOut();
  18099. }
  18100. }
  18101. }
  18102. _changeTouches(changedTouches, flag) {
  18103. var offsetX = 0, offsetY = 0;
  18104. var lastCount = this._touches.length;
  18105. for (var j = 0, m = changedTouches.length; j < m; j++) {
  18106. var nativeTouch = changedTouches[j];
  18107. var identifier = nativeTouch.identifier;
  18108. if (!this._multiTouchEnabled && identifier !== 0)
  18109. continue;
  18110. var touch = this._getTouch(identifier);
  18111. var pos = touch._position;
  18112. var mousePoint = Input3D._tempPoint;
  18113. mousePoint.setTo(nativeTouch.pageX, nativeTouch.pageY);
  18114. Laya.ILaya.stage._canvasTransform.invertTransformPoint(mousePoint);
  18115. var posX = mousePoint.x;
  18116. var posY = mousePoint.y;
  18117. switch (flag) {
  18118. case 0:
  18119. this._touches.add(touch);
  18120. offsetX += posX;
  18121. offsetY += posY;
  18122. break;
  18123. case 1:
  18124. this._touches.remove(touch);
  18125. offsetX -= posX;
  18126. offsetY -= posY;
  18127. break;
  18128. case 2:
  18129. offsetX = posX - pos.x;
  18130. offsetY = posY - pos.y;
  18131. break;
  18132. }
  18133. pos.x = posX;
  18134. pos.y = posY;
  18135. }
  18136. var touchCount = this._touches.length;
  18137. if (touchCount === 0) {
  18138. this._mouseTouch.mousePositionX = 0;
  18139. this._mouseTouch.mousePositionY = 0;
  18140. }
  18141. else {
  18142. this._mouseTouch.mousePositionX = (this._mouseTouch.mousePositionX * lastCount + offsetX) / touchCount;
  18143. this._mouseTouch.mousePositionY = (this._mouseTouch.mousePositionY * lastCount + offsetY) / touchCount;
  18144. }
  18145. }
  18146. _update() {
  18147. var enablePhysics = Physics3D._enbalePhysics && !PhysicsSimulation.disableSimulation;
  18148. var i, n, j, m;
  18149. n = this._eventList.length;
  18150. var cameras = this._scene._cameraPool;
  18151. if (n > 0) {
  18152. var rayCast = false;
  18153. for (i = 0; i < n; i++) {
  18154. var e = this._eventList[i];
  18155. switch (e.type) {
  18156. case "mousedown":
  18157. (enablePhysics) && (this._mouseTouchDown());
  18158. break;
  18159. case "mouseup":
  18160. (enablePhysics) && (this._mouseTouchUp());
  18161. break;
  18162. case "mousemove":
  18163. var mousePoint = Input3D._tempPoint;
  18164. mousePoint.setTo(e.pageX, e.pageY);
  18165. Laya.ILaya.stage._canvasTransform.invertTransformPoint(mousePoint);
  18166. this._mouseTouch.mousePositionX = mousePoint.x;
  18167. this._mouseTouch.mousePositionY = mousePoint.y;
  18168. (enablePhysics) && (rayCast = true);
  18169. break;
  18170. case "touchstart":
  18171. var lastLength = this._touches.length;
  18172. this._changeTouches(e.changedTouches, 0);
  18173. if (enablePhysics) {
  18174. rayCast = true;
  18175. (lastLength === 0) && (this._mouseTouchDown());
  18176. }
  18177. break;
  18178. case "touchend":
  18179. case "touchcancel":
  18180. this._changeTouches(e.changedTouches, 1);
  18181. (enablePhysics && this._touches.length === 0) && (this._mouseTouchUp());
  18182. break;
  18183. case "touchmove":
  18184. this._changeTouches(e.changedTouches, 2);
  18185. (enablePhysics) && (rayCast = true);
  18186. break;
  18187. default:
  18188. throw "Input3D:unkonwn event type.";
  18189. }
  18190. }
  18191. (rayCast) && (this._mouseTouchRayCast(cameras));
  18192. this._eventList.length = 0;
  18193. }
  18194. if (enablePhysics) {
  18195. var mouseTouch = this._mouseTouch;
  18196. var pressedSprite = mouseTouch._pressedSprite;
  18197. if (pressedSprite && (Laya.Stat.loopCount > mouseTouch._pressedLoopCount)) {
  18198. var pressedScripts = pressedSprite._scripts;
  18199. if (pressedScripts) {
  18200. for (j = 0, m = pressedScripts.length; j < m; j++)
  18201. pressedScripts[j].onMouseDrag();
  18202. }
  18203. }
  18204. var touchSprite = mouseTouch.sprite;
  18205. if (touchSprite) {
  18206. var scripts = touchSprite._scripts;
  18207. if (scripts) {
  18208. for (j = 0, m = scripts.length; j < m; j++)
  18209. scripts[j].onMouseOver();
  18210. }
  18211. }
  18212. }
  18213. }
  18214. getTouch(index) {
  18215. if (index < this._touches.length) {
  18216. return this._touches.elements[index];
  18217. }
  18218. else {
  18219. return null;
  18220. }
  18221. }
  18222. }
  18223. Input3D._tempPoint = new Laya.Point();
  18224. Input3D._tempVector20 = new Vector2();
  18225. Input3D._tempRay0 = new Ray(new Vector3(), new Vector3());
  18226. Input3D._tempHitResult0 = new HitResult();
  18227. class PhysicsSettings {
  18228. constructor() {
  18229. this.flags = 0;
  18230. this.maxSubSteps = 1;
  18231. this.fixedTimeStep = 1.0 / 60.0;
  18232. }
  18233. }
  18234. class VertexPositionTexture0 {
  18235. static get vertexDeclaration() {
  18236. return VertexPositionTexture0._vertexDeclaration;
  18237. }
  18238. static __init__() {
  18239. VertexPositionTexture0._vertexDeclaration = new VertexDeclaration(20, [new VertexElement(0, VertexElementFormat.Vector3, VertexMesh.MESH_POSITION0),
  18240. new VertexElement(12, VertexElementFormat.Vector2, VertexMesh.MESH_TEXTURECOORDINATE0)]);
  18241. }
  18242. get position() {
  18243. return this._position;
  18244. }
  18245. get textureCoordinate0() {
  18246. return this._textureCoordinate0;
  18247. }
  18248. get vertexDeclaration() {
  18249. return VertexPositionTexture0._vertexDeclaration;
  18250. }
  18251. constructor(position, textureCoordinate0) {
  18252. this._position = position;
  18253. this._textureCoordinate0 = textureCoordinate0;
  18254. }
  18255. }
  18256. class SkyDome extends SkyMesh {
  18257. constructor(stacks = 48, slices = 48) {
  18258. super();
  18259. var gl = Laya.LayaGL.instance;
  18260. this._stacks = stacks;
  18261. this._slices = slices;
  18262. var vertexDeclaration = VertexPositionTexture0.vertexDeclaration;
  18263. var vertexFloatCount = vertexDeclaration.vertexStride / 4;
  18264. var numberVertices = (this._stacks + 1) * (this._slices + 1);
  18265. var numberIndices = (3 * this._stacks * (this._slices + 1)) * 2;
  18266. var vertices = new Float32Array(numberVertices * vertexFloatCount);
  18267. var indices = new Uint16Array(numberIndices);
  18268. var stackAngle = Math.PI / this._stacks;
  18269. var sliceAngle = (Math.PI * 2.0) / this._slices;
  18270. var vertexIndex = 0;
  18271. var vertexCount = 0;
  18272. var indexCount = 0;
  18273. for (var stack = 0; stack < (this._stacks + 1); stack++) {
  18274. var r = Math.sin(stack * stackAngle);
  18275. var y = Math.cos(stack * stackAngle);
  18276. for (var slice = 0; slice < (this._slices + 1); slice++) {
  18277. var x = r * Math.sin(slice * sliceAngle);
  18278. var z = r * Math.cos(slice * sliceAngle);
  18279. vertices[vertexCount + 0] = x * SkyDome._radius;
  18280. vertices[vertexCount + 1] = y * SkyDome._radius;
  18281. vertices[vertexCount + 2] = z * SkyDome._radius;
  18282. vertices[vertexCount + 3] = -(slice / this._slices) + 0.75;
  18283. vertices[vertexCount + 4] = stack / this._stacks;
  18284. vertexCount += vertexFloatCount;
  18285. if (stack != (this._stacks - 1)) {
  18286. indices[indexCount++] = vertexIndex + 1;
  18287. indices[indexCount++] = vertexIndex;
  18288. indices[indexCount++] = vertexIndex + (this._slices + 1);
  18289. indices[indexCount++] = vertexIndex + (this._slices + 1);
  18290. indices[indexCount++] = vertexIndex;
  18291. indices[indexCount++] = vertexIndex + (this._slices);
  18292. vertexIndex++;
  18293. }
  18294. }
  18295. }
  18296. this._vertexBuffer = new VertexBuffer3D(vertices.length * 4, gl.STATIC_DRAW, false);
  18297. this._vertexBuffer.vertexDeclaration = vertexDeclaration;
  18298. this._indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, indices.length, gl.STATIC_DRAW, false);
  18299. this._vertexBuffer.setData(vertices.buffer);
  18300. this._indexBuffer.setData(indices);
  18301. var bufferState = new BufferState();
  18302. bufferState.bind();
  18303. bufferState.applyVertexBuffer(this._vertexBuffer);
  18304. bufferState.applyIndexBuffer(this._indexBuffer);
  18305. bufferState.unBind();
  18306. this._bufferState = bufferState;
  18307. }
  18308. static __init__() {
  18309. SkyDome.instance = new SkyDome();
  18310. }
  18311. get stacks() {
  18312. return this._stacks;
  18313. }
  18314. get slices() {
  18315. return this._slices;
  18316. }
  18317. _render(state) {
  18318. var gl = Laya.LayaGL.instance;
  18319. var indexCount = this._indexBuffer.indexCount;
  18320. gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, 0);
  18321. Laya.Stat.trianglesFaces += indexCount / 3;
  18322. Laya.Stat.renderBatches++;
  18323. }
  18324. }
  18325. SkyDome._radius = 1;
  18326. class PostProcessRenderContext {
  18327. constructor() {
  18328. this.source = null;
  18329. this.destination = null;
  18330. this.camera = null;
  18331. this.compositeShaderData = null;
  18332. this.command = null;
  18333. this.deferredReleaseTextures = [];
  18334. }
  18335. }
  18336. class PostProcess {
  18337. constructor() {
  18338. this._compositeShader = Shader3D.find("PostProcessComposite");
  18339. this._compositeShaderData = new ShaderData();
  18340. this._context = null;
  18341. this._effects = [];
  18342. this._context = new PostProcessRenderContext();
  18343. this._context.compositeShaderData = this._compositeShaderData;
  18344. }
  18345. static __init__() {
  18346. PostProcess.SHADERDEFINE_BLOOM_LOW = PostProcess.shaderDefines.registerDefine("BLOOM_LOW");
  18347. PostProcess.SHADERDEFINE_BLOOM = PostProcess.shaderDefines.registerDefine("BLOOM");
  18348. PostProcess.SHADERDEFINE_FINALPASS = PostProcess.shaderDefines.registerDefine("FINALPASS");
  18349. }
  18350. _init(camera, command) {
  18351. this._context.camera = camera;
  18352. this._context.command = command;
  18353. }
  18354. _render() {
  18355. var noteValue = ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_;
  18356. Laya.ILaya.Render.supportWebGLPlusRendering && ShaderData.setRuntimeValueMode(false);
  18357. var camera = this._context.camera;
  18358. var screenTexture = RenderTexture.createFromPool(RenderContext3D.clientWidth, RenderContext3D.clientHeight, camera._getRenderTextureFormat(), Laya.BaseTexture.FORMAT_DEPTHSTENCIL_NONE);
  18359. var cameraTarget = camera._renderTexture;
  18360. this._context.command.clear();
  18361. this._context.source = screenTexture;
  18362. this._context.destination = cameraTarget;
  18363. this._context.compositeShaderData.clearDefine();
  18364. this._context.command.blitScreenTriangle(cameraTarget, screenTexture);
  18365. this._context.compositeShaderData.setTexture(PostProcess.SHADERVALUE_AUTOEXPOSURETEX, Laya.Texture2D.whiteTexture);
  18366. for (var i = 0, n = this._effects.length; i < n; i++)
  18367. this._effects[i].render(this._context);
  18368. this._compositeShaderData.addDefine(PostProcess.SHADERDEFINE_FINALPASS);
  18369. var offScreenTexture = camera.renderTarget;
  18370. var dest = offScreenTexture ? offScreenTexture : null;
  18371. this._context.destination = dest;
  18372. this._context.command.blitScreenTriangle(this._context.source, dest, this._compositeShader, this._compositeShaderData);
  18373. RenderTexture.recoverToPool(screenTexture);
  18374. var tempRenderTextures = this._context.deferredReleaseTextures;
  18375. for (i = 0, n = tempRenderTextures.length; i < n; i++)
  18376. RenderTexture.recoverToPool(tempRenderTextures[i]);
  18377. tempRenderTextures.length = 0;
  18378. Laya.ILaya.Render.supportWebGLPlusRendering && ShaderData.setRuntimeValueMode(noteValue);
  18379. }
  18380. addEffect(effect) {
  18381. this._effects.push(effect);
  18382. }
  18383. removeEffect(effect) {
  18384. var index = this._effects.indexOf(effect);
  18385. if (index !== -1)
  18386. this._effects.splice(index, 1);
  18387. }
  18388. }
  18389. PostProcess.SHADERVALUE_MAINTEX = Shader3D.propertyNameToID("u_MainTex");
  18390. PostProcess.SHADERVALUE_BLOOMTEX = Shader3D.propertyNameToID("u_BloomTex");
  18391. PostProcess.SHADERVALUE_AUTOEXPOSURETEX = Shader3D.propertyNameToID("u_AutoExposureTex");
  18392. PostProcess.SHADERVALUE_BLOOM_DIRTTEX = Shader3D.propertyNameToID("u_Bloom_DirtTex");
  18393. PostProcess.SHADERVALUE_BLOOMTEX_TEXELSIZE = Shader3D.propertyNameToID("u_BloomTex_TexelSize");
  18394. PostProcess.SHADERVALUE_BLOOM_DIRTTILEOFFSET = Shader3D.propertyNameToID("u_Bloom_DirtTileOffset");
  18395. PostProcess.SHADERVALUE_BLOOM_SETTINGS = Shader3D.propertyNameToID("u_Bloom_Settings");
  18396. PostProcess.SHADERVALUE_BLOOM_COLOR = Shader3D.propertyNameToID("u_Bloom_Color");
  18397. PostProcess.shaderDefines = new ShaderDefines();
  18398. class EffectMaterial extends BaseMaterial {
  18399. constructor() {
  18400. super();
  18401. this.setShaderName("Effect");
  18402. this._color = new Vector4(1.0, 1.0, 1.0, 1.0);
  18403. this._shaderValues.setVector(EffectMaterial.TINTCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  18404. this.renderMode = EffectMaterial.RENDERMODE_ADDTIVE;
  18405. }
  18406. static __initDefine__() {
  18407. EffectMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  18408. EffectMaterial.SHADERDEFINE_MAINTEXTURE = EffectMaterial.shaderDefines.registerDefine("MAINTEXTURE");
  18409. EffectMaterial.SHADERDEFINE_TILINGOFFSET = EffectMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  18410. EffectMaterial.SHADERDEFINE_ADDTIVEFOG = EffectMaterial.shaderDefines.registerDefine("ADDTIVEFOG");
  18411. }
  18412. get _TintColorR() {
  18413. return this._color.x;
  18414. }
  18415. set _TintColorR(value) {
  18416. this._color.x = value;
  18417. this.color = this._color;
  18418. }
  18419. get _TintColorG() {
  18420. return this._color.y;
  18421. }
  18422. set _TintColorG(value) {
  18423. this._color.y = value;
  18424. this.color = this._color;
  18425. }
  18426. get _TintColorB() {
  18427. return this._color.z;
  18428. }
  18429. set _TintColorB(value) {
  18430. this._color.z = value;
  18431. this.color = this._color;
  18432. }
  18433. get _TintColorA() {
  18434. return this._color.w;
  18435. }
  18436. set _TintColorA(value) {
  18437. this._color.w = value;
  18438. this.color = this._color;
  18439. }
  18440. get _MainTex_STX() {
  18441. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).x;
  18442. }
  18443. set _MainTex_STX(x) {
  18444. var tilOff = this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18445. tilOff.x = x;
  18446. this.tilingOffset = tilOff;
  18447. }
  18448. get _MainTex_STY() {
  18449. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).y;
  18450. }
  18451. set _MainTex_STY(y) {
  18452. var tilOff = this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18453. tilOff.y = y;
  18454. this.tilingOffset = tilOff;
  18455. }
  18456. get _MainTex_STZ() {
  18457. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).z;
  18458. }
  18459. set _MainTex_STZ(z) {
  18460. var tilOff = this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18461. tilOff.z = z;
  18462. this.tilingOffset = tilOff;
  18463. }
  18464. get _MainTex_STW() {
  18465. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).w;
  18466. }
  18467. set _MainTex_STW(w) {
  18468. var tilOff = this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18469. tilOff.w = w;
  18470. this.tilingOffset = tilOff;
  18471. }
  18472. set renderMode(value) {
  18473. switch (value) {
  18474. case EffectMaterial.RENDERMODE_ADDTIVE:
  18475. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  18476. this.alphaTest = false;
  18477. this.depthWrite = false;
  18478. this.cull = RenderState.CULL_NONE;
  18479. this.blend = RenderState.BLEND_ENABLE_ALL;
  18480. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  18481. this.blendDst = RenderState.BLENDPARAM_ONE;
  18482. this.depthTest = RenderState.DEPTHTEST_LESS;
  18483. this._shaderValues.addDefine(EffectMaterial.SHADERDEFINE_ADDTIVEFOG);
  18484. break;
  18485. case EffectMaterial.RENDERMODE_ALPHABLENDED:
  18486. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  18487. this.alphaTest = false;
  18488. this.depthWrite = false;
  18489. this.cull = RenderState.CULL_NONE;
  18490. this.blend = RenderState.BLEND_ENABLE_ALL;
  18491. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  18492. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  18493. this.depthTest = RenderState.DEPTHTEST_LESS;
  18494. this._shaderValues.removeDefine(EffectMaterial.SHADERDEFINE_ADDTIVEFOG);
  18495. break;
  18496. default:
  18497. throw new Error("MeshEffectMaterial : renderMode value error.");
  18498. }
  18499. }
  18500. get colorR() {
  18501. return this._TintColorR;
  18502. }
  18503. set colorR(value) {
  18504. this._TintColorR = value;
  18505. }
  18506. get colorG() {
  18507. return this._TintColorG;
  18508. }
  18509. set colorG(value) {
  18510. this._TintColorG = value;
  18511. }
  18512. get colorB() {
  18513. return this._TintColorB;
  18514. }
  18515. set colorB(value) {
  18516. this._TintColorB = value;
  18517. }
  18518. get colorA() {
  18519. return this._TintColorA;
  18520. }
  18521. set colorA(value) {
  18522. this._TintColorA = value;
  18523. }
  18524. get color() {
  18525. return this._shaderValues.getVector(EffectMaterial.TINTCOLOR);
  18526. }
  18527. set color(value) {
  18528. this._shaderValues.setVector(EffectMaterial.TINTCOLOR, value);
  18529. }
  18530. get texture() {
  18531. return this._shaderValues.getTexture(EffectMaterial.MAINTEXTURE);
  18532. }
  18533. set texture(value) {
  18534. if (value)
  18535. this._shaderValues.addDefine(EffectMaterial.SHADERDEFINE_MAINTEXTURE);
  18536. else
  18537. this._shaderValues.removeDefine(EffectMaterial.SHADERDEFINE_MAINTEXTURE);
  18538. this._shaderValues.setTexture(EffectMaterial.MAINTEXTURE, value);
  18539. }
  18540. get tilingOffsetX() {
  18541. return this._MainTex_STX;
  18542. }
  18543. set tilingOffsetX(x) {
  18544. this._MainTex_STX = x;
  18545. }
  18546. get tilingOffsetY() {
  18547. return this._MainTex_STY;
  18548. }
  18549. set tilingOffsetY(y) {
  18550. this._MainTex_STY = y;
  18551. }
  18552. get tilingOffsetZ() {
  18553. return this._MainTex_STZ;
  18554. }
  18555. set tilingOffsetZ(z) {
  18556. this._MainTex_STZ = z;
  18557. }
  18558. get tilingOffsetW() {
  18559. return this._MainTex_STW;
  18560. }
  18561. set tilingOffsetW(w) {
  18562. this._MainTex_STW = w;
  18563. }
  18564. get tilingOffset() {
  18565. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18566. }
  18567. set tilingOffset(value) {
  18568. if (value) {
  18569. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  18570. this._shaderValues.addDefine(EffectMaterial.SHADERDEFINE_TILINGOFFSET);
  18571. else
  18572. this._shaderValues.removeDefine(EffectMaterial.SHADERDEFINE_TILINGOFFSET);
  18573. }
  18574. else {
  18575. this._shaderValues.removeDefine(EffectMaterial.SHADERDEFINE_TILINGOFFSET);
  18576. }
  18577. this._shaderValues.setVector(EffectMaterial.TILINGOFFSET, value);
  18578. }
  18579. set depthWrite(value) {
  18580. this._shaderValues.setBool(EffectMaterial.DEPTH_WRITE, value);
  18581. }
  18582. get depthWrite() {
  18583. return this._shaderValues.getBool(EffectMaterial.DEPTH_WRITE);
  18584. }
  18585. set cull(value) {
  18586. this._shaderValues.setInt(EffectMaterial.CULL, value);
  18587. }
  18588. get cull() {
  18589. return this._shaderValues.getInt(EffectMaterial.CULL);
  18590. }
  18591. set blend(value) {
  18592. this._shaderValues.setInt(EffectMaterial.BLEND, value);
  18593. }
  18594. get blend() {
  18595. return this._shaderValues.getInt(EffectMaterial.BLEND);
  18596. }
  18597. set blendSrc(value) {
  18598. this._shaderValues.setInt(EffectMaterial.BLEND_SRC, value);
  18599. }
  18600. get blendSrc() {
  18601. return this._shaderValues.getInt(EffectMaterial.BLEND_SRC);
  18602. }
  18603. set blendDst(value) {
  18604. this._shaderValues.setInt(EffectMaterial.BLEND_DST, value);
  18605. }
  18606. get blendDst() {
  18607. return this._shaderValues.getInt(EffectMaterial.BLEND_DST);
  18608. }
  18609. set depthTest(value) {
  18610. this._shaderValues.setInt(EffectMaterial.DEPTH_TEST, value);
  18611. }
  18612. get depthTest() {
  18613. return this._shaderValues.getInt(EffectMaterial.DEPTH_TEST);
  18614. }
  18615. clone() {
  18616. var dest = new EffectMaterial();
  18617. this.cloneTo(dest);
  18618. return dest;
  18619. }
  18620. }
  18621. EffectMaterial.RENDERMODE_ADDTIVE = 0;
  18622. EffectMaterial.RENDERMODE_ALPHABLENDED = 1;
  18623. EffectMaterial.MAINTEXTURE = Shader3D.propertyNameToID("u_AlbedoTexture");
  18624. EffectMaterial.TINTCOLOR = Shader3D.propertyNameToID("u_AlbedoColor");
  18625. EffectMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  18626. EffectMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  18627. EffectMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  18628. EffectMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  18629. EffectMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  18630. EffectMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  18631. EffectMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  18632. EffectMaterial.shaderDefines = null;
  18633. class ExtendTerrainMaterial extends BaseMaterial {
  18634. constructor() {
  18635. super();
  18636. this._enableLighting = true;
  18637. this.setShaderName("ExtendTerrain");
  18638. this.renderMode = ExtendTerrainMaterial.RENDERMODE_OPAQUE;
  18639. }
  18640. static __initDefine__() {
  18641. ExtendTerrainMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  18642. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM1");
  18643. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM2");
  18644. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM3");
  18645. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM4");
  18646. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM5");
  18647. }
  18648. get splatAlphaTexture() {
  18649. return this._shaderValues.getTexture(ExtendTerrainMaterial.SPLATALPHATEXTURE);
  18650. }
  18651. set splatAlphaTexture(value) {
  18652. this._shaderValues.setTexture(ExtendTerrainMaterial.SPLATALPHATEXTURE, value);
  18653. }
  18654. set diffuseTexture1(value) {
  18655. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE1, value);
  18656. this._setDetailNum(1);
  18657. }
  18658. get diffuseTexture2() {
  18659. return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE2);
  18660. }
  18661. set diffuseTexture2(value) {
  18662. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE2, value);
  18663. this._setDetailNum(2);
  18664. }
  18665. get diffuseTexture3() {
  18666. return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE3);
  18667. }
  18668. set diffuseTexture3(value) {
  18669. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE3, value);
  18670. this._setDetailNum(3);
  18671. }
  18672. get diffuseTexture4() {
  18673. return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE4);
  18674. }
  18675. set diffuseTexture4(value) {
  18676. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE4, value);
  18677. this._setDetailNum(4);
  18678. }
  18679. get diffuseTexture5() {
  18680. return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE5);
  18681. }
  18682. set diffuseTexture5(value) {
  18683. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE5, value);
  18684. this._setDetailNum(5);
  18685. }
  18686. _setDetailNum(value) {
  18687. switch (value) {
  18688. case 1:
  18689. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18690. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18691. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18692. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18693. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18694. break;
  18695. case 2:
  18696. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18697. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18698. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18699. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18700. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18701. break;
  18702. case 3:
  18703. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18704. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18705. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18706. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18707. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18708. break;
  18709. case 4:
  18710. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18711. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18712. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18713. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18714. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18715. break;
  18716. case 5:
  18717. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18718. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18719. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18720. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18721. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18722. break;
  18723. }
  18724. }
  18725. set diffuseScaleOffset1(scaleOffset1) {
  18726. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET1, scaleOffset1);
  18727. }
  18728. set diffuseScaleOffset2(scaleOffset2) {
  18729. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET2, scaleOffset2);
  18730. }
  18731. set diffuseScaleOffset3(scaleOffset3) {
  18732. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET3, scaleOffset3);
  18733. }
  18734. set diffuseScaleOffset4(scaleOffset4) {
  18735. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET4, scaleOffset4);
  18736. }
  18737. set diffuseScaleOffset5(scaleOffset5) {
  18738. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET5, scaleOffset5);
  18739. }
  18740. get enableLighting() {
  18741. return this._enableLighting;
  18742. }
  18743. set enableLighting(value) {
  18744. if (this._enableLighting !== value) {
  18745. if (value)
  18746. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT);
  18747. else
  18748. this._disablePublicDefineDatas.add(Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT);
  18749. this._enableLighting = value;
  18750. }
  18751. }
  18752. set renderMode(value) {
  18753. switch (value) {
  18754. case ExtendTerrainMaterial.RENDERMODE_OPAQUE:
  18755. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  18756. this.depthWrite = true;
  18757. this.cull = RenderState.CULL_BACK;
  18758. this.blend = RenderState.BLEND_DISABLE;
  18759. this.depthTest = RenderState.DEPTHTEST_LESS;
  18760. break;
  18761. case ExtendTerrainMaterial.RENDERMODE_TRANSPARENT:
  18762. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  18763. this.depthWrite = false;
  18764. this.cull = RenderState.CULL_BACK;
  18765. this.blend = RenderState.BLEND_ENABLE_ALL;
  18766. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  18767. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  18768. this.depthTest = RenderState.DEPTHTEST_LEQUAL;
  18769. break;
  18770. default:
  18771. throw new Error("ExtendTerrainMaterial:renderMode value error.");
  18772. }
  18773. }
  18774. set depthWrite(value) {
  18775. this._shaderValues.setBool(ExtendTerrainMaterial.DEPTH_WRITE, value);
  18776. }
  18777. get depthWrite() {
  18778. return this._shaderValues.getBool(ExtendTerrainMaterial.DEPTH_WRITE);
  18779. }
  18780. set cull(value) {
  18781. this._shaderValues.setInt(ExtendTerrainMaterial.CULL, value);
  18782. }
  18783. get cull() {
  18784. return this._shaderValues.getInt(ExtendTerrainMaterial.CULL);
  18785. }
  18786. set blend(value) {
  18787. this._shaderValues.setInt(ExtendTerrainMaterial.BLEND, value);
  18788. }
  18789. get blend() {
  18790. return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND);
  18791. }
  18792. set blendSrc(value) {
  18793. this._shaderValues.setInt(ExtendTerrainMaterial.BLEND_SRC, value);
  18794. }
  18795. get blendSrc() {
  18796. return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND_SRC);
  18797. }
  18798. set blendDst(value) {
  18799. this._shaderValues.setInt(ExtendTerrainMaterial.BLEND_DST, value);
  18800. }
  18801. get blendDst() {
  18802. return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND_DST);
  18803. }
  18804. set depthTest(value) {
  18805. this._shaderValues.setInt(ExtendTerrainMaterial.DEPTH_TEST, value);
  18806. }
  18807. get depthTest() {
  18808. return this._shaderValues.getInt(ExtendTerrainMaterial.DEPTH_TEST);
  18809. }
  18810. clone() {
  18811. var dest = new ExtendTerrainMaterial();
  18812. this.cloneTo(dest);
  18813. return dest;
  18814. }
  18815. }
  18816. ExtendTerrainMaterial.RENDERMODE_OPAQUE = 1;
  18817. ExtendTerrainMaterial.RENDERMODE_TRANSPARENT = 2;
  18818. ExtendTerrainMaterial.SPLATALPHATEXTURE = Shader3D.propertyNameToID("u_SplatAlphaTexture");
  18819. ExtendTerrainMaterial.DIFFUSETEXTURE1 = Shader3D.propertyNameToID("u_DiffuseTexture1");
  18820. ExtendTerrainMaterial.DIFFUSETEXTURE2 = Shader3D.propertyNameToID("u_DiffuseTexture2");
  18821. ExtendTerrainMaterial.DIFFUSETEXTURE3 = Shader3D.propertyNameToID("u_DiffuseTexture3");
  18822. ExtendTerrainMaterial.DIFFUSETEXTURE4 = Shader3D.propertyNameToID("u_DiffuseTexture4");
  18823. ExtendTerrainMaterial.DIFFUSETEXTURE5 = Shader3D.propertyNameToID("u_DiffuseTexture5");
  18824. ExtendTerrainMaterial.DIFFUSESCALEOFFSET1 = Shader3D.propertyNameToID("u_DiffuseScaleOffset1");
  18825. ExtendTerrainMaterial.DIFFUSESCALEOFFSET2 = Shader3D.propertyNameToID("u_DiffuseScaleOffset2");
  18826. ExtendTerrainMaterial.DIFFUSESCALEOFFSET3 = Shader3D.propertyNameToID("u_DiffuseScaleOffset3");
  18827. ExtendTerrainMaterial.DIFFUSESCALEOFFSET4 = Shader3D.propertyNameToID("u_DiffuseScaleOffset4");
  18828. ExtendTerrainMaterial.DIFFUSESCALEOFFSET5 = Shader3D.propertyNameToID("u_DiffuseScaleOffset5");
  18829. ExtendTerrainMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  18830. ExtendTerrainMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  18831. ExtendTerrainMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  18832. ExtendTerrainMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  18833. ExtendTerrainMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  18834. ExtendTerrainMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  18835. ExtendTerrainMaterial.shaderDefines = null;
  18836. class PBRSpecularMaterial extends BaseMaterial {
  18837. constructor() {
  18838. super();
  18839. this.setShaderName("PBRSpecular");
  18840. this._albedoColor = new Vector4(1.0, 1.0, 1.0, 1.0);
  18841. this._shaderValues.setVector(PBRSpecularMaterial.ALBEDOCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  18842. this._emissionColor = new Vector4(0.0, 0.0, 0.0, 0.0);
  18843. this._shaderValues.setVector(PBRSpecularMaterial.EMISSIONCOLOR, new Vector4(0.0, 0.0, 0.0, 0.0));
  18844. this._specularColor = new Vector4(0.2, 0.2, 0.2, 0.2);
  18845. this._shaderValues.setVector(PBRSpecularMaterial.SPECULARCOLOR, new Vector4(0.2, 0.2, 0.2, 0.2));
  18846. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESS, 0.5);
  18847. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSCALE, 1.0);
  18848. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSOURCE, 0);
  18849. this._shaderValues.setNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH, 1.0);
  18850. this._shaderValues.setNumber(PBRSpecularMaterial.NORMALSCALE, 1.0);
  18851. this._shaderValues.setNumber(PBRSpecularMaterial.PARALLAXSCALE, 0.001);
  18852. this._shaderValues.setBool(PBRSpecularMaterial.ENABLEEMISSION, false);
  18853. this._shaderValues.setNumber(BaseMaterial.ALPHATESTVALUE, 0.5);
  18854. this.renderMode = PBRSpecularMaterial.RENDERMODE_OPAQUE;
  18855. }
  18856. static __initDefine__() {
  18857. PBRSpecularMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  18858. PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
  18859. PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("SPECULARTEXTURE");
  18860. PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA = PBRSpecularMaterial.shaderDefines.registerDefine("SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA");
  18861. PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
  18862. PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("PARALLAXTEXTURE");
  18863. PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("OCCLUSIONTEXTURE");
  18864. PBRSpecularMaterial.SHADERDEFINE_EMISSION = PBRSpecularMaterial.shaderDefines.registerDefine("EMISSION");
  18865. PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("EMISSIONTEXTURE");
  18866. PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET = PBRSpecularMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  18867. PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY = PBRSpecularMaterial.shaderDefines.registerDefine("ALPHAPREMULTIPLY");
  18868. }
  18869. get _ColorR() {
  18870. return this._albedoColor.x;
  18871. }
  18872. set _ColorR(value) {
  18873. this._albedoColor.x = value;
  18874. this.albedoColor = this._albedoColor;
  18875. }
  18876. get _ColorG() {
  18877. return this._albedoColor.y;
  18878. }
  18879. set _ColorG(value) {
  18880. this._albedoColor.y = value;
  18881. this.albedoColor = this._albedoColor;
  18882. }
  18883. get _ColorB() {
  18884. return this._albedoColor.z;
  18885. }
  18886. set _ColorB(value) {
  18887. this._albedoColor.z = value;
  18888. this.albedoColor = this._albedoColor;
  18889. }
  18890. get _ColorA() {
  18891. return this._albedoColor.w;
  18892. }
  18893. set _ColorA(value) {
  18894. this._albedoColor.w = value;
  18895. this.albedoColor = this._albedoColor;
  18896. }
  18897. get _SpecColorR() {
  18898. return this._specularColor.x;
  18899. }
  18900. set _SpecColorR(value) {
  18901. this._specularColor.x = value;
  18902. this.specularColor = this._specularColor;
  18903. }
  18904. get _SpecColorG() {
  18905. return this._specularColor.y;
  18906. }
  18907. set _SpecColorG(value) {
  18908. this._specularColor.y = value;
  18909. this.specularColor = this._specularColor;
  18910. }
  18911. get _SpecColorB() {
  18912. return this._specularColor.z;
  18913. }
  18914. set _SpecColorB(value) {
  18915. this._specularColor.z = value;
  18916. this.specularColor = this._specularColor;
  18917. }
  18918. get _SpecColorA() {
  18919. return this._specularColor.w;
  18920. }
  18921. set _SpecColorA(value) {
  18922. this._specularColor.w = value;
  18923. this.specularColor = this._specularColor;
  18924. }
  18925. get _Glossiness() {
  18926. return this._shaderValues.getNumber(PBRSpecularMaterial.SMOOTHNESS);
  18927. }
  18928. set _Glossiness(value) {
  18929. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESS, value);
  18930. }
  18931. get _GlossMapScale() {
  18932. return this._shaderValues.getNumber(PBRSpecularMaterial.SMOOTHNESSSCALE);
  18933. }
  18934. set _GlossMapScale(value) {
  18935. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSCALE, value);
  18936. }
  18937. get _BumpScale() {
  18938. return this._shaderValues.getNumber(PBRSpecularMaterial.NORMALSCALE);
  18939. }
  18940. set _BumpScale(value) {
  18941. this._shaderValues.setNumber(PBRSpecularMaterial.NORMALSCALE, value);
  18942. }
  18943. get _Parallax() {
  18944. return this._shaderValues.getNumber(PBRSpecularMaterial.PARALLAXSCALE);
  18945. }
  18946. set _Parallax(value) {
  18947. this._shaderValues.setNumber(PBRSpecularMaterial.PARALLAXSCALE, value);
  18948. }
  18949. get _OcclusionStrength() {
  18950. return this._shaderValues.getNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH);
  18951. }
  18952. set _OcclusionStrength(value) {
  18953. this._shaderValues.setNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH, value);
  18954. }
  18955. get _EmissionColorR() {
  18956. return this._emissionColor.x;
  18957. }
  18958. set _EmissionColorR(value) {
  18959. this._emissionColor.x = value;
  18960. this.emissionColor = this._emissionColor;
  18961. }
  18962. get _EmissionColorG() {
  18963. return this._emissionColor.y;
  18964. }
  18965. set _EmissionColorG(value) {
  18966. this._emissionColor.y = value;
  18967. this.emissionColor = this._emissionColor;
  18968. }
  18969. get _EmissionColorB() {
  18970. return this._emissionColor.z;
  18971. }
  18972. set _EmissionColorB(value) {
  18973. this._emissionColor.z = value;
  18974. this.emissionColor = this._emissionColor;
  18975. }
  18976. get _EmissionColorA() {
  18977. return this._emissionColor.w;
  18978. }
  18979. set _EmissionColorA(value) {
  18980. this._emissionColor.w = value;
  18981. this.emissionColor = this._emissionColor;
  18982. }
  18983. get _MainTex_STX() {
  18984. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).x;
  18985. }
  18986. set _MainTex_STX(x) {
  18987. var tilOff = this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  18988. tilOff.x = x;
  18989. this.tilingOffset = tilOff;
  18990. }
  18991. get _MainTex_STY() {
  18992. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).y;
  18993. }
  18994. set _MainTex_STY(y) {
  18995. var tilOff = this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  18996. tilOff.y = y;
  18997. this.tilingOffset = tilOff;
  18998. }
  18999. get _MainTex_STZ() {
  19000. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).z;
  19001. }
  19002. set _MainTex_STZ(z) {
  19003. var tilOff = this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  19004. tilOff.z = z;
  19005. this.tilingOffset = tilOff;
  19006. }
  19007. get _MainTex_STW() {
  19008. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).w;
  19009. }
  19010. set _MainTex_STW(w) {
  19011. var tilOff = this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  19012. tilOff.w = w;
  19013. this.tilingOffset = tilOff;
  19014. }
  19015. get _Cutoff() {
  19016. return this.alphaTestValue;
  19017. }
  19018. set _Cutoff(value) {
  19019. this.alphaTestValue = value;
  19020. }
  19021. get albedoColorR() {
  19022. return this._ColorR;
  19023. }
  19024. set albedoColorR(value) {
  19025. this._ColorR = value;
  19026. }
  19027. get albedoColorG() {
  19028. return this._ColorG;
  19029. }
  19030. set albedoColorG(value) {
  19031. this._ColorG = value;
  19032. }
  19033. get albedoColorB() {
  19034. return this._ColorB;
  19035. }
  19036. set albedoColorB(value) {
  19037. this._ColorB = value;
  19038. }
  19039. get albedoColorA() {
  19040. return this._ColorA;
  19041. }
  19042. set albedoColorA(value) {
  19043. this._ColorA = value;
  19044. }
  19045. get albedoColor() {
  19046. return this._albedoColor;
  19047. }
  19048. set albedoColor(value) {
  19049. this._albedoColor = value;
  19050. this._shaderValues.setVector(PBRSpecularMaterial.ALBEDOCOLOR, value);
  19051. }
  19052. get albedoTexture() {
  19053. return this._shaderValues.getTexture(PBRSpecularMaterial.ALBEDOTEXTURE);
  19054. }
  19055. set albedoTexture(value) {
  19056. if (value) {
  19057. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  19058. }
  19059. else {
  19060. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  19061. }
  19062. this._shaderValues.setTexture(PBRSpecularMaterial.ALBEDOTEXTURE, value);
  19063. }
  19064. get normalTexture() {
  19065. return this._shaderValues.getTexture(PBRSpecularMaterial.NORMALTEXTURE);
  19066. }
  19067. set normalTexture(value) {
  19068. if (value) {
  19069. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE);
  19070. }
  19071. else {
  19072. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE);
  19073. }
  19074. this._shaderValues.setTexture(PBRSpecularMaterial.NORMALTEXTURE, value);
  19075. }
  19076. get normalTextureScale() {
  19077. return this._BumpScale;
  19078. }
  19079. set normalTextureScale(value) {
  19080. this._BumpScale = value;
  19081. }
  19082. get parallaxTexture() {
  19083. return this._shaderValues.getTexture(PBRSpecularMaterial.PARALLAXTEXTURE);
  19084. }
  19085. set parallaxTexture(value) {
  19086. if (value) {
  19087. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE);
  19088. }
  19089. else {
  19090. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE);
  19091. }
  19092. this._shaderValues.setTexture(PBRSpecularMaterial.PARALLAXTEXTURE, value);
  19093. }
  19094. get parallaxTextureScale() {
  19095. return this._Parallax;
  19096. }
  19097. set parallaxTextureScale(value) {
  19098. this._Parallax = Math.max(0.005, Math.min(0.08, value));
  19099. }
  19100. get occlusionTexture() {
  19101. return this._shaderValues.getTexture(PBRSpecularMaterial.OCCLUSIONTEXTURE);
  19102. }
  19103. set occlusionTexture(value) {
  19104. if (value) {
  19105. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
  19106. }
  19107. else {
  19108. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
  19109. }
  19110. this._shaderValues.setTexture(PBRSpecularMaterial.OCCLUSIONTEXTURE, value);
  19111. }
  19112. get occlusionTextureStrength() {
  19113. return this._OcclusionStrength;
  19114. }
  19115. set occlusionTextureStrength(value) {
  19116. this._OcclusionStrength = Math.max(0.0, Math.min(1.0, value));
  19117. }
  19118. get specularTexture() {
  19119. return this._shaderValues.getTexture(PBRSpecularMaterial.SPECULARTEXTURE);
  19120. }
  19121. set specularTexture(value) {
  19122. if (value) {
  19123. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE);
  19124. }
  19125. else {
  19126. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE);
  19127. }
  19128. this._shaderValues.setTexture(PBRSpecularMaterial.SPECULARTEXTURE, value);
  19129. }
  19130. get specularColorR() {
  19131. return this._SpecColorR;
  19132. }
  19133. set specularColorR(value) {
  19134. this._SpecColorR = value;
  19135. }
  19136. get specularColorG() {
  19137. return this._SpecColorG;
  19138. }
  19139. set specularColorG(value) {
  19140. this._SpecColorG = value;
  19141. }
  19142. get specularColorB() {
  19143. return this._SpecColorB;
  19144. }
  19145. set specularColorB(value) {
  19146. this._SpecColorB = value;
  19147. }
  19148. get specularColorA() {
  19149. return this._SpecColorA;
  19150. }
  19151. set specularColorA(value) {
  19152. this._SpecColorA = value;
  19153. }
  19154. get specularColor() {
  19155. return this._shaderValues.getVector(PBRSpecularMaterial.SPECULARCOLOR);
  19156. }
  19157. set specularColor(value) {
  19158. this._shaderValues.setVector(PBRSpecularMaterial.SPECULARCOLOR, value);
  19159. }
  19160. get smoothness() {
  19161. return this._Glossiness;
  19162. }
  19163. set smoothness(value) {
  19164. this._Glossiness = Math.max(0.0, Math.min(1.0, value));
  19165. }
  19166. get smoothnessTextureScale() {
  19167. return this._GlossMapScale;
  19168. }
  19169. set smoothnessTextureScale(value) {
  19170. this._GlossMapScale = Math.max(0.0, Math.min(1.0, value));
  19171. }
  19172. get smoothnessSource() {
  19173. return this._shaderValues.getInt(PBRSpecularMaterial.SMOOTHNESSSOURCE);
  19174. }
  19175. set smoothnessSource(value) {
  19176. if (value) {
  19177. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
  19178. this._shaderValues.setInt(PBRSpecularMaterial.SMOOTHNESSSOURCE, 1);
  19179. }
  19180. else {
  19181. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
  19182. this._shaderValues.setInt(PBRSpecularMaterial.SMOOTHNESSSOURCE, 0);
  19183. }
  19184. }
  19185. get enableEmission() {
  19186. return this._shaderValues.getBool(PBRSpecularMaterial.ENABLEEMISSION);
  19187. }
  19188. set enableEmission(value) {
  19189. if (value)
  19190. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_EMISSION);
  19191. else {
  19192. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_EMISSION);
  19193. }
  19194. this._shaderValues.setBool(PBRSpecularMaterial.ENABLEEMISSION, value);
  19195. }
  19196. get emissionColor() {
  19197. return this._shaderValues.getVector(PBRSpecularMaterial.EMISSIONCOLOR);
  19198. }
  19199. set emissionColor(value) {
  19200. this._shaderValues.setVector(PBRSpecularMaterial.EMISSIONCOLOR, value);
  19201. }
  19202. get emissionTexture() {
  19203. return this._shaderValues.getTexture(PBRSpecularMaterial.EMISSIONTEXTURE);
  19204. }
  19205. set emissionTexture(value) {
  19206. if (value)
  19207. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE);
  19208. else
  19209. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE);
  19210. this._shaderValues.setTexture(PBRSpecularMaterial.EMISSIONTEXTURE, value);
  19211. }
  19212. get enableReflection() {
  19213. return this._shaderValues.getBool(PBRSpecularMaterial.ENABLEREFLECT);
  19214. }
  19215. set enableReflection(value) {
  19216. this._shaderValues.setBool(PBRSpecularMaterial.ENABLEREFLECT, true);
  19217. if (value)
  19218. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19219. else
  19220. this._disablePublicDefineDatas.add(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19221. }
  19222. get tilingOffsetX() {
  19223. return this._MainTex_STX;
  19224. }
  19225. set tilingOffsetX(x) {
  19226. this._MainTex_STX = x;
  19227. }
  19228. get tilingOffsetY() {
  19229. return this._MainTex_STY;
  19230. }
  19231. set tilingOffsetY(y) {
  19232. this._MainTex_STY = y;
  19233. }
  19234. get tilingOffsetZ() {
  19235. return this._MainTex_STZ;
  19236. }
  19237. set tilingOffsetZ(z) {
  19238. this._MainTex_STZ = z;
  19239. }
  19240. get tilingOffsetW() {
  19241. return this._MainTex_STW;
  19242. }
  19243. set tilingOffsetW(w) {
  19244. this._MainTex_STW = w;
  19245. }
  19246. get tilingOffset() {
  19247. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  19248. }
  19249. set tilingOffset(value) {
  19250. if (value) {
  19251. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  19252. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
  19253. else
  19254. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
  19255. }
  19256. else {
  19257. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
  19258. }
  19259. this._shaderValues.setVector(PBRSpecularMaterial.TILINGOFFSET, value);
  19260. }
  19261. set renderMode(value) {
  19262. switch (value) {
  19263. case PBRSpecularMaterial.RENDERMODE_OPAQUE:
  19264. this.alphaTest = false;
  19265. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  19266. this.depthWrite = true;
  19267. this.cull = RenderState.CULL_BACK;
  19268. this.blend = RenderState.BLEND_DISABLE;
  19269. this.depthTest = RenderState.DEPTHTEST_LESS;
  19270. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19271. break;
  19272. case PBRSpecularMaterial.RENDERMODE_CUTOUT:
  19273. this.renderQueue = BaseMaterial.RENDERQUEUE_ALPHATEST;
  19274. this.alphaTest = true;
  19275. this.depthWrite = true;
  19276. this.cull = RenderState.CULL_BACK;
  19277. this.blend = RenderState.BLEND_DISABLE;
  19278. this.depthTest = RenderState.DEPTHTEST_LESS;
  19279. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19280. break;
  19281. case PBRSpecularMaterial.RENDERMODE_FADE:
  19282. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  19283. this.alphaTest = false;
  19284. this.depthWrite = false;
  19285. this.cull = RenderState.CULL_BACK;
  19286. this.blend = RenderState.BLEND_ENABLE_ALL;
  19287. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  19288. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  19289. this.depthTest = RenderState.DEPTHTEST_LESS;
  19290. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19291. break;
  19292. case PBRSpecularMaterial.RENDERMODE_TRANSPARENT:
  19293. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  19294. this.alphaTest = false;
  19295. this.depthWrite = false;
  19296. this.cull = RenderState.CULL_BACK;
  19297. this.blend = RenderState.BLEND_ENABLE_ALL;
  19298. this.blendSrc = RenderState.BLENDPARAM_ONE;
  19299. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  19300. this.depthTest = RenderState.DEPTHTEST_LESS;
  19301. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19302. break;
  19303. default:
  19304. throw new Error("PBRSpecularMaterial : renderMode value error.");
  19305. }
  19306. }
  19307. set depthWrite(value) {
  19308. this._shaderValues.setBool(PBRSpecularMaterial.DEPTH_WRITE, value);
  19309. }
  19310. get depthWrite() {
  19311. return this._shaderValues.getBool(PBRSpecularMaterial.DEPTH_WRITE);
  19312. }
  19313. set cull(value) {
  19314. this._shaderValues.setInt(PBRSpecularMaterial.CULL, value);
  19315. }
  19316. get cull() {
  19317. return this._shaderValues.getInt(PBRSpecularMaterial.CULL);
  19318. }
  19319. set blend(value) {
  19320. this._shaderValues.setInt(PBRSpecularMaterial.BLEND, value);
  19321. }
  19322. get blend() {
  19323. return this._shaderValues.getInt(PBRSpecularMaterial.BLEND);
  19324. }
  19325. set blendSrc(value) {
  19326. this._shaderValues.setInt(PBRSpecularMaterial.BLEND_SRC, value);
  19327. }
  19328. get blendSrc() {
  19329. return this._shaderValues.getInt(PBRSpecularMaterial.BLEND_SRC);
  19330. }
  19331. set blendDst(value) {
  19332. this._shaderValues.setInt(PBRSpecularMaterial.BLEND_DST, value);
  19333. }
  19334. get blendDst() {
  19335. return this._shaderValues.getInt(PBRSpecularMaterial.BLEND_DST);
  19336. }
  19337. set depthTest(value) {
  19338. this._shaderValues.setInt(PBRSpecularMaterial.DEPTH_TEST, value);
  19339. }
  19340. get depthTest() {
  19341. return this._shaderValues.getInt(PBRSpecularMaterial.DEPTH_TEST);
  19342. }
  19343. clone() {
  19344. var dest = new PBRSpecularMaterial();
  19345. this.cloneTo(dest);
  19346. return dest;
  19347. }
  19348. cloneTo(destObject) {
  19349. super.cloneTo(destObject);
  19350. var destMaterial = destObject;
  19351. this._albedoColor.cloneTo(destMaterial._albedoColor);
  19352. this._specularColor.cloneTo(destMaterial._specularColor);
  19353. this._emissionColor.cloneTo(destMaterial._emissionColor);
  19354. }
  19355. }
  19356. PBRSpecularMaterial.SmoothnessSource_SpecularTexture_Alpha = 0;
  19357. PBRSpecularMaterial.SmoothnessSource_AlbedoTexture_Alpha = 1;
  19358. PBRSpecularMaterial.RENDERMODE_OPAQUE = 0;
  19359. PBRSpecularMaterial.RENDERMODE_CUTOUT = 1;
  19360. PBRSpecularMaterial.RENDERMODE_FADE = 2;
  19361. PBRSpecularMaterial.RENDERMODE_TRANSPARENT = 3;
  19362. PBRSpecularMaterial.ALBEDOTEXTURE = Shader3D.propertyNameToID("u_AlbedoTexture");
  19363. PBRSpecularMaterial.SPECULARTEXTURE = Shader3D.propertyNameToID("u_SpecularTexture");
  19364. PBRSpecularMaterial.NORMALTEXTURE = Shader3D.propertyNameToID("u_NormalTexture");
  19365. PBRSpecularMaterial.PARALLAXTEXTURE = Shader3D.propertyNameToID("u_ParallaxTexture");
  19366. PBRSpecularMaterial.OCCLUSIONTEXTURE = Shader3D.propertyNameToID("u_OcclusionTexture");
  19367. PBRSpecularMaterial.EMISSIONTEXTURE = Shader3D.propertyNameToID("u_EmissionTexture");
  19368. PBRSpecularMaterial.ALBEDOCOLOR = Shader3D.propertyNameToID("u_AlbedoColor");
  19369. PBRSpecularMaterial.SPECULARCOLOR = Shader3D.propertyNameToID("u_SpecularColor");
  19370. PBRSpecularMaterial.EMISSIONCOLOR = Shader3D.propertyNameToID("u_EmissionColor");
  19371. PBRSpecularMaterial.SMOOTHNESS = Shader3D.propertyNameToID("u_smoothness");
  19372. PBRSpecularMaterial.SMOOTHNESSSCALE = Shader3D.propertyNameToID("u_smoothnessScale");
  19373. PBRSpecularMaterial.SMOOTHNESSSOURCE = -1;
  19374. PBRSpecularMaterial.OCCLUSIONSTRENGTH = Shader3D.propertyNameToID("u_occlusionStrength");
  19375. PBRSpecularMaterial.NORMALSCALE = Shader3D.propertyNameToID("u_normalScale");
  19376. PBRSpecularMaterial.PARALLAXSCALE = Shader3D.propertyNameToID("u_parallaxScale");
  19377. PBRSpecularMaterial.ENABLEEMISSION = -1;
  19378. PBRSpecularMaterial.ENABLEREFLECT = -1;
  19379. PBRSpecularMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  19380. PBRSpecularMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  19381. PBRSpecularMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  19382. PBRSpecularMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  19383. PBRSpecularMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  19384. PBRSpecularMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  19385. PBRSpecularMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  19386. PBRSpecularMaterial.shaderDefines = null;
  19387. class PBRStandardMaterial extends BaseMaterial {
  19388. constructor() {
  19389. super();
  19390. this.setShaderName("PBRStandard");
  19391. this._albedoColor = new Vector4(1.0, 1.0, 1.0, 1.0);
  19392. this._shaderValues.setVector(PBRStandardMaterial.ALBEDOCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  19393. this._emissionColor = new Vector4(0.0, 0.0, 0.0, 0.0);
  19394. this._shaderValues.setVector(PBRStandardMaterial.EMISSIONCOLOR, new Vector4(0.0, 0.0, 0.0, 0.0));
  19395. this._shaderValues.setNumber(PBRStandardMaterial.METALLIC, 0.0);
  19396. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESS, 0.5);
  19397. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSCALE, 1.0);
  19398. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSOURCE, 0);
  19399. this._shaderValues.setNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH, 1.0);
  19400. this._shaderValues.setNumber(PBRStandardMaterial.NORMALSCALE, 1.0);
  19401. this._shaderValues.setNumber(PBRStandardMaterial.PARALLAXSCALE, 0.001);
  19402. this._shaderValues.setBool(PBRStandardMaterial.ENABLEEMISSION, false);
  19403. this._shaderValues.setBool(PBRStandardMaterial.ENABLEREFLECT, true);
  19404. this._shaderValues.setNumber(BaseMaterial.ALPHATESTVALUE, 0.5);
  19405. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19406. this.renderMode = PBRStandardMaterial.RENDERMODE_OPAQUE;
  19407. }
  19408. static __initDefine__() {
  19409. PBRStandardMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  19410. PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
  19411. PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("METALLICGLOSSTEXTURE");
  19412. PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA = PBRStandardMaterial.shaderDefines.registerDefine("SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA");
  19413. PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
  19414. PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("PARALLAXTEXTURE");
  19415. PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("OCCLUSIONTEXTURE");
  19416. PBRStandardMaterial.SHADERDEFINE_EMISSION = PBRStandardMaterial.shaderDefines.registerDefine("EMISSION");
  19417. PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("EMISSIONTEXTURE");
  19418. PBRStandardMaterial.SHADERDEFINE_REFLECTMAP = PBRStandardMaterial.shaderDefines.registerDefine("REFLECTMAP");
  19419. PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET = PBRStandardMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  19420. PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY = PBRStandardMaterial.shaderDefines.registerDefine("ALPHAPREMULTIPLY");
  19421. }
  19422. get _ColorR() {
  19423. return this._albedoColor.x;
  19424. }
  19425. set _ColorR(value) {
  19426. this._albedoColor.x = value;
  19427. this.albedoColor = this._albedoColor;
  19428. }
  19429. get _ColorG() {
  19430. return this._albedoColor.y;
  19431. }
  19432. set _ColorG(value) {
  19433. this._albedoColor.y = value;
  19434. this.albedoColor = this._albedoColor;
  19435. }
  19436. get _ColorB() {
  19437. return this._albedoColor.z;
  19438. }
  19439. set _ColorB(value) {
  19440. this._albedoColor.z = value;
  19441. this.albedoColor = this._albedoColor;
  19442. }
  19443. get _ColorA() {
  19444. return this._albedoColor.w;
  19445. }
  19446. set _ColorA(value) {
  19447. this._albedoColor.w = value;
  19448. this.albedoColor = this._albedoColor;
  19449. }
  19450. get _Metallic() {
  19451. return this._shaderValues.getNumber(PBRStandardMaterial.METALLIC);
  19452. }
  19453. set _Metallic(value) {
  19454. this._shaderValues.setNumber(PBRStandardMaterial.METALLIC, value);
  19455. }
  19456. get _Glossiness() {
  19457. return this._shaderValues.getNumber(PBRStandardMaterial.SMOOTHNESS);
  19458. }
  19459. set _Glossiness(value) {
  19460. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESS, value);
  19461. }
  19462. get _GlossMapScale() {
  19463. return this._shaderValues.getNumber(PBRStandardMaterial.SMOOTHNESSSCALE);
  19464. }
  19465. set _GlossMapScale(value) {
  19466. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSCALE, value);
  19467. }
  19468. get _BumpScale() {
  19469. return this._shaderValues.getNumber(PBRStandardMaterial.NORMALSCALE);
  19470. }
  19471. set _BumpScale(value) {
  19472. this._shaderValues.setNumber(PBRStandardMaterial.NORMALSCALE, value);
  19473. }
  19474. get _Parallax() {
  19475. return this._shaderValues.getNumber(PBRStandardMaterial.PARALLAXSCALE);
  19476. }
  19477. set _Parallax(value) {
  19478. this._shaderValues.setNumber(PBRStandardMaterial.PARALLAXSCALE, value);
  19479. }
  19480. get _OcclusionStrength() {
  19481. return this._shaderValues.getNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH);
  19482. }
  19483. set _OcclusionStrength(value) {
  19484. this._shaderValues.setNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH, value);
  19485. }
  19486. get _EmissionColorR() {
  19487. return this._emissionColor.x;
  19488. }
  19489. set _EmissionColorR(value) {
  19490. this._emissionColor.x = value;
  19491. this.emissionColor = this._emissionColor;
  19492. }
  19493. get _EmissionColorG() {
  19494. return this._emissionColor.y;
  19495. }
  19496. set _EmissionColorG(value) {
  19497. this._emissionColor.y = value;
  19498. this.emissionColor = this._emissionColor;
  19499. }
  19500. get _EmissionColorB() {
  19501. return this._emissionColor.z;
  19502. }
  19503. set _EmissionColorB(value) {
  19504. this._emissionColor.z = value;
  19505. this.emissionColor = this._emissionColor;
  19506. }
  19507. get _EmissionColorA() {
  19508. return this._emissionColor.w;
  19509. }
  19510. set _EmissionColorA(value) {
  19511. this._emissionColor.w = value;
  19512. this.emissionColor = this._emissionColor;
  19513. }
  19514. get _MainTex_STX() {
  19515. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).x;
  19516. }
  19517. set _MainTex_STX(x) {
  19518. var tilOff = this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19519. tilOff.x = x;
  19520. this.tilingOffset = tilOff;
  19521. }
  19522. get _MainTex_STY() {
  19523. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).y;
  19524. }
  19525. set _MainTex_STY(y) {
  19526. var tilOff = this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19527. tilOff.y = y;
  19528. this.tilingOffset = tilOff;
  19529. }
  19530. get _MainTex_STZ() {
  19531. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).z;
  19532. }
  19533. set _MainTex_STZ(z) {
  19534. var tilOff = this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19535. tilOff.z = z;
  19536. this.tilingOffset = tilOff;
  19537. }
  19538. get _MainTex_STW() {
  19539. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).w;
  19540. }
  19541. set _MainTex_STW(w) {
  19542. var tilOff = this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19543. tilOff.w = w;
  19544. this.tilingOffset = tilOff;
  19545. }
  19546. get _Cutoff() {
  19547. return this.alphaTestValue;
  19548. }
  19549. set _Cutoff(value) {
  19550. this.alphaTestValue = value;
  19551. }
  19552. get albedoColorR() {
  19553. return this._ColorR;
  19554. }
  19555. set albedoColorR(value) {
  19556. this._ColorR = value;
  19557. }
  19558. get albedoColorG() {
  19559. return this._ColorG;
  19560. }
  19561. set albedoColorG(value) {
  19562. this._ColorG = value;
  19563. }
  19564. get albedoColorB() {
  19565. return this._ColorB;
  19566. }
  19567. set albedoColorB(value) {
  19568. this._ColorB = value;
  19569. }
  19570. get albedoColorA() {
  19571. return this._ColorA;
  19572. }
  19573. set albedoColorA(value) {
  19574. this._ColorA = value;
  19575. }
  19576. get albedoColor() {
  19577. return this._albedoColor;
  19578. }
  19579. set albedoColor(value) {
  19580. this._albedoColor = value;
  19581. this._shaderValues.setVector(PBRStandardMaterial.ALBEDOCOLOR, value);
  19582. }
  19583. get albedoTexture() {
  19584. return this._shaderValues.getTexture(PBRStandardMaterial.ALBEDOTEXTURE);
  19585. }
  19586. set albedoTexture(value) {
  19587. if (value) {
  19588. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  19589. }
  19590. else {
  19591. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  19592. }
  19593. this._shaderValues.setTexture(PBRStandardMaterial.ALBEDOTEXTURE, value);
  19594. }
  19595. get normalTexture() {
  19596. return this._shaderValues.getTexture(PBRStandardMaterial.NORMALTEXTURE);
  19597. }
  19598. set normalTexture(value) {
  19599. if (value) {
  19600. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE);
  19601. }
  19602. else {
  19603. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE);
  19604. }
  19605. this._shaderValues.setTexture(PBRStandardMaterial.NORMALTEXTURE, value);
  19606. }
  19607. get normalTextureScale() {
  19608. return this._BumpScale;
  19609. }
  19610. set normalTextureScale(value) {
  19611. this._BumpScale = value;
  19612. }
  19613. get parallaxTexture() {
  19614. return this._shaderValues.getTexture(PBRStandardMaterial.PARALLAXTEXTURE);
  19615. }
  19616. set parallaxTexture(value) {
  19617. if (value) {
  19618. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE);
  19619. }
  19620. else {
  19621. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE);
  19622. }
  19623. this._shaderValues.setTexture(PBRStandardMaterial.PARALLAXTEXTURE, value);
  19624. }
  19625. get parallaxTextureScale() {
  19626. return this._Parallax;
  19627. }
  19628. set parallaxTextureScale(value) {
  19629. this._Parallax = Math.max(0.005, Math.min(0.08, value));
  19630. }
  19631. get occlusionTexture() {
  19632. return this._shaderValues.getTexture(PBRStandardMaterial.OCCLUSIONTEXTURE);
  19633. }
  19634. set occlusionTexture(value) {
  19635. if (value) {
  19636. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
  19637. }
  19638. else {
  19639. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
  19640. }
  19641. this._shaderValues.setTexture(PBRStandardMaterial.OCCLUSIONTEXTURE, value);
  19642. }
  19643. get occlusionTextureStrength() {
  19644. return this._OcclusionStrength;
  19645. }
  19646. set occlusionTextureStrength(value) {
  19647. this._OcclusionStrength = Math.max(0.0, Math.min(1.0, value));
  19648. }
  19649. get metallicGlossTexture() {
  19650. return this._shaderValues.getTexture(PBRStandardMaterial.METALLICGLOSSTEXTURE);
  19651. }
  19652. set metallicGlossTexture(value) {
  19653. if (value) {
  19654. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE);
  19655. }
  19656. else {
  19657. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE);
  19658. }
  19659. this._shaderValues.setTexture(PBRStandardMaterial.METALLICGLOSSTEXTURE, value);
  19660. }
  19661. get metallic() {
  19662. return this._Metallic;
  19663. }
  19664. set metallic(value) {
  19665. this._Metallic = Math.max(0.0, Math.min(1.0, value));
  19666. }
  19667. get smoothness() {
  19668. return this._Glossiness;
  19669. }
  19670. set smoothness(value) {
  19671. this._Glossiness = Math.max(0.0, Math.min(1.0, value));
  19672. }
  19673. get smoothnessTextureScale() {
  19674. return this._GlossMapScale;
  19675. }
  19676. set smoothnessTextureScale(value) {
  19677. this._GlossMapScale = Math.max(0.0, Math.min(1.0, value));
  19678. }
  19679. get smoothnessSource() {
  19680. return this._shaderValues.getInt(PBRStandardMaterial.SMOOTHNESSSOURCE);
  19681. }
  19682. set smoothnessSource(value) {
  19683. if (value) {
  19684. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
  19685. this._shaderValues.setInt(PBRStandardMaterial.SMOOTHNESSSOURCE, 1);
  19686. }
  19687. else {
  19688. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
  19689. this._shaderValues.setInt(PBRStandardMaterial.SMOOTHNESSSOURCE, 0);
  19690. }
  19691. }
  19692. get enableEmission() {
  19693. return this._shaderValues.getBool(PBRStandardMaterial.ENABLEEMISSION);
  19694. }
  19695. set enableEmission(value) {
  19696. if (value) {
  19697. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_EMISSION);
  19698. }
  19699. else {
  19700. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_EMISSION);
  19701. }
  19702. this._shaderValues.setBool(PBRStandardMaterial.ENABLEEMISSION, value);
  19703. }
  19704. get emissionColorR() {
  19705. return this._EmissionColorR;
  19706. }
  19707. set emissionColorR(value) {
  19708. this._EmissionColorR = value;
  19709. }
  19710. get emissionColorG() {
  19711. return this._EmissionColorG;
  19712. }
  19713. set emissionColorG(value) {
  19714. this._EmissionColorG = value;
  19715. }
  19716. get emissionColorB() {
  19717. return this._EmissionColorB;
  19718. }
  19719. set emissionColorB(value) {
  19720. this._EmissionColorB = value;
  19721. }
  19722. get emissionColorA() {
  19723. return this._EmissionColorA;
  19724. }
  19725. set emissionColorA(value) {
  19726. this._EmissionColorA = value;
  19727. }
  19728. get emissionColor() {
  19729. return this._shaderValues.getVector(PBRStandardMaterial.EMISSIONCOLOR);
  19730. }
  19731. set emissionColor(value) {
  19732. this._shaderValues.setVector(PBRStandardMaterial.EMISSIONCOLOR, value);
  19733. }
  19734. get emissionTexture() {
  19735. return this._shaderValues.getTexture(PBRStandardMaterial.EMISSIONTEXTURE);
  19736. }
  19737. set emissionTexture(value) {
  19738. if (value) {
  19739. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE);
  19740. }
  19741. else {
  19742. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE);
  19743. }
  19744. this._shaderValues.setTexture(PBRStandardMaterial.EMISSIONTEXTURE, value);
  19745. }
  19746. get enableReflection() {
  19747. return this._shaderValues.getBool(PBRStandardMaterial.ENABLEREFLECT);
  19748. }
  19749. set enableReflection(value) {
  19750. this._shaderValues.setBool(PBRStandardMaterial.ENABLEREFLECT, true);
  19751. if (value) {
  19752. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19753. }
  19754. else {
  19755. this._disablePublicDefineDatas.add(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19756. }
  19757. }
  19758. get tilingOffsetX() {
  19759. return this._MainTex_STX;
  19760. }
  19761. set tilingOffsetX(x) {
  19762. this._MainTex_STX = x;
  19763. }
  19764. get tilingOffsetY() {
  19765. return this._MainTex_STY;
  19766. }
  19767. set tilingOffsetY(y) {
  19768. this._MainTex_STY = y;
  19769. }
  19770. get tilingOffsetZ() {
  19771. return this._MainTex_STZ;
  19772. }
  19773. set tilingOffsetZ(z) {
  19774. this._MainTex_STZ = z;
  19775. }
  19776. get tilingOffsetW() {
  19777. return this._MainTex_STW;
  19778. }
  19779. set tilingOffsetW(w) {
  19780. this._MainTex_STW = w;
  19781. }
  19782. get tilingOffset() {
  19783. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19784. }
  19785. set tilingOffset(value) {
  19786. if (value) {
  19787. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0) {
  19788. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
  19789. }
  19790. else {
  19791. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
  19792. }
  19793. }
  19794. else {
  19795. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
  19796. }
  19797. this._shaderValues.setVector(PBRStandardMaterial.TILINGOFFSET, value);
  19798. }
  19799. set renderMode(value) {
  19800. switch (value) {
  19801. case PBRStandardMaterial.RENDERMODE_OPAQUE:
  19802. this.alphaTest = false;
  19803. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  19804. this.depthWrite = true;
  19805. this.cull = RenderState.CULL_BACK;
  19806. this.blend = RenderState.BLEND_DISABLE;
  19807. this.depthTest = RenderState.DEPTHTEST_LESS;
  19808. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19809. break;
  19810. case PBRStandardMaterial.RENDERMODE_CUTOUT:
  19811. this.renderQueue = BaseMaterial.RENDERQUEUE_ALPHATEST;
  19812. this.alphaTest = true;
  19813. this.depthWrite = true;
  19814. this.cull = RenderState.CULL_BACK;
  19815. this.blend = RenderState.BLEND_DISABLE;
  19816. this.depthTest = RenderState.DEPTHTEST_LESS;
  19817. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19818. break;
  19819. case PBRStandardMaterial.RENDERMODE_FADE:
  19820. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  19821. this.alphaTest = false;
  19822. this.depthWrite = false;
  19823. this.cull = RenderState.CULL_BACK;
  19824. this.blend = RenderState.BLEND_ENABLE_ALL;
  19825. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  19826. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  19827. this.depthTest = RenderState.DEPTHTEST_LESS;
  19828. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19829. break;
  19830. break;
  19831. case PBRStandardMaterial.RENDERMODE_TRANSPARENT:
  19832. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  19833. this.alphaTest = false;
  19834. this.depthWrite = false;
  19835. this.cull = RenderState.CULL_BACK;
  19836. this.blend = RenderState.BLEND_ENABLE_ALL;
  19837. this.blendSrc = RenderState.BLENDPARAM_ONE;
  19838. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  19839. this.depthTest = RenderState.DEPTHTEST_LESS;
  19840. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19841. break;
  19842. default:
  19843. throw new Error("PBRSpecularMaterial : renderMode value error.");
  19844. }
  19845. }
  19846. set depthWrite(value) {
  19847. this._shaderValues.setBool(PBRStandardMaterial.DEPTH_WRITE, value);
  19848. }
  19849. get depthWrite() {
  19850. return this._shaderValues.getBool(PBRStandardMaterial.DEPTH_WRITE);
  19851. }
  19852. set cull(value) {
  19853. this._shaderValues.setInt(PBRStandardMaterial.CULL, value);
  19854. }
  19855. get cull() {
  19856. return this._shaderValues.getInt(PBRStandardMaterial.CULL);
  19857. }
  19858. set blend(value) {
  19859. this._shaderValues.setInt(PBRStandardMaterial.BLEND, value);
  19860. }
  19861. get blend() {
  19862. return this._shaderValues.getInt(PBRStandardMaterial.BLEND);
  19863. }
  19864. set blendSrc(value) {
  19865. this._shaderValues.setInt(PBRStandardMaterial.BLEND_SRC, value);
  19866. }
  19867. get blendSrc() {
  19868. return this._shaderValues.getInt(PBRStandardMaterial.BLEND_SRC);
  19869. }
  19870. set blendDst(value) {
  19871. this._shaderValues.setInt(PBRStandardMaterial.BLEND_DST, value);
  19872. }
  19873. get blendDst() {
  19874. return this._shaderValues.getInt(PBRStandardMaterial.BLEND_DST);
  19875. }
  19876. set depthTest(value) {
  19877. this._shaderValues.setInt(PBRStandardMaterial.DEPTH_TEST, value);
  19878. }
  19879. get depthTest() {
  19880. return this._shaderValues.getInt(PBRStandardMaterial.DEPTH_TEST);
  19881. }
  19882. clone() {
  19883. var dest = new PBRStandardMaterial();
  19884. this.cloneTo(dest);
  19885. return dest;
  19886. }
  19887. cloneTo(destObject) {
  19888. super.cloneTo(destObject);
  19889. var destMaterial = destObject;
  19890. this._albedoColor.cloneTo(destMaterial._albedoColor);
  19891. this._emissionColor.cloneTo(destMaterial._emissionColor);
  19892. }
  19893. }
  19894. PBRStandardMaterial.SmoothnessSource_MetallicGlossTexture_Alpha = 0;
  19895. PBRStandardMaterial.SmoothnessSource_AlbedoTexture_Alpha = 1;
  19896. PBRStandardMaterial.RENDERMODE_OPAQUE = 0;
  19897. PBRStandardMaterial.RENDERMODE_CUTOUT = 1;
  19898. PBRStandardMaterial.RENDERMODE_FADE = 2;
  19899. PBRStandardMaterial.RENDERMODE_TRANSPARENT = 3;
  19900. PBRStandardMaterial.ALBEDOTEXTURE = Shader3D.propertyNameToID("u_AlbedoTexture");
  19901. PBRStandardMaterial.METALLICGLOSSTEXTURE = Shader3D.propertyNameToID("u_MetallicGlossTexture");
  19902. PBRStandardMaterial.NORMALTEXTURE = Shader3D.propertyNameToID("u_NormalTexture");
  19903. PBRStandardMaterial.PARALLAXTEXTURE = Shader3D.propertyNameToID("u_ParallaxTexture");
  19904. PBRStandardMaterial.OCCLUSIONTEXTURE = Shader3D.propertyNameToID("u_OcclusionTexture");
  19905. PBRStandardMaterial.EMISSIONTEXTURE = Shader3D.propertyNameToID("u_EmissionTexture");
  19906. PBRStandardMaterial.ALBEDOCOLOR = Shader3D.propertyNameToID("u_AlbedoColor");
  19907. PBRStandardMaterial.EMISSIONCOLOR = Shader3D.propertyNameToID("u_EmissionColor");
  19908. PBRStandardMaterial.METALLIC = Shader3D.propertyNameToID("u_metallic");
  19909. PBRStandardMaterial.SMOOTHNESS = Shader3D.propertyNameToID("u_smoothness");
  19910. PBRStandardMaterial.SMOOTHNESSSCALE = Shader3D.propertyNameToID("u_smoothnessScale");
  19911. PBRStandardMaterial.SMOOTHNESSSOURCE = -1;
  19912. PBRStandardMaterial.OCCLUSIONSTRENGTH = Shader3D.propertyNameToID("u_occlusionStrength");
  19913. PBRStandardMaterial.NORMALSCALE = Shader3D.propertyNameToID("u_normalScale");
  19914. PBRStandardMaterial.PARALLAXSCALE = Shader3D.propertyNameToID("u_parallaxScale");
  19915. PBRStandardMaterial.ENABLEEMISSION = -1;
  19916. PBRStandardMaterial.ENABLEREFLECT = -1;
  19917. PBRStandardMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  19918. PBRStandardMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  19919. PBRStandardMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  19920. PBRStandardMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  19921. PBRStandardMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  19922. PBRStandardMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  19923. PBRStandardMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  19924. PBRStandardMaterial.shaderDefines = null;
  19925. class SkyProceduralMaterial extends BaseMaterial {
  19926. constructor() {
  19927. super();
  19928. this.setShaderName("SkyBoxProcedural");
  19929. this.sunDisk = SkyProceduralMaterial.SUN_HIGH_QUALITY;
  19930. this.sunSize = 0.04;
  19931. this.sunSizeConvergence = 5;
  19932. this.atmosphereThickness = 1.0;
  19933. this.skyTint = new Vector4(0.5, 0.5, 0.5, 1.0);
  19934. this.groundTint = new Vector4(0.369, 0.349, 0.341, 1.0);
  19935. this.exposure = 1.3;
  19936. }
  19937. static __initDefine__() {
  19938. SkyProceduralMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  19939. SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY = SkyProceduralMaterial.shaderDefines.registerDefine("SUN_HIGH_QUALITY");
  19940. SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE = SkyProceduralMaterial.shaderDefines.registerDefine("SUN_SIMPLE");
  19941. }
  19942. get sunDisk() {
  19943. return this._sunDisk;
  19944. }
  19945. set sunDisk(value) {
  19946. switch (value) {
  19947. case SkyProceduralMaterial.SUN_HIGH_QUALITY:
  19948. this._shaderValues.removeDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
  19949. this._shaderValues.addDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
  19950. break;
  19951. case SkyProceduralMaterial.SUN_SIMPLE:
  19952. this._shaderValues.removeDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
  19953. this._shaderValues.addDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
  19954. break;
  19955. case SkyProceduralMaterial.SUN_NODE:
  19956. this._shaderValues.removeDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
  19957. this._shaderValues.removeDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
  19958. break;
  19959. default:
  19960. throw "SkyBoxProceduralMaterial: unknown sun value.";
  19961. }
  19962. this._sunDisk = value;
  19963. }
  19964. get sunSize() {
  19965. return this._shaderValues.getNumber(SkyProceduralMaterial.SUNSIZE);
  19966. }
  19967. set sunSize(value) {
  19968. value = Math.min(Math.max(0.0, value), 1.0);
  19969. this._shaderValues.setNumber(SkyProceduralMaterial.SUNSIZE, value);
  19970. }
  19971. get sunSizeConvergence() {
  19972. return this._shaderValues.getNumber(SkyProceduralMaterial.SUNSIZECONVERGENCE);
  19973. }
  19974. set sunSizeConvergence(value) {
  19975. value = Math.min(Math.max(0.0, value), 20.0);
  19976. this._shaderValues.setNumber(SkyProceduralMaterial.SUNSIZECONVERGENCE, value);
  19977. }
  19978. get atmosphereThickness() {
  19979. return this._shaderValues.getNumber(SkyProceduralMaterial.ATMOSPHERETHICKNESS);
  19980. }
  19981. set atmosphereThickness(value) {
  19982. value = Math.min(Math.max(0.0, value), 5.0);
  19983. this._shaderValues.setNumber(SkyProceduralMaterial.ATMOSPHERETHICKNESS, value);
  19984. }
  19985. get skyTint() {
  19986. return this._shaderValues.getVector(SkyProceduralMaterial.SKYTINT);
  19987. }
  19988. set skyTint(value) {
  19989. this._shaderValues.setVector(SkyProceduralMaterial.SKYTINT, value);
  19990. }
  19991. get groundTint() {
  19992. return this._shaderValues.getVector(SkyProceduralMaterial.GROUNDTINT);
  19993. }
  19994. set groundTint(value) {
  19995. this._shaderValues.setVector(SkyProceduralMaterial.GROUNDTINT, value);
  19996. }
  19997. get exposure() {
  19998. return this._shaderValues.getNumber(SkyProceduralMaterial.EXPOSURE);
  19999. }
  20000. set exposure(value) {
  20001. value = Math.min(Math.max(0.0, value), 8.0);
  20002. this._shaderValues.setNumber(SkyProceduralMaterial.EXPOSURE, value);
  20003. }
  20004. clone() {
  20005. var dest = new SkyProceduralMaterial();
  20006. this.cloneTo(dest);
  20007. return dest;
  20008. }
  20009. }
  20010. SkyProceduralMaterial.SUN_NODE = 0;
  20011. SkyProceduralMaterial.SUN_SIMPLE = 1;
  20012. SkyProceduralMaterial.SUN_HIGH_QUALITY = 2;
  20013. SkyProceduralMaterial.SUNSIZE = Shader3D.propertyNameToID("u_SunSize");
  20014. SkyProceduralMaterial.SUNSIZECONVERGENCE = Shader3D.propertyNameToID("u_SunSizeConvergence");
  20015. SkyProceduralMaterial.ATMOSPHERETHICKNESS = Shader3D.propertyNameToID("u_AtmosphereThickness");
  20016. SkyProceduralMaterial.SKYTINT = Shader3D.propertyNameToID("u_SkyTint");
  20017. SkyProceduralMaterial.GROUNDTINT = Shader3D.propertyNameToID("u_GroundTint");
  20018. SkyProceduralMaterial.EXPOSURE = Shader3D.propertyNameToID("u_Exposure");
  20019. SkyProceduralMaterial.shaderDefines = null;
  20020. class UnlitMaterial extends BaseMaterial {
  20021. constructor() {
  20022. super();
  20023. this._albedoColor = new Vector4(1.0, 1.0, 1.0, 1.0);
  20024. this._albedoIntensity = 1.0;
  20025. this._enableVertexColor = false;
  20026. this.setShaderName("Unlit");
  20027. this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  20028. this.renderMode = UnlitMaterial.RENDERMODE_OPAQUE;
  20029. }
  20030. static __initDefine__() {
  20031. UnlitMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  20032. UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE = UnlitMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
  20033. UnlitMaterial.SHADERDEFINE_TILINGOFFSET = UnlitMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  20034. UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR = UnlitMaterial.shaderDefines.registerDefine("ENABLEVERTEXCOLOR");
  20035. }
  20036. get _ColorR() {
  20037. return this._albedoColor.x;
  20038. }
  20039. set _ColorR(value) {
  20040. this._albedoColor.x = value;
  20041. this.albedoColor = this._albedoColor;
  20042. }
  20043. get _ColorG() {
  20044. return this._albedoColor.y;
  20045. }
  20046. set _ColorG(value) {
  20047. this._albedoColor.y = value;
  20048. this.albedoColor = this._albedoColor;
  20049. }
  20050. get _ColorB() {
  20051. return this._albedoColor.z;
  20052. }
  20053. set _ColorB(value) {
  20054. this._albedoColor.z = value;
  20055. this.albedoColor = this._albedoColor;
  20056. }
  20057. get _ColorA() {
  20058. return this._albedoColor.w;
  20059. }
  20060. set _ColorA(value) {
  20061. this._albedoColor.w = value;
  20062. this.albedoColor = this._albedoColor;
  20063. }
  20064. get _AlbedoIntensity() {
  20065. return this._albedoIntensity;
  20066. }
  20067. set _AlbedoIntensity(value) {
  20068. if (this._albedoIntensity !== value) {
  20069. var finalAlbedo = this._shaderValues.getVector(UnlitMaterial.ALBEDOCOLOR);
  20070. Vector4.scale(this._albedoColor, value, finalAlbedo);
  20071. this._albedoIntensity = value;
  20072. this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR, finalAlbedo);
  20073. }
  20074. }
  20075. get _MainTex_STX() {
  20076. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).x;
  20077. }
  20078. set _MainTex_STX(x) {
  20079. var tilOff = this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20080. tilOff.x = x;
  20081. this.tilingOffset = tilOff;
  20082. }
  20083. get _MainTex_STY() {
  20084. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).y;
  20085. }
  20086. set _MainTex_STY(y) {
  20087. var tilOff = this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20088. tilOff.y = y;
  20089. this.tilingOffset = tilOff;
  20090. }
  20091. get _MainTex_STZ() {
  20092. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).z;
  20093. }
  20094. set _MainTex_STZ(z) {
  20095. var tilOff = this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20096. tilOff.z = z;
  20097. this.tilingOffset = tilOff;
  20098. }
  20099. get _MainTex_STW() {
  20100. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).w;
  20101. }
  20102. set _MainTex_STW(w) {
  20103. var tilOff = this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20104. tilOff.w = w;
  20105. this.tilingOffset = tilOff;
  20106. }
  20107. get _Cutoff() {
  20108. return this.alphaTestValue;
  20109. }
  20110. set _Cutoff(value) {
  20111. this.alphaTestValue = value;
  20112. }
  20113. get albedoColorR() {
  20114. return this._ColorR;
  20115. }
  20116. set albedoColorR(value) {
  20117. this._ColorR = value;
  20118. }
  20119. get albedoColorG() {
  20120. return this._ColorG;
  20121. }
  20122. set albedoColorG(value) {
  20123. this._ColorG = value;
  20124. }
  20125. get albedoColorB() {
  20126. return this._ColorB;
  20127. }
  20128. set albedoColorB(value) {
  20129. this._ColorB = value;
  20130. }
  20131. get albedoColorA() {
  20132. return this._ColorA;
  20133. }
  20134. set albedoColorA(value) {
  20135. this._ColorA = value;
  20136. }
  20137. get albedoColor() {
  20138. return this._albedoColor;
  20139. }
  20140. set albedoColor(value) {
  20141. var finalAlbedo = this._shaderValues.getVector(UnlitMaterial.ALBEDOCOLOR);
  20142. Vector4.scale(value, this._albedoIntensity, finalAlbedo);
  20143. this._albedoColor = value;
  20144. this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR, finalAlbedo);
  20145. }
  20146. get albedoIntensity() {
  20147. return this._albedoIntensity;
  20148. }
  20149. set albedoIntensity(value) {
  20150. this._AlbedoIntensity = value;
  20151. }
  20152. get albedoTexture() {
  20153. return this._shaderValues.getTexture(UnlitMaterial.ALBEDOTEXTURE);
  20154. }
  20155. set albedoTexture(value) {
  20156. if (value)
  20157. this._shaderValues.addDefine(UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  20158. else
  20159. this._shaderValues.removeDefine(UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  20160. this._shaderValues.setTexture(UnlitMaterial.ALBEDOTEXTURE, value);
  20161. }
  20162. get tilingOffsetX() {
  20163. return this._MainTex_STX;
  20164. }
  20165. set tilingOffsetX(x) {
  20166. this._MainTex_STX = x;
  20167. }
  20168. get tilingOffsetY() {
  20169. return this._MainTex_STY;
  20170. }
  20171. set tilingOffsetY(y) {
  20172. this._MainTex_STY = y;
  20173. }
  20174. get tilingOffsetZ() {
  20175. return this._MainTex_STZ;
  20176. }
  20177. set tilingOffsetZ(z) {
  20178. this._MainTex_STZ = z;
  20179. }
  20180. get tilingOffsetW() {
  20181. return this._MainTex_STW;
  20182. }
  20183. set tilingOffsetW(w) {
  20184. this._MainTex_STW = w;
  20185. }
  20186. get tilingOffset() {
  20187. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20188. }
  20189. set tilingOffset(value) {
  20190. if (value) {
  20191. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  20192. this._shaderValues.addDefine(UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
  20193. else
  20194. this._shaderValues.removeDefine(UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
  20195. }
  20196. else {
  20197. this._shaderValues.removeDefine(UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
  20198. }
  20199. this._shaderValues.setVector(UnlitMaterial.TILINGOFFSET, value);
  20200. }
  20201. get enableVertexColor() {
  20202. return this._enableVertexColor;
  20203. }
  20204. set enableVertexColor(value) {
  20205. this._enableVertexColor = value;
  20206. if (value)
  20207. this._shaderValues.addDefine(UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
  20208. else
  20209. this._shaderValues.removeDefine(UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
  20210. }
  20211. set renderMode(value) {
  20212. switch (value) {
  20213. case UnlitMaterial.RENDERMODE_OPAQUE:
  20214. this.alphaTest = false;
  20215. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  20216. this.depthWrite = true;
  20217. this.cull = RenderState.CULL_BACK;
  20218. this.blend = RenderState.BLEND_DISABLE;
  20219. this.depthTest = RenderState.DEPTHTEST_LESS;
  20220. break;
  20221. case UnlitMaterial.RENDERMODE_CUTOUT:
  20222. this.renderQueue = BaseMaterial.RENDERQUEUE_ALPHATEST;
  20223. this.alphaTest = true;
  20224. this.depthWrite = true;
  20225. this.cull = RenderState.CULL_BACK;
  20226. this.blend = RenderState.BLEND_DISABLE;
  20227. this.depthTest = RenderState.DEPTHTEST_LESS;
  20228. break;
  20229. case UnlitMaterial.RENDERMODE_TRANSPARENT:
  20230. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  20231. this.alphaTest = false;
  20232. this.depthWrite = false;
  20233. this.cull = RenderState.CULL_BACK;
  20234. this.blend = RenderState.BLEND_ENABLE_ALL;
  20235. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  20236. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  20237. this.depthTest = RenderState.DEPTHTEST_LESS;
  20238. break;
  20239. default:
  20240. throw new Error("UnlitMaterial : renderMode value error.");
  20241. }
  20242. }
  20243. set depthWrite(value) {
  20244. this._shaderValues.setBool(UnlitMaterial.DEPTH_WRITE, value);
  20245. }
  20246. get depthWrite() {
  20247. return this._shaderValues.getBool(UnlitMaterial.DEPTH_WRITE);
  20248. }
  20249. set cull(value) {
  20250. this._shaderValues.setInt(UnlitMaterial.CULL, value);
  20251. }
  20252. get cull() {
  20253. return this._shaderValues.getInt(UnlitMaterial.CULL);
  20254. }
  20255. set blend(value) {
  20256. this._shaderValues.setInt(UnlitMaterial.BLEND, value);
  20257. }
  20258. get blend() {
  20259. return this._shaderValues.getInt(UnlitMaterial.BLEND);
  20260. }
  20261. set blendSrc(value) {
  20262. this._shaderValues.setInt(UnlitMaterial.BLEND_SRC, value);
  20263. }
  20264. get blendSrc() {
  20265. return this._shaderValues.getInt(UnlitMaterial.BLEND_SRC);
  20266. }
  20267. set blendDst(value) {
  20268. this._shaderValues.setInt(UnlitMaterial.BLEND_DST, value);
  20269. }
  20270. get blendDst() {
  20271. return this._shaderValues.getInt(UnlitMaterial.BLEND_DST);
  20272. }
  20273. set depthTest(value) {
  20274. this._shaderValues.setInt(UnlitMaterial.DEPTH_TEST, value);
  20275. }
  20276. get depthTest() {
  20277. return this._shaderValues.getInt(UnlitMaterial.DEPTH_TEST);
  20278. }
  20279. clone() {
  20280. var dest = new UnlitMaterial();
  20281. this.cloneTo(dest);
  20282. return dest;
  20283. }
  20284. }
  20285. UnlitMaterial.RENDERMODE_OPAQUE = 0;
  20286. UnlitMaterial.RENDERMODE_CUTOUT = 1;
  20287. UnlitMaterial.RENDERMODE_TRANSPARENT = 2;
  20288. UnlitMaterial.RENDERMODE_ADDTIVE = 3;
  20289. UnlitMaterial.ALBEDOTEXTURE = Shader3D.propertyNameToID("u_AlbedoTexture");
  20290. UnlitMaterial.ALBEDOCOLOR = Shader3D.propertyNameToID("u_AlbedoColor");
  20291. UnlitMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  20292. UnlitMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  20293. UnlitMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  20294. UnlitMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  20295. UnlitMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  20296. UnlitMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  20297. UnlitMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  20298. UnlitMaterial.shaderDefines = null;
  20299. class WaterPrimaryMaterial extends BaseMaterial {
  20300. constructor() {
  20301. super();
  20302. this.setShaderName("WaterPrimary");
  20303. this._shaderValues.setVector(WaterPrimaryMaterial.HORIZONCOLOR, new Vector4(0.172, 0.463, 0.435, 0));
  20304. this._shaderValues.setNumber(WaterPrimaryMaterial.WAVESCALE, 0.15);
  20305. this._shaderValues.setVector(WaterPrimaryMaterial.WAVESPEED, new Vector4(19, 9, -16, -7));
  20306. }
  20307. static __initDefine__() {
  20308. WaterPrimaryMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  20309. WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE = WaterPrimaryMaterial.shaderDefines.registerDefine("MAINTEXTURE");
  20310. WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE = WaterPrimaryMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
  20311. }
  20312. get horizonColor() {
  20313. return this._shaderValues.getVector(WaterPrimaryMaterial.HORIZONCOLOR);
  20314. }
  20315. set horizonColor(value) {
  20316. this._shaderValues.setVector(WaterPrimaryMaterial.HORIZONCOLOR, value);
  20317. }
  20318. get mainTexture() {
  20319. return this._shaderValues.getTexture(WaterPrimaryMaterial.MAINTEXTURE);
  20320. }
  20321. set mainTexture(value) {
  20322. if (value)
  20323. this._shaderValues.addDefine(WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE);
  20324. else
  20325. this._shaderValues.removeDefine(WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE);
  20326. this._shaderValues.setTexture(WaterPrimaryMaterial.MAINTEXTURE, value);
  20327. }
  20328. get normalTexture() {
  20329. return this._shaderValues.getTexture(WaterPrimaryMaterial.NORMALTEXTURE);
  20330. }
  20331. set normalTexture(value) {
  20332. if (value)
  20333. this._shaderValues.addDefine(WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE);
  20334. else
  20335. this._shaderValues.removeDefine(WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE);
  20336. this._shaderValues.setTexture(WaterPrimaryMaterial.NORMALTEXTURE, value);
  20337. }
  20338. get waveScale() {
  20339. return this._shaderValues.getNumber(WaterPrimaryMaterial.WAVESCALE);
  20340. }
  20341. set waveScale(value) {
  20342. this._shaderValues.setNumber(WaterPrimaryMaterial.WAVESCALE, value);
  20343. }
  20344. get waveSpeed() {
  20345. return this._shaderValues.getVector(WaterPrimaryMaterial.WAVESPEED);
  20346. }
  20347. set waveSpeed(value) {
  20348. this._shaderValues.setVector(WaterPrimaryMaterial.WAVESPEED, value);
  20349. }
  20350. clone() {
  20351. var dest = new WaterPrimaryMaterial();
  20352. this.cloneTo(dest);
  20353. return dest;
  20354. }
  20355. }
  20356. WaterPrimaryMaterial.HORIZONCOLOR = Shader3D.propertyNameToID("u_HorizonColor");
  20357. WaterPrimaryMaterial.MAINTEXTURE = Shader3D.propertyNameToID("u_MainTexture");
  20358. WaterPrimaryMaterial.NORMALTEXTURE = Shader3D.propertyNameToID("u_NormalTexture");
  20359. WaterPrimaryMaterial.WAVESCALE = Shader3D.propertyNameToID("u_WaveScale");
  20360. WaterPrimaryMaterial.WAVESPEED = Shader3D.propertyNameToID("u_WaveSpeed");
  20361. WaterPrimaryMaterial.shaderDefines = null;
  20362. class SkinnedMeshSprite3DShaderDeclaration {
  20363. }
  20364. class SkinnedMeshRenderer extends MeshRenderer {
  20365. constructor(owner) {
  20366. super(owner);
  20367. this._bones = [];
  20368. this._skinnedDataLoopMarks = [];
  20369. this._localBounds = new Bounds(Vector3._ZERO, Vector3._ZERO);
  20370. this._cacheAnimationNode = [];
  20371. }
  20372. get localBounds() {
  20373. return this._localBounds;
  20374. }
  20375. set localBounds(value) {
  20376. this._localBounds = value;
  20377. }
  20378. get rootBone() {
  20379. return this._cacheRootBone;
  20380. }
  20381. set rootBone(value) {
  20382. if (this._cacheRootBone != value) {
  20383. if (this._cacheRootBone)
  20384. this._cacheRootBone.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20385. else
  20386. this._owner.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20387. if (value)
  20388. value.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20389. else
  20390. this._owner.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20391. this._cacheRootBone = value;
  20392. this._onWorldMatNeedChange(Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE);
  20393. }
  20394. }
  20395. get bones() {
  20396. return this._bones;
  20397. }
  20398. _computeSkinnedData() {
  20399. if (this._cacheMesh && this._cacheAvatar || this._cacheMesh && !this._cacheAvatar) {
  20400. var bindPoses = this._cacheMesh._inverseBindPoses;
  20401. var meshBindPoseIndices = this._cacheMesh._bindPoseIndices;
  20402. var pathMarks = this._cacheMesh._skinDataPathMarks;
  20403. for (var i = 0, n = this._cacheMesh.subMeshCount; i < n; i++) {
  20404. var subMeshBoneIndices = this._cacheMesh.getSubMesh(i)._boneIndicesList;
  20405. var subData = this._skinnedData[i];
  20406. for (var j = 0, m = subMeshBoneIndices.length; j < m; j++) {
  20407. var boneIndices = subMeshBoneIndices[j];
  20408. this._computeSubSkinnedData(bindPoses, boneIndices, meshBindPoseIndices, subData[j], pathMarks);
  20409. }
  20410. }
  20411. }
  20412. }
  20413. _computeSubSkinnedData(bindPoses, boneIndices, meshBindPoseInices, data, pathMarks) {
  20414. for (var k = 0, q = boneIndices.length; k < q; k++) {
  20415. var index = boneIndices[k];
  20416. if (this._skinnedDataLoopMarks[index] === Laya.Stat.loopCount) {
  20417. var p = pathMarks[index];
  20418. var preData = this._skinnedData[p[0]][p[1]];
  20419. var srcIndex = p[2] * 16;
  20420. var dstIndex = k * 16;
  20421. for (var d = 0; d < 16; d++)
  20422. data[dstIndex + d] = preData[srcIndex + d];
  20423. }
  20424. else {
  20425. if (!this._cacheAvatar) {
  20426. var boneIndex = meshBindPoseInices[index];
  20427. Utils3D._mulMatrixArray(this._bones[boneIndex].transform.worldMatrix.elements, bindPoses[boneIndex], data, k * 16);
  20428. }
  20429. else {
  20430. Utils3D._mulMatrixArray(this._cacheAnimationNode[index].transform.getWorldMatrix(), bindPoses[meshBindPoseInices[index]], data, k * 16);
  20431. }
  20432. this._skinnedDataLoopMarks[index] = Laya.Stat.loopCount;
  20433. }
  20434. }
  20435. }
  20436. _onWorldMatNeedChange(flag) {
  20437. this._boundsChange = true;
  20438. if (this._octreeNode) {
  20439. if (this._cacheAvatar) {
  20440. if (this._indexInOctreeMotionList === -1)
  20441. this._octreeNode._octree.addMotionObject(this);
  20442. }
  20443. else {
  20444. flag &= Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE;
  20445. if (flag) {
  20446. if (this._indexInOctreeMotionList === -1)
  20447. this._octreeNode._octree.addMotionObject(this);
  20448. }
  20449. }
  20450. }
  20451. }
  20452. _createRenderElement() {
  20453. return new RenderElement();
  20454. }
  20455. _onMeshChange(value) {
  20456. super._onMeshChange(value);
  20457. this._cacheMesh = value;
  20458. var subMeshCount = value.subMeshCount;
  20459. this._skinnedData = [];
  20460. this._skinnedDataLoopMarks.length = value._bindPoseIndices.length;
  20461. for (var i = 0; i < subMeshCount; i++) {
  20462. var subBoneIndices = value.getSubMesh(i)._boneIndicesList;
  20463. var subCount = subBoneIndices.length;
  20464. var subData = this._skinnedData[i] = [];
  20465. for (var j = 0; j < subCount; j++)
  20466. subData[j] = new Float32Array(subBoneIndices[j].length * 16);
  20467. }
  20468. (this._cacheAvatar && value) && (this._getCacheAnimationNodes());
  20469. }
  20470. _setCacheAnimator(animator) {
  20471. this._cacheAnimator = animator;
  20472. this._shaderValues.addDefine(SkinnedMeshSprite3DShaderDeclaration.SHADERDEFINE_BONE);
  20473. this._setRootNode();
  20474. }
  20475. _calculateBoundingBox() {
  20476. if (!this._cacheAvatar) {
  20477. if (this._cacheRootBone)
  20478. this._localBounds._tranform(this._cacheRootBone.transform.worldMatrix, this._bounds);
  20479. else
  20480. this._localBounds._tranform(this._owner.transform.worldMatrix, this._bounds);
  20481. }
  20482. else {
  20483. if (this._cacheAnimator && this._rootBone) {
  20484. var worldMat = SkinnedMeshRenderer._tempMatrix4x4;
  20485. Utils3D.matrix4x4MultiplyMFM(this._cacheAnimator.owner.transform.worldMatrix, this._cacheRootAnimationNode.transform.getWorldMatrix(), worldMat);
  20486. this._localBounds._tranform(worldMat, this._bounds);
  20487. }
  20488. else {
  20489. super._calculateBoundingBox();
  20490. }
  20491. }
  20492. if (Laya.Render.supportWebGLPlusCulling) {
  20493. var min = this._bounds.getMin();
  20494. var max = this._bounds.getMax();
  20495. var buffer = FrustumCulling._cullingBuffer;
  20496. buffer[this._cullingBufferIndex + 1] = min.x;
  20497. buffer[this._cullingBufferIndex + 2] = min.y;
  20498. buffer[this._cullingBufferIndex + 3] = min.z;
  20499. buffer[this._cullingBufferIndex + 4] = max.x;
  20500. buffer[this._cullingBufferIndex + 5] = max.y;
  20501. buffer[this._cullingBufferIndex + 6] = max.z;
  20502. }
  20503. }
  20504. _renderUpdate(context, transform) {
  20505. if (this._cacheAnimator) {
  20506. this._computeSkinnedData();
  20507. if (!this._cacheAvatar) {
  20508. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, Matrix4x4.DEFAULT);
  20509. }
  20510. else {
  20511. var aniOwnerTrans = this._cacheAnimator.owner._transform;
  20512. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, aniOwnerTrans.worldMatrix);
  20513. }
  20514. }
  20515. else {
  20516. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, transform.worldMatrix);
  20517. }
  20518. }
  20519. _renderUpdateWithCamera(context, transform) {
  20520. var projectionView = context.projectionViewMatrix;
  20521. if (this._cacheAnimator) {
  20522. if (!this._cacheAvatar) {
  20523. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, projectionView);
  20524. }
  20525. else {
  20526. var aniOwnerTrans = this._cacheAnimator.owner._transform;
  20527. Matrix4x4.multiply(projectionView, aniOwnerTrans.worldMatrix, this._projectionViewWorldMatrix);
  20528. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  20529. }
  20530. }
  20531. else {
  20532. Matrix4x4.multiply(projectionView, transform.worldMatrix, this._projectionViewWorldMatrix);
  20533. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  20534. }
  20535. }
  20536. _destroy() {
  20537. super._destroy();
  20538. if (!this._cacheAvatar) {
  20539. if (this._cacheRootBone)
  20540. (!this._cacheRootBone.destroyed) && (this._cacheRootBone.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange));
  20541. else
  20542. (this._owner && !this._owner.destroyed) && (this._owner.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange));
  20543. }
  20544. else {
  20545. if (this._cacheRootAnimationNode)
  20546. this._cacheRootAnimationNode.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20547. }
  20548. }
  20549. get bounds() {
  20550. if (this._boundsChange || this._cacheAvatar) {
  20551. this._calculateBoundingBox();
  20552. this._boundsChange = false;
  20553. }
  20554. return this._bounds;
  20555. }
  20556. _setRootBone(name) {
  20557. this._rootBone = name;
  20558. this._setRootNode();
  20559. }
  20560. _setRootNode() {
  20561. var rootNode;
  20562. if (this._cacheAnimator && this._rootBone && this._cacheAvatar)
  20563. rootNode = this._cacheAnimator._avatarNodeMap[this._rootBone];
  20564. else
  20565. rootNode = null;
  20566. if (this._cacheRootAnimationNode != rootNode) {
  20567. this._onWorldMatNeedChange(Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE);
  20568. this._owner.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20569. if (this._cacheRootAnimationNode)
  20570. this._cacheRootAnimationNode.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20571. (rootNode) && (rootNode.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange));
  20572. this._cacheRootAnimationNode = rootNode;
  20573. }
  20574. }
  20575. _getCacheAnimationNodes() {
  20576. var meshBoneNames = this._cacheMesh._boneNames;
  20577. var bindPoseIndices = this._cacheMesh._bindPoseIndices;
  20578. var innerBindPoseCount = bindPoseIndices.length;
  20579. if (!Laya.Render.supportWebGLPlusAnimation) {
  20580. this._cacheAnimationNode.length = innerBindPoseCount;
  20581. var nodeMap = this._cacheAnimator._avatarNodeMap;
  20582. for (var i = 0; i < innerBindPoseCount; i++) {
  20583. var node = nodeMap[meshBoneNames[bindPoseIndices[i]]];
  20584. this._cacheAnimationNode[i] = node;
  20585. }
  20586. }
  20587. else {
  20588. this._cacheAnimationNodeIndices = new Uint16Array(innerBindPoseCount);
  20589. var nodeMapC = this._cacheAnimator._avatarNodeMap;
  20590. for (i = 0; i < innerBindPoseCount; i++) {
  20591. var nodeC = nodeMapC[meshBoneNames[bindPoseIndices[i]]];
  20592. this._cacheAnimationNodeIndices[i] = nodeC._worldMatrixIndex;
  20593. }
  20594. }
  20595. }
  20596. _setCacheAvatar(value) {
  20597. if (this._cacheAvatar !== value) {
  20598. if (this._cacheMesh) {
  20599. this._cacheAvatar = value;
  20600. if (value) {
  20601. this._shaderValues.addDefine(SkinnedMeshSprite3DShaderDeclaration.SHADERDEFINE_BONE);
  20602. this._getCacheAnimationNodes();
  20603. }
  20604. }
  20605. else {
  20606. this._cacheAvatar = value;
  20607. }
  20608. this._setRootNode();
  20609. }
  20610. }
  20611. _computeSubSkinnedDataNative(worldMatrixs, cacheAnimationNodeIndices, inverseBindPosesBuffer, boneIndices, bindPoseInices, data) {
  20612. Laya.LayaGL.instance.computeSubSkinnedData(worldMatrixs, cacheAnimationNodeIndices, inverseBindPosesBuffer, boneIndices, bindPoseInices, data);
  20613. }
  20614. _computeSkinnedDataForNative() {
  20615. if (this._cacheMesh && this._cacheAvatar || this._cacheMesh && !this._cacheAvatar) {
  20616. var bindPoses = this._cacheMesh._inverseBindPoses;
  20617. var meshBindPoseIndices = this._cacheMesh._bindPoseIndices;
  20618. var pathMarks = this._cacheMesh._skinDataPathMarks;
  20619. for (var i = 0, n = this._cacheMesh.subMeshCount; i < n; i++) {
  20620. var subMeshBoneIndices = this._cacheMesh.getSubMesh(i)._boneIndicesList;
  20621. var subData = this._skinnedData[i];
  20622. for (var j = 0, m = subMeshBoneIndices.length; j < m; j++) {
  20623. var boneIndices = subMeshBoneIndices[j];
  20624. if (this._cacheAvatar && Laya.Render.supportWebGLPlusAnimation)
  20625. this._computeSubSkinnedDataNative(this._cacheAnimator._animationNodeWorldMatrixs, this._cacheAnimationNodeIndices, this._cacheMesh._inverseBindPosesBuffer, boneIndices, meshBindPoseIndices, subData[j]);
  20626. else
  20627. this._computeSubSkinnedData(bindPoses, boneIndices, meshBindPoseIndices, subData[j], pathMarks);
  20628. }
  20629. }
  20630. }
  20631. }
  20632. }
  20633. SkinnedMeshRenderer._tempMatrix4x4 = new Matrix4x4();
  20634. class SkinnedMeshSprite3D extends RenderableSprite3D {
  20635. constructor(mesh = null, name = null) {
  20636. super(name);
  20637. this._meshFilter = new MeshFilter(this);
  20638. this._render = new SkinnedMeshRenderer(this);
  20639. (mesh) && (this._meshFilter.sharedMesh = mesh);
  20640. }
  20641. static __init__() {
  20642. SkinnedMeshSprite3D.shaderDefines = new ShaderDefines(MeshSprite3D.shaderDefines);
  20643. SkinnedMeshSprite3DShaderDeclaration.SHADERDEFINE_BONE = SkinnedMeshSprite3D.shaderDefines.registerDefine("BONE");
  20644. }
  20645. get meshFilter() {
  20646. return this._meshFilter;
  20647. }
  20648. get skinnedMeshRenderer() {
  20649. return this._render;
  20650. }
  20651. _parse(data, spriteMap) {
  20652. super._parse(data, spriteMap);
  20653. var render = this.skinnedMeshRenderer;
  20654. var lightmapIndex = data.lightmapIndex;
  20655. (lightmapIndex != null) && (render.lightmapIndex = lightmapIndex);
  20656. var lightmapScaleOffsetArray = data.lightmapScaleOffset;
  20657. (lightmapScaleOffsetArray) && (render.lightmapScaleOffset = new Vector4(lightmapScaleOffsetArray[0], lightmapScaleOffsetArray[1], lightmapScaleOffsetArray[2], lightmapScaleOffsetArray[3]));
  20658. var meshPath;
  20659. meshPath = data.meshPath;
  20660. if (meshPath) {
  20661. var mesh = Laya.Loader.getRes(meshPath);
  20662. (mesh) && (this.meshFilter.sharedMesh = mesh);
  20663. }
  20664. var materials = data.materials;
  20665. if (materials) {
  20666. var sharedMaterials = render.sharedMaterials;
  20667. var materialCount = materials.length;
  20668. sharedMaterials.length = materialCount;
  20669. for (var i = 0; i < materialCount; i++) {
  20670. sharedMaterials[i] = Laya.Loader.getRes(materials[i].path);
  20671. }
  20672. render.sharedMaterials = sharedMaterials;
  20673. }
  20674. var boundBox = data.boundBox;
  20675. var min = boundBox.min;
  20676. var max = boundBox.max;
  20677. render.localBounds.setMin(new Vector3(min[0], min[1], min[2]));
  20678. render.localBounds.setMax(new Vector3(max[0], max[1], max[2]));
  20679. if (spriteMap) {
  20680. var rootBoneData = data.rootBone;
  20681. render.rootBone = spriteMap[rootBoneData];
  20682. var bonesData = data.bones;
  20683. var n;
  20684. for (i = 0, n = bonesData.length; i < n; i++)
  20685. render.bones.push(spriteMap[bonesData[i]]);
  20686. }
  20687. else {
  20688. (data.rootBone) && (render._setRootBone(data.rootBone));
  20689. }
  20690. }
  20691. _changeHierarchyAnimator(animator) {
  20692. super._changeHierarchyAnimator(animator);
  20693. this.skinnedMeshRenderer._setCacheAnimator(animator);
  20694. }
  20695. _changeAnimatorAvatar(avatar) {
  20696. this.skinnedMeshRenderer._setCacheAvatar(avatar);
  20697. }
  20698. _cloneTo(destObject, srcRoot, dstRoot) {
  20699. var meshSprite3D = destObject;
  20700. meshSprite3D.meshFilter.sharedMesh = this.meshFilter.sharedMesh;
  20701. var meshRender = this._render;
  20702. var destMeshRender = meshSprite3D._render;
  20703. destMeshRender.enable = meshRender.enable;
  20704. destMeshRender.sharedMaterials = meshRender.sharedMaterials;
  20705. destMeshRender.castShadow = meshRender.castShadow;
  20706. var lightmapScaleOffset = meshRender.lightmapScaleOffset;
  20707. lightmapScaleOffset && (destMeshRender.lightmapScaleOffset = lightmapScaleOffset.clone());
  20708. destMeshRender.receiveShadow = meshRender.receiveShadow;
  20709. destMeshRender.sortingFudge = meshRender.sortingFudge;
  20710. destMeshRender._rootBone = meshRender._rootBone;
  20711. var bones = meshRender.bones;
  20712. var destBones = destMeshRender.bones;
  20713. var bonesCount = bones.length;
  20714. destBones.length = bonesCount;
  20715. var rootBone = meshRender.rootBone;
  20716. if (rootBone) {
  20717. var pathes = Utils3D._getHierarchyPath(srcRoot, rootBone, SkinnedMeshSprite3D._tempArray0);
  20718. if (pathes)
  20719. destMeshRender.rootBone = Utils3D._getNodeByHierarchyPath(dstRoot, pathes);
  20720. else
  20721. destMeshRender.rootBone = rootBone;
  20722. }
  20723. for (var i = 0; i < bones.length; i++) {
  20724. pathes = Utils3D._getHierarchyPath(srcRoot, bones[i], SkinnedMeshSprite3D._tempArray0);
  20725. if (pathes)
  20726. destBones[i] = Utils3D._getNodeByHierarchyPath(dstRoot, pathes);
  20727. else
  20728. destBones[i] = bones[i];
  20729. }
  20730. var lbb = meshRender.localBounds;
  20731. (lbb) && (lbb.cloneTo(destMeshRender.localBounds));
  20732. super._cloneTo(destObject, srcRoot, dstRoot);
  20733. }
  20734. destroy(destroyChild = true) {
  20735. if (this.destroyed)
  20736. return;
  20737. super.destroy(destroyChild);
  20738. this._meshFilter.destroy();
  20739. }
  20740. _create() {
  20741. return new SkinnedMeshSprite3D();
  20742. }
  20743. }
  20744. SkinnedMeshSprite3D._tempArray0 = [];
  20745. SkinnedMeshSprite3D.BONES = Shader3D.propertyNameToID("u_Bones");
  20746. SkinnedMeshSprite3D.shaderDefines = null;
  20747. class TrailMaterial extends BaseMaterial {
  20748. constructor() {
  20749. super();
  20750. this.setShaderName("Trail");
  20751. this._color = new Vector4(1.0, 1.0, 1.0, 1.0);
  20752. this._shaderValues.setVector(TrailMaterial.TINTCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  20753. this.renderMode = TrailMaterial.RENDERMODE_ALPHABLENDED;
  20754. }
  20755. static __initDefine__() {
  20756. TrailMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  20757. TrailMaterial.SHADERDEFINE_MAINTEXTURE = TrailMaterial.shaderDefines.registerDefine("MAINTEXTURE");
  20758. TrailMaterial.SHADERDEFINE_TILINGOFFSET = TrailMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  20759. TrailMaterial.SHADERDEFINE_ADDTIVEFOG = TrailMaterial.shaderDefines.registerDefine("ADDTIVEFOG");
  20760. }
  20761. get _TintColorR() {
  20762. return this._color.x;
  20763. }
  20764. set _TintColorR(value) {
  20765. this._color.x = value;
  20766. this.color = this._color;
  20767. }
  20768. get _TintColorG() {
  20769. return this._color.y;
  20770. }
  20771. set _TintColorG(value) {
  20772. this._color.y = value;
  20773. this.color = this._color;
  20774. }
  20775. get _TintColorB() {
  20776. return this._color.z;
  20777. }
  20778. set _TintColorB(value) {
  20779. this._color.z = value;
  20780. this.color = this._color;
  20781. }
  20782. get _TintColorA() {
  20783. return this._color.w;
  20784. }
  20785. set _TintColorA(value) {
  20786. this._color.w = value;
  20787. this.color = this._color;
  20788. }
  20789. get _MainTex_STX() {
  20790. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).x;
  20791. }
  20792. set _MainTex_STX(x) {
  20793. var tilOff = this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20794. tilOff.x = x;
  20795. this.tilingOffset = tilOff;
  20796. }
  20797. get _MainTex_STY() {
  20798. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).y;
  20799. }
  20800. set _MainTex_STY(y) {
  20801. var tilOff = this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20802. tilOff.y = y;
  20803. this.tilingOffset = tilOff;
  20804. }
  20805. get _MainTex_STZ() {
  20806. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).z;
  20807. }
  20808. set _MainTex_STZ(z) {
  20809. var tilOff = this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20810. tilOff.z = z;
  20811. this.tilingOffset = tilOff;
  20812. }
  20813. get _MainTex_STW() {
  20814. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).w;
  20815. }
  20816. set _MainTex_STW(w) {
  20817. var tilOff = this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20818. tilOff.w = w;
  20819. this.tilingOffset = tilOff;
  20820. }
  20821. set renderMode(value) {
  20822. switch (value) {
  20823. case TrailMaterial.RENDERMODE_ADDTIVE:
  20824. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  20825. this.alphaTest = false;
  20826. this.depthWrite = false;
  20827. this.cull = RenderState.CULL_NONE;
  20828. this.blend = RenderState.BLEND_ENABLE_ALL;
  20829. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  20830. this.blendDst = RenderState.BLENDPARAM_ONE;
  20831. this.depthTest = RenderState.DEPTHTEST_LESS;
  20832. this._shaderValues.addDefine(TrailMaterial.SHADERDEFINE_ADDTIVEFOG);
  20833. break;
  20834. case TrailMaterial.RENDERMODE_ALPHABLENDED:
  20835. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  20836. this.alphaTest = false;
  20837. this.depthWrite = false;
  20838. this.cull = RenderState.CULL_NONE;
  20839. this.blend = RenderState.BLEND_ENABLE_ALL;
  20840. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  20841. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  20842. this.depthTest = RenderState.DEPTHTEST_LESS;
  20843. this._shaderValues.removeDefine(TrailMaterial.SHADERDEFINE_ADDTIVEFOG);
  20844. break;
  20845. default:
  20846. throw new Error("TrailMaterial : renderMode value error.");
  20847. }
  20848. }
  20849. get colorR() {
  20850. return this._TintColorR;
  20851. }
  20852. set colorR(value) {
  20853. this._TintColorR = value;
  20854. }
  20855. get colorG() {
  20856. return this._TintColorG;
  20857. }
  20858. set colorG(value) {
  20859. this._TintColorG = value;
  20860. }
  20861. get colorB() {
  20862. return this._TintColorB;
  20863. }
  20864. set colorB(value) {
  20865. this._TintColorB = value;
  20866. }
  20867. get colorA() {
  20868. return this._TintColorA;
  20869. }
  20870. set colorA(value) {
  20871. this._TintColorA = value;
  20872. }
  20873. get color() {
  20874. return this._shaderValues.getVector(TrailMaterial.TINTCOLOR);
  20875. }
  20876. set color(value) {
  20877. this._shaderValues.setVector(TrailMaterial.TINTCOLOR, value);
  20878. }
  20879. get texture() {
  20880. return this._shaderValues.getTexture(TrailMaterial.MAINTEXTURE);
  20881. }
  20882. set texture(value) {
  20883. if (value)
  20884. this._shaderValues.addDefine(TrailMaterial.SHADERDEFINE_MAINTEXTURE);
  20885. else
  20886. this._shaderValues.removeDefine(TrailMaterial.SHADERDEFINE_MAINTEXTURE);
  20887. this._shaderValues.setTexture(TrailMaterial.MAINTEXTURE, value);
  20888. }
  20889. get tilingOffsetX() {
  20890. return this._MainTex_STX;
  20891. }
  20892. set tilingOffsetX(x) {
  20893. this._MainTex_STX = x;
  20894. }
  20895. get tilingOffsetY() {
  20896. return this._MainTex_STY;
  20897. }
  20898. set tilingOffsetY(y) {
  20899. this._MainTex_STY = y;
  20900. }
  20901. get tilingOffsetZ() {
  20902. return this._MainTex_STZ;
  20903. }
  20904. set tilingOffsetZ(z) {
  20905. this._MainTex_STZ = z;
  20906. }
  20907. get tilingOffsetW() {
  20908. return this._MainTex_STW;
  20909. }
  20910. set tilingOffsetW(w) {
  20911. this._MainTex_STW = w;
  20912. }
  20913. get tilingOffset() {
  20914. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20915. }
  20916. set tilingOffset(value) {
  20917. if (value) {
  20918. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  20919. this._shaderValues.addDefine(TrailMaterial.SHADERDEFINE_TILINGOFFSET);
  20920. else
  20921. this._shaderValues.removeDefine(TrailMaterial.SHADERDEFINE_TILINGOFFSET);
  20922. }
  20923. else {
  20924. this._shaderValues.removeDefine(TrailMaterial.SHADERDEFINE_TILINGOFFSET);
  20925. }
  20926. this._shaderValues.setVector(TrailMaterial.TILINGOFFSET, value);
  20927. }
  20928. set depthWrite(value) {
  20929. this._shaderValues.setBool(TrailMaterial.DEPTH_WRITE, value);
  20930. }
  20931. get depthWrite() {
  20932. return this._shaderValues.getBool(TrailMaterial.DEPTH_WRITE);
  20933. }
  20934. set cull(value) {
  20935. this._shaderValues.setInt(TrailMaterial.CULL, value);
  20936. }
  20937. get cull() {
  20938. return this._shaderValues.getInt(TrailMaterial.CULL);
  20939. }
  20940. set blend(value) {
  20941. this._shaderValues.setInt(TrailMaterial.BLEND, value);
  20942. }
  20943. get blend() {
  20944. return this._shaderValues.getInt(TrailMaterial.BLEND);
  20945. }
  20946. set blendSrc(value) {
  20947. this._shaderValues.setInt(TrailMaterial.BLEND_SRC, value);
  20948. }
  20949. get blendSrc() {
  20950. return this._shaderValues.getInt(TrailMaterial.BLEND_SRC);
  20951. }
  20952. set blendDst(value) {
  20953. this._shaderValues.setInt(TrailMaterial.BLEND_DST, value);
  20954. }
  20955. get blendDst() {
  20956. return this._shaderValues.getInt(TrailMaterial.BLEND_DST);
  20957. }
  20958. set depthTest(value) {
  20959. this._shaderValues.setInt(TrailMaterial.DEPTH_TEST, value);
  20960. }
  20961. get depthTest() {
  20962. return this._shaderValues.getInt(TrailMaterial.DEPTH_TEST);
  20963. }
  20964. clone() {
  20965. var dest = new TrailMaterial();
  20966. this.cloneTo(dest);
  20967. return dest;
  20968. }
  20969. }
  20970. TrailMaterial.RENDERMODE_ALPHABLENDED = 0;
  20971. TrailMaterial.RENDERMODE_ADDTIVE = 1;
  20972. TrailMaterial.MAINTEXTURE = Shader3D.propertyNameToID("u_MainTexture");
  20973. TrailMaterial.TINTCOLOR = Shader3D.propertyNameToID("u_MainColor");
  20974. TrailMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  20975. TrailMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  20976. TrailMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  20977. TrailMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  20978. TrailMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  20979. TrailMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  20980. TrailMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  20981. TrailMaterial.shaderDefines = null;
  20982. class Keyframe {
  20983. constructor() {
  20984. }
  20985. cloneTo(destObject) {
  20986. var destKeyFrame = destObject;
  20987. destKeyFrame.time = this.time;
  20988. }
  20989. clone() {
  20990. var dest = new Keyframe();
  20991. this.cloneTo(dest);
  20992. return dest;
  20993. }
  20994. }
  20995. class FloatKeyframe extends Keyframe {
  20996. constructor() {
  20997. super();
  20998. }
  20999. cloneTo(destObject) {
  21000. super.cloneTo(destObject);
  21001. var destKeyFrame = destObject;
  21002. destKeyFrame.inTangent = this.inTangent;
  21003. destKeyFrame.outTangent = this.outTangent;
  21004. destKeyFrame.value = this.value;
  21005. }
  21006. }
  21007. if (window.conch && window.conchFloatKeyframe) {
  21008. FloatKeyframe = window.conchFloatKeyframe;
  21009. }
  21010. if (window.qq && window.qq.webglPlus) {
  21011. FloatKeyframe = window.qq.webglPlus.conchFloatKeyframe;
  21012. }
  21013. class TextureMode {
  21014. }
  21015. TextureMode.Stretch = 0;
  21016. TextureMode.Tile = 1;
  21017. (function (TrailAlignment) {
  21018. TrailAlignment[TrailAlignment["View"] = 0] = "View";
  21019. TrailAlignment[TrailAlignment["TransformZ"] = 1] = "TransformZ";
  21020. })(exports.TrailAlignment || (exports.TrailAlignment = {}));
  21021. class VertexTrail {
  21022. constructor() {
  21023. }
  21024. static get vertexDeclaration1() {
  21025. return VertexTrail._vertexDeclaration1;
  21026. }
  21027. static get vertexDeclaration2() {
  21028. return VertexTrail._vertexDeclaration2;
  21029. }
  21030. get vertexDeclaration() {
  21031. return VertexTrail._vertexDeclaration1;
  21032. }
  21033. static __init__() {
  21034. VertexTrail._vertexDeclaration1 = new VertexDeclaration(32, [new VertexElement(0, VertexElementFormat.Vector3, VertexTrail.TRAIL_POSITION0),
  21035. new VertexElement(12, VertexElementFormat.Vector3, VertexTrail.TRAIL_OFFSETVECTOR),
  21036. new VertexElement(24, VertexElementFormat.Single, VertexTrail.TRAIL_TIME0),
  21037. new VertexElement(28, VertexElementFormat.Single, VertexTrail.TRAIL_TEXTURECOORDINATE0Y)]);
  21038. VertexTrail._vertexDeclaration2 = new VertexDeclaration(20, [new VertexElement(0, VertexElementFormat.Single, VertexTrail.TRAIL_TEXTURECOORDINATE0X),
  21039. new VertexElement(4, VertexElementFormat.Color, VertexTrail.TRAIL_COLOR)]);
  21040. }
  21041. }
  21042. VertexTrail.TRAIL_POSITION0 = 0;
  21043. VertexTrail.TRAIL_OFFSETVECTOR = 1;
  21044. VertexTrail.TRAIL_TIME0 = 2;
  21045. VertexTrail.TRAIL_TEXTURECOORDINATE0Y = 3;
  21046. VertexTrail.TRAIL_TEXTURECOORDINATE0X = 4;
  21047. VertexTrail.TRAIL_COLOR = 5;
  21048. class TrailGeometry extends GeometryElement {
  21049. constructor(owner) {
  21050. super();
  21051. this._floatCountPerVertices1 = 8;
  21052. this._floatCountPerVertices2 = 5;
  21053. this._increaseSegementCount = 16;
  21054. this._activeIndex = 0;
  21055. this._endIndex = 0;
  21056. this._needAddFirstVertex = false;
  21057. this._isTempEndVertex = false;
  21058. this._vertices1 = null;
  21059. this._vertices2 = null;
  21060. this._lastFixedVertexPosition = new Vector3();
  21061. this._bufferState = new BufferState();
  21062. this.tmpColor = new Color();
  21063. this._disappearBoundsMode = false;
  21064. this._owner = owner;
  21065. this._segementCount = this._increaseSegementCount;
  21066. this._resizeData(this._segementCount, this._bufferState);
  21067. var bounds = this._owner._owner.trailRenderer.bounds;
  21068. var min = bounds.getMin();
  21069. var max = bounds.getMax();
  21070. min.setValue(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  21071. max.setValue(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  21072. bounds.setMin(min);
  21073. bounds.setMax(max);
  21074. Laya.Render.supportWebGLPlusCulling && this._calculateBoundingBoxForNative();
  21075. }
  21076. _resizeData(segementCount, bufferState) {
  21077. this._subBirthTime = new Float32Array(segementCount);
  21078. this._subDistance = new Float64Array(segementCount);
  21079. var gl = Laya.LayaGL.instance;
  21080. var vertexCount = segementCount * 2;
  21081. var vertexDeclaration1 = VertexTrail.vertexDeclaration1;
  21082. var vertexDeclaration2 = VertexTrail.vertexDeclaration2;
  21083. var vertexBuffers = [];
  21084. var vertexbuffer1Size = vertexCount * vertexDeclaration1.vertexStride;
  21085. var vertexbuffer2Size = vertexCount * vertexDeclaration2.vertexStride;
  21086. var memorySize = vertexbuffer1Size + vertexbuffer2Size;
  21087. this._vertices1 = new Float32Array(vertexCount * this._floatCountPerVertices1);
  21088. this._vertices2 = new Float32Array(vertexCount * this._floatCountPerVertices2);
  21089. this._vertexBuffer1 = new VertexBuffer3D(vertexbuffer1Size, gl.STATIC_DRAW, false);
  21090. this._vertexBuffer1.vertexDeclaration = vertexDeclaration1;
  21091. this._vertexBuffer2 = new VertexBuffer3D(vertexbuffer2Size, gl.DYNAMIC_DRAW, false);
  21092. this._vertexBuffer2.vertexDeclaration = vertexDeclaration2;
  21093. vertexBuffers.push(this._vertexBuffer1);
  21094. vertexBuffers.push(this._vertexBuffer2);
  21095. bufferState.bind();
  21096. bufferState.applyVertexBuffers(vertexBuffers);
  21097. bufferState.unBind();
  21098. Laya.Resource._addMemory(memorySize, memorySize);
  21099. }
  21100. _resetData() {
  21101. var count = this._endIndex - this._activeIndex;
  21102. var oldVertices1 = new Float32Array(this._vertices1.buffer, this._floatCountPerVertices1 * 2 * this._activeIndex * 4, this._floatCountPerVertices1 * 2 * count);
  21103. var oldVertices2 = new Float32Array(this._vertices2.buffer, this._floatCountPerVertices2 * 2 * this._activeIndex * 4, this._floatCountPerVertices2 * 2 * count);
  21104. var oldSubDistance = new Float64Array(this._subDistance.buffer, this._activeIndex * 8, count);
  21105. var oldSubBirthTime = new Float32Array(this._subBirthTime.buffer, this._activeIndex * 4, count);
  21106. if (count === this._segementCount) {
  21107. this._vertexBuffer1.destroy();
  21108. this._vertexBuffer2.destroy();
  21109. this._segementCount += this._increaseSegementCount;
  21110. this._resizeData(this._segementCount, this._bufferState);
  21111. }
  21112. this._vertices1.set(oldVertices1, 0);
  21113. this._vertices2.set(oldVertices2, 0);
  21114. this._subDistance.set(oldSubDistance, 0);
  21115. this._subBirthTime.set(oldSubBirthTime, 0);
  21116. this._endIndex = count;
  21117. this._activeIndex = 0;
  21118. this._vertexBuffer1.setData(this._vertices1.buffer, 0, this._floatCountPerVertices1 * 2 * this._activeIndex * 4, this._floatCountPerVertices1 * 2 * count * 4);
  21119. this._vertexBuffer2.setData(this._vertices2.buffer, 0, this._floatCountPerVertices2 * 2 * this._activeIndex * 4, this._floatCountPerVertices2 * 2 * count * 4);
  21120. }
  21121. _updateTrail(camera, lastPosition, position) {
  21122. if (!Vector3.equals(lastPosition, position)) {
  21123. if ((this._endIndex - this._activeIndex) === 0)
  21124. this._addTrailByFirstPosition(camera, position);
  21125. else
  21126. this._addTrailByNextPosition(camera, position);
  21127. }
  21128. }
  21129. _addTrailByFirstPosition(camera, position) {
  21130. (this._endIndex === this._segementCount) && (this._resetData());
  21131. this._subDistance[this._endIndex] = 0;
  21132. this._subBirthTime[this._endIndex] = this._owner._curtime;
  21133. this._endIndex++;
  21134. position.cloneTo(this._lastFixedVertexPosition);
  21135. this._needAddFirstVertex = true;
  21136. }
  21137. _addTrailByNextPosition(camera, position) {
  21138. var delVector3 = TrailGeometry._tempVector30;
  21139. var pointAtoBVector3 = TrailGeometry._tempVector31;
  21140. switch (this._owner.alignment) {
  21141. case exports.TrailAlignment.View:
  21142. var cameraMatrix = camera.viewMatrix;
  21143. Vector3.transformCoordinate(position, cameraMatrix, TrailGeometry._tempVector33);
  21144. Vector3.transformCoordinate(this._lastFixedVertexPosition, cameraMatrix, TrailGeometry._tempVector34);
  21145. Vector3.subtract(TrailGeometry._tempVector33, TrailGeometry._tempVector34, delVector3);
  21146. Vector3.cross(TrailGeometry._tempVector33, delVector3, pointAtoBVector3);
  21147. break;
  21148. case exports.TrailAlignment.TransformZ:
  21149. Vector3.subtract(position, this._lastFixedVertexPosition, delVector3);
  21150. var forward = TrailGeometry._tempVector32;
  21151. this._owner._owner.transform.localMatrix.getForward(forward);
  21152. Vector3.cross(delVector3, forward, pointAtoBVector3);
  21153. break;
  21154. }
  21155. Vector3.normalize(pointAtoBVector3, pointAtoBVector3);
  21156. Vector3.scale(pointAtoBVector3, this._owner.widthMultiplier / 2, pointAtoBVector3);
  21157. var delLength = Vector3.scalarLength(delVector3);
  21158. var tempEndIndex;
  21159. var offset;
  21160. if (this._needAddFirstVertex) {
  21161. this._updateVerticesByPositionData(position, pointAtoBVector3, this._endIndex - 1);
  21162. this._needAddFirstVertex = false;
  21163. }
  21164. if (delLength - this._owner.minVertexDistance >= MathUtils3D.zeroTolerance) {
  21165. if (this._isTempEndVertex) {
  21166. tempEndIndex = this._endIndex - 1;
  21167. offset = delLength - this._subDistance[tempEndIndex];
  21168. this._updateVerticesByPosition(position, pointAtoBVector3, delLength, tempEndIndex);
  21169. this._owner._totalLength += offset;
  21170. }
  21171. else {
  21172. (this._endIndex === this._segementCount) && (this._resetData());
  21173. this._updateVerticesByPosition(position, pointAtoBVector3, delLength, this._endIndex);
  21174. this._owner._totalLength += delLength;
  21175. this._endIndex++;
  21176. }
  21177. position.cloneTo(this._lastFixedVertexPosition);
  21178. this._isTempEndVertex = false;
  21179. }
  21180. else {
  21181. if (this._isTempEndVertex) {
  21182. tempEndIndex = this._endIndex - 1;
  21183. offset = delLength - this._subDistance[tempEndIndex];
  21184. this._updateVerticesByPosition(position, pointAtoBVector3, delLength, tempEndIndex);
  21185. this._owner._totalLength += offset;
  21186. }
  21187. else {
  21188. (this._endIndex === this._segementCount) && (this._resetData());
  21189. this._updateVerticesByPosition(position, pointAtoBVector3, delLength, this._endIndex);
  21190. this._owner._totalLength += delLength;
  21191. this._endIndex++;
  21192. }
  21193. this._isTempEndVertex = true;
  21194. }
  21195. }
  21196. _updateVerticesByPositionData(position, pointAtoBVector3, index) {
  21197. var vertexOffset = this._floatCountPerVertices1 * 2 * index;
  21198. var curtime = this._owner._curtime;
  21199. this._vertices1[vertexOffset] = position.x;
  21200. this._vertices1[vertexOffset + 1] = position.y;
  21201. this._vertices1[vertexOffset + 2] = position.z;
  21202. this._vertices1[vertexOffset + 3] = -pointAtoBVector3.x;
  21203. this._vertices1[vertexOffset + 4] = -pointAtoBVector3.y;
  21204. this._vertices1[vertexOffset + 5] = -pointAtoBVector3.z;
  21205. this._vertices1[vertexOffset + 6] = curtime;
  21206. this._vertices1[vertexOffset + 7] = 1.0;
  21207. this._vertices1[vertexOffset + 8] = position.x;
  21208. this._vertices1[vertexOffset + 9] = position.y;
  21209. this._vertices1[vertexOffset + 10] = position.z;
  21210. this._vertices1[vertexOffset + 11] = pointAtoBVector3.x;
  21211. this._vertices1[vertexOffset + 12] = pointAtoBVector3.y;
  21212. this._vertices1[vertexOffset + 13] = pointAtoBVector3.z;
  21213. this._vertices1[vertexOffset + 14] = curtime;
  21214. this._vertices1[vertexOffset + 15] = 0.0;
  21215. var bounds = this._owner._owner.trailRenderer.bounds;
  21216. var min = bounds.getMin();
  21217. var max = bounds.getMax();
  21218. var up = TrailGeometry._tempVector35;
  21219. var down = TrailGeometry._tempVector36;
  21220. var out = TrailGeometry._tempVector32;
  21221. Vector3.add(position, pointAtoBVector3, up);
  21222. Vector3.subtract(position, pointAtoBVector3, down);
  21223. Vector3.min(down, up, out);
  21224. Vector3.min(min, out, min);
  21225. bounds.setMin(min);
  21226. Vector3.max(up, down, out);
  21227. Vector3.max(max, out, max);
  21228. bounds.setMax(max);
  21229. Laya.Render.supportWebGLPlusCulling && this._calculateBoundingBoxForNative();
  21230. var floatCount = this._floatCountPerVertices1 * 2;
  21231. this._vertexBuffer1.setData(this._vertices1.buffer, vertexOffset * 4, vertexOffset * 4, floatCount * 4);
  21232. }
  21233. _updateVerticesByPosition(position, pointAtoBVector3, delDistance, index) {
  21234. this._updateVerticesByPositionData(position, pointAtoBVector3, index);
  21235. this._subDistance[index] = delDistance;
  21236. this._subBirthTime[index] = this._owner._curtime;
  21237. }
  21238. _updateVertexBufferUV() {
  21239. var bounds;
  21240. var min, max;
  21241. if (this._disappearBoundsMode) {
  21242. bounds = this._owner._owner.trailRenderer.bounds;
  21243. min = bounds.getMin();
  21244. max = bounds.getMax();
  21245. min.setValue(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  21246. max.setValue(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  21247. Laya.Render.supportWebGLPlusCulling && this._calculateBoundingBoxForNative();
  21248. }
  21249. var vertexCount = this._endIndex;
  21250. var curLength = 0;
  21251. var gradient = this._owner.colorGradient;
  21252. var startAlphaIndex = gradient.colorAlphaKeysCount - 1;
  21253. var startColorIndex = gradient.colorRGBKeysCount - 1;
  21254. var totalLength = this._owner._totalLength;
  21255. var stride = this._floatCountPerVertices2 * 2;
  21256. for (var i = this._activeIndex; i < vertexCount; i++) {
  21257. (i !== this._activeIndex) && (curLength += this._subDistance[i]);
  21258. var uvX;
  21259. var lerpFactor;
  21260. if (this._owner.textureMode == TextureMode.Stretch) {
  21261. uvX = 1.0 - curLength / totalLength;
  21262. lerpFactor = uvX;
  21263. }
  21264. else {
  21265. lerpFactor = 1.0 - curLength / totalLength;
  21266. uvX = 1.0 - (totalLength - curLength);
  21267. }
  21268. startColorIndex = gradient.evaluateColorRGB(lerpFactor, this.tmpColor, startColorIndex, true);
  21269. startAlphaIndex = gradient.evaluateColorAlpha(lerpFactor, this.tmpColor, startAlphaIndex, true);
  21270. var index = i * stride;
  21271. this._vertices2[index + 0] = uvX;
  21272. this._vertices2[index + 1] = this.tmpColor.r;
  21273. this._vertices2[index + 2] = this.tmpColor.g;
  21274. this._vertices2[index + 3] = this.tmpColor.b;
  21275. this._vertices2[index + 4] = this.tmpColor.a;
  21276. this._vertices2[index + 5] = uvX;
  21277. this._vertices2[index + 6] = this.tmpColor.r;
  21278. this._vertices2[index + 7] = this.tmpColor.g;
  21279. this._vertices2[index + 8] = this.tmpColor.b;
  21280. this._vertices2[index + 9] = this.tmpColor.a;
  21281. if (this._disappearBoundsMode) {
  21282. var posOffset = this._floatCountPerVertices1 * 2 * i;
  21283. var pos = TrailGeometry._tempVector32;
  21284. var up = TrailGeometry._tempVector33;
  21285. var side = TrailGeometry._tempVector34;
  21286. pos.setValue(this._vertices1[posOffset + 0], this._vertices1[posOffset + 1], this._vertices1[posOffset + 2]);
  21287. up.setValue(this._vertices1[posOffset + 3], this._vertices1[posOffset + 4], this._vertices1[posOffset + 5]);
  21288. Vector3.add(pos, up, side);
  21289. Vector3.min(side, min, min);
  21290. Vector3.max(side, max, max);
  21291. Vector3.subtract(pos, up, side);
  21292. Vector3.min(side, min, min);
  21293. Vector3.max(side, max, max);
  21294. }
  21295. }
  21296. if (this._disappearBoundsMode) {
  21297. bounds.setMin(min);
  21298. bounds.setMax(max);
  21299. this._disappearBoundsMode = false;
  21300. Laya.Render.supportWebGLPlusCulling && this._calculateBoundingBoxForNative();
  21301. }
  21302. var offset = this._activeIndex * stride;
  21303. this._vertexBuffer2.setData(this._vertices2.buffer, offset * 4, offset * 4, (vertexCount * stride - offset) * 4);
  21304. }
  21305. _updateDisappear() {
  21306. var count = this._endIndex;
  21307. for (var i = this._activeIndex; i < count; i++) {
  21308. if (this._owner._curtime - this._subBirthTime[i] >= this._owner.time + MathUtils3D.zeroTolerance) {
  21309. var nextIndex = i + 1;
  21310. if (nextIndex !== count)
  21311. this._owner._totalLength -= this._subDistance[nextIndex];
  21312. if (this._isTempEndVertex && (nextIndex === count - 1)) {
  21313. var offset = this._floatCountPerVertices1 * i * 2;
  21314. var fixedPos = this._lastFixedVertexPosition;
  21315. fixedPos.x = this._vertices1[0];
  21316. fixedPos.y = this._vertices1[1];
  21317. fixedPos.z = this._vertices1[2];
  21318. this._isTempEndVertex = false;
  21319. }
  21320. this._activeIndex++;
  21321. this._disappearBoundsMode = true;
  21322. }
  21323. else {
  21324. break;
  21325. }
  21326. }
  21327. }
  21328. _getType() {
  21329. return TrailGeometry._type;
  21330. }
  21331. _prepareRender(state) {
  21332. return this._endIndex - this._activeIndex > 1;
  21333. }
  21334. _render(state) {
  21335. this._bufferState.bind();
  21336. var gl = Laya.LayaGL.instance;
  21337. var start = this._activeIndex * 2;
  21338. var count = this._endIndex * 2 - start;
  21339. gl.drawArrays(gl.TRIANGLE_STRIP, start, count);
  21340. Laya.Stat.renderBatches++;
  21341. Laya.Stat.trianglesFaces += count - 2;
  21342. }
  21343. destroy() {
  21344. super.destroy();
  21345. var memorySize = this._vertexBuffer1._byteLength + this._vertexBuffer2._byteLength;
  21346. Laya.Resource._addMemory(-memorySize, -memorySize);
  21347. this._bufferState.destroy();
  21348. this._vertexBuffer1.destroy();
  21349. this._vertexBuffer2.destroy();
  21350. this._bufferState = null;
  21351. this._vertices1 = null;
  21352. this._vertexBuffer1 = null;
  21353. this._vertices2 = null;
  21354. this._vertexBuffer2 = null;
  21355. this._subBirthTime = null;
  21356. this._subDistance = null;
  21357. this._lastFixedVertexPosition = null;
  21358. this._disappearBoundsMode = false;
  21359. }
  21360. _calculateBoundingBoxForNative() {
  21361. var trail = this._owner._owner.trailRenderer;
  21362. var bounds = trail.bounds;
  21363. var min = bounds.getMin();
  21364. var max = bounds.getMax();
  21365. var buffer = FrustumCulling._cullingBuffer;
  21366. buffer[trail._cullingBufferIndex + 1] = min.x;
  21367. buffer[trail._cullingBufferIndex + 2] = min.y;
  21368. buffer[trail._cullingBufferIndex + 3] = min.z;
  21369. buffer[trail._cullingBufferIndex + 4] = max.x;
  21370. buffer[trail._cullingBufferIndex + 5] = max.y;
  21371. buffer[trail._cullingBufferIndex + 6] = max.z;
  21372. }
  21373. }
  21374. TrailGeometry.ALIGNMENT_VIEW = 0;
  21375. TrailGeometry.ALIGNMENT_TRANSFORM_Z = 1;
  21376. TrailGeometry._tempVector30 = new Vector3();
  21377. TrailGeometry._tempVector31 = new Vector3();
  21378. TrailGeometry._tempVector32 = new Vector3();
  21379. TrailGeometry._tempVector33 = new Vector3();
  21380. TrailGeometry._tempVector34 = new Vector3();
  21381. TrailGeometry._tempVector35 = new Vector3();
  21382. TrailGeometry._tempVector36 = new Vector3();
  21383. TrailGeometry._type = GeometryElement._typeCounter++;
  21384. class TrailFilter {
  21385. constructor(owner) {
  21386. this._totalLength = 0;
  21387. this._lastPosition = new Vector3();
  21388. this._curtime = 0;
  21389. this.alignment = TrailFilter.ALIGNMENT_VIEW;
  21390. this._owner = owner;
  21391. this._initDefaultData();
  21392. this.addRenderElement();
  21393. }
  21394. get time() {
  21395. return this._time;
  21396. }
  21397. set time(value) {
  21398. this._time = value;
  21399. this._owner._render._shaderValues.setNumber(TrailFilter.LIFETIME, value);
  21400. }
  21401. get minVertexDistance() {
  21402. return this._minVertexDistance;
  21403. }
  21404. set minVertexDistance(value) {
  21405. this._minVertexDistance = value;
  21406. }
  21407. get widthMultiplier() {
  21408. return this._widthMultiplier;
  21409. }
  21410. set widthMultiplier(value) {
  21411. this._widthMultiplier = value;
  21412. }
  21413. get widthCurve() {
  21414. return this._widthCurve;
  21415. }
  21416. set widthCurve(value) {
  21417. this._widthCurve = value;
  21418. var widthCurveFloatArray = new Float32Array(value.length * 4);
  21419. var i, j, index = 0;
  21420. for (i = 0, j = value.length; i < j; i++) {
  21421. widthCurveFloatArray[index++] = value[i].time;
  21422. widthCurveFloatArray[index++] = value[i].inTangent;
  21423. widthCurveFloatArray[index++] = value[i].outTangent;
  21424. widthCurveFloatArray[index++] = value[i].value;
  21425. }
  21426. this._owner._render._shaderValues.setBuffer(TrailFilter.WIDTHCURVE, widthCurveFloatArray);
  21427. this._owner._render._shaderValues.setInt(TrailFilter.WIDTHCURVEKEYLENGTH, value.length);
  21428. }
  21429. get colorGradient() {
  21430. return this._colorGradient;
  21431. }
  21432. set colorGradient(value) {
  21433. this._colorGradient = value;
  21434. }
  21435. get textureMode() {
  21436. return this._textureMode;
  21437. }
  21438. set textureMode(value) {
  21439. this._textureMode = value;
  21440. }
  21441. addRenderElement() {
  21442. var render = this._owner._render;
  21443. var elements = render._renderElements;
  21444. var material = render.sharedMaterials[0];
  21445. (material) || (material = TrailMaterial.defaultMaterial);
  21446. var element = new RenderElement();
  21447. element.setTransform(this._owner._transform);
  21448. element.render = render;
  21449. element.material = material;
  21450. this._trialGeometry = new TrailGeometry(this);
  21451. element.setGeometry(this._trialGeometry);
  21452. elements.push(element);
  21453. }
  21454. _update(state) {
  21455. var render = this._owner._render;
  21456. this._curtime += state.scene.timer._delta / 1000;
  21457. render._shaderValues.setNumber(TrailFilter.CURTIME, this._curtime);
  21458. var curPos = this._owner.transform.position;
  21459. var element = render._renderElements[0]._geometry;
  21460. element._updateDisappear();
  21461. element._updateTrail(state.camera, this._lastPosition, curPos);
  21462. element._updateVertexBufferUV();
  21463. curPos.cloneTo(this._lastPosition);
  21464. }
  21465. _initDefaultData() {
  21466. this.time = 5.0;
  21467. this.minVertexDistance = 0.1;
  21468. this.widthMultiplier = 1;
  21469. this.textureMode = TextureMode.Stretch;
  21470. var widthKeyFrames = [];
  21471. var widthKeyFrame1 = new FloatKeyframe();
  21472. widthKeyFrame1.time = 0;
  21473. widthKeyFrame1.inTangent = 0;
  21474. widthKeyFrame1.outTangent = 0;
  21475. widthKeyFrame1.value = 1;
  21476. widthKeyFrames.push(widthKeyFrame1);
  21477. var widthKeyFrame2 = new FloatKeyframe();
  21478. widthKeyFrame2.time = 1;
  21479. widthKeyFrame2.inTangent = 0;
  21480. widthKeyFrame2.outTangent = 0;
  21481. widthKeyFrame2.value = 1;
  21482. widthKeyFrames.push(widthKeyFrame2);
  21483. this.widthCurve = widthKeyFrames;
  21484. var gradient = new Gradient(2, 2);
  21485. gradient.mode = GradientMode.Blend;
  21486. gradient.addColorRGB(0, Color.WHITE);
  21487. gradient.addColorRGB(1, Color.WHITE);
  21488. gradient.addColorAlpha(0, 1);
  21489. gradient.addColorAlpha(1, 1);
  21490. this.colorGradient = gradient;
  21491. }
  21492. destroy() {
  21493. this._trialGeometry.destroy();
  21494. this._trialGeometry = null;
  21495. this._widthCurve = null;
  21496. this._colorGradient = null;
  21497. }
  21498. }
  21499. TrailFilter.CURTIME = Shader3D.propertyNameToID("u_CurTime");
  21500. TrailFilter.LIFETIME = Shader3D.propertyNameToID("u_LifeTime");
  21501. TrailFilter.WIDTHCURVE = Shader3D.propertyNameToID("u_WidthCurve");
  21502. TrailFilter.WIDTHCURVEKEYLENGTH = Shader3D.propertyNameToID("u_WidthCurveKeyLength");
  21503. TrailFilter.ALIGNMENT_VIEW = 0;
  21504. TrailFilter.ALIGNMENT_TRANSFORM_Z = 1;
  21505. class TrailRenderer extends BaseRender {
  21506. constructor(owner) {
  21507. super(owner);
  21508. this._projectionViewWorldMatrix = new Matrix4x4();
  21509. }
  21510. _calculateBoundingBox() {
  21511. }
  21512. _needRender(boundFrustum, context) {
  21513. this._owner.trailFilter._update(context);
  21514. if (boundFrustum)
  21515. return boundFrustum.intersects(this.bounds._getBoundBox());
  21516. else
  21517. return true;
  21518. }
  21519. _updateForNative(context) {
  21520. this._owner.trailFilter._update(context);
  21521. }
  21522. _renderUpdate(state, transform) {
  21523. super._renderUpdate(state, transform);
  21524. }
  21525. _renderUpdateWithCamera(context, transform) {
  21526. var projectionView = context.projectionViewMatrix;
  21527. if (transform) {
  21528. Matrix4x4.multiply(projectionView, transform.worldMatrix, this._projectionViewWorldMatrix);
  21529. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  21530. }
  21531. else {
  21532. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, projectionView);
  21533. }
  21534. }
  21535. }
  21536. class TrailSprite3D extends RenderableSprite3D {
  21537. static __init__() {
  21538. }
  21539. get trailFilter() {
  21540. return this._geometryFilter;
  21541. }
  21542. get trailRenderer() {
  21543. return this._render;
  21544. }
  21545. constructor(name = null) {
  21546. super(name);
  21547. this._render = new TrailRenderer(this);
  21548. this._geometryFilter = new TrailFilter(this);
  21549. }
  21550. _parse(data, spriteMap) {
  21551. super._parse(data, spriteMap);
  21552. var render = this._render;
  21553. var filter = this._geometryFilter;
  21554. var i, j;
  21555. var materials = data.materials;
  21556. if (materials) {
  21557. var sharedMaterials = render.sharedMaterials;
  21558. var materialCount = materials.length;
  21559. sharedMaterials.length = materialCount;
  21560. for (i = 0; i < materialCount; i++)
  21561. sharedMaterials[i] = Laya.Loader.getRes(materials[i].path);
  21562. render.sharedMaterials = sharedMaterials;
  21563. }
  21564. filter.time = data.time;
  21565. filter.minVertexDistance = data.minVertexDistance;
  21566. filter.widthMultiplier = data.widthMultiplier;
  21567. filter.textureMode = data.textureMode;
  21568. (data.alignment != null) && (filter.alignment = data.alignment);
  21569. var widthCurve = [];
  21570. var widthCurveData = data.widthCurve;
  21571. for (i = 0, j = widthCurveData.length; i < j; i++) {
  21572. var trailkeyframe = new FloatKeyframe();
  21573. trailkeyframe.time = widthCurveData[i].time;
  21574. trailkeyframe.inTangent = widthCurveData[i].inTangent;
  21575. trailkeyframe.outTangent = widthCurveData[i].outTangent;
  21576. trailkeyframe.value = widthCurveData[i].value;
  21577. widthCurve.push(trailkeyframe);
  21578. }
  21579. filter.widthCurve = widthCurve;
  21580. var colorGradientData = data.colorGradient;
  21581. var colorKeys = colorGradientData.colorKeys;
  21582. var alphaKeys = colorGradientData.alphaKeys;
  21583. var colorGradient = new Gradient(colorKeys.length, alphaKeys.length);
  21584. colorGradient.mode = colorGradientData.mode;
  21585. for (i = 0, j = colorKeys.length; i < j; i++) {
  21586. var colorKey = colorKeys[i];
  21587. colorGradient.addColorRGB(colorKey.time, new Color(colorKey.value[0], colorKey.value[1], colorKey.value[2], 1.0));
  21588. }
  21589. for (i = 0, j = alphaKeys.length; i < j; i++) {
  21590. var alphaKey = alphaKeys[i];
  21591. colorGradient.addColorAlpha(alphaKey.time, alphaKey.value);
  21592. }
  21593. filter.colorGradient = colorGradient;
  21594. }
  21595. _onActive() {
  21596. super._onActive();
  21597. this._transform.position.cloneTo(this._geometryFilter._lastPosition);
  21598. }
  21599. _cloneTo(destObject, srcSprite, dstSprite) {
  21600. super._cloneTo(destObject, srcSprite, dstSprite);
  21601. var i, j;
  21602. var destTrailSprite3D = destObject;
  21603. var destTrailFilter = destTrailSprite3D.trailFilter;
  21604. destTrailFilter.time = this.trailFilter.time;
  21605. destTrailFilter.minVertexDistance = this.trailFilter.minVertexDistance;
  21606. destTrailFilter.widthMultiplier = this.trailFilter.widthMultiplier;
  21607. destTrailFilter.textureMode = this.trailFilter.textureMode;
  21608. var widthCurveData = this.trailFilter.widthCurve;
  21609. var widthCurve = [];
  21610. for (i = 0, j = widthCurveData.length; i < j; i++) {
  21611. var keyFrame = new FloatKeyframe();
  21612. widthCurveData[i].cloneTo(keyFrame);
  21613. widthCurve.push(keyFrame);
  21614. }
  21615. destTrailFilter.widthCurve = widthCurve;
  21616. var destColorGradient = new Gradient(this.trailFilter.colorGradient.maxColorRGBKeysCount, this.trailFilter.colorGradient.maxColorAlphaKeysCount);
  21617. this.trailFilter.colorGradient.cloneTo(destColorGradient);
  21618. destTrailFilter.colorGradient = destColorGradient;
  21619. var destTrailRender = destTrailSprite3D.trailRenderer;
  21620. destTrailRender.sharedMaterial = this.trailRenderer.sharedMaterial;
  21621. }
  21622. destroy(destroyChild = true) {
  21623. if (this.destroyed)
  21624. return;
  21625. super.destroy(destroyChild);
  21626. this._geometryFilter.destroy();
  21627. this._geometryFilter = null;
  21628. }
  21629. _create() {
  21630. return new TrailSprite3D();
  21631. }
  21632. }
  21633. class ShaderVariable {
  21634. constructor() {
  21635. this.textureID = -1;
  21636. }
  21637. }
  21638. class ShaderInstance extends Laya.Resource {
  21639. constructor(vs, ps, attributeMap, uniformMap, shaderPass) {
  21640. super();
  21641. this._stateParamsMap = [];
  21642. this._uploadMark = -1;
  21643. this._uploadRenderType = -1;
  21644. this._vs = vs;
  21645. this._ps = ps;
  21646. this._attributeMap = attributeMap;
  21647. this._uniformMap = uniformMap;
  21648. this._shaderPass = shaderPass;
  21649. this._create();
  21650. this.lock = true;
  21651. }
  21652. _create() {
  21653. var gl = Laya.LayaGL.instance;
  21654. this._program = gl.createProgram();
  21655. this._vshader = this._createShader(gl, this._vs, gl.VERTEX_SHADER);
  21656. this._pshader = this._createShader(gl, this._ps, gl.FRAGMENT_SHADER);
  21657. gl.attachShader(this._program, this._vshader);
  21658. gl.attachShader(this._program, this._pshader);
  21659. for (var k in this._attributeMap)
  21660. gl.bindAttribLocation(this._program, this._attributeMap[k], k);
  21661. gl.linkProgram(this._program);
  21662. if (!Laya.Render.isConchApp && Shader3D.debugMode && !gl.getProgramParameter(this._program, gl.LINK_STATUS))
  21663. throw gl.getProgramInfoLog(this._program);
  21664. var sceneParms = [];
  21665. var cameraParms = [];
  21666. var spriteParms = [];
  21667. var materialParms = [];
  21668. var customParms = [];
  21669. this._customUniformParamsMap = [];
  21670. var nUniformNum = gl.getProgramParameter(this._program, gl.ACTIVE_UNIFORMS);
  21671. Laya.WebGLContext.useProgram(gl, this._program);
  21672. this._curActTexIndex = 0;
  21673. var one, i, n;
  21674. for (i = 0; i < nUniformNum; i++) {
  21675. var uniformData = gl.getActiveUniform(this._program, i);
  21676. var uniName = uniformData.name;
  21677. one = new ShaderVariable();
  21678. one.location = gl.getUniformLocation(this._program, uniName);
  21679. if (uniName.indexOf('[0]') > 0) {
  21680. one.name = uniName = uniName.substr(0, uniName.length - 3);
  21681. one.isArray = true;
  21682. }
  21683. else {
  21684. one.name = uniName;
  21685. one.isArray = false;
  21686. }
  21687. one.type = uniformData.type;
  21688. this._addShaderUnifiormFun(one);
  21689. var uniformPeriod = this._uniformMap[uniName];
  21690. if (uniformPeriod != null) {
  21691. one.dataOffset = Shader3D.propertyNameToID(uniName);
  21692. switch (uniformPeriod) {
  21693. case Shader3D.PERIOD_CUSTOM:
  21694. customParms.push(one);
  21695. break;
  21696. case Shader3D.PERIOD_MATERIAL:
  21697. materialParms.push(one);
  21698. break;
  21699. case Shader3D.PERIOD_SPRITE:
  21700. spriteParms.push(one);
  21701. break;
  21702. case Shader3D.PERIOD_CAMERA:
  21703. cameraParms.push(one);
  21704. break;
  21705. case Shader3D.PERIOD_SCENE:
  21706. sceneParms.push(one);
  21707. break;
  21708. default:
  21709. throw new Error("Shader3D: period is unkonw.");
  21710. }
  21711. }
  21712. }
  21713. this._sceneUniformParamsMap = Laya.LayaGL.instance.createCommandEncoder(sceneParms.length * 4 * 5 + 4, 64, true);
  21714. for (i = 0, n = sceneParms.length; i < n; i++)
  21715. this._sceneUniformParamsMap.addShaderUniform(sceneParms[i]);
  21716. this._cameraUniformParamsMap = Laya.LayaGL.instance.createCommandEncoder(cameraParms.length * 4 * 5 + 4, 64, true);
  21717. for (i = 0, n = cameraParms.length; i < n; i++)
  21718. this._cameraUniformParamsMap.addShaderUniform(cameraParms[i]);
  21719. this._spriteUniformParamsMap = Laya.LayaGL.instance.createCommandEncoder(spriteParms.length * 4 * 5 + 4, 64, true);
  21720. for (i = 0, n = spriteParms.length; i < n; i++)
  21721. this._spriteUniformParamsMap.addShaderUniform(spriteParms[i]);
  21722. this._materialUniformParamsMap = Laya.LayaGL.instance.createCommandEncoder(materialParms.length * 4 * 5 + 4, 64, true);
  21723. for (i = 0, n = materialParms.length; i < n; i++)
  21724. this._materialUniformParamsMap.addShaderUniform(materialParms[i]);
  21725. this._customUniformParamsMap.length = customParms.length;
  21726. for (i = 0, n = customParms.length; i < n; i++) {
  21727. var custom = customParms[i];
  21728. this._customUniformParamsMap[custom.dataOffset] = custom;
  21729. }
  21730. var stateMap = this._shaderPass._stateMap;
  21731. for (var s in stateMap)
  21732. this._stateParamsMap[stateMap[s]] = Shader3D.propertyNameToID(s);
  21733. }
  21734. _getRenderState(shaderDatas, stateIndex) {
  21735. var stateID = this._stateParamsMap[stateIndex];
  21736. if (stateID == null)
  21737. return null;
  21738. else
  21739. return shaderDatas[stateID];
  21740. }
  21741. _disposeResource() {
  21742. Laya.LayaGL.instance.deleteShader(this._vshader);
  21743. Laya.LayaGL.instance.deleteShader(this._pshader);
  21744. Laya.LayaGL.instance.deleteProgram(this._program);
  21745. this._vshader = this._pshader = this._program = null;
  21746. this._setGPUMemory(0);
  21747. this._curActTexIndex = 0;
  21748. }
  21749. _addShaderUnifiormFun(one) {
  21750. var gl = Laya.LayaGL.instance;
  21751. one.caller = this;
  21752. var isArray = one.isArray;
  21753. switch (one.type) {
  21754. case gl.BOOL:
  21755. one.fun = this._uniform1i;
  21756. one.uploadedValue = new Array(1);
  21757. break;
  21758. case gl.INT:
  21759. one.fun = isArray ? this._uniform1iv : this._uniform1i;
  21760. one.uploadedValue = new Array(1);
  21761. break;
  21762. case gl.FLOAT:
  21763. one.fun = isArray ? this._uniform1fv : this._uniform1f;
  21764. one.uploadedValue = new Array(1);
  21765. break;
  21766. case gl.FLOAT_VEC2:
  21767. one.fun = isArray ? this._uniform_vec2v : this._uniform_vec2;
  21768. one.uploadedValue = new Array(2);
  21769. break;
  21770. case gl.FLOAT_VEC3:
  21771. one.fun = isArray ? this._uniform_vec3v : this._uniform_vec3;
  21772. one.uploadedValue = new Array(3);
  21773. break;
  21774. case gl.FLOAT_VEC4:
  21775. one.fun = isArray ? this._uniform_vec4v : this._uniform_vec4;
  21776. one.uploadedValue = new Array(4);
  21777. break;
  21778. case gl.FLOAT_MAT2:
  21779. one.fun = this._uniformMatrix2fv;
  21780. break;
  21781. case gl.FLOAT_MAT3:
  21782. one.fun = this._uniformMatrix3fv;
  21783. break;
  21784. case gl.FLOAT_MAT4:
  21785. one.fun = isArray ? this._uniformMatrix4fv : this._uniformMatrix4f;
  21786. break;
  21787. case gl.SAMPLER_2D:
  21788. gl.uniform1i(one.location, this._curActTexIndex);
  21789. one.textureID = Laya.WebGLContext._glTextureIDs[this._curActTexIndex++];
  21790. one.fun = this._uniform_sampler2D;
  21791. break;
  21792. case 0x8b5f:
  21793. gl.uniform1i(one.location, this._curActTexIndex);
  21794. one.textureID = Laya.WebGLContext._glTextureIDs[this._curActTexIndex++];
  21795. one.fun = this._uniform_sampler3D;
  21796. break;
  21797. case gl.SAMPLER_CUBE:
  21798. gl.uniform1i(one.location, this._curActTexIndex);
  21799. one.textureID = Laya.WebGLContext._glTextureIDs[this._curActTexIndex++];
  21800. one.fun = this._uniform_samplerCube;
  21801. break;
  21802. default:
  21803. throw new Error("compile shader err!");
  21804. break;
  21805. }
  21806. }
  21807. _createShader(gl, str, type) {
  21808. var shader = gl.createShader(type);
  21809. gl.shaderSource(shader, str);
  21810. gl.compileShader(shader);
  21811. if (Shader3D.debugMode && !gl.getShaderParameter(shader, gl.COMPILE_STATUS))
  21812. throw gl.getShaderInfoLog(shader);
  21813. return shader;
  21814. }
  21815. _uniform1f(one, value) {
  21816. var uploadedValue = one.uploadedValue;
  21817. if (uploadedValue[0] !== value) {
  21818. Laya.LayaGL.instance.uniform1f(one.location, uploadedValue[0] = value);
  21819. return 1;
  21820. }
  21821. return 0;
  21822. }
  21823. _uniform1fv(one, value) {
  21824. if (value.length < 4) {
  21825. var uploadedValue = one.uploadedValue;
  21826. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  21827. Laya.LayaGL.instance.uniform1fv(one.location, value);
  21828. uploadedValue[0] = value[0];
  21829. uploadedValue[1] = value[1];
  21830. uploadedValue[2] = value[2];
  21831. uploadedValue[3] = value[3];
  21832. return 1;
  21833. }
  21834. return 0;
  21835. }
  21836. else {
  21837. Laya.LayaGL.instance.uniform1fv(one.location, value);
  21838. return 1;
  21839. }
  21840. }
  21841. _uniform_vec2(one, v) {
  21842. var uploadedValue = one.uploadedValue;
  21843. if (uploadedValue[0] !== v.x || uploadedValue[1] !== v.y) {
  21844. Laya.LayaGL.instance.uniform2f(one.location, uploadedValue[0] = v.x, uploadedValue[1] = v.y);
  21845. return 1;
  21846. }
  21847. return 0;
  21848. }
  21849. _uniform_vec2v(one, value) {
  21850. if (value.length < 2) {
  21851. var uploadedValue = one.uploadedValue;
  21852. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  21853. Laya.LayaGL.instance.uniform2fv(one.location, value);
  21854. uploadedValue[0] = value[0];
  21855. uploadedValue[1] = value[1];
  21856. uploadedValue[2] = value[2];
  21857. uploadedValue[3] = value[3];
  21858. return 1;
  21859. }
  21860. return 0;
  21861. }
  21862. else {
  21863. Laya.LayaGL.instance.uniform2fv(one.location, value);
  21864. return 1;
  21865. }
  21866. }
  21867. _uniform_vec3(one, v) {
  21868. var uploadedValue = one.uploadedValue;
  21869. if (uploadedValue[0] !== v.x || uploadedValue[1] !== v.y || uploadedValue[2] !== v.z) {
  21870. Laya.LayaGL.instance.uniform3f(one.location, uploadedValue[0] = v.x, uploadedValue[1] = v.y, uploadedValue[2] = v.z);
  21871. return 1;
  21872. }
  21873. return 0;
  21874. }
  21875. _uniform_vec3v(one, v) {
  21876. Laya.LayaGL.instance.uniform3fv(one.location, v);
  21877. return 1;
  21878. }
  21879. _uniform_vec4(one, v) {
  21880. var uploadedValue = one.uploadedValue;
  21881. if (uploadedValue[0] !== v.x || uploadedValue[1] !== v.y || uploadedValue[2] !== v.z || uploadedValue[3] !== v.w) {
  21882. Laya.LayaGL.instance.uniform4f(one.location, uploadedValue[0] = v.x, uploadedValue[1] = v.y, uploadedValue[2] = v.z, uploadedValue[3] = v.w);
  21883. return 1;
  21884. }
  21885. return 0;
  21886. }
  21887. _uniform_vec4v(one, v) {
  21888. Laya.LayaGL.instance.uniform4fv(one.location, v);
  21889. return 1;
  21890. }
  21891. _uniformMatrix2fv(one, value) {
  21892. Laya.LayaGL.instance.uniformMatrix2fv(one.location, false, value);
  21893. return 1;
  21894. }
  21895. _uniformMatrix3fv(one, value) {
  21896. Laya.LayaGL.instance.uniformMatrix3fv(one.location, false, value);
  21897. return 1;
  21898. }
  21899. _uniformMatrix4f(one, m) {
  21900. var value = m.elements;
  21901. Laya.LayaGL.instance.uniformMatrix4fv(one.location, false, value);
  21902. return 1;
  21903. }
  21904. _uniformMatrix4fv(one, m) {
  21905. Laya.LayaGL.instance.uniformMatrix4fv(one.location, false, m);
  21906. return 1;
  21907. }
  21908. _uniform1i(one, value) {
  21909. var uploadedValue = one.uploadedValue;
  21910. if (uploadedValue[0] !== value) {
  21911. Laya.LayaGL.instance.uniform1i(one.location, uploadedValue[0] = value);
  21912. return 1;
  21913. }
  21914. return 0;
  21915. }
  21916. _uniform1iv(one, value) {
  21917. Laya.LayaGL.instance.uniform1iv(one.location, value);
  21918. return 1;
  21919. }
  21920. _uniform_ivec2(one, value) {
  21921. var uploadedValue = one.uploadedValue;
  21922. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1]) {
  21923. Laya.LayaGL.instance.uniform2i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1]);
  21924. return 1;
  21925. }
  21926. return 0;
  21927. }
  21928. _uniform_ivec2v(one, value) {
  21929. Laya.LayaGL.instance.uniform2iv(one.location, value);
  21930. return 1;
  21931. }
  21932. _uniform_vec3i(one, value) {
  21933. var uploadedValue = one.uploadedValue;
  21934. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2]) {
  21935. Laya.LayaGL.instance.uniform3i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2]);
  21936. return 1;
  21937. }
  21938. return 0;
  21939. }
  21940. _uniform_vec3vi(one, value) {
  21941. Laya.LayaGL.instance.uniform3iv(one.location, value);
  21942. return 1;
  21943. }
  21944. _uniform_vec4i(one, value) {
  21945. var uploadedValue = one.uploadedValue;
  21946. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  21947. Laya.LayaGL.instance.uniform4i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2], uploadedValue[3] = value[3]);
  21948. return 1;
  21949. }
  21950. return 0;
  21951. }
  21952. _uniform_vec4vi(one, value) {
  21953. Laya.LayaGL.instance.uniform4iv(one.location, value);
  21954. return 1;
  21955. }
  21956. _uniform_sampler2D(one, texture) {
  21957. var value = texture._getSource() || texture.defaulteTexture._getSource();
  21958. var gl = Laya.LayaGL.instance;
  21959. Laya.WebGLContext.activeTexture(gl, one.textureID);
  21960. Laya.WebGLContext.bindTexture(gl, gl.TEXTURE_2D, value);
  21961. return 0;
  21962. }
  21963. _uniform_sampler3D(one, texture) {
  21964. var value = texture._getSource() || texture.defaulteTexture._getSource();
  21965. var gl = Laya.LayaGL.instance;
  21966. Laya.WebGLContext.activeTexture(gl, one.textureID);
  21967. Laya.WebGLContext.bindTexture(gl, WebGL2RenderingContext.TEXTURE_3D, value);
  21968. return 0;
  21969. }
  21970. _uniform_samplerCube(one, texture) {
  21971. var value = texture._getSource() || texture.defaulteTexture._getSource();
  21972. var gl = Laya.LayaGL.instance;
  21973. Laya.WebGLContext.activeTexture(gl, one.textureID);
  21974. Laya.WebGLContext.bindTexture(gl, gl.TEXTURE_CUBE_MAP, value);
  21975. return 0;
  21976. }
  21977. bind() {
  21978. return Laya.WebGLContext.useProgram(Laya.LayaGL.instance, this._program);
  21979. }
  21980. uploadUniforms(shaderUniform, shaderDatas, uploadUnTexture) {
  21981. Laya.Stat.shaderCall += Laya.LayaGLRunner.uploadShaderUniforms(Laya.LayaGL.instance, shaderUniform, shaderDatas, uploadUnTexture);
  21982. }
  21983. uploadRenderStateBlendDepth(shaderDatas) {
  21984. var gl = Laya.LayaGL.instance;
  21985. var renderState = this._shaderPass.renderState;
  21986. var datas = shaderDatas.getData();
  21987. var depthWrite = this._getRenderState(datas, Shader3D.RENDER_STATE_DEPTH_WRITE);
  21988. var depthTest = this._getRenderState(datas, Shader3D.RENDER_STATE_DEPTH_TEST);
  21989. var blend = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND);
  21990. depthWrite == null && (depthWrite = renderState.depthWrite);
  21991. depthTest == null && (depthTest = renderState.depthTest);
  21992. blend == null && (blend = renderState.blend);
  21993. Laya.WebGLContext.setDepthMask(gl, depthWrite);
  21994. if (depthTest === RenderState.DEPTHTEST_OFF)
  21995. Laya.WebGLContext.setDepthTest(gl, false);
  21996. else {
  21997. Laya.WebGLContext.setDepthTest(gl, true);
  21998. Laya.WebGLContext.setDepthFunc(gl, depthTest);
  21999. }
  22000. switch (blend) {
  22001. case RenderState.BLEND_DISABLE:
  22002. Laya.WebGLContext.setBlend(gl, false);
  22003. break;
  22004. case RenderState.BLEND_ENABLE_ALL:
  22005. Laya.WebGLContext.setBlend(gl, true);
  22006. var srcBlend = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_SRC);
  22007. srcBlend == null && (srcBlend = renderState.srcBlend);
  22008. var dstBlend = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_DST);
  22009. dstBlend == null && (dstBlend = renderState.dstBlend);
  22010. Laya.WebGLContext.setBlendFunc(gl, srcBlend, dstBlend);
  22011. break;
  22012. case RenderState.BLEND_ENABLE_SEPERATE:
  22013. Laya.WebGLContext.setBlend(gl, true);
  22014. var srcRGB = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_SRC_RGB);
  22015. srcRGB == null && (srcRGB = renderState.srcBlendRGB);
  22016. var dstRGB = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_DST_RGB);
  22017. dstRGB == null && (dstRGB = renderState.dstBlendRGB);
  22018. var srcAlpha = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_SRC_ALPHA);
  22019. srcAlpha == null && (srcAlpha = renderState.srcBlendAlpha);
  22020. var dstAlpha = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_DST_ALPHA);
  22021. dstAlpha == null && (dstAlpha = renderState.dstBlendAlpha);
  22022. Laya.WebGLContext.setBlendFuncSeperate(gl, srcRGB, dstRGB, srcAlpha, dstAlpha);
  22023. break;
  22024. }
  22025. }
  22026. uploadRenderStateFrontFace(shaderDatas, isTarget, invertFront) {
  22027. var gl = Laya.LayaGL.instance;
  22028. var renderState = this._shaderPass.renderState;
  22029. var datas = shaderDatas.getData();
  22030. var cull = this._getRenderState(datas, Shader3D.RENDER_STATE_CULL);
  22031. cull == null && (cull = renderState.cull);
  22032. var forntFace;
  22033. switch (cull) {
  22034. case RenderState.CULL_NONE:
  22035. Laya.WebGLContext.setCullFace(gl, false);
  22036. break;
  22037. case RenderState.CULL_FRONT:
  22038. Laya.WebGLContext.setCullFace(gl, true);
  22039. if (isTarget) {
  22040. if (invertFront)
  22041. forntFace = gl.CCW;
  22042. else
  22043. forntFace = gl.CW;
  22044. }
  22045. else {
  22046. if (invertFront)
  22047. forntFace = gl.CW;
  22048. else
  22049. forntFace = gl.CCW;
  22050. }
  22051. Laya.WebGLContext.setFrontFace(gl, forntFace);
  22052. break;
  22053. case RenderState.CULL_BACK:
  22054. Laya.WebGLContext.setCullFace(gl, true);
  22055. if (isTarget) {
  22056. if (invertFront)
  22057. forntFace = gl.CW;
  22058. else
  22059. forntFace = gl.CCW;
  22060. }
  22061. else {
  22062. if (invertFront)
  22063. forntFace = gl.CCW;
  22064. else
  22065. forntFace = gl.CW;
  22066. }
  22067. Laya.WebGLContext.setFrontFace(gl, forntFace);
  22068. break;
  22069. }
  22070. }
  22071. uploadCustomUniform(index, data) {
  22072. Laya.Stat.shaderCall += Laya.LayaGLRunner.uploadCustomUniform(Laya.LayaGL.instance, this._customUniformParamsMap, index, data);
  22073. }
  22074. _uniformMatrix2fvForNative(one, value) {
  22075. Laya.LayaGL.instance.uniformMatrix2fvEx(one.location, false, value);
  22076. return 1;
  22077. }
  22078. _uniformMatrix3fvForNative(one, value) {
  22079. Laya.LayaGL.instance.uniformMatrix3fvEx(one.location, false, value);
  22080. return 1;
  22081. }
  22082. _uniformMatrix4fvForNative(one, m) {
  22083. Laya.LayaGL.instance.uniformMatrix4fvEx(one.location, false, m);
  22084. return 1;
  22085. }
  22086. }
  22087. class ShaderPass extends Laya.ShaderCompile {
  22088. constructor(owner, vs, ps, stateMap) {
  22089. super(vs, ps, null);
  22090. this._renderState = new RenderState();
  22091. this._owner = owner;
  22092. this._cacheSharders = [];
  22093. this._publicValidDefine = 0;
  22094. this._spriteValidDefine = 0;
  22095. this._materialValidDefine = 0;
  22096. var publicDefineMap = this._owner._publicDefinesMap;
  22097. var spriteDefineMap = this._owner._spriteDefinesMap;
  22098. var materialDefineMap = this._owner._materialDefinesMap;
  22099. for (var k in this.defs) {
  22100. if (publicDefineMap[k] != null)
  22101. this._publicValidDefine |= publicDefineMap[k];
  22102. else if (spriteDefineMap[k] != null)
  22103. this._spriteValidDefine |= spriteDefineMap[k];
  22104. else if (materialDefineMap[k] != null)
  22105. this._materialValidDefine |= materialDefineMap[k];
  22106. }
  22107. this._stateMap = stateMap;
  22108. }
  22109. get renderState() {
  22110. return this._renderState;
  22111. }
  22112. _definesToNameDic(value, int2Name) {
  22113. var o = {};
  22114. var d = 1;
  22115. for (var i = 0; i < 32; i++) {
  22116. d = 1 << i;
  22117. if (d > value)
  22118. break;
  22119. if (value & d) {
  22120. var name = int2Name[d];
  22121. o[name] = "";
  22122. }
  22123. }
  22124. return o;
  22125. }
  22126. _compileToTree(parent, lines, start, includefiles, defs) {
  22127. var node, preNode;
  22128. var text, name, fname;
  22129. var ofs, words, noUseNode;
  22130. var i, n, j;
  22131. for (i = start; i < lines.length; i++) {
  22132. text = lines[i];
  22133. if (text.length < 1)
  22134. continue;
  22135. ofs = text.indexOf("//");
  22136. if (ofs === 0)
  22137. continue;
  22138. if (ofs >= 0)
  22139. text = text.substr(0, ofs);
  22140. node = noUseNode || new Laya.ShaderNode(includefiles);
  22141. noUseNode = null;
  22142. node.text = text;
  22143. if ((ofs = text.indexOf("#")) >= 0) {
  22144. name = "#";
  22145. for (j = ofs + 1, n = text.length; j < n; j++) {
  22146. var c = text.charAt(j);
  22147. if (c === ' ' || c === '\t' || c === '?')
  22148. break;
  22149. name += c;
  22150. }
  22151. node.name = name;
  22152. switch (name) {
  22153. case "#ifdef":
  22154. case "#ifndef":
  22155. node.setParent(parent);
  22156. parent = node;
  22157. if (defs) {
  22158. words = text.substr(j).split(Laya.ShaderCompile._splitToWordExps3);
  22159. for (j = 0; j < words.length; j++) {
  22160. text = words[j];
  22161. text.length && (defs[text] = true);
  22162. }
  22163. }
  22164. continue;
  22165. case "#if":
  22166. case "#elif":
  22167. node.setParent(parent);
  22168. parent = node;
  22169. if (defs) {
  22170. words = text.substr(j).split(Laya.ShaderCompile._splitToWordExps3);
  22171. for (j = 0; j < words.length; j++) {
  22172. text = words[j];
  22173. text.length && text != "defined" && (defs[text] = true);
  22174. }
  22175. }
  22176. continue;
  22177. case "#else":
  22178. parent = parent.parent;
  22179. preNode = parent.childs[parent.childs.length - 1];
  22180. node.setParent(parent);
  22181. parent = node;
  22182. continue;
  22183. case "#endif":
  22184. parent = parent.parent;
  22185. preNode = parent.childs[parent.childs.length - 1];
  22186. node.setParent(parent);
  22187. continue;
  22188. case "#include":
  22189. words = Laya.ShaderCompile.splitToWords(text, null);
  22190. var inlcudeFile = Laya.ShaderCompile.includes[words[1]];
  22191. if (!inlcudeFile) {
  22192. throw "ShaderCompile error no this include file:" + words[1];
  22193. }
  22194. if ((ofs = words[0].indexOf("?")) < 0) {
  22195. node.setParent(parent);
  22196. text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  22197. this._compileToTree(node, text.split('\n'), 0, includefiles, defs);
  22198. node.text = "";
  22199. continue;
  22200. }
  22201. node.setCondition(words[0].substr(ofs + 1), Laya.ShaderCompile.IFDEF_YES);
  22202. node.text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  22203. break;
  22204. case "#import":
  22205. words = Laya.ShaderCompile.splitToWords(text, null);
  22206. fname = words[1];
  22207. includefiles.push({ node: node, file: Laya.ShaderCompile.includes[fname], ofs: node.text.length });
  22208. continue;
  22209. }
  22210. }
  22211. else {
  22212. preNode = parent.childs[parent.childs.length - 1];
  22213. if (preNode && !preNode.name) {
  22214. includefiles.length > 0 && Laya.ShaderCompile.splitToWords(text, preNode);
  22215. noUseNode = node;
  22216. preNode.text += "\n" + text;
  22217. continue;
  22218. }
  22219. includefiles.length > 0 && Laya.ShaderCompile.splitToWords(text, node);
  22220. }
  22221. node.setParent(parent);
  22222. }
  22223. }
  22224. withCompile(publicDefine, spriteDefine, materialDefine) {
  22225. publicDefine &= this._publicValidDefine;
  22226. spriteDefine &= this._spriteValidDefine;
  22227. materialDefine &= this._materialValidDefine;
  22228. var shader;
  22229. var spriteDefShaders, materialDefShaders;
  22230. spriteDefShaders = this._cacheSharders[publicDefine];
  22231. if (spriteDefShaders) {
  22232. materialDefShaders = spriteDefShaders[spriteDefine];
  22233. if (materialDefShaders) {
  22234. shader = materialDefShaders[materialDefine];
  22235. if (shader)
  22236. return shader;
  22237. }
  22238. else {
  22239. materialDefShaders = spriteDefShaders[spriteDefine] = [];
  22240. }
  22241. }
  22242. else {
  22243. spriteDefShaders = this._cacheSharders[publicDefine] = [];
  22244. materialDefShaders = spriteDefShaders[spriteDefine] = [];
  22245. }
  22246. var publicDefGroup = this._definesToNameDic(publicDefine, this._owner._publicDefines);
  22247. var spriteDefGroup = this._definesToNameDic(spriteDefine, this._owner._spriteDefines);
  22248. var materialDefGroup = this._definesToNameDic(materialDefine, this._owner._materialDefines);
  22249. var key;
  22250. if (Shader3D.debugMode) {
  22251. var publicDefGroupStr = "";
  22252. for (key in publicDefGroup)
  22253. publicDefGroupStr += key + " ";
  22254. var spriteDefGroupStr = "";
  22255. for (key in spriteDefGroup)
  22256. spriteDefGroupStr += key + " ";
  22257. var materialDefGroupStr = "";
  22258. for (key in materialDefGroup)
  22259. materialDefGroupStr += key + " ";
  22260. if (!Laya.WebGL.shaderHighPrecision)
  22261. publicDefine += Shader3D.SHADERDEFINE_HIGHPRECISION;
  22262. console.log("%cShader3DDebugMode---(Name:" + this._owner._owner._name + " SubShaderIndex:" + this._owner._owner._subShaders.indexOf(this._owner) + " PassIndex:" + this._owner._passes.indexOf(this) + " PublicDefine:" + publicDefine + " SpriteDefine:" + spriteDefine + " MaterialDefine:" + materialDefine + " PublicDefineGroup:" + publicDefGroupStr + " SpriteDefineGroup:" + spriteDefGroupStr + "MaterialDefineGroup: " + materialDefGroupStr + ")---ShaderCompile3DDebugMode", "color:green");
  22263. }
  22264. var defMap = {};
  22265. var defineStr = "";
  22266. if (publicDefGroup) {
  22267. for (key in publicDefGroup) {
  22268. defineStr += "#define " + key + "\n";
  22269. defMap[key] = true;
  22270. }
  22271. }
  22272. if (spriteDefGroup) {
  22273. for (key in spriteDefGroup) {
  22274. defineStr += "#define " + key + "\n";
  22275. defMap[key] = true;
  22276. }
  22277. }
  22278. if (materialDefGroup) {
  22279. for (key in materialDefGroup) {
  22280. defineStr += "#define " + key + "\n";
  22281. defMap[key] = true;
  22282. }
  22283. }
  22284. var vs = this._VS.toscript(defMap, []);
  22285. var vsVersion = '';
  22286. if (vs[0].indexOf('#version') == 0) {
  22287. vsVersion = vs[0] + '\n';
  22288. vs.shift();
  22289. }
  22290. var ps = this._PS.toscript(defMap, []);
  22291. var psVersion = '';
  22292. if (ps[0].indexOf('#version') == 0) {
  22293. psVersion = ps[0] + '\n';
  22294. ps.shift();
  22295. }
  22296. shader = new ShaderInstance(vsVersion + defineStr + vs.join('\n'), psVersion + defineStr + ps.join('\n'), this._owner._attributeMap || this._owner._owner._attributeMap, this._owner._uniformMap || this._owner._owner._uniformMap, this);
  22297. materialDefShaders[materialDefine] = shader;
  22298. return shader;
  22299. }
  22300. }
  22301. class SubShader {
  22302. constructor(attributeMap, uniformMap, spriteDefines = null, materialDefines = null) {
  22303. this._flags = {};
  22304. this._passes = [];
  22305. this._publicDefines = [];
  22306. this._publicDefinesMap = {};
  22307. this._spriteDefines = [];
  22308. this._spriteDefinesMap = {};
  22309. this._materialDefines = [];
  22310. this._materialDefinesMap = {};
  22311. this._addDefines(this._publicDefines, this._publicDefinesMap, Shader3D._globleDefines);
  22312. (spriteDefines) && (this._addDefines(this._spriteDefines, this._spriteDefinesMap, spriteDefines.defines));
  22313. (materialDefines) && (this._addDefines(this._materialDefines, this._materialDefinesMap, materialDefines.defines));
  22314. this._attributeMap = attributeMap;
  22315. this._uniformMap = uniformMap;
  22316. }
  22317. _addDefines(defines, definesMap, supportDefines) {
  22318. for (var k in supportDefines) {
  22319. var name = supportDefines[k];
  22320. var i = parseInt(k);
  22321. defines[i] = name;
  22322. definesMap[name] = i;
  22323. }
  22324. }
  22325. getMaterialDefineByName(name) {
  22326. return this._materialDefinesMap[name];
  22327. }
  22328. setFlag(key, value) {
  22329. if (value)
  22330. this._flags[key] = value;
  22331. else
  22332. delete this._flags[key];
  22333. }
  22334. getFlag(key) {
  22335. return this._flags[key];
  22336. }
  22337. addShaderPass(vs, ps, stateMap = null) {
  22338. var shaderPass = new ShaderPass(this, vs, ps, stateMap);
  22339. this._passes.push(shaderPass);
  22340. return shaderPass;
  22341. }
  22342. }
  22343. var BlitScreenPS = "#ifdef FSHIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\nuniform sampler2D u_MainTex;\r\nvarying vec2 v_Texcoord0;\r\n\r\nvoid main() {\r\n\tgl_FragColor = texture2D(u_MainTex, v_Texcoord0);\r\n}\r\n\r\n";
  22344. var BlitScreenVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_PositionTexcoord;\r\nvarying vec2 v_Texcoord0;\r\n\r\nvoid main() {\r\n\tgl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\r\n\tv_Texcoord0 = a_PositionTexcoord.zw;\r\n\tgl_Position = remapGLPositionZ(gl_Position);\r\n}";
  22345. var EffectPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#ifdef COLOR\r\n\tvarying vec4 v_Color;\r\n#endif\r\nvarying vec2 v_Texcoord0;\r\n\r\n#ifdef MAINTEXTURE\r\n\tuniform sampler2D u_AlbedoTexture;\r\n#endif\r\n\r\nuniform vec4 u_AlbedoColor;\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\t#ifdef ADDTIVEFOG\r\n\t#else\r\n\t\tuniform vec3 u_FogColor;\r\n\t#endif\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = 2.0 * u_AlbedoColor;\r\n\t#ifdef COLOR\r\n\t\tcolor *= v_Color;\r\n\t#endif\r\n\t#ifdef MAINTEXTURE\r\n\t\tcolor *= texture2D(u_AlbedoTexture, v_Texcoord0);\r\n\t#endif\r\n\t\r\n\tgl_FragColor = color;\r\n\t\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\r\n\t\t#ifdef ADDTIVEFOG\r\n\t\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.0), lerpFact);\r\n\t\t#else\r\n\t\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\r\n\t\t#endif\r\n\t#endif\r\n}\r\n\r\n";
  22346. var EffectVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec4 a_Color;\r\nattribute vec2 a_Texcoord0;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\n\r\n#ifdef COLOR\r\n\tvarying vec4 v_Color;\r\n#endif\r\nvarying vec2 v_Texcoord0;\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\tposition=skinTransform*a_Position;\r\n\t#else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t\r\n\t#ifdef TILINGOFFSET\r\n\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t#else\r\n\t\tv_Texcoord0=a_Texcoord0;\r\n\t#endif\r\n\t\t\r\n\t#ifdef COLOR\r\n\t\tv_Color = a_Color;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}";
  22347. var extendTerrainPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Lighting.glsl\";\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\r\n\tuniform vec3 u_CameraPos;\r\n\tvarying vec3 v_Normal;\r\n\tvarying vec3 v_PositionWorld;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\tuniform vec3 u_FogColor;\r\n#endif\r\n\r\n\r\n#ifdef DIRECTIONLIGHT\r\n\tuniform DirectionLight u_DirectionLight;\r\n#endif\r\n\r\n#ifdef POINTLIGHT\r\n\tuniform PointLight u_PointLight;\r\n#endif\r\n\r\n#ifdef SPOTLIGHT\r\n\tuniform SpotLight u_SpotLight;\r\n#endif\r\n\r\n#include \"ShadowHelper.glsl\"\r\n#ifdef RECEIVESHADOW\r\n\t#if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\r\n\tuniform mat4 u_lightShadowVP[4];\r\n\t#endif\r\n\t#ifdef SHADOWMAP_PSSM1 \r\n\tvarying vec4 v_lightMVPPos;\r\n\t#endif\r\n#endif\r\nvarying float v_posViewZ;\r\n\r\nuniform vec3 u_AmbientColor;\r\n\r\nuniform sampler2D u_SplatAlphaTexture;\r\n\r\nuniform sampler2D u_DiffuseTexture1;\r\nuniform sampler2D u_DiffuseTexture2;\r\nuniform sampler2D u_DiffuseTexture3;\r\nuniform sampler2D u_DiffuseTexture4;\r\nuniform sampler2D u_DiffuseTexture5;\r\n\r\nuniform vec4 u_DiffuseScaleOffset1;\r\nuniform vec4 u_DiffuseScaleOffset2;\r\nuniform vec4 u_DiffuseScaleOffset3;\r\nuniform vec4 u_DiffuseScaleOffset4;\r\nuniform vec4 u_DiffuseScaleOffset5;\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\n#ifdef LIGHTMAP\r\n\tuniform sampler2D u_LightMap;\r\n\tvarying vec2 v_LightMapUV;\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 splatAlpha = vec4(1.0);\r\n\t#ifdef ExtendTerrain_DETAIL_NUM1\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r;\r\n\t#endif\r\n\t#ifdef ExtendTerrain_DETAIL_NUM2\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * (1.0 - splatAlpha.r);\r\n\t#endif\r\n\t#ifdef ExtendTerrain_DETAIL_NUM3\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\r\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * (1.0 - splatAlpha.r - splatAlpha.g);\r\n\t#endif\r\n\t#ifdef ExtendTerrain_DETAIL_NUM4\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\r\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\r\n\t\tvec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord0 * u_DiffuseScaleOffset4.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * splatAlpha.b + color4.xyz * (1.0 - splatAlpha.r - splatAlpha.g - splatAlpha.b);\r\n\t#endif\r\n\t#ifdef ExtendTerrain_DETAIL_NUM5\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\r\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\r\n\t\tvec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord0 * u_DiffuseScaleOffset4.xy);\r\n\t\tvec4 color5 = texture2D(u_DiffuseTexture5, v_Texcoord0 * u_DiffuseScaleOffset5.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * splatAlpha.b + color4.xyz * splatAlpha.a + color5.xyz * (1.0 - splatAlpha.r - splatAlpha.g - splatAlpha.b - splatAlpha.a);\r\n\t#endif\r\n\t\tgl_FragColor.w = splatAlpha.a;\r\n\t\t\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n vec3 normal = v_Normal;\r\n\tvec3 dif, spe;\r\n#endif\r\n\r\nvec3 diffuse = vec3(0.0);\r\nvec3 specular= vec3(0.0);\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\r\n\tvec3 toEye;\r\n\t#ifdef FOG\r\n\t\ttoEye=u_CameraPos-v_PositionWorld;\r\n\t\tfloat toEyeLength=length(toEye);\r\n\t\ttoEye/=toEyeLength;\r\n\t#else\r\n\t\ttoEye=normalize(u_CameraPos-v_PositionWorld);\r\n\t#endif\r\n#endif\r\n\r\n#ifdef DIRECTIONLIGHT\r\n\tLayaAirBlinnPhongDiectionLight(vec3(0.0), 1.0, normal, vec3(1.0), toEye,u_DirectionLight, dif, spe);\r\n\tdiffuse+=dif;\r\n\tspecular+=spe;\r\n#endif\r\n \r\n#ifdef POINTLIGHT\r\n\tLayaAirBlinnPhongPointLight(v_PositionWorld, vec3(0.0), 1.0, normal, vec3(1.0), toEye, u_PointLight, dif, spe);\r\n\tdiffuse+=dif;\r\n\tspecular+=spe;\r\n#endif\r\n\r\n#ifdef SPOTLIGHT\r\n\tLayaAirBlinnPhongSpotLight(v_PositionWorld, vec3(0.0), 1.0, normal, vec3(1.0), toEye, u_SpotLight, dif, spe);\r\n\tdiffuse+=dif;\r\n\tspecular+=spe;\r\n#endif\r\n\r\nvec3 globalDiffuse = u_AmbientColor;\r\n#ifdef LIGHTMAP\r\n\tglobalDiffuse += DecodeLightmap(texture2D(u_LightMap, v_LightMapUV));\r\n#endif\r\n\r\n#ifdef RECEIVESHADOW\r\n\tfloat shadowValue = 1.0;\r\n\t#ifdef SHADOWMAP_PSSM3\r\n\t\tshadowValue = getShadowPSSM3( u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\r\n\t#endif\r\n\t#ifdef SHADOWMAP_PSSM2\r\n\t\tshadowValue = getShadowPSSM2( u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\r\n\t#endif \r\n\t#ifdef SHADOWMAP_PSSM1\r\n\t\tshadowValue = getShadowPSSM1( u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\r\n\t#endif\r\n\tgl_FragColor = vec4(gl_FragColor.rgb * (globalDiffuse + diffuse) * shadowValue, gl_FragColor.a);\r\n#else\r\n\tgl_FragColor = vec4(gl_FragColor.rgb * (globalDiffuse + diffuse), gl_FragColor.a);\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t#ifdef RECEIVESHADOW\r\n\t\tgl_FragColor.rgb += specular * shadowValue;\r\n\t#else\r\n\t\tgl_FragColor.rgb += specular;\r\n\t#endif\r\n#endif\r\n\r\n#ifdef FOG\r\n\tfloat lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);\r\n\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\r\n#endif\r\n}\r\n\r\n\r\n\r\n\r\n\r\n";
  22348. var extendTerrainVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec2 a_Texcoord0;\r\n\r\nuniform mat4 u_MvpMatrix;\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(LIGHTMAP)\r\n\tattribute vec3 a_Normal;\r\n\tvarying vec3 v_Normal;\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)||(defined(RECEIVESHADOW)&&defined(SHADOWMAP_PSSM1))\r\n\tuniform mat4 u_WorldMat;\r\n\tvarying vec3 v_PositionWorld;\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n\tvarying vec2 v_LightMapUV;\r\n\tuniform vec4 u_LightmapScaleOffset;\r\n#endif\r\n\r\n#ifdef RECEIVESHADOW\r\n\tvarying float v_posViewZ;\r\n\t#ifdef SHADOWMAP_PSSM1 \r\n\t\tvarying vec4 v_lightMVPPos;\r\n\t\tuniform mat4 u_lightShadowVP[4];\r\n\t#endif\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tgl_Position = u_MvpMatrix * a_Position;\r\n \r\n\tv_Texcoord0 = a_Texcoord0;\r\n \r\n\t#ifdef LIGHTMAP\r\n\t\tv_LightMapUV = vec2(a_Texcoord0.x, 1.0 - a_Texcoord0.y) * u_LightmapScaleOffset.xy + u_LightmapScaleOffset.zw;\r\n\t\tv_LightMapUV.y = 1.0 - v_LightMapUV.y;\r\n\t#endif\r\n \r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tv_Normal = a_Normal;\r\n\t#endif\r\n\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)||(defined(RECEIVESHADOW)&&defined(SHADOWMAP_PSSM1))\r\n\t\tv_PositionWorld=(u_WorldMat*a_Position).xyz;\r\n\t#endif\r\n\r\n\t#ifdef RECEIVESHADOW\r\n\t\tv_posViewZ = gl_Position.w;\r\n\t\t#ifdef SHADOWMAP_PSSM1\r\n\t\t\tv_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\r\n\t\t#endif\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}";
  22349. var LightingGLSL = "\r\nstruct DirectionLight {\r\n\tvec3 Color;\r\n\tvec3 Direction;\r\n};\r\n\r\nstruct PointLight {\r\n\tvec3 Color;\r\n\tvec3 Position;\r\n\tfloat Range;\r\n};\r\n\r\nstruct SpotLight {\r\n\tvec3 Color;\r\n\tvec3 Position;\r\n\tvec3 Direction;\r\n\tfloat Spot;\r\n\tfloat Range;\r\n};\r\n\r\n// Laya中使用衰减纹理\r\nfloat LayaAttenuation(in vec3 L,in float invLightRadius) {\r\n\tfloat fRatio = clamp(length(L) * invLightRadius,0.0,1.0);\r\n\tfRatio *= fRatio;\r\n\treturn 1.0 / (1.0 + 25.0 * fRatio)* clamp(4.0*(1.0 - fRatio),0.0,1.0); //fade to black as if 4 pixel texture\r\n}\r\n\r\n// Same as Just Cause 2 and Crysis 2 (you can read GPU Pro 1 book for more information)\r\nfloat BasicAttenuation(in vec3 L,in float invLightRadius) {\r\n\tvec3 distance = L * invLightRadius;\r\n\tfloat attenuation = clamp(1.0 - dot(distance, distance),0.0,1.0); // Equals float attenuation = saturate(1.0f - dot(L, L) / (lightRadius * lightRadius));\r\n\treturn attenuation * attenuation;\r\n}\r\n\r\n// Inspired on http://fools.slindev.com/viewtopic.php?f=11&t=21&view=unread#unread\r\nfloat NaturalAttenuation(in vec3 L,in float invLightRadius) {\r\n\tfloat attenuationFactor = 30.0;\r\n\tvec3 distance = L * invLightRadius;\r\n\tfloat attenuation = dot(distance, distance); // Equals float attenuation = dot(L, L) / (lightRadius * lightRadius);\r\n\tattenuation = 1.0 / (attenuation * attenuationFactor + 1.0);\r\n\t// Second we move down the function therewith it reaches zero at abscissa 1:\r\n\tattenuationFactor = 1.0 / (attenuationFactor + 1.0); //attenuationFactor contains now the value we have to subtract\r\n\tattenuation = max(attenuation - attenuationFactor, 0.0); // The max fixes a bug.\r\n\t// Finally we expand the equation along the y-axis so that it starts with a function value of 1 again.\r\n\tattenuation /= 1.0 - attenuationFactor;\r\n\treturn attenuation;\r\n}\r\n\r\nvoid LayaAirBlinnPhongLight (in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir,in vec3 lightColor, in vec3 lightVec,out vec3 diffuseColor,out vec3 specularColor) {\r\n\tmediump vec3 h = normalize(viewDir-lightVec);\r\n\tlowp float ln = max (0.0, dot (-lightVec,normal));\r\n\tfloat nh = max (0.0, dot (h,normal));\r\n\tdiffuseColor=lightColor * ln;\r\n\tspecularColor=lightColor *specColor*pow (nh, specColorIntensity*128.0) * gloss;\r\n}\r\n\r\nvoid LayaAirBlinnPhongDiectionLight (in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in DirectionLight light,out vec3 diffuseColor,out vec3 specularColor) {\r\n\tvec3 lightVec=normalize(light.Direction);\r\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,lightVec,diffuseColor,specularColor);\r\n}\r\n\r\nvoid LayaAirBlinnPhongPointLight (in vec3 pos,in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in PointLight light,out vec3 diffuseColor,out vec3 specularColor) {\r\n\tvec3 lightVec = pos-light.Position;\r\n\t//if( length(lightVec) > light.Range )\r\n\t//\treturn;\r\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,lightVec/length(lightVec),diffuseColor,specularColor);\r\n\tfloat attenuate = LayaAttenuation(lightVec, 1.0/light.Range);\r\n\tdiffuseColor *= attenuate;\r\n\tspecularColor*= attenuate;\r\n}\r\n\r\nvoid LayaAirBlinnPhongSpotLight (in vec3 pos,in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in SpotLight light,out vec3 diffuseColor,out vec3 specularColor) {\r\n\tvec3 lightVec = pos-light.Position;\r\n\t//if( length(lightVec) > light.Range)\r\n\t//\treturn;\r\n\r\n\tvec3 normalLightVec=lightVec/length(lightVec);\r\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,normalLightVec,diffuseColor,specularColor);\r\n\tvec2 cosAngles=cos(vec2(light.Spot,light.Spot*0.5)*0.5);//ConeAttenuation\r\n\tfloat dl=dot(normalize(light.Direction),normalLightVec);\r\n\tdl*=smoothstep(cosAngles[0],cosAngles[1],dl);\r\n\tfloat attenuate = LayaAttenuation(lightVec, 1.0/light.Range)*dl;\r\n\tdiffuseColor *=attenuate;\r\n\tspecularColor *=attenuate;\r\n}\r\n\r\nvec3 NormalSampleToWorldSpace(vec3 normalMapSample, vec3 unitNormal, vec3 tangent,vec3 binormal) {\r\n\tvec3 normalT =vec3(2.0*normalMapSample.x - 1.0,1.0-2.0*normalMapSample.y,2.0*normalMapSample.z - 1.0);\r\n\r\n\t// Build orthonormal basis.\r\n\tvec3 N = normalize(unitNormal);\r\n\tvec3 T = normalize(tangent);\r\n\tvec3 B = normalize(binormal);\r\n\tmat3 TBN = mat3(T, B, N);\r\n\r\n\t// Transform from tangent space to world space.\r\n\tvec3 bumpedNormal = TBN*normalT;\r\n\r\n\treturn bumpedNormal;\r\n}\r\n\r\nvec3 NormalSampleToWorldSpace1(vec4 normalMapSample, vec3 tangent, vec3 binormal, vec3 unitNormal) {\r\n\tvec3 normalT;\r\n\tnormalT.x = 2.0 * normalMapSample.x - 1.0;\r\n\tnormalT.y = 1.0 - 2.0 * normalMapSample.y;\r\n\tnormalT.z = sqrt(1.0 - clamp(dot(normalT.xy, normalT.xy), 0.0, 1.0));\r\n\r\n\tvec3 T = normalize(tangent);\r\n\tvec3 B = normalize(binormal);\r\n\tvec3 N = normalize(unitNormal);\r\n\tmat3 TBN = mat3(T, B, N);\r\n\r\n\t// Transform from tangent space to world space.\r\n\tvec3 bumpedNormal = TBN * normalize(normalT);\r\n\r\n\treturn bumpedNormal;\r\n}\r\n\r\nvec3 DecodeLightmap(vec4 color) {\r\n\treturn color.rgb*color.a*5.0;\r\n}\r\n\r\nvec2 TransformUV(vec2 texcoord,vec4 tilingOffset) {\r\n\tvec2 transTexcoord=vec2(texcoord.x,texcoord.y-1.0)*tilingOffset.xy+vec2(tilingOffset.z,-tilingOffset.w);\r\n\ttransTexcoord.y+=1.0;\r\n\treturn transTexcoord;\r\n}\r\n\r\nvec4 remapGLPositionZ(vec4 position) {\r\n\tposition.z=position.z * 2.0 - position.w;\r\n\treturn position;\r\n}\r\n\r\nmat3 inverse(mat3 m) {\r\n float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];\r\n float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];\r\n float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];\r\n\r\n float b01 = a22 * a11 - a12 * a21;\r\n float b11 = -a22 * a10 + a12 * a20;\r\n float b21 = a21 * a10 - a11 * a20;\r\n\r\n float det = a00 * b01 + a01 * b11 + a02 * b21;\r\n\r\n return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),\r\n b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),\r\n b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;\r\n}\r\n\r\n";
  22350. var linePS = "#ifdef HIGHPRECISION\r\nprecision highp float;\r\n#else\r\nprecision mediump float;\r\n#endif\r\n\r\nvarying vec4 v_Color;\r\nuniform vec4 u_Color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = v_Color * u_Color; \r\n}\r\n\r\n";
  22351. var lineVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\nuniform mat4 u_MvpMatrix;\r\nuniform vec4 u_Color;\r\nattribute vec4 a_Color;\r\nvarying vec4 v_Color;\r\n\r\n\r\nvoid main()\r\n{\r\n\tgl_Position = u_MvpMatrix * a_Position;\r\n\tv_Color=a_Color*u_Color;\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}";
  22352. var MeshBlinnPhongPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Lighting.glsl\";\r\n\r\nuniform vec4 u_DiffuseColor;\r\n\r\n#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\tvarying vec4 v_Color;\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\tvarying vec3 v_ViewDir; \r\n#endif\r\n\r\n#ifdef ALPHATEST\r\n\tuniform float u_AlphaTestValue;\r\n#endif\r\n\r\n#ifdef DIFFUSEMAP\r\n\tuniform sampler2D u_DiffuseTexture;\r\n#endif\r\n\r\n\r\n\r\n#if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))\r\n\tvarying vec2 v_Texcoord0;\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n\tvarying vec2 v_LightMapUV;\r\n\tuniform sampler2D u_LightMap;\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\tuniform vec3 u_MaterialSpecular;\r\n\tuniform float u_Shininess;\r\n\t#ifdef SPECULARMAP \r\n\t\tuniform sampler2D u_SpecularTexture;\r\n\t#endif\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\tuniform vec3 u_FogColor;\r\n#endif\r\n\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\tvarying vec3 v_Normal;\r\n#endif\r\n\r\n#if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&defined(NORMALMAP)\r\n\tuniform sampler2D u_NormalTexture;\r\n\tvarying vec3 v_Tangent;\r\n\tvarying vec3 v_Binormal;\r\n#endif\r\n\r\n#ifdef DIRECTIONLIGHT\r\n\tuniform DirectionLight u_DirectionLight;\r\n#endif\r\n\r\n#ifdef POINTLIGHT\r\n\tuniform PointLight u_PointLight;\r\n#endif\r\n\r\n#ifdef SPOTLIGHT\r\n\tuniform SpotLight u_SpotLight;\r\n#endif\r\n\r\nuniform vec3 u_AmbientColor;\r\n\r\n\r\n#if defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\r\n\tvarying vec3 v_PositionWorld;\r\n#endif\r\n\r\n#include \"ShadowHelper.glsl\"\r\nvarying float v_posViewZ;\r\n#ifdef RECEIVESHADOW\r\n\t#if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\r\n\t\tuniform mat4 u_lightShadowVP[4];\r\n\t#endif\r\n\t#ifdef SHADOWMAP_PSSM1 \r\n\t\tvarying vec4 v_lightMVPPos;\r\n\t#endif\r\n#endif\r\n\r\nvoid main_castShadow()\r\n{\r\n\t//gl_FragColor=vec4(v_posViewZ,0.0,0.0,1.0);\r\n\tgl_FragColor=packDepth(v_posViewZ);\r\n\t#if defined(DIFFUSEMAP)&&defined(ALPHATEST)\r\n\t\tfloat alpha = texture2D(u_DiffuseTexture,v_Texcoord0).w;\r\n\t\tif( alpha < u_AlphaTestValue )\r\n\t\t{\r\n\t\t\tdiscard;\r\n\t\t}\r\n\t#endif\r\n}\r\nvoid main_normal()\r\n{\r\n\tvec3 globalDiffuse=u_AmbientColor;\r\n\t#ifdef LIGHTMAP\t\r\n\t\tglobalDiffuse += DecodeLightmap(texture2D(u_LightMap, v_LightMapUV));\r\n\t#endif\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tvec3 normal;\r\n\t\t#if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&defined(NORMALMAP)\r\n\t\t\tvec3 normalMapSample = texture2D(u_NormalTexture, v_Texcoord0).rgb;\r\n\t\t\tnormal = normalize(NormalSampleToWorldSpace(normalMapSample, v_Normal, v_Tangent,v_Binormal));\r\n\t\t#else\r\n\t\t\tnormal = normalize(v_Normal);\r\n\t\t#endif\r\n\t\tvec3 viewDir= normalize(v_ViewDir);\r\n\t#endif\r\n\t\r\n\tvec4 mainColor=u_DiffuseColor;\r\n\t#ifdef DIFFUSEMAP\r\n\t\tvec4 difTexColor=texture2D(u_DiffuseTexture, v_Texcoord0);\r\n\t\tmainColor=mainColor*difTexColor;\r\n\t#endif \r\n\t#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\t\tmainColor=mainColor*v_Color;\r\n\t#endif \r\n \r\n\t#ifdef ALPHATEST\r\n\t\tif(mainColor.a<u_AlphaTestValue)\r\n\t\t\tdiscard;\r\n\t#endif\r\n \r\n\t\r\n\tvec3 diffuse = vec3(0.0);\r\n\tvec3 specular= vec3(0.0);\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tvec3 dif,spe;\r\n\t\t#ifdef SPECULARMAP\r\n\t\t\tvec3 gloss=texture2D(u_SpecularTexture, v_Texcoord0).rgb;\r\n\t\t#else\r\n\t\t\t#ifdef DIFFUSEMAP\r\n\t\t\t\tvec3 gloss=vec3(difTexColor.a);\r\n\t\t\t#else\r\n\t\t\t\tvec3 gloss=vec3(1.0);\r\n\t\t\t#endif\r\n\t\t#endif\r\n\t#endif\r\n\r\n\t\r\n\t#ifdef DIRECTIONLIGHT\r\n\t\tLayaAirBlinnPhongDiectionLight(u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_DirectionLight,dif,spe);\r\n\t\tdiffuse+=dif;\r\n\t\tspecular+=spe;\r\n\t#endif\r\n \r\n\t#ifdef POINTLIGHT\r\n\t\tLayaAirBlinnPhongPointLight(v_PositionWorld,u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_PointLight,dif,spe);\r\n\t\tdiffuse+=dif;\r\n\t\tspecular+=spe;\r\n\t#endif\r\n\r\n\t#ifdef SPOTLIGHT\r\n\t\tLayaAirBlinnPhongSpotLight(v_PositionWorld,u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_SpotLight,dif,spe);\r\n\t\tdiffuse+=dif;\r\n\t\tspecular+=spe;\r\n\t#endif\r\n\r\n\t#ifdef RECEIVESHADOW\r\n\t\tfloat shadowValue = 1.0;\r\n\t\t#ifdef SHADOWMAP_PSSM3\r\n\t\t\tshadowValue = getShadowPSSM3(u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\r\n\t\t#endif\r\n\t\t#ifdef SHADOWMAP_PSSM2\r\n\t\t\tshadowValue = getShadowPSSM2(u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\r\n\t\t#endif \r\n\t\t#ifdef SHADOWMAP_PSSM1\r\n\t\t\tshadowValue = getShadowPSSM1(u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\r\n\t\t#endif\r\n\t\tgl_FragColor =vec4(mainColor.rgb*(globalDiffuse + diffuse*shadowValue),mainColor.a);\r\n\t#else\r\n\t\tgl_FragColor =vec4(mainColor.rgb*(globalDiffuse + diffuse),mainColor.a);\r\n\t#endif\r\n\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\t#ifdef RECEIVESHADOW\r\n\t\t\tgl_FragColor.rgb+=specular*shadowValue;\r\n\t\t#else\r\n\t\t\tgl_FragColor.rgb+=specular;\r\n\t\t#endif\r\n\t#endif\r\n\t \r\n\t#ifdef FOG\r\n\t\tfloat lerpFact=clamp((1.0/gl_FragCoord.w-u_FogStart)/u_FogRange,0.0,1.0);\r\n\t\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\r\n\t#endif\r\n}\r\n\r\nvoid main()\r\n{\r\n\t#ifdef CASTSHADOW\t\t\r\n\t\tmain_castShadow();\r\n\t#else\r\n\t\tmain_normal();\r\n\t#endif \r\n}\r\n\r\n";
  22353. var MeshBlinnPhongVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\n\r\n\r\n#if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))||(defined(LIGHTMAP)&&defined(UV))\r\n\tattribute vec2 a_Texcoord0;\r\n\tvarying vec2 v_Texcoord0;\r\n#endif\r\n\r\n#if defined(LIGHTMAP)&&defined(UV1)\r\n\tattribute vec2 a_Texcoord1;\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n\tuniform vec4 u_LightmapScaleOffset;\r\n\tvarying vec2 v_LightMapUV;\r\n#endif\r\n\r\n#ifdef COLOR\r\n\tattribute vec4 a_Color;\r\n\tvarying vec4 v_Color;\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\tattribute vec3 a_Normal;\r\n\tvarying vec3 v_Normal; \r\n\tuniform vec3 u_CameraPos;\r\n\tvarying vec3 v_ViewDir; \r\n#endif\r\n\r\n#if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&defined(NORMALMAP)\r\n\tattribute vec4 a_Tangent0;\r\n\tvarying vec3 v_Tangent;\r\n\tvarying vec3 v_Binormal;\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\r\n\t#ifdef GPU_INSTANCE\r\n\t\tattribute mat4 a_WorldMat;\r\n\t#else\r\n\t\tuniform mat4 u_WorldMat;\r\n\t#endif\r\n\tvarying vec3 v_PositionWorld;\r\n#endif\r\n\r\nvarying float v_posViewZ;\r\n#ifdef RECEIVESHADOW\r\n #ifdef SHADOWMAP_PSSM1 \r\n varying vec4 v_lightMVPPos;\r\n uniform mat4 u_lightShadowVP[4];\r\n #endif\r\n#endif\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\nvoid main_castShadow()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\tposition=skinTransform*a_Position;\r\n\t#else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t\r\n\t//TODO没考虑UV动画呢\r\n\t#if defined(DIFFUSEMAP)&&defined(ALPHATEST)\r\n\t\tv_Texcoord0=a_Texcoord0;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n\tv_posViewZ = gl_Position.z;\r\n}\r\n\r\nvoid main_normal()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\tposition=skinTransform*a_Position;\r\n\t#else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\r\n\t\tmat4 worldMat;\r\n\t\t#ifdef GPU_INSTANCE\r\n\t\t\tworldMat = a_WorldMat;\r\n\t\t#else\r\n\t\t\tworldMat = u_WorldMat;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tmat3 worldInvMat;\r\n\t\t#ifdef BONE\r\n\t\t\tworldInvMat=inverse(mat3(worldMat*skinTransform));\r\n\t\t#else\r\n\t\t\tworldInvMat=inverse(mat3(worldMat));\r\n\t\t#endif \r\n\t\tv_Normal=a_Normal*worldInvMat;\r\n\t\t#if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&defined(NORMALMAP)\r\n\t\t\tv_Tangent=a_Tangent0.xyz*worldInvMat;\r\n\t\t\tv_Binormal=cross(v_Normal,v_Tangent)*a_Tangent0.w;\r\n\t\t#endif\r\n\t#endif\r\n\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\r\n\t\tv_PositionWorld=(worldMat*position).xyz;\r\n\t#endif\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tv_ViewDir=u_CameraPos-v_PositionWorld;\r\n\t#endif\r\n\r\n\t#if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))\r\n\t\t#ifdef TILINGOFFSET\r\n\t\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t\t#else\r\n\t\t\tv_Texcoord0=a_Texcoord0;\r\n\t\t#endif\r\n\t#endif\r\n\r\n\t#ifdef LIGHTMAP\r\n\t\t#ifdef SCALEOFFSETLIGHTINGMAPUV\r\n\t\t\t#ifdef UV1\r\n\t\t\t\tv_LightMapUV=vec2(a_Texcoord1.x,1.0-a_Texcoord1.y)*u_LightmapScaleOffset.xy+u_LightmapScaleOffset.zw;\r\n\t\t\t#else\r\n\t\t\t\tv_LightMapUV=vec2(a_Texcoord0.x,1.0-a_Texcoord0.y)*u_LightmapScaleOffset.xy+u_LightmapScaleOffset.zw;\r\n\t\t\t#endif \r\n\t\t\tv_LightMapUV.y=1.0-v_LightMapUV.y;\r\n\t\t#else\r\n\t\t\t#ifdef UV1\r\n\t\t\t\tv_LightMapUV=a_Texcoord1;\r\n\t\t\t#else\r\n\t\t\t\tv_LightMapUV=a_Texcoord0;\r\n\t\t\t#endif \r\n\t\t#endif \r\n\t#endif\r\n\r\n\t#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\t\tv_Color=a_Color;\r\n\t#endif\r\n\r\n\t#ifdef RECEIVESHADOW\r\n\t\tv_posViewZ = gl_Position.w;\r\n\t\t#ifdef SHADOWMAP_PSSM1 \r\n\t\t\tv_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\r\n\t\t#endif\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n\r\nvoid main()\r\n{\r\n\t#ifdef CASTSHADOW\r\n\t\tmain_castShadow();\r\n\t#else\r\n\t\tmain_normal();\r\n\t#endif\r\n}";
  22354. var ParticleShuriKenPS = "#ifdef HIGHPRECISION\r\n precision highp float;\r\n#else\r\n precision mediump float;\r\n#endif\r\n\r\nvarying float v_Discard;\r\nvarying vec4 v_Color;\r\nvarying vec2 v_TextureCoordinate;\r\nuniform sampler2D u_texture;\r\nuniform vec4 u_Tintcolor;\r\n\r\n#ifdef RENDERMODE_MESH\r\n\tvarying vec4 v_MeshColor;\r\n#endif\r\n\r\n#ifdef FOG\r\n\t//varying vec3 v_PositionWorld;\r\n\t//uniform vec3 u_CameraPos;\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\t#ifdef ADDTIVEFOG\r\n\t#else\r\n\t\tuniform vec3 u_FogColor;\r\n\t#endif\r\n#endif\r\n\r\n\r\nvoid main()\r\n{\t\r\n\t#ifdef RENDERMODE_MESH\r\n\t\tgl_FragColor=v_MeshColor;\r\n\t#else\r\n\t\tgl_FragColor=vec4(1.0);\t\r\n\t#endif\r\n\t\t\r\n\t#ifdef DIFFUSEMAP\r\n\t\tif(v_Discard!=0.0)\r\n\t\t\tdiscard;\r\n\t\t#ifdef TINTCOLOR\r\n\t\t\tgl_FragColor*=texture2D(u_texture,v_TextureCoordinate)*u_Tintcolor*2.0*v_Color;\r\n\t\t#else\r\n\t\t\tgl_FragColor*=texture2D(u_texture,v_TextureCoordinate)*v_Color;\r\n\t\t#endif\r\n\t#else\r\n\t\t#ifdef TINTCOLOR\r\n\t\t\tgl_FragColor*=u_Tintcolor*2.0*v_Color;\r\n\t\t#else\r\n\t\t\tgl_FragColor*=v_Color;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\t#ifdef FOG\r\n\t\t//vec3 toEye=u_CameraPos-v_PositionWorld;\r\n\t\t//float toEyeLength=length(toEye);\r\n\t\t//toEye/=toEyeLength;\r\n\t\t\r\n\t\t//float lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);\r\n\t\t#ifdef ADDTIVEFOG\r\n\t\t\t//gl_FragColor.rgb=mix(gl_FragColor.rgb,vec3(0.0,0.0,0.0),lerpFact);\r\n\t\t#else\r\n\t\t\t//gl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact=clamp((1.0/gl_FragCoord.w-u_FogStart)/u_FogRange,0.0,1.0);\r\n\t\t#ifdef ADDTIVEFOG\r\n\t\t\tgl_FragColor.rgb=mix(gl_FragColor.rgb,vec3(0.0,0.0,0.0),lerpFact);\r\n\t\t#else\r\n\t\t\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\r\n\t\t#endif\r\n\t#endif\r\n}";
  22355. var ParticleShuriKenVS = "#include \"Lighting.glsl\";\r\n\r\n#ifdef HIGHPRECISION\r\n precision highp float;\r\n#else\r\n precision mediump float;\r\n#endif\r\n\r\n#if defined(SPHERHBILLBOARD)||defined(STRETCHEDBILLBOARD)||defined(HORIZONTALBILLBOARD)||defined(VERTICALBILLBOARD)\r\n\tattribute vec4 a_CornerTextureCoordinate;\r\n#endif\r\n#ifdef RENDERMODE_MESH\r\n\tattribute vec3 a_MeshPosition;\r\n\tattribute vec4 a_MeshColor;\r\n\tattribute vec2 a_MeshTextureCoordinate;\r\n\tvarying vec4 v_MeshColor;\r\n#endif\r\n\r\nattribute vec4 a_ShapePositionStartLifeTime;\r\nattribute vec4 a_DirectionTime;\r\nattribute vec4 a_StartColor;\r\nattribute vec3 a_StartSize;\r\nattribute vec3 a_StartRotation0;\r\nattribute float a_StartSpeed;\r\n#if defined(COLOROVERLIFETIME)||defined(RANDOMCOLOROVERLIFETIME)||defined(SIZEOVERLIFETIMERANDOMCURVES)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\r\n attribute vec4 a_Random0;\r\n#endif\r\n#if defined(TEXTURESHEETANIMATIONRANDOMCURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n attribute vec4 a_Random1;\r\n#endif\r\nattribute vec3 a_SimulationWorldPostion;\r\nattribute vec4 a_SimulationWorldRotation;\r\n\r\nvarying float v_Discard;\r\nvarying vec4 v_Color;\r\n#ifdef DIFFUSEMAP\r\n\tvarying vec2 v_TextureCoordinate;\r\n#endif\r\n\r\nuniform float u_CurrentTime;\r\nuniform vec3 u_Gravity;\r\n\r\nuniform vec3 u_WorldPosition;\r\nuniform vec4 u_WorldRotation;\r\nuniform bool u_ThreeDStartRotation;\r\nuniform int u_ScalingMode;\r\nuniform vec3 u_PositionScale;\r\nuniform vec3 u_SizeScale;\r\nuniform mat4 u_View;\r\nuniform mat4 u_Projection;\r\n\r\n#ifdef STRETCHEDBILLBOARD\r\n\tuniform vec3 u_CameraPos;\r\n#endif\r\nuniform vec3 u_CameraDirection;//TODO:只有几种广告牌模式需要用\r\nuniform vec3 u_CameraUp;\r\n\r\nuniform float u_StretchedBillboardLengthScale;\r\nuniform float u_StretchedBillboardSpeedScale;\r\nuniform int u_SimulationSpace;\r\n\r\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n uniform int u_VOLSpaceType;\r\n#endif\r\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)\r\n uniform vec3 u_VOLVelocityConst;\r\n#endif\r\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n uniform vec2 u_VOLVelocityGradientX[4];//x为key,y为速度\r\n uniform vec2 u_VOLVelocityGradientY[4];//x为key,y为速度\r\n uniform vec2 u_VOLVelocityGradientZ[4];//x为key,y为速度\r\n#endif\r\n#ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\r\n uniform vec3 u_VOLVelocityConstMax;\r\n#endif\r\n#ifdef VELOCITYOVERLIFETIMERANDOMCURVE\r\n uniform vec2 u_VOLVelocityGradientMaxX[4];//x为key,y为速度\r\n uniform vec2 u_VOLVelocityGradientMaxY[4];//x为key,y为速度\r\n uniform vec2 u_VOLVelocityGradientMaxZ[4];//x为key,y为速度\r\n#endif\r\n\r\n#ifdef COLOROVERLIFETIME\r\n uniform vec4 u_ColorOverLifeGradientColors[4];//x为key,yzw为Color\r\n uniform vec2 u_ColorOverLifeGradientAlphas[4];//x为key,y为Alpha\r\n#endif\r\n#ifdef RANDOMCOLOROVERLIFETIME\r\n uniform vec4 u_ColorOverLifeGradientColors[4];//x为key,yzw为Color\r\n uniform vec2 u_ColorOverLifeGradientAlphas[4];//x为key,y为Alpha\r\n uniform vec4 u_MaxColorOverLifeGradientColors[4];//x为key,yzw为Color\r\n uniform vec2 u_MaxColorOverLifeGradientAlphas[4];//x为key,y为Alpha\r\n#endif\r\n\r\n\r\n#if defined(SIZEOVERLIFETIMECURVE)||defined(SIZEOVERLIFETIMERANDOMCURVES)\r\n uniform vec2 u_SOLSizeGradient[4];//x为key,y为尺寸\r\n#endif\r\n#ifdef SIZEOVERLIFETIMERANDOMCURVES\r\n uniform vec2 u_SOLSizeGradientMax[4];//x为key,y为尺寸\r\n#endif\r\n#if defined(SIZEOVERLIFETIMECURVESEPERATE)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)\r\n uniform vec2 u_SOLSizeGradientX[4];//x为key,y为尺寸\r\n uniform vec2 u_SOLSizeGradientY[4];//x为key,y为尺寸\r\n uniform vec2 u_SOLSizeGradientZ[4];//x为key,y为尺寸\r\n#endif\r\n#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\r\n uniform vec2 u_SOLSizeGradientMaxX[4];//x为key,y为尺寸\r\n uniform vec2 u_SOLSizeGradientMaxY[4];//x为key,y为尺寸\r\n uniform vec2 u_SOLSizeGradientMaxZ[4];//x为key,y为尺寸\r\n#endif\r\n\r\n\r\n#ifdef ROTATIONOVERLIFETIME\r\n #if defined(ROTATIONOVERLIFETIMECONSTANT)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)\r\n uniform float u_ROLAngularVelocityConst;\r\n #endif\r\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n uniform float u_ROLAngularVelocityConstMax;\r\n #endif\r\n #if defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\r\n uniform vec2 u_ROLAngularVelocityGradient[4];//x为key,y为旋转\r\n #endif\r\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n uniform vec2 u_ROLAngularVelocityGradientMax[4];//x为key,y为旋转\r\n #endif\r\n#endif\r\n#ifdef ROTATIONOVERLIFETIMESEPERATE\r\n #if defined(ROTATIONOVERLIFETIMECONSTANT)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)\r\n uniform vec3 u_ROLAngularVelocityConstSeprarate;\r\n #endif\r\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n uniform vec3 u_ROLAngularVelocityConstMaxSeprarate;\r\n #endif\r\n #if defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\r\n uniform vec2 u_ROLAngularVelocityGradientX[4];\r\n uniform vec2 u_ROLAngularVelocityGradientY[4];\r\n uniform vec2 u_ROLAngularVelocityGradientZ[4];\r\n #endif\r\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n uniform vec2 u_ROLAngularVelocityGradientMaxX[4];\r\n uniform vec2 u_ROLAngularVelocityGradientMaxY[4];\r\n uniform vec2 u_ROLAngularVelocityGradientMaxZ[4];\r\n\tuniform vec2 u_ROLAngularVelocityGradientMaxW[4];\r\n #endif\r\n#endif\r\n\r\n#if defined(TEXTURESHEETANIMATIONCURVE)||defined(TEXTURESHEETANIMATIONRANDOMCURVE)\r\n uniform float u_TSACycles;\r\n uniform vec2 u_TSASubUVLength;\r\n uniform vec2 u_TSAGradientUVs[4];//x为key,y为frame\r\n#endif\r\n#ifdef TEXTURESHEETANIMATIONRANDOMCURVE\r\n uniform vec2 u_TSAMaxGradientUVs[4];//x为key,y为frame\r\n#endif\r\n\r\n#ifdef FOG\r\n\t//varying vec3 v_PositionWorld;\r\n#endif\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\nvec3 rotationByEuler(in vec3 vector,in vec3 rot)\r\n{\r\n\tfloat halfRoll = rot.z * 0.5;\r\n float halfPitch = rot.x * 0.5;\r\n\tfloat halfYaw = rot.y * 0.5;\r\n\r\n\tfloat sinRoll = sin(halfRoll);\r\n\tfloat cosRoll = cos(halfRoll);\r\n\tfloat sinPitch = sin(halfPitch);\r\n\tfloat cosPitch = cos(halfPitch);\r\n\tfloat sinYaw = sin(halfYaw);\r\n\tfloat cosYaw = cos(halfYaw);\r\n\r\n\tfloat quaX = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);\r\n\tfloat quaY = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);\r\n\tfloat quaZ = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);\r\n\tfloat quaW = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);\r\n\t\r\n\t//vec4 q=vec4(quaX,quaY,quaZ,quaW);\r\n\t//vec3 temp = cross(q.xyz, vector) + q.w * vector;\r\n\t//return (cross(temp, -q.xyz) + dot(q.xyz,vector) * q.xyz + q.w * temp);\r\n\t\r\n\tfloat x = quaX + quaX;\r\n float y = quaY + quaY;\r\n float z = quaZ + quaZ;\r\n float wx = quaW * x;\r\n float wy = quaW * y;\r\n float wz = quaW * z;\r\n\tfloat xx = quaX * x;\r\n float xy = quaX * y;\r\n\tfloat xz = quaX * z;\r\n float yy = quaY * y;\r\n float yz = quaY * z;\r\n float zz = quaZ * z;\r\n\r\n return vec3(((vector.x * ((1.0 - yy) - zz)) + (vector.y * (xy - wz))) + (vector.z * (xz + wy)),\r\n ((vector.x * (xy + wz)) + (vector.y * ((1.0 - xx) - zz))) + (vector.z * (yz - wx)),\r\n ((vector.x * (xz - wy)) + (vector.y * (yz + wx))) + (vector.z * ((1.0 - xx) - yy)));\r\n\t\r\n}\r\n\r\n//假定axis已经归一化\r\nvec3 rotationByAxis(in vec3 vector,in vec3 axis, in float angle)\r\n{\r\n\tfloat halfAngle = angle * 0.5;\r\n\tfloat sin = sin(halfAngle);\r\n\t\r\n\tfloat quaX = axis.x * sin;\r\n\tfloat quaY = axis.y * sin;\r\n\tfloat quaZ = axis.z * sin;\r\n\tfloat quaW = cos(halfAngle);\r\n\t\r\n\t//vec4 q=vec4(quaX,quaY,quaZ,quaW);\r\n\t//vec3 temp = cross(q.xyz, vector) + q.w * vector;\r\n\t//return (cross(temp, -q.xyz) + dot(q.xyz,vector) * q.xyz + q.w * temp);\r\n\t\r\n\tfloat x = quaX + quaX;\r\n float y = quaY + quaY;\r\n float z = quaZ + quaZ;\r\n float wx = quaW * x;\r\n float wy = quaW * y;\r\n float wz = quaW * z;\r\n\tfloat xx = quaX * x;\r\n float xy = quaX * y;\r\n\tfloat xz = quaX * z;\r\n float yy = quaY * y;\r\n float yz = quaY * z;\r\n float zz = quaZ * z;\r\n\r\n return vec3(((vector.x * ((1.0 - yy) - zz)) + (vector.y * (xy - wz))) + (vector.z * (xz + wy)),\r\n ((vector.x * (xy + wz)) + (vector.y * ((1.0 - xx) - zz))) + (vector.z * (yz - wx)),\r\n ((vector.x * (xz - wy)) + (vector.y * (yz + wx))) + (vector.z * ((1.0 - xx) - yy)));\r\n\t\r\n}\r\n\r\nvec3 rotationByQuaternions(in vec3 v,in vec4 q) \r\n{\r\n\treturn v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\r\n}\r\n\r\n \r\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)||defined(SIZEOVERLIFETIMECURVE)||defined(SIZEOVERLIFETIMECURVESEPERATE)||defined(SIZEOVERLIFETIMERANDOMCURVES)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)\r\nfloat getCurValueFromGradientFloat(in vec2 gradientNumbers[4],in float normalizedAge)\r\n{\r\n\tfloat curValue;\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec2 gradientNumber=gradientNumbers[i];\r\n\t\tfloat key=gradientNumber.x;\r\n\t\tif(key>=normalizedAge)\r\n\t\t{\r\n\t\t\tvec2 lastGradientNumber=gradientNumbers[i-1];\r\n\t\t\tfloat lastKey=lastGradientNumber.x;\r\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\r\n\t\t\tcurValue=mix(lastGradientNumber.y,gradientNumber.y,age);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn curValue;\r\n}\r\n#endif\r\n\r\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)||defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\r\nfloat getTotalValueFromGradientFloat(in vec2 gradientNumbers[4],in float normalizedAge)\r\n{\r\n\tfloat totalValue=0.0;\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec2 gradientNumber=gradientNumbers[i];\r\n\t\tfloat key=gradientNumber.x;\r\n\t\tvec2 lastGradientNumber=gradientNumbers[i-1];\r\n\t\tfloat lastValue=lastGradientNumber.y;\r\n\t\t\r\n\t\tif(key>=normalizedAge){\r\n\t\t\tfloat lastKey=lastGradientNumber.x;\r\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\r\n\t\t\ttotalValue+=(lastValue+mix(lastValue,gradientNumber.y,age))/2.0*a_ShapePositionStartLifeTime.w*(normalizedAge-lastKey);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\telse{\r\n\t\t\ttotalValue+=(lastValue+gradientNumber.y)/2.0*a_ShapePositionStartLifeTime.w*(key-lastGradientNumber.x);\r\n\t\t}\r\n\t}\r\n\treturn totalValue;\r\n}\r\n#endif\r\n\r\n#if defined(COLOROVERLIFETIME)||defined(RANDOMCOLOROVERLIFETIME)\r\nvec4 getColorFromGradient(in vec2 gradientAlphas[4],in vec4 gradientColors[4],in float normalizedAge)\r\n{\r\n\tvec4 overTimeColor;\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec2 gradientAlpha=gradientAlphas[i];\r\n\t\tfloat alphaKey=gradientAlpha.x;\r\n\t\tif(alphaKey>=normalizedAge)\r\n\t\t{\r\n\t\t\tvec2 lastGradientAlpha=gradientAlphas[i-1];\r\n\t\t\tfloat lastAlphaKey=lastGradientAlpha.x;\r\n\t\t\tfloat age=(normalizedAge-lastAlphaKey)/(alphaKey-lastAlphaKey);\r\n\t\t\toverTimeColor.a=mix(lastGradientAlpha.y,gradientAlpha.y,age);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\t\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec4 gradientColor=gradientColors[i];\r\n\t\tfloat colorKey=gradientColor.x;\r\n\t\tif(colorKey>=normalizedAge)\r\n\t\t{\r\n\t\t\tvec4 lastGradientColor=gradientColors[i-1];\r\n\t\t\tfloat lastColorKey=lastGradientColor.x;\r\n\t\t\tfloat age=(normalizedAge-lastColorKey)/(colorKey-lastColorKey);\r\n\t\t\toverTimeColor.rgb=mix(gradientColors[i-1].yzw,gradientColor.yzw,age);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn overTimeColor;\r\n}\r\n#endif\r\n\r\n\r\n#if defined(TEXTURESHEETANIMATIONCURVE)||defined(TEXTURESHEETANIMATIONRANDOMCURVE)\r\nfloat getFrameFromGradient(in vec2 gradientFrames[4],in float normalizedAge)\r\n{\r\n\tfloat overTimeFrame;\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec2 gradientFrame=gradientFrames[i];\r\n\t\tfloat key=gradientFrame.x;\r\n\t\tif(key>=normalizedAge)\r\n\t\t{\r\n\t\t\tvec2 lastGradientFrame=gradientFrames[i-1];\r\n\t\t\tfloat lastKey=lastGradientFrame.x;\r\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\r\n\t\t\toverTimeFrame=mix(lastGradientFrame.y,gradientFrame.y,age);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn floor(overTimeFrame);\r\n}\r\n#endif\r\n\r\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\nvec3 computeParticleLifeVelocity(in float normalizedAge)\r\n{\r\n vec3 outLifeVelocity;\r\n #ifdef VELOCITYOVERLIFETIMECONSTANT\r\n\t outLifeVelocity=u_VOLVelocityConst; \r\n #endif\r\n #ifdef VELOCITYOVERLIFETIMECURVE\r\n outLifeVelocity= vec3(getCurValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge));\r\n #endif\r\n #ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\r\n\t outLifeVelocity=mix(u_VOLVelocityConst,u_VOLVelocityConstMax,vec3(a_Random1.y,a_Random1.z,a_Random1.w)); \r\n #endif\r\n #ifdef VELOCITYOVERLIFETIMERANDOMCURVE\r\n outLifeVelocity=vec3(mix(getCurValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxX,normalizedAge),a_Random1.y),\r\n\t mix(getCurValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxY,normalizedAge),a_Random1.z),\r\n\t\t\t\t\t mix(getCurValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxZ,normalizedAge),a_Random1.w));\r\n #endif\r\n\t\t\t\t\t\r\n return outLifeVelocity;\r\n} \r\n#endif\r\n\r\nvec3 computeParticlePosition(in vec3 startVelocity, in vec3 lifeVelocity,in float age,in float normalizedAge,vec3 gravityVelocity,vec4 worldRotation)\r\n{\r\n vec3 startPosition;\r\n vec3 lifePosition;\r\n #if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n\t#ifdef VELOCITYOVERLIFETIMECONSTANT\r\n\t\t startPosition=startVelocity*age;\r\n\t\t lifePosition=lifeVelocity*age;\r\n\t#endif\r\n\t#ifdef VELOCITYOVERLIFETIMECURVE\r\n\t\t startPosition=startVelocity*age;\r\n\t\t lifePosition=vec3(getTotalValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge));\r\n\t#endif\r\n\t#ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\r\n\t\t startPosition=startVelocity*age;\r\n\t\t lifePosition=lifeVelocity*age;\r\n\t#endif\r\n\t#ifdef VELOCITYOVERLIFETIMERANDOMCURVE\r\n\t\t startPosition=startVelocity*age;\r\n\t\t lifePosition=vec3(mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxX,normalizedAge),a_Random1.y)\r\n\t ,mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxY,normalizedAge),a_Random1.z)\r\n\t ,mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxZ,normalizedAge),a_Random1.w));\r\n\t#endif\r\n\t\r\n\tvec3 finalPosition;\r\n\tif(u_VOLSpaceType==0){\r\n\t if(u_ScalingMode!=2)\r\n\t finalPosition =rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition),worldRotation);\r\n\t else\r\n\t finalPosition =rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition,worldRotation);\r\n\t}\r\n\telse{\r\n\t if(u_ScalingMode!=2)\r\n\t finalPosition = rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition),worldRotation)+lifePosition;\r\n\t else\r\n\t finalPosition = rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation)+lifePosition;\r\n\t}\r\n #else\r\n\t startPosition=startVelocity*age;\r\n\t vec3 finalPosition;\r\n\t if(u_ScalingMode!=2)\r\n\t\t\tfinalPosition = rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition),worldRotation);\r\n\t else\r\n\t \tfinalPosition = rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation);\r\n #endif\r\n \r\n if(u_SimulationSpace==0)\r\n finalPosition=finalPosition+a_SimulationWorldPostion;\r\n else if(u_SimulationSpace==1) \r\n finalPosition=finalPosition+u_WorldPosition;\r\n \r\n finalPosition+=0.5*gravityVelocity*age;\r\n \r\n return finalPosition;\r\n}\r\n\r\n\r\nvec4 computeParticleColor(in vec4 color,in float normalizedAge)\r\n{\r\n\t#ifdef COLOROVERLIFETIME\r\n\t color*=getColorFromGradient(u_ColorOverLifeGradientAlphas,u_ColorOverLifeGradientColors,normalizedAge);\r\n\t#endif\r\n\t\r\n\t#ifdef RANDOMCOLOROVERLIFETIME\r\n\t color*=mix(getColorFromGradient(u_ColorOverLifeGradientAlphas,u_ColorOverLifeGradientColors,normalizedAge),getColorFromGradient(u_MaxColorOverLifeGradientAlphas,u_MaxColorOverLifeGradientColors,normalizedAge),a_Random0.y);\r\n\t#endif\r\n\r\n return color;\r\n}\r\n\r\nvec2 computeParticleSizeBillbard(in vec2 size,in float normalizedAge)\r\n{\r\n\t#ifdef SIZEOVERLIFETIMECURVE\r\n\t\tsize*=getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge);\r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVES\r\n\t size*=mix(getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMax,normalizedAge),a_Random0.z); \r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMECURVESEPERATE\r\n\t\tsize*=vec2(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge));\r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\r\n\t size*=vec2(mix(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxX,normalizedAge),a_Random0.z)\r\n\t ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxY,normalizedAge),a_Random0.z));\r\n\t#endif\r\n\treturn size;\r\n}\r\n\r\n#ifdef RENDERMODE_MESH\r\nvec3 computeParticleSizeMesh(in vec3 size,in float normalizedAge)\r\n{\r\n\t#ifdef SIZEOVERLIFETIMECURVE\r\n\t\tsize*=getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge);\r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVES\r\n\t size*=mix(getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMax,normalizedAge),a_Random0.z); \r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMECURVESEPERATE\r\n\t\tsize*=vec3(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientZ,normalizedAge));\r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\r\n\t size*=vec3(mix(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxX,normalizedAge),a_Random0.z)\r\n\t ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxY,normalizedAge),a_Random0.z)\r\n\t\t,mix(getCurValueFromGradientFloat(u_SOLSizeGradientZ,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxZ,normalizedAge),a_Random0.z));\r\n\t#endif\r\n\treturn size;\r\n}\r\n#endif\r\n\r\nfloat computeParticleRotationFloat(in float rotation,in float age,in float normalizedAge)\r\n{ \r\n\t#ifdef ROTATIONOVERLIFETIME\r\n\t\t#ifdef ROTATIONOVERLIFETIMECONSTANT\r\n\t\t\tfloat ageRot=u_ROLAngularVelocityConst*age;\r\n\t rotation+=ageRot;\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\r\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;\r\n\t rotation+=ageRot;\r\n\t #endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\r\n\t\t#endif\r\n\t#endif\r\n\t#ifdef ROTATIONOVERLIFETIMESEPERATE\r\n\t\t#ifdef ROTATIONOVERLIFETIMECONSTANT\r\n\t\t\tfloat ageRot=u_ROLAngularVelocityConstSeprarate.z*age;\r\n\t rotation+=ageRot;\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\r\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge);\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConstSeprarate.z,u_ROLAngularVelocityConstMaxSeprarate.z,a_Random0.w)*age;\r\n\t rotation+=ageRot;\r\n\t #endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxZ,normalizedAge),a_Random0.w));\r\n\t\t#endif\r\n\t#endif\r\n\treturn rotation;\r\n}\r\n\r\n#if defined(RENDERMODE_MESH)&&(defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE))\r\nvec3 computeParticleRotationVec3(in vec3 rotation,in float age,in float normalizedAge)\r\n{ \r\n\t#ifdef ROTATIONOVERLIFETIME\r\n\t#ifdef ROTATIONOVERLIFETIMECONSTANT\r\n\t\t\tfloat ageRot=u_ROLAngularVelocityConst*age;\r\n\t rotation+=ageRot;\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\r\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;\r\n\t rotation+=ageRot;\r\n\t #endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\r\n\t\t#endif\r\n\t#endif\r\n\t#ifdef ROTATIONOVERLIFETIMESEPERATE\r\n\t\t#ifdef ROTATIONOVERLIFETIMECONSTANT\r\n\t\t\tvec3 ageRot=u_ROLAngularVelocityConstSeprarate*age;\r\n\t rotation+=ageRot;\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\r\n\t\t\trotation+=vec3(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge));\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n\t\t\tvec3 ageRot=mix(u_ROLAngularVelocityConstSeprarate,u_ROLAngularVelocityConstMaxSeprarate,a_Random0.w)*age;\r\n\t rotation+=ageRot;\r\n\t #endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n\t\t\trotation+=vec3(mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxX,normalizedAge),a_Random0.w)\r\n\t ,mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxY,normalizedAge),a_Random0.w)\r\n\t ,mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxZ,normalizedAge),a_Random0.w));\r\n\t\t#endif\r\n\t#endif\r\n\treturn rotation;\r\n}\r\n#endif\r\n\r\nvec2 computeParticleUV(in vec2 uv,in float normalizedAge)\r\n{ \r\n\t#ifdef TEXTURESHEETANIMATIONCURVE\r\n\t\tfloat cycleNormalizedAge=normalizedAge*u_TSACycles;\r\n\t\tfloat frame=getFrameFromGradient(u_TSAGradientUVs,cycleNormalizedAge-floor(cycleNormalizedAge));\r\n\t\tfloat totalULength=frame*u_TSASubUVLength.x;\r\n\t\tfloat floorTotalULength=floor(totalULength);\r\n\t uv.x+=totalULength-floorTotalULength;\r\n\t\tuv.y+=floorTotalULength*u_TSASubUVLength.y;\r\n #endif\r\n\t#ifdef TEXTURESHEETANIMATIONRANDOMCURVE\r\n\t\tfloat cycleNormalizedAge=normalizedAge*u_TSACycles;\r\n\t\tfloat uvNormalizedAge=cycleNormalizedAge-floor(cycleNormalizedAge);\r\n\t float frame=floor(mix(getFrameFromGradient(u_TSAGradientUVs,uvNormalizedAge),getFrameFromGradient(u_TSAMaxGradientUVs,uvNormalizedAge),a_Random1.x));\r\n\t\tfloat totalULength=frame*u_TSASubUVLength.x;\r\n\t\tfloat floorTotalULength=floor(totalULength);\r\n\t uv.x+=totalULength-floorTotalULength;\r\n\t\tuv.y+=floorTotalULength*u_TSASubUVLength.y;\r\n #endif\r\n\treturn uv;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tfloat age = u_CurrentTime - a_DirectionTime.w;\r\n\tfloat normalizedAge = age/a_ShapePositionStartLifeTime.w;\r\n\tvec3 lifeVelocity;\r\n\tif(normalizedAge<1.0){ \r\n\tvec3 startVelocity=a_DirectionTime.xyz*a_StartSpeed;\r\n\t#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n\t\tlifeVelocity= computeParticleLifeVelocity(normalizedAge);//计算粒子生命周期速度\r\n\t#endif \r\n\tvec3 gravityVelocity=u_Gravity*age;\r\n\t\r\n\tvec4 worldRotation;\r\n\tif(u_SimulationSpace==0)\r\n\t\tworldRotation=a_SimulationWorldRotation;\r\n\telse\r\n\t\tworldRotation=u_WorldRotation;\r\n\t\r\n\tvec3 center=computeParticlePosition(startVelocity, lifeVelocity, age, normalizedAge,gravityVelocity,worldRotation);//计算粒子位置\r\n \r\n \r\n #ifdef SPHERHBILLBOARD\r\n\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\r\n vec3 cameraUpVector =normalize(u_CameraUp);//TODO:是否外面归一化\r\n vec3 sideVector = normalize(cross(u_CameraDirection,cameraUpVector));\r\n vec3 upVector = normalize(cross(sideVector,u_CameraDirection));\r\n\t corner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\r\n\t\t#if defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE)\r\n\t\t\tif(u_ThreeDStartRotation){\r\n\t\t\t\tvec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z,age,normalizedAge));\r\n\t\t\t\tcenter += u_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,rotation);\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\r\n\t\t\t\tfloat c = cos(rot);\r\n\t\t\t\tfloat s = sin(rot);\r\n\t\t\t\tmat2 rotation= mat2(c, -s, s, c);\r\n\t\t\t\tcorner=rotation*corner;\r\n\t\t\t\tcenter += u_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);\r\n\t\t\t}\r\n\t\t#else\r\n\t\t\tif(u_ThreeDStartRotation){\r\n\t\t\t\tcenter += u_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,a_StartRotation0);\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\tfloat c = cos(a_StartRotation0.x);\r\n\t\t\t\tfloat s = sin(a_StartRotation0.x);\r\n\t\t\t\tmat2 rotation= mat2(c, -s, s, c);\r\n\t\t\t\tcorner=rotation*corner;\r\n\t\t\t\tcenter += u_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);\r\n\t\t\t}\r\n\t\t#endif\r\n #endif\r\n \r\n #ifdef STRETCHEDBILLBOARD\r\n\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\r\n\tvec3 velocity;\r\n\t#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n\t if(u_VOLSpaceType==0)\r\n\t\t velocity=rotationByQuaternions(u_SizeScale*(startVelocity+lifeVelocity),worldRotation)+gravityVelocity;\r\n\t else\r\n\t\t velocity=rotationByQuaternions(u_SizeScale*startVelocity,worldRotation)+lifeVelocity+gravityVelocity;\r\n #else\r\n\t velocity= rotationByQuaternions(u_SizeScale*startVelocity,worldRotation)+gravityVelocity;\r\n #endif\t\r\n\t\tvec3 cameraUpVector = normalize(velocity);\r\n\t\tvec3 direction = normalize(center-u_CameraPos);\r\n vec3 sideVector = normalize(cross(direction,normalize(velocity)));\r\n\t\t\r\n\t\tsideVector=u_SizeScale.xzy*sideVector;\r\n\t\tcameraUpVector=length(vec3(u_SizeScale.x,0.0,0.0))*cameraUpVector;\r\n\t\t\r\n\t vec2 size=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\r\n\t\t\r\n\t const mat2 rotaionZHalfPI=mat2(0.0, -1.0, 1.0, 0.0);\r\n\t corner=rotaionZHalfPI*corner;\r\n\t corner.y=corner.y-abs(corner.y);\r\n\t\t\r\n\t float speed=length(velocity);//TODO:\r\n\t center +=sign(u_SizeScale.x)*(sign(u_StretchedBillboardLengthScale)*size.x*corner.x*sideVector+(speed*u_StretchedBillboardSpeedScale+size.y*u_StretchedBillboardLengthScale)*corner.y*cameraUpVector);\r\n #endif\r\n \r\n #ifdef HORIZONTALBILLBOARD\r\n\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\r\n const vec3 cameraUpVector=vec3(0.0,0.0,1.0);\r\n\t const vec3 sideVector = vec3(-1.0,0.0,0.0);\r\n\t\t\r\n\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\r\n float c = cos(rot);\r\n float s = sin(rot);\r\n mat2 rotation= mat2(c, -s, s, c);\r\n\t corner=rotation*corner*cos(0.78539816339744830961566084581988);//TODO:临时缩小cos45,不确定U3D原因\r\n\t\tcorner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\r\n center +=u_SizeScale.xzy*(corner.x*sideVector+ corner.y*cameraUpVector);\r\n #endif\r\n \r\n #ifdef VERTICALBILLBOARD\r\n\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\r\n const vec3 cameraUpVector =vec3(0.0,1.0,0.0);\r\n vec3 sideVector = normalize(cross(u_CameraDirection,cameraUpVector));\r\n\t\t\r\n\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\r\n float c = cos(rot);\r\n float s = sin(rot);\r\n mat2 rotation= mat2(c, -s, s, c);\r\n\t corner=rotation*corner*cos(0.78539816339744830961566084581988);//TODO:临时缩小cos45,不确定U3D原因\r\n\t\tcorner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\r\n center +=u_SizeScale.xzy*(corner.x*sideVector+ corner.y*cameraUpVector);\r\n #endif\r\n \r\n #ifdef RENDERMODE_MESH\r\n\t vec3 size=computeParticleSizeMesh(a_StartSize,normalizedAge);\r\n\t\t#if defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE)\r\n\t\t\tif(u_ThreeDStartRotation){\r\n\t\t\t\tvec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z, age,normalizedAge));\r\n\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByEuler(a_MeshPosition*size,rotation),worldRotation);\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\t#ifdef ROTATIONOVERLIFETIME\r\n\t\t\t\t\tfloat angle=computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\r\n\t\t\t\t\tif(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){\r\n\t\t\t\t\t\tcenter+= (rotationByQuaternions(rotationByAxis(u_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),angle),worldRotation));//已验证\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\t#ifdef SHAPE\r\n\t\t\t\t\t\t\tcenter+= u_SizeScale.xzy*(rotationByQuaternions(rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),angle),worldRotation));\r\n\t\t\t\t\t\t#else\r\n\t\t\t\t\t\t\tif(u_SimulationSpace==0)\r\n\t\t\t\t\t\t\t\tcenter+=rotationByAxis(u_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle);//已验证\r\n\t\t\t\t\t\t\telse if(u_SimulationSpace==1)\r\n\t\t\t\t\t\t\t\tcenter+=rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle),worldRotation);//已验证\r\n\t\t\t\t\t\t#endif\r\n\t\t\t\t\t}\r\n\t\t\t\t#endif\r\n\t\t\t\t#ifdef ROTATIONOVERLIFETIMESEPERATE\r\n\t\t\t\t\t//TODO:是否应合并if(u_ThreeDStartRotation)分支代码,待测试\r\n\t\t\t\t\tvec3 angle=computeParticleRotationVec3(vec3(0.0,0.0,-a_StartRotation0.x), age,normalizedAge);\r\n\t\t\t\t\tcenter+= (rotationByQuaternions(rotationByEuler(u_SizeScale*a_MeshPosition*size,vec3(angle.x,angle.y,angle.z)),worldRotation));//已验证\r\n\t\t\t\t#endif\t\t\r\n\t\t\t}\r\n\t\t#else\r\n\t\t\tif(u_ThreeDStartRotation){\r\n\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByEuler(a_MeshPosition*size,a_StartRotation0),worldRotation);//已验证\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\tif(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){\r\n\t\t\t\t\tif(u_SimulationSpace==0)\r\n\t\t\t\t\t\tcenter+= rotationByAxis(u_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x);\r\n\t\t\t\t\telse if(u_SimulationSpace==1)\r\n\t\t\t\t\t\tcenter+= (rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x),worldRotation));//已验证\r\n\t\t\t\t}\r\n\t\t\t\telse{\r\n\t\t\t\t\t#ifdef SHAPE\r\n\t\t\t\t\t\tif(u_SimulationSpace==0)\r\n\t\t\t\t\t\t\tcenter+= u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x);\r\n\t\t\t\t\t\telse if(u_SimulationSpace==1)\r\n\t\t\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x),worldRotation);\t\r\n\t\t\t\t\t#else\r\n\t\t\t\t\t\tif(u_SimulationSpace==0)\r\n\t\t\t\t\t\t\tcenter+= rotationByAxis(u_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x);\r\n\t\t\t\t\t\telse if(u_SimulationSpace==1)\r\n\t\t\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x),worldRotation);//已验证\r\n\t\t\t\t\t#endif\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t#endif\r\n\t\tv_MeshColor=a_MeshColor;\r\n #endif\r\n \r\n gl_Position=u_Projection*u_View*vec4(center,1.0);\r\n v_Color = computeParticleColor(a_StartColor, normalizedAge);\r\n\t#ifdef DIFFUSEMAP\r\n\t\t#if defined(SPHERHBILLBOARD)||defined(STRETCHEDBILLBOARD)||defined(HORIZONTALBILLBOARD)||defined(VERTICALBILLBOARD)\r\n\t\t\tv_TextureCoordinate =computeParticleUV(a_CornerTextureCoordinate.zw, normalizedAge);\r\n\t\t#endif\r\n\t\t#ifdef RENDERMODE_MESH\r\n\t\t\tv_TextureCoordinate =computeParticleUV(a_MeshTextureCoordinate, normalizedAge);\r\n\t\t#endif\r\n\t\t\r\n\t\t#ifdef TILINGOFFSET\r\n\t\t\tv_TextureCoordinate=vec2(v_TextureCoordinate.x,1.0-v_TextureCoordinate.y)*u_TilingOffset.xy+vec2(u_TilingOffset.z,-u_TilingOffset.w);//需要特殊处理\r\n\t\t\tv_TextureCoordinate=vec2(v_TextureCoordinate.x,1.0-v_TextureCoordinate.y);//需要特殊处理\r\n\t\t#endif\r\n\t#endif\r\n v_Discard=0.0;\r\n\t \r\n\t#ifdef FOG\r\n\t\t//v_PositionWorld=center;\r\n\t#endif\r\n }\r\n else\r\n\t{\r\n\t\tv_Discard=1.0;\r\n\t}\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n\r\n";
  22356. var BRDFGLSL = "struct LayaGI\r\n{\r\n\tvec3 diffuse;\r\n\tvec3 specular;\r\n};\r\n\r\nvec4 LayaAirBRDF(in vec3 diffuseColor, in vec3 specularColor, in float oneMinusReflectivity, in float smoothness, in vec3 normal, in vec3 viewDir, in vec3 lightDir, in vec3 lightColor, in LayaGI gi)\r\n{\r\n\tfloat perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness);\r\n\tvec3 halfDir = SafeNormalize(viewDir - lightDir);\r\n\t\r\n\tfloat nv = abs(dot(normal, viewDir));\r\n\t\r\n\tfloat nl = clamp(dot(normal, -lightDir), 0.0, 1.0);\r\n\tfloat nh = clamp(dot(normal, halfDir), 0.0, 1.0);\r\n\tfloat lv = clamp(dot(lightDir, viewDir), 0.0, 1.0);\r\n\tfloat lh = clamp(dot(lightDir, -halfDir), 0.0, 1.0);\r\n\t\r\n\tfloat diffuseTerm = DisneyDiffuse(nv, nl, lh, perceptualRoughness) * nl;\r\n\t\r\n\tfloat roughness = PerceptualRoughnessToRoughness(perceptualRoughness);\r\n\t\r\n\t//#if UNITY_BRDF_GGX\r\n\t // GGX with roughtness to 0 would mean no specular at all, using max(roughness, 0.002) here to match HDrenderloop roughtness remapping.\r\n\troughness = max(roughness,0.014);\r\n\tfloat V = SmithJointGGXVisibilityTerm(nl, nv, roughness);\r\n\tfloat D = GGXTerm(nh, roughness);\r\n\t\r\n\tfloat specularTerm = V * D * PI;\r\n\t\r\n\tspecularTerm = sqrt(max(0.0001, specularTerm));\r\n\tspecularTerm = max(0.0, specularTerm * nl);\r\n\t\r\n\tfloat surfaceReduction = 1.0 - 0.28 * roughness * perceptualRoughness;\r\n\tfloat grazingTerm = clamp(smoothness + (1.0 - oneMinusReflectivity), 0.0, 1.0);\r\n\t\r\n\tvec4 color;\r\n\tcolor.rgb = diffuseColor * (gi.diffuse+lightColor * diffuseTerm) \r\n\t\t\t + specularTerm * lightColor * FresnelTerm (specularColor, lh);\r\n\t\t\t //+ surfaceReduction * gi.specular * FresnelLerp(specularColor, vec3(grazingTerm), nv);\r\n\t\r\n\treturn color;\r\n}\r\nvec4 LayaAirStandardReflect(in vec4 albedoColor,in float metallic,in float smoothness,in LayaGI gi)\r\n{\r\n\tvec3 diffuseColor;\r\n\tvec3 specularColor;\r\n\tfloat alpha;\r\n\tfloat oneMinusReflectivity;\r\n\tdiffuseColor = DiffuseAndSpecularFromMetallic (albedoColor.rgb, metallic, specularColor, oneMinusReflectivity);\r\n\tdiffuseColor = LayaPreMultiplyAlpha(diffuseColor, albedoColor.a, oneMinusReflectivity, alpha);\r\n\tfloat perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness);\r\n\tfloat roughness = PerceptualRoughnessToRoughness(perceptualRoughness);\r\n\tfloat surfaceReduction = 1.0 - 0.28 * roughness * perceptualRoughness;\r\n\tvec4 color;\r\n\tcolor.rgb = surfaceReduction * gi.specular;\r\n\tcolor.a = alpha;\r\n\treturn color;\r\n\r\n}\r\n\r\nvec4 LayaAirSpecularReflect(in vec4 albedoColor,in vec3 specularColor,in float smoothness,in LayaGI gi)\r\n{\r\n\tfloat oneMinusReflectivity;\r\n\tvec3 diffuseColor;\r\n\tfloat alpha;\r\n\t\r\n\tdiffuseColor = EnergyConservationBetweenDiffuseAndSpecular (albedoColor.rgb, specularColor, oneMinusReflectivity);\r\n\t\r\n\tdiffuseColor = LayaPreMultiplyAlpha(diffuseColor, albedoColor.a, oneMinusReflectivity, alpha);\r\n\r\n\tfloat perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness);\r\n\tfloat roughness = PerceptualRoughnessToRoughness(perceptualRoughness);\r\n\tfloat surfaceReduction = 1.0 - 0.28 * roughness * perceptualRoughness;\r\n\tvec4 color;\r\n\tcolor.rgb = surfaceReduction * gi.specular;\r\n\tcolor.a = alpha;\r\n\treturn color;\r\n}";
  22357. var PBRSpecularLightingGLSL = "#include \"PBRUtils.glsl\"\r\n#include \"BRDF.glsl\"\r\n\r\nvec4 PBRSpecularLight(in vec4 albedoColor, in vec3 specularColor, in float smoothness, in vec3 normal, in vec3 viewDir, in vec3 lightDir, in vec3 lightColor, in LayaGI gi)\r\n{\r\n\tfloat oneMinusReflectivity;\r\n\tvec3 diffuseColor;\r\n\tfloat alpha;\r\n\t\r\n\tdiffuseColor = EnergyConservationBetweenDiffuseAndSpecular (albedoColor.rgb, specularColor, oneMinusReflectivity);\r\n\t\r\n\tdiffuseColor = LayaPreMultiplyAlpha(diffuseColor, albedoColor.a, oneMinusReflectivity, alpha);\r\n\t\r\n\tvec4 color = LayaAirBRDF(diffuseColor, specularColor, oneMinusReflectivity, smoothness, normal, viewDir, lightDir, lightColor, gi);\r\n\tcolor.a = alpha;\r\n\treturn color;\r\n}\r\n\r\nvec4 PBRSpecularDiectionLight (in vec4 albedoColor, in vec3 specularColor, in float smoothness, in vec3 normal, in vec3 viewDir, in DirectionLight light, in LayaGI gi)\r\n{\r\n\tvec3 lightVec = normalize(light.Direction);\r\n\treturn PBRSpecularLight(albedoColor, specularColor, smoothness, normal, viewDir, lightVec, light.Color, gi);\r\n}\r\n#ifdef POINTLIGHT\r\nvec4 PBRSpecularPointLight (in vec4 albedoColor, in vec3 specularColor, in float smoothness, in vec3 normal, in vec3 viewDir, in PointLight light, in vec3 pos, in LayaGI gi)\r\n{\r\n\tvec3 lightCoord = (u_PointLightMatrix * vec4(pos, 1.0)).xyz;\r\n\tfloat distance = dot(lightCoord, lightCoord);\r\n\tfloat attenuate = texture2D(u_RangeTexture, vec2(distance)).w;\r\n\tvec3 lightVec = normalize(pos - light.Position);\r\n\treturn PBRSpecularLight(albedoColor, specularColor, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\r\n}\r\n#endif\r\nvec4 PBRSpecularSpotLight (in vec4 albedoColor, in vec3 specularColor, in float smoothness, in vec3 normal, in vec3 viewDir, in SpotLight light, in vec3 pos, in LayaGI gi)\r\n{\r\n\tvec3 lightVec = pos - light.Position;\r\n\tvec3 normalLightVec = normalize(lightVec);\r\n\tvec2 cosAngles = cos(vec2(light.SpotAngle, light.SpotAngle*0.5) * 0.5);//ConeAttenuation\r\n\tfloat dl = dot(normalize(light.Direction), normalLightVec);\r\n\tdl *= smoothstep(cosAngles[0], cosAngles[1], dl);\r\n\tfloat attenuate = LayaAttenuation(lightVec, 1.0/light.Range) * dl;\r\n\treturn PBRSpecularLight(albedoColor, specularColor, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\r\n}\r\n\r\n//vec4 PBRStandardSpotLight1 (in vec4 albedoColor, in float metallic, in float smoothness, in vec3 normal, in vec3 viewDir, in SpotLight light, in vec3 pos, in LayaGI gi)\r\n//{\r\n//\tvec4 lightCoord = u_SpotLightMatrix * vec4(pos, 1.0);\r\n//\t\r\n//\tfloat distance = dot(lightCoord, lightCoord);\r\n//\tfloat attenuate = (lightCoord.z < 0.0) ? texture2D(u_RangeTexture, vec2(distance)).w : 0.0;\r\n//\t//float attenuate = (lightCoord.z < 0.0) ? texture2D(u_AngleTexture, vec2(lightCoord.x / lightCoord.w + 0.5, lightCoord.y / lightCoord.w + 0.5)).r * texture2D(u_RangeTexture, vec2(distance)).w : 0.0;\r\n//\t//vec2 _uv = vec2(pos.x * 180.0/(2.0 * pos.z) + 0.5, pos.y * 180.0/(2.0 * pos.z) + 0.5);\r\n//\tvec3 lightVec = normalize(pos - light.Position);\r\n//\treturn PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\r\n//}\r\n\r\nvec4 SpecularGloss(float albedoTextureAlpha, in vec2 uv0)\r\n{\r\n vec4 sg;\r\n\t\r\n\t#ifdef SPECULARTEXTURE\r\n\t\tvec4 specularTextureColor = texture2D(u_SpecularTexture, uv0);\r\n\t\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\t\tsg.rgb = specularTextureColor.rgb;\r\n\t\t\tsg.a = albedoTextureAlpha;\r\n\t\t#else\r\n\t\t\tsg = specularTextureColor;\r\n\t\t#endif\r\n\t\tsg.a *= u_smoothnessScale;\r\n\t#else\r\n\t\tsg.rgb = u_SpecularColor.rgb;\r\n\t\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\t\tsg.a = albedoTextureAlpha * u_smoothnessScale;\r\n\t\t#else\r\n\t\t\tsg.a = u_smoothness;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n return sg;\r\n}\r\n\r\n";
  22358. var PBRStandardLightingGLSL = "#include \"PBRUtils.glsl\"\r\n#include \"BRDF.glsl\"\r\n\r\nvec4 PBRStandardLight(in vec4 albedoColor, in float metallic, in float smoothness, in vec3 normal, in vec3 viewDir, in vec3 lightDir, in vec3 lightColor, in LayaGI gi)\r\n{\r\n\tfloat oneMinusReflectivity;\r\n\tvec3 diffuseColor;\r\n\tvec3 specularColor;\r\n\tfloat alpha;\r\n\t\r\n\tdiffuseColor = DiffuseAndSpecularFromMetallic (albedoColor.rgb, metallic, specularColor, oneMinusReflectivity);\r\n\t\r\n\tdiffuseColor = LayaPreMultiplyAlpha(diffuseColor, albedoColor.a, oneMinusReflectivity, alpha);\r\n\t\r\n\tvec4 color = LayaAirBRDF(diffuseColor, specularColor, oneMinusReflectivity, smoothness, normal, viewDir, lightDir, lightColor, gi);\r\n\tcolor.a = alpha;\r\n\treturn color;\r\n}\r\n\r\nvec4 PBRStandardDiectionLight (in vec4 albedoColor, in float metallic, in float smoothness, in vec3 normal, in vec3 viewDir, in DirectionLight light, in LayaGI gi)\r\n{\r\n\tvec3 lightVec = normalize(light.Direction);\r\n\treturn PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi);\r\n}\r\n#ifdef POINTLIGHT\r\nvec4 PBRStandardPointLight (in vec4 albedoColor, in float metallic, in float smoothness, in vec3 normal, in vec3 viewDir, in PointLight light, in vec3 pos, in LayaGI gi)\r\n{\r\n\tvec3 lightCoord = (u_PointLightMatrix * vec4(pos, 1.0)).xyz;\r\n\tfloat distance = dot(lightCoord, lightCoord);\r\n\tfloat attenuate = texture2D(u_RangeTexture, vec2(distance)).w;\r\n\tvec3 lightVec = normalize(pos - light.Position);\r\n\treturn PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\r\n}\r\n#endif\r\nvec4 PBRStandardSpotLight (in vec4 albedoColor, in float metallic, in float smoothness, in vec3 normal, in vec3 viewDir, in SpotLight light, in vec3 pos, in LayaGI gi)\r\n{\r\n\tvec3 lightVec = pos - light.Position;\r\n\tvec3 normalLightVec = normalize(lightVec);\r\n\tvec2 cosAngles = cos(vec2(light.SpotAngle, light.SpotAngle*0.5) * 0.5);//ConeAttenuation\r\n\tfloat dl = dot(normalize(light.Direction), normalLightVec);\r\n\tdl *= smoothstep(cosAngles[0], cosAngles[1], dl);\r\n\tfloat attenuate = LayaAttenuation(lightVec, 1.0/light.Range) * dl;\r\n\treturn PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\r\n}\r\n\r\n//vec4 PBRStandardSpotLight1 (in vec4 albedoColor, in float metallic, in float smoothness, in vec3 normal, in vec3 viewDir, in SpotLight light, in vec3 pos, in LayaGI gi)\r\n//{\r\n//\tvec4 lightCoord = u_SpotLightMatrix * vec4(pos, 1.0);\r\n//\t\r\n//\tfloat distance = dot(lightCoord, lightCoord);\r\n//\tfloat attenuate = (lightCoord.z < 0.0) ? texture2D(u_RangeTexture, vec2(distance)).w : 0.0;\r\n//\t//float attenuate = (lightCoord.z < 0.0) ? texture2D(u_AngleTexture, vec2(lightCoord.x / lightCoord.w + 0.5, lightCoord.y / lightCoord.w + 0.5)).r * texture2D(u_RangeTexture, vec2(distance)).w : 0.0;\r\n//\t//vec2 _uv = vec2(pos.x * 180.0/(2.0 * pos.z) + 0.5, pos.y * 180.0/(2.0 * pos.z) + 0.5);\r\n//\tvec3 lightVec = normalize(pos - light.Position);\r\n//\treturn PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\r\n//}\r\n\r\nvec2 MetallicGloss(in float albedoTextureAlpha, in vec2 uv0)\r\n{\r\n\tvec2 mg;\r\n\t\r\n\t#ifdef METALLICGLOSSTEXTURE\r\n\t\tvec4 metallicGlossTextureColor = texture2D(u_MetallicGlossTexture, uv0);\r\n\t\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\t\tmg.r = metallicGlossTextureColor.r;\r\n\t\t\tmg.g = albedoTextureAlpha;\r\n\t\t#else\r\n\t\t mg = metallicGlossTextureColor.ra;\r\n\t\t#endif\r\n\t\tmg.g *= u_smoothnessScale;\r\n\t#else\r\n\t\tmg.r = u_metallic;\r\n\t\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\t\tmg.g = albedoTextureAlpha * u_smoothnessScale;\r\n\t\t#else\r\n\t\t\tmg.g = u_smoothness;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\treturn mg;\r\n}\r\n\r\n";
  22359. var PBRUtilsGLSL = "struct DirectionLight\r\n{\r\n\tvec3 Color;\r\n\tvec3 Direction;\r\n};\r\n\r\nstruct PointLight\r\n{\r\n\tvec3 Color;\r\n\tvec3 Position;\r\n\tfloat Range;\r\n};\r\n\r\nstruct SpotLight\r\n{\r\n\tvec3 Color;\r\n\tvec3 Position;\r\n\tvec3 Direction;\r\n\tfloat SpotAngle;\r\n\tfloat Range;\r\n};\r\n\r\nvec3 UnpackScaleNormal(in vec2 uv0)\r\n{\r\n\t#ifdef NORMALTEXTURE\r\n\t\tvec3 normalT;\r\n\t\tvec4 normalMapSample = texture2D(u_NormalTexture, uv0);\r\n\t\tnormalT.x = 2.0 * normalMapSample.x - 1.0;\r\n\t\tnormalT.y = 1.0 - 2.0 * normalMapSample.y;\r\n\t\tnormalT.xy *= u_normalScale;\r\n\t\tnormalT.z = sqrt(1.0 - clamp(dot(normalT.xy, normalT.xy), 0.0, 1.0));\r\n\t\t\r\n\t\tvec3 T = normalize(v_Tangent);\r\n\t\tvec3 B = normalize(v_Binormal);\r\n\t\tvec3 N = normalize(v_Normal);\r\n\t\tmat3 TBN = mat3(T, B, N);\r\n\t\t\r\n\t\tvec3 bumpedNormal = TBN * normalize(normalT);\r\n\t\treturn bumpedNormal;\r\n\t#else\r\n\t\treturn normalize(v_Normal);\r\n\t#endif\r\n}\r\n\r\nvec4 DielectricSpecularColor = vec4(0.220916301, 0.220916301, 0.220916301, 1.0 - 0.220916301);\r\n\r\nfloat PI = 3.14159265359;\r\n\r\nvec3 FresnelTerm (in vec3 F0, in float cosA)\r\n{\r\n\treturn F0 + (vec3(1.0) - F0) * pow(1.0 - cosA, 5.0);\r\n}\r\n\r\nvec3 FresnelLerp (in vec3 F0, in vec3 F90, float cosA)\r\n{\r\n float t = pow(1.0 - cosA, 5.0);\r\n return mix(F0, F90, t);\r\n}\r\n\r\nfloat PerceptualRoughnessToRoughness(in float perceptualRoughness)\r\n{\r\n\treturn perceptualRoughness * perceptualRoughness;\r\n}\r\n\r\nfloat PerceptualRoughnessToSpecularPower(in float perceptualRoughness)\r\n{\r\n\tfloat m = PerceptualRoughnessToRoughness(perceptualRoughness);\r\n\tfloat sq = max(0.0001, m * m);\r\n\tfloat n = (2.0 / sq) - 2.0;\r\n\tn = max(n, 0.0001);\r\n\treturn n;\r\n}\r\n\r\nfloat RoughnessToPerceptualRoughness(in float roughness)\r\n{\r\n\treturn sqrt(roughness);\r\n}\r\n\r\nfloat SmoothnessToRoughness(in float smoothness)\r\n{\r\n\treturn (1.0 - smoothness) * (1.0 - smoothness);\r\n}\r\n\r\nfloat SmoothnessToPerceptualRoughness(in float smoothness)\r\n{\r\n\treturn (1.0 - smoothness);\r\n}\r\n\r\nvec3 SafeNormalize(in vec3 inVec)\r\n{\r\n\tfloat dp3 = max(0.001,dot(inVec,inVec));\r\n\treturn inVec * (1.0 / sqrt(dp3));\r\n}\r\n\r\nfloat DisneyDiffuse(in float NdotV, in float NdotL, in float LdotH, in float perceptualRoughness)\r\n{\r\n\tfloat fd90 = 0.5 + 2.0 * LdotH * LdotH * perceptualRoughness;\r\n\tfloat lightScatter\t= (1.0 + (fd90 - 1.0) * pow(1.0 - NdotL,5.0));\r\n\tfloat viewScatter\t= (1.0 + (fd90 - 1.0) * pow(1.0 - NdotV,5.0));\r\n\r\n\treturn lightScatter * viewScatter;\r\n}\r\n\r\nfloat SmithJointGGXVisibilityTerm (float NdotL, float NdotV, float roughness)\r\n{\r\n\tfloat a = roughness;\r\n\tfloat lambdaV = NdotL * (NdotV * (1.0 - a) + a);\r\n\tfloat lambdaL = NdotV * (NdotL * (1.0 - a) + a);\r\n\r\n\treturn 0.5 / (lambdaV + lambdaL + 0.00001);\r\n}\r\n\r\nfloat GGXTerm (float NdotH, float roughness)\r\n{\r\n\tfloat a2 = roughness * roughness;\r\n\tfloat d = (NdotH * a2 - NdotH) * NdotH + 1.0;\r\n\treturn 0.31830988618 * a2 / (d * d + 0.0000001);\r\n}\r\n\r\nfloat OneMinusReflectivityFromMetallic(in float metallic)\r\n{\r\n\tfloat oneMinusDielectricSpec = DielectricSpecularColor.a;\r\n\treturn oneMinusDielectricSpec - metallic * oneMinusDielectricSpec;\r\n}\r\n\r\nfloat SpecularStrength(vec3 specular)\r\n{\r\n //(SHADER_TARGET < 30)return specular.r; \r\n return max (max (specular.r, specular.g), specular.b);\r\n}\r\n\r\nvec3 DiffuseAndSpecularFromMetallic(in vec3 diffuseColor, in float metallic, out vec3 specularColor, out float oneMinusReflectivity)\r\n{\r\n\tspecularColor = mix(DielectricSpecularColor.rgb, diffuseColor, metallic);\r\n\toneMinusReflectivity = OneMinusReflectivityFromMetallic(metallic);\r\n\treturn diffuseColor * oneMinusReflectivity;\r\n}\r\n\r\nvec3 EnergyConservationBetweenDiffuseAndSpecular(in vec3 diffuseColor, in vec3 specularColor, out float oneMinusReflectivity)\r\n{\r\n\toneMinusReflectivity = 1.0 - SpecularStrength(specularColor);\r\n\treturn diffuseColor * oneMinusReflectivity;\r\n}\r\n\r\nvec4 Occlusion(in vec2 uv0){\r\n\t#ifdef OCCLUSIONTEXTURE\r\n\t\tvec4 occlusionTextureColor = texture2D(u_OcclusionTexture, uv0);\r\n\t\tfloat occ = occlusionTextureColor.g;\r\n\t\tfloat oneMinusT = 1.0 - u_occlusionStrength;\r\n\t\tfloat lerpOneTo = oneMinusT + occ * u_occlusionStrength;\r\n\t\treturn occlusionTextureColor * lerpOneTo;\r\n\t#else\r\n\t\treturn vec4(1.0);\r\n\t#endif\r\n}\r\n\r\nvec2 ParallaxOffset(in vec3 viewDir){\r\n\t#ifdef PARALLAXTEXTURE\r\n\t\tfloat h = texture2D(u_ParallaxTexture, v_Texcoord0).g;\r\n\t\th = h * u_parallaxScale - u_parallaxScale / 2.0;\r\n\t\tvec3 v = viewDir;\r\n\t\tv.z += 0.42;\r\n\t\tvec2 offset = h * (v.xy / v.z);\r\n\t\treturn v_Texcoord0 + offset;\r\n\t#else\r\n\t\treturn v_Texcoord0;\r\n\t#endif\r\n}\r\n\r\nvec3 ReflectCubeMap(in vec3 viewDir, in vec3 normal){\r\n\t#ifdef REFLECTMAP\r\n\t\tvec3 incident = -viewDir;\r\n\t\tvec3 reflectionVector = reflect(incident, normal);\r\n\t\tvec3 reflectionColor = textureCube(u_ReflectTexture, vec3(-reflectionVector.x, reflectionVector.yz)).rgb;\r\n\t\treturn reflectionColor * u_ReflectIntensity;\r\n\t#else\r\n\t\treturn vec3(0.0);\r\n\t#endif\r\n}\r\n\r\nfloat LayaAttenuation(in vec3 L, in float invLightRadius)\r\n{\r\n\tfloat fRatio = clamp(length(L) * invLightRadius, 0.0, 1.0);\r\n\tfRatio *= fRatio;\r\n\treturn 1.0 / (1.0 + 25.0 * fRatio) * clamp(4.0*(1.0 - fRatio), 0.0, 1.0); //fade to black as if 4 pixel texture\r\n}\r\n\r\nvec3 LayaPreMultiplyAlpha(vec3 diffColor, float alpha, float oneMinusReflectivity, out float outModifiedAlpha)\r\n{\r\n\t#ifdef ALPHAPREMULTIPLY\r\n\t\tdiffColor *= alpha;\r\n\t\toutModifiedAlpha = 1.0 - oneMinusReflectivity + alpha * oneMinusReflectivity;\r\n\t#else\r\n\t\toutModifiedAlpha = alpha;\r\n\t#endif\r\n\treturn diffColor;\r\n}\r\n\r\n";
  22360. var PBRSpecularPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\nvarying vec2 v_Texcoord0;\r\nvarying vec3 v_Normal;\r\nvarying vec3 v_Tangent;\r\nvarying vec3 v_Binormal;\r\nvarying vec3 v_ViewDir;\r\nvarying vec3 v_PositionWorld;\r\n\r\nuniform vec3 u_AmbientColor;\r\nuniform vec4 u_AlbedoColor;\r\nuniform vec4 u_SpecularColor;\r\n\r\n#ifdef ALBEDOTEXTURE\r\n\tuniform sampler2D u_AlbedoTexture;\r\n#endif\r\n#ifdef SPECULARTEXTURE\r\n\tuniform sampler2D u_SpecularTexture;\r\n#endif\r\n#ifdef NORMALTEXTURE\r\n\tuniform sampler2D u_NormalTexture;\r\n\tuniform float u_normalScale;\r\n#endif\r\n#ifdef PARALLAXTEXTURE\r\n\tuniform sampler2D u_ParallaxTexture;\r\n\tuniform float u_parallaxScale;\r\n#endif\r\n#ifdef OCCLUSIONTEXTURE\r\n\tuniform sampler2D u_OcclusionTexture;\r\n\tuniform float u_occlusionStrength;\r\n#endif\r\n#ifdef EMISSION\r\n\t#ifdef EMISSIONTEXTURE\r\n\t\tuniform sampler2D u_EmissionTexture;\r\n\t#endif\r\n\tuniform vec4 u_EmissionColor;\r\n#endif\r\n#ifdef REFLECTMAP\r\n\tuniform samplerCube u_ReflectTexture;\r\n\tuniform float u_ReflectIntensity;\r\n#endif\r\n\r\nuniform float u_AlphaTestValue;\r\nuniform float u_metallic;\r\nuniform float u_smoothness;\r\nuniform float u_smoothnessScale;\r\n\r\nuniform sampler2D u_RangeTexture;\r\n//uniform sampler2D u_AngleTexture;\r\n#ifdef POINTLIGHT\r\n\tuniform mat4 u_PointLightMatrix;\r\n#endif\r\n//uniform mat4 u_SpotLightMatrix;\r\n\r\n#include \"PBRSpecularLighting.glsl\"\r\n#include \"ShadowHelper.glsl\"\r\n\r\nvarying float v_posViewZ;\r\n#ifdef RECEIVESHADOW\r\n\t#if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\r\n\t\tuniform mat4 u_lightShadowVP[4];\r\n\t#endif\r\n\t#ifdef SHADOWMAP_PSSM1 \r\n\t\tvarying vec4 v_lightMVPPos;\r\n\t#endif\r\n#endif\r\n\r\n#ifdef DIRECTIONLIGHT\r\n\tuniform DirectionLight u_DirectionLight;\r\n#endif\r\n#ifdef POINTLIGHT\r\n\tuniform PointLight u_PointLight;\r\n#endif\r\n#ifdef SPOTLIGHT\r\n\tuniform SpotLight u_SpotLight;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\tuniform vec3 u_FogColor;\r\n#endif\r\n\r\nvoid main_castShadow()\r\n{\r\n\tgl_FragColor=packDepth(v_posViewZ);\r\n\t#if defined(DIFFUSEMAP)&&defined(ALPHATEST)\r\n\t\tfloat alpha = texture2D(u_AlbedoTexture,v_Texcoord0).w;\r\n\t\tif( alpha < u_AlphaTestValue )\r\n\t\t{\r\n\t\t\tdiscard;\r\n\t\t}\r\n\t#endif\r\n}\r\n\r\nvoid main_normal()\r\n{\t\r\n\tvec3 viewDir = normalize(v_ViewDir);\r\n\t\r\n\tvec2 uv0 = ParallaxOffset(viewDir);\r\n\t\r\n\tvec4 sg;\r\n\tvec4 albedoColor;\r\n\t#ifdef ALBEDOTEXTURE\r\n\t\tvec4 albedoTextureColor = texture2D(u_AlbedoTexture, uv0);\r\n\t\talbedoColor = albedoTextureColor * u_AlbedoColor;\r\n\t\tsg = SpecularGloss(albedoTextureColor.a, uv0);\r\n\t#else\r\n\t\talbedoColor = u_AlbedoColor;\r\n\t\tsg = SpecularGloss(1.0, uv0);\r\n\t#endif\r\n\t\r\n\t#ifdef ALPHATEST\r\n\t\tif(albedoColor.a < u_AlphaTestValue)\r\n\t\t\tdiscard;\r\n\t#endif\r\n \r\n\tvec3 normal = UnpackScaleNormal(uv0);\r\n\t\r\n\tLayaGI gi;\r\n\tgi.diffuse = u_AmbientColor * Occlusion(uv0).rgb;\r\n\tgi.specular = ReflectCubeMap(viewDir, normal);\r\n\t\r\n\t//float a = (sg.r+sg.g+sg.b) / 3.0;\r\n \r\n\tvec4 color = vec4(0.0);\r\n\t\r\n\t#ifdef DIRECTIONLIGHT\r\n\t\tcolor += PBRSpecularDiectionLight(albedoColor, sg.rgb, sg.a, normal, viewDir, u_DirectionLight, gi);\r\n\t#endif\r\n \r\n\t#ifdef POINTLIGHT\r\n\t\tcolor.a = 0.0;\r\n\t\tcolor += PBRSpecularPointLight(albedoColor, sg.rgb, sg.a, normal, viewDir, u_PointLight, v_PositionWorld, gi);\r\n\t#endif\r\n\t\r\n\t#ifdef SPOTLIGHT\r\n\t\tcolor.a = 0.0;\r\n\t\tcolor += PBRSpecularSpotLight(albedoColor, sg.rgb, sg.a, normal, viewDir, u_SpotLight, v_PositionWorld, gi);\r\n\t#endif\r\n\r\n\t#ifdef REFLECTMAP\r\n\t \tcolor += LayaAirSpecularReflect(albedoColor,sg.rgb,sg.a,gi);\r\n\t#endif\r\n\r\n\t#ifdef EMISSION\r\n\t\tvec4 emissionColor = u_EmissionColor;\r\n\t\t#ifdef EMISSIONTEXTURE\r\n\t\t\temissionColor *= texture2D(u_EmissionTexture, uv0);\r\n\t\t#endif\r\n\t\tcolor.rgb += emissionColor.rgb;\r\n\t#endif\r\n\t\r\n\t#ifdef RECEIVESHADOW\r\n\t\tfloat shadowValue = 1.0;\r\n\t\t#ifdef SHADOWMAP_PSSM3\r\n\t\t\tshadowValue = getShadowPSSM3( u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\r\n\t\t#endif\r\n\t\t#ifdef SHADOWMAP_PSSM2\r\n\t\t\tshadowValue = getShadowPSSM2( u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\r\n\t\t#endif \r\n\t\t#ifdef SHADOWMAP_PSSM1\r\n\t\t\tshadowValue = getShadowPSSM1( u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\r\n\t\t#endif\r\n\t\tgl_FragColor = vec4(color.rgb * shadowValue, color.a);\r\n\t#else\r\n\t\tgl_FragColor = color;\r\n\t#endif\r\n\t\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\r\n\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\r\n\t#endif\r\n}\r\n\r\nvoid main()\r\n{\r\n\t#ifdef CASTSHADOW\t\t\r\n\t\tmain_castShadow();\r\n\t#else\r\n\t\tmain_normal();\r\n\t#endif \r\n}\r\n\r\n";
  22361. var PBRSpecularVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec3 a_Normal;\r\nattribute vec4 a_Tangent0;\r\nattribute vec2 a_Texcoord0;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_WorldMat;\r\n#else\r\n\tuniform mat4 u_WorldMat;\r\n#endif\r\nuniform vec3 u_CameraPos;\r\n\r\nvarying vec2 v_Texcoord0;\r\nvarying vec3 v_Normal;\r\nvarying vec3 v_Tangent;\r\nvarying vec3 v_Binormal;\r\nvarying vec3 v_ViewDir;\r\nvarying vec3 v_PositionWorld;\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\nvarying float v_posViewZ;\r\n#ifdef RECEIVESHADOW\r\n #ifdef SHADOWMAP_PSSM1 \r\n\t varying vec4 v_lightMVPPos;\r\n\t uniform mat4 u_lightShadowVP[4];\r\n #endif\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\nvoid main_castShadow()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\tposition=skinTransform*a_Position;\r\n\t#else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t \r\n\t//TODO没考虑UV动画呢\r\n\t#if defined(DIFFUSEMAP)&&defined(ALPHATEST)\r\n\t\tv_Texcoord0 = a_Texcoord0;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n\tv_posViewZ = gl_Position.z;\r\n}\r\n\r\nvoid main_normal()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\tposition=skinTransform*a_Position;\r\n\t#else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)||defined(REFLECTMAP)\r\n\t\tmat4 worldMat;\r\n\t\t#ifdef GPU_INSTANCE\r\n\t\t\tworldMat = a_WorldMat;\r\n\t\t#else\r\n\t\t\tworldMat = u_WorldMat;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(REFLECTMAP)\r\n\t\tmat3 worldInvMat;\r\n\t\t#ifdef BONE\r\n\t\t\tworldInvMat=inverse(mat3(worldMat*skinTransform));\r\n\t\t#else\r\n\t\t\tworldInvMat=inverse(mat3(worldMat));\r\n\t\t#endif \r\n\t\tv_Normal=a_Normal*worldInvMat;\r\n\t\t#if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))\r\n\t\t\tv_Tangent=a_Tangent0.xyz*worldInvMat;\r\n\t\t\tv_Binormal=cross(v_Normal,v_Tangent)*a_Tangent0.w;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)||defined(REFLECTMAP)\r\n\t\tv_PositionWorld=(worldMat*position).xyz;\r\n\t#endif\r\n\t\r\n \r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(REFLECTMAP)\r\n\t\tv_ViewDir=u_CameraPos-v_PositionWorld;\r\n\t#endif\r\n\r\n\t#ifdef TILINGOFFSET\r\n\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t#else\r\n\t\tv_Texcoord0=a_Texcoord0;\r\n\t#endif\r\n \r\n\t#ifdef RECEIVESHADOW\r\n\t\tv_posViewZ = gl_Position.w;\r\n\t\t#ifdef SHADOWMAP_PSSM1 \r\n\t\t\tv_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\r\n\t\t#endif\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n\r\nvoid main()\r\n{\r\n\t#ifdef CASTSHADOW\r\n\t\tmain_castShadow();\r\n\t#else\r\n\t\tmain_normal();\r\n\t#endif\r\n}";
  22362. var PBRStandardPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\nvarying vec2 v_Texcoord0;\r\nvarying vec3 v_Normal;\r\nvarying vec3 v_Tangent;\r\nvarying vec3 v_Binormal;\r\nvarying vec3 v_ViewDir;\r\nvarying vec3 v_PositionWorld;\r\n\r\nuniform vec3 u_AmbientColor;\r\nuniform vec4 u_AlbedoColor;\r\n\r\n#ifdef ALBEDOTEXTURE\r\n\tuniform sampler2D u_AlbedoTexture;\r\n#endif\r\n#ifdef METALLICGLOSSTEXTURE\r\n\tuniform sampler2D u_MetallicGlossTexture;\r\n#endif\r\n#ifdef NORMALTEXTURE\r\n\tuniform sampler2D u_NormalTexture;\r\n\tuniform float u_normalScale;\r\n#endif\r\n#ifdef PARALLAXTEXTURE\r\n\tuniform sampler2D u_ParallaxTexture;\r\n\tuniform float u_parallaxScale;\r\n#endif\r\n#ifdef OCCLUSIONTEXTURE\r\n\tuniform sampler2D u_OcclusionTexture;\r\n\tuniform float u_occlusionStrength;\r\n#endif\r\n#ifdef EMISSION\r\n\t#ifdef EMISSIONTEXTURE\r\n\t\tuniform sampler2D u_EmissionTexture;\r\n\t#endif\r\n\tuniform vec4 u_EmissionColor;\r\n#endif\r\n#ifdef REFLECTMAP\r\n\tuniform samplerCube u_ReflectTexture;\r\n\tuniform float u_ReflectIntensity;\r\n#endif\r\n\r\nuniform float u_AlphaTestValue;\r\nuniform float u_metallic;\r\nuniform float u_smoothness;\r\nuniform float u_smoothnessScale;\r\n\r\nuniform sampler2D u_RangeTexture;\r\n//uniform sampler2D u_AngleTexture;\r\n#ifdef POINTLIGHT\r\n\tuniform mat4 u_PointLightMatrix;\r\n#endif\r\n//uniform mat4 u_SpotLightMatrix;\r\n\r\n#include \"PBRStandardLighting.glsl\"\r\n#include \"ShadowHelper.glsl\"\r\n\r\nvarying float v_posViewZ;\r\n#ifdef RECEIVESHADOW\r\n\t#if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\r\n\t\tuniform mat4 u_lightShadowVP[4];\r\n\t#endif\r\n\t#ifdef SHADOWMAP_PSSM1 \r\n\t\tvarying vec4 v_lightMVPPos;\r\n\t#endif\r\n#endif\r\n\r\n#ifdef DIRECTIONLIGHT\r\n\tuniform DirectionLight u_DirectionLight;\r\n#endif\r\n#ifdef POINTLIGHT\r\n\tuniform PointLight u_PointLight;\r\n#endif\r\n#ifdef SPOTLIGHT\r\n\tuniform SpotLight u_SpotLight;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\tuniform vec3 u_FogColor;\r\n#endif\r\n\r\nvoid main_castShadow()\r\n{\r\n\tgl_FragColor=packDepth(v_posViewZ);\r\n\t#if defined(DIFFUSEMAP)&&defined(ALPHATEST)\r\n\t\tfloat alpha = texture2D(u_AlbedoTexture,v_Texcoord0).w;\r\n\t\tif( alpha < u_AlphaTestValue )\r\n\t\t{\r\n\t\t\tdiscard;\r\n\t\t}\r\n\t#endif\r\n}\r\n\r\nvoid main_normal()\r\n{\t\r\n\tvec3 viewDir = normalize(v_ViewDir);\r\n\t\r\n\tvec2 uv0 = ParallaxOffset(viewDir);\r\n\t\r\n\tvec2 mg;\r\n\tvec4 albedoColor;\r\n\t#ifdef ALBEDOTEXTURE\r\n\t\tvec4 abledoTextureColor = texture2D(u_AlbedoTexture, uv0);\r\n\t\talbedoColor = abledoTextureColor * u_AlbedoColor;\r\n\t\tmg = MetallicGloss(abledoTextureColor.a, uv0);\r\n\t#else\r\n\t\talbedoColor = u_AlbedoColor;\r\n\t\tmg = MetallicGloss(1.0, uv0);\r\n\t#endif\r\n\t\r\n\t#ifdef ALPHATEST\r\n\t\tif(albedoColor.a < u_AlphaTestValue)\r\n\t\t\tdiscard;\r\n\t#endif\r\n\t\r\n\tvec3 normal = UnpackScaleNormal(uv0);\r\n \r\n\tLayaGI gi;\r\n\tgi.diffuse = u_AmbientColor * Occlusion(uv0).rgb;\r\n\tgi.specular = ReflectCubeMap(viewDir, normal);\r\n \r\n\tvec4 color = vec4(0.0);\r\n\t\r\n\t#ifdef DIRECTIONLIGHT\r\n\t\tcolor += PBRStandardDiectionLight(albedoColor, mg.r, mg.g, normal, viewDir, u_DirectionLight, gi);\r\n\t#endif\r\n \r\n\t#ifdef POINTLIGHT\r\n\t\tcolor.a = 0.0;\r\n\t\tcolor += PBRStandardPointLight(albedoColor, mg.r, mg.g, normal, viewDir, u_PointLight, v_PositionWorld, gi);\r\n\t#endif\r\n\t\r\n\t#ifdef SPOTLIGHT\r\n\t\tcolor.a = 0.0;\r\n\t\tcolor += PBRStandardSpotLight(albedoColor, mg.r, mg.g, normal, viewDir, u_SpotLight, v_PositionWorld, gi);\r\n\t#endif\r\n\t\r\n\t#ifdef REFLECTMAP\r\n\t \tcolor += LayaAirStandardReflect(albedoColor,mg.r,mg.g,gi);\r\n\t#endif\r\n\r\n\t#ifdef EMISSION\r\n\t\tvec4 emissionColor = u_EmissionColor;\r\n\t\t#ifdef EMISSIONTEXTURE\r\n\t\t\temissionColor *= texture2D(u_EmissionTexture, uv0);\r\n\t\t#endif\r\n\t\tcolor.rgb += emissionColor.rgb;\r\n\t#endif\r\n\t\r\n\t#ifdef RECEIVESHADOW\r\n\t\tfloat shadowValue = 1.0;\r\n\t\t#ifdef SHADOWMAP_PSSM3\r\n\t\t\tshadowValue = getShadowPSSM3( u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\r\n\t\t#endif\r\n\t\t#ifdef SHADOWMAP_PSSM2\r\n\t\t\tshadowValue = getShadowPSSM2( u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\r\n\t\t#endif \r\n\t\t#ifdef SHADOWMAP_PSSM1\r\n\t\t\tshadowValue = getShadowPSSM1( u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\r\n\t\t#endif\r\n\t\tgl_FragColor = vec4(color.rgb * shadowValue, color.a);\r\n\t#else\r\n\t\tgl_FragColor = color;\r\n\t#endif\r\n\t\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\r\n\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\r\n\t#endif\r\n}\r\n\r\nvoid main()\r\n{\r\n\t#ifdef CASTSHADOW\t\t\r\n\t\tmain_castShadow();\r\n\t#else\r\n\t\tmain_normal();\r\n\t#endif \r\n}";
  22363. var PBRStandardVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec3 a_Normal;\r\nattribute vec4 a_Tangent0;\r\nattribute vec2 a_Texcoord0;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_WorldMat;\r\n#else\r\n\tuniform mat4 u_WorldMat;\r\n#endif\r\n\r\nuniform vec3 u_CameraPos;\r\n\r\nvarying vec2 v_Texcoord0;\r\nvarying vec3 v_Normal;\r\nvarying vec3 v_Tangent;\r\nvarying vec3 v_Binormal;\r\nvarying vec3 v_ViewDir;\r\nvarying vec3 v_PositionWorld;\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\nvarying float v_posViewZ;\r\n#ifdef RECEIVESHADOW\r\n #ifdef SHADOWMAP_PSSM1 \r\n\t varying vec4 v_lightMVPPos;\r\n\t uniform mat4 u_lightShadowVP[4];\r\n #endif\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\nvoid main_castShadow()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\tposition=skinTransform*a_Position;\r\n\t#else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t \r\n\t//TODO没考虑UV动画呢\r\n\t#if defined(DIFFUSEMAP)&&defined(ALPHATEST)\r\n\t\tv_Texcoord0 = a_Texcoord0;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n\tv_posViewZ = gl_Position.z;\r\n}\r\n\r\nvoid main_normal()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\tposition=skinTransform*a_Position;\r\n\t#else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)||defined(REFLECTMAP)\r\n\t\tmat4 worldMat;\r\n\t\t#ifdef GPU_INSTANCE\r\n\t\t\tworldMat = a_WorldMat;\r\n\t\t#else\r\n\t\t\tworldMat = u_WorldMat;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(REFLECTMAP)\r\n\t\tmat3 worldInvMat;\r\n\t\t#ifdef BONE\r\n\t\t\tworldInvMat=inverse(mat3(worldMat*skinTransform));\r\n\t\t#else\r\n\t\t\tworldInvMat=inverse(mat3(worldMat));\r\n\t\t#endif \r\n\t\tv_Normal=a_Normal*worldInvMat;\r\n\t\t#if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))\r\n\t\t\tv_Tangent=a_Tangent0.xyz*worldInvMat;\r\n\t\t\tv_Binormal=cross(v_Normal,v_Tangent)*a_Tangent0.w;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)||defined(REFLECTMAP)\r\n\t\tv_PositionWorld=(worldMat*position).xyz;\r\n\t#endif\r\n\t\r\n \r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(REFLECTMAP)||defined(REFLECTMAP)\r\n\t\tv_ViewDir=u_CameraPos-v_PositionWorld;\r\n\t#endif\r\n\r\n\t#ifdef TILINGOFFSET\r\n\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t#else\r\n\t\tv_Texcoord0=a_Texcoord0;\r\n\t#endif\r\n \r\n\t#ifdef RECEIVESHADOW\r\n\t\tv_posViewZ = gl_Position.w;\r\n\t\t#ifdef SHADOWMAP_PSSM1 \r\n\t\t\tv_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\r\n\t\t#endif\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n\r\nvoid main()\r\n{\r\n\t#ifdef CASTSHADOW\r\n\t\tmain_castShadow();\r\n\t#else\r\n\t\tmain_normal();\r\n\t#endif\r\n}";
  22364. var BloomVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_PositionTexcoord;\r\nvarying vec2 v_Texcoord0;\r\n\r\nvoid main() {\r\n\tgl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\r\n\tv_Texcoord0 = a_PositionTexcoord.zw;\r\n\tgl_Position = remapGLPositionZ(gl_Position);\r\n}";
  22365. var BloomDownsample13PS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Colors.glsl\";\r\n#include \"Sampling.glsl\";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform vec4 u_MainTex_TexelSize;\r\n\r\nvoid fragDownsample13() {\r\n\tmediump vec4 color = downsampleBox13Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\r\n\tgl_FragColor = color;\r\n}\r\n\r\nvoid main() {\r\n\tfragDownsample13();\r\n}";
  22366. var BloomDownsample4PS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Colors.glsl\";\r\n#include \"Sampling.glsl\";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform vec4 u_MainTex_TexelSize;\r\n\r\nvoid fragDownsample4() {\r\n\tmediump vec4 color = downsampleBox4Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\r\n\tgl_FragColor = color;\r\n}\r\n\r\nvoid main() {\r\n\tfragDownsample4();\r\n}";
  22367. var BloomPrefilter13PS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Colors.glsl\";\r\n#include \"Sampling.glsl\";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_AutoExposureTex;\r\nuniform vec4 u_MainTex_TexelSize;\r\nuniform vec4 u_Threshold; // x: threshold value (linear), y: threshold - knee, z: knee * 2, w: 0.25 / knee\r\nuniform vec4 u_Params; // x: clamp, yzw: unused\r\n\r\nmediump vec4 prefilter(mediump vec4 color, vec2 uv) {\r\n\tmediump float autoExposure = texture2D(u_AutoExposureTex, uv).r;\r\n\tcolor *= autoExposure;\r\n\tcolor = min(vec4(u_Params.x), color); // clamp to max\r\n\tcolor = quadraticThreshold(color, u_Threshold.x, u_Threshold.yzw);\r\n\treturn color;\r\n}\r\n\r\nvoid fragPrefilter13() {\r\n\tmediump vec4 color = downsampleBox13Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\r\n\tgl_FragColor = prefilter(safeHDR(color), v_Texcoord0);\r\n}\r\n\r\nvoid main() {\r\n\tfragPrefilter13();\r\n}";
  22368. var BloomPrefilter4PS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Colors.glsl\";\r\n#include \"Sampling.glsl\";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_AutoExposureTex;\r\nuniform vec4 u_MainTex_TexelSize;\r\nuniform vec4 u_Threshold; // x: threshold value (linear), y: threshold - knee, z: knee * 2, w: 0.25 / knee\r\nuniform vec4 u_Params; // x: clamp, yzw: unused\r\n\r\nmediump vec4 prefilter(mediump vec4 color, vec2 uv) {\r\n\tmediump float autoExposure = texture2D(u_AutoExposureTex, uv).r;\r\n\tcolor *= autoExposure;\r\n\tcolor = min(vec4(u_Params.x), color); // clamp to max\r\n\tcolor = quadraticThreshold(color, u_Threshold.x, u_Threshold.yzw);\r\n\treturn color;\r\n}\r\n\r\nvoid fragPrefilter4() {\r\n\tmediump vec4 color = downsampleBox4Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\r\n\tgl_FragColor = prefilter(safeHDR(color), v_Texcoord0);\r\n}\r\n\r\nvoid main() {\r\n\tfragPrefilter4();\r\n}";
  22369. var BloomUpsampleBoxPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Colors.glsl\";\r\n#include \"Sampling.glsl\";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_BloomTex;\r\n\r\nuniform vec4 u_MainTex_TexelSize;\r\nuniform float u_SampleScale;\r\n\r\nmediump vec4 combine(mediump vec4 bloom, vec2 uv) {\r\n\tmediump vec4 color = texture2D(u_BloomTex, uv);\r\n\treturn bloom + color;\r\n}\r\n\r\nvoid fragUpsampleBox() {\r\n\tmediump vec4 bloom = upsampleBox(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy, vec4(u_SampleScale));\r\n\tgl_FragColor = combine(bloom, v_Texcoord0);\r\n}\r\n\r\nvoid main() {\r\n\tfragUpsampleBox();\r\n}";
  22370. var BloomUpsampleTentPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Colors.glsl\";\r\n#include \"Sampling.glsl\";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_BloomTex;\r\n\r\nuniform vec4 u_MainTex_TexelSize;\r\nuniform float u_SampleScale;\r\n\r\nmediump vec4 combine(mediump vec4 bloom, vec2 uv) {\r\n\tmediump vec4 color = texture2D(u_BloomTex, uv);\r\n\treturn bloom + color;\r\n}\r\n\r\nvoid fragUpsampleTent() {\r\n\tmediump vec4 bloom = upsampleTent(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy, vec4(u_SampleScale));\r\n\tgl_FragColor = combine(bloom, v_Texcoord0);\r\n}\r\n\r\nvoid main() {\r\n\tfragUpsampleTent();\r\n}";
  22371. var ColorsGLSL = "#include \"StdLib.glsl\";\r\n\r\n#define EPSILON 1.0e-4\r\n\r\n// Quadratic color thresholding\r\n// curve = (threshold - knee, knee * 2, 0.25 / knee)\r\nmediump vec4 quadraticThreshold(mediump vec4 color, mediump float threshold, mediump vec3 curve) {\r\n\t// Pixel brightness\r\n\tmediump float br = max3(color.r, color.g, color.b);\r\n\r\n\t// Under-threshold part: quadratic curve\r\n\tmediump float rq = clamp(br - curve.x, 0.0, curve.y);\r\n\trq = curve.z * rq * rq;\r\n\r\n\t// Combine and apply the brightness response curve.\r\n\tcolor *= max(rq, br - threshold) / max(br, EPSILON);\r\n\r\n\treturn color;\r\n}\r\n\r\n\r\n\r\n//\r\n// sRGB transfer functions\r\n// Fast path ref: http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1\r\n//\r\nmediump vec3 sRGBToLinear(mediump vec3 c) {\r\n\t#ifdef USE_VERY_FAST_SRGB\r\n\t\treturn c * c;\r\n\t#elif defined(USE_FAST_SRGB)\r\n\t\treturn c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);\r\n\t#else\r\n\t\tmediump vec3 linearRGBLo = c / 12.92;\r\n\t\tmediump vec3 power=vec3(2.4, 2.4, 2.4);\r\n\t\tmediump vec3 linearRGBHi = positivePow((c + 0.055) / 1.055, power);\r\n\t\tmediump vec3 linearRGB =vec3((c.r<=0.04045) ? linearRGBLo.r : linearRGBHi.r,(c.g<=0.04045) ? linearRGBLo.g : linearRGBHi.g,(c.b<=0.04045) ? linearRGBLo.b : linearRGBHi.b);\r\n\t\treturn linearRGB;\r\n\t#endif\r\n}\r\n\r\nmediump vec4 sRGBToLinear(mediump vec4 c){\r\n return vec4(sRGBToLinear(c.rgb), c.a);\r\n}\r\n\r\n\r\n\r\nmediump vec3 linearToSRGB(mediump vec3 c) {\r\n\t#ifdef USE_VERY_FAST_SRGB\r\n\t\treturn sqrt(c);\r\n\t#elif defined(USE_FAST_SRGB)\r\n\t\treturn max(1.055 * PositivePow(c, 0.416666667) - 0.055, 0.0);\r\n\t#else\r\n\t\tmediump vec3 sRGBLo = c * 12.92;\r\n\t\tmediump vec3 power=vec3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4);\r\n\t\tmediump vec3 sRGBHi = (positivePow(c, power) * 1.055) - 0.055;\r\n\t\tmediump vec3 sRGB =vec3((c.r<=0.0031308) ? sRGBLo.r : sRGBHi.r,(c.g<=0.0031308) ? sRGBLo.g : sRGBHi.g,(c.b<=0.0031308) ? sRGBLo.b : sRGBHi.b);\r\n\t\treturn sRGB;\r\n\t#endif\r\n}\r\n\r\nmediump vec4 linearToSRGB(mediump vec4 c){\r\n return vec4(linearToSRGB(c.rgb), c.a);\r\n}";
  22372. var CompositePS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Colors.glsl\";\r\n#include \"Sampling.glsl\";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_BloomTex;\r\n\r\nuniform sampler2D u_AutoExposureTex;\r\nuniform sampler2D u_Bloom_DirtTex;\r\nuniform vec4 u_BloomTex_TexelSize;\r\nuniform vec4 u_Bloom_DirtTileOffset; // xy: tiling, zw: offset\r\nuniform mediump vec3 u_Bloom_Settings;// x: sampleScale, y: intensity, z: dirt intensity\r\nuniform mediump vec3 u_Bloom_Color;\r\n\r\nvoid main() {\r\n\tmediump float autoExposure = texture2D(u_AutoExposureTex, v_Texcoord0).r;\r\n\tmediump vec4 color=vec4(0.0);\r\n\tcolor = texture2D(u_MainTex, v_Texcoord0);\r\n\t\r\n\tcolor = sRGBToLinear(color);\r\n\tcolor.rgb *= autoExposure;\r\n\t\r\n\t#if defined(BLOOM)||defined(BLOOM_LOW)\r\n\t\t#ifdef BLOOM\r\n\t\t\tmediump vec4 bloom = upsampleTent(u_BloomTex, v_Texcoord0, u_BloomTex_TexelSize.xy, vec4(u_Bloom_Settings.x));\r\n\t\t#else\r\n\t\t\tmediump vec4 bloom = upsampleBox(u_BloomTex, v_Texcoord0, u_BloomTex_TexelSize.xy, vec4(u_Bloom_Settings.x));\r\n\t\t#endif\r\n\r\n\t\t// UVs should be Distort(uv * u_Bloom_DirtTileOffset.xy + u_Bloom_DirtTileOffset.zw)\r\n\t\t// but considering we use a cover-style scale on the dirt texture the difference\r\n\t\t// isn't massive so we chose to save a few ALUs here instead in case lens distortion\r\n\t\t// is active\r\n\t\tmediump vec4 dirt =vec4(texture2D(u_Bloom_DirtTex, v_Texcoord0 * u_Bloom_DirtTileOffset.xy + u_Bloom_DirtTileOffset.zw).rgb, 0.0);\r\n\r\n\t\t// Additive bloom (artist friendly)\r\n\t\tbloom *= u_Bloom_Settings.y;\r\n\t\tdirt *= u_Bloom_Settings.z;\r\n\t\tmediump vec4 bloomColor=vec4(u_Bloom_Color, 1.0);\r\n\t\tcolor += bloom * bloomColor;\r\n\t\tcolor += dirt * bloom;\r\n\t#endif\r\n\t\r\n\tmediump vec4 finalColor = color;\r\n\tfinalColor = linearToSRGB(finalColor);\r\n\t//finalColor.rgb = Dither(finalColor.rgb, v_Texcoord0);//TODO:抖动\r\n\tgl_FragColor = finalColor;\r\n}";
  22373. var CompositeVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_PositionTexcoord;\r\nvarying vec2 v_Texcoord0;\r\n\r\nvoid main() {\r\n\tgl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\r\n\tv_Texcoord0 = a_PositionTexcoord.zw;\r\n\tgl_Position = remapGLPositionZ(gl_Position);\r\n}";
  22374. var SamplingGLSL = "// Better, temporally stable box filtering\r\n// [Jimenez14] http://goo.gl/eomGso\r\n// . . . . . . .\r\n// . A . B . C .\r\n// . . D . E . .\r\n// . F . G . H .\r\n// . . I . J . .\r\n// . K . L . M .\r\n// . . . . . . .\r\nmediump vec4 downsampleBox13Tap(sampler2D tex, vec2 uv, vec2 texelSize)\r\n{\r\n mediump vec4 A = texture2D(tex, uv + texelSize * vec2(-1.0, -1.0));\r\n mediump vec4 B = texture2D(tex, uv + texelSize * vec2( 0.0, -1.0));\r\n mediump vec4 C = texture2D(tex, uv + texelSize * vec2( 1.0, -1.0));\r\n mediump vec4 D = texture2D(tex, uv + texelSize * vec2(-0.5, -0.5));\r\n mediump vec4 E = texture2D(tex, uv + texelSize * vec2( 0.5, -0.5));\r\n mediump vec4 F = texture2D(tex, uv + texelSize * vec2(-1.0, 0.0));\r\n mediump vec4 G = texture2D(tex, uv);\r\n mediump vec4 H = texture2D(tex, uv + texelSize * vec2( 1.0, 0.0));\r\n mediump vec4 I = texture2D(tex, uv + texelSize * vec2(-0.5, 0.5));\r\n mediump vec4 J = texture2D(tex, uv + texelSize * vec2( 0.5, 0.5));\r\n mediump vec4 K = texture2D(tex, uv + texelSize * vec2(-1.0, 1.0));\r\n mediump vec4 L = texture2D(tex, uv + texelSize * vec2( 0.0, 1.0));\r\n mediump vec4 M = texture2D(tex, uv + texelSize * vec2( 1.0, 1.0));\r\n\r\n\tmediump vec2 scale= vec2(0.5, 0.125);\r\n mediump vec2 div = (1.0 / 4.0) * scale;\r\n\r\n mediump vec4 o = (D + E + I + J) * div.x;\r\n o += (A + B + G + F) * div.y;\r\n o += (B + C + H + G) * div.y;\r\n o += (F + G + L + K) * div.y;\r\n o += (G + H + M + L) * div.y;\r\n\r\n return o;\r\n}\r\n\r\n// Standard box filtering\r\nmediump vec4 downsampleBox4Tap(sampler2D tex, vec2 uv, vec2 texelSize)\r\n{\r\n vec4 d = texelSize.xyxy * vec4(-1.0, -1.0, 1.0, 1.0);\r\n\r\n mediump vec4 s = texture2D(tex, uv + d.xy);\r\n s += texture2D(tex, uv + d.zy);\r\n s += texture2D(tex, uv + d.xw);\r\n s += texture2D(tex, uv + d.zw);\r\n\r\n return s * (1.0 / 4.0);\r\n}\r\n\r\n// 9-tap bilinear upsampler (tent filter)\r\n// . . . . . . .\r\n// . 1 . 2 . 1 .\r\n// . . . . . . .\r\n// . 2 . 4 . 2 .\r\n// . . . . . . .\r\n// . 1 . 2 . 1 .\r\n// . . . . . . .\r\nmediump vec4 upsampleTent(sampler2D tex, vec2 uv, vec2 texelSize, vec4 sampleScale)\r\n{\r\n vec4 d = texelSize.xyxy * vec4(1.0, 1.0, -1.0, 0.0) * sampleScale;\r\n\r\n mediump vec4 s = texture2D(tex, uv - d.xy);\r\n s += texture2D(tex, uv - d.wy) * 2.0;\r\n s += texture2D(tex, uv - d.zy);\r\n\r\n s += texture2D(tex, uv + d.zw) * 2.0;\r\n s += texture2D(tex, uv) * 4.0;\r\n s += texture2D(tex,\tuv + d.xw) * 2.0;\r\n\r\n s += texture2D(tex, uv + d.zy);\r\n s += texture2D(tex, uv + d.wy) * 2.0;\r\n s += texture2D(tex, uv + d.xy);\r\n\r\n return s * (1.0 / 16.0);\r\n}\r\n\r\n// Standard box filtering\r\nmediump vec4 upsampleBox(sampler2D tex, vec2 uv, vec2 texelSize, vec4 sampleScale)\r\n{\r\n vec4 d = texelSize.xyxy * vec4(-1.0, -1.0, 1.0, 1.0) * 0.5 * sampleScale;\r\n\r\n mediump vec4 s = texture2D(tex, uv + d.xy);\r\n s += texture2D(tex, uv + d.zy);\r\n s += texture2D(tex, uv + d.xw);\r\n s += texture2D(tex, uv + d.zw);\r\n\r\n return s * (1.0 / 4.0);\r\n}";
  22375. var StdLibGLSL = "#define HALF_MAX 65504.0 // (2 - 2^-10) * 2^15\r\n\r\n#define FLT_EPSILON 1.192092896e-07 // Smallest positive number, such that 1.0 + FLT_EPSILON != 1.0\r\n\r\nmediump vec4 safeHDR(mediump vec4 c)\r\n{\r\n return min(c, HALF_MAX);\r\n}\r\n\r\nfloat max3(float a, float b, float c)\r\n{\r\n return max(max(a, b), c);\r\n}\r\n\r\nvec3 positivePow(vec3 base, vec3 power)\r\n{\r\n return pow(max(abs(base), vec3(FLT_EPSILON, FLT_EPSILON, FLT_EPSILON)), power);\r\n}";
  22376. var ShadowHelperGLSL = "uniform sampler2D u_shadowMap1;\r\nuniform sampler2D u_shadowMap2;\r\nuniform sampler2D u_shadowMap3;\r\nuniform vec2\t u_shadowPCFoffset;\r\nuniform vec4 u_shadowPSSMDistance;\r\nvec4 packDepth(const in float depth)\r\n{\r\n\tconst vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\r\n\tconst vec4 bitMask\t= vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\r\n\tvec4 res = mod(depth*bitShift*vec4(255), vec4(256))/vec4(255);\r\n\tres -= res.xxyz * bitMask;\r\n\treturn res;\r\n}\r\nfloat unpackDepth(const in vec4 rgbaDepth)\r\n{\r\n\tconst vec4 bitShift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\r\n\tfloat depth = dot(rgbaDepth, bitShift);\r\n\treturn depth;\r\n}\r\nfloat tex2DPCF( sampler2D shadowMap,vec2 texcoord,vec2 invsize,float zRef )\r\n{\r\n\tvec2 texelpos =texcoord / invsize;\r\n\tvec2 lerps = fract( texelpos );\r\n\tfloat sourcevals[4];\r\n\tsourcevals[0] = float( unpackDepth(texture2D(shadowMap,texcoord)) > zRef );\r\n\tsourcevals[1] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(invsize.x,0))) > zRef );\r\n\tsourcevals[2] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(0,invsize.y))) > zRef );\r\n\tsourcevals[3] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(invsize.x, invsize.y) )) > zRef );\r\n\treturn mix( mix(sourcevals[0],sourcevals[2],lerps.y),mix(sourcevals[1],sourcevals[3],lerps.y),lerps.x );\r\n}\r\nfloat getShadowPSSM3( sampler2D shadowMap1,sampler2D shadowMap2,sampler2D shadowMap3,mat4 lightShadowVP[4],vec4 pssmDistance,vec2 shadowPCFOffset,vec3 worldPos,float posViewZ,float zBias )\r\n{\r\n\tfloat value = 1.0;\r\n\tint nPSNum = int(posViewZ>pssmDistance.x);\r\n\tnPSNum += int(posViewZ>pssmDistance.y);\r\n\tnPSNum += int(posViewZ>pssmDistance.z);\r\n\t//真SB,webgl不支持在PS中直接访问数组\r\n\tmat4 lightVP;\r\n\tif( nPSNum == 0 )\r\n\t{\r\n\t\tlightVP = lightShadowVP[1];\r\n\t}\r\n\telse if( nPSNum == 1 )\r\n\t{\r\n\t\tlightVP = lightShadowVP[2];\r\n\t}\r\n\telse if( nPSNum == 2 )\r\n\t{\r\n\t\tlightVP = lightShadowVP[3];\r\n\t}\r\n\tvec4 vLightMVPPos = lightVP * vec4(worldPos,1.0);\r\n\t//为了效率,在CPU计算/2.0 + 0.5\r\n\t//vec3 vText = (vLightMVPPos.xyz / vLightMVPPos.w)/2.0 + 0.5;\r\n\tvec3 vText = vLightMVPPos.xyz / vLightMVPPos.w;\r\n\tfloat fMyZ = vText.z - zBias;\r\n\t/*\r\n\tbvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\r\n\tbool bInFrustum = all( bInFrustumVec );\r\n\tbvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\r\n\tbool bFrustumTest = all( bFrustumTestVec );\r\n\tif ( bFrustumTest ) \r\n\t*/\r\n\tif( fMyZ <= 1.0 )\r\n\t{\r\n\t\tfloat zdepth=0.0;\r\n#ifdef SHADOWMAP_PCF3\r\n\t\tif ( nPSNum == 0 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset,\tfMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset,\tfMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset,\tfMyZ );\r\n\t\t\tvalue = value/4.0;\r\n\t\t} \r\n\t\telse if( nPSNum == 1 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\r\n\t\t}\r\n\t\telse if( nPSNum == 2 )\r\n\t\t{\r\n\t\t\tvec4 color = texture2D( shadowMap3,vText.xy );\r\n\t\t\tzdepth = unpackDepth(color);\r\n\t\t\tvalue = float(fMyZ < zdepth);\r\n\t\t}\r\n#endif\r\n#ifdef SHADOWMAP_PCF2\r\n\t\tif ( nPSNum == 0 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\r\n\t\t}\r\n\t\telse if( nPSNum == 1 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\r\n\t\t}\r\n\t\telse if( nPSNum == 2 )\r\n\t\t{\r\n\t\t\tvec4 color = texture2D( shadowMap3,vText.xy );\r\n\t\t\tzdepth = unpackDepth(color);\r\n\t\t\tvalue = float(fMyZ < zdepth);\r\n\t\t}\r\n\r\n#endif\r\n#ifdef SHADOWMAP_PCF1\r\n\t\tif ( nPSNum == 0 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\r\n\t\t}\r\n\t\telse if( nPSNum == 1 )\r\n\t\t{\r\n\t\t\tvec4 color = texture2D( shadowMap2,vText.xy );\r\n\t\t\tzdepth = unpackDepth(color);\r\n\t\t\tvalue = float(fMyZ < zdepth);\r\n\t\t}\r\n\t\telse if( nPSNum == 2 )\r\n\t\t{\r\n\t\t\tvec4 color = texture2D( shadowMap3,vText.xy );\r\n\t\t\tzdepth = unpackDepth(color);\r\n\t\t\tvalue = float(fMyZ < zdepth);\r\n\t\t}\r\n#endif\r\n#ifdef SHADOWMAP_PCF_NO\r\n\t\tvec4 color;\r\n\t\tif ( nPSNum == 0 )\r\n\t\t{\r\n\t\t\tcolor = texture2D( shadowMap1,vText.xy );\r\n\t\t}\r\n\t\telse if( nPSNum == 1 )\r\n\t\t{\r\n\t\t\tcolor = texture2D( shadowMap2,vText.xy );\r\n\t\t}\r\n\t\telse if( nPSNum == 2 )\r\n\t\t{\r\n\t\t\tcolor = texture2D( shadowMap3,vText.xy );\r\n\t\t}\r\n\t\tzdepth = unpackDepth(color);\r\n\t\tvalue = float(fMyZ < zdepth);\r\n#endif\r\n\t}\r\n\treturn value;\r\n}\r\nfloat getShadowPSSM2( sampler2D shadowMap1,sampler2D shadowMap2,mat4 lightShadowVP[4],vec4 pssmDistance,vec2 shadowPCFOffset,vec3 worldPos,float posViewZ,float zBias )\r\n{\r\n\tfloat value = 1.0;\r\n\tint nPSNum = int(posViewZ>pssmDistance.x);\r\n\tnPSNum += int(posViewZ>pssmDistance.y);\r\n\t//真SB,webgl不支持在PS中直接访问数组\r\n\tmat4 lightVP;\r\n\tif( nPSNum == 0 )\r\n\t{\r\n\t\tlightVP = lightShadowVP[1];\r\n\t}\r\n\telse if( nPSNum == 1 )\r\n\t{\r\n\t\tlightVP = lightShadowVP[2];\r\n\t}\r\n\tvec4 vLightMVPPos = lightVP * vec4(worldPos,1.0);\r\n\t//为了效率,在CPU计算/2.0 + 0.5\r\n\t//vec3 vText = (vLightMVPPos.xyz / vLightMVPPos.w)/2.0 + 0.5;\r\n\tvec3 vText = vLightMVPPos.xyz / vLightMVPPos.w;\r\n\tfloat fMyZ = vText.z - zBias;\r\n\t/*\r\n\tbvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\r\n\tbool bInFrustum = all( bInFrustumVec );\r\n\tbvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\r\n\tbool bFrustumTest = all( bFrustumTestVec );\r\n\tif ( bFrustumTest ) \r\n\t*/\r\n\tif( fMyZ <= 1.0 )\r\n\t{\r\n\t\tfloat zdepth=0.0;\r\n#ifdef SHADOWMAP_PCF3\r\n\t\tif ( nPSNum == 0 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset,\tfMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset,\tfMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset,\tfMyZ );\r\n\t\t\tvalue = value/4.0;\r\n\t\t}\r\n\t\telse if( nPSNum == 1 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\r\n\t\t}\r\n#endif\r\n#ifdef SHADOWMAP_PCF2\r\n\t\tif ( nPSNum == 0 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\r\n\t\t}\r\n\t\telse if( nPSNum == 1 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\r\n\t\t}\r\n#endif\r\n#ifdef SHADOWMAP_PCF1\r\n\t\tif ( nPSNum == 0 )\r\n\t\t{\r\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\r\n\t\t}\r\n\t\telse if( nPSNum == 1 )\r\n\t\t{\r\n\t\t\tvec4 color = texture2D( shadowMap2,vText.xy );\r\n\t\t\tzdepth = unpackDepth(color);\r\n\t\t\tvalue = float(fMyZ < zdepth);\r\n\t\t}\r\n#endif\r\n#ifdef SHADOWMAP_PCF_NO\r\n\t\tvec4 color;\r\n\t\tif ( nPSNum == 0 )\r\n\t\t{\r\n\t\t\tcolor = texture2D( shadowMap1,vText.xy );\r\n\t\t}\r\n\t\telse if( nPSNum == 1 )\r\n\t\t{\r\n\t\t\tcolor = texture2D( shadowMap2,vText.xy );\r\n\t\t}\r\n\t\tzdepth = unpackDepth(color);\r\n\t\tvalue = float(fMyZ < zdepth);\r\n#endif\r\n\t}\r\n\treturn value;\r\n}\r\nfloat getShadowPSSM1( sampler2D shadowMap1,vec4 lightMVPPos,vec4 pssmDistance,vec2 shadowPCFOffset,float posViewZ,float zBias )\r\n{\r\n\tfloat value = 1.0;\r\n\tif( posViewZ < pssmDistance.x )\r\n\t{\r\n\t\tvec3 vText = lightMVPPos.xyz / lightMVPPos.w;\r\n\t\tfloat fMyZ = vText.z - zBias;\r\n\t\t/*\r\n\t\tbvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\r\n\t\tbool bInFrustum = all( bInFrustumVec );\r\n\t\tbvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\r\n\t\tbool bFrustumTest = all( bFrustumTestVec );\r\n\t\t*/\r\n\t\tif ( fMyZ <= 1.0 ) \r\n\t\t{\r\n\t\t\tfloat zdepth=0.0;\r\n#ifdef SHADOWMAP_PCF3\r\n\t\t\tvalue = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset,fMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset,fMyZ );\r\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset,fMyZ );\r\n\t\t\tvalue = value/4.0;\r\n#endif\r\n#ifdef SHADOWMAP_PCF2\t\t\r\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\r\n#endif\r\n#ifdef SHADOWMAP_PCF1\r\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\r\n#endif\r\n#ifdef SHADOWMAP_PCF_NO\t\t\r\n\t\t\tvec4 color = texture2D( shadowMap1,vText.xy );\r\n\t\t\tzdepth = unpackDepth(color);\r\n\t\t\tvalue = float(fMyZ < zdepth);\r\n#endif\r\n\t\t}\r\n\t}\r\n\treturn value;\r\n}";
  22377. var SkyBoxPS = "#ifdef HIGHPRECISION\r\nprecision highp float;\r\n#else\r\nprecision mediump float;\r\n#endif\r\n\r\nvarying vec3 v_Texcoord;\r\n\r\nuniform samplerCube u_CubeTexture;\r\nuniform float u_Exposure;\r\nuniform vec4 u_TintColor;\r\n\r\n\r\nvoid main()\r\n{\t\r\n\tvec3 color=textureCube(u_CubeTexture, v_Texcoord).rgb*u_TintColor.rgb*u_Exposure*2.0;\r\n\tgl_FragColor=vec4(color,1.0);\r\n}\r\n\r\n";
  22378. var SkyBoxVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\nuniform mat4 u_ViewProjection;\r\nuniform float u_Rotation;\r\nvarying vec3 v_Texcoord;\r\n\r\n\r\nvec4 rotateAroundYInDegrees (vec4 vertex, float degrees)\r\n{\r\n\tfloat angle = degrees * 3.141593 / 180.0;\r\n\tfloat sina=sin(angle);\r\n\tfloat cosa=cos(angle);\r\n\tmat2 m = mat2(cosa, -sina, sina, cosa);\r\n\treturn vec4(m*vertex.xz, vertex.yw).xzyw;\r\n}\r\n\t\t\r\nvoid main()\r\n{\r\n\tvec4 position=rotateAroundYInDegrees(a_Position,u_Rotation);\r\n\tgl_Position = (u_ViewProjection*position).xyww;\r\n\tv_Texcoord=vec3(-a_Position.x,a_Position.yz);//转换坐标系\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n";
  22379. var SkyBoxProceduralPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Lighting.glsl\";\r\n\r\nconst float MIE_G = -0.990;\r\nconst float MIE_G2 = 0.9801;\r\nconst float SKY_GROUND_THRESHOLD = 0.02;\r\n\r\nuniform float u_SunSize;\r\nuniform float u_SunSizeConvergence;\r\nuniform DirectionLight u_DirectionLight;\r\n\r\n\r\nvarying vec3 v_GroundColor;\r\nvarying vec3 v_SkyColor;\r\n\r\n\r\n#ifdef SUN_HIGH_QUALITY\r\n\tvarying vec3 v_Vertex;\r\n#elif defined(SUN_SIMPLE)\r\n\tvarying vec3 v_RayDir;\r\n#else\r\n\tvarying float v_SkyGroundFactor;\r\n#endif\r\n\r\n#if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\r\n\tvarying vec3 v_SunColor;\r\n#endif\r\n\r\n// Calculates the Mie phase function\r\nfloat getMiePhase(float eyeCos, float eyeCos2) {\r\n\tfloat temp = 1.0 + MIE_G2 - 2.0 * MIE_G * eyeCos;\r\n\ttemp = pow(temp, pow(u_SunSize,0.65) * 10.0);\r\n\ttemp = max(temp,1.0e-4); // prevent division by zero, esp. in half precision\r\n\ttemp = 1.5 * ((1.0 - MIE_G2) / (2.0 + MIE_G2)) * (1.0 + eyeCos2) / temp;\r\n\treturn temp;\r\n}\r\n\r\n// Calculates the sun shape\r\nfloat calcSunAttenuation(vec3 lightPos, vec3 ray) {\r\n\t#ifdef SUN_HIGH_QUALITY\r\n\t\tfloat focusedEyeCos = pow(clamp(dot(lightPos, ray),0.0,1.0), u_SunSizeConvergence);\r\n\t\treturn getMiePhase(-focusedEyeCos, focusedEyeCos * focusedEyeCos);\r\n\t#else //SUN_SIMPLE\r\n\t\tvec3 delta = lightPos - ray;\r\n\t\tfloat dist = length(delta);\r\n\t\tfloat spot = 1.0 - smoothstep(0.0, u_SunSize, dist);\r\n\t\treturn spot * spot;\r\n\t#endif\r\n}\r\n\r\nvoid main() {\r\n\t// if y > 1 [eyeRay.y < -SKY_GROUND_THRESHOLD] - ground\r\n\t// if y >= 0 and < 1 [eyeRay.y <= 0 and > -SKY_GROUND_THRESHOLD] - horizon\r\n\t// if y < 0 [eyeRay.y > 0] - sky\r\n\tvec3 col = vec3(0.0, 0.0, 0.0);\r\n\r\n\t#ifdef SUN_HIGH_QUALITY\r\n\t\tvec3 ray = normalize(v_Vertex);\r\n\t\tfloat y = ray.y / SKY_GROUND_THRESHOLD;\r\n\t#elif defined(SUN_SIMPLE) \r\n\t\tvec3 ray = v_RayDir;\r\n\t\tfloat y = ray.y / SKY_GROUND_THRESHOLD;\t\r\n\t#else\r\n\t\tfloat y = v_SkyGroundFactor;\r\n\t#endif\r\n\r\n\t// if we did precalculate color in vprog: just do lerp between them\r\n\tcol = mix(v_SkyColor, v_GroundColor, clamp(y,0.0,1.0));\r\n\r\n\t#if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\r\n\t\tif (y < 0.0)\r\n\t\t\tcol += v_SunColor * calcSunAttenuation(-u_DirectionLight.Direction, -ray);\r\n\t#endif\r\n\r\n\tcol = sqrt(col);//linear space convert to gamma space\r\n\tgl_FragColor=vec4(col,1.0);\r\n}\r\n\r\n";
  22380. var SkyBoxProceduralVS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Lighting.glsl\";\r\n\r\n#define OUTER_RADIUS 1.025\r\n#define RAYLEIGH (mix(0.0, 0.0025, pow(u_AtmosphereThickness,2.5)))// Rayleigh constant Rayleigh为夜空光和极光亮度单位\r\n#define MIE 0.0010 // Mie constant 米氏散射\r\n#define SUN_BRIGHTNESS 20.0 // Sun brightness\r\n#define MAX_SCATTER 50.0 // Maximum scattering value, to prevent math overflows on Adrenos\r\n\r\nconst float SKY_GROUND_THRESHOLD = 0.02;\r\nconst float outerRadius = OUTER_RADIUS;\r\nconst float outerRadius2 = OUTER_RADIUS*OUTER_RADIUS;\r\nconst float innerRadius = 1.0;\r\nconst float innerRadius2 = 1.0;\r\nconst float cameraHeight = 0.0001;\r\n\r\nconst float HDSundiskIntensityFactor = 15.0;\r\nconst float simpleSundiskIntensityFactor = 27.0;\r\n\r\nconst float sunScale = 400.0 * SUN_BRIGHTNESS;\r\nconst float kmESun = MIE * SUN_BRIGHTNESS;\r\nconst float km4PI = MIE * 4.0 * 3.14159265;\r\nconst float scale = 1.0 / (OUTER_RADIUS - 1.0);\r\nconst float scaleDepth = 0.25;\r\nconst float scaleOverScaleDepth = (1.0 / (OUTER_RADIUS - 1.0)) / 0.25;\r\nconst float samples = 2.0; // THIS IS UNROLLED MANUALLY, DON'T TOUCH\r\n\r\n// RGB wavelengths .35 (.62=158), .43 (.68=174), .525 (.75=190)\r\nconst vec3 c_DefaultScatteringWavelength = vec3(0.65, 0.57, 0.475);//默认散射波长\r\nconst vec3 c_VariableRangeForScatteringWavelength = vec3(0.15, 0.15, 0.15);//散射播放的可变范围\r\n\r\nattribute vec4 a_Position;\r\n\r\nuniform mat4 u_ViewProjection;\r\nuniform vec3 u_SkyTint;\r\nuniform vec3 u_GroundTint;\r\nuniform float u_Exposure;\r\nuniform float u_AtmosphereThickness;\r\nuniform DirectionLight u_DirectionLight;\r\n\r\nvarying vec3 v_GroundColor;\r\nvarying vec3 v_SkyColor;\r\n\r\n#ifdef SUN_HIGH_QUALITY\r\n\tvarying vec3 v_Vertex;\r\n#elif defined(SUN_SIMPLE)\r\n\tvarying vec3 v_RayDir;\r\n#else\r\n\tvarying float v_SkyGroundFactor;\r\n#endif\r\n\r\n#if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\r\n\tvarying vec3 v_SunColor;\r\n#endif\r\n\r\n// Calculates the Rayleigh phase function\r\nfloat getRayleighPhase(vec3 light, vec3 ray) \r\n{\r\n\tfloat eyeCos = dot(light, ray);\r\n\treturn 0.75 + 0.75*eyeCos*eyeCos;\r\n}\r\n\r\nfloat scaleAngle(float inCos)\r\n{\r\n\tfloat x = 1.0 - inCos;\r\n\treturn 0.25 * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));\r\n}\r\n\r\n\r\nvoid main () {\r\n\tgl_Position = (u_ViewProjection*a_Position).xyww;\r\n\r\n\tvec3 skyTintInGammaSpace = u_SkyTint;//支持非GAMMA空间后要调整\r\n\tvec3 scatteringWavelength = mix(c_DefaultScatteringWavelength-c_VariableRangeForScatteringWavelength,c_DefaultScatteringWavelength+c_VariableRangeForScatteringWavelength,vec3(1.0) - skyTintInGammaSpace); // using Tint in sRGB+ gamma allows for more visually linear interpolation and to keep (0.5) at (128, gray in sRGB) point\r\n\tvec3 invWavelength = 1.0 / pow(scatteringWavelength, vec3(4.0));\r\n\r\n\tfloat krESun = RAYLEIGH * SUN_BRIGHTNESS;\r\n\tfloat kr4PI = RAYLEIGH * 4.0 * 3.14159265;\r\n\r\n\tvec3 cameraPos = vec3(0.0,innerRadius + cameraHeight,0.0); // The camera's current position\r\n\r\n\t// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)\r\n\tvec3 eyeRay = normalize(a_Position.xyz);\r\n\r\n\tfloat far = 0.0;\r\n\tvec3 cIn, cOut;\r\n\tif (eyeRay.y >= 0.0) {// Sky\r\n\t\t// Calculate the length of the \"atmosphere\"\r\n\t\tfar = sqrt(outerRadius2 + innerRadius2 * eyeRay.y * eyeRay.y - innerRadius2) - innerRadius * eyeRay.y;\r\n\r\n\t\t// Calculate the ray's starting position, then calculate its scattering offset\r\n\t\tfloat height = innerRadius + cameraHeight;\r\n\t\tfloat depth = exp(scaleOverScaleDepth * -cameraHeight);\r\n\t\tfloat startAngle = dot(eyeRay, cameraPos) / height;\r\n\t\tfloat startOffset = depth*scaleAngle(startAngle);\r\n\r\n\t\t// Initialize the scattering loop variables\r\n\t\tfloat sampleLength = far / samples;\r\n\t\tfloat scaledLength = sampleLength * scale;\r\n\t\tvec3 sampleRay = eyeRay * sampleLength;\r\n\t\tvec3 samplePoint = cameraPos + sampleRay * 0.5;\r\n\r\n\t\tvec3 frontColor = vec3(0.0);\r\n\t\t//unrolling this manually to avoid some platform for loop slow\r\n\t\t{\r\n\t\t\tfloat height = length(samplePoint);\r\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\r\n\t\t\tfloat lightAngle = dot(-u_DirectionLight.Direction, samplePoint) / height;\r\n\t\t\tfloat cameraAngle = dot(eyeRay, samplePoint) / height;\r\n\t\t\tfloat scatter = (startOffset + depth*(scaleAngle(lightAngle) - scaleAngle(cameraAngle)));\r\n\t\t\tvec3 attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\r\n\r\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\r\n\t\t\tsamplePoint += sampleRay;\r\n\t\t}\r\n\t\t{\r\n\t\t\tfloat height = length(samplePoint);\r\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\r\n\t\t\tfloat lightAngle = dot(-u_DirectionLight.Direction, samplePoint) / height;\r\n\t\t\tfloat cameraAngle = dot(eyeRay, samplePoint) / height;\r\n\t\t\tfloat scatter = (startOffset + depth*(scaleAngle(lightAngle) - scaleAngle(cameraAngle)));\r\n\t\t\tvec3 attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\r\n\r\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\r\n\t\t\tsamplePoint += sampleRay;\r\n\t\t}\r\n\r\n\t\t// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader\r\n\t\tcIn = frontColor * (invWavelength * krESun);\r\n\t\tcOut = frontColor * kmESun;\r\n\t} else {// Ground\r\n\t\tfar = (-cameraHeight) / (min(-0.001, eyeRay.y));\r\n\t\tvec3 pos = cameraPos + far * eyeRay;\r\n\r\n\t\t// Calculate the ray's starting position, then calculate its scattering offset\r\n\t\tfloat depth = exp((-cameraHeight) * (1.0/scaleDepth));\r\n\t\tfloat cameraAngle = dot(-eyeRay, pos);\r\n\t\tfloat lightAngle = dot(-u_DirectionLight.Direction, pos);\r\n\t\tfloat cameraScale = scaleAngle(cameraAngle);\r\n\t\tfloat lightScale = scaleAngle(lightAngle);\r\n\t\tfloat cameraOffset = depth*cameraScale;\r\n\t\tfloat temp = lightScale + cameraScale;\r\n\r\n\t\t// Initialize the scattering loop variables\r\n\t\tfloat sampleLength = far / samples;\r\n\t\tfloat scaledLength = sampleLength * scale;\r\n\t\tvec3 sampleRay = eyeRay * sampleLength;\r\n\t\tvec3 samplePoint = cameraPos + sampleRay * 0.5;\r\n\r\n\t\t// Now loop through the sample rays\r\n\t\tvec3 frontColor = vec3(0.0, 0.0, 0.0);\r\n\t\tvec3 attenuate;\r\n\r\n\t\t// Loop removed because we kept hitting SM2.0 temp variable limits. Doesn't affect the image too much.\r\n\t\t{\r\n\t\t\tfloat height = length(samplePoint);\r\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\r\n\t\t\tfloat scatter = depth*temp - cameraOffset;\r\n\t\t\tattenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\r\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\r\n\t\t\tsamplePoint += sampleRay;\r\n\t\t}\r\n\r\n\t\tcIn = frontColor * (invWavelength * krESun + kmESun);\r\n\t\tcOut = clamp(attenuate, 0.0, 1.0);\r\n\t}\r\n\r\n\t#ifdef SUN_HIGH_QUALITY\r\n\t\tv_Vertex = -a_Position.xyz;\r\n\t#elif defined(SUN_SIMPLE) \r\n\t\tv_RayDir = -eyeRay;\r\n\t#else\r\n\t\tv_SkyGroundFactor = -eyeRay.y / SKY_GROUND_THRESHOLD;\r\n\t#endif\r\n\r\n\t// if we want to calculate color in vprog:\r\n\t// in case of linear: multiply by _Exposure in here (even in case of lerp it will be common multiplier, so we can skip mul in fshader)\r\n\tv_GroundColor = u_Exposure * (cIn + u_GroundTint*u_GroundTint * cOut);//u_GroundColor*u_GroundColor is gamma space convert to linear space\r\n\tv_SkyColor = u_Exposure * (cIn * getRayleighPhase(-u_DirectionLight.Direction, -eyeRay));\r\n\r\n\t\r\n\t// The sun should have a stable intensity in its course in the sky. Moreover it should match the highlight of a purely specular material.\r\n\t// This matching was done using the Unity3D standard shader BRDF1 on the 5/31/2017\r\n\t// Finally we want the sun to be always bright even in LDR thus the normalization of the lightColor for low intensity.\r\n\tfloat lightColorIntensity = clamp(length(u_DirectionLight.Color), 0.25, 1.0);\r\n\r\n\t#ifdef SUN_HIGH_QUALITY \r\n\t\tv_SunColor = HDSundiskIntensityFactor * clamp(cOut,0.0,1.0) * u_DirectionLight.Color / lightColorIntensity;\r\n\t#elif defined(SUN_SIMPLE) \r\n\t\tv_SunColor = simpleSundiskIntensityFactor * clamp(cOut * sunScale,0.0,1.0) * u_DirectionLight.Color / lightColorIntensity;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n";
  22381. var TrailPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\nuniform sampler2D u_MainTexture;\r\nuniform vec4 u_MainColor;\r\n\r\nvarying vec2 v_Texcoord0;\r\nvarying vec4 v_Color;\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = 2.0 * u_MainColor * v_Color;\r\n\t#ifdef MAINTEXTURE\r\n\t\tvec4 mainTextureColor = texture2D(u_MainTexture, v_Texcoord0);\r\n\t\tcolor *= mainTextureColor;\r\n\t#endif\r\n\tgl_FragColor = color;\r\n}\r\n\r\n ";
  22382. var TrailVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec3 a_Position;\r\nattribute vec3 a_OffsetVector;\r\nattribute vec4 a_Color;\r\nattribute float a_Texcoord0X;\r\nattribute float a_Texcoord0Y;\r\nattribute float a_BirthTime;\r\n\r\nuniform mat4 u_View;\r\nuniform mat4 u_Projection;\r\n\r\nuniform vec4 u_TilingOffset;\r\n\r\nuniform float u_CurTime;\r\nuniform float u_LifeTime;\r\nuniform vec4 u_WidthCurve[10];\r\nuniform int u_WidthCurveKeyLength;\r\n\r\nvarying vec2 v_Texcoord0;\r\nvarying vec4 v_Color;\r\n\r\nfloat hermiteInterpolate(float t, float outTangent, float inTangent, float duration, float value1, float value2)\r\n{\r\n\tfloat t2 = t * t;\r\n\tfloat t3 = t2 * t;\r\n\tfloat a = 2.0 * t3 - 3.0 * t2 + 1.0;\r\n\tfloat b = t3 - 2.0 * t2 + t;\r\n\tfloat c = t3 - t2;\r\n\tfloat d = -2.0 * t3 + 3.0 * t2;\r\n\treturn a * value1 + b * outTangent * duration + c * inTangent * duration + d * value2;\r\n}\r\n\r\nfloat getCurWidth(in float normalizeTime)\r\n{\r\n\tfloat width;\r\n\tif(normalizeTime == 0.0){\r\n\t\twidth=u_WidthCurve[0].w;\r\n\t}\r\n\telse if(normalizeTime >= 1.0){\r\n\t\twidth=u_WidthCurve[u_WidthCurveKeyLength - 1].w;\r\n\t}\r\n\telse{\r\n\t\tfor(int i = 0; i < 10; i ++ )\r\n\t\t{\r\n\t\t\tif(normalizeTime == u_WidthCurve[i].x){\r\n\t\t\t\twidth=u_WidthCurve[i].w;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvec4 lastFrame = u_WidthCurve[i];\r\n\t\t\tvec4 nextFrame = u_WidthCurve[i + 1];\r\n\t\t\tif(normalizeTime > lastFrame.x && normalizeTime < nextFrame.x)\r\n\t\t\t{\r\n\t\t\t\tfloat duration = nextFrame.x - lastFrame.x;\r\n\t\t\t\tfloat t = (normalizeTime - lastFrame.x) / duration;\r\n\t\t\t\tfloat outTangent = lastFrame.z;\r\n\t\t\t\tfloat inTangent = nextFrame.y;\r\n\t\t\t\tfloat value1 = lastFrame.w;\r\n\t\t\t\tfloat value2 = nextFrame.w;\r\n\t\t\t\twidth=hermiteInterpolate(t, outTangent, inTangent, duration, value1, value2);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn width;\r\n}\t\r\n\r\nvoid main()\r\n{\r\n\tfloat normalizeTime = (u_CurTime - a_BirthTime) / u_LifeTime;\r\n\t\r\n\t#ifdef TILINGOFFSET\r\n\t\tv_Texcoord0 = vec2(a_Texcoord0X, 1.0 - a_Texcoord0Y) * u_TilingOffset.xy + u_TilingOffset.zw;\r\n\t#else\r\n\t\tv_Texcoord0 = vec2(a_Texcoord0X, a_Texcoord0Y);\r\n\t#endif\r\n\t\r\n\tv_Color = a_Color;\r\n\t\r\n\tgl_Position = u_Projection * u_View * vec4(a_Position + a_OffsetVector * getCurWidth(normalizeTime),1.0);\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n";
  22383. var UnlitPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\tvarying vec4 v_Color;\r\n#endif\r\n\r\n#ifdef ALBEDOTEXTURE\r\n\tuniform sampler2D u_AlbedoTexture;\r\n\tvarying vec2 v_Texcoord0;\r\n#endif\r\n\r\nuniform vec4 u_AlbedoColor;\r\n\r\n#ifdef ALPHATEST\r\n\tuniform float u_AlphaTestValue;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\t#ifdef ADDTIVEFOG\r\n\t#else\r\n\t\tuniform vec3 u_FogColor;\r\n\t#endif\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = u_AlbedoColor;\r\n\t#ifdef ALBEDOTEXTURE\r\n\t\tcolor *= texture2D(u_AlbedoTexture, v_Texcoord0);\r\n\t#endif\r\n\t#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\t\tcolor *= v_Color;\r\n\t#endif\r\n\t\r\n\t#ifdef ALPHATEST\r\n\t\tif(color.a < u_AlphaTestValue)\r\n\t\t\tdiscard;\r\n\t#endif\r\n\t\r\n\tgl_FragColor = color;\r\n\t\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\r\n\t\t#ifdef ADDTIVEFOG\r\n\t\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.0), lerpFact);\r\n\t\t#else\r\n\t\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n}\r\n\r\n";
  22384. var UnlitVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\n\r\nattribute vec2 a_Texcoord0;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\n\r\nattribute vec4 a_Color;\r\nvarying vec4 v_Color;\r\nvarying vec2 v_Texcoord0;\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\nvoid main() {\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\tposition=skinTransform*a_Position;\r\n\t#else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\r\n\t#ifdef TILINGOFFSET\r\n\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t#else\r\n\t\tv_Texcoord0=a_Texcoord0;\r\n\t#endif\r\n\r\n\t#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\t\tv_Color = a_Color;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}";
  22385. var WaterPrimaryPS = "#ifdef HIGHPRECISION\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#ifdef MAINTEXTURE\r\n\tuniform sampler2D u_MainTexture;\r\n#endif\r\n\r\n#ifdef NORMALTEXTURE\r\n\tuniform sampler2D u_NormalTexture;\r\n#endif\r\n\r\nuniform vec4 u_HorizonColor;\r\n\r\nvarying vec3 v_Normal;\r\nvarying vec3 v_Tangent;\r\nvarying vec3 v_Binormal;\r\nvarying vec3 v_ViewDir;\r\nvarying vec2 v_Texcoord0;\r\nvarying vec2 v_Texcoord1;\r\n\r\n#include \"Lighting.glsl\"\r\n\r\nvoid main()\r\n{\r\n\tvec4 bumpColor1 = texture2D(u_NormalTexture, v_Texcoord0);\r\n\tvec4 bumpColor2 = texture2D(u_NormalTexture, v_Texcoord1);\r\n\t\r\n\tvec3 normal1 = NormalSampleToWorldSpace1(bumpColor1, v_Tangent, v_Binormal, v_Normal);\r\n\tvec3 normal2 = NormalSampleToWorldSpace1(bumpColor2, v_Tangent, v_Binormal, v_Normal);\r\n\t\r\n\tvec3 normal = normalize((normal1 + normal2) * 0.5);\r\n\tvec3 viewDir = normalize(v_ViewDir);\r\n\tfloat fresnel = dot(viewDir, normal);\r\n\t\r\n\tvec4 waterColor = texture2D(u_MainTexture, vec2(fresnel, fresnel));\r\n\t\r\n\tvec4 color;\r\n\tcolor.rgb = mix(waterColor.rgb, u_HorizonColor.rgb, vec3(waterColor.a));\r\n\tcolor.a = u_HorizonColor.a;\r\n\t\r\n\tgl_FragColor = color;\r\n}\r\n\r\n";
  22386. var WaterPrimaryVS = "#include \"Lighting.glsl\";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec3 a_Normal;\r\nattribute vec4 a_Tangent0;\r\n\r\nuniform mat4 u_MvpMatrix;\r\nuniform mat4 u_WorldMat;\r\nuniform vec3 u_CameraPos;\r\nuniform float u_WaveScale;\r\nuniform vec4 u_WaveSpeed;\r\nuniform float u_Time;\r\n\r\nvarying vec3 v_Normal;\r\nvarying vec3 v_Tangent;\r\nvarying vec3 v_Binormal;\r\nvarying vec3 v_ViewDir;\r\nvarying vec2 v_Texcoord0;\r\nvarying vec2 v_Texcoord1;\r\n\r\nvoid main()\r\n{\r\n\tvec4 positionWorld = u_WorldMat * a_Position;\r\n\tvec4 position = u_MvpMatrix * a_Position;\r\n\t\r\n\tvec4 temp = vec4(positionWorld.x, positionWorld.z, positionWorld.x, positionWorld.z) * u_WaveScale + u_WaveSpeed * u_WaveScale * u_Time;\r\n\t\r\n\tv_Texcoord0 = temp.xy * vec2(0.4, 0.45);\r\n\tv_Texcoord1 = temp.wz;\r\n\t\r\n\tmat3 worldMat = mat3(u_WorldMat);\r\n\tv_Normal = worldMat * a_Normal;\r\n\tv_Tangent = worldMat * a_Tangent0.xyz;\r\n\tv_Binormal = cross(v_Normal, v_Tangent) * a_Tangent0.w;\r\n\t\r\n\tv_ViewDir = u_CameraPos - positionWorld.xyz;\r\n\tgl_Position = position;\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}";
  22387. class ShaderInit3D {
  22388. constructor() {
  22389. }
  22390. static __init__() {
  22391. ShaderInit3D._rangeAttenTex = Utils3D._buildTexture2D(1024, 1, Laya.BaseTexture.FORMAT_ALPHA8, TextureGenerator.lightAttenTexture);
  22392. ShaderInit3D._rangeAttenTex.wrapModeU = Laya.BaseTexture.WARPMODE_CLAMP;
  22393. ShaderInit3D._rangeAttenTex.wrapModeV = Laya.BaseTexture.WARPMODE_CLAMP;
  22394. ShaderInit3D._rangeAttenTex.lock = true;
  22395. Shader3D.SHADERDEFINE_HIGHPRECISION = Shader3D.registerPublicDefine("HIGHPRECISION");
  22396. Shader3D.addInclude("Lighting.glsl", LightingGLSL);
  22397. Shader3D.addInclude("ShadowHelper.glsl", ShadowHelperGLSL);
  22398. Shader3D.addInclude("BRDF.glsl", BRDFGLSL);
  22399. Shader3D.addInclude("PBRUtils.glsl", PBRUtilsGLSL);
  22400. Shader3D.addInclude("PBRStandardLighting.glsl", PBRStandardLightingGLSL);
  22401. Shader3D.addInclude("PBRSpecularLighting.glsl", PBRSpecularLightingGLSL);
  22402. Shader3D.addInclude("Colors.glsl", ColorsGLSL);
  22403. Shader3D.addInclude("Sampling.glsl", SamplingGLSL);
  22404. Shader3D.addInclude("StdLib.glsl", StdLibGLSL);
  22405. var attributeMap = {
  22406. 'a_Position': VertexMesh.MESH_POSITION0,
  22407. 'a_Color': VertexMesh.MESH_COLOR0,
  22408. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22409. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22410. 'a_Texcoord1': VertexMesh.MESH_TEXTURECOORDINATE1,
  22411. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22412. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22413. 'a_Tangent0': VertexMesh.MESH_TANGENT0,
  22414. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0,
  22415. 'a_WorldMat': VertexMesh.MESH_WORLDMATRIX_ROW0
  22416. };
  22417. var uniformMap = {
  22418. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22419. 'u_DiffuseTexture': Shader3D.PERIOD_MATERIAL,
  22420. 'u_SpecularTexture': Shader3D.PERIOD_MATERIAL,
  22421. 'u_NormalTexture': Shader3D.PERIOD_MATERIAL,
  22422. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22423. 'u_DiffuseColor': Shader3D.PERIOD_MATERIAL,
  22424. 'u_MaterialSpecular': Shader3D.PERIOD_MATERIAL,
  22425. 'u_Shininess': Shader3D.PERIOD_MATERIAL,
  22426. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22427. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22428. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22429. 'u_LightmapScaleOffset': Shader3D.PERIOD_SPRITE,
  22430. 'u_LightMap': Shader3D.PERIOD_SPRITE,
  22431. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22432. 'u_ReflectTexture': Shader3D.PERIOD_SCENE,
  22433. 'u_ReflectIntensity': Shader3D.PERIOD_SCENE,
  22434. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22435. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22436. 'u_FogColor': Shader3D.PERIOD_SCENE,
  22437. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE,
  22438. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22439. 'u_PointLight.Position': Shader3D.PERIOD_SCENE,
  22440. 'u_PointLight.Range': Shader3D.PERIOD_SCENE,
  22441. 'u_PointLight.Color': Shader3D.PERIOD_SCENE,
  22442. 'u_SpotLight.Position': Shader3D.PERIOD_SCENE,
  22443. 'u_SpotLight.Direction': Shader3D.PERIOD_SCENE,
  22444. 'u_SpotLight.Range': Shader3D.PERIOD_SCENE,
  22445. 'u_SpotLight.Spot': Shader3D.PERIOD_SCENE,
  22446. 'u_SpotLight.Color': Shader3D.PERIOD_SCENE,
  22447. 'u_AmbientColor': Shader3D.PERIOD_SCENE,
  22448. 'u_shadowMap1': Shader3D.PERIOD_SCENE,
  22449. 'u_shadowMap2': Shader3D.PERIOD_SCENE,
  22450. 'u_shadowMap3': Shader3D.PERIOD_SCENE,
  22451. 'u_shadowPSSMDistance': Shader3D.PERIOD_SCENE,
  22452. 'u_lightShadowVP': Shader3D.PERIOD_SCENE,
  22453. 'u_shadowPCFoffset': Shader3D.PERIOD_SCENE
  22454. };
  22455. var stateMap = {
  22456. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22457. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22458. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22459. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22460. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22461. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22462. };
  22463. var shader = Shader3D.add("BLINNPHONG", null, null, true);
  22464. var subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, BlinnPhongMaterial.shaderDefines);
  22465. shader.addSubShader(subShader);
  22466. subShader.addShaderPass(MeshBlinnPhongVS, MeshBlinnPhongPS, stateMap);
  22467. attributeMap = {
  22468. 'a_Position': VertexMesh.MESH_POSITION0,
  22469. 'a_Color': VertexMesh.MESH_COLOR0
  22470. };
  22471. uniformMap = {
  22472. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22473. 'u_Color': Shader3D.PERIOD_MATERIAL
  22474. };
  22475. stateMap = {
  22476. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22477. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22478. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22479. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22480. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22481. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22482. };
  22483. shader = Shader3D.add("LineShader");
  22484. subShader = new SubShader(attributeMap, uniformMap);
  22485. shader.addSubShader(subShader);
  22486. subShader.addShaderPass(lineVS, linePS, stateMap);
  22487. attributeMap = {
  22488. 'a_Position': VertexMesh.MESH_POSITION0,
  22489. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22490. 'a_Tangent0': VertexMesh.MESH_TANGENT0,
  22491. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22492. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22493. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22494. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0,
  22495. 'a_WorldMat': VertexMesh.MESH_WORLDMATRIX_ROW0
  22496. };
  22497. uniformMap = {
  22498. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22499. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22500. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22501. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22502. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22503. 'u_AlbedoColor': Shader3D.PERIOD_MATERIAL,
  22504. 'u_EmissionColor': Shader3D.PERIOD_MATERIAL,
  22505. 'u_AlbedoTexture': Shader3D.PERIOD_MATERIAL,
  22506. 'u_NormalTexture': Shader3D.PERIOD_MATERIAL,
  22507. 'u_ParallaxTexture': Shader3D.PERIOD_MATERIAL,
  22508. 'u_MetallicGlossTexture': Shader3D.PERIOD_MATERIAL,
  22509. 'u_OcclusionTexture': Shader3D.PERIOD_MATERIAL,
  22510. 'u_EmissionTexture': Shader3D.PERIOD_MATERIAL,
  22511. 'u_metallic': Shader3D.PERIOD_MATERIAL,
  22512. 'u_smoothness': Shader3D.PERIOD_MATERIAL,
  22513. 'u_smoothnessScale': Shader3D.PERIOD_MATERIAL,
  22514. 'u_occlusionStrength': Shader3D.PERIOD_MATERIAL,
  22515. 'u_normalScale': Shader3D.PERIOD_MATERIAL,
  22516. 'u_parallaxScale': Shader3D.PERIOD_MATERIAL,
  22517. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22518. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22519. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE,
  22520. 'u_PointLightMatrix': Shader3D.PERIOD_SCENE,
  22521. 'u_PointLight.Position': Shader3D.PERIOD_SCENE,
  22522. 'u_PointLight.Range': Shader3D.PERIOD_SCENE,
  22523. 'u_PointLight.Color': Shader3D.PERIOD_SCENE,
  22524. 'u_SpotLight.Position': Shader3D.PERIOD_SCENE,
  22525. 'u_SpotLight.Direction': Shader3D.PERIOD_SCENE,
  22526. 'u_SpotLight.Range': Shader3D.PERIOD_SCENE,
  22527. 'u_SpotLight.SpotAngle': Shader3D.PERIOD_SCENE,
  22528. 'u_SpotLight.Color': Shader3D.PERIOD_SCENE,
  22529. 'u_RangeTexture': Shader3D.PERIOD_SCENE,
  22530. 'u_ReflectTexture': Shader3D.PERIOD_SCENE,
  22531. 'u_ReflectIntensity': Shader3D.PERIOD_SCENE,
  22532. 'u_AmbientColor': Shader3D.PERIOD_SCENE,
  22533. 'u_shadowMap1': Shader3D.PERIOD_SCENE,
  22534. 'u_shadowMap2': Shader3D.PERIOD_SCENE,
  22535. 'u_shadowMap3': Shader3D.PERIOD_SCENE,
  22536. 'u_shadowPSSMDistance': Shader3D.PERIOD_SCENE,
  22537. 'u_lightShadowVP': Shader3D.PERIOD_SCENE,
  22538. 'u_shadowPCFoffset': Shader3D.PERIOD_SCENE,
  22539. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22540. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22541. 'u_FogColor': Shader3D.PERIOD_SCENE
  22542. };
  22543. stateMap = {
  22544. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22545. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22546. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22547. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22548. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22549. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22550. };
  22551. shader = Shader3D.add("PBRStandard", null, null, true);
  22552. subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, PBRStandardMaterial.shaderDefines);
  22553. shader.addSubShader(subShader);
  22554. subShader.addShaderPass(PBRStandardVS, PBRStandardPS, stateMap);
  22555. attributeMap = {
  22556. 'a_Position': VertexMesh.MESH_POSITION0,
  22557. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22558. 'a_Tangent0': VertexMesh.MESH_TANGENT0,
  22559. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22560. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22561. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22562. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0,
  22563. 'a_WorldMat': VertexMesh.MESH_WORLDMATRIX_ROW0
  22564. };
  22565. uniformMap = {
  22566. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22567. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22568. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22569. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22570. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22571. 'u_AlbedoColor': Shader3D.PERIOD_MATERIAL,
  22572. 'u_SpecularColor': Shader3D.PERIOD_MATERIAL,
  22573. 'u_EmissionColor': Shader3D.PERIOD_MATERIAL,
  22574. 'u_AlbedoTexture': Shader3D.PERIOD_MATERIAL,
  22575. 'u_NormalTexture': Shader3D.PERIOD_MATERIAL,
  22576. 'u_ParallaxTexture': Shader3D.PERIOD_MATERIAL,
  22577. 'u_SpecularTexture': Shader3D.PERIOD_MATERIAL,
  22578. 'u_OcclusionTexture': Shader3D.PERIOD_MATERIAL,
  22579. 'u_EmissionTexture': Shader3D.PERIOD_MATERIAL,
  22580. 'u_smoothness': Shader3D.PERIOD_MATERIAL,
  22581. 'u_smoothnessScale': Shader3D.PERIOD_MATERIAL,
  22582. 'u_occlusionStrength': Shader3D.PERIOD_MATERIAL,
  22583. 'u_normalScale': Shader3D.PERIOD_MATERIAL,
  22584. 'u_parallaxScale': Shader3D.PERIOD_MATERIAL,
  22585. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22586. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22587. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE,
  22588. 'u_PointLightMatrix': Shader3D.PERIOD_SCENE,
  22589. 'u_PointLight.Position': Shader3D.PERIOD_SCENE,
  22590. 'u_PointLight.Range': Shader3D.PERIOD_SCENE,
  22591. 'u_PointLight.Color': Shader3D.PERIOD_SCENE,
  22592. 'u_SpotLight.Position': Shader3D.PERIOD_SCENE,
  22593. 'u_SpotLight.Direction': Shader3D.PERIOD_SCENE,
  22594. 'u_SpotLight.Range': Shader3D.PERIOD_SCENE,
  22595. 'u_SpotLight.SpotAngle': Shader3D.PERIOD_SCENE,
  22596. 'u_SpotLight.Color': Shader3D.PERIOD_SCENE,
  22597. 'u_RangeTexture': Shader3D.PERIOD_SCENE,
  22598. 'u_ReflectTexture': Shader3D.PERIOD_SCENE,
  22599. 'u_ReflectIntensity': Shader3D.PERIOD_SCENE,
  22600. 'u_AmbientColor': Shader3D.PERIOD_SCENE,
  22601. 'u_shadowMap1': Shader3D.PERIOD_SCENE,
  22602. 'u_shadowMap2': Shader3D.PERIOD_SCENE,
  22603. 'u_shadowMap3': Shader3D.PERIOD_SCENE,
  22604. 'u_shadowPSSMDistance': Shader3D.PERIOD_SCENE,
  22605. 'u_lightShadowVP': Shader3D.PERIOD_SCENE,
  22606. 'u_shadowPCFoffset': Shader3D.PERIOD_SCENE,
  22607. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22608. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22609. 'u_FogColor': Shader3D.PERIOD_SCENE
  22610. };
  22611. stateMap = {
  22612. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22613. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22614. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22615. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22616. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22617. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22618. };
  22619. shader = Shader3D.add("PBRSpecular", null, null, true);
  22620. subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, PBRSpecularMaterial.shaderDefines);
  22621. shader.addSubShader(subShader);
  22622. subShader.addShaderPass(PBRSpecularVS, PBRSpecularPS, stateMap);
  22623. attributeMap = {
  22624. 'a_Position': VertexMesh.MESH_POSITION0,
  22625. 'a_Color': VertexMesh.MESH_COLOR0,
  22626. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22627. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22628. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22629. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0
  22630. };
  22631. uniformMap = {
  22632. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22633. 'u_AlbedoTexture': Shader3D.PERIOD_MATERIAL,
  22634. 'u_AlbedoColor': Shader3D.PERIOD_MATERIAL,
  22635. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22636. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22637. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22638. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22639. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22640. 'u_FogColor': Shader3D.PERIOD_SCENE
  22641. };
  22642. stateMap = {
  22643. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22644. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22645. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22646. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22647. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22648. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22649. };
  22650. shader = Shader3D.add("Unlit", null, null, true);
  22651. subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, UnlitMaterial.shaderDefines);
  22652. shader.addSubShader(subShader);
  22653. subShader.addShaderPass(UnlitVS, UnlitPS, stateMap);
  22654. attributeMap = {
  22655. 'a_Position': VertexMesh.MESH_POSITION0,
  22656. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22657. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22658. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22659. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0
  22660. };
  22661. uniformMap = {
  22662. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22663. 'u_AlbedoTexture': Shader3D.PERIOD_MATERIAL,
  22664. 'u_AlbedoColor': Shader3D.PERIOD_MATERIAL,
  22665. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22666. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22667. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22668. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22669. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22670. 'u_FogColor': Shader3D.PERIOD_SCENE
  22671. };
  22672. stateMap = {
  22673. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22674. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22675. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22676. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22677. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22678. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22679. };
  22680. shader = Shader3D.add("Effect", null, null, true);
  22681. subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, EffectMaterial.shaderDefines);
  22682. shader.addSubShader(subShader);
  22683. subShader.addShaderPass(EffectVS, EffectPS, stateMap);
  22684. attributeMap = {
  22685. 'a_CornerTextureCoordinate': VertexShuriKenParticle.PARTICLE_CORNERTEXTURECOORDINATE0,
  22686. 'a_MeshPosition': VertexShuriKenParticle.PARTICLE_POSITION0,
  22687. 'a_MeshColor': VertexShuriKenParticle.PARTICLE_COLOR0,
  22688. 'a_MeshTextureCoordinate': VertexShuriKenParticle.PARTICLE_TEXTURECOORDINATE0,
  22689. 'a_ShapePositionStartLifeTime': VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME,
  22690. 'a_DirectionTime': VertexShuriKenParticle.PARTICLE_DIRECTIONTIME,
  22691. 'a_StartColor': VertexShuriKenParticle.PARTICLE_STARTCOLOR0,
  22692. 'a_EndColor': VertexShuriKenParticle.PARTICLE_ENDCOLOR0,
  22693. 'a_StartSize': VertexShuriKenParticle.PARTICLE_STARTSIZE,
  22694. 'a_StartRotation0': VertexShuriKenParticle.PARTICLE_STARTROTATION,
  22695. 'a_StartSpeed': VertexShuriKenParticle.PARTICLE_STARTSPEED,
  22696. 'a_Random0': VertexShuriKenParticle.PARTICLE_RANDOM0,
  22697. 'a_Random1': VertexShuriKenParticle.PARTICLE_RANDOM1,
  22698. 'a_SimulationWorldPostion': VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION,
  22699. 'a_SimulationWorldRotation': VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION
  22700. };
  22701. uniformMap = {
  22702. 'u_Tintcolor': Shader3D.PERIOD_MATERIAL,
  22703. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22704. 'u_texture': Shader3D.PERIOD_MATERIAL,
  22705. 'u_WorldPosition': Shader3D.PERIOD_SPRITE,
  22706. 'u_WorldRotation': Shader3D.PERIOD_SPRITE,
  22707. 'u_PositionScale': Shader3D.PERIOD_SPRITE,
  22708. 'u_SizeScale': Shader3D.PERIOD_SPRITE,
  22709. 'u_ScalingMode': Shader3D.PERIOD_SPRITE,
  22710. 'u_Gravity': Shader3D.PERIOD_SPRITE,
  22711. 'u_ThreeDStartRotation': Shader3D.PERIOD_SPRITE,
  22712. 'u_StretchedBillboardLengthScale': Shader3D.PERIOD_SPRITE,
  22713. 'u_StretchedBillboardSpeedScale': Shader3D.PERIOD_SPRITE,
  22714. 'u_SimulationSpace': Shader3D.PERIOD_SPRITE,
  22715. 'u_CurrentTime': Shader3D.PERIOD_SPRITE,
  22716. 'u_ColorOverLifeGradientAlphas': Shader3D.PERIOD_SPRITE,
  22717. 'u_ColorOverLifeGradientColors': Shader3D.PERIOD_SPRITE,
  22718. 'u_MaxColorOverLifeGradientAlphas': Shader3D.PERIOD_SPRITE,
  22719. 'u_MaxColorOverLifeGradientColors': Shader3D.PERIOD_SPRITE,
  22720. 'u_VOLVelocityConst': Shader3D.PERIOD_SPRITE,
  22721. 'u_VOLVelocityGradientX': Shader3D.PERIOD_SPRITE,
  22722. 'u_VOLVelocityGradientY': Shader3D.PERIOD_SPRITE,
  22723. 'u_VOLVelocityGradientZ': Shader3D.PERIOD_SPRITE,
  22724. 'u_VOLVelocityConstMax': Shader3D.PERIOD_SPRITE,
  22725. 'u_VOLVelocityGradientMaxX': Shader3D.PERIOD_SPRITE,
  22726. 'u_VOLVelocityGradientMaxY': Shader3D.PERIOD_SPRITE,
  22727. 'u_VOLVelocityGradientMaxZ': Shader3D.PERIOD_SPRITE,
  22728. 'u_VOLSpaceType': Shader3D.PERIOD_SPRITE,
  22729. 'u_SOLSizeGradient': Shader3D.PERIOD_SPRITE,
  22730. 'u_SOLSizeGradientX': Shader3D.PERIOD_SPRITE,
  22731. 'u_SOLSizeGradientY': Shader3D.PERIOD_SPRITE,
  22732. 'u_SOLSizeGradientZ': Shader3D.PERIOD_SPRITE,
  22733. 'u_SOLSizeGradientMax': Shader3D.PERIOD_SPRITE,
  22734. 'u_SOLSizeGradientMaxX': Shader3D.PERIOD_SPRITE,
  22735. 'u_SOLSizeGradientMaxY': Shader3D.PERIOD_SPRITE,
  22736. 'u_SOLSizeGradientMaxZ': Shader3D.PERIOD_SPRITE,
  22737. 'u_ROLAngularVelocityConst': Shader3D.PERIOD_SPRITE,
  22738. 'u_ROLAngularVelocityConstSeprarate': Shader3D.PERIOD_SPRITE,
  22739. 'u_ROLAngularVelocityGradient': Shader3D.PERIOD_SPRITE,
  22740. 'u_ROLAngularVelocityGradientX': Shader3D.PERIOD_SPRITE,
  22741. 'u_ROLAngularVelocityGradientY': Shader3D.PERIOD_SPRITE,
  22742. 'u_ROLAngularVelocityGradientZ': Shader3D.PERIOD_SPRITE,
  22743. 'u_ROLAngularVelocityConstMax': Shader3D.PERIOD_SPRITE,
  22744. 'u_ROLAngularVelocityConstMaxSeprarate': Shader3D.PERIOD_SPRITE,
  22745. 'u_ROLAngularVelocityGradientMax': Shader3D.PERIOD_SPRITE,
  22746. 'u_ROLAngularVelocityGradientMaxX': Shader3D.PERIOD_SPRITE,
  22747. 'u_ROLAngularVelocityGradientMaxY': Shader3D.PERIOD_SPRITE,
  22748. 'u_ROLAngularVelocityGradientMaxZ': Shader3D.PERIOD_SPRITE,
  22749. 'u_ROLAngularVelocityGradientMaxW': Shader3D.PERIOD_SPRITE,
  22750. 'u_TSACycles': Shader3D.PERIOD_SPRITE,
  22751. 'u_TSASubUVLength': Shader3D.PERIOD_SPRITE,
  22752. 'u_TSAGradientUVs': Shader3D.PERIOD_SPRITE,
  22753. 'u_TSAMaxGradientUVs': Shader3D.PERIOD_SPRITE,
  22754. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22755. 'u_CameraDirection': Shader3D.PERIOD_CAMERA,
  22756. 'u_CameraUp': Shader3D.PERIOD_CAMERA,
  22757. 'u_View': Shader3D.PERIOD_CAMERA,
  22758. 'u_Projection': Shader3D.PERIOD_CAMERA,
  22759. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22760. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22761. 'u_FogColor': Shader3D.PERIOD_SCENE
  22762. };
  22763. stateMap = {
  22764. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22765. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22766. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22767. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22768. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22769. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22770. };
  22771. shader = Shader3D.add("PARTICLESHURIKEN");
  22772. subShader = new SubShader(attributeMap, uniformMap, ShuriKenParticle3D.shaderDefines, ShurikenParticleMaterial.shaderDefines);
  22773. shader.addSubShader(subShader);
  22774. subShader.addShaderPass(ParticleShuriKenVS, ParticleShuriKenPS, stateMap);
  22775. attributeMap = {
  22776. 'a_Position': VertexMesh.MESH_POSITION0
  22777. };
  22778. uniformMap = {
  22779. 'u_TintColor': Shader3D.PERIOD_MATERIAL,
  22780. 'u_Exposure': Shader3D.PERIOD_MATERIAL,
  22781. 'u_Rotation': Shader3D.PERIOD_MATERIAL,
  22782. 'u_CubeTexture': Shader3D.PERIOD_MATERIAL,
  22783. 'u_ViewProjection': Shader3D.PERIOD_CAMERA
  22784. };
  22785. shader = Shader3D.add("SkyBox");
  22786. subShader = new SubShader(attributeMap, uniformMap);
  22787. shader.addSubShader(subShader);
  22788. subShader.addShaderPass(SkyBoxVS, SkyBoxPS);
  22789. attributeMap = {
  22790. 'a_Position': VertexMesh.MESH_POSITION0
  22791. };
  22792. uniformMap = {
  22793. 'u_SunSize': Shader3D.PERIOD_MATERIAL,
  22794. 'u_SunSizeConvergence': Shader3D.PERIOD_MATERIAL,
  22795. 'u_AtmosphereThickness': Shader3D.PERIOD_MATERIAL,
  22796. 'u_SkyTint': Shader3D.PERIOD_MATERIAL,
  22797. 'u_GroundTint': Shader3D.PERIOD_MATERIAL,
  22798. 'u_Exposure': Shader3D.PERIOD_MATERIAL,
  22799. 'u_ViewProjection': Shader3D.PERIOD_CAMERA,
  22800. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22801. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE
  22802. };
  22803. shader = Shader3D.add("SkyBoxProcedural");
  22804. subShader = new SubShader(attributeMap, uniformMap, null, SkyProceduralMaterial.shaderDefines);
  22805. shader.addSubShader(subShader);
  22806. subShader.addShaderPass(SkyBoxProceduralVS, SkyBoxProceduralPS);
  22807. attributeMap = {
  22808. 'a_Position': VertexMesh.MESH_POSITION0,
  22809. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22810. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0
  22811. };
  22812. uniformMap = {
  22813. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22814. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22815. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22816. 'u_LightmapScaleOffset': Shader3D.PERIOD_SPRITE,
  22817. 'u_LightMap': Shader3D.PERIOD_SPRITE,
  22818. 'u_SplatAlphaTexture': Shader3D.PERIOD_MATERIAL,
  22819. 'u_DiffuseTexture1': Shader3D.PERIOD_MATERIAL,
  22820. 'u_DiffuseTexture2': Shader3D.PERIOD_MATERIAL,
  22821. 'u_DiffuseTexture3': Shader3D.PERIOD_MATERIAL,
  22822. 'u_DiffuseTexture4': Shader3D.PERIOD_MATERIAL,
  22823. 'u_DiffuseTexture5': Shader3D.PERIOD_MATERIAL,
  22824. 'u_DiffuseScaleOffset1': Shader3D.PERIOD_MATERIAL,
  22825. 'u_DiffuseScaleOffset2': Shader3D.PERIOD_MATERIAL,
  22826. 'u_DiffuseScaleOffset3': Shader3D.PERIOD_MATERIAL,
  22827. 'u_DiffuseScaleOffset4': Shader3D.PERIOD_MATERIAL,
  22828. 'u_DiffuseScaleOffset5': Shader3D.PERIOD_MATERIAL,
  22829. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22830. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22831. 'u_FogColor': Shader3D.PERIOD_SCENE,
  22832. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22833. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE,
  22834. 'u_PointLight.Position': Shader3D.PERIOD_SCENE,
  22835. 'u_PointLight.Range': Shader3D.PERIOD_SCENE,
  22836. 'u_PointLight.Attenuation': Shader3D.PERIOD_SCENE,
  22837. 'u_PointLight.Color': Shader3D.PERIOD_SCENE,
  22838. 'u_SpotLight.Position': Shader3D.PERIOD_SCENE,
  22839. 'u_SpotLight.Direction': Shader3D.PERIOD_SCENE,
  22840. 'u_SpotLight.Range': Shader3D.PERIOD_SCENE,
  22841. 'u_SpotLight.Spot': Shader3D.PERIOD_SCENE,
  22842. 'u_SpotLight.Color': Shader3D.PERIOD_SCENE,
  22843. 'u_AmbientColor': Shader3D.PERIOD_SCENE,
  22844. 'u_shadowMap1': Shader3D.PERIOD_SCENE,
  22845. 'u_shadowMap2': Shader3D.PERIOD_SCENE,
  22846. 'u_shadowMap3': Shader3D.PERIOD_SCENE,
  22847. 'u_shadowPSSMDistance': Shader3D.PERIOD_SCENE,
  22848. 'u_lightShadowVP': Shader3D.PERIOD_SCENE,
  22849. 'u_shadowPCFoffset': Shader3D.PERIOD_SCENE
  22850. };
  22851. stateMap = {
  22852. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22853. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22854. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22855. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22856. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22857. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22858. };
  22859. shader = Shader3D.add("ExtendTerrain");
  22860. subShader = new SubShader(attributeMap, uniformMap, RenderableSprite3D.shaderDefines, ExtendTerrainMaterial.shaderDefines);
  22861. shader.addSubShader(subShader);
  22862. subShader.addShaderPass(extendTerrainVS, extendTerrainPS, stateMap);
  22863. attributeMap = {
  22864. 'a_Position': VertexTrail.TRAIL_POSITION0,
  22865. 'a_OffsetVector': VertexTrail.TRAIL_OFFSETVECTOR,
  22866. 'a_Texcoord0X': VertexTrail.TRAIL_TEXTURECOORDINATE0X,
  22867. 'a_Texcoord0Y': VertexTrail.TRAIL_TEXTURECOORDINATE0Y,
  22868. 'a_BirthTime': VertexTrail.TRAIL_TIME0,
  22869. 'a_Color': VertexTrail.TRAIL_COLOR
  22870. };
  22871. uniformMap = {
  22872. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22873. 'u_View': Shader3D.PERIOD_CAMERA,
  22874. 'u_Projection': Shader3D.PERIOD_CAMERA,
  22875. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22876. 'u_MainTexture': Shader3D.PERIOD_MATERIAL,
  22877. 'u_MainColor': Shader3D.PERIOD_MATERIAL,
  22878. 'u_CurTime': Shader3D.PERIOD_SPRITE,
  22879. 'u_LifeTime': Shader3D.PERIOD_SPRITE,
  22880. 'u_WidthCurve': Shader3D.PERIOD_SPRITE,
  22881. 'u_WidthCurveKeyLength': Shader3D.PERIOD_SPRITE,
  22882. 'u_GradientColorkey': Shader3D.PERIOD_SPRITE,
  22883. 'u_GradientAlphakey': Shader3D.PERIOD_SPRITE
  22884. };
  22885. stateMap = {
  22886. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22887. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22888. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22889. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22890. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22891. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22892. };
  22893. shader = Shader3D.add("Trail");
  22894. subShader = new SubShader(attributeMap, uniformMap, TrailSprite3D.shaderDefines, TrailMaterial.shaderDefines);
  22895. shader.addSubShader(subShader);
  22896. subShader.addShaderPass(TrailVS, TrailPS, stateMap);
  22897. attributeMap = {
  22898. 'a_Position': VertexMesh.MESH_POSITION0,
  22899. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22900. 'a_Tangent0': VertexMesh.MESH_TANGENT0
  22901. };
  22902. uniformMap = {
  22903. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22904. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22905. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22906. 'u_Time': Shader3D.PERIOD_SCENE,
  22907. 'u_MainTexture': Shader3D.PERIOD_MATERIAL,
  22908. 'u_NormalTexture': Shader3D.PERIOD_MATERIAL,
  22909. 'u_HorizonColor': Shader3D.PERIOD_MATERIAL,
  22910. 'u_WaveScale': Shader3D.PERIOD_MATERIAL,
  22911. 'u_WaveSpeed': Shader3D.PERIOD_MATERIAL
  22912. };
  22913. shader = Shader3D.add("WaterPrimary");
  22914. subShader = new SubShader(attributeMap, uniformMap, null, WaterPrimaryMaterial.shaderDefines);
  22915. shader.addSubShader(subShader);
  22916. subShader.addShaderPass(WaterPrimaryVS, WaterPrimaryPS);
  22917. attributeMap = {
  22918. 'a_PositionTexcoord': VertexMesh.MESH_POSITION0
  22919. };
  22920. uniformMap = {
  22921. 'u_MainTex': Shader3D.PERIOD_MATERIAL
  22922. };
  22923. shader = Shader3D.add("BlitScreen");
  22924. subShader = new SubShader(attributeMap, uniformMap, null, null);
  22925. shader.addSubShader(subShader);
  22926. var shaderPass = subShader.addShaderPass(BlitScreenVS, BlitScreenPS);
  22927. var renderState = shaderPass.renderState;
  22928. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22929. renderState.depthWrite = false;
  22930. renderState.cull = RenderState.CULL_NONE;
  22931. renderState.blend = RenderState.BLEND_DISABLE;
  22932. attributeMap = {
  22933. 'a_PositionTexcoord': VertexMesh.MESH_POSITION0
  22934. };
  22935. uniformMap = {
  22936. 'u_MainTex': Shader3D.PERIOD_MATERIAL,
  22937. 'u_BloomTex': Shader3D.PERIOD_MATERIAL,
  22938. 'u_AutoExposureTex': Shader3D.PERIOD_MATERIAL,
  22939. 'u_MainTex_TexelSize': Shader3D.PERIOD_MATERIAL,
  22940. 'u_SampleScale': Shader3D.PERIOD_MATERIAL,
  22941. 'u_Threshold': Shader3D.PERIOD_MATERIAL,
  22942. 'u_Params': Shader3D.PERIOD_MATERIAL
  22943. };
  22944. shader = Shader3D.add("PostProcessBloom", attributeMap, uniformMap);
  22945. subShader = new SubShader(null, null, null, null);
  22946. shader.addSubShader(subShader);
  22947. shaderPass = subShader.addShaderPass(BloomVS, BloomPrefilter13PS);
  22948. renderState = shaderPass.renderState;
  22949. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22950. renderState.depthWrite = false;
  22951. renderState.cull = RenderState.CULL_NONE;
  22952. renderState.blend = RenderState.BLEND_DISABLE;
  22953. subShader = new SubShader(null, null, null, null);
  22954. shader.addSubShader(subShader);
  22955. shaderPass = subShader.addShaderPass(BloomVS, BloomPrefilter4PS);
  22956. renderState = shaderPass.renderState;
  22957. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22958. renderState.depthWrite = false;
  22959. renderState.cull = RenderState.CULL_NONE;
  22960. renderState.blend = RenderState.BLEND_DISABLE;
  22961. subShader = new SubShader(null, null, null, null);
  22962. shader.addSubShader(subShader);
  22963. shaderPass = subShader.addShaderPass(BloomVS, BloomDownsample13PS);
  22964. renderState = shaderPass.renderState;
  22965. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22966. renderState.depthWrite = false;
  22967. renderState.cull = RenderState.CULL_NONE;
  22968. renderState.blend = RenderState.BLEND_DISABLE;
  22969. subShader = new SubShader(null, null, null, null);
  22970. shader.addSubShader(subShader);
  22971. shaderPass = subShader.addShaderPass(BloomVS, BloomDownsample4PS);
  22972. renderState = shaderPass.renderState;
  22973. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22974. renderState.depthWrite = false;
  22975. renderState.cull = RenderState.CULL_NONE;
  22976. renderState.blend = RenderState.BLEND_DISABLE;
  22977. subShader = new SubShader(null, null, null, null);
  22978. shader.addSubShader(subShader);
  22979. shaderPass = subShader.addShaderPass(BloomVS, BloomUpsampleTentPS);
  22980. renderState = shaderPass.renderState;
  22981. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22982. renderState.depthWrite = false;
  22983. renderState.cull = RenderState.CULL_NONE;
  22984. renderState.blend = RenderState.BLEND_DISABLE;
  22985. subShader = new SubShader(null, null, null, null);
  22986. shader.addSubShader(subShader);
  22987. shaderPass = subShader.addShaderPass(BloomVS, BloomUpsampleBoxPS);
  22988. renderState = shaderPass.renderState;
  22989. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22990. renderState.depthWrite = false;
  22991. renderState.cull = RenderState.CULL_NONE;
  22992. renderState.blend = RenderState.BLEND_DISABLE;
  22993. attributeMap = {
  22994. 'a_PositionTexcoord': VertexMesh.MESH_POSITION0
  22995. };
  22996. uniformMap = {
  22997. 'u_MainTex': Shader3D.PERIOD_MATERIAL,
  22998. 'u_BloomTex': Shader3D.PERIOD_MATERIAL,
  22999. 'u_AutoExposureTex': Shader3D.PERIOD_MATERIAL,
  23000. 'u_Bloom_DirtTileOffset': Shader3D.PERIOD_MATERIAL,
  23001. 'u_Bloom_DirtTex': Shader3D.PERIOD_MATERIAL,
  23002. 'u_BloomTex_TexelSize': Shader3D.PERIOD_MATERIAL,
  23003. 'u_Bloom_Settings': Shader3D.PERIOD_MATERIAL,
  23004. 'u_Bloom_Color': Shader3D.PERIOD_MATERIAL
  23005. };
  23006. shader = Shader3D.add("PostProcessComposite", attributeMap, uniformMap);
  23007. subShader = new SubShader(null, null, null, PostProcess.shaderDefines);
  23008. shader.addSubShader(subShader);
  23009. shaderPass = subShader.addShaderPass(CompositeVS, CompositePS);
  23010. renderState = shaderPass.renderState;
  23011. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  23012. renderState.depthWrite = false;
  23013. renderState.cull = RenderState.CULL_NONE;
  23014. renderState.blend = RenderState.BLEND_DISABLE;
  23015. }
  23016. }
  23017. class PixelLineMaterial extends BaseMaterial {
  23018. constructor() {
  23019. super();
  23020. this.setShaderName("LineShader");
  23021. this._shaderValues.setVector(PixelLineMaterial.COLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  23022. }
  23023. static __initDefine__() {
  23024. PixelLineMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  23025. }
  23026. get color() {
  23027. return this._shaderValues.getVector(PixelLineMaterial.COLOR);
  23028. }
  23029. set color(value) {
  23030. this._shaderValues.setVector(PixelLineMaterial.COLOR, value);
  23031. }
  23032. set depthWrite(value) {
  23033. this._shaderValues.setBool(PixelLineMaterial.DEPTH_WRITE, value);
  23034. }
  23035. get depthWrite() {
  23036. return this._shaderValues.getBool(PixelLineMaterial.DEPTH_WRITE);
  23037. }
  23038. set cull(value) {
  23039. this._shaderValues.setInt(PixelLineMaterial.CULL, value);
  23040. }
  23041. get cull() {
  23042. return this._shaderValues.getInt(PixelLineMaterial.CULL);
  23043. }
  23044. set blend(value) {
  23045. this._shaderValues.setInt(PixelLineMaterial.BLEND, value);
  23046. }
  23047. get blend() {
  23048. return this._shaderValues.getInt(PixelLineMaterial.BLEND);
  23049. }
  23050. set blendSrc(value) {
  23051. this._shaderValues.setInt(PixelLineMaterial.BLEND_SRC, value);
  23052. }
  23053. get blendSrc() {
  23054. return this._shaderValues.getInt(PixelLineMaterial.BLEND_SRC);
  23055. }
  23056. set blendDst(value) {
  23057. this._shaderValues.setInt(PixelLineMaterial.BLEND_DST, value);
  23058. }
  23059. get blendDst() {
  23060. return this._shaderValues.getInt(PixelLineMaterial.BLEND_DST);
  23061. }
  23062. set depthTest(value) {
  23063. this._shaderValues.setInt(PixelLineMaterial.DEPTH_TEST, value);
  23064. }
  23065. get depthTest() {
  23066. return this._shaderValues.getInt(PixelLineMaterial.DEPTH_TEST);
  23067. }
  23068. clone() {
  23069. var dest = new PixelLineMaterial();
  23070. this.cloneTo(dest);
  23071. return dest;
  23072. }
  23073. }
  23074. PixelLineMaterial.COLOR = Shader3D.propertyNameToID("u_Color");
  23075. PixelLineMaterial.shaderDefines = null;
  23076. PixelLineMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  23077. PixelLineMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  23078. PixelLineMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  23079. PixelLineMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  23080. PixelLineMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  23081. PixelLineMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  23082. class PixelLineVertex {
  23083. static get vertexDeclaration() {
  23084. return PixelLineVertex._vertexDeclaration;
  23085. }
  23086. static __init__() {
  23087. PixelLineVertex._vertexDeclaration = new VertexDeclaration(28, [new VertexElement(0, VertexElementFormat.Vector3, VertexMesh.MESH_POSITION0),
  23088. new VertexElement(12, VertexElementFormat.Vector4, VertexMesh.MESH_COLOR0)]);
  23089. }
  23090. get vertexDeclaration() {
  23091. return PixelLineVertex._vertexDeclaration;
  23092. }
  23093. constructor() {
  23094. }
  23095. }
  23096. class PixelLineFilter extends GeometryElement {
  23097. constructor(owner, maxLineCount) {
  23098. super();
  23099. this._floatCountPerVertices = 7;
  23100. this._minUpdate = Number.MAX_VALUE;
  23101. this._maxUpdate = Number.MIN_VALUE;
  23102. this._bufferState = new BufferState();
  23103. this._maxLineCount = 0;
  23104. this._lineCount = 0;
  23105. var pointCount = maxLineCount * 2;
  23106. this._owner = owner;
  23107. this._maxLineCount = maxLineCount;
  23108. this._vertices = new Float32Array(pointCount * this._floatCountPerVertices);
  23109. this._vertexBuffer = new VertexBuffer3D(PixelLineVertex.vertexDeclaration.vertexStride * pointCount, Laya.LayaGL.instance.STATIC_DRAW, false);
  23110. this._vertexBuffer.vertexDeclaration = PixelLineVertex.vertexDeclaration;
  23111. this._bufferState.bind();
  23112. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  23113. this._bufferState.unBind();
  23114. }
  23115. _getType() {
  23116. return PixelLineFilter._type;
  23117. }
  23118. _resizeLineData(maxCount) {
  23119. var pointCount = maxCount * 2;
  23120. var lastVertices = this._vertices;
  23121. this._vertexBuffer.destroy();
  23122. this._maxLineCount = maxCount;
  23123. var vertexCount = pointCount * this._floatCountPerVertices;
  23124. this._vertices = new Float32Array(vertexCount);
  23125. this._vertexBuffer = new VertexBuffer3D(PixelLineVertex.vertexDeclaration.vertexStride * pointCount, Laya.LayaGL.instance.STATIC_DRAW, false);
  23126. this._vertexBuffer.vertexDeclaration = PixelLineVertex.vertexDeclaration;
  23127. if (vertexCount < lastVertices.length) {
  23128. this._vertices.set(new Float32Array(lastVertices.buffer, 0, vertexCount));
  23129. this._vertexBuffer.setData(this._vertices.buffer, 0, 0, vertexCount * 4);
  23130. }
  23131. else {
  23132. this._vertices.set(lastVertices);
  23133. this._vertexBuffer.setData(this._vertices.buffer, 0, 0, lastVertices.length * 4);
  23134. }
  23135. this._bufferState.bind();
  23136. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  23137. this._bufferState.unBind();
  23138. }
  23139. _updateLineVertices(offset, startPosition, endPosition, startColor, endColor) {
  23140. if (startPosition) {
  23141. this._vertices[offset + 0] = startPosition.x;
  23142. this._vertices[offset + 1] = startPosition.y;
  23143. this._vertices[offset + 2] = startPosition.z;
  23144. }
  23145. if (startColor) {
  23146. this._vertices[offset + 3] = startColor.r;
  23147. this._vertices[offset + 4] = startColor.g;
  23148. this._vertices[offset + 5] = startColor.b;
  23149. this._vertices[offset + 6] = startColor.a;
  23150. }
  23151. if (endPosition) {
  23152. this._vertices[offset + 7] = endPosition.x;
  23153. this._vertices[offset + 8] = endPosition.y;
  23154. this._vertices[offset + 9] = endPosition.z;
  23155. }
  23156. if (endColor) {
  23157. this._vertices[offset + 10] = endColor.r;
  23158. this._vertices[offset + 11] = endColor.g;
  23159. this._vertices[offset + 12] = endColor.b;
  23160. this._vertices[offset + 13] = endColor.a;
  23161. }
  23162. this._minUpdate = Math.min(this._minUpdate, offset);
  23163. this._maxUpdate = Math.max(this._maxUpdate, offset + this._floatCountPerVertices * 2);
  23164. }
  23165. _removeLineData(index) {
  23166. var floatCount = this._floatCountPerVertices * 2;
  23167. var nextIndex = index + 1;
  23168. var offset = index * floatCount;
  23169. var rightPartVertices = new Float32Array(this._vertices.buffer, nextIndex * floatCount * 4, (this._lineCount - nextIndex) * floatCount);
  23170. this._vertices.set(rightPartVertices, offset);
  23171. this._minUpdate = Math.min(this._minUpdate, offset);
  23172. this._maxUpdate = Math.max(this._maxUpdate, offset + rightPartVertices.length);
  23173. this._lineCount--;
  23174. }
  23175. _updateLineData(index, startPosition, endPosition, startColor, endColor) {
  23176. var floatCount = this._floatCountPerVertices * 2;
  23177. var offset = index * floatCount;
  23178. this._updateLineVertices(offset, startPosition, endPosition, startColor, endColor);
  23179. }
  23180. _updateLineDatas(index, data) {
  23181. var floatCount = this._floatCountPerVertices * 2;
  23182. var count = data.length;
  23183. for (var i = 0; i < count; i++) {
  23184. var line = data[i];
  23185. this._updateLineVertices((index + i) * floatCount, line.startPosition, line.endPosition, line.startColor, line.endColor);
  23186. }
  23187. }
  23188. _getLineData(index, out) {
  23189. var startPosition = out.startPosition;
  23190. var startColor = out.startColor;
  23191. var endPosition = out.endPosition;
  23192. var endColor = out.endColor;
  23193. var vertices = this._vertices;
  23194. var offset = index * this._floatCountPerVertices * 2;
  23195. startPosition.x = vertices[offset + 0];
  23196. startPosition.y = vertices[offset + 1];
  23197. startPosition.z = vertices[offset + 2];
  23198. startColor.r = vertices[offset + 3];
  23199. startColor.g = vertices[offset + 4];
  23200. startColor.b = vertices[offset + 5];
  23201. startColor.a = vertices[offset + 6];
  23202. endPosition.x = vertices[offset + 7];
  23203. endPosition.y = vertices[offset + 8];
  23204. endPosition.z = vertices[offset + 9];
  23205. endColor.r = vertices[offset + 10];
  23206. endColor.g = vertices[offset + 11];
  23207. endColor.b = vertices[offset + 12];
  23208. endColor.a = vertices[offset + 13];
  23209. }
  23210. _prepareRender(state) {
  23211. return true;
  23212. }
  23213. _render(state) {
  23214. if (this._minUpdate !== Number.MAX_VALUE && this._maxUpdate !== Number.MIN_VALUE) {
  23215. this._vertexBuffer.setData(this._vertices.buffer, this._minUpdate * 4, this._minUpdate * 4, (this._maxUpdate - this._minUpdate) * 4);
  23216. this._minUpdate = Number.MAX_VALUE;
  23217. this._maxUpdate = Number.MIN_VALUE;
  23218. }
  23219. if (this._lineCount > 0) {
  23220. this._bufferState.bind();
  23221. var gl = Laya.LayaGL.instance;
  23222. gl.drawArrays(gl.LINES, 0, this._lineCount * 2);
  23223. Laya.Stat.renderBatches++;
  23224. }
  23225. }
  23226. destroy() {
  23227. if (this._destroyed)
  23228. return;
  23229. super.destroy();
  23230. this._bufferState.destroy();
  23231. this._vertexBuffer.destroy();
  23232. this._bufferState = null;
  23233. this._vertexBuffer = null;
  23234. this._vertices = null;
  23235. }
  23236. }
  23237. PixelLineFilter._type = GeometryElement._typeCounter++;
  23238. class PixelLineRenderer extends BaseRender {
  23239. constructor(owner) {
  23240. super(owner);
  23241. this._projectionViewWorldMatrix = new Matrix4x4();
  23242. this._supportOctree = false;
  23243. }
  23244. _calculateBoundingBox() {
  23245. var min = this._bounds.getMin();
  23246. min.x = -Number.MAX_VALUE;
  23247. min.y = -Number.MAX_VALUE;
  23248. min.z = -Number.MAX_VALUE;
  23249. this._bounds.setMin(min);
  23250. var max = this._bounds.getMax();
  23251. max.x = Number.MAX_VALUE;
  23252. max.y = Number.MAX_VALUE;
  23253. max.z = Number.MAX_VALUE;
  23254. this._bounds.setMax(max);
  23255. if (Laya.Render.supportWebGLPlusCulling) {
  23256. var min = this._bounds.getMin();
  23257. var max = this._bounds.getMax();
  23258. var buffer = FrustumCulling._cullingBuffer;
  23259. buffer[this._cullingBufferIndex + 1] = min.x;
  23260. buffer[this._cullingBufferIndex + 2] = min.y;
  23261. buffer[this._cullingBufferIndex + 3] = min.z;
  23262. buffer[this._cullingBufferIndex + 4] = max.x;
  23263. buffer[this._cullingBufferIndex + 5] = max.y;
  23264. buffer[this._cullingBufferIndex + 6] = max.z;
  23265. }
  23266. }
  23267. _renderUpdateWithCamera(context, transform) {
  23268. var projectionView = context.projectionViewMatrix;
  23269. var sv = this._shaderValues;
  23270. if (transform) {
  23271. var worldMat = transform.worldMatrix;
  23272. sv.setMatrix4x4(Sprite3D.WORLDMATRIX, worldMat);
  23273. Matrix4x4.multiply(projectionView, worldMat, this._projectionViewWorldMatrix);
  23274. sv.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  23275. }
  23276. else {
  23277. sv.setMatrix4x4(Sprite3D.WORLDMATRIX, Matrix4x4.DEFAULT);
  23278. sv.setMatrix4x4(Sprite3D.MVPMATRIX, projectionView);
  23279. }
  23280. }
  23281. }
  23282. class PixelLineSprite3D extends RenderableSprite3D {
  23283. get maxLineCount() {
  23284. return this._geometryFilter._maxLineCount;
  23285. }
  23286. set maxLineCount(value) {
  23287. this._geometryFilter._resizeLineData(value);
  23288. this._geometryFilter._lineCount = Math.min(this._geometryFilter._lineCount, value);
  23289. }
  23290. get lineCount() {
  23291. return this._geometryFilter._lineCount;
  23292. }
  23293. set lineCount(value) {
  23294. if (value > this.maxLineCount)
  23295. throw "PixelLineSprite3D: lineCount can't large than maxLineCount";
  23296. else
  23297. this._geometryFilter._lineCount = value;
  23298. }
  23299. get pixelLineRenderer() {
  23300. return this._render;
  23301. }
  23302. constructor(maxCount = 2, name = null) {
  23303. super(name);
  23304. this._geometryFilter = new PixelLineFilter(this, maxCount);
  23305. this._render = new PixelLineRenderer(this);
  23306. this._changeRenderObjects(this._render, 0, PixelLineMaterial.defaultMaterial);
  23307. }
  23308. _changeRenderObjects(sender, index, material) {
  23309. var renderObjects = this._render._renderElements;
  23310. (material) || (material = PixelLineMaterial.defaultMaterial);
  23311. var renderElement = renderObjects[index];
  23312. (renderElement) || (renderElement = renderObjects[index] = new RenderElement());
  23313. renderElement.setTransform(this._transform);
  23314. renderElement.setGeometry(this._geometryFilter);
  23315. renderElement.render = this._render;
  23316. renderElement.material = material;
  23317. }
  23318. addLine(startPosition, endPosition, startColor, endColor) {
  23319. if (this._geometryFilter._lineCount !== this._geometryFilter._maxLineCount)
  23320. this._geometryFilter._updateLineData(this._geometryFilter._lineCount++, startPosition, endPosition, startColor, endColor);
  23321. else
  23322. throw "PixelLineSprite3D: lineCount has equal with maxLineCount.";
  23323. }
  23324. addLines(lines) {
  23325. var lineCount = this._geometryFilter._lineCount;
  23326. var addCount = lines.length;
  23327. if (lineCount + addCount > this._geometryFilter._maxLineCount) {
  23328. throw "PixelLineSprite3D: lineCount plus lines count must less than maxLineCount.";
  23329. }
  23330. else {
  23331. this._geometryFilter._updateLineDatas(lineCount, lines);
  23332. this._geometryFilter._lineCount += addCount;
  23333. }
  23334. }
  23335. removeLine(index) {
  23336. if (index < this._geometryFilter._lineCount)
  23337. this._geometryFilter._removeLineData(index);
  23338. else
  23339. throw "PixelLineSprite3D: index must less than lineCount.";
  23340. }
  23341. setLine(index, startPosition, endPosition, startColor, endColor) {
  23342. if (index < this._geometryFilter._lineCount)
  23343. this._geometryFilter._updateLineData(index, startPosition, endPosition, startColor, endColor);
  23344. else
  23345. throw "PixelLineSprite3D: index must less than lineCount.";
  23346. }
  23347. getLine(index, out) {
  23348. if (index < this.lineCount)
  23349. this._geometryFilter._getLineData(index, out);
  23350. else
  23351. throw "PixelLineSprite3D: index must less than lineCount.";
  23352. }
  23353. clear() {
  23354. this._geometryFilter._lineCount = 0;
  23355. }
  23356. _create() {
  23357. return new PixelLineSprite3D();
  23358. }
  23359. }
  23360. class RenderQueue {
  23361. constructor(isTransparent = false) {
  23362. this.isTransparent = false;
  23363. this.elements = new SingletonList();
  23364. this.lastTransparentRenderElement = null;
  23365. this.lastTransparentBatched = false;
  23366. this.isTransparent = isTransparent;
  23367. }
  23368. _compare(left, right) {
  23369. var renderQueue = left.material.renderQueue - right.material.renderQueue;
  23370. if (renderQueue === 0) {
  23371. var sort = this.isTransparent ? right.render._distanceForSort - left.render._distanceForSort : left.render._distanceForSort - right.render._distanceForSort;
  23372. return sort + right.render.sortingFudge - left.render.sortingFudge;
  23373. }
  23374. else {
  23375. return renderQueue;
  23376. }
  23377. }
  23378. _partitionRenderObject(left, right) {
  23379. var elements = this.elements.elements;
  23380. var pivot = elements[Math.floor((right + left) / 2)];
  23381. while (left <= right) {
  23382. while (this._compare(elements[left], pivot) < 0)
  23383. left++;
  23384. while (this._compare(elements[right], pivot) > 0)
  23385. right--;
  23386. if (left < right) {
  23387. var temp = elements[left];
  23388. elements[left] = elements[right];
  23389. elements[right] = temp;
  23390. left++;
  23391. right--;
  23392. }
  23393. else if (left === right) {
  23394. left++;
  23395. break;
  23396. }
  23397. }
  23398. return left;
  23399. }
  23400. _quickSort(left, right) {
  23401. if (this.elements.length > 1) {
  23402. var index = this._partitionRenderObject(left, right);
  23403. var leftIndex = index - 1;
  23404. if (left < leftIndex)
  23405. this._quickSort(left, leftIndex);
  23406. if (index < right)
  23407. this._quickSort(index, right);
  23408. }
  23409. }
  23410. _render(context, isTarget) {
  23411. var elements = this.elements.elements;
  23412. for (var i = 0, n = this.elements.length; i < n; i++)
  23413. elements[i]._render(context, isTarget);
  23414. }
  23415. clear() {
  23416. this.elements.length = 0;
  23417. this.lastTransparentRenderElement = null;
  23418. this.lastTransparentBatched = false;
  23419. }
  23420. }
  23421. class BoundsOctreeNode {
  23422. constructor(octree, parent, baseLength, center) {
  23423. this._bounds = new BoundBox(new Vector3(), new Vector3());
  23424. this._objects = [];
  23425. this._isContaion = false;
  23426. this.center = new Vector3();
  23427. this.baseLength = 0.0;
  23428. this._setValues(octree, parent, baseLength, center);
  23429. }
  23430. static _encapsulates(outerBound, innerBound) {
  23431. return CollisionUtils.boxContainsBox(outerBound, innerBound) == ContainmentType.Contains;
  23432. }
  23433. _setValues(octree, parent, baseLength, center) {
  23434. this._octree = octree;
  23435. this._parent = parent;
  23436. this.baseLength = baseLength;
  23437. center.cloneTo(this.center);
  23438. var min = this._bounds.min;
  23439. var max = this._bounds.max;
  23440. var halfSize = (octree._looseness * baseLength) / 2;
  23441. min.setValue(center.x - halfSize, center.y - halfSize, center.z - halfSize);
  23442. max.setValue(center.x + halfSize, center.y + halfSize, center.z + halfSize);
  23443. }
  23444. _getChildBound(index) {
  23445. if (this._children != null && this._children[index]) {
  23446. return this._children[index]._bounds;
  23447. }
  23448. else {
  23449. var quarter = this.baseLength / 4;
  23450. var halfChildSize = ((this.baseLength / 2) * this._octree._looseness) / 2;
  23451. var bounds = BoundsOctreeNode._tempBoundBox;
  23452. var min = bounds.min;
  23453. var max = bounds.max;
  23454. switch (index) {
  23455. case 0:
  23456. min.x = this.center.x - quarter - halfChildSize;
  23457. min.y = this.center.y + quarter - halfChildSize;
  23458. min.z = this.center.z - quarter - halfChildSize;
  23459. max.x = this.center.x - quarter + halfChildSize;
  23460. max.y = this.center.y + quarter + halfChildSize;
  23461. max.z = this.center.z - quarter + halfChildSize;
  23462. break;
  23463. case 1:
  23464. min.x = this.center.x + quarter - halfChildSize;
  23465. min.y = this.center.y + quarter - halfChildSize;
  23466. min.z = this.center.z - quarter - halfChildSize;
  23467. max.x = this.center.x + quarter + halfChildSize;
  23468. max.y = this.center.y + quarter + halfChildSize;
  23469. max.z = this.center.z - quarter + halfChildSize;
  23470. break;
  23471. case 2:
  23472. min.x = this.center.x - quarter - halfChildSize;
  23473. min.y = this.center.y + quarter - halfChildSize;
  23474. min.z = this.center.z + quarter - halfChildSize;
  23475. max.x = this.center.x - quarter + halfChildSize;
  23476. max.y = this.center.y + quarter + halfChildSize;
  23477. max.z = this.center.z + quarter + halfChildSize;
  23478. break;
  23479. case 3:
  23480. min.x = this.center.x + quarter - halfChildSize;
  23481. min.y = this.center.y + quarter - halfChildSize;
  23482. min.z = this.center.z + quarter - halfChildSize;
  23483. max.x = this.center.x + quarter + halfChildSize;
  23484. max.y = this.center.y + quarter + halfChildSize;
  23485. max.z = this.center.z + quarter + halfChildSize;
  23486. break;
  23487. case 4:
  23488. min.x = this.center.x - quarter - halfChildSize;
  23489. min.y = this.center.y - quarter - halfChildSize;
  23490. min.z = this.center.z - quarter - halfChildSize;
  23491. max.x = this.center.x - quarter + halfChildSize;
  23492. max.y = this.center.y - quarter + halfChildSize;
  23493. max.z = this.center.z - quarter + halfChildSize;
  23494. break;
  23495. case 5:
  23496. min.x = this.center.x + quarter - halfChildSize;
  23497. min.y = this.center.y - quarter - halfChildSize;
  23498. min.z = this.center.z - quarter - halfChildSize;
  23499. max.x = this.center.x + quarter + halfChildSize;
  23500. max.y = this.center.y - quarter + halfChildSize;
  23501. max.z = this.center.z - quarter + halfChildSize;
  23502. break;
  23503. case 6:
  23504. min.x = this.center.x - quarter - halfChildSize;
  23505. min.y = this.center.y - quarter - halfChildSize;
  23506. min.z = this.center.z + quarter - halfChildSize;
  23507. max.x = this.center.x - quarter + halfChildSize;
  23508. max.y = this.center.y - quarter + halfChildSize;
  23509. max.z = this.center.z + quarter + halfChildSize;
  23510. break;
  23511. case 7:
  23512. min.x = this.center.x + quarter - halfChildSize;
  23513. min.y = this.center.y - quarter - halfChildSize;
  23514. min.z = this.center.z + quarter - halfChildSize;
  23515. max.x = this.center.x + quarter + halfChildSize;
  23516. max.y = this.center.y - quarter + halfChildSize;
  23517. max.z = this.center.z + quarter + halfChildSize;
  23518. break;
  23519. default:
  23520. }
  23521. return bounds;
  23522. }
  23523. }
  23524. _getChildCenter(index) {
  23525. if (this._children != null) {
  23526. return this._children[index].center;
  23527. }
  23528. else {
  23529. var quarter = this.baseLength / 4;
  23530. var childCenter = BoundsOctreeNode._tempVector30;
  23531. switch (index) {
  23532. case 0:
  23533. childCenter.x = this.center.x - quarter;
  23534. childCenter.y = this.center.y + quarter;
  23535. childCenter.z = this.center.z - quarter;
  23536. break;
  23537. case 1:
  23538. childCenter.x = this.center.x + quarter;
  23539. childCenter.y = this.center.y + quarter;
  23540. childCenter.z = this.center.z - quarter;
  23541. break;
  23542. case 2:
  23543. childCenter.x = this.center.x - quarter;
  23544. childCenter.y = this.center.y + quarter;
  23545. childCenter.z = this.center.z + quarter;
  23546. break;
  23547. case 3:
  23548. childCenter.x = this.center.x + quarter;
  23549. childCenter.y = this.center.y + quarter;
  23550. childCenter.z = this.center.z + quarter;
  23551. break;
  23552. case 4:
  23553. childCenter.x = this.center.x - quarter;
  23554. childCenter.y = this.center.y - quarter;
  23555. childCenter.z = this.center.z - quarter;
  23556. break;
  23557. case 5:
  23558. childCenter.x = this.center.x + quarter;
  23559. childCenter.y = this.center.y - quarter;
  23560. childCenter.z = this.center.z - quarter;
  23561. break;
  23562. case 6:
  23563. childCenter.x = this.center.x - quarter;
  23564. childCenter.y = this.center.y - quarter;
  23565. childCenter.z = this.center.z + quarter;
  23566. break;
  23567. case 7:
  23568. childCenter.x = this.center.x + quarter;
  23569. childCenter.y = this.center.y - quarter;
  23570. childCenter.z = this.center.z + quarter;
  23571. break;
  23572. default:
  23573. }
  23574. return childCenter;
  23575. }
  23576. }
  23577. _getChild(index) {
  23578. var quarter = this.baseLength / 4;
  23579. this._children || (this._children = []);
  23580. switch (index) {
  23581. case 0:
  23582. return this._children[0] || (this._children[0] = new BoundsOctreeNode(this._octree, this, this.baseLength / 2, new Vector3(this.center.x + -quarter, this.center.y + quarter, this.center.z - quarter)));
  23583. case 1:
  23584. return this._children[1] || (this._children[1] = new BoundsOctreeNode(this._octree, this, this.baseLength / 2, new Vector3(this.center.x + quarter, this.center.y + quarter, this.center.z - quarter)));
  23585. case 2:
  23586. return this._children[2] || (this._children[2] = new BoundsOctreeNode(this._octree, this, this.baseLength / 2, new Vector3(this.center.x - quarter, this.center.y + quarter, this.center.z + quarter)));
  23587. case 3:
  23588. return this._children[3] || (this._children[3] = new BoundsOctreeNode(this._octree, this, this.baseLength / 2, new Vector3(this.center.x + quarter, this.center.y + quarter, this.center.z + quarter)));
  23589. case 4:
  23590. return this._children[4] || (this._children[4] = new BoundsOctreeNode(this._octree, this, this.baseLength / 2, new Vector3(this.center.x - quarter, this.center.y - quarter, this.center.z - quarter)));
  23591. case 5:
  23592. return this._children[5] || (this._children[5] = new BoundsOctreeNode(this._octree, this, this.baseLength / 2, new Vector3(this.center.x + quarter, this.center.y - quarter, this.center.z - quarter)));
  23593. case 6:
  23594. return this._children[6] || (this._children[6] = new BoundsOctreeNode(this._octree, this, this.baseLength / 2, new Vector3(this.center.x - quarter, this.center.y - quarter, this.center.z + quarter)));
  23595. case 7:
  23596. return this._children[7] || (this._children[7] = new BoundsOctreeNode(this._octree, this, this.baseLength / 2, new Vector3(this.center.x + quarter, this.center.y - quarter, this.center.z + quarter)));
  23597. default:
  23598. throw "BoundsOctreeNode: unknown index.";
  23599. }
  23600. }
  23601. _shouldMerge() {
  23602. var objectCount = this._objects.length;
  23603. for (var i = 0; i < 8; i++) {
  23604. var child = this._children[i];
  23605. if (child) {
  23606. if (child._children != null)
  23607. return false;
  23608. objectCount += child._objects.length;
  23609. }
  23610. }
  23611. return objectCount <= BoundsOctreeNode._NUM_OBJECTS_ALLOWED;
  23612. }
  23613. _mergeChildren() {
  23614. for (var i = 0; i < 8; i++) {
  23615. var child = this._children[i];
  23616. if (child) {
  23617. child._parent = null;
  23618. var childObjects = child._objects;
  23619. for (var j = childObjects.length - 1; j >= 0; j--) {
  23620. var childObject = childObjects[j];
  23621. this._objects.push(childObject);
  23622. childObject._setOctreeNode(this);
  23623. }
  23624. }
  23625. }
  23626. this._children = null;
  23627. }
  23628. _merge() {
  23629. if (this._children === null) {
  23630. var parent = this._parent;
  23631. if (parent && parent._shouldMerge()) {
  23632. parent._mergeChildren();
  23633. parent._merge();
  23634. }
  23635. }
  23636. }
  23637. _checkAddNode(object) {
  23638. if (this._children == null) {
  23639. if (this._objects.length < BoundsOctreeNode._NUM_OBJECTS_ALLOWED || (this.baseLength / 2) < this._octree._minSize) {
  23640. return this;
  23641. }
  23642. for (var i = this._objects.length - 1; i >= 0; i--) {
  23643. var existObject = this._objects[i];
  23644. var fitChildIndex = this._bestFitChild(existObject.bounds.getCenter());
  23645. if (BoundsOctreeNode._encapsulates(this._getChildBound(fitChildIndex), existObject.bounds._getBoundBox())) {
  23646. this._objects.splice(this._objects.indexOf(existObject), 1);
  23647. this._getChild(fitChildIndex)._add(existObject);
  23648. }
  23649. }
  23650. }
  23651. var newFitChildIndex = this._bestFitChild(object.bounds.getCenter());
  23652. if (BoundsOctreeNode._encapsulates(this._getChildBound(newFitChildIndex), object.bounds._getBoundBox()))
  23653. return this._getChild(newFitChildIndex)._checkAddNode(object);
  23654. else
  23655. return this;
  23656. }
  23657. _add(object) {
  23658. var addNode = this._checkAddNode(object);
  23659. addNode._objects.push(object);
  23660. object._setOctreeNode(addNode);
  23661. }
  23662. _remove(object) {
  23663. var index = this._objects.indexOf(object);
  23664. this._objects.splice(index, 1);
  23665. object._setOctreeNode(null);
  23666. this._merge();
  23667. }
  23668. _addUp(object) {
  23669. if ((CollisionUtils.boxContainsBox(this._bounds, object.bounds._getBoundBox()) === ContainmentType.Contains)) {
  23670. this._add(object);
  23671. return true;
  23672. }
  23673. else {
  23674. if (this._parent)
  23675. return this._parent._addUp(object);
  23676. else
  23677. return false;
  23678. }
  23679. }
  23680. _getCollidingWithFrustum(context, frustum, testVisible, camPos, customShader, replacementTag) {
  23681. if (testVisible) {
  23682. var type = frustum.containsBoundBox(this._bounds);
  23683. Laya.Stat.octreeNodeCulling++;
  23684. if (type === ContainmentType.Disjoint)
  23685. return;
  23686. testVisible = (type === ContainmentType.Intersects);
  23687. }
  23688. this._isContaion = !testVisible;
  23689. var camera = context.camera;
  23690. var scene = context.scene;
  23691. for (var i = 0, n = this._objects.length; i < n; i++) {
  23692. var render = this._objects[i];
  23693. if (camera._isLayerVisible(render._owner.layer) && render._enable) {
  23694. if (testVisible) {
  23695. Laya.Stat.frustumCulling++;
  23696. if (!render._needRender(frustum, context))
  23697. continue;
  23698. }
  23699. render._distanceForSort = Vector3.distance(render.bounds.getCenter(), camPos);
  23700. var elements = render._renderElements;
  23701. for (var j = 0, m = elements.length; j < m; j++) {
  23702. var element = elements[j];
  23703. element._update(scene, context, customShader, replacementTag);
  23704. }
  23705. }
  23706. }
  23707. if (this._children != null) {
  23708. for (i = 0; i < 8; i++) {
  23709. var child = this._children[i];
  23710. child && child._getCollidingWithFrustum(context, frustum, testVisible, camPos, customShader, replacementTag);
  23711. }
  23712. }
  23713. }
  23714. _getCollidingWithBoundBox(checkBound, testVisible, result) {
  23715. if (testVisible) {
  23716. var type = CollisionUtils.boxContainsBox(this._bounds, checkBound);
  23717. if (type === ContainmentType.Disjoint)
  23718. return;
  23719. testVisible = (type === ContainmentType.Intersects);
  23720. }
  23721. if (testVisible) {
  23722. for (var i = 0, n = this._objects.length; i < n; i++) {
  23723. var object = this._objects[i];
  23724. if (CollisionUtils.intersectsBoxAndBox(object.bounds._getBoundBox(), checkBound)) {
  23725. result.push(object);
  23726. }
  23727. }
  23728. }
  23729. if (this._children != null) {
  23730. for (i = 0; i < 8; i++) {
  23731. var child = this._children[i];
  23732. child._getCollidingWithBoundBox(checkBound, testVisible, result);
  23733. }
  23734. }
  23735. }
  23736. _bestFitChild(boundCenter) {
  23737. return (boundCenter.x <= this.center.x ? 0 : 1) + (boundCenter.y >= this.center.y ? 0 : 4) + (boundCenter.z <= this.center.z ? 0 : 2);
  23738. }
  23739. _update(object) {
  23740. if (CollisionUtils.boxContainsBox(this._bounds, object.bounds._getBoundBox()) === ContainmentType.Contains) {
  23741. var addNode = this._checkAddNode(object);
  23742. if (addNode !== object._getOctreeNode()) {
  23743. addNode._objects.push(object);
  23744. object._setOctreeNode(addNode);
  23745. var index = this._objects.indexOf(object);
  23746. this._objects.splice(index, 1);
  23747. this._merge();
  23748. }
  23749. return true;
  23750. }
  23751. else {
  23752. if (this._parent) {
  23753. var sucess = this._parent._addUp(object);
  23754. if (sucess) {
  23755. index = this._objects.indexOf(object);
  23756. this._objects.splice(index, 1);
  23757. this._merge();
  23758. }
  23759. return sucess;
  23760. }
  23761. else {
  23762. return false;
  23763. }
  23764. }
  23765. }
  23766. add(object) {
  23767. if (!BoundsOctreeNode._encapsulates(this._bounds, object.bounds._getBoundBox()))
  23768. return false;
  23769. this._add(object);
  23770. return true;
  23771. }
  23772. remove(object) {
  23773. if (object._getOctreeNode() !== this)
  23774. return false;
  23775. this._remove(object);
  23776. return true;
  23777. }
  23778. update(object) {
  23779. if (object._getOctreeNode() !== this)
  23780. return false;
  23781. return this._update(object);
  23782. }
  23783. shrinkIfPossible(minLength) {
  23784. if (this.baseLength < minLength * 2)
  23785. return this;
  23786. var bestFit = -1;
  23787. for (var i = 0, n = this._objects.length; i < n; i++) {
  23788. var object = this._objects[i];
  23789. var newBestFit = this._bestFitChild(object.bounds.getCenter());
  23790. if (i == 0 || newBestFit == bestFit) {
  23791. var childBounds = this._getChildBound(newBestFit);
  23792. if (BoundsOctreeNode._encapsulates(childBounds, object.bounds._getBoundBox()))
  23793. (i == 0) && (bestFit = newBestFit);
  23794. else
  23795. return this;
  23796. }
  23797. else {
  23798. return this;
  23799. }
  23800. }
  23801. if (this._children != null) {
  23802. var childHadContent = false;
  23803. for (i = 0, n = this._children.length; i < n; i++) {
  23804. var child = this._children[i];
  23805. if (child && child.hasAnyObjects()) {
  23806. if (childHadContent)
  23807. return this;
  23808. if (bestFit >= 0 && bestFit != i)
  23809. return this;
  23810. childHadContent = true;
  23811. bestFit = i;
  23812. }
  23813. }
  23814. }
  23815. else {
  23816. if (bestFit != -1) {
  23817. var childCenter = this._getChildCenter(bestFit);
  23818. this._setValues(this._octree, null, this.baseLength / 2, childCenter);
  23819. }
  23820. return this;
  23821. }
  23822. if (bestFit != -1) {
  23823. var newRoot = this._children[bestFit];
  23824. newRoot._parent = null;
  23825. return newRoot;
  23826. }
  23827. else {
  23828. return this;
  23829. }
  23830. }
  23831. hasAnyObjects() {
  23832. if (this._objects.length > 0)
  23833. return true;
  23834. if (this._children != null) {
  23835. for (var i = 0; i < 8; i++) {
  23836. var child = this._children[i];
  23837. if (child && child.hasAnyObjects())
  23838. return true;
  23839. }
  23840. }
  23841. return false;
  23842. }
  23843. getCollidingWithBoundBox(checkBound, result) {
  23844. this._getCollidingWithBoundBox(checkBound, true, result);
  23845. }
  23846. getCollidingWithRay(ray, result, maxDistance = Number.MAX_VALUE) {
  23847. var distance = CollisionUtils.intersectsRayAndBoxRD(ray, this._bounds);
  23848. if (distance == -1 || distance > maxDistance)
  23849. return;
  23850. for (var i = 0, n = this._objects.length; i < n; i++) {
  23851. var object = this._objects[i];
  23852. distance = CollisionUtils.intersectsRayAndBoxRD(ray, object.bounds._getBoundBox());
  23853. if (distance !== -1 && distance <= maxDistance)
  23854. result.push(object);
  23855. }
  23856. if (this._children != null) {
  23857. for (i = 0; i < 8; i++) {
  23858. var child = this._children[i];
  23859. child.getCollidingWithRay(ray, result, maxDistance);
  23860. }
  23861. }
  23862. }
  23863. getCollidingWithFrustum(context, customShader, replacementTag) {
  23864. var cameraPos = context.camera.transform.position;
  23865. var boundFrustum = context.camera.boundFrustum;
  23866. this._getCollidingWithFrustum(context, boundFrustum, true, cameraPos, customShader, replacementTag);
  23867. }
  23868. isCollidingWithBoundBox(checkBound) {
  23869. if (!(CollisionUtils.intersectsBoxAndBox(this._bounds, checkBound)))
  23870. return false;
  23871. for (var i = 0, n = this._objects.length; i < n; i++) {
  23872. var object = this._objects[i];
  23873. if (CollisionUtils.intersectsBoxAndBox(object.bounds._getBoundBox(), checkBound))
  23874. return true;
  23875. }
  23876. if (this._children != null) {
  23877. for (i = 0; i < 8; i++) {
  23878. var child = this._children[i];
  23879. if (child.isCollidingWithBoundBox(checkBound))
  23880. return true;
  23881. }
  23882. }
  23883. return false;
  23884. }
  23885. isCollidingWithRay(ray, maxDistance = Number.MAX_VALUE) {
  23886. var distance = CollisionUtils.intersectsRayAndBoxRD(ray, this._bounds);
  23887. if (distance == -1 || distance > maxDistance)
  23888. return false;
  23889. for (var i = 0, n = this._objects.length; i < n; i++) {
  23890. var object = this._objects[i];
  23891. distance = CollisionUtils.intersectsRayAndBoxRD(ray, object.bounds._getBoundBox());
  23892. if (distance !== -1 && distance <= maxDistance)
  23893. return true;
  23894. }
  23895. if (this._children != null) {
  23896. for (i = 0; i < 8; i++) {
  23897. var child = this._children[i];
  23898. if (child.isCollidingWithRay(ray, maxDistance))
  23899. return true;
  23900. }
  23901. }
  23902. return false;
  23903. }
  23904. getBound() {
  23905. return this._bounds;
  23906. }
  23907. drawAllBounds(debugLine, currentDepth, maxDepth) {
  23908. if (this._children === null && this._objects.length == 0)
  23909. return;
  23910. currentDepth++;
  23911. var color = BoundsOctreeNode._tempColor0;
  23912. if (this._isContaion) {
  23913. color.r = 0.0;
  23914. color.g = 0.0;
  23915. color.b = 1.0;
  23916. }
  23917. else {
  23918. var tint = maxDepth ? currentDepth / maxDepth : 0;
  23919. color.r = 1.0 - tint;
  23920. color.g = tint;
  23921. color.b = 0.0;
  23922. }
  23923. color.a = 0.3;
  23924. Utils3D._drawBound(debugLine, this._bounds, color);
  23925. if (this._children != null) {
  23926. for (var i = 0; i < 8; i++) {
  23927. var child = this._children[i];
  23928. child && child.drawAllBounds(debugLine, currentDepth, maxDepth);
  23929. }
  23930. }
  23931. }
  23932. drawAllObjects(debugLine, currentDepth, maxDepth) {
  23933. currentDepth++;
  23934. var color = BoundsOctreeNode._tempColor0;
  23935. if (this._isContaion) {
  23936. color.r = 0.0;
  23937. color.g = 0.0;
  23938. color.b = 1.0;
  23939. }
  23940. else {
  23941. var tint = maxDepth ? currentDepth / maxDepth : 0;
  23942. color.r = 1.0 - tint;
  23943. color.g = tint;
  23944. color.b = 0.0;
  23945. }
  23946. color.a = 1.0;
  23947. for (var i = 0, n = this._objects.length; i < n; i++)
  23948. Utils3D._drawBound(debugLine, this._objects[i].bounds._getBoundBox(), color);
  23949. if (this._children != null) {
  23950. for (i = 0; i < 8; i++) {
  23951. var child = this._children[i];
  23952. child && child.drawAllObjects(debugLine, currentDepth, maxDepth);
  23953. }
  23954. }
  23955. }
  23956. }
  23957. BoundsOctreeNode._tempVector3 = new Vector3();
  23958. BoundsOctreeNode._tempVector30 = new Vector3();
  23959. BoundsOctreeNode._tempVector31 = new Vector3();
  23960. BoundsOctreeNode._tempColor0 = new Color();
  23961. BoundsOctreeNode._tempBoundBox = new BoundBox(new Vector3(), new Vector3());
  23962. BoundsOctreeNode._NUM_OBJECTS_ALLOWED = 8;
  23963. class OctreeMotionList extends SingletonList {
  23964. constructor() {
  23965. super();
  23966. }
  23967. add(element) {
  23968. var index = element._getIndexInMotionList();
  23969. if (index !== -1)
  23970. throw "OctreeMotionList:element has in PhysicsUpdateList.";
  23971. this._add(element);
  23972. element._setIndexInMotionList(this.length++);
  23973. }
  23974. remove(element) {
  23975. var index = element._getIndexInMotionList();
  23976. this.length--;
  23977. if (index !== this.length) {
  23978. var end = this.elements[this.length];
  23979. this.elements[index] = end;
  23980. end._setIndexInMotionList(index);
  23981. }
  23982. element._setIndexInMotionList(-1);
  23983. }
  23984. }
  23985. class BoundsOctree {
  23986. constructor(initialWorldSize, initialWorldPos, minNodeSize, looseness) {
  23987. this._motionObjects = new OctreeMotionList();
  23988. this.count = 0;
  23989. if (minNodeSize > initialWorldSize) {
  23990. console.warn("Minimum node size must be at least as big as the initial world size. Was: " + minNodeSize + " Adjusted to: " + initialWorldSize);
  23991. minNodeSize = initialWorldSize;
  23992. }
  23993. this._initialSize = initialWorldSize;
  23994. this._minSize = minNodeSize;
  23995. this._looseness = Math.min(Math.max(looseness, 1.0), 2.0);
  23996. this._rootNode = new BoundsOctreeNode(this, null, initialWorldSize, initialWorldPos);
  23997. }
  23998. _getMaxDepth(node, depth) {
  23999. depth++;
  24000. var children = node._children;
  24001. if (children != null) {
  24002. var curDepth = depth;
  24003. for (var i = 0, n = children.length; i < n; i++) {
  24004. var child = children[i];
  24005. child && (depth = Math.max(this._getMaxDepth(child, curDepth), depth));
  24006. }
  24007. }
  24008. return depth;
  24009. }
  24010. _grow(growObjectCenter) {
  24011. var xDirection = growObjectCenter.x >= 0 ? 1 : -1;
  24012. var yDirection = growObjectCenter.y >= 0 ? 1 : -1;
  24013. var zDirection = growObjectCenter.z >= 0 ? 1 : -1;
  24014. var oldRoot = this._rootNode;
  24015. var half = this._rootNode.baseLength / 2;
  24016. var newLength = this._rootNode.baseLength * 2;
  24017. var rootCenter = this._rootNode.center;
  24018. var newCenter = new Vector3(rootCenter.x + xDirection * half, rootCenter.y + yDirection * half, rootCenter.z + zDirection * half);
  24019. this._rootNode = new BoundsOctreeNode(this, null, newLength, newCenter);
  24020. if (oldRoot.hasAnyObjects()) {
  24021. var rootPos = this._rootNode._bestFitChild(oldRoot.center);
  24022. var children = [];
  24023. for (var i = 0; i < 8; i++) {
  24024. if (i == rootPos) {
  24025. oldRoot._parent = this._rootNode;
  24026. children[i] = oldRoot;
  24027. }
  24028. }
  24029. this._rootNode._children = children;
  24030. }
  24031. }
  24032. add(object) {
  24033. var count = 0;
  24034. while (!this._rootNode.add(object)) {
  24035. var growCenter = BoundsOctree._tempVector30;
  24036. Vector3.subtract(object.bounds.getCenter(), this._rootNode.center, growCenter);
  24037. this._grow(growCenter);
  24038. if (++count > 20) {
  24039. throw "Aborted Add operation as it seemed to be going on forever (" + (count - 1) + ") attempts at growing the octree.";
  24040. }
  24041. }
  24042. this.count++;
  24043. }
  24044. remove(object) {
  24045. var removed = object._getOctreeNode().remove(object);
  24046. if (removed) {
  24047. this.count--;
  24048. }
  24049. return removed;
  24050. }
  24051. update(object) {
  24052. var count = 0;
  24053. var octreeNode = object._getOctreeNode();
  24054. if (octreeNode) {
  24055. while (!octreeNode._update(object)) {
  24056. var growCenter = BoundsOctree._tempVector30;
  24057. Vector3.subtract(object.bounds.getCenter(), this._rootNode.center, growCenter);
  24058. this._grow(growCenter);
  24059. if (++count > 20) {
  24060. throw "Aborted Add operation as it seemed to be going on forever (" + (count - 1) + ") attempts at growing the octree.";
  24061. }
  24062. }
  24063. return true;
  24064. }
  24065. else {
  24066. return false;
  24067. }
  24068. }
  24069. shrinkRootIfPossible() {
  24070. this._rootNode = this._rootNode.shrinkIfPossible(this._initialSize);
  24071. }
  24072. addMotionObject(object) {
  24073. this._motionObjects.add(object);
  24074. }
  24075. removeMotionObject(object) {
  24076. this._motionObjects.remove(object);
  24077. }
  24078. updateMotionObjects() {
  24079. var elements = this._motionObjects.elements;
  24080. for (var i = 0, n = this._motionObjects.length; i < n; i++) {
  24081. var object = elements[i];
  24082. this.update(object);
  24083. object._setIndexInMotionList(-1);
  24084. }
  24085. this._motionObjects.length = 0;
  24086. }
  24087. isCollidingWithBoundBox(checkBounds) {
  24088. return this._rootNode.isCollidingWithBoundBox(checkBounds);
  24089. }
  24090. isCollidingWithRay(ray, maxDistance = Number.MAX_VALUE) {
  24091. return this._rootNode.isCollidingWithRay(ray, maxDistance);
  24092. }
  24093. getCollidingWithBoundBox(checkBound, result) {
  24094. this._rootNode.getCollidingWithBoundBox(checkBound, result);
  24095. }
  24096. getCollidingWithRay(ray, result, maxDistance = Number.MAX_VALUE) {
  24097. this._rootNode.getCollidingWithRay(ray, result, maxDistance);
  24098. }
  24099. getCollidingWithFrustum(context, shader, replacementTag) {
  24100. this._rootNode.getCollidingWithFrustum(context, shader, replacementTag);
  24101. }
  24102. getMaxBounds() {
  24103. return this._rootNode.getBound();
  24104. }
  24105. drawAllBounds(pixelLine) {
  24106. var maxDepth = this._getMaxDepth(this._rootNode, -1);
  24107. this._rootNode.drawAllBounds(pixelLine, -1, maxDepth);
  24108. }
  24109. drawAllObjects(pixelLine) {
  24110. var maxDepth = this._getMaxDepth(this._rootNode, -1);
  24111. this._rootNode.drawAllObjects(pixelLine, -1, maxDepth);
  24112. }
  24113. }
  24114. BoundsOctree._tempVector30 = new Vector3();
  24115. class Scene3D extends Laya.Sprite {
  24116. constructor() {
  24117. super();
  24118. this._lights = [];
  24119. this._lightmaps = [];
  24120. this._skyRenderer = new SkyRenderer();
  24121. this._reflectionMode = 1;
  24122. this._enableLightCount = 3;
  24123. this._input = new Input3D();
  24124. this._timer = Laya.ILaya.timer;
  24125. this._collsionTestList = [];
  24126. this._renders = new SimpleSingletonList();
  24127. this._opaqueQueue = new RenderQueue(false);
  24128. this._transparentQueue = new RenderQueue(true);
  24129. this._cameraPool = [];
  24130. this._animatorPool = new SimpleSingletonList();
  24131. this._scriptPool = new Array();
  24132. this._tempScriptPool = new Array();
  24133. this._needClearScriptPool = false;
  24134. this._castShadowRenders = new CastShadowList();
  24135. this.currentCreationLayer = Math.pow(2, 0);
  24136. this.enableLight = true;
  24137. this._key = new Laya.SubmitKey();
  24138. this._time = 0;
  24139. this._pickIdToSprite = new Object();
  24140. if (Physics3D._enbalePhysics)
  24141. this._physicsSimulation = new PhysicsSimulation(Scene3D.physicsSettings);
  24142. this._shaderValues = new ShaderData(null);
  24143. this.parallelSplitShadowMaps = [];
  24144. this.enableFog = false;
  24145. this.fogStart = 300;
  24146. this.fogRange = 1000;
  24147. this.fogColor = new Vector3(0.7, 0.7, 0.7);
  24148. this.ambientColor = new Vector3(0.212, 0.227, 0.259);
  24149. this.reflectionIntensity = 1.0;
  24150. (Laya.WebGL.shaderHighPrecision) && (this._shaderValues.addDefine(Shader3D.SHADERDEFINE_HIGHPRECISION));
  24151. if (Laya.Render.supportWebGLPlusCulling) {
  24152. this._cullingBufferIndices = new Int32Array(1024);
  24153. this._cullingBufferResult = new Int32Array(1024);
  24154. }
  24155. this._shaderValues.setTexture(Scene3D.RANGEATTENUATIONTEXTURE, ShaderInit3D._rangeAttenTex);
  24156. this._scene = this;
  24157. this._input.__init__(Laya.Render.canvas, this);
  24158. if (Scene3D.octreeCulling) {
  24159. this._octree = new BoundsOctree(Scene3D.octreeInitialSize, Scene3D.octreeInitialCenter, Scene3D.octreeMinNodeSize, Scene3D.octreeLooseness);
  24160. }
  24161. if (FrustumCulling.debugFrustumCulling) {
  24162. this._debugTool = new PixelLineSprite3D();
  24163. var lineMaterial = new PixelLineMaterial();
  24164. lineMaterial.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  24165. lineMaterial.alphaTest = false;
  24166. lineMaterial.depthWrite = false;
  24167. lineMaterial.cull = RenderState.CULL_BACK;
  24168. lineMaterial.blend = RenderState.BLEND_ENABLE_ALL;
  24169. lineMaterial.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  24170. lineMaterial.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  24171. lineMaterial.depthTest = RenderState.DEPTHTEST_LESS;
  24172. this._debugTool.pixelLineRenderer.sharedMaterial = lineMaterial;
  24173. }
  24174. }
  24175. static __init__() {
  24176. Scene3DShaderDeclaration.SHADERDEFINE_FOG = Shader3D.registerPublicDefine("FOG");
  24177. Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT = Shader3D.registerPublicDefine("DIRECTIONLIGHT");
  24178. Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT = Shader3D.registerPublicDefine("POINTLIGHT");
  24179. Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT = Shader3D.registerPublicDefine("SPOTLIGHT");
  24180. Scene3DShaderDeclaration.SHADERDEFINE_CAST_SHADOW = Shader3D.registerPublicDefine("CASTSHADOW");
  24181. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM1 = Shader3D.registerPublicDefine("SHADOWMAP_PSSM1");
  24182. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM2 = Shader3D.registerPublicDefine("SHADOWMAP_PSSM2");
  24183. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM3 = Shader3D.registerPublicDefine("SHADOWMAP_PSSM3");
  24184. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF_NO = Shader3D.registerPublicDefine("SHADOWMAP_PCF_NO");
  24185. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF1 = Shader3D.registerPublicDefine("SHADOWMAP_PCF1");
  24186. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF2 = Shader3D.registerPublicDefine("SHADOWMAP_PCF2");
  24187. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF3 = Shader3D.registerPublicDefine("SHADOWMAP_PCF3");
  24188. Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP = Shader3D.registerPublicDefine("REFLECTMAP");
  24189. }
  24190. static load(url, complete) {
  24191. Laya.ILaya.loader.create(url, complete, null, Scene3D.HIERARCHY);
  24192. }
  24193. _allotPickColorByID(id, pickColor) {
  24194. var pickColorR = Math.floor(id / (255 * 255));
  24195. id -= pickColorR * 255 * 255;
  24196. var pickColorG = Math.floor(id / 255);
  24197. id -= pickColorG * 255;
  24198. var pickColorB = id;
  24199. pickColor.x = pickColorR / 255;
  24200. pickColor.y = pickColorG / 255;
  24201. pickColor.z = pickColorB / 255;
  24202. pickColor.w = 1.0;
  24203. }
  24204. _searchIDByPickColor(pickColor) {
  24205. var id = pickColor.x * 255 * 255 + pickColor.y * 255 + pickColor.z;
  24206. return id;
  24207. }
  24208. get url() {
  24209. return this._url;
  24210. }
  24211. get enableFog() {
  24212. return this._enableFog;
  24213. }
  24214. set enableFog(value) {
  24215. if (this._enableFog !== value) {
  24216. this._enableFog = value;
  24217. if (value) {
  24218. this._shaderValues.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_FOG);
  24219. }
  24220. else
  24221. this._shaderValues.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_FOG);
  24222. }
  24223. }
  24224. get fogColor() {
  24225. return this._shaderValues.getVector3(Scene3D.FOGCOLOR);
  24226. }
  24227. set fogColor(value) {
  24228. this._shaderValues.setVector3(Scene3D.FOGCOLOR, value);
  24229. }
  24230. get fogStart() {
  24231. return this._shaderValues.getNumber(Scene3D.FOGSTART);
  24232. }
  24233. set fogStart(value) {
  24234. this._shaderValues.setNumber(Scene3D.FOGSTART, value);
  24235. }
  24236. get fogRange() {
  24237. return this._shaderValues.getNumber(Scene3D.FOGRANGE);
  24238. }
  24239. set fogRange(value) {
  24240. this._shaderValues.setNumber(Scene3D.FOGRANGE, value);
  24241. }
  24242. get ambientColor() {
  24243. return this._shaderValues.getVector3(Scene3D.AMBIENTCOLOR);
  24244. }
  24245. set ambientColor(value) {
  24246. this._shaderValues.setVector3(Scene3D.AMBIENTCOLOR, value);
  24247. }
  24248. get skyRenderer() {
  24249. return this._skyRenderer;
  24250. }
  24251. get customReflection() {
  24252. return this._shaderValues.getTexture(Scene3D.REFLECTIONTEXTURE);
  24253. }
  24254. set customReflection(value) {
  24255. this._shaderValues.setTexture(Scene3D.REFLECTIONTEXTURE, value);
  24256. if (value)
  24257. this._shaderValues.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  24258. else
  24259. this._shaderValues.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  24260. }
  24261. get reflectionIntensity() {
  24262. return this._shaderValues.getNumber(Scene3D.REFLETIONINTENSITY);
  24263. }
  24264. set reflectionIntensity(value) {
  24265. value = Math.max(Math.min(value, 1.0), 0.0);
  24266. this._shaderValues.setNumber(Scene3D.REFLETIONINTENSITY, value);
  24267. }
  24268. get physicsSimulation() {
  24269. return this._physicsSimulation;
  24270. }
  24271. get reflectionMode() {
  24272. return this._reflectionMode;
  24273. }
  24274. set reflectionMode(value) {
  24275. this._reflectionMode = value;
  24276. }
  24277. get timer() {
  24278. return this._timer;
  24279. }
  24280. set timer(value) {
  24281. this._timer = value;
  24282. }
  24283. get input() {
  24284. return this._input;
  24285. }
  24286. _setLightmapToChildNode(sprite) {
  24287. if (sprite instanceof RenderableSprite3D)
  24288. sprite._render._applyLightMapParams();
  24289. var children = sprite._children;
  24290. for (var i = 0, n = children.length; i < n; i++)
  24291. this._setLightmapToChildNode(children[i]);
  24292. }
  24293. _update() {
  24294. var delta = this.timer._delta / 1000;
  24295. this._time += delta;
  24296. this._shaderValues.setNumber(Scene3D.TIME, this._time);
  24297. var simulation = this._physicsSimulation;
  24298. if (Physics3D._enbalePhysics && !PhysicsSimulation.disableSimulation) {
  24299. simulation._updatePhysicsTransformFromRender();
  24300. PhysicsComponent._addUpdateList = false;
  24301. simulation._simulate(delta);
  24302. simulation._updateCharacters();
  24303. PhysicsComponent._addUpdateList = true;
  24304. simulation._updateCollisions();
  24305. simulation._eventScripts();
  24306. }
  24307. this._input._update();
  24308. this._clearScript();
  24309. this._updateScript();
  24310. Animator._update(this);
  24311. this._lateUpdateScript();
  24312. }
  24313. _binarySearchIndexInCameraPool(camera) {
  24314. var start = 0;
  24315. var end = this._cameraPool.length - 1;
  24316. var mid;
  24317. while (start <= end) {
  24318. mid = Math.floor((start + end) / 2);
  24319. var midValue = this._cameraPool[mid]._renderingOrder;
  24320. if (midValue == camera._renderingOrder)
  24321. return mid;
  24322. else if (midValue > camera._renderingOrder)
  24323. end = mid - 1;
  24324. else
  24325. start = mid + 1;
  24326. }
  24327. return start;
  24328. }
  24329. onEnable() {
  24330. this._input._onCanvasEvent(Laya.Render.canvas);
  24331. }
  24332. onDisable() {
  24333. this._input._offCanvasEvent(Laya.Render.canvas);
  24334. }
  24335. _setCreateURL(url) {
  24336. this._url = Laya.URL.formatURL(url);
  24337. }
  24338. _getGroup() {
  24339. return this._group;
  24340. }
  24341. _setGroup(value) {
  24342. this._group = value;
  24343. }
  24344. _clearScript() {
  24345. if (this._needClearScriptPool) {
  24346. var scripts = this._scriptPool;
  24347. for (var i = 0, n = scripts.length; i < n; i++) {
  24348. var script = scripts[i];
  24349. if (script) {
  24350. script._indexInPool = this._tempScriptPool.length;
  24351. this._tempScriptPool.push(script);
  24352. }
  24353. }
  24354. this._scriptPool = this._tempScriptPool;
  24355. scripts.length = 0;
  24356. this._tempScriptPool = scripts;
  24357. this._needClearScriptPool = false;
  24358. }
  24359. }
  24360. _updateScript() {
  24361. var scripts = this._scriptPool;
  24362. for (var i = 0, n = scripts.length; i < n; i++) {
  24363. var script = scripts[i];
  24364. (script && script.enabled) && (script.onUpdate());
  24365. }
  24366. }
  24367. _lateUpdateScript() {
  24368. var scripts = this._scriptPool;
  24369. for (var i = 0, n = scripts.length; i < n; i++) {
  24370. var script = scripts[i];
  24371. (script && script.enabled) && (script.onLateUpdate());
  24372. }
  24373. }
  24374. _addScript(script) {
  24375. var scripts = this._scriptPool;
  24376. script._indexInPool = scripts.length;
  24377. scripts.push(script);
  24378. }
  24379. _removeScript(script) {
  24380. this._scriptPool[script._indexInPool] = null;
  24381. script._indexInPool = -1;
  24382. this._needClearScriptPool = true;
  24383. }
  24384. _preRenderScript() {
  24385. var scripts = this._scriptPool;
  24386. for (var i = 0, n = scripts.length; i < n; i++) {
  24387. var script = scripts[i];
  24388. (script && script.enabled) && (script.onPreRender());
  24389. }
  24390. }
  24391. _postRenderScript() {
  24392. var scripts = this._scriptPool;
  24393. for (var i = 0, n = scripts.length; i < n; i++) {
  24394. var script = scripts[i];
  24395. (script && script.enabled) && (script.onPostRender());
  24396. }
  24397. }
  24398. _prepareSceneToRender() {
  24399. var lightCount = this._lights.length;
  24400. if (lightCount > 0) {
  24401. var renderLightCount = 0;
  24402. for (var i = 0; i < lightCount; i++) {
  24403. if (!this._lights[i]._prepareToScene())
  24404. continue;
  24405. renderLightCount++;
  24406. if (renderLightCount >= this._enableLightCount)
  24407. break;
  24408. }
  24409. }
  24410. }
  24411. _addCamera(camera) {
  24412. var index = this._binarySearchIndexInCameraPool(camera);
  24413. var order = camera._renderingOrder;
  24414. var count = this._cameraPool.length;
  24415. while (index < count && this._cameraPool[index]._renderingOrder <= order)
  24416. index++;
  24417. this._cameraPool.splice(index, 0, camera);
  24418. }
  24419. _removeCamera(camera) {
  24420. this._cameraPool.splice(this._cameraPool.indexOf(camera), 1);
  24421. }
  24422. _preCulling(context, camera, shader, replacementTag) {
  24423. FrustumCulling.renderObjectCulling(camera, this, context, this._renders, shader, replacementTag);
  24424. }
  24425. _clear(gl, state) {
  24426. var viewport = state.viewport;
  24427. var camera = state.camera;
  24428. var renderTexture = camera._renderTexture || camera._offScreenRenderTexture;
  24429. var vpW = viewport.width;
  24430. var vpH = viewport.height;
  24431. var vpX = viewport.x;
  24432. var vpY = camera._getCanvasHeight() - viewport.y - vpH;
  24433. gl.viewport(vpX, vpY, vpW, vpH);
  24434. var flag;
  24435. var clearFlag = camera.clearFlag;
  24436. if (clearFlag === BaseCamera.CLEARFLAG_SKY && !(camera.skyRenderer._isAvailable() || this._skyRenderer._isAvailable()))
  24437. clearFlag = BaseCamera.CLEARFLAG_SOLIDCOLOR;
  24438. switch (clearFlag) {
  24439. case BaseCamera.CLEARFLAG_SOLIDCOLOR:
  24440. var clearColor = camera.clearColor;
  24441. gl.enable(gl.SCISSOR_TEST);
  24442. gl.scissor(vpX, vpY, vpW, vpH);
  24443. if (clearColor)
  24444. gl.clearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
  24445. else
  24446. gl.clearColor(0, 0, 0, 0);
  24447. if (renderTexture) {
  24448. flag = gl.COLOR_BUFFER_BIT;
  24449. switch (renderTexture.depthStencilFormat) {
  24450. case Laya.BaseTexture.FORMAT_DEPTH_16:
  24451. flag |= gl.DEPTH_BUFFER_BIT;
  24452. break;
  24453. case Laya.BaseTexture.FORMAT_STENCIL_8:
  24454. flag |= gl.STENCIL_BUFFER_BIT;
  24455. break;
  24456. case Laya.BaseTexture.FORMAT_DEPTHSTENCIL_16_8:
  24457. flag |= gl.DEPTH_BUFFER_BIT;
  24458. flag |= gl.STENCIL_BUFFER_BIT;
  24459. break;
  24460. }
  24461. }
  24462. else {
  24463. flag = gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT;
  24464. }
  24465. Laya.WebGLContext.setDepthMask(gl, true);
  24466. gl.clear(flag);
  24467. gl.disable(gl.SCISSOR_TEST);
  24468. break;
  24469. case BaseCamera.CLEARFLAG_SKY:
  24470. case BaseCamera.CLEARFLAG_DEPTHONLY:
  24471. gl.enable(gl.SCISSOR_TEST);
  24472. gl.scissor(vpX, vpY, vpW, vpH);
  24473. if (renderTexture) {
  24474. switch (renderTexture.depthStencilFormat) {
  24475. case Laya.BaseTexture.FORMAT_DEPTH_16:
  24476. flag = gl.DEPTH_BUFFER_BIT;
  24477. break;
  24478. case Laya.BaseTexture.FORMAT_STENCIL_8:
  24479. flag = gl.STENCIL_BUFFER_BIT;
  24480. break;
  24481. case Laya.BaseTexture.FORMAT_DEPTHSTENCIL_16_8:
  24482. flag = gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT;
  24483. break;
  24484. }
  24485. }
  24486. else {
  24487. flag = gl.DEPTH_BUFFER_BIT;
  24488. }
  24489. Laya.WebGLContext.setDepthMask(gl, true);
  24490. gl.clear(flag);
  24491. gl.disable(gl.SCISSOR_TEST);
  24492. break;
  24493. case BaseCamera.CLEARFLAG_NONE:
  24494. break;
  24495. default:
  24496. throw new Error("BaseScene:camera clearFlag invalid.");
  24497. }
  24498. }
  24499. _renderScene(context) {
  24500. var camera = context.camera;
  24501. var renderTar = camera._renderTexture || camera._offScreenRenderTexture;
  24502. renderTar ? this._opaqueQueue._render(context, true) : this._opaqueQueue._render(context, false);
  24503. if (camera.clearFlag === BaseCamera.CLEARFLAG_SKY) {
  24504. if (camera.skyRenderer._isAvailable())
  24505. camera.skyRenderer._render(context);
  24506. else if (this._skyRenderer._isAvailable())
  24507. this._skyRenderer._render(context);
  24508. }
  24509. renderTar ? this._transparentQueue._render(context, true) : this._transparentQueue._render(context, false);
  24510. if (FrustumCulling.debugFrustumCulling) {
  24511. var renderElements = this._debugTool._render._renderElements;
  24512. for (var i = 0, n = renderElements.length; i < n; i++) {
  24513. renderElements[i]._update(this, context, null, null);
  24514. renderElements[i]._render(context, false);
  24515. }
  24516. }
  24517. }
  24518. _parse(data, spriteMap) {
  24519. var lightMapsData = data.lightmaps;
  24520. if (lightMapsData) {
  24521. var lightMapCount = lightMapsData.length;
  24522. var lightmaps = [];
  24523. for (var i = 0; i < lightMapCount; i++)
  24524. lightmaps[i] = Laya.Loader.getRes(lightMapsData[i].path);
  24525. this.setlightmaps(lightmaps);
  24526. }
  24527. var ambientColorData = data.ambientColor;
  24528. if (ambientColorData) {
  24529. var ambCol = this.ambientColor;
  24530. ambCol.fromArray(ambientColorData);
  24531. this.ambientColor = ambCol;
  24532. }
  24533. var skyData = data.sky;
  24534. if (skyData) {
  24535. this._skyRenderer.material = Laya.Loader.getRes(skyData.material.path);
  24536. switch (skyData.mesh) {
  24537. case "SkyBox":
  24538. this._skyRenderer.mesh = SkyBox.instance;
  24539. break;
  24540. case "SkyDome":
  24541. this._skyRenderer.mesh = SkyDome.instance;
  24542. break;
  24543. default:
  24544. this.skyRenderer.mesh = SkyBox.instance;
  24545. }
  24546. }
  24547. var reflectionTextureData = data.reflectionTexture;
  24548. reflectionTextureData && (this.customReflection = Laya.Loader.getRes(reflectionTextureData));
  24549. this.enableFog = data.enableFog;
  24550. this.fogStart = data.fogStart;
  24551. this.fogRange = data.fogRange;
  24552. var fogColorData = data.fogColor;
  24553. if (fogColorData) {
  24554. var fogCol = this.fogColor;
  24555. fogCol.fromArray(fogColorData);
  24556. this.fogColor = fogCol;
  24557. }
  24558. }
  24559. _onActive() {
  24560. super._onActive();
  24561. Laya.ILaya.stage._scene3Ds.push(this);
  24562. }
  24563. _onInActive() {
  24564. super._onInActive();
  24565. var scenes = Laya.ILaya.stage._scene3Ds;
  24566. scenes.splice(scenes.indexOf(this), 1);
  24567. }
  24568. _addLight(light) {
  24569. if (this._lights.indexOf(light) < 0)
  24570. this._lights.push(light);
  24571. }
  24572. _removeLight(light) {
  24573. var index = this._lights.indexOf(light);
  24574. index >= 0 && (this._lights.splice(index, 1));
  24575. }
  24576. _addRenderObject(render) {
  24577. if (this._octree && render._supportOctree) {
  24578. this._octree.add(render);
  24579. }
  24580. else {
  24581. this._renders.add(render);
  24582. if (Laya.Render.supportWebGLPlusCulling) {
  24583. var indexInList = render._getIndexInList();
  24584. var length = this._cullingBufferIndices.length;
  24585. if (indexInList >= length) {
  24586. var tempIndices = this._cullingBufferIndices;
  24587. var tempResult = this._cullingBufferResult;
  24588. this._cullingBufferIndices = new Int32Array(length + 1024);
  24589. this._cullingBufferResult = new Int32Array(length + 1024);
  24590. this._cullingBufferIndices.set(tempIndices, 0);
  24591. this._cullingBufferResult.set(tempResult, 0);
  24592. }
  24593. this._cullingBufferIndices[indexInList] = render._cullingBufferIndex;
  24594. }
  24595. }
  24596. }
  24597. _removeRenderObject(render) {
  24598. if (this._octree && render._supportOctree) {
  24599. this._octree.remove(render);
  24600. }
  24601. else {
  24602. var endRender;
  24603. if (Laya.Render.supportWebGLPlusCulling) {
  24604. endRender = this._renders.elements[this._renders.length - 1];
  24605. }
  24606. this._renders.remove(render);
  24607. if (Laya.Render.supportWebGLPlusCulling) {
  24608. this._cullingBufferIndices[endRender._getIndexInList()] = endRender._cullingBufferIndex;
  24609. }
  24610. }
  24611. }
  24612. _addShadowCastRenderObject(render) {
  24613. if (this._octree) ;
  24614. else {
  24615. this._castShadowRenders.add(render);
  24616. }
  24617. }
  24618. _removeShadowCastRenderObject(render) {
  24619. if (this._octree) ;
  24620. else {
  24621. this._castShadowRenders.remove(render);
  24622. }
  24623. }
  24624. _getRenderQueue(index) {
  24625. if (index <= 2500)
  24626. return this._opaqueQueue;
  24627. else
  24628. return this._transparentQueue;
  24629. }
  24630. setlightmaps(value) {
  24631. var maps = this._lightmaps;
  24632. for (var i = 0, n = maps.length; i < n; i++)
  24633. maps[i]._removeReference();
  24634. if (value) {
  24635. var count = value.length;
  24636. maps.length = count;
  24637. for (i = 0; i < count; i++) {
  24638. var lightMap = value[i];
  24639. lightMap._addReference();
  24640. maps[i] = lightMap;
  24641. }
  24642. }
  24643. else {
  24644. throw new Error("Scene3D: value value can't be null.");
  24645. }
  24646. for (i = 0, n = this._children.length; i < n; i++)
  24647. this._setLightmapToChildNode(this._children[i]);
  24648. }
  24649. getlightmaps() {
  24650. return this._lightmaps.slice();
  24651. }
  24652. destroy(destroyChild = true) {
  24653. if (this.destroyed)
  24654. return;
  24655. super.destroy(destroyChild);
  24656. this._skyRenderer.destroy();
  24657. this._skyRenderer = null;
  24658. this._lights = null;
  24659. this._lightmaps = null;
  24660. this._renderTargetTexture = null;
  24661. this._shaderValues = null;
  24662. this._renders = null;
  24663. this._castShadowRenders = null;
  24664. this._cameraPool = null;
  24665. this._octree = null;
  24666. this.parallelSplitShadowMaps = null;
  24667. this._physicsSimulation && this._physicsSimulation._destroy();
  24668. Laya.Loader.clearRes(this.url);
  24669. }
  24670. render(ctx, x, y) {
  24671. ctx._curSubmit = Laya.SubmitBase.RENDERBASE;
  24672. this._children.length > 0 && ctx.addRenderObject(this);
  24673. }
  24674. renderSubmit() {
  24675. var gl = Laya.LayaGL.instance;
  24676. this._prepareSceneToRender();
  24677. var i, n, n1;
  24678. for (i = 0, n = this._cameraPool.length, n1 = n - 1; i < n; i++) {
  24679. if (Laya.Render.supportWebGLPlusRendering)
  24680. ShaderData.setRuntimeValueMode((i == n1) ? true : false);
  24681. var camera = this._cameraPool[i];
  24682. camera.enableRender && camera.render();
  24683. }
  24684. Laya.Context.set2DRenderConfig();
  24685. return 1;
  24686. }
  24687. getRenderType() {
  24688. return 0;
  24689. }
  24690. releaseRender() {
  24691. }
  24692. reUse(context, pos) {
  24693. return 0;
  24694. }
  24695. }
  24696. Scene3D.HIERARCHY = "HIERARCHY";
  24697. Scene3D.physicsSettings = new PhysicsSettings();
  24698. Scene3D.octreeCulling = false;
  24699. Scene3D.octreeInitialSize = 64.0;
  24700. Scene3D.octreeInitialCenter = new Vector3(0, 0, 0);
  24701. Scene3D.octreeMinNodeSize = 2.0;
  24702. Scene3D.octreeLooseness = 1.25;
  24703. Scene3D.REFLECTIONMODE_SKYBOX = 0;
  24704. Scene3D.REFLECTIONMODE_CUSTOM = 1;
  24705. Scene3D.FOGCOLOR = Shader3D.propertyNameToID("u_FogColor");
  24706. Scene3D.FOGSTART = Shader3D.propertyNameToID("u_FogStart");
  24707. Scene3D.FOGRANGE = Shader3D.propertyNameToID("u_FogRange");
  24708. Scene3D.LIGHTDIRECTION = Shader3D.propertyNameToID("u_DirectionLight.Direction");
  24709. Scene3D.LIGHTDIRCOLOR = Shader3D.propertyNameToID("u_DirectionLight.Color");
  24710. Scene3D.POINTLIGHTPOS = Shader3D.propertyNameToID("u_PointLight.Position");
  24711. Scene3D.POINTLIGHTRANGE = Shader3D.propertyNameToID("u_PointLight.Range");
  24712. Scene3D.POINTLIGHTATTENUATION = Shader3D.propertyNameToID("u_PointLight.Attenuation");
  24713. Scene3D.POINTLIGHTCOLOR = Shader3D.propertyNameToID("u_PointLight.Color");
  24714. Scene3D.SPOTLIGHTPOS = Shader3D.propertyNameToID("u_SpotLight.Position");
  24715. Scene3D.SPOTLIGHTDIRECTION = Shader3D.propertyNameToID("u_SpotLight.Direction");
  24716. Scene3D.SPOTLIGHTSPOTANGLE = Shader3D.propertyNameToID("u_SpotLight.Spot");
  24717. Scene3D.SPOTLIGHTRANGE = Shader3D.propertyNameToID("u_SpotLight.Range");
  24718. Scene3D.SPOTLIGHTCOLOR = Shader3D.propertyNameToID("u_SpotLight.Color");
  24719. Scene3D.SHADOWDISTANCE = Shader3D.propertyNameToID("u_shadowPSSMDistance");
  24720. Scene3D.SHADOWLIGHTVIEWPROJECT = Shader3D.propertyNameToID("u_lightShadowVP");
  24721. Scene3D.SHADOWMAPPCFOFFSET = Shader3D.propertyNameToID("u_shadowPCFoffset");
  24722. Scene3D.SHADOWMAPTEXTURE1 = Shader3D.propertyNameToID("u_shadowMap1");
  24723. Scene3D.SHADOWMAPTEXTURE2 = Shader3D.propertyNameToID("u_shadowMap2");
  24724. Scene3D.SHADOWMAPTEXTURE3 = Shader3D.propertyNameToID("u_shadowMap3");
  24725. Scene3D.AMBIENTCOLOR = Shader3D.propertyNameToID("u_AmbientColor");
  24726. Scene3D.REFLECTIONTEXTURE = Shader3D.propertyNameToID("u_ReflectTexture");
  24727. Scene3D.REFLETIONINTENSITY = Shader3D.propertyNameToID("u_ReflectIntensity");
  24728. Scene3D.TIME = Shader3D.propertyNameToID("u_Time");
  24729. Scene3D.ANGLEATTENUATIONTEXTURE = Shader3D.propertyNameToID("u_AngleTexture");
  24730. Scene3D.RANGEATTENUATIONTEXTURE = Shader3D.propertyNameToID("u_RangeTexture");
  24731. Scene3D.POINTLIGHTMATRIX = Shader3D.propertyNameToID("u_PointLightMatrix");
  24732. Scene3D.SPOTLIGHTMATRIX = Shader3D.propertyNameToID("u_SpotLightMatrix");
  24733. class Scene3DUtils {
  24734. static _createSprite3DInstance(nodeData, spriteMap, outBatchSprites) {
  24735. var node;
  24736. switch (nodeData.type) {
  24737. case "Scene3D":
  24738. node = new Scene3D();
  24739. break;
  24740. case "Sprite3D":
  24741. node = new Sprite3D();
  24742. break;
  24743. case "MeshSprite3D":
  24744. node = new MeshSprite3D();
  24745. (outBatchSprites) && (outBatchSprites.push(node));
  24746. break;
  24747. case "SkinnedMeshSprite3D":
  24748. node = new SkinnedMeshSprite3D();
  24749. break;
  24750. case "ShuriKenParticle3D":
  24751. node = new ShuriKenParticle3D();
  24752. break;
  24753. case "Camera":
  24754. node = new Camera();
  24755. break;
  24756. case "DirectionLight":
  24757. node = new DirectionLight();
  24758. break;
  24759. case "PointLight":
  24760. node = new PointLight();
  24761. break;
  24762. case "SpotLight":
  24763. node = new SpotLight();
  24764. break;
  24765. case "TrailSprite3D":
  24766. node = new TrailSprite3D();
  24767. break;
  24768. default:
  24769. throw new Error("Utils3D:unidentified class type in (.lh) file.");
  24770. }
  24771. var childData = nodeData.child;
  24772. if (childData) {
  24773. for (var i = 0, n = childData.length; i < n; i++) {
  24774. var child = Scene3DUtils._createSprite3DInstance(childData[i], spriteMap, outBatchSprites);
  24775. node.addChild(child);
  24776. }
  24777. }
  24778. spriteMap[nodeData.instanceID] = node;
  24779. return node;
  24780. }
  24781. static _createComponentInstance(nodeData, spriteMap) {
  24782. var node = spriteMap[nodeData.instanceID];
  24783. node._parse(nodeData.props, spriteMap);
  24784. var childData = nodeData.child;
  24785. if (childData) {
  24786. for (var i = 0, n = childData.length; i < n; i++)
  24787. Scene3DUtils._createComponentInstance(childData[i], spriteMap);
  24788. }
  24789. var componentsData = nodeData.components;
  24790. if (componentsData) {
  24791. for (var j = 0, m = componentsData.length; j < m; j++) {
  24792. var data = componentsData[j];
  24793. var clas = Laya.ClassUtils.getRegClass(data.type);
  24794. if (clas) {
  24795. var component = node.addComponent(clas);
  24796. component._parse(data);
  24797. }
  24798. else {
  24799. console.warn("Unkown component type.");
  24800. }
  24801. }
  24802. }
  24803. }
  24804. static _createNodeByJson02(nodeData, outBatchSprites) {
  24805. var spriteMap = {};
  24806. var node = Scene3DUtils._createSprite3DInstance(nodeData, spriteMap, outBatchSprites);
  24807. Scene3DUtils._createComponentInstance(nodeData, spriteMap);
  24808. return node;
  24809. }
  24810. static _parse(data, propertyParams = null, constructParams = null) {
  24811. var json = data.data;
  24812. var outBatchSprits = [];
  24813. var sprite;
  24814. switch (data.version) {
  24815. case "LAYAHIERARCHY:02":
  24816. sprite = Scene3DUtils._createNodeByJson02(json, outBatchSprits);
  24817. break;
  24818. default:
  24819. sprite = Scene3DUtils._createNodeByJson(json, outBatchSprits);
  24820. }
  24821. StaticBatchManager.combine(sprite, outBatchSprits);
  24822. return sprite;
  24823. }
  24824. static _parseScene(data, propertyParams = null, constructParams = null) {
  24825. var json = data.data;
  24826. var outBatchSprits = [];
  24827. var scene;
  24828. switch (data.version) {
  24829. case "LAYASCENE3D:02":
  24830. scene = Scene3DUtils._createNodeByJson02(json, outBatchSprits);
  24831. break;
  24832. default:
  24833. scene = Scene3DUtils._createNodeByJson(json, outBatchSprits);
  24834. }
  24835. StaticBatchManager.combine(null, outBatchSprits);
  24836. return scene;
  24837. }
  24838. static _createNodeByJson(nodeData, outBatchSprites) {
  24839. var node;
  24840. switch (nodeData.type) {
  24841. case "Scene3D":
  24842. node = new Scene3D();
  24843. break;
  24844. case "Sprite3D":
  24845. node = new Sprite3D();
  24846. break;
  24847. case "MeshSprite3D":
  24848. node = new MeshSprite3D();
  24849. (outBatchSprites) && (outBatchSprites.push(node));
  24850. break;
  24851. case "SkinnedMeshSprite3D":
  24852. node = new SkinnedMeshSprite3D();
  24853. break;
  24854. case "ShuriKenParticle3D":
  24855. node = new ShuriKenParticle3D();
  24856. break;
  24857. case "Camera":
  24858. node = new Camera();
  24859. break;
  24860. case "DirectionLight":
  24861. node = new DirectionLight();
  24862. break;
  24863. case "PointLight":
  24864. node = new PointLight();
  24865. break;
  24866. case "SpotLight":
  24867. node = new SpotLight();
  24868. break;
  24869. case "TrailSprite3D":
  24870. node = new TrailSprite3D();
  24871. break;
  24872. default:
  24873. throw new Error("Utils3D:unidentified class type in (.lh) file.");
  24874. }
  24875. var childData = nodeData.child;
  24876. if (childData) {
  24877. for (var i = 0, n = childData.length; i < n; i++) {
  24878. var child = Scene3DUtils._createNodeByJson(childData[i], outBatchSprites);
  24879. node.addChild(child);
  24880. }
  24881. }
  24882. var componentsData = nodeData.components;
  24883. if (componentsData) {
  24884. for (var j = 0, m = componentsData.length; j < m; j++) {
  24885. var data = componentsData[j];
  24886. var clas = Laya.ClassUtils.getRegClass(data.type);
  24887. if (clas) {
  24888. var component = node.addComponent(clas);
  24889. component._parse(data);
  24890. }
  24891. else {
  24892. console.warn("Unkown component type.");
  24893. }
  24894. }
  24895. }
  24896. node._parse(nodeData.props, null);
  24897. return node;
  24898. }
  24899. }
  24900. class KeyframeNode {
  24901. constructor() {
  24902. this._ownerPath = [];
  24903. this._propertys = [];
  24904. this._keyFrames = [];
  24905. }
  24906. get ownerPathCount() {
  24907. return this._ownerPath.length;
  24908. }
  24909. get propertyCount() {
  24910. return this._propertys.length;
  24911. }
  24912. get keyFramesCount() {
  24913. return this._keyFrames.length;
  24914. }
  24915. _setOwnerPathCount(value) {
  24916. this._ownerPath.length = value;
  24917. }
  24918. _setOwnerPathByIndex(index, value) {
  24919. this._ownerPath[index] = value;
  24920. }
  24921. _joinOwnerPath(sep) {
  24922. return this._ownerPath.join(sep);
  24923. }
  24924. _setPropertyCount(value) {
  24925. this._propertys.length = value;
  24926. }
  24927. _setPropertyByIndex(index, value) {
  24928. this._propertys[index] = value;
  24929. }
  24930. _joinProperty(sep) {
  24931. return this._propertys.join(sep);
  24932. }
  24933. _setKeyframeCount(value) {
  24934. this._keyFrames.length = value;
  24935. }
  24936. _setKeyframeByIndex(index, value) {
  24937. this._keyFrames[index] = value;
  24938. }
  24939. getOwnerPathByIndex(index) {
  24940. return this._ownerPath[index];
  24941. }
  24942. getPropertyByIndex(index) {
  24943. return this._propertys[index];
  24944. }
  24945. getKeyframeByIndex(index) {
  24946. return this._keyFrames[index];
  24947. }
  24948. }
  24949. if (window.conch && window.conchKeyframeNode) {
  24950. KeyframeNode = window.conchKeyframeNode;
  24951. }
  24952. if (window.qq && window.qq.webglPlus) {
  24953. KeyframeNode = window.qq.webglPlus.conchKeyframeNode;
  24954. }
  24955. class AnimationEvent {
  24956. constructor() {
  24957. }
  24958. }
  24959. class QuaternionKeyframe extends Keyframe {
  24960. constructor() {
  24961. super();
  24962. this.inTangent = new Vector4();
  24963. this.outTangent = new Vector4();
  24964. this.value = new Quaternion();
  24965. }
  24966. cloneTo(dest) {
  24967. super.cloneTo(dest);
  24968. var destKeyFarme = dest;
  24969. this.inTangent.cloneTo(destKeyFarme.inTangent);
  24970. this.outTangent.cloneTo(destKeyFarme.outTangent);
  24971. this.value.cloneTo(destKeyFarme.value);
  24972. }
  24973. }
  24974. if (window.conch && window.conchFloatArrayKeyframe) {
  24975. QuaternionKeyframe = window.conchFloatArrayKeyframe;
  24976. }
  24977. if (window.qq && window.qq.webglPlus) {
  24978. QuaternionKeyframe = window.qq.webglPlus.conchFloatArrayKeyframe;
  24979. }
  24980. class Vector3Keyframe extends Keyframe {
  24981. constructor() {
  24982. super();
  24983. this.inTangent = new Vector3();
  24984. this.outTangent = new Vector3();
  24985. this.value = new Vector3();
  24986. }
  24987. cloneTo(dest) {
  24988. super.cloneTo(dest);
  24989. var destKeyFarme = dest;
  24990. this.inTangent.cloneTo(destKeyFarme.inTangent);
  24991. this.outTangent.cloneTo(destKeyFarme.outTangent);
  24992. this.value.cloneTo(destKeyFarme.value);
  24993. }
  24994. }
  24995. if (window.conch && window.conchFloatArrayKeyframe) {
  24996. Vector3Keyframe = window.conchFloatArrayKeyframe;
  24997. }
  24998. if (window.qq && window.qq.webglPlus) {
  24999. Vector3Keyframe = window.qq.webglPlus.conchFloatArrayKeyframe;
  25000. }
  25001. class ConchVector4 {
  25002. constructor(x = 0, y = 0, z = 0, w = 0) {
  25003. var v = this.elements = new Float32Array(4);
  25004. v[0] = x;
  25005. v[1] = y;
  25006. v[2] = z;
  25007. v[3] = w;
  25008. }
  25009. get x() {
  25010. return this.elements[0];
  25011. }
  25012. set x(value) {
  25013. this.elements[0] = value;
  25014. }
  25015. get y() {
  25016. return this.elements[1];
  25017. }
  25018. set y(value) {
  25019. this.elements[1] = value;
  25020. }
  25021. get z() {
  25022. return this.elements[2];
  25023. }
  25024. set z(value) {
  25025. this.elements[2] = value;
  25026. }
  25027. get w() {
  25028. return this.elements[3];
  25029. }
  25030. set w(value) {
  25031. this.elements[3] = value;
  25032. }
  25033. fromArray(array, offset = 0) {
  25034. this.elements[0] = array[offset + 0];
  25035. this.elements[1] = array[offset + 1];
  25036. this.elements[2] = array[offset + 2];
  25037. this.elements[3] = array[offset + 3];
  25038. }
  25039. cloneTo(destObject) {
  25040. var destVector4 = destObject;
  25041. var destE = destVector4.elements;
  25042. var s = this.elements;
  25043. destE[0] = s[0];
  25044. destE[1] = s[1];
  25045. destE[2] = s[2];
  25046. destE[3] = s[3];
  25047. }
  25048. clone() {
  25049. var destVector4 = new ConchVector4();
  25050. this.cloneTo(destVector4);
  25051. return destVector4;
  25052. }
  25053. static lerp(a, b, t, out) {
  25054. var e = out.elements;
  25055. var f = a.elements;
  25056. var g = b.elements;
  25057. var ax = f[0], ay = f[1], az = f[2], aw = f[3];
  25058. e[0] = ax + t * (g[0] - ax);
  25059. e[1] = ay + t * (g[1] - ay);
  25060. e[2] = az + t * (g[2] - az);
  25061. e[3] = aw + t * (g[3] - aw);
  25062. }
  25063. static transformByM4x4(vector4, m4x4, out) {
  25064. var ve = vector4.elements;
  25065. var vx = ve[0];
  25066. var vy = ve[1];
  25067. var vz = ve[2];
  25068. var vw = ve[3];
  25069. var me = m4x4.elements;
  25070. var oe = out.elements;
  25071. oe[0] = vx * me[0] + vy * me[4] + vz * me[8] + vw * me[12];
  25072. oe[1] = vx * me[1] + vy * me[5] + vz * me[9] + vw * me[13];
  25073. oe[2] = vx * me[2] + vy * me[6] + vz * me[10] + vw * me[14];
  25074. oe[3] = vx * me[3] + vy * me[7] + vz * me[11] + vw * me[15];
  25075. }
  25076. static equals(a, b) {
  25077. var ae = a.elements;
  25078. var be = b.elements;
  25079. return MathUtils3D.nearEqual(Math.abs(ae[0]), Math.abs(be[0])) && MathUtils3D.nearEqual(Math.abs(ae[1]), Math.abs(be[1])) && MathUtils3D.nearEqual(Math.abs(ae[2]), Math.abs(be[2])) && MathUtils3D.nearEqual(Math.abs(ae[3]), Math.abs(be[3]));
  25080. }
  25081. length() {
  25082. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  25083. }
  25084. lengthSquared() {
  25085. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  25086. }
  25087. static normalize(s, out) {
  25088. var se = s.elements;
  25089. var oe = out.elements;
  25090. var len = s.length();
  25091. if (len > 0) {
  25092. oe[0] = se[0] * len;
  25093. oe[1] = se[1] * len;
  25094. oe[2] = se[2] * len;
  25095. oe[3] = se[3] * len;
  25096. }
  25097. }
  25098. static add(a, b, out) {
  25099. var oe = out.elements;
  25100. var ae = a.elements;
  25101. var be = b.elements;
  25102. oe[0] = ae[0] + be[0];
  25103. oe[1] = ae[1] + be[1];
  25104. oe[2] = ae[2] + be[2];
  25105. oe[3] = ae[3] + be[3];
  25106. }
  25107. static subtract(a, b, out) {
  25108. var oe = out.elements;
  25109. var ae = a.elements;
  25110. var be = b.elements;
  25111. oe[0] = ae[0] - be[0];
  25112. oe[1] = ae[1] - be[1];
  25113. oe[2] = ae[2] - be[2];
  25114. oe[3] = ae[3] - be[3];
  25115. }
  25116. static multiply(a, b, out) {
  25117. var oe = out.elements;
  25118. var ae = a.elements;
  25119. var be = b.elements;
  25120. oe[0] = ae[0] * be[0];
  25121. oe[1] = ae[1] * be[1];
  25122. oe[2] = ae[2] * be[2];
  25123. oe[3] = ae[3] * be[3];
  25124. }
  25125. static scale(a, b, out) {
  25126. var oe = out.elements;
  25127. var ae = a.elements;
  25128. oe[0] = ae[0] * b;
  25129. oe[1] = ae[1] * b;
  25130. oe[2] = ae[2] * b;
  25131. oe[3] = ae[3] * b;
  25132. }
  25133. static Clamp(value, min, max, out) {
  25134. var valuee = value.elements;
  25135. var x = valuee[0];
  25136. var y = valuee[1];
  25137. var z = valuee[2];
  25138. var w = valuee[3];
  25139. var mine = min.elements;
  25140. var mineX = mine[0];
  25141. var mineY = mine[1];
  25142. var mineZ = mine[2];
  25143. var mineW = mine[3];
  25144. var maxe = max.elements;
  25145. var maxeX = maxe[0];
  25146. var maxeY = maxe[1];
  25147. var maxeZ = maxe[2];
  25148. var maxeW = maxe[3];
  25149. var oute = out.elements;
  25150. x = (x > maxeX) ? maxeX : x;
  25151. x = (x < mineX) ? mineX : x;
  25152. y = (y > maxeY) ? maxeY : y;
  25153. y = (y < mineY) ? mineY : y;
  25154. z = (z > maxeZ) ? maxeZ : z;
  25155. z = (z < mineZ) ? mineZ : z;
  25156. w = (w > maxeW) ? maxeW : w;
  25157. w = (w < mineW) ? mineW : w;
  25158. oute[0] = x;
  25159. oute[1] = y;
  25160. oute[2] = z;
  25161. oute[3] = w;
  25162. }
  25163. static distanceSquared(value1, value2) {
  25164. var value1e = value1.elements;
  25165. var value2e = value2.elements;
  25166. var x = value1e[0] - value2e[0];
  25167. var y = value1e[1] - value2e[1];
  25168. var z = value1e[2] - value2e[2];
  25169. var w = value1e[3] - value2e[3];
  25170. return (x * x) + (y * y) + (z * z) + (w * w);
  25171. }
  25172. static distance(value1, value2) {
  25173. var value1e = value1.elements;
  25174. var value2e = value2.elements;
  25175. var x = value1e[0] - value2e[0];
  25176. var y = value1e[1] - value2e[1];
  25177. var z = value1e[2] - value2e[2];
  25178. var w = value1e[3] - value2e[3];
  25179. return Math.sqrt((x * x) + (y * y) + (z * z) + (w * w));
  25180. }
  25181. static dot(a, b) {
  25182. var ae = a.elements;
  25183. var be = b.elements;
  25184. var r = (ae[0] * be[0]) + (ae[1] * be[1]) + (ae[2] * be[2]) + (ae[3] * be[3]);
  25185. return r;
  25186. }
  25187. static min(a, b, out) {
  25188. var e = out.elements;
  25189. var f = a.elements;
  25190. var g = b.elements;
  25191. e[0] = Math.min(f[0], g[0]);
  25192. e[1] = Math.min(f[1], g[1]);
  25193. e[2] = Math.min(f[2], g[2]);
  25194. e[3] = Math.min(f[3], g[3]);
  25195. }
  25196. static max(a, b, out) {
  25197. var e = out.elements;
  25198. var f = a.elements;
  25199. var g = b.elements;
  25200. e[0] = Math.max(f[0], g[0]);
  25201. e[1] = Math.max(f[1], g[1]);
  25202. e[2] = Math.max(f[2], g[2]);
  25203. e[3] = Math.max(f[3], g[3]);
  25204. }
  25205. }
  25206. ConchVector4.ZERO = new ConchVector4();
  25207. ConchVector4.ONE = new ConchVector4(1.0, 1.0, 1.0, 1.0);
  25208. ConchVector4.UnitX = new ConchVector4(1.0, 0.0, 0.0, 0.0);
  25209. ConchVector4.UnitY = new ConchVector4(0.0, 1.0, 0.0, 0.0);
  25210. ConchVector4.UnitZ = new ConchVector4(0.0, 0.0, 1.0, 0.0);
  25211. ConchVector4.UnitW = new ConchVector4(0.0, 0.0, 0.0, 1.0);
  25212. class ConchVector3 {
  25213. constructor(x = 0, y = 0, z = 0, nativeElements = null) {
  25214. var v;
  25215. if (nativeElements) {
  25216. v = nativeElements;
  25217. }
  25218. else {
  25219. v = new Float32Array(3);
  25220. }
  25221. this.elements = v;
  25222. v[0] = x;
  25223. v[1] = y;
  25224. v[2] = z;
  25225. }
  25226. static distanceSquared(value1, value2) {
  25227. var value1e = value1.elements;
  25228. var value2e = value2.elements;
  25229. var x = value1e[0] - value2e[0];
  25230. var y = value1e[1] - value2e[1];
  25231. var z = value1e[2] - value2e[2];
  25232. return (x * x) + (y * y) + (z * z);
  25233. }
  25234. static distance(value1, value2) {
  25235. var value1e = value1.elements;
  25236. var value2e = value2.elements;
  25237. var x = value1e[0] - value2e[0];
  25238. var y = value1e[1] - value2e[1];
  25239. var z = value1e[2] - value2e[2];
  25240. return Math.sqrt((x * x) + (y * y) + (z * z));
  25241. }
  25242. static min(a, b, out) {
  25243. var e = out.elements;
  25244. var f = a.elements;
  25245. var g = b.elements;
  25246. e[0] = Math.min(f[0], g[0]);
  25247. e[1] = Math.min(f[1], g[1]);
  25248. e[2] = Math.min(f[2], g[2]);
  25249. }
  25250. static max(a, b, out) {
  25251. var e = out.elements;
  25252. var f = a.elements;
  25253. var g = b.elements;
  25254. e[0] = Math.max(f[0], g[0]);
  25255. e[1] = Math.max(f[1], g[1]);
  25256. e[2] = Math.max(f[2], g[2]);
  25257. }
  25258. static transformQuat(source, rotation, out) {
  25259. var destination = out.elements;
  25260. var se = source.elements;
  25261. var re = rotation.elements;
  25262. var x = se[0], y = se[1], z = se[2], qx = re[0], qy = re[1], qz = re[2], qw = re[3], ix = qw * x + qy * z - qz * y, iy = qw * y + qz * x - qx * z, iz = qw * z + qx * y - qy * x, iw = -qx * x - qy * y - qz * z;
  25263. destination[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  25264. destination[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  25265. destination[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  25266. }
  25267. static scalarLength(a) {
  25268. var f = a.elements;
  25269. var x = f[0], y = f[1], z = f[2];
  25270. return Math.sqrt(x * x + y * y + z * z);
  25271. }
  25272. static scalarLengthSquared(a) {
  25273. var f = a.elements;
  25274. var x = f[0], y = f[1], z = f[2];
  25275. return x * x + y * y + z * z;
  25276. }
  25277. static normalize(s, out) {
  25278. var se = s.elements;
  25279. var oe = out.elements;
  25280. var x = se[0], y = se[1], z = se[2];
  25281. var len = x * x + y * y + z * z;
  25282. if (len > 0) {
  25283. len = 1 / Math.sqrt(len);
  25284. oe[0] = se[0] * len;
  25285. oe[1] = se[1] * len;
  25286. oe[2] = se[2] * len;
  25287. }
  25288. }
  25289. static multiply(a, b, out) {
  25290. var e = out.elements;
  25291. var f = a.elements;
  25292. var g = b.elements;
  25293. e[0] = f[0] * g[0];
  25294. e[1] = f[1] * g[1];
  25295. e[2] = f[2] * g[2];
  25296. }
  25297. static scale(a, b, out) {
  25298. var e = out.elements;
  25299. var f = a.elements;
  25300. e[0] = f[0] * b;
  25301. e[1] = f[1] * b;
  25302. e[2] = f[2] * b;
  25303. }
  25304. static lerp(a, b, t, out) {
  25305. var e = out.elements;
  25306. var f = a.elements;
  25307. var g = b.elements;
  25308. var ax = f[0], ay = f[1], az = f[2];
  25309. e[0] = ax + t * (g[0] - ax);
  25310. e[1] = ay + t * (g[1] - ay);
  25311. e[2] = az + t * (g[2] - az);
  25312. }
  25313. static transformV3ToV3(vector, transform, result) {
  25314. var intermediate = ConchVector3._tempVector4;
  25315. ConchVector3.transformV3ToV4(vector, transform, intermediate);
  25316. var intermediateElem = intermediate.elements;
  25317. var resultElem = result.elements;
  25318. resultElem[0] = intermediateElem[0];
  25319. resultElem[1] = intermediateElem[1];
  25320. resultElem[2] = intermediateElem[2];
  25321. }
  25322. static transformV3ToV4(vector, transform, result) {
  25323. var vectorElem = vector.elements;
  25324. var vectorX = vectorElem[0];
  25325. var vectorY = vectorElem[1];
  25326. var vectorZ = vectorElem[2];
  25327. var transformElem = transform.elements;
  25328. var resultElem = result.elements;
  25329. resultElem[0] = (vectorX * transformElem[0]) + (vectorY * transformElem[4]) + (vectorZ * transformElem[8]) + transformElem[12];
  25330. resultElem[1] = (vectorX * transformElem[1]) + (vectorY * transformElem[5]) + (vectorZ * transformElem[9]) + transformElem[13];
  25331. resultElem[2] = (vectorX * transformElem[2]) + (vectorY * transformElem[6]) + (vectorZ * transformElem[10]) + transformElem[14];
  25332. resultElem[3] = (vectorX * transformElem[3]) + (vectorY * transformElem[7]) + (vectorZ * transformElem[11]) + transformElem[15];
  25333. }
  25334. static TransformNormal(normal, transform, result) {
  25335. var normalElem = normal.elements;
  25336. var normalX = normalElem[0];
  25337. var normalY = normalElem[1];
  25338. var normalZ = normalElem[2];
  25339. var transformElem = transform.elements;
  25340. var resultElem = result.elements;
  25341. resultElem[0] = (normalX * transformElem[0]) + (normalY * transformElem[4]) + (normalZ * transformElem[8]);
  25342. resultElem[1] = (normalX * transformElem[1]) + (normalY * transformElem[5]) + (normalZ * transformElem[9]);
  25343. resultElem[2] = (normalX * transformElem[2]) + (normalY * transformElem[6]) + (normalZ * transformElem[10]);
  25344. }
  25345. static transformCoordinate(coordinate, transform, result) {
  25346. var coordinateElem = coordinate.elements;
  25347. var coordinateX = coordinateElem[0];
  25348. var coordinateY = coordinateElem[1];
  25349. var coordinateZ = coordinateElem[2];
  25350. var transformElem = transform.elements;
  25351. var w = ((coordinateX * transformElem[3]) + (coordinateY * transformElem[7]) + (coordinateZ * transformElem[11]) + transformElem[15]);
  25352. var resultElem = result.elements;
  25353. resultElem[0] = (coordinateX * transformElem[0]) + (coordinateY * transformElem[4]) + (coordinateZ * transformElem[8]) + transformElem[12] / w;
  25354. resultElem[1] = (coordinateX * transformElem[1]) + (coordinateY * transformElem[5]) + (coordinateZ * transformElem[9]) + transformElem[13] / w;
  25355. resultElem[2] = (coordinateX * transformElem[2]) + (coordinateY * transformElem[6]) + (coordinateZ * transformElem[10]) + transformElem[14] / w;
  25356. }
  25357. static Clamp(value, min, max, out) {
  25358. var valuee = value.elements;
  25359. var x = valuee[0];
  25360. var y = valuee[1];
  25361. var z = valuee[2];
  25362. var mine = min.elements;
  25363. var mineX = mine[0];
  25364. var mineY = mine[1];
  25365. var mineZ = mine[2];
  25366. var maxe = max.elements;
  25367. var maxeX = maxe[0];
  25368. var maxeY = maxe[1];
  25369. var maxeZ = maxe[2];
  25370. var oute = out.elements;
  25371. x = (x > maxeX) ? maxeX : x;
  25372. x = (x < mineX) ? mineX : x;
  25373. y = (y > maxeY) ? maxeY : y;
  25374. y = (y < mineY) ? mineY : y;
  25375. z = (z > maxeZ) ? maxeZ : z;
  25376. z = (z < mineZ) ? mineZ : z;
  25377. oute[0] = x;
  25378. oute[1] = y;
  25379. oute[2] = z;
  25380. }
  25381. static add(a, b, out) {
  25382. var e = out.elements;
  25383. var f = a.elements;
  25384. var g = b.elements;
  25385. e[0] = f[0] + g[0];
  25386. e[1] = f[1] + g[1];
  25387. e[2] = f[2] + g[2];
  25388. }
  25389. static subtract(a, b, o) {
  25390. var oe = o.elements;
  25391. var ae = a.elements;
  25392. var be = b.elements;
  25393. oe[0] = ae[0] - be[0];
  25394. oe[1] = ae[1] - be[1];
  25395. oe[2] = ae[2] - be[2];
  25396. }
  25397. static cross(a, b, o) {
  25398. var ae = a.elements;
  25399. var be = b.elements;
  25400. var oe = o.elements;
  25401. var ax = ae[0], ay = ae[1], az = ae[2], bx = be[0], by = be[1], bz = be[2];
  25402. oe[0] = ay * bz - az * by;
  25403. oe[1] = az * bx - ax * bz;
  25404. oe[2] = ax * by - ay * bx;
  25405. }
  25406. static dot(a, b) {
  25407. var ae = a.elements;
  25408. var be = b.elements;
  25409. var r = (ae[0] * be[0]) + (ae[1] * be[1]) + (ae[2] * be[2]);
  25410. return r;
  25411. }
  25412. static equals(a, b) {
  25413. var ae = a.elements;
  25414. var be = b.elements;
  25415. return MathUtils3D.nearEqual(ae[0], be[0]) && MathUtils3D.nearEqual(ae[1], be[1]) && MathUtils3D.nearEqual(ae[2], be[2]);
  25416. }
  25417. get x() {
  25418. return this.elements[0];
  25419. }
  25420. set x(value) {
  25421. this.elements[0] = value;
  25422. }
  25423. get y() {
  25424. return this.elements[1];
  25425. }
  25426. set y(value) {
  25427. this.elements[1] = value;
  25428. }
  25429. get z() {
  25430. return this.elements[2];
  25431. }
  25432. set z(value) {
  25433. this.elements[2] = value;
  25434. }
  25435. setValue(x, y, z) {
  25436. this.elements[0] = x;
  25437. this.elements[1] = y;
  25438. this.elements[2] = z;
  25439. }
  25440. fromArray(array, offset = 0) {
  25441. this.elements[0] = array[offset + 0];
  25442. this.elements[1] = array[offset + 1];
  25443. this.elements[2] = array[offset + 2];
  25444. }
  25445. cloneTo(destObject) {
  25446. var destVector3 = destObject;
  25447. var destE = destVector3.elements;
  25448. var s = this.elements;
  25449. destE[0] = s[0];
  25450. destE[1] = s[1];
  25451. destE[2] = s[2];
  25452. }
  25453. clone() {
  25454. var destVector3 = new ConchVector3();
  25455. this.cloneTo(destVector3);
  25456. return destVector3;
  25457. }
  25458. toDefault() {
  25459. this.elements[0] = 0;
  25460. this.elements[1] = 0;
  25461. this.elements[2] = 0;
  25462. }
  25463. }
  25464. ConchVector3._tempVector4 = new ConchVector4();
  25465. ConchVector3.ZERO = new ConchVector3(0.0, 0.0, 0.0);
  25466. ConchVector3.ONE = new ConchVector3(1.0, 1.0, 1.0);
  25467. ConchVector3.NegativeUnitX = new ConchVector3(-1, 0, 0);
  25468. ConchVector3.UnitX = new ConchVector3(1, 0, 0);
  25469. ConchVector3.UnitY = new ConchVector3(0, 1, 0);
  25470. ConchVector3.UnitZ = new ConchVector3(0, 0, 1);
  25471. ConchVector3.ForwardRH = new ConchVector3(0, 0, -1);
  25472. ConchVector3.ForwardLH = new ConchVector3(0, 0, 1);
  25473. ConchVector3.Up = new ConchVector3(0, 1, 0);
  25474. ConchVector3.NAN = new ConchVector3(NaN, NaN, NaN);
  25475. class ConchQuaternion {
  25476. constructor(x = 0, y = 0, z = 0, w = 1, nativeElements = null) {
  25477. var v;
  25478. if (nativeElements) {
  25479. v = nativeElements;
  25480. }
  25481. else {
  25482. v = new Float32Array(4);
  25483. }
  25484. v[0] = x;
  25485. v[1] = y;
  25486. v[2] = z;
  25487. v[3] = w;
  25488. this.elements = v;
  25489. }
  25490. static _dotArray(l, r) {
  25491. return l[0] * r[0] + l[1] * r[1] + l[2] * r[2] + l[3] * r[3];
  25492. }
  25493. static _normalizeArray(f, o) {
  25494. var x = f[0], y = f[1], z = f[2], w = f[3];
  25495. var len = x * x + y * y + z * z + w * w;
  25496. if (len > 0) {
  25497. len = 1 / Math.sqrt(len);
  25498. o[0] = x * len;
  25499. o[1] = y * len;
  25500. o[2] = z * len;
  25501. o[3] = w * len;
  25502. }
  25503. }
  25504. static _lerpArray(l, r, amount, o) {
  25505. var inverse = 1.0 - amount;
  25506. if (ConchQuaternion._dotArray(l, r) >= 0) {
  25507. o[0] = (inverse * l[0]) + (amount * r[0]);
  25508. o[1] = (inverse * l[1]) + (amount * r[1]);
  25509. o[2] = (inverse * l[2]) + (amount * r[2]);
  25510. o[3] = (inverse * l[3]) + (amount * r[3]);
  25511. }
  25512. else {
  25513. o[0] = (inverse * l[0]) - (amount * r[0]);
  25514. o[1] = (inverse * l[1]) - (amount * r[1]);
  25515. o[2] = (inverse * l[2]) - (amount * r[2]);
  25516. o[3] = (inverse * l[3]) - (amount * r[3]);
  25517. }
  25518. ConchQuaternion._normalizeArray(o, o);
  25519. }
  25520. static createFromYawPitchRoll(yaw, pitch, roll, out) {
  25521. var halfRoll = roll * 0.5;
  25522. var halfPitch = pitch * 0.5;
  25523. var halfYaw = yaw * 0.5;
  25524. var sinRoll = Math.sin(halfRoll);
  25525. var cosRoll = Math.cos(halfRoll);
  25526. var sinPitch = Math.sin(halfPitch);
  25527. var cosPitch = Math.cos(halfPitch);
  25528. var sinYaw = Math.sin(halfYaw);
  25529. var cosYaw = Math.cos(halfYaw);
  25530. var oe = out.elements;
  25531. oe[0] = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);
  25532. oe[1] = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);
  25533. oe[2] = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);
  25534. oe[3] = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);
  25535. }
  25536. static multiply(left, right, out) {
  25537. var le = left.elements;
  25538. var re = right.elements;
  25539. var oe = out.elements;
  25540. var lx = le[0];
  25541. var ly = le[1];
  25542. var lz = le[2];
  25543. var lw = le[3];
  25544. var rx = re[0];
  25545. var ry = re[1];
  25546. var rz = re[2];
  25547. var rw = re[3];
  25548. var a = (ly * rz - lz * ry);
  25549. var b = (lz * rx - lx * rz);
  25550. var c = (lx * ry - ly * rx);
  25551. var d = (lx * rx + ly * ry + lz * rz);
  25552. oe[0] = (lx * rw + rx * lw) + a;
  25553. oe[1] = (ly * rw + ry * lw) + b;
  25554. oe[2] = (lz * rw + rz * lw) + c;
  25555. oe[3] = lw * rw - d;
  25556. }
  25557. static arcTanAngle(x, y) {
  25558. if (x == 0) {
  25559. if (y == 1)
  25560. return Math.PI / 2;
  25561. return -Math.PI / 2;
  25562. }
  25563. if (x > 0)
  25564. return Math.atan(y / x);
  25565. if (x < 0) {
  25566. if (y > 0)
  25567. return Math.atan(y / x) + Math.PI;
  25568. return Math.atan(y / x) - Math.PI;
  25569. }
  25570. return 0;
  25571. }
  25572. static angleTo(from, location, angle) {
  25573. ConchVector3.subtract(location, from, ConchQuaternion.TEMPVector30);
  25574. ConchVector3.normalize(ConchQuaternion.TEMPVector30, ConchQuaternion.TEMPVector30);
  25575. angle.elements[0] = Math.asin(ConchQuaternion.TEMPVector30.y);
  25576. angle.elements[1] = ConchQuaternion.arcTanAngle(-ConchQuaternion.TEMPVector30.z, -ConchQuaternion.TEMPVector30.x);
  25577. }
  25578. static createFromAxisAngle(axis, rad, out) {
  25579. var e = out.elements;
  25580. var f = axis.elements;
  25581. rad = rad * 0.5;
  25582. var s = Math.sin(rad);
  25583. e[0] = s * f[0];
  25584. e[1] = s * f[1];
  25585. e[2] = s * f[2];
  25586. e[3] = Math.cos(rad);
  25587. }
  25588. static createFromMatrix3x3(sou, out) {
  25589. var e = out.elements;
  25590. var f = sou.elements;
  25591. var fTrace = f[0] + f[4] + f[8];
  25592. var fRoot;
  25593. if (fTrace > 0.0) {
  25594. fRoot = Math.sqrt(fTrace + 1.0);
  25595. e[3] = 0.5 * fRoot;
  25596. fRoot = 0.5 / fRoot;
  25597. e[0] = (f[5] - f[7]) * fRoot;
  25598. e[1] = (f[6] - f[2]) * fRoot;
  25599. e[2] = (f[1] - f[3]) * fRoot;
  25600. }
  25601. else {
  25602. var i = 0;
  25603. if (f[4] > f[0])
  25604. i = 1;
  25605. if (f[8] > f[i * 3 + i])
  25606. i = 2;
  25607. var j = (i + 1) % 3;
  25608. var k = (i + 2) % 3;
  25609. fRoot = Math.sqrt(f[i * 3 + i] - f[j * 3 + j] - f[k * 3 + k] + 1.0);
  25610. e[i] = 0.5 * fRoot;
  25611. fRoot = 0.5 / fRoot;
  25612. e[3] = (f[j * 3 + k] - f[k * 3 + j]) * fRoot;
  25613. e[j] = (f[j * 3 + i] + f[i * 3 + j]) * fRoot;
  25614. e[k] = (f[k * 3 + i] + f[i * 3 + k]) * fRoot;
  25615. }
  25616. return;
  25617. }
  25618. static createFromMatrix4x4(mat, out) {
  25619. var me = mat.elements;
  25620. var oe = out.elements;
  25621. var sqrt;
  25622. var half;
  25623. var scale = me[0] + me[5] + me[10];
  25624. if (scale > 0.0) {
  25625. sqrt = Math.sqrt(scale + 1.0);
  25626. oe[3] = sqrt * 0.5;
  25627. sqrt = 0.5 / sqrt;
  25628. oe[0] = (me[6] - me[9]) * sqrt;
  25629. oe[1] = (me[8] - me[2]) * sqrt;
  25630. oe[2] = (me[1] - me[4]) * sqrt;
  25631. }
  25632. else if ((me[0] >= me[5]) && (me[0] >= me[10])) {
  25633. sqrt = Math.sqrt(1.0 + me[0] - me[5] - me[10]);
  25634. half = 0.5 / sqrt;
  25635. oe[0] = 0.5 * sqrt;
  25636. oe[1] = (me[1] + me[4]) * half;
  25637. oe[2] = (me[2] + me[8]) * half;
  25638. oe[3] = (me[6] - me[9]) * half;
  25639. }
  25640. else if (me[5] > me[10]) {
  25641. sqrt = Math.sqrt(1.0 + me[5] - me[0] - me[10]);
  25642. half = 0.5 / sqrt;
  25643. oe[0] = (me[4] + me[1]) * half;
  25644. oe[1] = 0.5 * sqrt;
  25645. oe[2] = (me[9] + me[6]) * half;
  25646. oe[3] = (me[8] - me[2]) * half;
  25647. }
  25648. else {
  25649. sqrt = Math.sqrt(1.0 + me[10] - me[0] - me[5]);
  25650. half = 0.5 / sqrt;
  25651. oe[0] = (me[8] + me[2]) * half;
  25652. oe[1] = (me[9] + me[6]) * half;
  25653. oe[2] = 0.5 * sqrt;
  25654. oe[3] = (me[1] - me[4]) * half;
  25655. }
  25656. }
  25657. static slerp(left, right, t, out) {
  25658. var a = left.elements;
  25659. var b = right.elements;
  25660. var oe = out.elements;
  25661. var ax = a[0], ay = a[1], az = a[2], aw = a[3], bx = b[0], by = b[1], bz = b[2], bw = b[3];
  25662. var omega, cosom, sinom, scale0, scale1;
  25663. cosom = ax * bx + ay * by + az * bz + aw * bw;
  25664. if (cosom < 0.0) {
  25665. cosom = -cosom;
  25666. bx = -bx;
  25667. by = -by;
  25668. bz = -bz;
  25669. bw = -bw;
  25670. }
  25671. if ((1.0 - cosom) > 0.000001) {
  25672. omega = Math.acos(cosom);
  25673. sinom = Math.sin(omega);
  25674. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  25675. scale1 = Math.sin(t * omega) / sinom;
  25676. }
  25677. else {
  25678. scale0 = 1.0 - t;
  25679. scale1 = t;
  25680. }
  25681. oe[0] = scale0 * ax + scale1 * bx;
  25682. oe[1] = scale0 * ay + scale1 * by;
  25683. oe[2] = scale0 * az + scale1 * bz;
  25684. oe[3] = scale0 * aw + scale1 * bw;
  25685. return oe;
  25686. }
  25687. static lerp(left, right, amount, out) {
  25688. ConchQuaternion._lerpArray(left.elements, right.elements, amount, out.elements);
  25689. }
  25690. static add(left, right, out) {
  25691. var e = out.elements;
  25692. var f = left.elements;
  25693. var g = right.elements;
  25694. e[0] = f[0] + g[0];
  25695. e[1] = f[1] + g[1];
  25696. e[2] = f[2] + g[2];
  25697. e[3] = f[3] + g[3];
  25698. }
  25699. static dot(left, right) {
  25700. return ConchQuaternion._dotArray(left.elements, right.elements);
  25701. }
  25702. get x() {
  25703. return this.elements[0];
  25704. }
  25705. set x(value) {
  25706. this.elements[0] = value;
  25707. }
  25708. get y() {
  25709. return this.elements[1];
  25710. }
  25711. set y(value) {
  25712. this.elements[1] = value;
  25713. }
  25714. get z() {
  25715. return this.elements[2];
  25716. }
  25717. set z(value) {
  25718. this.elements[2] = value;
  25719. }
  25720. get w() {
  25721. return this.elements[3];
  25722. }
  25723. set w(value) {
  25724. this.elements[3] = value;
  25725. }
  25726. scaling(scaling, out) {
  25727. var e = out.elements;
  25728. var f = this.elements;
  25729. e[0] = f[0] * scaling;
  25730. e[1] = f[1] * scaling;
  25731. e[2] = f[2] * scaling;
  25732. e[3] = f[3] * scaling;
  25733. }
  25734. normalize(out) {
  25735. ConchQuaternion._normalizeArray(this.elements, out.elements);
  25736. }
  25737. length() {
  25738. var f = this.elements;
  25739. var x = f[0], y = f[1], z = f[2], w = f[3];
  25740. return Math.sqrt(x * x + y * y + z * z + w * w);
  25741. }
  25742. rotateX(rad, out) {
  25743. var e = out.elements;
  25744. var f = this.elements;
  25745. rad *= 0.5;
  25746. var ax = f[0], ay = f[1], az = f[2], aw = f[3];
  25747. var bx = Math.sin(rad), bw = Math.cos(rad);
  25748. e[0] = ax * bw + aw * bx;
  25749. e[1] = ay * bw + az * bx;
  25750. e[2] = az * bw - ay * bx;
  25751. e[3] = aw * bw - ax * bx;
  25752. }
  25753. rotateY(rad, out) {
  25754. var e = out.elements;
  25755. var f = this.elements;
  25756. rad *= 0.5;
  25757. var ax = f[0], ay = f[1], az = f[2], aw = f[3], by = Math.sin(rad), bw = Math.cos(rad);
  25758. e[0] = ax * bw - az * by;
  25759. e[1] = ay * bw + aw * by;
  25760. e[2] = az * bw + ax * by;
  25761. e[3] = aw * bw - ay * by;
  25762. }
  25763. rotateZ(rad, out) {
  25764. var e = out.elements;
  25765. var f = this.elements;
  25766. rad *= 0.5;
  25767. var ax = f[0], ay = f[1], az = f[2], aw = f[3], bz = Math.sin(rad), bw = Math.cos(rad);
  25768. e[0] = ax * bw + ay * bz;
  25769. e[1] = ay * bw - ax * bz;
  25770. e[2] = az * bw + aw * bz;
  25771. e[3] = aw * bw - az * bz;
  25772. }
  25773. getYawPitchRoll(out) {
  25774. ConchVector3.transformQuat(ConchVector3.ForwardRH, this, ConchQuaternion.TEMPVector31);
  25775. ConchVector3.transformQuat(ConchVector3.Up, this, ConchQuaternion.TEMPVector32);
  25776. var upe = ConchQuaternion.TEMPVector32.elements;
  25777. ConchQuaternion.angleTo(ConchVector3.ZERO, ConchQuaternion.TEMPVector31, ConchQuaternion.TEMPVector33);
  25778. var anglee = ConchQuaternion.TEMPVector33.elements;
  25779. if (anglee[0] == Math.PI / 2) {
  25780. anglee[1] = ConchQuaternion.arcTanAngle(upe[2], upe[0]);
  25781. anglee[2] = 0;
  25782. }
  25783. else if (anglee[0] == -Math.PI / 2) {
  25784. anglee[1] = ConchQuaternion.arcTanAngle(-upe[2], -upe[0]);
  25785. anglee[2] = 0;
  25786. }
  25787. else {
  25788. Matrix4x4.createRotationY(-anglee[1], ConchQuaternion.TEMPMatrix0);
  25789. Matrix4x4.createRotationX(-anglee[0], ConchQuaternion.TEMPMatrix1);
  25790. ConchVector3.transformCoordinate(ConchQuaternion.TEMPVector32, ConchQuaternion.TEMPMatrix0, ConchQuaternion.TEMPVector32);
  25791. ConchVector3.transformCoordinate(ConchQuaternion.TEMPVector32, ConchQuaternion.TEMPMatrix1, ConchQuaternion.TEMPVector32);
  25792. anglee[2] = ConchQuaternion.arcTanAngle(upe[1], -upe[0]);
  25793. }
  25794. if (anglee[1] <= -Math.PI)
  25795. anglee[1] = Math.PI;
  25796. if (anglee[2] <= -Math.PI)
  25797. anglee[2] = Math.PI;
  25798. if (anglee[1] >= Math.PI && anglee[2] >= Math.PI) {
  25799. anglee[1] = 0;
  25800. anglee[2] = 0;
  25801. anglee[0] = Math.PI - anglee[0];
  25802. }
  25803. var oe = out.elements;
  25804. oe[0] = anglee[1];
  25805. oe[1] = anglee[0];
  25806. oe[2] = anglee[2];
  25807. }
  25808. invert(out) {
  25809. var e = out.elements;
  25810. var f = this.elements;
  25811. var a0 = f[0], a1 = f[1], a2 = f[2], a3 = f[3];
  25812. var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
  25813. var invDot = dot ? 1.0 / dot : 0;
  25814. e[0] = -a0 * invDot;
  25815. e[1] = -a1 * invDot;
  25816. e[2] = -a2 * invDot;
  25817. e[3] = a3 * invDot;
  25818. }
  25819. identity() {
  25820. var e = this.elements;
  25821. e[0] = 0;
  25822. e[1] = 0;
  25823. e[2] = 0;
  25824. e[3] = 1;
  25825. }
  25826. fromArray(array, offset = 0) {
  25827. this.elements[0] = array[offset + 0];
  25828. this.elements[1] = array[offset + 1];
  25829. this.elements[2] = array[offset + 2];
  25830. this.elements[3] = array[offset + 3];
  25831. }
  25832. cloneTo(destObject) {
  25833. var i, s, d;
  25834. s = this.elements;
  25835. d = destObject.elements;
  25836. if (s === d) {
  25837. return;
  25838. }
  25839. for (i = 0; i < 4; ++i) {
  25840. d[i] = s[i];
  25841. }
  25842. }
  25843. clone() {
  25844. var dest = new ConchQuaternion();
  25845. this.cloneTo(dest);
  25846. return dest;
  25847. }
  25848. equals(b) {
  25849. var ae = this.elements;
  25850. var be = b.elements;
  25851. return MathUtils3D.nearEqual(ae[0], be[0]) && MathUtils3D.nearEqual(ae[1], be[1]) && MathUtils3D.nearEqual(ae[2], be[2]) && MathUtils3D.nearEqual(ae[3], be[3]);
  25852. }
  25853. static rotationLookAt(forward, up, out) {
  25854. ConchQuaternion.lookAt(ConchVector3.ZERO, forward, up, out);
  25855. }
  25856. static lookAt(eye, target, up, out) {
  25857. Matrix3x3.lookAt(eye, target, up, ConchQuaternion._tempMatrix3x3);
  25858. ConchQuaternion.rotationMatrix(ConchQuaternion._tempMatrix3x3, out);
  25859. }
  25860. lengthSquared() {
  25861. var x = this.elements[0];
  25862. var y = this.elements[1];
  25863. var z = this.elements[2];
  25864. var w = this.elements[3];
  25865. return (x * x) + (y * y) + (z * z) + (w * w);
  25866. }
  25867. static invert(value, out) {
  25868. var vE = value.elements;
  25869. var oE = out.elements;
  25870. var lengthSq = value.lengthSquared();
  25871. if (!MathUtils3D.isZero(lengthSq)) {
  25872. lengthSq = 1.0 / lengthSq;
  25873. oE[0] = -vE[0] * lengthSq;
  25874. oE[1] = -vE[1] * lengthSq;
  25875. oE[2] = -vE[2] * lengthSq;
  25876. oE[3] = vE[3] * lengthSq;
  25877. }
  25878. }
  25879. static rotationMatrix(matrix3x3, out) {
  25880. var me = matrix3x3.elements;
  25881. var m11 = me[0];
  25882. var m12 = me[1];
  25883. var m13 = me[2];
  25884. var m21 = me[3];
  25885. var m22 = me[4];
  25886. var m23 = me[5];
  25887. var m31 = me[6];
  25888. var m32 = me[7];
  25889. var m33 = me[8];
  25890. var oe = out.elements;
  25891. var sqrt, half;
  25892. var scale = m11 + m22 + m33;
  25893. if (scale > 0) {
  25894. sqrt = Math.sqrt(scale + 1);
  25895. oe[3] = sqrt * 0.5;
  25896. sqrt = 0.5 / sqrt;
  25897. oe[0] = (m23 - m32) * sqrt;
  25898. oe[1] = (m31 - m13) * sqrt;
  25899. oe[2] = (m12 - m21) * sqrt;
  25900. }
  25901. else if ((m11 >= m22) && (m11 >= m33)) {
  25902. sqrt = Math.sqrt(1 + m11 - m22 - m33);
  25903. half = 0.5 / sqrt;
  25904. oe[0] = 0.5 * sqrt;
  25905. oe[1] = (m12 + m21) * half;
  25906. oe[2] = (m13 + m31) * half;
  25907. oe[3] = (m23 - m32) * half;
  25908. }
  25909. else if (m22 > m33) {
  25910. sqrt = Math.sqrt(1 + m22 - m11 - m33);
  25911. half = 0.5 / sqrt;
  25912. oe[0] = (m21 + m12) * half;
  25913. oe[1] = 0.5 * sqrt;
  25914. oe[2] = (m32 + m23) * half;
  25915. oe[3] = (m31 - m13) * half;
  25916. }
  25917. else {
  25918. sqrt = Math.sqrt(1 + m33 - m11 - m22);
  25919. half = 0.5 / sqrt;
  25920. oe[0] = (m31 + m13) * half;
  25921. oe[1] = (m32 + m23) * half;
  25922. oe[2] = 0.5 * sqrt;
  25923. oe[3] = (m12 - m21) * half;
  25924. }
  25925. }
  25926. }
  25927. ConchQuaternion.TEMPVector30 = new ConchVector3();
  25928. ConchQuaternion.TEMPVector31 = new ConchVector3();
  25929. ConchQuaternion.TEMPVector32 = new ConchVector3();
  25930. ConchQuaternion.TEMPVector33 = new ConchVector3();
  25931. ConchQuaternion.TEMPMatrix0 = new Matrix4x4();
  25932. ConchQuaternion.TEMPMatrix1 = new Matrix4x4();
  25933. ConchQuaternion._tempMatrix3x3 = new Matrix3x3();
  25934. ConchQuaternion.DEFAULT = new ConchQuaternion();
  25935. ConchQuaternion.NAN = new ConchQuaternion(NaN, NaN, NaN, NaN);
  25936. class AnimationClipParser03 {
  25937. static READ_DATA() {
  25938. AnimationClipParser03._DATA.offset = AnimationClipParser03._reader.getUint32();
  25939. AnimationClipParser03._DATA.size = AnimationClipParser03._reader.getUint32();
  25940. }
  25941. static READ_BLOCK() {
  25942. var count = AnimationClipParser03._BLOCK.count = AnimationClipParser03._reader.getUint16();
  25943. var blockStarts = AnimationClipParser03._BLOCK.blockStarts = [];
  25944. var blockLengths = AnimationClipParser03._BLOCK.blockLengths = [];
  25945. for (var i = 0; i < count; i++) {
  25946. blockStarts.push(AnimationClipParser03._reader.getUint32());
  25947. blockLengths.push(AnimationClipParser03._reader.getUint32());
  25948. }
  25949. }
  25950. static READ_STRINGS() {
  25951. var offset = AnimationClipParser03._reader.getUint32();
  25952. var count = AnimationClipParser03._reader.getUint16();
  25953. var prePos = AnimationClipParser03._reader.pos;
  25954. AnimationClipParser03._reader.pos = offset + AnimationClipParser03._DATA.offset;
  25955. for (var i = 0; i < count; i++)
  25956. AnimationClipParser03._strings[i] = AnimationClipParser03._reader.readUTFString();
  25957. AnimationClipParser03._reader.pos = prePos;
  25958. }
  25959. static parse(clip, reader) {
  25960. AnimationClipParser03._animationClip = clip;
  25961. AnimationClipParser03._reader = reader;
  25962. var arrayBuffer = reader.__getBuffer();
  25963. AnimationClipParser03.READ_DATA();
  25964. AnimationClipParser03.READ_BLOCK();
  25965. AnimationClipParser03.READ_STRINGS();
  25966. for (var i = 0, n = AnimationClipParser03._BLOCK.count; i < n; i++) {
  25967. var index = reader.getUint16();
  25968. var blockName = AnimationClipParser03._strings[index];
  25969. var fn = AnimationClipParser03["READ_" + blockName];
  25970. if (fn == null)
  25971. throw new Error("model file err,no this function:" + index + " " + blockName);
  25972. else
  25973. fn.call(null);
  25974. }
  25975. }
  25976. static READ_ANIMATIONS() {
  25977. var i, j;
  25978. var node;
  25979. var reader = AnimationClipParser03._reader;
  25980. var buffer = reader.__getBuffer();
  25981. var startTimeTypes = [];
  25982. var startTimeTypeCount = reader.getUint16();
  25983. startTimeTypes.length = startTimeTypeCount;
  25984. for (i = 0; i < startTimeTypeCount; i++)
  25985. startTimeTypes[i] = reader.getFloat32();
  25986. var clip = AnimationClipParser03._animationClip;
  25987. clip.name = AnimationClipParser03._strings[reader.getUint16()];
  25988. var clipDur = clip._duration = reader.getFloat32();
  25989. clip.islooping = !!reader.getByte();
  25990. clip._frameRate = reader.getInt16();
  25991. var nodeCount = reader.getInt16();
  25992. var nodes = clip._nodes;
  25993. nodes.count = nodeCount;
  25994. var nodesMap = clip._nodesMap = {};
  25995. var nodesDic = clip._nodesDic = {};
  25996. for (i = 0; i < nodeCount; i++) {
  25997. node = new KeyframeNode();
  25998. nodes.setNodeByIndex(i, node);
  25999. node._indexInList = i;
  26000. var type = node.type = reader.getUint8();
  26001. var pathLength = reader.getUint16();
  26002. node._setOwnerPathCount(pathLength);
  26003. for (j = 0; j < pathLength; j++)
  26004. node._setOwnerPathByIndex(j, AnimationClipParser03._strings[reader.getUint16()]);
  26005. var nodePath = node._joinOwnerPath("/");
  26006. var mapArray = nodesMap[nodePath];
  26007. (mapArray) || (nodesMap[nodePath] = mapArray = []);
  26008. mapArray.push(node);
  26009. node.propertyOwner = AnimationClipParser03._strings[reader.getUint16()];
  26010. var propertyLength = reader.getUint16();
  26011. node._setPropertyCount(propertyLength);
  26012. for (j = 0; j < propertyLength; j++)
  26013. node._setPropertyByIndex(j, AnimationClipParser03._strings[reader.getUint16()]);
  26014. var fullPath = nodePath + "." + node.propertyOwner + "." + node._joinProperty(".");
  26015. nodesDic[fullPath] = node;
  26016. node.fullPath = fullPath;
  26017. var keyframeCount = reader.getUint16();
  26018. node._setKeyframeCount(keyframeCount);
  26019. var startTime;
  26020. switch (type) {
  26021. case 0:
  26022. break;
  26023. case 1:
  26024. case 3:
  26025. case 4:
  26026. node.data = Laya.Render.supportWebGLPlusAnimation ? new ConchVector3 : new Vector3();
  26027. break;
  26028. case 2:
  26029. node.data = Laya.Render.supportWebGLPlusAnimation ? new ConchQuaternion : new Quaternion();
  26030. break;
  26031. default:
  26032. throw "AnimationClipParser03:unknown type.";
  26033. }
  26034. for (j = 0; j < keyframeCount; j++) {
  26035. switch (type) {
  26036. case 0:
  26037. var floatKeyframe = new FloatKeyframe();
  26038. node._setKeyframeByIndex(j, floatKeyframe);
  26039. startTime = floatKeyframe.time = startTimeTypes[reader.getUint16()];
  26040. floatKeyframe.inTangent = reader.getFloat32();
  26041. floatKeyframe.outTangent = reader.getFloat32();
  26042. floatKeyframe.value = reader.getFloat32();
  26043. break;
  26044. case 1:
  26045. case 3:
  26046. case 4:
  26047. var floatArrayKeyframe = new Vector3Keyframe();
  26048. node._setKeyframeByIndex(j, floatArrayKeyframe);
  26049. startTime = floatArrayKeyframe.time = startTimeTypes[reader.getUint16()];
  26050. if (Laya.Render.supportWebGLPlusAnimation) {
  26051. var data = floatArrayKeyframe.data = new Float32Array(3 * 3);
  26052. for (var k = 0; k < 3; k++)
  26053. data[k] = reader.getFloat32();
  26054. for (k = 0; k < 3; k++)
  26055. data[3 + k] = reader.getFloat32();
  26056. for (k = 0; k < 3; k++)
  26057. data[6 + k] = reader.getFloat32();
  26058. }
  26059. else {
  26060. var inTangent = floatArrayKeyframe.inTangent;
  26061. var outTangent = floatArrayKeyframe.outTangent;
  26062. var value = floatArrayKeyframe.value;
  26063. inTangent.x = reader.getFloat32();
  26064. inTangent.y = reader.getFloat32();
  26065. inTangent.z = reader.getFloat32();
  26066. outTangent.x = reader.getFloat32();
  26067. outTangent.y = reader.getFloat32();
  26068. outTangent.z = reader.getFloat32();
  26069. value.x = reader.getFloat32();
  26070. value.y = reader.getFloat32();
  26071. value.z = reader.getFloat32();
  26072. }
  26073. break;
  26074. case 2:
  26075. var quaArrayKeyframe = new QuaternionKeyframe();
  26076. node._setKeyframeByIndex(j, quaArrayKeyframe);
  26077. startTime = quaArrayKeyframe.time = startTimeTypes[reader.getUint16()];
  26078. if (Laya.Render.supportWebGLPlusAnimation) {
  26079. data = quaArrayKeyframe.data = new Float32Array(3 * 4);
  26080. for (k = 0; k < 4; k++)
  26081. data[k] = reader.getFloat32();
  26082. for (k = 0; k < 4; k++)
  26083. data[4 + k] = reader.getFloat32();
  26084. for (k = 0; k < 4; k++)
  26085. data[8 + k] = reader.getFloat32();
  26086. }
  26087. else {
  26088. var inTangentQua = quaArrayKeyframe.inTangent;
  26089. var outTangentQua = quaArrayKeyframe.outTangent;
  26090. var valueQua = quaArrayKeyframe.value;
  26091. inTangentQua.x = reader.getFloat32();
  26092. inTangentQua.y = reader.getFloat32();
  26093. inTangentQua.z = reader.getFloat32();
  26094. inTangentQua.w = reader.getFloat32();
  26095. outTangentQua.x = reader.getFloat32();
  26096. outTangentQua.y = reader.getFloat32();
  26097. outTangentQua.z = reader.getFloat32();
  26098. outTangentQua.w = reader.getFloat32();
  26099. valueQua.x = reader.getFloat32();
  26100. valueQua.y = reader.getFloat32();
  26101. valueQua.z = reader.getFloat32();
  26102. valueQua.w = reader.getFloat32();
  26103. }
  26104. break;
  26105. default:
  26106. throw "AnimationClipParser03:unknown type.";
  26107. }
  26108. }
  26109. }
  26110. var eventCount = reader.getUint16();
  26111. for (i = 0; i < eventCount; i++) {
  26112. var event = new AnimationEvent();
  26113. event.time = Math.min(clipDur, reader.getFloat32());
  26114. event.eventName = AnimationClipParser03._strings[reader.getUint16()];
  26115. var params;
  26116. var paramCount = reader.getUint16();
  26117. (paramCount > 0) && (event.params = params = []);
  26118. for (j = 0; j < paramCount; j++) {
  26119. var eventType = reader.getByte();
  26120. switch (eventType) {
  26121. case 0:
  26122. params.push(!!reader.getByte());
  26123. break;
  26124. case 1:
  26125. params.push(reader.getInt32());
  26126. break;
  26127. case 2:
  26128. params.push(reader.getFloat32());
  26129. break;
  26130. case 3:
  26131. params.push(AnimationClipParser03._strings[reader.getUint16()]);
  26132. break;
  26133. default:
  26134. throw new Error("unknown type.");
  26135. }
  26136. }
  26137. clip.addEvent(event);
  26138. }
  26139. }
  26140. }
  26141. AnimationClipParser03._strings = [];
  26142. AnimationClipParser03._BLOCK = { count: 0 };
  26143. AnimationClipParser03._DATA = { offset: 0, size: 0 };
  26144. class HalfFloatUtils {
  26145. static __init__() {
  26146. for (var i = 0; i < 256; ++i) {
  26147. var e = i - 127;
  26148. if (e < -27) {
  26149. HalfFloatUtils._baseTable[i | 0x000] = 0x0000;
  26150. HalfFloatUtils._baseTable[i | 0x100] = 0x8000;
  26151. HalfFloatUtils._shiftTable[i | 0x000] = 24;
  26152. HalfFloatUtils._shiftTable[i | 0x100] = 24;
  26153. }
  26154. else if (e < -14) {
  26155. HalfFloatUtils._baseTable[i | 0x000] = 0x0400 >> (-e - 14);
  26156. HalfFloatUtils._baseTable[i | 0x100] = (0x0400 >> (-e - 14)) | 0x8000;
  26157. HalfFloatUtils._shiftTable[i | 0x000] = -e - 1;
  26158. HalfFloatUtils._shiftTable[i | 0x100] = -e - 1;
  26159. }
  26160. else if (e <= 15) {
  26161. HalfFloatUtils._baseTable[i | 0x000] = (e + 15) << 10;
  26162. HalfFloatUtils._baseTable[i | 0x100] = ((e + 15) << 10) | 0x8000;
  26163. HalfFloatUtils._shiftTable[i | 0x000] = 13;
  26164. HalfFloatUtils._shiftTable[i | 0x100] = 13;
  26165. }
  26166. else if (e < 128) {
  26167. HalfFloatUtils._baseTable[i | 0x000] = 0x7c00;
  26168. HalfFloatUtils._baseTable[i | 0x100] = 0xfc00;
  26169. HalfFloatUtils._shiftTable[i | 0x000] = 24;
  26170. HalfFloatUtils._shiftTable[i | 0x100] = 24;
  26171. }
  26172. else {
  26173. HalfFloatUtils._baseTable[i | 0x000] = 0x7c00;
  26174. HalfFloatUtils._baseTable[i | 0x100] = 0xfc00;
  26175. HalfFloatUtils._shiftTable[i | 0x000] = 13;
  26176. HalfFloatUtils._shiftTable[i | 0x100] = 13;
  26177. }
  26178. }
  26179. HalfFloatUtils._mantissaTable[0] = 0;
  26180. for (i = 1; i < 1024; ++i) {
  26181. var m = i << 13;
  26182. e = 0;
  26183. while ((m & 0x00800000) === 0) {
  26184. e -= 0x00800000;
  26185. m <<= 1;
  26186. }
  26187. m &= ~0x00800000;
  26188. e += 0x38800000;
  26189. HalfFloatUtils._mantissaTable[i] = m | e;
  26190. }
  26191. for (i = 1024; i < 2048; ++i) {
  26192. HalfFloatUtils._mantissaTable[i] = 0x38000000 + ((i - 1024) << 13);
  26193. }
  26194. HalfFloatUtils._exponentTable[0] = 0;
  26195. for (i = 1; i < 31; ++i) {
  26196. HalfFloatUtils._exponentTable[i] = i << 23;
  26197. }
  26198. HalfFloatUtils._exponentTable[31] = 0x47800000;
  26199. HalfFloatUtils._exponentTable[32] = 0x80000000;
  26200. for (i = 33; i < 63; ++i) {
  26201. HalfFloatUtils._exponentTable[i] = 0x80000000 + ((i - 32) << 23);
  26202. }
  26203. HalfFloatUtils._exponentTable[63] = 0xc7800000;
  26204. HalfFloatUtils._offsetTable[0] = 0;
  26205. for (i = 1; i < 64; ++i) {
  26206. if (i === 32) {
  26207. HalfFloatUtils._offsetTable[i] = 0;
  26208. }
  26209. else {
  26210. HalfFloatUtils._offsetTable[i] = 1024;
  26211. }
  26212. }
  26213. }
  26214. static roundToFloat16Bits(num) {
  26215. HalfFloatUtils._floatView[0] = num;
  26216. var f = HalfFloatUtils._uint32View[0];
  26217. var e = (f >> 23) & 0x1ff;
  26218. return HalfFloatUtils._baseTable[e] + ((f & 0x007fffff) >> HalfFloatUtils._shiftTable[e]);
  26219. }
  26220. static convertToNumber(float16bits) {
  26221. var m = float16bits >> 10;
  26222. HalfFloatUtils._uint32View[0] = HalfFloatUtils._mantissaTable[HalfFloatUtils._offsetTable[m] + (float16bits & 0x3ff)] + HalfFloatUtils._exponentTable[m];
  26223. return HalfFloatUtils._floatView[0];
  26224. }
  26225. }
  26226. HalfFloatUtils._buffer = new ArrayBuffer(4);
  26227. HalfFloatUtils._floatView = new Float32Array(HalfFloatUtils._buffer);
  26228. HalfFloatUtils._uint32View = new Uint32Array(HalfFloatUtils._buffer);
  26229. HalfFloatUtils._baseTable = new Uint32Array(512);
  26230. HalfFloatUtils._shiftTable = new Uint32Array(512);
  26231. HalfFloatUtils._mantissaTable = new Uint32Array(2048);
  26232. HalfFloatUtils._exponentTable = new Uint32Array(64);
  26233. HalfFloatUtils._offsetTable = new Uint32Array(64);
  26234. class AnimationClipParser04 {
  26235. static READ_DATA() {
  26236. AnimationClipParser04._DATA.offset = AnimationClipParser04._reader.getUint32();
  26237. AnimationClipParser04._DATA.size = AnimationClipParser04._reader.getUint32();
  26238. }
  26239. static READ_BLOCK() {
  26240. var count = AnimationClipParser04._BLOCK.count = AnimationClipParser04._reader.getUint16();
  26241. var blockStarts = AnimationClipParser04._BLOCK.blockStarts = [];
  26242. var blockLengths = AnimationClipParser04._BLOCK.blockLengths = [];
  26243. for (var i = 0; i < count; i++) {
  26244. blockStarts.push(AnimationClipParser04._reader.getUint32());
  26245. blockLengths.push(AnimationClipParser04._reader.getUint32());
  26246. }
  26247. }
  26248. static READ_STRINGS() {
  26249. var offset = AnimationClipParser04._reader.getUint32();
  26250. var count = AnimationClipParser04._reader.getUint16();
  26251. var prePos = AnimationClipParser04._reader.pos;
  26252. AnimationClipParser04._reader.pos = offset + AnimationClipParser04._DATA.offset;
  26253. for (var i = 0; i < count; i++)
  26254. AnimationClipParser04._strings[i] = AnimationClipParser04._reader.readUTFString();
  26255. AnimationClipParser04._reader.pos = prePos;
  26256. }
  26257. static parse(clip, reader, version) {
  26258. AnimationClipParser04._animationClip = clip;
  26259. AnimationClipParser04._reader = reader;
  26260. AnimationClipParser04._version = version;
  26261. AnimationClipParser04.READ_DATA();
  26262. AnimationClipParser04.READ_BLOCK();
  26263. AnimationClipParser04.READ_STRINGS();
  26264. for (var i = 0, n = AnimationClipParser04._BLOCK.count; i < n; i++) {
  26265. var index = reader.getUint16();
  26266. var blockName = AnimationClipParser04._strings[index];
  26267. var fn = AnimationClipParser04["READ_" + blockName];
  26268. if (fn == null)
  26269. throw new Error("model file err,no this function:" + index + " " + blockName);
  26270. else
  26271. fn.call(null);
  26272. }
  26273. AnimationClipParser04._version = null;
  26274. AnimationClipParser04._reader = null;
  26275. AnimationClipParser04._animationClip = null;
  26276. }
  26277. static READ_ANIMATIONS() {
  26278. var i, j;
  26279. var node;
  26280. var reader = AnimationClipParser04._reader;
  26281. var buffer = reader.__getBuffer();
  26282. var startTimeTypes = [];
  26283. var startTimeTypeCount = reader.getUint16();
  26284. startTimeTypes.length = startTimeTypeCount;
  26285. for (i = 0; i < startTimeTypeCount; i++)
  26286. startTimeTypes[i] = reader.getFloat32();
  26287. var clip = AnimationClipParser04._animationClip;
  26288. clip.name = AnimationClipParser04._strings[reader.getUint16()];
  26289. var clipDur = clip._duration = reader.getFloat32();
  26290. clip.islooping = !!reader.getByte();
  26291. clip._frameRate = reader.getInt16();
  26292. var nodeCount = reader.getInt16();
  26293. var nodes = clip._nodes;
  26294. nodes.count = nodeCount;
  26295. var nodesMap = clip._nodesMap = {};
  26296. var nodesDic = clip._nodesDic = {};
  26297. for (i = 0; i < nodeCount; i++) {
  26298. node = new KeyframeNode();
  26299. nodes.setNodeByIndex(i, node);
  26300. node._indexInList = i;
  26301. var type = node.type = reader.getUint8();
  26302. var pathLength = reader.getUint16();
  26303. node._setOwnerPathCount(pathLength);
  26304. for (j = 0; j < pathLength; j++)
  26305. node._setOwnerPathByIndex(j, AnimationClipParser04._strings[reader.getUint16()]);
  26306. var nodePath = node._joinOwnerPath("/");
  26307. var mapArray = nodesMap[nodePath];
  26308. (mapArray) || (nodesMap[nodePath] = mapArray = []);
  26309. mapArray.push(node);
  26310. node.propertyOwner = AnimationClipParser04._strings[reader.getUint16()];
  26311. var propertyLength = reader.getUint16();
  26312. node._setPropertyCount(propertyLength);
  26313. for (j = 0; j < propertyLength; j++)
  26314. node._setPropertyByIndex(j, AnimationClipParser04._strings[reader.getUint16()]);
  26315. var fullPath = nodePath + "." + node.propertyOwner + "." + node._joinProperty(".");
  26316. nodesDic[fullPath] = node;
  26317. node.fullPath = fullPath;
  26318. var keyframeCount = reader.getUint16();
  26319. node._setKeyframeCount(keyframeCount);
  26320. var startTime;
  26321. switch (type) {
  26322. case 0:
  26323. break;
  26324. case 1:
  26325. case 3:
  26326. case 4:
  26327. node.data = Laya.Render.supportWebGLPlusAnimation ? new ConchVector3 : new Vector3();
  26328. break;
  26329. case 2:
  26330. node.data = Laya.Render.supportWebGLPlusAnimation ? new ConchQuaternion : new Quaternion();
  26331. break;
  26332. default:
  26333. throw "AnimationClipParser04:unknown type.";
  26334. }
  26335. switch (AnimationClipParser04._version) {
  26336. case "LAYAANIMATION:04":
  26337. for (j = 0; j < keyframeCount; j++) {
  26338. switch (type) {
  26339. case 0:
  26340. var floatKeyframe = new FloatKeyframe();
  26341. node._setKeyframeByIndex(j, floatKeyframe);
  26342. startTime = floatKeyframe.time = startTimeTypes[reader.getUint16()];
  26343. floatKeyframe.inTangent = reader.getFloat32();
  26344. floatKeyframe.outTangent = reader.getFloat32();
  26345. floatKeyframe.value = reader.getFloat32();
  26346. break;
  26347. case 1:
  26348. case 3:
  26349. case 4:
  26350. var floatArrayKeyframe = new Vector3Keyframe();
  26351. node._setKeyframeByIndex(j, floatArrayKeyframe);
  26352. startTime = floatArrayKeyframe.time = startTimeTypes[reader.getUint16()];
  26353. if (Laya.Render.supportWebGLPlusAnimation) {
  26354. var data = floatArrayKeyframe.data = new Float32Array(3 * 3);
  26355. for (var k = 0; k < 3; k++)
  26356. data[k] = reader.getFloat32();
  26357. for (k = 0; k < 3; k++)
  26358. data[3 + k] = reader.getFloat32();
  26359. for (k = 0; k < 3; k++)
  26360. data[6 + k] = reader.getFloat32();
  26361. }
  26362. else {
  26363. var inTangent = floatArrayKeyframe.inTangent;
  26364. var outTangent = floatArrayKeyframe.outTangent;
  26365. var value = floatArrayKeyframe.value;
  26366. inTangent.x = reader.getFloat32();
  26367. inTangent.y = reader.getFloat32();
  26368. inTangent.z = reader.getFloat32();
  26369. outTangent.x = reader.getFloat32();
  26370. outTangent.y = reader.getFloat32();
  26371. outTangent.z = reader.getFloat32();
  26372. value.x = reader.getFloat32();
  26373. value.y = reader.getFloat32();
  26374. value.z = reader.getFloat32();
  26375. }
  26376. break;
  26377. case 2:
  26378. var quaternionKeyframe = new QuaternionKeyframe();
  26379. node._setKeyframeByIndex(j, quaternionKeyframe);
  26380. startTime = quaternionKeyframe.time = startTimeTypes[reader.getUint16()];
  26381. if (Laya.Render.supportWebGLPlusAnimation) {
  26382. data = quaternionKeyframe.data = new Float32Array(3 * 4);
  26383. for (k = 0; k < 4; k++)
  26384. data[k] = reader.getFloat32();
  26385. for (k = 0; k < 4; k++)
  26386. data[4 + k] = reader.getFloat32();
  26387. for (k = 0; k < 4; k++)
  26388. data[8 + k] = reader.getFloat32();
  26389. }
  26390. else {
  26391. var inTangentQua = quaternionKeyframe.inTangent;
  26392. var outTangentQua = quaternionKeyframe.outTangent;
  26393. var valueQua = quaternionKeyframe.value;
  26394. inTangentQua.x = reader.getFloat32();
  26395. inTangentQua.y = reader.getFloat32();
  26396. inTangentQua.z = reader.getFloat32();
  26397. inTangentQua.w = reader.getFloat32();
  26398. outTangentQua.x = reader.getFloat32();
  26399. outTangentQua.y = reader.getFloat32();
  26400. outTangentQua.z = reader.getFloat32();
  26401. outTangentQua.w = reader.getFloat32();
  26402. valueQua.x = reader.getFloat32();
  26403. valueQua.y = reader.getFloat32();
  26404. valueQua.z = reader.getFloat32();
  26405. valueQua.w = reader.getFloat32();
  26406. }
  26407. break;
  26408. default:
  26409. throw "AnimationClipParser04:unknown type.";
  26410. }
  26411. }
  26412. break;
  26413. case "LAYAANIMATION:COMPRESSION_04":
  26414. for (j = 0; j < keyframeCount; j++) {
  26415. switch (type) {
  26416. case 0:
  26417. floatKeyframe = new FloatKeyframe();
  26418. node._setKeyframeByIndex(j, floatKeyframe);
  26419. startTime = floatKeyframe.time = startTimeTypes[reader.getUint16()];
  26420. floatKeyframe.inTangent = HalfFloatUtils.convertToNumber(reader.getUint16());
  26421. floatKeyframe.outTangent = HalfFloatUtils.convertToNumber(reader.getUint16());
  26422. floatKeyframe.value = HalfFloatUtils.convertToNumber(reader.getUint16());
  26423. break;
  26424. case 1:
  26425. case 3:
  26426. case 4:
  26427. floatArrayKeyframe = new Vector3Keyframe();
  26428. node._setKeyframeByIndex(j, floatArrayKeyframe);
  26429. startTime = floatArrayKeyframe.time = startTimeTypes[reader.getUint16()];
  26430. if (Laya.Render.supportWebGLPlusAnimation) {
  26431. data = floatArrayKeyframe.data = new Float32Array(3 * 3);
  26432. for (k = 0; k < 3; k++)
  26433. data[k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26434. for (k = 0; k < 3; k++)
  26435. data[3 + k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26436. for (k = 0; k < 3; k++)
  26437. data[6 + k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26438. }
  26439. else {
  26440. inTangent = floatArrayKeyframe.inTangent;
  26441. outTangent = floatArrayKeyframe.outTangent;
  26442. value = floatArrayKeyframe.value;
  26443. inTangent.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26444. inTangent.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26445. inTangent.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26446. outTangent.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26447. outTangent.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26448. outTangent.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26449. value.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26450. value.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26451. value.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26452. }
  26453. break;
  26454. case 2:
  26455. quaternionKeyframe = new QuaternionKeyframe();
  26456. node._setKeyframeByIndex(j, quaternionKeyframe);
  26457. startTime = quaternionKeyframe.time = startTimeTypes[reader.getUint16()];
  26458. if (Laya.Render.supportWebGLPlusAnimation) {
  26459. data = quaternionKeyframe.data = new Float32Array(3 * 4);
  26460. for (k = 0; k < 4; k++)
  26461. data[k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26462. for (k = 0; k < 4; k++)
  26463. data[4 + k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26464. for (k = 0; k < 4; k++)
  26465. data[8 + k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26466. }
  26467. else {
  26468. inTangentQua = quaternionKeyframe.inTangent;
  26469. outTangentQua = quaternionKeyframe.outTangent;
  26470. valueQua = quaternionKeyframe.value;
  26471. inTangentQua.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26472. inTangentQua.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26473. inTangentQua.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26474. inTangentQua.w = HalfFloatUtils.convertToNumber(reader.getUint16());
  26475. outTangentQua.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26476. outTangentQua.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26477. outTangentQua.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26478. outTangentQua.w = HalfFloatUtils.convertToNumber(reader.getUint16());
  26479. valueQua.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26480. valueQua.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26481. valueQua.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26482. valueQua.w = HalfFloatUtils.convertToNumber(reader.getUint16());
  26483. }
  26484. break;
  26485. default:
  26486. throw "AnimationClipParser04:unknown type.";
  26487. }
  26488. }
  26489. break;
  26490. }
  26491. }
  26492. var eventCount = reader.getUint16();
  26493. for (i = 0; i < eventCount; i++) {
  26494. var event = new AnimationEvent();
  26495. event.time = Math.min(clipDur, reader.getFloat32());
  26496. event.eventName = AnimationClipParser04._strings[reader.getUint16()];
  26497. var params;
  26498. var paramCount = reader.getUint16();
  26499. (paramCount > 0) && (event.params = params = []);
  26500. for (j = 0; j < paramCount; j++) {
  26501. var eventType = reader.getByte();
  26502. switch (eventType) {
  26503. case 0:
  26504. params.push(!!reader.getByte());
  26505. break;
  26506. case 1:
  26507. params.push(reader.getInt32());
  26508. break;
  26509. case 2:
  26510. params.push(reader.getFloat32());
  26511. break;
  26512. case 3:
  26513. params.push(AnimationClipParser04._strings[reader.getUint16()]);
  26514. break;
  26515. default:
  26516. throw new Error("unknown type.");
  26517. }
  26518. }
  26519. clip.addEvent(event);
  26520. }
  26521. }
  26522. }
  26523. AnimationClipParser04._strings = [];
  26524. AnimationClipParser04._BLOCK = { count: 0 };
  26525. AnimationClipParser04._DATA = { offset: 0, size: 0 };
  26526. class KeyframeNodeList {
  26527. constructor() {
  26528. this._nodes = [];
  26529. }
  26530. get count() {
  26531. return this._nodes.length;
  26532. }
  26533. set count(value) {
  26534. this._nodes.length = value;
  26535. }
  26536. getNodeByIndex(index) {
  26537. return this._nodes[index];
  26538. }
  26539. setNodeByIndex(index, node) {
  26540. this._nodes[index] = node;
  26541. }
  26542. }
  26543. if (window.conch && window.conchKeyframeNodeList) {
  26544. KeyframeNodeList = window.conchKeyframeNodeList;
  26545. }
  26546. if (window.qq && window.qq.webglPlus) {
  26547. KeyframeNodeList = window.qq.webglPlus.conchKeyframeNodeList;
  26548. }
  26549. class AnimationClip extends Laya.Resource {
  26550. constructor() {
  26551. super();
  26552. this._nodes = new KeyframeNodeList();
  26553. this._animationEvents = [];
  26554. }
  26555. static _parse(data, propertyParams = null, constructParams = null) {
  26556. var clip = new AnimationClip();
  26557. var reader = new Laya.Byte(data);
  26558. var version = reader.readUTFString();
  26559. switch (version) {
  26560. case "LAYAANIMATION:03":
  26561. AnimationClipParser03.parse(clip, reader);
  26562. break;
  26563. case "LAYAANIMATION:04":
  26564. case "LAYAANIMATION:COMPRESSION_04":
  26565. AnimationClipParser04.parse(clip, reader, version);
  26566. break;
  26567. default:
  26568. throw "unknown animationClip version.";
  26569. }
  26570. return clip;
  26571. }
  26572. static load(url, complete) {
  26573. Laya.ILaya.loader.create(url, complete, null, AnimationClip.ANIMATIONCLIP);
  26574. }
  26575. duration() {
  26576. return this._duration;
  26577. }
  26578. _hermiteInterpolate(frame, nextFrame, t, dur) {
  26579. var t0 = frame.outTangent, t1 = nextFrame.inTangent;
  26580. if (Number.isFinite(t0) && Number.isFinite(t1)) {
  26581. var t2 = t * t;
  26582. var t3 = t2 * t;
  26583. var a = 2.0 * t3 - 3.0 * t2 + 1.0;
  26584. var b = t3 - 2.0 * t2 + t;
  26585. var c = t3 - t2;
  26586. var d = -2.0 * t3 + 3.0 * t2;
  26587. return a * frame.value + b * t0 * dur + c * t1 * dur + d * nextFrame.value;
  26588. }
  26589. else
  26590. return frame.value;
  26591. }
  26592. _hermiteInterpolateVector3(frame, nextFrame, t, dur, out) {
  26593. var p0 = frame.value;
  26594. var tan0 = frame.outTangent;
  26595. var p1 = nextFrame.value;
  26596. var tan1 = nextFrame.inTangent;
  26597. var t2 = t * t;
  26598. var t3 = t2 * t;
  26599. var a = 2.0 * t3 - 3.0 * t2 + 1.0;
  26600. var b = t3 - 2.0 * t2 + t;
  26601. var c = t3 - t2;
  26602. var d = -2.0 * t3 + 3.0 * t2;
  26603. var t0 = tan0.x, t1 = tan1.x;
  26604. if (Number.isFinite(t0) && Number.isFinite(t1))
  26605. out.x = a * p0.x + b * t0 * dur + c * t1 * dur + d * p1.x;
  26606. else
  26607. out.x = p0.x;
  26608. t0 = tan0.y, t1 = tan1.y;
  26609. if (Number.isFinite(t0) && Number.isFinite(t1))
  26610. out.y = a * p0.y + b * t0 * dur + c * t1 * dur + d * p1.y;
  26611. else
  26612. out.y = p0.y;
  26613. t0 = tan0.z, t1 = tan1.z;
  26614. if (Number.isFinite(t0) && Number.isFinite(t1))
  26615. out.z = a * p0.z + b * t0 * dur + c * t1 * dur + d * p1.z;
  26616. else
  26617. out.z = p0.z;
  26618. }
  26619. _hermiteInterpolateQuaternion(frame, nextFrame, t, dur, out) {
  26620. var p0 = frame.value;
  26621. var tan0 = frame.outTangent;
  26622. var p1 = nextFrame.value;
  26623. var tan1 = nextFrame.inTangent;
  26624. var t2 = t * t;
  26625. var t3 = t2 * t;
  26626. var a = 2.0 * t3 - 3.0 * t2 + 1.0;
  26627. var b = t3 - 2.0 * t2 + t;
  26628. var c = t3 - t2;
  26629. var d = -2.0 * t3 + 3.0 * t2;
  26630. var t0 = tan0.x, t1 = tan1.x;
  26631. if (Number.isFinite(t0) && Number.isFinite(t1))
  26632. out.x = a * p0.x + b * t0 * dur + c * t1 * dur + d * p1.x;
  26633. else
  26634. out.x = p0.x;
  26635. t0 = tan0.y, t1 = tan1.y;
  26636. if (Number.isFinite(t0) && Number.isFinite(t1))
  26637. out.y = a * p0.y + b * t0 * dur + c * t1 * dur + d * p1.y;
  26638. else
  26639. out.y = p0.y;
  26640. t0 = tan0.z, t1 = tan1.z;
  26641. if (Number.isFinite(t0) && Number.isFinite(t1))
  26642. out.z = a * p0.z + b * t0 * dur + c * t1 * dur + d * p1.z;
  26643. else
  26644. out.z = p0.z;
  26645. t0 = tan0.w, t1 = tan1.w;
  26646. if (Number.isFinite(t0) && Number.isFinite(t1))
  26647. out.w = a * p0.w + b * t0 * dur + c * t1 * dur + d * p1.w;
  26648. else
  26649. out.w = p0.w;
  26650. }
  26651. _evaluateClipDatasRealTime(nodes, playCurTime, realTimeCurrentFrameIndexes, addtive, frontPlay) {
  26652. for (var i = 0, n = nodes.count; i < n; i++) {
  26653. var node = nodes.getNodeByIndex(i);
  26654. var type = node.type;
  26655. var nextFrameIndex;
  26656. var keyFrames = node._keyFrames;
  26657. var keyFramesCount = keyFrames.length;
  26658. var frameIndex = realTimeCurrentFrameIndexes[i];
  26659. if (frontPlay) {
  26660. if ((frameIndex !== -1) && (playCurTime < keyFrames[frameIndex].time)) {
  26661. frameIndex = -1;
  26662. realTimeCurrentFrameIndexes[i] = frameIndex;
  26663. }
  26664. nextFrameIndex = frameIndex + 1;
  26665. while (nextFrameIndex < keyFramesCount) {
  26666. if (keyFrames[nextFrameIndex].time > playCurTime)
  26667. break;
  26668. frameIndex++;
  26669. nextFrameIndex++;
  26670. realTimeCurrentFrameIndexes[i] = frameIndex;
  26671. }
  26672. }
  26673. else {
  26674. nextFrameIndex = frameIndex + 1;
  26675. if ((nextFrameIndex !== keyFramesCount) && (playCurTime > keyFrames[nextFrameIndex].time)) {
  26676. frameIndex = keyFramesCount - 1;
  26677. realTimeCurrentFrameIndexes[i] = frameIndex;
  26678. }
  26679. nextFrameIndex = frameIndex + 1;
  26680. while (frameIndex > -1) {
  26681. if (keyFrames[frameIndex].time < playCurTime)
  26682. break;
  26683. frameIndex--;
  26684. nextFrameIndex--;
  26685. realTimeCurrentFrameIndexes[i] = frameIndex;
  26686. }
  26687. }
  26688. var isEnd = nextFrameIndex === keyFramesCount;
  26689. switch (type) {
  26690. case 0:
  26691. if (frameIndex !== -1) {
  26692. var frame = keyFrames[frameIndex];
  26693. if (isEnd) {
  26694. node.data = frame.value;
  26695. }
  26696. else {
  26697. var nextFarme = keyFrames[nextFrameIndex];
  26698. var d = nextFarme.time - frame.time;
  26699. var t;
  26700. if (d !== 0)
  26701. t = (playCurTime - frame.time) / d;
  26702. else
  26703. t = 0;
  26704. node.data = this._hermiteInterpolate(frame, nextFarme, t, d);
  26705. }
  26706. }
  26707. else {
  26708. node.data = keyFrames[0].value;
  26709. }
  26710. if (addtive)
  26711. node.data -= keyFrames[0].value;
  26712. break;
  26713. case 1:
  26714. case 4:
  26715. var clipData = node.data;
  26716. this._evaluateFrameNodeVector3DatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, clipData);
  26717. if (addtive) {
  26718. var firstFrameValue = keyFrames[0].value;
  26719. clipData.x -= firstFrameValue.x;
  26720. clipData.y -= firstFrameValue.y;
  26721. clipData.z -= firstFrameValue.z;
  26722. }
  26723. break;
  26724. case 2:
  26725. var clipQuat = node.data;
  26726. this._evaluateFrameNodeQuaternionDatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, clipQuat);
  26727. if (addtive) {
  26728. var tempQuat = AnimationClip._tempQuaternion0;
  26729. var firstFrameValueQua = keyFrames[0].value;
  26730. Utils3D.quaternionConjugate(firstFrameValueQua, tempQuat);
  26731. Quaternion.multiply(tempQuat, clipQuat, clipQuat);
  26732. }
  26733. break;
  26734. case 3:
  26735. clipData = node.data;
  26736. this._evaluateFrameNodeVector3DatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, clipData);
  26737. if (addtive) {
  26738. firstFrameValue = keyFrames[0].value;
  26739. clipData.x /= firstFrameValue.x;
  26740. clipData.y /= firstFrameValue.y;
  26741. clipData.z /= firstFrameValue.z;
  26742. }
  26743. break;
  26744. default:
  26745. throw "AnimationClip:unknown node type.";
  26746. }
  26747. }
  26748. }
  26749. _evaluateClipDatasRealTimeForNative(nodes, playCurTime, realTimeCurrentFrameIndexes, addtive) {
  26750. Laya.LayaGL.instance.evaluateClipDatasRealTime(nodes._nativeObj, playCurTime, realTimeCurrentFrameIndexes, addtive);
  26751. }
  26752. _evaluateFrameNodeVector3DatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, outDatas) {
  26753. if (frameIndex !== -1) {
  26754. var frame = keyFrames[frameIndex];
  26755. if (isEnd) {
  26756. var frameData = frame.value;
  26757. outDatas.x = frameData.x;
  26758. outDatas.y = frameData.y;
  26759. outDatas.z = frameData.z;
  26760. }
  26761. else {
  26762. var nextKeyFrame = keyFrames[frameIndex + 1];
  26763. var t;
  26764. var startTime = frame.time;
  26765. var d = nextKeyFrame.time - startTime;
  26766. if (d !== 0)
  26767. t = (playCurTime - startTime) / d;
  26768. else
  26769. t = 0;
  26770. this._hermiteInterpolateVector3(frame, nextKeyFrame, t, d, outDatas);
  26771. }
  26772. }
  26773. else {
  26774. var firstFrameDatas = keyFrames[0].value;
  26775. outDatas.x = firstFrameDatas.x;
  26776. outDatas.y = firstFrameDatas.y;
  26777. outDatas.z = firstFrameDatas.z;
  26778. }
  26779. }
  26780. _evaluateFrameNodeQuaternionDatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, outDatas) {
  26781. if (frameIndex !== -1) {
  26782. var frame = keyFrames[frameIndex];
  26783. if (isEnd) {
  26784. var frameData = frame.value;
  26785. outDatas.x = frameData.x;
  26786. outDatas.y = frameData.y;
  26787. outDatas.z = frameData.z;
  26788. outDatas.w = frameData.w;
  26789. }
  26790. else {
  26791. var nextKeyFrame = keyFrames[frameIndex + 1];
  26792. var t;
  26793. var startTime = frame.time;
  26794. var d = nextKeyFrame.time - startTime;
  26795. if (d !== 0)
  26796. t = (playCurTime - startTime) / d;
  26797. else
  26798. t = 0;
  26799. this._hermiteInterpolateQuaternion(frame, nextKeyFrame, t, d, outDatas);
  26800. }
  26801. }
  26802. else {
  26803. var firstFrameDatas = keyFrames[0].value;
  26804. outDatas.x = firstFrameDatas.x;
  26805. outDatas.y = firstFrameDatas.y;
  26806. outDatas.z = firstFrameDatas.z;
  26807. outDatas.w = firstFrameDatas.w;
  26808. }
  26809. }
  26810. _binarySearchEventIndex(time) {
  26811. var start = 0;
  26812. var end = this._animationEvents.length - 1;
  26813. var mid;
  26814. while (start <= end) {
  26815. mid = Math.floor((start + end) / 2);
  26816. var midValue = this._animationEvents[mid].time;
  26817. if (midValue == time)
  26818. return mid;
  26819. else if (midValue > time)
  26820. end = mid - 1;
  26821. else
  26822. start = mid + 1;
  26823. }
  26824. return start;
  26825. }
  26826. addEvent(event) {
  26827. var index = this._binarySearchEventIndex(event.time);
  26828. this._animationEvents.splice(index, 0, event);
  26829. }
  26830. _disposeResource() {
  26831. this._nodes = null;
  26832. this._nodesMap = null;
  26833. }
  26834. }
  26835. AnimationClip.ANIMATIONCLIP = "ANIMATIONCLIP";
  26836. AnimationClip._tempQuaternion0 = new Quaternion();
  26837. class AnimationTransform3D extends Laya.EventDispatcher {
  26838. constructor(owner, localPosition = null, localRotation = null, localScale = null, worldMatrix = null) {
  26839. super();
  26840. this._owner = owner;
  26841. this._children = [];
  26842. this._localMatrix = new Float32Array(16);
  26843. if (Laya.Render.supportWebGLPlusAnimation) {
  26844. this._localPosition = new ConchVector3(0, 0, 0, localPosition);
  26845. this._localRotation = new ConchQuaternion(0, 0, 0, 1, localRotation);
  26846. this._localScale = new ConchVector3(0, 0, 0, localScale);
  26847. this._worldMatrix = worldMatrix;
  26848. }
  26849. else {
  26850. this._localPosition = new Vector3();
  26851. this._localRotation = new Quaternion();
  26852. this._localScale = new Vector3();
  26853. this._worldMatrix = new Float32Array(16);
  26854. }
  26855. this._localQuaternionUpdate = false;
  26856. this._locaEulerlUpdate = false;
  26857. this._localUpdate = false;
  26858. this._worldUpdate = true;
  26859. }
  26860. _getlocalMatrix() {
  26861. if (this._localUpdate) {
  26862. Utils3D._createAffineTransformationArray(this._localPosition, this._localRotation, this._localScale, this._localMatrix);
  26863. this._localUpdate = false;
  26864. }
  26865. return this._localMatrix;
  26866. }
  26867. _onWorldTransform() {
  26868. if (!this._worldUpdate) {
  26869. this._worldUpdate = true;
  26870. this.event(Laya.Event.TRANSFORM_CHANGED);
  26871. for (var i = 0, n = this._children.length; i < n; i++)
  26872. this._children[i]._onWorldTransform();
  26873. }
  26874. }
  26875. get localPosition() {
  26876. return this._localPosition;
  26877. }
  26878. set localPosition(value) {
  26879. this._localPosition = value;
  26880. this._localUpdate = true;
  26881. this._onWorldTransform();
  26882. }
  26883. get localRotation() {
  26884. if (this._localQuaternionUpdate) {
  26885. var euler = this._localRotationEuler;
  26886. Quaternion.createFromYawPitchRoll(euler.y / AnimationTransform3D._angleToRandin, euler.x / AnimationTransform3D._angleToRandin, euler.z / AnimationTransform3D._angleToRandin, this._localRotation);
  26887. this._localQuaternionUpdate = false;
  26888. }
  26889. return this._localRotation;
  26890. }
  26891. set localRotation(value) {
  26892. this._localRotation = value;
  26893. this._locaEulerlUpdate = true;
  26894. this._localQuaternionUpdate = false;
  26895. this._localUpdate = true;
  26896. this._onWorldTransform();
  26897. }
  26898. get localScale() {
  26899. return this._localScale;
  26900. }
  26901. set localScale(value) {
  26902. this._localScale = value;
  26903. this._localUpdate = true;
  26904. this._onWorldTransform();
  26905. }
  26906. get localRotationEuler() {
  26907. if (this._locaEulerlUpdate) {
  26908. this._localRotation.getYawPitchRoll(AnimationTransform3D._tempVector3);
  26909. var euler = AnimationTransform3D._tempVector3;
  26910. var localRotationEuler = this._localRotationEuler;
  26911. localRotationEuler.x = euler.y * AnimationTransform3D._angleToRandin;
  26912. localRotationEuler.y = euler.x * AnimationTransform3D._angleToRandin;
  26913. localRotationEuler.z = euler.z * AnimationTransform3D._angleToRandin;
  26914. this._locaEulerlUpdate = false;
  26915. }
  26916. return this._localRotationEuler;
  26917. }
  26918. set localRotationEuler(value) {
  26919. this._localRotationEuler = value;
  26920. this._locaEulerlUpdate = false;
  26921. this._localQuaternionUpdate = true;
  26922. this._localUpdate = true;
  26923. this._onWorldTransform();
  26924. }
  26925. getWorldMatrix() {
  26926. if (!Laya.Render.supportWebGLPlusAnimation && this._worldUpdate) {
  26927. if (this._parent != null) {
  26928. Utils3D.matrix4x4MultiplyFFF(this._parent.getWorldMatrix(), this._getlocalMatrix(), this._worldMatrix);
  26929. }
  26930. else {
  26931. var e = this._worldMatrix;
  26932. e[1] = e[2] = e[3] = e[4] = e[6] = e[7] = e[8] = e[9] = e[11] = e[12] = e[13] = e[14] = 0;
  26933. e[0] = e[5] = e[10] = e[15] = 1;
  26934. }
  26935. this._worldUpdate = false;
  26936. }
  26937. if (Laya.Render.supportWebGLPlusAnimation && this._worldUpdate) {
  26938. this._worldUpdate = false;
  26939. }
  26940. return this._worldMatrix;
  26941. }
  26942. setParent(value) {
  26943. if (this._parent !== value) {
  26944. if (this._parent) {
  26945. var parentChilds = this._parent._children;
  26946. var index = parentChilds.indexOf(this);
  26947. parentChilds.splice(index, 1);
  26948. }
  26949. if (value) {
  26950. value._children.push(this);
  26951. (value) && (this._onWorldTransform());
  26952. }
  26953. this._parent = value;
  26954. }
  26955. }
  26956. }
  26957. AnimationTransform3D._tempVector3 = new Vector3();
  26958. AnimationTransform3D._angleToRandin = 180 / Math.PI;
  26959. class AnimationNode {
  26960. constructor(localPosition = null, localRotation = null, localScale = null, worldMatrix = null) {
  26961. this._children = [];
  26962. this.transform = new AnimationTransform3D(this, localPosition, localRotation, localScale, worldMatrix);
  26963. }
  26964. addChild(child) {
  26965. child._parent = this;
  26966. child.transform.setParent(this.transform);
  26967. this._children.push(child);
  26968. }
  26969. removeChild(child) {
  26970. var index = this._children.indexOf(child);
  26971. (index !== -1) && (this._children.splice(index, 1));
  26972. }
  26973. getChildByName(name) {
  26974. for (var i = 0, n = this._children.length; i < n; i++) {
  26975. var child = this._children[i];
  26976. if (child.name === name)
  26977. return child;
  26978. }
  26979. return null;
  26980. }
  26981. getChildByIndex(index) {
  26982. return this._children[index];
  26983. }
  26984. getChildCount() {
  26985. return this._children.length;
  26986. }
  26987. cloneTo(destObject) {
  26988. var destNode = destObject;
  26989. destNode.name = this.name;
  26990. for (var i = 0, n = this._children.length; i < n; i++) {
  26991. var child = this._children[i];
  26992. var destChild = child.clone();
  26993. destNode.addChild(destChild);
  26994. var transform = child.transform;
  26995. var destTransform = destChild.transform;
  26996. var destLocalPosition = destTransform.localPosition;
  26997. var destLocalRotation = destTransform.localRotation;
  26998. var destLocalScale = destTransform.localScale;
  26999. transform.localPosition.cloneTo(destLocalPosition);
  27000. transform.localRotation.cloneTo(destLocalRotation);
  27001. transform.localScale.cloneTo(destLocalScale);
  27002. destTransform.localPosition = destLocalPosition;
  27003. destTransform.localRotation = destLocalRotation;
  27004. destTransform.localScale = destLocalScale;
  27005. }
  27006. }
  27007. clone() {
  27008. var dest = new AnimationNode();
  27009. this.cloneTo(dest);
  27010. return dest;
  27011. }
  27012. _cloneNative(localPositions, localRotations, localScales, animationNodeWorldMatrixs, animationNodeParentIndices, parentIndex, avatar) {
  27013. var curID = avatar._nativeCurCloneCount;
  27014. animationNodeParentIndices[curID] = parentIndex;
  27015. var localPosition = new Float32Array(localPositions.buffer, curID * 3 * 4, 3);
  27016. var localRotation = new Float32Array(localRotations.buffer, curID * 4 * 4, 4);
  27017. var localScale = new Float32Array(localScales.buffer, curID * 3 * 4, 3);
  27018. var worldMatrix = new Float32Array(animationNodeWorldMatrixs.buffer, curID * 16 * 4, 16);
  27019. var dest = new AnimationNode(localPosition, localRotation, localScale, worldMatrix);
  27020. dest._worldMatrixIndex = curID;
  27021. this._cloneToNative(dest, localPositions, localRotations, localScales, animationNodeWorldMatrixs, animationNodeParentIndices, curID, avatar);
  27022. return dest;
  27023. }
  27024. _cloneToNative(destObject, localPositions, localRotations, localScales, animationNodeWorldMatrixs, animationNodeParentIndices, parentIndex, avatar) {
  27025. var destNode = destObject;
  27026. destNode.name = this.name;
  27027. for (var i = 0, n = this._children.length; i < n; i++) {
  27028. var child = this._children[i];
  27029. avatar._nativeCurCloneCount++;
  27030. var destChild = child._cloneNative(localPositions, localRotations, localScales, animationNodeWorldMatrixs, animationNodeParentIndices, parentIndex, avatar);
  27031. destNode.addChild(destChild);
  27032. var transform = child.transform;
  27033. var destTransform = destChild.transform;
  27034. var destLocalPosition = destTransform.localPosition;
  27035. var destLocalRotation = destTransform.localRotation;
  27036. var destLocalScale = destTransform.localScale;
  27037. transform.localPosition.cloneTo(destLocalPosition);
  27038. transform.localRotation.cloneTo(destLocalRotation);
  27039. transform.localScale.cloneTo(destLocalScale);
  27040. destTransform.localPosition = destLocalPosition;
  27041. destTransform.localRotation = destLocalRotation;
  27042. destTransform.localScale = destLocalScale;
  27043. }
  27044. }
  27045. }
  27046. class Avatar extends Laya.Resource {
  27047. constructor() {
  27048. super();
  27049. this._nativeNodeCount = 0;
  27050. this._nativeCurCloneCount = 0;
  27051. }
  27052. static _parse(data, propertyParams = null, constructParams = null) {
  27053. var avatar = new Avatar();
  27054. avatar._rootNode = new AnimationNode(new Float32Array(3), new Float32Array(4), new Float32Array(3), new Float32Array(16));
  27055. if (Laya.Render.supportWebGLPlusAnimation)
  27056. avatar._nativeNodeCount++;
  27057. if (data.version) {
  27058. var rootNode = data.rootNode;
  27059. (rootNode) && (avatar._parseNode(rootNode, avatar._rootNode));
  27060. }
  27061. return avatar;
  27062. }
  27063. static load(url, complete) {
  27064. Laya.ILaya.loader.create(url, complete, null, Avatar.AVATAR);
  27065. }
  27066. _initCloneToAnimator(destNode, destAnimator) {
  27067. destAnimator._avatarNodeMap[destNode.name] = destNode;
  27068. for (var i = 0, n = destNode.getChildCount(); i < n; i++)
  27069. this._initCloneToAnimator(destNode.getChildByIndex(i), destAnimator);
  27070. }
  27071. _parseNode(nodaData, node) {
  27072. var name = nodaData.props.name;
  27073. node.name = name;
  27074. var props = nodaData.props;
  27075. var transform = node.transform;
  27076. var pos = transform.localPosition;
  27077. var rot = transform.localRotation;
  27078. var sca = transform.localScale;
  27079. pos.fromArray(props.translate);
  27080. rot.fromArray(props.rotation);
  27081. sca.fromArray(props.scale);
  27082. transform.localPosition = pos;
  27083. transform.localRotation = rot;
  27084. transform.localScale = sca;
  27085. var childrenData = nodaData.child;
  27086. for (var j = 0, n = childrenData.length; j < n; j++) {
  27087. var childData = childrenData[j];
  27088. var childBone = new AnimationNode(new Float32Array(3), new Float32Array(4), new Float32Array(3), new Float32Array(16));
  27089. node.addChild(childBone);
  27090. if (Laya.Render.supportWebGLPlusAnimation)
  27091. this._nativeNodeCount++;
  27092. this._parseNode(childData, childBone);
  27093. }
  27094. }
  27095. _cloneDatasToAnimator(destAnimator) {
  27096. var destRoot;
  27097. destRoot = this._rootNode.clone();
  27098. var transform = this._rootNode.transform;
  27099. var destTransform = destRoot.transform;
  27100. var destPosition = destTransform.localPosition;
  27101. var destRotation = destTransform.localRotation;
  27102. var destScale = destTransform.localScale;
  27103. transform.localPosition.cloneTo(destPosition);
  27104. transform.localRotation.cloneTo(destRotation);
  27105. transform.localScale.cloneTo(destScale);
  27106. destTransform.localPosition = destPosition;
  27107. destTransform.localRotation = destRotation;
  27108. destTransform.localScale = destScale;
  27109. destAnimator._avatarNodeMap = {};
  27110. this._initCloneToAnimator(destRoot, destAnimator);
  27111. }
  27112. cloneTo(destObject) {
  27113. var destAvatar = destObject;
  27114. var destRoot = this._rootNode.clone();
  27115. destAvatar._rootNode = destRoot;
  27116. }
  27117. clone() {
  27118. var dest = new Avatar();
  27119. this.cloneTo(dest);
  27120. return dest;
  27121. }
  27122. _cloneDatasToAnimatorNative(destAnimator) {
  27123. var animationNodeLocalPositions = new Float32Array(this._nativeNodeCount * 3);
  27124. var animationNodeLocalRotations = new Float32Array(this._nativeNodeCount * 4);
  27125. var animationNodeLocalScales = new Float32Array(this._nativeNodeCount * 3);
  27126. var animationNodeWorldMatrixs = new Float32Array(this._nativeNodeCount * 16);
  27127. var animationNodeParentIndices = new Int16Array(this._nativeNodeCount);
  27128. destAnimator._animationNodeLocalPositions = animationNodeLocalPositions;
  27129. destAnimator._animationNodeLocalRotations = animationNodeLocalRotations;
  27130. destAnimator._animationNodeLocalScales = animationNodeLocalScales;
  27131. destAnimator._animationNodeWorldMatrixs = animationNodeWorldMatrixs;
  27132. destAnimator._animationNodeParentIndices = animationNodeParentIndices;
  27133. this._nativeCurCloneCount = 0;
  27134. var destRoot = this._rootNode._cloneNative(animationNodeLocalPositions, animationNodeLocalRotations, animationNodeLocalScales, animationNodeWorldMatrixs, animationNodeParentIndices, -1, this);
  27135. var transform = this._rootNode.transform;
  27136. var destTransform = destRoot.transform;
  27137. var destPosition = destTransform.localPosition;
  27138. var destRotation = destTransform.localRotation;
  27139. var destScale = destTransform.localScale;
  27140. transform.localPosition.cloneTo(destPosition);
  27141. transform.localRotation.cloneTo(destRotation);
  27142. transform.localScale.cloneTo(destScale);
  27143. destTransform.localPosition = destPosition;
  27144. destTransform.localRotation = destRotation;
  27145. destTransform.localScale = destScale;
  27146. destAnimator._avatarNodeMap = {};
  27147. this._initCloneToAnimator(destRoot, destAnimator);
  27148. }
  27149. }
  27150. Avatar.AVATAR = "AVATAR";
  27151. class SkyBoxMaterial extends BaseMaterial {
  27152. constructor() {
  27153. super();
  27154. this.setShaderName("SkyBox");
  27155. this.tintColor = new Vector4(0.5, 0.5, 0.5, 0.5);
  27156. this.exposure = 1.0;
  27157. this.rotation = 0;
  27158. }
  27159. static __initDefine__() {
  27160. }
  27161. get tintColor() {
  27162. return this._shaderValues.getVector(SkyBoxMaterial.TINTCOLOR);
  27163. }
  27164. set tintColor(value) {
  27165. this._shaderValues.setVector(SkyBoxMaterial.TINTCOLOR, value);
  27166. }
  27167. get exposure() {
  27168. return this._shaderValues.getNumber(SkyBoxMaterial.EXPOSURE);
  27169. }
  27170. set exposure(value) {
  27171. this._shaderValues.setNumber(SkyBoxMaterial.EXPOSURE, value);
  27172. }
  27173. get rotation() {
  27174. return this._shaderValues.getNumber(SkyBoxMaterial.ROTATION);
  27175. }
  27176. set rotation(value) {
  27177. this._shaderValues.setNumber(SkyBoxMaterial.ROTATION, value);
  27178. }
  27179. get textureCube() {
  27180. return this._shaderValues.getTexture(SkyBoxMaterial.TEXTURECUBE);
  27181. }
  27182. set textureCube(value) {
  27183. this._shaderValues.setTexture(SkyBoxMaterial.TEXTURECUBE, value);
  27184. }
  27185. clone() {
  27186. var dest = new SkyBoxMaterial();
  27187. this.cloneTo(dest);
  27188. return dest;
  27189. }
  27190. }
  27191. SkyBoxMaterial.TINTCOLOR = Shader3D.propertyNameToID("u_TintColor");
  27192. SkyBoxMaterial.EXPOSURE = Shader3D.propertyNameToID("u_Exposure");
  27193. SkyBoxMaterial.ROTATION = Shader3D.propertyNameToID("u_Rotation");
  27194. SkyBoxMaterial.TEXTURECUBE = Shader3D.propertyNameToID("u_CubeTexture");
  27195. class SubMesh extends GeometryElement {
  27196. constructor(mesh) {
  27197. super();
  27198. this._id = ++SubMesh._uniqueIDCounter;
  27199. this._mesh = mesh;
  27200. this._boneIndicesList = [];
  27201. this._subIndexBufferStart = [];
  27202. this._subIndexBufferCount = [];
  27203. }
  27204. get indexCount() {
  27205. return this._indexCount;
  27206. }
  27207. _setIndexRange(indexStart, indexCount) {
  27208. this._indexStart = indexStart;
  27209. this._indexCount = indexCount;
  27210. this._indices = new Uint16Array(this._indexBuffer.getData().buffer, indexStart * 2, indexCount);
  27211. }
  27212. _getType() {
  27213. return SubMesh._type;
  27214. }
  27215. _prepareRender(state) {
  27216. this._mesh._uploadVerticesData();
  27217. return true;
  27218. }
  27219. _render(state) {
  27220. var gl = Laya.LayaGL.instance;
  27221. this._mesh._bufferState.bind();
  27222. var skinnedDatas = state.renderElement.render._skinnedData;
  27223. if (skinnedDatas) {
  27224. var subSkinnedDatas = skinnedDatas[this._indexInMesh];
  27225. var boneIndicesListCount = this._boneIndicesList.length;
  27226. for (var i = 0; i < boneIndicesListCount; i++) {
  27227. state.shader.uploadCustomUniform(SkinnedMeshSprite3D.BONES, subSkinnedDatas[i]);
  27228. gl.drawElements(gl.TRIANGLES, this._subIndexBufferCount[i], gl.UNSIGNED_SHORT, this._subIndexBufferStart[i] * 2);
  27229. }
  27230. }
  27231. else {
  27232. gl.drawElements(gl.TRIANGLES, this._indexCount, gl.UNSIGNED_SHORT, this._indexStart * 2);
  27233. }
  27234. Laya.Stat.trianglesFaces += this._indexCount / 3;
  27235. Laya.Stat.renderBatches++;
  27236. }
  27237. getIndices() {
  27238. if (this._mesh._isReadable)
  27239. return this._indices.slice();
  27240. else
  27241. throw "SubMesh:can't get indices on subMesh,mesh's isReadable must be true.";
  27242. }
  27243. setIndices(indices) {
  27244. this._indexBuffer.setData(indices, this._indexStart, 0, this._indexCount);
  27245. }
  27246. destroy() {
  27247. if (this._destroyed)
  27248. return;
  27249. super.destroy();
  27250. this._indexBuffer.destroy();
  27251. this._indexBuffer = null;
  27252. this._mesh = null;
  27253. this._boneIndicesList = null;
  27254. this._subIndexBufferStart = null;
  27255. this._subIndexBufferCount = null;
  27256. this._skinAnimationDatas = null;
  27257. }
  27258. }
  27259. SubMesh._uniqueIDCounter = 0;
  27260. SubMesh._type = GeometryElement._typeCounter++;
  27261. class LoadModelV04 {
  27262. static parse(readData, version, mesh, subMeshes) {
  27263. LoadModelV04._mesh = mesh;
  27264. LoadModelV04._subMeshes = subMeshes;
  27265. LoadModelV04._version = version;
  27266. LoadModelV04._readData = readData;
  27267. LoadModelV04.READ_DATA();
  27268. LoadModelV04.READ_BLOCK();
  27269. LoadModelV04.READ_STRINGS();
  27270. for (var i = 0, n = LoadModelV04._BLOCK.count; i < n; i++) {
  27271. LoadModelV04._readData.pos = LoadModelV04._BLOCK.blockStarts[i];
  27272. var index = LoadModelV04._readData.getUint16();
  27273. var blockName = LoadModelV04._strings[index];
  27274. var fn = LoadModelV04["READ_" + blockName];
  27275. if (fn == null)
  27276. throw new Error("model file err,no this function:" + index + " " + blockName);
  27277. else
  27278. fn.call(null);
  27279. }
  27280. LoadModelV04._mesh._bindPoseIndices = new Uint16Array(LoadModelV04._bindPoseIndices);
  27281. LoadModelV04._bindPoseIndices.length = 0;
  27282. LoadModelV04._strings.length = 0;
  27283. LoadModelV04._readData = null;
  27284. LoadModelV04._version = null;
  27285. LoadModelV04._mesh = null;
  27286. LoadModelV04._subMeshes = null;
  27287. }
  27288. static _readString() {
  27289. return LoadModelV04._strings[LoadModelV04._readData.getUint16()];
  27290. }
  27291. static READ_DATA() {
  27292. LoadModelV04._DATA.offset = LoadModelV04._readData.getUint32();
  27293. LoadModelV04._DATA.size = LoadModelV04._readData.getUint32();
  27294. }
  27295. static READ_BLOCK() {
  27296. var count = LoadModelV04._BLOCK.count = LoadModelV04._readData.getUint16();
  27297. var blockStarts = LoadModelV04._BLOCK.blockStarts = [];
  27298. var blockLengths = LoadModelV04._BLOCK.blockLengths = [];
  27299. for (var i = 0; i < count; i++) {
  27300. blockStarts.push(LoadModelV04._readData.getUint32());
  27301. blockLengths.push(LoadModelV04._readData.getUint32());
  27302. }
  27303. }
  27304. static READ_STRINGS() {
  27305. var offset = LoadModelV04._readData.getUint32();
  27306. var count = LoadModelV04._readData.getUint16();
  27307. var prePos = LoadModelV04._readData.pos;
  27308. LoadModelV04._readData.pos = offset + LoadModelV04._DATA.offset;
  27309. for (var i = 0; i < count; i++)
  27310. LoadModelV04._strings[i] = LoadModelV04._readData.readUTFString();
  27311. LoadModelV04._readData.pos = prePos;
  27312. }
  27313. static READ_MESH() {
  27314. var gl = Laya.LayaGL.instance;
  27315. var name = LoadModelV04._readString();
  27316. var arrayBuffer = LoadModelV04._readData.__getBuffer();
  27317. var i;
  27318. var memorySize = 0;
  27319. var vertexBufferCount = LoadModelV04._readData.getInt16();
  27320. var offset = LoadModelV04._DATA.offset;
  27321. for (i = 0; i < vertexBufferCount; i++) {
  27322. var vbStart = offset + LoadModelV04._readData.getUint32();
  27323. var vbLength = LoadModelV04._readData.getUint32();
  27324. var vbArrayBuffer = arrayBuffer.slice(vbStart, vbStart + vbLength);
  27325. var vbDatas = new Float32Array(vbArrayBuffer);
  27326. var bufferAttribute = LoadModelV04._readString();
  27327. var vertexDeclaration;
  27328. switch (LoadModelV04._version) {
  27329. case "LAYAMODEL:0301":
  27330. case "LAYAMODEL:0400":
  27331. vertexDeclaration = VertexMesh.getVertexDeclaration(bufferAttribute);
  27332. break;
  27333. case "LAYAMODEL:0401":
  27334. vertexDeclaration = VertexMesh.getVertexDeclaration(bufferAttribute, false);
  27335. break;
  27336. default:
  27337. throw new Error("LoadModelV03: unknown version.");
  27338. }
  27339. if (!vertexDeclaration)
  27340. throw new Error("LoadModelV03: unknown vertexDeclaration.");
  27341. var vertexBuffer = new VertexBuffer3D(vbDatas.length * 4, gl.STATIC_DRAW, true);
  27342. vertexBuffer.vertexDeclaration = vertexDeclaration;
  27343. vertexBuffer.setData(vbDatas.buffer);
  27344. LoadModelV04._mesh._vertexBuffer = vertexBuffer;
  27345. LoadModelV04._mesh._vertexCount += vertexBuffer.vertexCount;
  27346. memorySize += vbDatas.length * 4;
  27347. }
  27348. var ibStart = offset + LoadModelV04._readData.getUint32();
  27349. var ibLength = LoadModelV04._readData.getUint32();
  27350. var ibDatas = new Uint16Array(arrayBuffer.slice(ibStart, ibStart + ibLength));
  27351. var indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, ibLength / 2, gl.STATIC_DRAW, true);
  27352. indexBuffer.setData(ibDatas);
  27353. LoadModelV04._mesh._indexBuffer = indexBuffer;
  27354. memorySize += indexBuffer.indexCount * 2;
  27355. LoadModelV04._mesh._setBuffer(LoadModelV04._mesh._vertexBuffer, indexBuffer);
  27356. LoadModelV04._mesh._setCPUMemory(memorySize);
  27357. LoadModelV04._mesh._setGPUMemory(memorySize);
  27358. var boneNames = LoadModelV04._mesh._boneNames = [];
  27359. var boneCount = LoadModelV04._readData.getUint16();
  27360. boneNames.length = boneCount;
  27361. for (i = 0; i < boneCount; i++)
  27362. boneNames[i] = LoadModelV04._strings[LoadModelV04._readData.getUint16()];
  27363. LoadModelV04._readData.pos += 8;
  27364. var bindPoseDataStart = LoadModelV04._readData.getUint32();
  27365. var bindPoseDataLength = LoadModelV04._readData.getUint32();
  27366. var bindPoseDatas = new Float32Array(arrayBuffer.slice(offset + bindPoseDataStart, offset + bindPoseDataStart + bindPoseDataLength));
  27367. var bindPoseFloatCount = bindPoseDatas.length;
  27368. var bindPoseBuffer = LoadModelV04._mesh._inverseBindPosesBuffer = new ArrayBuffer(bindPoseFloatCount * 4);
  27369. LoadModelV04._mesh._inverseBindPoses = [];
  27370. for (i = 0; i < bindPoseFloatCount; i += 16) {
  27371. var inverseGlobalBindPose = new Matrix4x4(bindPoseDatas[i + 0], bindPoseDatas[i + 1], bindPoseDatas[i + 2], bindPoseDatas[i + 3], bindPoseDatas[i + 4], bindPoseDatas[i + 5], bindPoseDatas[i + 6], bindPoseDatas[i + 7], bindPoseDatas[i + 8], bindPoseDatas[i + 9], bindPoseDatas[i + 10], bindPoseDatas[i + 11], bindPoseDatas[i + 12], bindPoseDatas[i + 13], bindPoseDatas[i + 14], bindPoseDatas[i + 15], new Float32Array(bindPoseBuffer, i * 4, 16));
  27372. LoadModelV04._mesh._inverseBindPoses[i / 16] = inverseGlobalBindPose;
  27373. }
  27374. return true;
  27375. }
  27376. static READ_SUBMESH() {
  27377. var arrayBuffer = LoadModelV04._readData.__getBuffer();
  27378. var subMesh = new SubMesh(LoadModelV04._mesh);
  27379. LoadModelV04._readData.getInt16();
  27380. LoadModelV04._readData.getUint32();
  27381. LoadModelV04._readData.getUint32();
  27382. var ibStart = LoadModelV04._readData.getUint32();
  27383. var ibCount = LoadModelV04._readData.getUint32();
  27384. var indexBuffer = LoadModelV04._mesh._indexBuffer;
  27385. subMesh._indexBuffer = indexBuffer;
  27386. subMesh._setIndexRange(ibStart, ibCount);
  27387. var vertexBuffer = LoadModelV04._mesh._vertexBuffer;
  27388. subMesh._vertexBuffer = vertexBuffer;
  27389. var offset = LoadModelV04._DATA.offset;
  27390. var subIndexBufferStart = subMesh._subIndexBufferStart;
  27391. var subIndexBufferCount = subMesh._subIndexBufferCount;
  27392. var boneIndicesList = subMesh._boneIndicesList;
  27393. var drawCount = LoadModelV04._readData.getUint16();
  27394. subIndexBufferStart.length = drawCount;
  27395. subIndexBufferCount.length = drawCount;
  27396. boneIndicesList.length = drawCount;
  27397. var pathMarks = LoadModelV04._mesh._skinDataPathMarks;
  27398. var bindPoseIndices = LoadModelV04._bindPoseIndices;
  27399. var subMeshIndex = LoadModelV04._subMeshes.length;
  27400. for (var i = 0; i < drawCount; i++) {
  27401. subIndexBufferStart[i] = LoadModelV04._readData.getUint32();
  27402. subIndexBufferCount[i] = LoadModelV04._readData.getUint32();
  27403. var boneDicofs = LoadModelV04._readData.getUint32();
  27404. var boneDicCount = LoadModelV04._readData.getUint32();
  27405. var boneIndices = boneIndicesList[i] = new Uint16Array(arrayBuffer.slice(offset + boneDicofs, offset + boneDicofs + boneDicCount));
  27406. for (var j = 0, m = boneIndices.length; j < m; j++) {
  27407. var index = boneIndices[j];
  27408. var combineIndex = bindPoseIndices.indexOf(index);
  27409. if (combineIndex === -1) {
  27410. boneIndices[j] = bindPoseIndices.length;
  27411. bindPoseIndices.push(index);
  27412. pathMarks.push([subMeshIndex, i, j]);
  27413. }
  27414. else {
  27415. boneIndices[j] = combineIndex;
  27416. }
  27417. }
  27418. }
  27419. LoadModelV04._subMeshes.push(subMesh);
  27420. return true;
  27421. }
  27422. }
  27423. LoadModelV04._BLOCK = { count: 0 };
  27424. LoadModelV04._DATA = { offset: 0, size: 0 };
  27425. LoadModelV04._strings = [];
  27426. LoadModelV04._bindPoseIndices = [];
  27427. class LoadModelV05 {
  27428. static parse(readData, version, mesh, subMeshes) {
  27429. LoadModelV05._mesh = mesh;
  27430. LoadModelV05._subMeshes = subMeshes;
  27431. LoadModelV05._version = version;
  27432. LoadModelV05._readData = readData;
  27433. LoadModelV05.READ_DATA();
  27434. LoadModelV05.READ_BLOCK();
  27435. LoadModelV05.READ_STRINGS();
  27436. for (var i = 0, n = LoadModelV05._BLOCK.count; i < n; i++) {
  27437. LoadModelV05._readData.pos = LoadModelV05._BLOCK.blockStarts[i];
  27438. var index = LoadModelV05._readData.getUint16();
  27439. var blockName = LoadModelV05._strings[index];
  27440. var fn = LoadModelV05["READ_" + blockName];
  27441. if (fn == null)
  27442. throw new Error("model file err,no this function:" + index + " " + blockName);
  27443. else
  27444. fn.call(null);
  27445. }
  27446. LoadModelV05._mesh._bindPoseIndices = new Uint16Array(LoadModelV05._bindPoseIndices);
  27447. LoadModelV05._bindPoseIndices.length = 0;
  27448. LoadModelV05._strings.length = 0;
  27449. LoadModelV05._readData = null;
  27450. LoadModelV05._version = null;
  27451. LoadModelV05._mesh = null;
  27452. LoadModelV05._subMeshes = null;
  27453. }
  27454. static _readString() {
  27455. return LoadModelV05._strings[LoadModelV05._readData.getUint16()];
  27456. }
  27457. static READ_DATA() {
  27458. LoadModelV05._DATA.offset = LoadModelV05._readData.getUint32();
  27459. LoadModelV05._DATA.size = LoadModelV05._readData.getUint32();
  27460. }
  27461. static READ_BLOCK() {
  27462. var count = LoadModelV05._BLOCK.count = LoadModelV05._readData.getUint16();
  27463. var blockStarts = LoadModelV05._BLOCK.blockStarts = [];
  27464. var blockLengths = LoadModelV05._BLOCK.blockLengths = [];
  27465. for (var i = 0; i < count; i++) {
  27466. blockStarts.push(LoadModelV05._readData.getUint32());
  27467. blockLengths.push(LoadModelV05._readData.getUint32());
  27468. }
  27469. }
  27470. static READ_STRINGS() {
  27471. var offset = LoadModelV05._readData.getUint32();
  27472. var count = LoadModelV05._readData.getUint16();
  27473. var prePos = LoadModelV05._readData.pos;
  27474. LoadModelV05._readData.pos = offset + LoadModelV05._DATA.offset;
  27475. for (var i = 0; i < count; i++)
  27476. LoadModelV05._strings[i] = LoadModelV05._readData.readUTFString();
  27477. LoadModelV05._readData.pos = prePos;
  27478. }
  27479. static READ_MESH() {
  27480. var gl = Laya.LayaGL.instance;
  27481. var i;
  27482. var memorySize = 0;
  27483. var name = LoadModelV05._readString();
  27484. var arrayBuffer = LoadModelV05._readData.__getBuffer();
  27485. var vertexBufferCount = LoadModelV05._readData.getInt16();
  27486. var offset = LoadModelV05._DATA.offset;
  27487. for (i = 0; i < vertexBufferCount; i++) {
  27488. var vbStart = offset + LoadModelV05._readData.getUint32();
  27489. var vertexCount = LoadModelV05._readData.getUint32();
  27490. var vertexFlag = LoadModelV05._readString();
  27491. var vertexDeclaration = VertexMesh.getVertexDeclaration(vertexFlag, false);
  27492. var vertexStride = vertexDeclaration.vertexStride;
  27493. var vertexData;
  27494. var floatData;
  27495. var uint8Data;
  27496. var subVertexFlags = vertexFlag.split(",");
  27497. var subVertexCount = subVertexFlags.length;
  27498. switch (LoadModelV05._version) {
  27499. case "LAYAMODEL:05":
  27500. vertexData = arrayBuffer.slice(vbStart, vbStart + vertexCount * vertexStride);
  27501. floatData = new Float32Array(vertexData);
  27502. uint8Data = new Uint8Array(vertexData);
  27503. break;
  27504. case "LAYAMODEL:COMPRESSION_05":
  27505. vertexData = new ArrayBuffer(vertexStride * vertexCount);
  27506. floatData = new Float32Array(vertexData);
  27507. uint8Data = new Uint8Array(vertexData);
  27508. var lastPosition = LoadModelV05._readData.pos;
  27509. LoadModelV05._readData.pos = vbStart;
  27510. for (var j = 0; j < vertexCount; j++) {
  27511. var subOffset;
  27512. var verOffset = j * vertexStride;
  27513. for (var k = 0; k < subVertexCount; k++) {
  27514. switch (subVertexFlags[k]) {
  27515. case "POSITION":
  27516. subOffset = verOffset / 4;
  27517. floatData[subOffset] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27518. floatData[subOffset + 1] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27519. floatData[subOffset + 2] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27520. verOffset += 12;
  27521. break;
  27522. case "NORMAL":
  27523. subOffset = verOffset / 4;
  27524. floatData[subOffset] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27525. floatData[subOffset + 1] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27526. floatData[subOffset + 2] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27527. verOffset += 12;
  27528. break;
  27529. case "COLOR":
  27530. subOffset = verOffset / 4;
  27531. floatData[subOffset] = LoadModelV05._readData.getUint8() / 255;
  27532. floatData[subOffset + 1] = LoadModelV05._readData.getUint8() / 255;
  27533. floatData[subOffset + 2] = LoadModelV05._readData.getUint8() / 255;
  27534. floatData[subOffset + 3] = LoadModelV05._readData.getUint8() / 255;
  27535. verOffset += 16;
  27536. break;
  27537. case "UV":
  27538. subOffset = verOffset / 4;
  27539. floatData[subOffset] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27540. floatData[subOffset + 1] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27541. verOffset += 8;
  27542. break;
  27543. case "UV1":
  27544. subOffset = verOffset / 4;
  27545. floatData[subOffset] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27546. floatData[subOffset + 1] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27547. verOffset += 8;
  27548. break;
  27549. case "BLENDWEIGHT":
  27550. subOffset = verOffset / 4;
  27551. floatData[subOffset] = LoadModelV05._readData.getUint8() / 255;
  27552. floatData[subOffset + 1] = LoadModelV05._readData.getUint8() / 255;
  27553. floatData[subOffset + 2] = LoadModelV05._readData.getUint8() / 255;
  27554. floatData[subOffset + 3] = LoadModelV05._readData.getUint8() / 255;
  27555. verOffset += 16;
  27556. break;
  27557. case "BLENDINDICES":
  27558. uint8Data[verOffset] = LoadModelV05._readData.getUint8();
  27559. uint8Data[verOffset + 1] = LoadModelV05._readData.getUint8();
  27560. uint8Data[verOffset + 2] = LoadModelV05._readData.getUint8();
  27561. uint8Data[verOffset + 3] = LoadModelV05._readData.getUint8();
  27562. verOffset += 4;
  27563. break;
  27564. case "TANGENT":
  27565. subOffset = verOffset / 4;
  27566. floatData[subOffset] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27567. floatData[subOffset + 1] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27568. floatData[subOffset + 2] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27569. floatData[subOffset + 3] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27570. verOffset += 16;
  27571. break;
  27572. }
  27573. }
  27574. }
  27575. LoadModelV05._readData.pos = lastPosition;
  27576. break;
  27577. }
  27578. var vertexBuffer = new VertexBuffer3D(vertexData.byteLength, gl.STATIC_DRAW, true);
  27579. vertexBuffer.vertexDeclaration = vertexDeclaration;
  27580. vertexBuffer.setData(vertexData);
  27581. LoadModelV05._mesh._vertexBuffer = vertexBuffer;
  27582. LoadModelV05._mesh._vertexCount += vertexBuffer.vertexCount;
  27583. memorySize += floatData.length * 4;
  27584. }
  27585. var ibStart = offset + LoadModelV05._readData.getUint32();
  27586. var ibLength = LoadModelV05._readData.getUint32();
  27587. var ibDatas = new Uint16Array(arrayBuffer.slice(ibStart, ibStart + ibLength));
  27588. var indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, ibLength / 2, gl.STATIC_DRAW, true);
  27589. indexBuffer.setData(ibDatas);
  27590. LoadModelV05._mesh._indexBuffer = indexBuffer;
  27591. LoadModelV05._mesh._setBuffer(LoadModelV05._mesh._vertexBuffer, indexBuffer);
  27592. memorySize += indexBuffer.indexCount * 2;
  27593. LoadModelV05._mesh._setCPUMemory(memorySize);
  27594. LoadModelV05._mesh._setGPUMemory(memorySize);
  27595. var boneNames = LoadModelV05._mesh._boneNames = [];
  27596. var boneCount = LoadModelV05._readData.getUint16();
  27597. boneNames.length = boneCount;
  27598. for (i = 0; i < boneCount; i++)
  27599. boneNames[i] = LoadModelV05._strings[LoadModelV05._readData.getUint16()];
  27600. var bindPoseDataStart = LoadModelV05._readData.getUint32();
  27601. var bindPoseDataLength = LoadModelV05._readData.getUint32();
  27602. var bindPoseDatas = new Float32Array(arrayBuffer.slice(offset + bindPoseDataStart, offset + bindPoseDataStart + bindPoseDataLength));
  27603. var bindPoseFloatCount = bindPoseDatas.length;
  27604. var bindPoseBuffer = LoadModelV05._mesh._inverseBindPosesBuffer = new ArrayBuffer(bindPoseFloatCount * 4);
  27605. LoadModelV05._mesh._inverseBindPoses = [];
  27606. for (i = 0; i < bindPoseFloatCount; i += 16) {
  27607. var inverseGlobalBindPose = new Matrix4x4(bindPoseDatas[i + 0], bindPoseDatas[i + 1], bindPoseDatas[i + 2], bindPoseDatas[i + 3], bindPoseDatas[i + 4], bindPoseDatas[i + 5], bindPoseDatas[i + 6], bindPoseDatas[i + 7], bindPoseDatas[i + 8], bindPoseDatas[i + 9], bindPoseDatas[i + 10], bindPoseDatas[i + 11], bindPoseDatas[i + 12], bindPoseDatas[i + 13], bindPoseDatas[i + 14], bindPoseDatas[i + 15], new Float32Array(bindPoseBuffer, i * 4, 16));
  27608. LoadModelV05._mesh._inverseBindPoses[i / 16] = inverseGlobalBindPose;
  27609. }
  27610. return true;
  27611. }
  27612. static READ_SUBMESH() {
  27613. var arrayBuffer = LoadModelV05._readData.__getBuffer();
  27614. var subMesh = new SubMesh(LoadModelV05._mesh);
  27615. LoadModelV05._readData.getInt16();
  27616. var ibStart = LoadModelV05._readData.getUint32();
  27617. var ibCount = LoadModelV05._readData.getUint32();
  27618. var indexBuffer = LoadModelV05._mesh._indexBuffer;
  27619. subMesh._indexBuffer = indexBuffer;
  27620. subMesh._setIndexRange(ibStart, ibCount);
  27621. var vertexBuffer = LoadModelV05._mesh._vertexBuffer;
  27622. subMesh._vertexBuffer = vertexBuffer;
  27623. var offset = LoadModelV05._DATA.offset;
  27624. var subIndexBufferStart = subMesh._subIndexBufferStart;
  27625. var subIndexBufferCount = subMesh._subIndexBufferCount;
  27626. var boneIndicesList = subMesh._boneIndicesList;
  27627. var drawCount = LoadModelV05._readData.getUint16();
  27628. subIndexBufferStart.length = drawCount;
  27629. subIndexBufferCount.length = drawCount;
  27630. boneIndicesList.length = drawCount;
  27631. var pathMarks = LoadModelV05._mesh._skinDataPathMarks;
  27632. var bindPoseIndices = LoadModelV05._bindPoseIndices;
  27633. var subMeshIndex = LoadModelV05._subMeshes.length;
  27634. for (var i = 0; i < drawCount; i++) {
  27635. subIndexBufferStart[i] = LoadModelV05._readData.getUint32();
  27636. subIndexBufferCount[i] = LoadModelV05._readData.getUint32();
  27637. var boneDicofs = LoadModelV05._readData.getUint32();
  27638. var boneDicCount = LoadModelV05._readData.getUint32();
  27639. var boneIndices = boneIndicesList[i] = new Uint16Array(arrayBuffer.slice(offset + boneDicofs, offset + boneDicofs + boneDicCount));
  27640. for (var j = 0, m = boneIndices.length; j < m; j++) {
  27641. var index = boneIndices[j];
  27642. var combineIndex = bindPoseIndices.indexOf(index);
  27643. if (combineIndex === -1) {
  27644. boneIndices[j] = bindPoseIndices.length;
  27645. bindPoseIndices.push(index);
  27646. pathMarks.push([subMeshIndex, i, j]);
  27647. }
  27648. else {
  27649. boneIndices[j] = combineIndex;
  27650. }
  27651. }
  27652. }
  27653. LoadModelV05._subMeshes.push(subMesh);
  27654. return true;
  27655. }
  27656. }
  27657. LoadModelV05._BLOCK = { count: 0 };
  27658. LoadModelV05._DATA = { offset: 0, size: 0 };
  27659. LoadModelV05._strings = [];
  27660. LoadModelV05._bindPoseIndices = [];
  27661. class MeshReader {
  27662. constructor() {
  27663. }
  27664. static read(data, mesh, subMeshes) {
  27665. var readData = new Laya.Byte(data);
  27666. readData.pos = 0;
  27667. var version = readData.readUTFString();
  27668. switch (version) {
  27669. case "LAYAMODEL:0301":
  27670. case "LAYAMODEL:0400":
  27671. case "LAYAMODEL:0401":
  27672. LoadModelV04.parse(readData, version, mesh, subMeshes);
  27673. break;
  27674. case "LAYAMODEL:05":
  27675. case "LAYAMODEL:COMPRESSION_05":
  27676. LoadModelV05.parse(readData, version, mesh, subMeshes);
  27677. break;
  27678. default:
  27679. throw new Error("MeshReader: unknown mesh version.");
  27680. }
  27681. mesh._setSubMeshes(subMeshes);
  27682. }
  27683. }
  27684. class Mesh extends Laya.Resource {
  27685. constructor(isReadable = true) {
  27686. super();
  27687. this._tempVector30 = new Vector3();
  27688. this._tempVector31 = new Vector3();
  27689. this._tempVector32 = new Vector3();
  27690. this._minVerticesUpdate = -1;
  27691. this._maxVerticesUpdate = -1;
  27692. this._needUpdateBounds = true;
  27693. this._bounds = new Bounds(new Vector3(), new Vector3());
  27694. this._bufferState = new BufferState();
  27695. this._instanceBufferState = new BufferState();
  27696. this._vertexBuffer = null;
  27697. this._indexBuffer = null;
  27698. this._vertexCount = 0;
  27699. this._isReadable = isReadable;
  27700. this._subMeshes = [];
  27701. this._skinDataPathMarks = [];
  27702. }
  27703. static __init__() {
  27704. var physics3D = Physics3D._physics3D;
  27705. if (physics3D) {
  27706. Mesh._nativeTempVector30 = new physics3D.btVector3(0, 0, 0);
  27707. Mesh._nativeTempVector31 = new physics3D.btVector3(0, 0, 0);
  27708. Mesh._nativeTempVector32 = new physics3D.btVector3(0, 0, 0);
  27709. }
  27710. }
  27711. static _parse(data, propertyParams = null, constructParams = null) {
  27712. var mesh = new Mesh();
  27713. MeshReader.read(data, mesh, mesh._subMeshes);
  27714. return mesh;
  27715. }
  27716. static load(url, complete) {
  27717. Laya.ILaya.loader.create(url, complete, null, Mesh.MESH);
  27718. }
  27719. get inverseAbsoluteBindPoses() {
  27720. return this._inverseBindPoses;
  27721. }
  27722. get vertexCount() {
  27723. return this._vertexCount;
  27724. }
  27725. get indexCount() {
  27726. return this._indexBuffer.indexCount;
  27727. }
  27728. get subMeshCount() {
  27729. return this._subMeshes.length;
  27730. }
  27731. get bounds() {
  27732. return this._bounds;
  27733. }
  27734. set bounds(value) {
  27735. if (this._bounds !== value)
  27736. value.cloneTo(this._bounds);
  27737. }
  27738. _getPositionElement(vertexBuffer) {
  27739. var vertexElements = vertexBuffer.vertexDeclaration._vertexElements;
  27740. for (var i = 0, n = vertexElements.length; i < n; i++) {
  27741. var vertexElement = vertexElements[i];
  27742. if (vertexElement._elementFormat === VertexElementFormat.Vector3 && vertexElement._elementUsage === VertexMesh.MESH_POSITION0)
  27743. return vertexElement;
  27744. }
  27745. return null;
  27746. }
  27747. _getVerticeElementData(data, elementUsage) {
  27748. data.length = this._vertexCount;
  27749. var verDec = this._vertexBuffer.vertexDeclaration;
  27750. var element = verDec.getVertexElementByUsage(elementUsage);
  27751. if (element) {
  27752. var uint8Vertices = this._vertexBuffer.getUint8Data();
  27753. var floatVertices = this._vertexBuffer.getFloat32Data();
  27754. var uint8VerStr = verDec.vertexStride;
  27755. var floatVerStr = uint8VerStr / 4;
  27756. var uint8EleOffset = element._offset;
  27757. var floatEleOffset = uint8EleOffset / 4;
  27758. switch (elementUsage) {
  27759. case VertexMesh.MESH_TEXTURECOORDINATE0:
  27760. case VertexMesh.MESH_TEXTURECOORDINATE1:
  27761. for (var i = 0; i < this._vertexCount; i++) {
  27762. var offset = floatVerStr * i + floatEleOffset;
  27763. data[i] = new Vector2(floatVertices[offset], floatVertices[offset + 1]);
  27764. }
  27765. break;
  27766. case VertexMesh.MESH_POSITION0:
  27767. case VertexMesh.MESH_NORMAL0:
  27768. for (var i = 0; i < this._vertexCount; i++) {
  27769. var offset = floatVerStr * i + floatEleOffset;
  27770. data[i] = new Vector3(floatVertices[offset], floatVertices[offset + 1], floatVertices[offset + 2]);
  27771. }
  27772. break;
  27773. case VertexMesh.MESH_TANGENT0:
  27774. case VertexMesh.MESH_BLENDWEIGHT0:
  27775. for (var i = 0; i < this._vertexCount; i++) {
  27776. var offset = floatVerStr * i + floatEleOffset;
  27777. data[i] = new Vector4(floatVertices[offset], floatVertices[offset + 1], floatVertices[offset + 2], floatVertices[offset + 3]);
  27778. }
  27779. break;
  27780. case VertexMesh.MESH_COLOR0:
  27781. for (var i = 0; i < this._vertexCount; i++) {
  27782. var offset = floatVerStr * i + floatEleOffset;
  27783. data[i] = new Color(floatVertices[offset], floatVertices[offset + 1], floatVertices[offset + 2], floatVertices[offset + 3]);
  27784. }
  27785. break;
  27786. case VertexMesh.MESH_BLENDINDICES0:
  27787. for (var i = 0; i < this._vertexCount; i++) {
  27788. var offset = uint8VerStr * i + uint8EleOffset;
  27789. data[i] = new Vector4(uint8Vertices[offset], uint8Vertices[offset + 1], uint8Vertices[offset + 2], uint8Vertices[offset + 3]);
  27790. }
  27791. break;
  27792. default:
  27793. throw "Mesh:Unknown elementUsage.";
  27794. }
  27795. }
  27796. }
  27797. _setVerticeElementData(data, elementUsage) {
  27798. var verDec = this._vertexBuffer.vertexDeclaration;
  27799. var element = verDec.getVertexElementByUsage(elementUsage);
  27800. if (element) {
  27801. var uint8Vertices = this._vertexBuffer.getUint8Data();
  27802. var floatVertices = this._vertexBuffer.getFloat32Data();
  27803. var uint8VerStr = verDec.vertexStride;
  27804. var float8VerStr = uint8VerStr / 4;
  27805. var uint8EleOffset = element._offset;
  27806. var floatEleOffset = uint8EleOffset / 4;
  27807. switch (elementUsage) {
  27808. case VertexMesh.MESH_TEXTURECOORDINATE0:
  27809. case VertexMesh.MESH_TEXTURECOORDINATE1:
  27810. for (var i = 0, n = data.length; i < n; i++) {
  27811. var offset = float8VerStr * i + floatEleOffset;
  27812. var vec2 = data[i];
  27813. floatVertices[offset] = vec2.x;
  27814. floatVertices[offset + 1] = vec2.y;
  27815. }
  27816. break;
  27817. case VertexMesh.MESH_POSITION0:
  27818. case VertexMesh.MESH_NORMAL0:
  27819. for (var i = 0, n = data.length; i < n; i++) {
  27820. var offset = float8VerStr * i + floatEleOffset;
  27821. var vec3 = data[i];
  27822. floatVertices[offset] = vec3.x;
  27823. floatVertices[offset + 1] = vec3.y;
  27824. floatVertices[offset + 2] = vec3.z;
  27825. }
  27826. break;
  27827. case VertexMesh.MESH_TANGENT0:
  27828. case VertexMesh.MESH_BLENDWEIGHT0:
  27829. for (var i = 0, n = data.length; i < n; i++) {
  27830. var offset = float8VerStr * i + floatEleOffset;
  27831. var vec4 = data[i];
  27832. floatVertices[offset] = vec4.x;
  27833. floatVertices[offset + 1] = vec4.y;
  27834. floatVertices[offset + 2] = vec4.z;
  27835. floatVertices[offset + 3] = vec4.w;
  27836. }
  27837. break;
  27838. case VertexMesh.MESH_COLOR0:
  27839. for (var i = 0, n = data.length; i < n; i++) {
  27840. var offset = float8VerStr * i + floatEleOffset;
  27841. var cor = data[i];
  27842. floatVertices[offset] = cor.r;
  27843. floatVertices[offset + 1] = cor.g;
  27844. floatVertices[offset + 2] = cor.b;
  27845. floatVertices[offset + 2] = cor.a;
  27846. }
  27847. break;
  27848. case VertexMesh.MESH_BLENDINDICES0:
  27849. for (var i = 0, n = data.length; i < n; i++) {
  27850. var offset = uint8VerStr * i + uint8EleOffset;
  27851. var vec4 = data[i];
  27852. uint8Vertices[offset] = vec4.x;
  27853. uint8Vertices[offset + 1] = vec4.y;
  27854. uint8Vertices[offset + 2] = vec4.z;
  27855. uint8Vertices[offset + 3] = vec4.w;
  27856. }
  27857. break;
  27858. default:
  27859. throw "Mesh:Unknown elementUsage.";
  27860. }
  27861. }
  27862. else {
  27863. console.warn("Mesh: the mesh don't have this VertexElement.");
  27864. }
  27865. }
  27866. _disposeResource() {
  27867. for (var i = 0, n = this._subMeshes.length; i < n; i++)
  27868. this._subMeshes[i].destroy();
  27869. this._nativeTriangleMesh && window.Physics3D.destroy(this._nativeTriangleMesh);
  27870. this._vertexBuffer.destroy();
  27871. this._indexBuffer.destroy();
  27872. this._setCPUMemory(0);
  27873. this._setGPUMemory(0);
  27874. this._bufferState.destroy();
  27875. this._instanceBufferState.destroy();
  27876. this._bufferState = null;
  27877. this._instanceBufferState = null;
  27878. this._vertexBuffer = null;
  27879. this._indexBuffer = null;
  27880. this._subMeshes = null;
  27881. this._nativeTriangleMesh = null;
  27882. this._indexBuffer = null;
  27883. this._boneNames = null;
  27884. this._inverseBindPoses = null;
  27885. }
  27886. _setSubMeshes(subMeshes) {
  27887. this._subMeshes = subMeshes;
  27888. for (var i = 0, n = subMeshes.length; i < n; i++)
  27889. subMeshes[i]._indexInMesh = i;
  27890. this.calculateBounds();
  27891. }
  27892. _setBuffer(vertexBuffer, indexBuffer) {
  27893. var bufferState = this._bufferState;
  27894. bufferState.bind();
  27895. bufferState.applyVertexBuffer(vertexBuffer);
  27896. bufferState.applyIndexBuffer(indexBuffer);
  27897. bufferState.unBind();
  27898. var instanceBufferState = this._instanceBufferState;
  27899. instanceBufferState.bind();
  27900. instanceBufferState.applyVertexBuffer(vertexBuffer);
  27901. instanceBufferState.applyInstanceVertexBuffer(SubMeshInstanceBatch.instance.instanceWorldMatrixBuffer);
  27902. instanceBufferState.applyInstanceVertexBuffer(SubMeshInstanceBatch.instance.instanceMVPMatrixBuffer);
  27903. instanceBufferState.applyIndexBuffer(indexBuffer);
  27904. instanceBufferState.unBind();
  27905. }
  27906. _getPhysicMesh() {
  27907. if (!this._nativeTriangleMesh) {
  27908. var physics3D = window.Physics3D;
  27909. var triangleMesh = new physics3D.btTriangleMesh();
  27910. var nativePositio0 = Mesh._nativeTempVector30;
  27911. var nativePositio1 = Mesh._nativeTempVector31;
  27912. var nativePositio2 = Mesh._nativeTempVector32;
  27913. var position0 = this._tempVector30;
  27914. var position1 = this._tempVector31;
  27915. var position2 = this._tempVector32;
  27916. var vertexBuffer = this._vertexBuffer;
  27917. var positionElement = this._getPositionElement(vertexBuffer);
  27918. var verticesData = vertexBuffer.getFloat32Data();
  27919. var floatCount = vertexBuffer.vertexDeclaration.vertexStride / 4;
  27920. var posOffset = positionElement._offset / 4;
  27921. var indices = this._indexBuffer.getData();
  27922. for (var i = 0, n = indices.length; i < n; i += 3) {
  27923. var p0Index = indices[i] * floatCount + posOffset;
  27924. var p1Index = indices[i + 1] * floatCount + posOffset;
  27925. var p2Index = indices[i + 2] * floatCount + posOffset;
  27926. position0.setValue(verticesData[p0Index], verticesData[p0Index + 1], verticesData[p0Index + 2]);
  27927. position1.setValue(verticesData[p1Index], verticesData[p1Index + 1], verticesData[p1Index + 2]);
  27928. position2.setValue(verticesData[p2Index], verticesData[p2Index + 1], verticesData[p2Index + 2]);
  27929. Utils3D._convertToBulletVec3(position0, nativePositio0, true);
  27930. Utils3D._convertToBulletVec3(position1, nativePositio1, true);
  27931. Utils3D._convertToBulletVec3(position2, nativePositio2, true);
  27932. triangleMesh.addTriangle(nativePositio0, nativePositio1, nativePositio2, true);
  27933. }
  27934. this._nativeTriangleMesh = triangleMesh;
  27935. }
  27936. return this._nativeTriangleMesh;
  27937. }
  27938. _uploadVerticesData() {
  27939. var min = this._minVerticesUpdate;
  27940. var max = this._maxVerticesUpdate;
  27941. if (min !== -1 && max !== -1) {
  27942. var offset = min * 4;
  27943. this._vertexBuffer.setData(this._vertexBuffer.getUint8Data().buffer, offset, offset, (max - min) * 4);
  27944. this._minVerticesUpdate = -1;
  27945. this._maxVerticesUpdate = -1;
  27946. }
  27947. }
  27948. getSubMesh(index) {
  27949. return this._subMeshes[index];
  27950. }
  27951. getPositions(positions) {
  27952. if (this._isReadable)
  27953. this._getVerticeElementData(positions, VertexMesh.MESH_POSITION0);
  27954. else
  27955. throw "Mesh:can't get positions on mesh,isReadable must be true.";
  27956. }
  27957. setPositions(positions) {
  27958. if (this._isReadable) {
  27959. this._setVerticeElementData(positions, VertexMesh.MESH_POSITION0);
  27960. this._needUpdateBounds = true;
  27961. }
  27962. else {
  27963. throw "Mesh:setPosition() need isReadable must be true or use setVertices().";
  27964. }
  27965. }
  27966. getColors(colors) {
  27967. if (this._isReadable)
  27968. this._getVerticeElementData(colors, VertexMesh.MESH_COLOR0);
  27969. else
  27970. throw "Mesh:can't get colors on mesh,isReadable must be true.";
  27971. }
  27972. setColors(colors) {
  27973. if (this._isReadable)
  27974. this._setVerticeElementData(colors, VertexMesh.MESH_COLOR0);
  27975. else
  27976. throw "Mesh:setColors() need isReadable must be true or use setVertices().";
  27977. }
  27978. getUVs(uvs, channel = 0) {
  27979. if (this._isReadable) {
  27980. switch (channel) {
  27981. case 0:
  27982. this._getVerticeElementData(uvs, VertexMesh.MESH_TEXTURECOORDINATE0);
  27983. break;
  27984. case 1:
  27985. this._getVerticeElementData(uvs, VertexMesh.MESH_TEXTURECOORDINATE1);
  27986. break;
  27987. default:
  27988. throw "Mesh:Invalid channel.";
  27989. }
  27990. }
  27991. else {
  27992. throw "Mesh:can't get uvs on mesh,isReadable must be true.";
  27993. }
  27994. }
  27995. setUVs(uvs, channel = 0) {
  27996. if (this._isReadable) {
  27997. switch (channel) {
  27998. case 0:
  27999. this._setVerticeElementData(uvs, VertexMesh.MESH_TEXTURECOORDINATE0);
  28000. break;
  28001. case 1:
  28002. this._setVerticeElementData(uvs, VertexMesh.MESH_TEXTURECOORDINATE1);
  28003. break;
  28004. default:
  28005. throw "Mesh:Invalid channel.";
  28006. }
  28007. }
  28008. else {
  28009. throw "Mesh:setUVs() need isReadable must be true or use setVertices().";
  28010. }
  28011. }
  28012. getNormals(normals) {
  28013. if (this._isReadable)
  28014. this._getVerticeElementData(normals, VertexMesh.MESH_NORMAL0);
  28015. else
  28016. throw "Mesh:can't get colors on mesh,isReadable must be true.";
  28017. }
  28018. setNormals(normals) {
  28019. if (this._isReadable)
  28020. this._setVerticeElementData(normals, VertexMesh.MESH_NORMAL0);
  28021. else
  28022. throw "Mesh:setNormals() need must be true or use setVertices().";
  28023. }
  28024. getTangents(tangents) {
  28025. if (this._isReadable)
  28026. this._getVerticeElementData(tangents, VertexMesh.MESH_TANGENT0);
  28027. else
  28028. throw "Mesh:can't get colors on mesh,isReadable must be true.";
  28029. }
  28030. setTangents(tangents) {
  28031. if (this._isReadable)
  28032. this._setVerticeElementData(tangents, VertexMesh.MESH_TANGENT0);
  28033. else
  28034. throw "Mesh:setTangents() need isReadable must be true or use setVertices().";
  28035. }
  28036. getBoneWeights(boneWeights) {
  28037. if (this._isReadable)
  28038. this._getVerticeElementData(boneWeights, VertexMesh.MESH_BLENDWEIGHT0);
  28039. else
  28040. throw "Mesh:can't get boneWeights on mesh,isReadable must be true.";
  28041. }
  28042. setBoneWeights(boneWeights) {
  28043. if (this._isReadable)
  28044. this._setVerticeElementData(boneWeights, VertexMesh.MESH_BLENDWEIGHT0);
  28045. else
  28046. throw "Mesh:setBoneWeights() need isReadable must be true or use setVertices().";
  28047. }
  28048. getBoneIndices(boneIndices) {
  28049. if (this._isReadable)
  28050. this._getVerticeElementData(boneIndices, VertexMesh.MESH_BLENDINDICES0);
  28051. else
  28052. throw "Mesh:can't get boneIndices on mesh,isReadable must be true.";
  28053. }
  28054. setBoneIndices(boneIndices) {
  28055. if (this._isReadable)
  28056. this._setVerticeElementData(boneIndices, VertexMesh.MESH_BLENDINDICES0);
  28057. else
  28058. throw "Mesh:setBoneIndices() need isReadable must be true or use setVertices().";
  28059. }
  28060. markAsUnreadbale() {
  28061. this._uploadVerticesData();
  28062. this._vertexBuffer.markAsUnreadbale();
  28063. this._isReadable = false;
  28064. }
  28065. getVertexDeclaration() {
  28066. return this._vertexBuffer._vertexDeclaration;
  28067. }
  28068. getVertices() {
  28069. if (this._isReadable)
  28070. return this._vertexBuffer.getUint8Data().buffer.slice(0);
  28071. else
  28072. throw "Mesh:can't get vertices on mesh,isReadable must be true.";
  28073. }
  28074. setVertices(vertices) {
  28075. this._vertexBuffer.setData(vertices);
  28076. this._needUpdateBounds = true;
  28077. }
  28078. getIndices() {
  28079. if (this._isReadable)
  28080. return this._indexBuffer.getData().slice();
  28081. else
  28082. throw "Mesh:can't get indices on subMesh,mesh's isReadable must be true.";
  28083. }
  28084. setIndices(indices) {
  28085. this._indexBuffer.setData(indices);
  28086. }
  28087. calculateBounds() {
  28088. if (this._isReadable) {
  28089. if (this._needUpdateBounds) {
  28090. var min = this._tempVector30;
  28091. var max = this._tempVector31;
  28092. min.x = min.y = min.z = Number.MAX_VALUE;
  28093. max.x = max.y = max.z = -Number.MAX_VALUE;
  28094. var vertexBuffer = this._vertexBuffer;
  28095. var positionElement = this._getPositionElement(vertexBuffer);
  28096. var verticesData = vertexBuffer.getFloat32Data();
  28097. var floatCount = vertexBuffer.vertexDeclaration.vertexStride / 4;
  28098. var posOffset = positionElement._offset / 4;
  28099. for (var j = 0, m = verticesData.length; j < m; j += floatCount) {
  28100. var ofset = j + posOffset;
  28101. var pX = verticesData[ofset];
  28102. var pY = verticesData[ofset + 1];
  28103. var pZ = verticesData[ofset + 2];
  28104. min.x = Math.min(min.x, pX);
  28105. min.y = Math.min(min.y, pY);
  28106. min.z = Math.min(min.z, pZ);
  28107. max.x = Math.max(max.x, pX);
  28108. max.y = Math.max(max.y, pY);
  28109. max.z = Math.max(max.z, pZ);
  28110. }
  28111. this._bounds.setMin(min);
  28112. this._bounds.setMax(max);
  28113. this._needUpdateBounds = false;
  28114. }
  28115. }
  28116. else {
  28117. throw "Mesh:can't calculate bounds on subMesh,mesh's isReadable must be true.";
  28118. }
  28119. }
  28120. cloneTo(destObject) {
  28121. var destMesh = destObject;
  28122. var vb = this._vertexBuffer;
  28123. var destVB = new VertexBuffer3D(vb._byteLength, vb.bufferUsage, vb.canRead);
  28124. destVB.vertexDeclaration = vb.vertexDeclaration;
  28125. destVB.setData(vb.getUint8Data().slice().buffer);
  28126. destMesh._vertexBuffer = destVB;
  28127. destMesh._vertexCount += destVB.vertexCount;
  28128. var ib = this._indexBuffer;
  28129. var destIB = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, ib.indexCount, ib.bufferUsage, ib.canRead);
  28130. destIB.setData(ib.getData().slice());
  28131. destMesh._indexBuffer = destIB;
  28132. destMesh._setBuffer(destMesh._vertexBuffer, destIB);
  28133. destMesh._setCPUMemory(this.cpuMemory);
  28134. destMesh._setGPUMemory(this.gpuMemory);
  28135. var i;
  28136. var boneNames = this._boneNames;
  28137. var destBoneNames = destMesh._boneNames = [];
  28138. for (i = 0; i < boneNames.length; i++)
  28139. destBoneNames[i] = boneNames[i];
  28140. var inverseBindPoses = this._inverseBindPoses;
  28141. var destInverseBindPoses = destMesh._inverseBindPoses = [];
  28142. for (i = 0; i < inverseBindPoses.length; i++)
  28143. destInverseBindPoses[i] = inverseBindPoses[i];
  28144. destMesh._bindPoseIndices = new Uint16Array(this._bindPoseIndices);
  28145. for (i = 0; i < this._skinDataPathMarks.length; i++)
  28146. destMesh._skinDataPathMarks[i] = this._skinDataPathMarks[i].slice();
  28147. for (i = 0; i < this.subMeshCount; i++) {
  28148. var subMesh = this._subMeshes[i];
  28149. var subIndexBufferStart = subMesh._subIndexBufferStart;
  28150. var subIndexBufferCount = subMesh._subIndexBufferCount;
  28151. var boneIndicesList = subMesh._boneIndicesList;
  28152. var destSubmesh = new SubMesh(destMesh);
  28153. destSubmesh._subIndexBufferStart.length = subIndexBufferStart.length;
  28154. destSubmesh._subIndexBufferCount.length = subIndexBufferCount.length;
  28155. destSubmesh._boneIndicesList.length = boneIndicesList.length;
  28156. for (var j = 0; j < subIndexBufferStart.length; j++)
  28157. destSubmesh._subIndexBufferStart[j] = subIndexBufferStart[j];
  28158. for (j = 0; j < subIndexBufferCount.length; j++)
  28159. destSubmesh._subIndexBufferCount[j] = subIndexBufferCount[j];
  28160. for (j = 0; j < boneIndicesList.length; j++)
  28161. destSubmesh._boneIndicesList[j] = new Uint16Array(boneIndicesList[j]);
  28162. destSubmesh._indexBuffer = destIB;
  28163. destSubmesh._indexStart = subMesh._indexStart;
  28164. destSubmesh._indexCount = subMesh._indexCount;
  28165. destSubmesh._indices = new Uint16Array(destIB.getData().buffer, subMesh._indexStart * 2, subMesh._indexCount);
  28166. var vertexBuffer = destMesh._vertexBuffer;
  28167. destSubmesh._vertexBuffer = vertexBuffer;
  28168. destMesh._subMeshes.push(destSubmesh);
  28169. }
  28170. destMesh._setSubMeshes(destMesh._subMeshes);
  28171. }
  28172. clone() {
  28173. var dest = new Mesh();
  28174. this.cloneTo(dest);
  28175. return dest;
  28176. }
  28177. }
  28178. Mesh.MESH = "MESH";
  28179. class TextureCube extends Laya.BaseTexture {
  28180. constructor(size, format = Laya.BaseTexture.FORMAT_R8G8B8, mipmap = false) {
  28181. super(format, mipmap);
  28182. this._glTextureType = Laya.LayaGL.instance.TEXTURE_CUBE_MAP;
  28183. this._width = size;
  28184. this._height = size;
  28185. var gl = Laya.LayaGL.instance;
  28186. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  28187. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  28188. this._setFilterMode(this._filterMode);
  28189. this._setAnisotropy(this._anisoLevel);
  28190. if (this._mipmap) {
  28191. this._mipmapCount = Math.ceil(Math.log2(size));
  28192. for (var i = 0; i < this._mipmapCount; i++)
  28193. this._setPixels([], i, Math.max(size >> i, 1), Math.max(size >> i, 1));
  28194. this._setGPUMemory(size * size * 4 * (1 + 1 / 3) * 6);
  28195. }
  28196. else {
  28197. this._mipmapCount = 1;
  28198. this._setGPUMemory(size * size * 4 * 6);
  28199. }
  28200. }
  28201. static __init__() {
  28202. var pixels = new Uint8Array(3);
  28203. pixels[0] = 128;
  28204. pixels[1] = 128;
  28205. pixels[2] = 128;
  28206. TextureCube.grayTexture = new TextureCube(1, Laya.BaseTexture.FORMAT_R8G8B8, false);
  28207. TextureCube.grayTexture.setSixSidePixels([pixels, pixels, pixels, pixels, pixels, pixels]);
  28208. TextureCube.grayTexture.lock = true;
  28209. }
  28210. static _parse(data, propertyParams = null, constructParams = null) {
  28211. var texture = constructParams ? new TextureCube(0, constructParams[0], constructParams[1]) : new TextureCube(0);
  28212. texture.setSixSideImageSources(data);
  28213. return texture;
  28214. }
  28215. static load(url, complete) {
  28216. Laya.ILaya.loader.create(url, complete, null, TextureCube.TEXTURECUBE);
  28217. }
  28218. get defaulteTexture() {
  28219. return TextureCube.grayTexture;
  28220. }
  28221. _setPixels(pixels, miplevel, width, height) {
  28222. var gl = Laya.LayaGL.instance;
  28223. var glFormat = this._getGLFormat();
  28224. Laya.WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  28225. if (this.format === Laya.BaseTexture.FORMAT_R8G8B8) {
  28226. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  28227. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[0]);
  28228. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[1]);
  28229. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[2]);
  28230. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[3]);
  28231. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[4]);
  28232. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[5]);
  28233. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  28234. }
  28235. else {
  28236. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[0]);
  28237. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[1]);
  28238. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[2]);
  28239. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[3]);
  28240. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[4]);
  28241. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[5]);
  28242. }
  28243. }
  28244. setSixSideImageSources(source, premultiplyAlpha = false) {
  28245. var width;
  28246. var height;
  28247. for (var i = 0; i < 6; i++) {
  28248. var img = source[i];
  28249. if (!img) {
  28250. console.log("TextureCube: image Source can't be null.");
  28251. return;
  28252. }
  28253. var nextWidth = img.width;
  28254. var nextHeight = img.height;
  28255. if (i > 0) {
  28256. if (width !== nextWidth) {
  28257. console.log("TextureCube: each side image's width and height must same.");
  28258. return;
  28259. }
  28260. }
  28261. width = nextWidth;
  28262. height = nextHeight;
  28263. if (width !== height) {
  28264. console.log("TextureCube: each side image's width and height must same.");
  28265. return;
  28266. }
  28267. }
  28268. this._width = width;
  28269. this._height = height;
  28270. var gl = Laya.LayaGL.instance;
  28271. Laya.WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  28272. var glFormat = this._getGLFormat();
  28273. if (!Laya.Render.isConchApp) {
  28274. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true));
  28275. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[0]);
  28276. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[1]);
  28277. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[2]);
  28278. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[3]);
  28279. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[4]);
  28280. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[5]);
  28281. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false));
  28282. }
  28283. else {
  28284. if (premultiplyAlpha == true) {
  28285. for (var j = 0; j < 6; j++)
  28286. source[j].setPremultiplyAlpha(premultiplyAlpha);
  28287. }
  28288. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[0]);
  28289. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[1]);
  28290. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[2]);
  28291. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[3]);
  28292. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[4]);
  28293. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[5]);
  28294. }
  28295. if (this._mipmap && this._isPot(width) && this._isPot(height)) {
  28296. gl.generateMipmap(this._glTextureType);
  28297. this._setGPUMemory(width * height * 4 * (1 + 1 / 3) * 6);
  28298. }
  28299. else {
  28300. this._setGPUMemory(width * height * 4 * 6);
  28301. }
  28302. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  28303. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  28304. this._setFilterMode(this._filterMode);
  28305. this._readyed = true;
  28306. this._activeResource();
  28307. }
  28308. setSixSidePixels(pixels, miplevel = 0) {
  28309. if (!pixels)
  28310. throw new Error("TextureCube:pixels can't be null.");
  28311. var width = Math.max(this._width >> miplevel, 1);
  28312. var height = Math.max(this._height >> miplevel, 1);
  28313. var pixelsCount = width * height * this._getFormatByteCount();
  28314. if (pixels[0].length < pixelsCount)
  28315. throw "TextureCube:pixels length should at least " + pixelsCount + ".";
  28316. this._setPixels(pixels, miplevel, width, height);
  28317. if (miplevel === 0) {
  28318. var gl = Laya.LayaGL.instance;
  28319. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  28320. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  28321. }
  28322. this._readyed = true;
  28323. this._activeResource();
  28324. }
  28325. _recoverResource() {
  28326. }
  28327. }
  28328. TextureCube.TEXTURECUBE = "TEXTURECUBE";
  28329. class PhysicsTriggerComponent extends PhysicsComponent {
  28330. constructor(collisionGroup, canCollideWith) {
  28331. super(collisionGroup, canCollideWith);
  28332. this._isTrigger = false;
  28333. }
  28334. get isTrigger() {
  28335. return this._isTrigger;
  28336. }
  28337. set isTrigger(value) {
  28338. this._isTrigger = value;
  28339. if (this._nativeColliderObject) {
  28340. var flags = this._nativeColliderObject.getCollisionFlags();
  28341. if (value) {
  28342. if ((flags & PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE) === 0)
  28343. this._nativeColliderObject.setCollisionFlags(flags | PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE);
  28344. }
  28345. else {
  28346. if ((flags & PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE) !== 0)
  28347. this._nativeColliderObject.setCollisionFlags(flags ^ PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE);
  28348. }
  28349. }
  28350. }
  28351. _onAdded() {
  28352. super._onAdded();
  28353. this.isTrigger = this._isTrigger;
  28354. }
  28355. _cloneTo(dest) {
  28356. super._cloneTo(dest);
  28357. dest.isTrigger = this._isTrigger;
  28358. }
  28359. }
  28360. class PhysicsCollider extends PhysicsTriggerComponent {
  28361. constructor(collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER, canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  28362. super(collisionGroup, canCollideWith);
  28363. this._enableProcessCollisions = false;
  28364. }
  28365. _addToSimulation() {
  28366. this._simulation._addPhysicsCollider(this, this._collisionGroup, this._canCollideWith);
  28367. }
  28368. _removeFromSimulation() {
  28369. this._simulation._removePhysicsCollider(this);
  28370. }
  28371. _onTransformChanged(flag) {
  28372. flag &= Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE;
  28373. if (flag) {
  28374. this._transformFlag |= flag;
  28375. if (this._isValid() && this._inPhysicUpdateListIndex === -1)
  28376. this._simulation._physicsUpdateList.add(this);
  28377. }
  28378. }
  28379. _parse(data) {
  28380. (data.friction != null) && (this.friction = data.friction);
  28381. (data.rollingFriction != null) && (this.rollingFriction = data.rollingFriction);
  28382. (data.restitution != null) && (this.restitution = data.restitution);
  28383. (data.isTrigger != null) && (this.isTrigger = data.isTrigger);
  28384. super._parse(data);
  28385. this._parseShape(data.shapes);
  28386. }
  28387. _onAdded() {
  28388. var physics3D = Physics3D._physics3D;
  28389. var btColObj = new physics3D.btCollisionObject();
  28390. btColObj.setUserIndex(this.id);
  28391. btColObj.forceActivationState(PhysicsComponent.ACTIVATIONSTATE_DISABLE_SIMULATION);
  28392. var flags = btColObj.getCollisionFlags();
  28393. if (this.owner.isStatic) {
  28394. if ((flags & PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT) > 0)
  28395. flags = flags ^ PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
  28396. flags = flags | PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT;
  28397. }
  28398. else {
  28399. if ((flags & PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT) > 0)
  28400. flags = flags ^ PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT;
  28401. flags = flags | PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
  28402. }
  28403. btColObj.setCollisionFlags(flags);
  28404. this._nativeColliderObject = btColObj;
  28405. super._onAdded();
  28406. }
  28407. }
  28408. class CharacterController extends PhysicsComponent {
  28409. constructor(stepheight = 0.1, upAxis = null, collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER, canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  28410. super(collisionGroup, canCollideWith);
  28411. this._upAxis = new Vector3(0, 1, 0);
  28412. this._maxSlope = 45.0;
  28413. this._jumpSpeed = 10.0;
  28414. this._fallSpeed = 55.0;
  28415. this._gravity = new Vector3(0, -9.8 * 3, 0);
  28416. this._nativeKinematicCharacter = null;
  28417. this._stepHeight = stepheight;
  28418. (upAxis) && (this._upAxis = upAxis);
  28419. }
  28420. static __init__() {
  28421. CharacterController._nativeTempVector30 = new Physics3D._physics3D.btVector3(0, 0, 0);
  28422. }
  28423. get fallSpeed() {
  28424. return this._fallSpeed;
  28425. }
  28426. set fallSpeed(value) {
  28427. this._fallSpeed = value;
  28428. this._nativeKinematicCharacter.setFallSpeed(value);
  28429. }
  28430. get jumpSpeed() {
  28431. return this._jumpSpeed;
  28432. }
  28433. set jumpSpeed(value) {
  28434. this._jumpSpeed = value;
  28435. this._nativeKinematicCharacter.setJumpSpeed(value);
  28436. }
  28437. get gravity() {
  28438. return this._gravity;
  28439. }
  28440. set gravity(value) {
  28441. this._gravity = value;
  28442. var nativeGravity = CharacterController._nativeTempVector30;
  28443. nativeGravity.setValue(-value.x, value.y, value.z);
  28444. this._nativeKinematicCharacter.setGravity(nativeGravity);
  28445. }
  28446. get maxSlope() {
  28447. return this._maxSlope;
  28448. }
  28449. set maxSlope(value) {
  28450. this._maxSlope = value;
  28451. this._nativeKinematicCharacter.setMaxSlope((value / 180) * Math.PI);
  28452. }
  28453. get isGrounded() {
  28454. return this._nativeKinematicCharacter.onGround();
  28455. }
  28456. get stepHeight() {
  28457. return this._stepHeight;
  28458. }
  28459. set stepHeight(value) {
  28460. this._stepHeight = value;
  28461. this._constructCharacter();
  28462. }
  28463. get upAxis() {
  28464. return this._upAxis;
  28465. }
  28466. set upAxis(value) {
  28467. this._upAxis = value;
  28468. this._constructCharacter();
  28469. }
  28470. _constructCharacter() {
  28471. var physics3D = Physics3D._physics3D;
  28472. if (this._nativeKinematicCharacter)
  28473. physics3D.destroy(this._nativeKinematicCharacter);
  28474. var nativeUpAxis = CharacterController._nativeTempVector30;
  28475. nativeUpAxis.setValue(this._upAxis.x, this._upAxis.y, this._upAxis.z);
  28476. this._nativeKinematicCharacter = new physics3D.btKinematicCharacterController(this._nativeColliderObject, this._colliderShape._nativeShape, this._stepHeight, nativeUpAxis);
  28477. this.fallSpeed = this._fallSpeed;
  28478. this.maxSlope = this._maxSlope;
  28479. this.jumpSpeed = this._jumpSpeed;
  28480. this.gravity = this._gravity;
  28481. }
  28482. _onShapeChange(colShape) {
  28483. super._onShapeChange(colShape);
  28484. this._constructCharacter();
  28485. }
  28486. _onAdded() {
  28487. var physics3D = Physics3D._physics3D;
  28488. var ghostObject = new physics3D.btPairCachingGhostObject();
  28489. ghostObject.setUserIndex(this.id);
  28490. ghostObject.setCollisionFlags(PhysicsComponent.COLLISIONFLAGS_CHARACTER_OBJECT);
  28491. this._nativeColliderObject = ghostObject;
  28492. if (this._colliderShape)
  28493. this._constructCharacter();
  28494. super._onAdded();
  28495. }
  28496. _addToSimulation() {
  28497. this._simulation._characters.push(this);
  28498. this._simulation._addCharacter(this, this._collisionGroup, this._canCollideWith);
  28499. }
  28500. _removeFromSimulation() {
  28501. this._simulation._removeCharacter(this);
  28502. var characters = this._simulation._characters;
  28503. characters.splice(characters.indexOf(this), 1);
  28504. }
  28505. _cloneTo(dest) {
  28506. super._cloneTo(dest);
  28507. var destCharacterController = dest;
  28508. destCharacterController.stepHeight = this._stepHeight;
  28509. destCharacterController.upAxis = this._upAxis;
  28510. destCharacterController.maxSlope = this._maxSlope;
  28511. destCharacterController.jumpSpeed = this._jumpSpeed;
  28512. destCharacterController.fallSpeed = this._fallSpeed;
  28513. destCharacterController.gravity = this._gravity;
  28514. }
  28515. _onDestroy() {
  28516. Physics3D._physics3D.destroy(this._nativeKinematicCharacter);
  28517. super._onDestroy();
  28518. this._nativeKinematicCharacter = null;
  28519. }
  28520. move(movement) {
  28521. var nativeMovement = CharacterController._nativeVector30;
  28522. nativeMovement.setValue(-movement.x, movement.y, movement.z);
  28523. this._nativeKinematicCharacter.setWalkDirection(nativeMovement);
  28524. }
  28525. jump(velocity = null) {
  28526. if (velocity) {
  28527. var nativeVelocity = CharacterController._nativeVector30;
  28528. Utils3D._convertToBulletVec3(velocity, nativeVelocity, true);
  28529. this._nativeKinematicCharacter.jump(nativeVelocity);
  28530. }
  28531. else {
  28532. this._nativeKinematicCharacter.jump();
  28533. }
  28534. }
  28535. }
  28536. CharacterController.UPAXIS_X = 0;
  28537. CharacterController.UPAXIS_Y = 1;
  28538. CharacterController.UPAXIS_Z = 2;
  28539. class Rigidbody3D extends PhysicsTriggerComponent {
  28540. constructor(collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER, canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  28541. super(collisionGroup, canCollideWith);
  28542. this._isKinematic = false;
  28543. this._mass = 1.0;
  28544. this._gravity = new Vector3(0, -10, 0);
  28545. this._angularDamping = 0.0;
  28546. this._linearDamping = 0.0;
  28547. this._overrideGravity = false;
  28548. this._totalTorque = new Vector3(0, 0, 0);
  28549. this._totalForce = new Vector3(0, 0, 0);
  28550. this._linearVelocity = new Vector3();
  28551. this._angularVelocity = new Vector3();
  28552. this._linearFactor = new Vector3(1, 1, 1);
  28553. this._angularFactor = new Vector3(1, 1, 1);
  28554. this._detectCollisions = true;
  28555. }
  28556. static __init__() {
  28557. Rigidbody3D._nativeTempVector30 = new Physics3D._physics3D.btVector3(0, 0, 0);
  28558. Rigidbody3D._nativeTempVector31 = new Physics3D._physics3D.btVector3(0, 0, 0);
  28559. Rigidbody3D._nativeVector3Zero = new Physics3D._physics3D.btVector3(0, 0, 0);
  28560. Rigidbody3D._nativeInertia = new Physics3D._physics3D.btVector3(0, 0, 0);
  28561. Rigidbody3D._nativeImpulse = new Physics3D._physics3D.btVector3(0, 0, 0);
  28562. Rigidbody3D._nativeImpulseOffset = new Physics3D._physics3D.btVector3(0, 0, 0);
  28563. Rigidbody3D._nativeGravity = new Physics3D._physics3D.btVector3(0, 0, 0);
  28564. }
  28565. get mass() {
  28566. return this._mass;
  28567. }
  28568. set mass(value) {
  28569. value = Math.max(value, 1e-07);
  28570. this._mass = value;
  28571. (this._isKinematic) || (this._updateMass(value));
  28572. }
  28573. get isKinematic() {
  28574. return this._isKinematic;
  28575. }
  28576. set isKinematic(value) {
  28577. this._isKinematic = value;
  28578. var canInSimulation = !!(this._simulation && this._enabled && this._colliderShape);
  28579. canInSimulation && this._removeFromSimulation();
  28580. var natColObj = this._nativeColliderObject;
  28581. var flags = natColObj.getCollisionFlags();
  28582. if (value) {
  28583. flags = flags | PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
  28584. natColObj.setCollisionFlags(flags);
  28585. this._nativeColliderObject.forceActivationState(PhysicsComponent.ACTIVATIONSTATE_DISABLE_DEACTIVATION);
  28586. this._enableProcessCollisions = false;
  28587. this._updateMass(0);
  28588. }
  28589. else {
  28590. if ((flags & PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT) > 0)
  28591. flags = flags ^ PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
  28592. natColObj.setCollisionFlags(flags);
  28593. this._nativeColliderObject.setActivationState(PhysicsComponent.ACTIVATIONSTATE_ACTIVE_TAG);
  28594. this._enableProcessCollisions = true;
  28595. this._updateMass(this._mass);
  28596. }
  28597. var nativeZero = Rigidbody3D._nativeVector3Zero;
  28598. natColObj.setInterpolationLinearVelocity(nativeZero);
  28599. natColObj.setLinearVelocity(nativeZero);
  28600. natColObj.setInterpolationAngularVelocity(nativeZero);
  28601. natColObj.setAngularVelocity(nativeZero);
  28602. canInSimulation && this._addToSimulation();
  28603. }
  28604. get linearDamping() {
  28605. return this._linearDamping;
  28606. }
  28607. set linearDamping(value) {
  28608. this._linearDamping = value;
  28609. if (this._nativeColliderObject)
  28610. this._nativeColliderObject.setDamping(value, this._angularDamping);
  28611. }
  28612. get angularDamping() {
  28613. return this._angularDamping;
  28614. }
  28615. set angularDamping(value) {
  28616. this._angularDamping = value;
  28617. if (this._nativeColliderObject)
  28618. this._nativeColliderObject.setDamping(this._linearDamping, value);
  28619. }
  28620. get overrideGravity() {
  28621. return this._overrideGravity;
  28622. }
  28623. set overrideGravity(value) {
  28624. this._overrideGravity = value;
  28625. if (this._nativeColliderObject) {
  28626. var flag = this._nativeColliderObject.getFlags();
  28627. if (value) {
  28628. if ((flag & Rigidbody3D._BT_DISABLE_WORLD_GRAVITY) === 0)
  28629. this._nativeColliderObject.setFlags(flag | Rigidbody3D._BT_DISABLE_WORLD_GRAVITY);
  28630. }
  28631. else {
  28632. if ((flag & Rigidbody3D._BT_DISABLE_WORLD_GRAVITY) > 0)
  28633. this._nativeColliderObject.setFlags(flag ^ Rigidbody3D._BT_DISABLE_WORLD_GRAVITY);
  28634. }
  28635. }
  28636. }
  28637. get gravity() {
  28638. return this._gravity;
  28639. }
  28640. set gravity(value) {
  28641. this._gravity = value;
  28642. Rigidbody3D._nativeGravity.setValue(-value.x, value.y, value.z);
  28643. this._nativeColliderObject.setGravity(Rigidbody3D._nativeGravity);
  28644. }
  28645. get totalForce() {
  28646. if (this._nativeColliderObject) {
  28647. var nativeTotalForce = this._nativeColliderObject.getTotalForce();
  28648. Utils3D._convertToLayaVec3(nativeTotalForce, this._totalForce, true);
  28649. return this._totalForce;
  28650. }
  28651. return null;
  28652. }
  28653. get linearFactor() {
  28654. if (this._nativeColliderObject)
  28655. return this._linearFactor;
  28656. return null;
  28657. }
  28658. set linearFactor(value) {
  28659. this._linearFactor = value;
  28660. if (this._nativeColliderObject) {
  28661. var nativeValue = Rigidbody3D._nativeTempVector30;
  28662. Utils3D._convertToBulletVec3(value, nativeValue, false);
  28663. this._nativeColliderObject.setLinearFactor(nativeValue);
  28664. }
  28665. }
  28666. get linearVelocity() {
  28667. if (this._nativeColliderObject)
  28668. Utils3D._convertToLayaVec3(this._nativeColliderObject.getLinearVelocity(), this._linearVelocity, true);
  28669. return this._linearVelocity;
  28670. }
  28671. set linearVelocity(value) {
  28672. this._linearVelocity = value;
  28673. if (this._nativeColliderObject) {
  28674. var nativeValue = Rigidbody3D._nativeTempVector30;
  28675. Utils3D._convertToBulletVec3(value, nativeValue, true);
  28676. (this.isSleeping) && (this.wakeUp());
  28677. this._nativeColliderObject.setLinearVelocity(nativeValue);
  28678. }
  28679. }
  28680. get angularFactor() {
  28681. if (this._nativeColliderObject)
  28682. return this._angularFactor;
  28683. return null;
  28684. }
  28685. set angularFactor(value) {
  28686. this._angularFactor = value;
  28687. if (this._nativeColliderObject) {
  28688. var nativeValue = Rigidbody3D._nativeTempVector30;
  28689. Utils3D._convertToBulletVec3(value, nativeValue, false);
  28690. this._nativeColliderObject.setAngularFactor(nativeValue);
  28691. }
  28692. }
  28693. get angularVelocity() {
  28694. if (this._nativeColliderObject)
  28695. Utils3D._convertToLayaVec3(this._nativeColliderObject.getAngularVelocity(), this._angularVelocity, true);
  28696. return this._angularVelocity;
  28697. }
  28698. set angularVelocity(value) {
  28699. this._angularVelocity = value;
  28700. if (this._nativeColliderObject) {
  28701. var nativeValue = Rigidbody3D._nativeTempVector30;
  28702. Utils3D._convertToBulletVec3(value, nativeValue, true);
  28703. (this.isSleeping) && (this.wakeUp());
  28704. this._nativeColliderObject.setAngularVelocity(nativeValue);
  28705. }
  28706. }
  28707. get totalTorque() {
  28708. if (this._nativeColliderObject) {
  28709. var nativeTotalTorque = this._nativeColliderObject.getTotalTorque();
  28710. Utils3D._convertToLayaVec3(nativeTotalTorque, this._totalTorque, true);
  28711. return this._totalTorque;
  28712. }
  28713. return null;
  28714. }
  28715. get detectCollisions() {
  28716. return this._detectCollisions;
  28717. }
  28718. set detectCollisions(value) {
  28719. if (this._detectCollisions !== value) {
  28720. this._detectCollisions = value;
  28721. if (this._colliderShape && this._enabled && this._simulation) {
  28722. this._simulation._removeRigidBody(this);
  28723. this._simulation._addRigidBody(this, this._collisionGroup, value ? this._canCollideWith : 0);
  28724. }
  28725. }
  28726. }
  28727. get isSleeping() {
  28728. if (this._nativeColliderObject)
  28729. return this._nativeColliderObject.getActivationState() === PhysicsComponent.ACTIVATIONSTATE_ISLAND_SLEEPING;
  28730. return false;
  28731. }
  28732. get sleepLinearVelocity() {
  28733. return this._nativeColliderObject.getLinearSleepingThreshold();
  28734. }
  28735. set sleepLinearVelocity(value) {
  28736. this._nativeColliderObject.setSleepingThresholds(value, this._nativeColliderObject.getAngularSleepingThreshold());
  28737. }
  28738. get sleepAngularVelocity() {
  28739. return this._nativeColliderObject.getAngularSleepingThreshold();
  28740. }
  28741. set sleepAngularVelocity(value) {
  28742. this._nativeColliderObject.setSleepingThresholds(this._nativeColliderObject.getLinearSleepingThreshold(), value);
  28743. }
  28744. _updateMass(mass) {
  28745. if (this._nativeColliderObject && this._colliderShape) {
  28746. this._colliderShape._nativeShape.calculateLocalInertia(mass, Rigidbody3D._nativeInertia);
  28747. this._nativeColliderObject.setMassProps(mass, Rigidbody3D._nativeInertia);
  28748. this._nativeColliderObject.updateInertiaTensor();
  28749. }
  28750. }
  28751. _delegateMotionStateGetWorldTransform(worldTransPointer) {
  28752. }
  28753. _delegateMotionStateSetWorldTransform(worldTransPointer) {
  28754. var rigidBody = this._rigidbody;
  28755. rigidBody._simulation._updatedRigidbodies++;
  28756. var physics3D = Physics3D._physics3D;
  28757. var worldTrans = physics3D.wrapPointer(worldTransPointer, physics3D.btTransform);
  28758. rigidBody._updateTransformComponent(worldTrans);
  28759. }
  28760. _delegateMotionStateGetWorldTransformNative(ridgidBody3D, worldTransPointer) {
  28761. }
  28762. _delegateMotionStateSetWorldTransformNative(rigidBody3D, worldTransPointer) {
  28763. var rigidBody = rigidBody3D;
  28764. rigidBody._simulation._updatedRigidbodies++;
  28765. var physics3D = Physics3D._physics3D;
  28766. var worldTrans = physics3D.wrapPointer(worldTransPointer, physics3D.btTransform);
  28767. rigidBody._updateTransformComponent(worldTrans);
  28768. }
  28769. _onScaleChange(scale) {
  28770. super._onScaleChange(scale);
  28771. this._updateMass(this._isKinematic ? 0 : this._mass);
  28772. }
  28773. _delegateMotionStateClear() {
  28774. this._rigidbody = null;
  28775. }
  28776. _onAdded() {
  28777. var physics3D = Physics3D._physics3D;
  28778. var motionState = new physics3D.LayaMotionState();
  28779. var isConchApp = (window.conch != null);
  28780. if (isConchApp && physics3D.LayaMotionState.prototype.setRigidbody) {
  28781. motionState.setRigidbody(this);
  28782. motionState.setNativeGetWorldTransform(this._delegateMotionStateGetWorldTransformNative);
  28783. motionState.setNativeSetWorldTransform(this._delegateMotionStateSetWorldTransformNative);
  28784. }
  28785. else {
  28786. motionState.getWorldTransform = this._delegateMotionStateGetWorldTransform;
  28787. motionState.setWorldTransform = this._delegateMotionStateSetWorldTransform;
  28788. }
  28789. motionState.clear = this._delegateMotionStateClear;
  28790. motionState._rigidbody = this;
  28791. this._nativeMotionState = motionState;
  28792. var constructInfo = new physics3D.btRigidBodyConstructionInfo(0.0, motionState, null, Rigidbody3D._nativeVector3Zero);
  28793. var btRigid = new physics3D.btRigidBody(constructInfo);
  28794. btRigid.setUserIndex(this.id);
  28795. this._nativeColliderObject = btRigid;
  28796. super._onAdded();
  28797. this.mass = this._mass;
  28798. this.linearFactor = this._linearFactor;
  28799. this.angularFactor = this._angularFactor;
  28800. this.linearDamping = this._linearDamping;
  28801. this.angularDamping = this._angularDamping;
  28802. this.overrideGravity = this._overrideGravity;
  28803. this.gravity = this._gravity;
  28804. this.isKinematic = this._isKinematic;
  28805. physics3D.destroy(constructInfo);
  28806. }
  28807. _onShapeChange(colShape) {
  28808. super._onShapeChange(colShape);
  28809. if (this._isKinematic) {
  28810. this._updateMass(0);
  28811. }
  28812. else {
  28813. this._nativeColliderObject.setCenterOfMassTransform(this._nativeColliderObject.getWorldTransform());
  28814. this._updateMass(this._mass);
  28815. }
  28816. }
  28817. _parse(data) {
  28818. (data.friction != null) && (this.friction = data.friction);
  28819. (data.rollingFriction != null) && (this.rollingFriction = data.rollingFriction);
  28820. (data.restitution != null) && (this.restitution = data.restitution);
  28821. (data.isTrigger != null) && (this.isTrigger = data.isTrigger);
  28822. (data.mass != null) && (this.mass = data.mass);
  28823. (data.isKinematic != null) && (this.isKinematic = data.isKinematic);
  28824. (data.linearDamping != null) && (this.linearDamping = data.linearDamping);
  28825. (data.angularDamping != null) && (this.angularDamping = data.angularDamping);
  28826. (data.overrideGravity != null) && (this.overrideGravity = data.overrideGravity);
  28827. if (data.gravity) {
  28828. this.gravity.fromArray(data.gravity);
  28829. this.gravity = this.gravity;
  28830. }
  28831. super._parse(data);
  28832. this._parseShape(data.shapes);
  28833. }
  28834. _onDestroy() {
  28835. var physics3D = Physics3D._physics3D;
  28836. this._nativeMotionState.clear();
  28837. physics3D.destroy(this._nativeMotionState);
  28838. super._onDestroy();
  28839. this._nativeMotionState = null;
  28840. this._gravity = null;
  28841. this._totalTorque = null;
  28842. this._linearVelocity = null;
  28843. this._angularVelocity = null;
  28844. this._linearFactor = null;
  28845. this._angularFactor = null;
  28846. }
  28847. _addToSimulation() {
  28848. this._simulation._addRigidBody(this, this._collisionGroup, this._detectCollisions ? this._canCollideWith : 0);
  28849. }
  28850. _removeFromSimulation() {
  28851. this._simulation._removeRigidBody(this);
  28852. }
  28853. _cloneTo(dest) {
  28854. super._cloneTo(dest);
  28855. var destRigidbody3D = dest;
  28856. destRigidbody3D.isKinematic = this._isKinematic;
  28857. destRigidbody3D.mass = this._mass;
  28858. destRigidbody3D.gravity = this._gravity;
  28859. destRigidbody3D.angularDamping = this._angularDamping;
  28860. destRigidbody3D.linearDamping = this._linearDamping;
  28861. destRigidbody3D.overrideGravity = this._overrideGravity;
  28862. destRigidbody3D.linearVelocity = this._linearVelocity;
  28863. destRigidbody3D.angularVelocity = this._angularVelocity;
  28864. destRigidbody3D.linearFactor = this._linearFactor;
  28865. destRigidbody3D.angularFactor = this._angularFactor;
  28866. destRigidbody3D.detectCollisions = this._detectCollisions;
  28867. }
  28868. applyForce(force, localOffset = null) {
  28869. if (this._nativeColliderObject == null)
  28870. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28871. var nativeForce = Rigidbody3D._nativeTempVector30;
  28872. nativeForce.setValue(-force.x, force.y, force.z);
  28873. if (localOffset) {
  28874. var nativeOffset = Rigidbody3D._nativeTempVector31;
  28875. nativeOffset.setValue(-localOffset.x, localOffset.y, localOffset.z);
  28876. this._nativeColliderObject.applyForce(nativeForce, nativeOffset);
  28877. }
  28878. else {
  28879. this._nativeColliderObject.applyCentralForce(nativeForce);
  28880. }
  28881. }
  28882. applyTorque(torque) {
  28883. if (this._nativeColliderObject == null)
  28884. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28885. var nativeTorque = Rigidbody3D._nativeTempVector30;
  28886. nativeTorque.setValue(-torque.x, torque.y, torque.z);
  28887. this._nativeColliderObject.applyTorque(nativeTorque);
  28888. }
  28889. applyImpulse(impulse, localOffset = null) {
  28890. if (this._nativeColliderObject == null)
  28891. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28892. Rigidbody3D._nativeImpulse.setValue(-impulse.x, impulse.y, impulse.z);
  28893. if (localOffset) {
  28894. Rigidbody3D._nativeImpulseOffset.setValue(-localOffset.x, localOffset.y, localOffset.z);
  28895. this._nativeColliderObject.applyImpulse(Rigidbody3D._nativeImpulse, Rigidbody3D._nativeImpulseOffset);
  28896. }
  28897. else {
  28898. this._nativeColliderObject.applyCentralImpulse(Rigidbody3D._nativeImpulse);
  28899. }
  28900. }
  28901. applyTorqueImpulse(torqueImpulse) {
  28902. if (this._nativeColliderObject == null)
  28903. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28904. var nativeTorqueImpulse = Rigidbody3D._nativeTempVector30;
  28905. nativeTorqueImpulse.setValue(-torqueImpulse.x, torqueImpulse.y, torqueImpulse.z);
  28906. this._nativeColliderObject.applyTorqueImpulse(nativeTorqueImpulse);
  28907. }
  28908. wakeUp() {
  28909. this._nativeColliderObject && (this._nativeColliderObject.activate(false));
  28910. }
  28911. clearForces() {
  28912. var rigidBody = this._nativeColliderObject;
  28913. if (rigidBody == null)
  28914. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28915. rigidBody.clearForces();
  28916. var nativeZero = Rigidbody3D._nativeVector3Zero;
  28917. rigidBody.setInterpolationLinearVelocity(nativeZero);
  28918. rigidBody.setLinearVelocity(nativeZero);
  28919. rigidBody.setInterpolationAngularVelocity(nativeZero);
  28920. rigidBody.setAngularVelocity(nativeZero);
  28921. }
  28922. }
  28923. Rigidbody3D.TYPE_STATIC = 0;
  28924. Rigidbody3D.TYPE_DYNAMIC = 1;
  28925. Rigidbody3D.TYPE_KINEMATIC = 2;
  28926. Rigidbody3D._BT_DISABLE_WORLD_GRAVITY = 1;
  28927. Rigidbody3D._BT_ENABLE_GYROPSCOPIC_FORCE = 2;
  28928. class StaticPlaneColliderShape extends ColliderShape {
  28929. static __init__() {
  28930. StaticPlaneColliderShape._nativeNormal = new Physics3D._physics3D.btVector3(0, 0, 0);
  28931. }
  28932. constructor(normal, offset) {
  28933. super();
  28934. this._normal = normal;
  28935. this._offset = offset;
  28936. this._type = ColliderShape.SHAPETYPES_STATICPLANE;
  28937. StaticPlaneColliderShape._nativeNormal.setValue(-normal.x, normal.y, normal.z);
  28938. this._nativeShape = new Physics3D._physics3D.btStaticPlaneShape(StaticPlaneColliderShape._nativeNormal, offset);
  28939. }
  28940. clone() {
  28941. var dest = new StaticPlaneColliderShape(this._normal, this._offset);
  28942. this.cloneTo(dest);
  28943. return dest;
  28944. }
  28945. }
  28946. class PrimitiveMesh {
  28947. static __init__() {
  28948. }
  28949. static _createMesh(vertexDeclaration, vertices, indices) {
  28950. var gl = Laya.LayaGL.instance;
  28951. var mesh = new Mesh();
  28952. var subMesh = new SubMesh(mesh);
  28953. var vertexBuffer = new VertexBuffer3D(vertices.length * 4, gl.STATIC_DRAW, true);
  28954. vertexBuffer.vertexDeclaration = vertexDeclaration;
  28955. vertexBuffer.setData(vertices.buffer);
  28956. mesh._vertexBuffer = vertexBuffer;
  28957. mesh._vertexCount += vertexBuffer.vertexCount;
  28958. var indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, indices.length, gl.STATIC_DRAW, true);
  28959. indexBuffer.setData(indices);
  28960. mesh._indexBuffer = indexBuffer;
  28961. var vertexBuffers = [];
  28962. vertexBuffers[0] = vertexBuffer;
  28963. mesh._setBuffer(vertexBuffer, indexBuffer);
  28964. subMesh._vertexBuffer = vertexBuffer;
  28965. subMesh._indexBuffer = indexBuffer;
  28966. subMesh._setIndexRange(0, indexBuffer.indexCount);
  28967. var subIndexBufferStart = subMesh._subIndexBufferStart;
  28968. var subIndexBufferCount = subMesh._subIndexBufferCount;
  28969. var boneIndicesList = subMesh._boneIndicesList;
  28970. subIndexBufferStart.length = 1;
  28971. subIndexBufferCount.length = 1;
  28972. boneIndicesList.length = 1;
  28973. subIndexBufferStart[0] = 0;
  28974. subIndexBufferCount[0] = indexBuffer.indexCount;
  28975. var subMeshes = [];
  28976. subMeshes.push(subMesh);
  28977. mesh._setSubMeshes(subMeshes);
  28978. var memorySize = vertexBuffer._byteLength + indexBuffer._byteLength;
  28979. mesh._setCPUMemory(memorySize);
  28980. mesh._setGPUMemory(memorySize);
  28981. return mesh;
  28982. }
  28983. static createBox(long = 1, height = 1, width = 1) {
  28984. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  28985. var halfLong = long / 2;
  28986. var halfHeight = height / 2;
  28987. var halfWidth = width / 2;
  28988. var vertices = new Float32Array([
  28989. -halfLong, halfHeight, -halfWidth, 0, 1, 0, 0, 0, halfLong, halfHeight, -halfWidth, 0, 1, 0, 1, 0, halfLong, halfHeight, halfWidth, 0, 1, 0, 1, 1, -halfLong, halfHeight, halfWidth, 0, 1, 0, 0, 1,
  28990. -halfLong, -halfHeight, -halfWidth, 0, -1, 0, 0, 1, halfLong, -halfHeight, -halfWidth, 0, -1, 0, 1, 1, halfLong, -halfHeight, halfWidth, 0, -1, 0, 1, 0, -halfLong, -halfHeight, halfWidth, 0, -1, 0, 0, 0,
  28991. -halfLong, halfHeight, -halfWidth, -1, 0, 0, 0, 0, -halfLong, halfHeight, halfWidth, -1, 0, 0, 1, 0, -halfLong, -halfHeight, halfWidth, -1, 0, 0, 1, 1, -halfLong, -halfHeight, -halfWidth, -1, 0, 0, 0, 1,
  28992. halfLong, halfHeight, -halfWidth, 1, 0, 0, 1, 0, halfLong, halfHeight, halfWidth, 1, 0, 0, 0, 0, halfLong, -halfHeight, halfWidth, 1, 0, 0, 0, 1, halfLong, -halfHeight, -halfWidth, 1, 0, 0, 1, 1,
  28993. -halfLong, halfHeight, halfWidth, 0, 0, 1, 0, 0, halfLong, halfHeight, halfWidth, 0, 0, 1, 1, 0, halfLong, -halfHeight, halfWidth, 0, 0, 1, 1, 1, -halfLong, -halfHeight, halfWidth, 0, 0, 1, 0, 1,
  28994. -halfLong, halfHeight, -halfWidth, 0, 0, -1, 1, 0, halfLong, halfHeight, -halfWidth, 0, 0, -1, 0, 0, halfLong, -halfHeight, -halfWidth, 0, 0, -1, 0, 1, -halfLong, -halfHeight, -halfWidth, 0, 0, -1, 1, 1
  28995. ]);
  28996. var indices = new Uint16Array([
  28997. 0, 1, 2, 2, 3, 0,
  28998. 4, 7, 6, 6, 5, 4,
  28999. 8, 9, 10, 10, 11, 8,
  29000. 12, 15, 14, 14, 13, 12,
  29001. 16, 17, 18, 18, 19, 16,
  29002. 20, 23, 22, 22, 21, 20
  29003. ]);
  29004. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29005. }
  29006. static createCapsule(radius = 0.5, height = 2, stacks = 16, slices = 32) {
  29007. var vertexCount = (stacks + 1) * (slices + 1) * 2 + (slices + 1) * 2;
  29008. var indexCount = (3 * stacks * (slices + 1)) * 2 * 2 + 2 * slices * 3;
  29009. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29010. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29011. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29012. var indices = new Uint16Array(indexCount);
  29013. var stackAngle = (Math.PI / 2.0) / stacks;
  29014. var sliceAngle = (Math.PI * 2.0) / slices;
  29015. var hcHeight = height / 2 - radius;
  29016. var posX = 0;
  29017. var posY = 0;
  29018. var posZ = 0;
  29019. var vc = 0;
  29020. var ic = 0;
  29021. var verticeCount = 0;
  29022. var stack, slice;
  29023. for (stack = 0; stack <= stacks; stack++) {
  29024. for (slice = 0; slice <= slices; slice++) {
  29025. posX = radius * Math.cos(stack * stackAngle) * Math.cos(slice * sliceAngle + Math.PI);
  29026. posY = radius * Math.sin(stack * stackAngle);
  29027. posZ = radius * Math.cos(stack * stackAngle) * Math.sin(slice * sliceAngle + Math.PI);
  29028. vertices[vc++] = posX;
  29029. vertices[vc++] = posY + hcHeight;
  29030. vertices[vc++] = posZ;
  29031. vertices[vc++] = posX;
  29032. vertices[vc++] = posY;
  29033. vertices[vc++] = posZ;
  29034. vertices[vc++] = 1 - slice / slices;
  29035. vertices[vc++] = (1 - stack / stacks) * ((Math.PI * radius / 2) / (height + Math.PI * radius));
  29036. if (stack < stacks) {
  29037. indices[ic++] = (stack * (slices + 1)) + slice + (slices + 1);
  29038. indices[ic++] = (stack * (slices + 1)) + slice;
  29039. indices[ic++] = (stack * (slices + 1)) + slice + 1;
  29040. indices[ic++] = (stack * (slices + 1)) + slice + (slices);
  29041. indices[ic++] = (stack * (slices + 1)) + slice;
  29042. indices[ic++] = (stack * (slices + 1)) + slice + (slices + 1);
  29043. }
  29044. }
  29045. }
  29046. verticeCount += (stacks + 1) * (slices + 1);
  29047. for (stack = 0; stack <= stacks; stack++) {
  29048. for (slice = 0; slice <= slices; slice++) {
  29049. posX = radius * Math.cos(stack * stackAngle) * Math.cos(slice * sliceAngle + Math.PI);
  29050. posY = radius * Math.sin(-stack * stackAngle);
  29051. posZ = radius * Math.cos(stack * stackAngle) * Math.sin(slice * sliceAngle + Math.PI);
  29052. vertices[vc++] = posX;
  29053. vertices[vc++] = posY - hcHeight;
  29054. vertices[vc++] = posZ;
  29055. vertices[vc++] = posX;
  29056. vertices[vc++] = posY;
  29057. vertices[vc++] = posZ;
  29058. vertices[vc++] = 1 - slice / slices;
  29059. vertices[vc++] = ((stack / stacks) * (Math.PI * radius / 2) + (height + Math.PI * radius / 2)) / (height + Math.PI * radius);
  29060. if (stack < stacks) {
  29061. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice;
  29062. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice + (slices + 1);
  29063. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice + 1;
  29064. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice;
  29065. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice + (slices);
  29066. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice + (slices + 1);
  29067. }
  29068. }
  29069. }
  29070. verticeCount += (stacks + 1) * (slices + 1);
  29071. for (slice = 0; slice <= slices; slice++) {
  29072. posX = radius * Math.cos(slice * sliceAngle + Math.PI);
  29073. posY = hcHeight;
  29074. posZ = radius * Math.sin(slice * sliceAngle + Math.PI);
  29075. vertices[vc++] = posX;
  29076. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29077. vertices[vc++] = posY;
  29078. vertices[vc + (slices + 1) * 8 - 1] = -posY;
  29079. vertices[vc++] = posZ;
  29080. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29081. vertices[vc++] = posX;
  29082. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29083. vertices[vc++] = 0;
  29084. vertices[vc + (slices + 1) * 8 - 1] = 0;
  29085. vertices[vc++] = posZ;
  29086. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29087. vertices[vc++] = 1 - slice * 1 / slices;
  29088. vertices[vc + (slices + 1) * 8 - 1] = 1 - slice * 1 / slices;
  29089. vertices[vc++] = (Math.PI * radius / 2) / (height + Math.PI * radius);
  29090. vertices[vc + (slices + 1) * 8 - 1] = (Math.PI * radius / 2 + height) / (height + Math.PI * radius);
  29091. }
  29092. for (slice = 0; slice < slices; slice++) {
  29093. indices[ic++] = slice + verticeCount + (slices + 1);
  29094. indices[ic++] = slice + verticeCount + 1;
  29095. indices[ic++] = slice + verticeCount;
  29096. indices[ic++] = slice + verticeCount + (slices + 1);
  29097. indices[ic++] = slice + verticeCount + (slices + 1) + 1;
  29098. indices[ic++] = slice + verticeCount + 1;
  29099. }
  29100. verticeCount += 2 * (slices + 1);
  29101. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29102. }
  29103. static createCone(radius = 0.5, height = 1, slices = 32) {
  29104. var vertexCount = (slices + 1 + 1) + (slices + 1) * 2;
  29105. var indexCount = 6 * slices + 3 * slices;
  29106. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29107. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29108. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29109. var indices = new Uint16Array(indexCount);
  29110. var sliceAngle = (Math.PI * 2.0) / slices;
  29111. var halfHeight = height / 2;
  29112. var curAngle = 0;
  29113. var verticeCount = 0;
  29114. var posX = 0;
  29115. var posY = 0;
  29116. var posZ = 0;
  29117. var normal = new Vector3();
  29118. var downV3 = new Vector3(0, -1, 0);
  29119. var upPoint = new Vector3(0, halfHeight, 0);
  29120. var downPoint = new Vector3();
  29121. var v3 = new Vector3();
  29122. var q4 = new Quaternion();
  29123. var rotateAxis = new Vector3();
  29124. var rotateRadius;
  29125. var vc = 0;
  29126. var ic = 0;
  29127. for (var rv = 0; rv <= slices; rv++) {
  29128. curAngle = rv * sliceAngle;
  29129. posX = Math.cos(curAngle + Math.PI) * radius;
  29130. posY = halfHeight;
  29131. posZ = Math.sin(curAngle + Math.PI) * radius;
  29132. vertices[vc++] = 0;
  29133. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29134. vertices[vc++] = posY;
  29135. vertices[vc + (slices + 1) * 8 - 1] = -posY;
  29136. vertices[vc++] = 0;
  29137. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29138. normal.x = posX;
  29139. normal.y = 0;
  29140. normal.z = posZ;
  29141. downPoint.x = posX;
  29142. downPoint.y = -posY;
  29143. downPoint.z = posZ;
  29144. Vector3.subtract(downPoint, upPoint, v3);
  29145. Vector3.normalize(v3, v3);
  29146. rotateRadius = Math.acos(Vector3.dot(downV3, v3));
  29147. Vector3.cross(downV3, v3, rotateAxis);
  29148. Vector3.normalize(rotateAxis, rotateAxis);
  29149. Quaternion.createFromAxisAngle(rotateAxis, rotateRadius, q4);
  29150. Vector3.normalize(normal, normal);
  29151. Vector3.transformQuat(normal, q4, normal);
  29152. Vector3.normalize(normal, normal);
  29153. vertices[vc++] = normal.x;
  29154. vertices[vc + (slices + 1) * 8 - 1] = normal.x;
  29155. vertices[vc++] = normal.y;
  29156. vertices[vc + (slices + 1) * 8 - 1] = normal.y;
  29157. vertices[vc++] = normal.z;
  29158. vertices[vc + (slices + 1) * 8 - 1] = normal.z;
  29159. vertices[vc++] = 1 - rv * 1 / slices;
  29160. vertices[vc + (slices + 1) * 8 - 1] = 1 - rv * 1 / slices;
  29161. vertices[vc++] = 0;
  29162. vertices[vc + (slices + 1) * 8 - 1] = 1;
  29163. }
  29164. vc += (slices + 1) * 8;
  29165. for (var ri = 0; ri < slices; ri++) {
  29166. indices[ic++] = ri + verticeCount + (slices + 1);
  29167. indices[ic++] = ri + verticeCount + 1;
  29168. indices[ic++] = ri + verticeCount;
  29169. indices[ic++] = ri + verticeCount + (slices + 1);
  29170. indices[ic++] = ri + verticeCount + (slices + 1) + 1;
  29171. indices[ic++] = ri + verticeCount + 1;
  29172. }
  29173. verticeCount += 2 * (slices + 1);
  29174. for (var bv = 0; bv <= slices; bv++) {
  29175. if (bv === 0) {
  29176. vertices[vc++] = 0;
  29177. vertices[vc++] = -halfHeight;
  29178. vertices[vc++] = 0;
  29179. vertices[vc++] = 0;
  29180. vertices[vc++] = -1;
  29181. vertices[vc++] = 0;
  29182. vertices[vc++] = 0.5;
  29183. vertices[vc++] = 0.5;
  29184. }
  29185. curAngle = bv * sliceAngle;
  29186. posX = Math.cos(curAngle + Math.PI) * radius;
  29187. posY = -halfHeight;
  29188. posZ = Math.sin(curAngle + Math.PI) * radius;
  29189. vertices[vc++] = posX;
  29190. vertices[vc++] = posY;
  29191. vertices[vc++] = posZ;
  29192. vertices[vc++] = 0;
  29193. vertices[vc++] = -1;
  29194. vertices[vc++] = 0;
  29195. vertices[vc++] = 0.5 + Math.cos(curAngle) * 0.5;
  29196. vertices[vc++] = 0.5 + Math.sin(curAngle) * 0.5;
  29197. }
  29198. for (var bi = 0; bi < slices; bi++) {
  29199. indices[ic++] = 0 + verticeCount;
  29200. indices[ic++] = bi + 2 + verticeCount;
  29201. indices[ic++] = bi + 1 + verticeCount;
  29202. }
  29203. verticeCount += slices + 1 + 1;
  29204. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29205. }
  29206. static createCylinder(radius = 0.5, height = 2, slices = 32) {
  29207. var vertexCount = (slices + 1 + 1) + (slices + 1) * 2 + (slices + 1 + 1);
  29208. var indexCount = 3 * slices + 6 * slices + 3 * slices;
  29209. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29210. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29211. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29212. var indices = new Uint16Array(indexCount);
  29213. var sliceAngle = (Math.PI * 2.0) / slices;
  29214. var halfHeight = height / 2;
  29215. var curAngle = 0;
  29216. var verticeCount = 0;
  29217. var posX = 0;
  29218. var posY = 0;
  29219. var posZ = 0;
  29220. var vc = 0;
  29221. var ic = 0;
  29222. for (var tv = 0; tv <= slices; tv++) {
  29223. if (tv === 0) {
  29224. vertices[vc++] = 0;
  29225. vertices[vc++] = halfHeight;
  29226. vertices[vc++] = 0;
  29227. vertices[vc++] = 0;
  29228. vertices[vc++] = 1;
  29229. vertices[vc++] = 0;
  29230. vertices[vc++] = 0.5;
  29231. vertices[vc++] = 0.5;
  29232. }
  29233. curAngle = tv * sliceAngle;
  29234. posX = Math.cos(curAngle) * radius;
  29235. posY = halfHeight;
  29236. posZ = Math.sin(curAngle) * radius;
  29237. vertices[vc++] = posX;
  29238. vertices[vc++] = posY;
  29239. vertices[vc++] = posZ;
  29240. vertices[vc++] = 0;
  29241. vertices[vc++] = 1;
  29242. vertices[vc++] = 0;
  29243. vertices[vc++] = 0.5 + Math.cos(curAngle) * 0.5;
  29244. vertices[vc++] = 0.5 + Math.sin(curAngle) * 0.5;
  29245. }
  29246. for (var ti = 0; ti < slices; ti++) {
  29247. indices[ic++] = 0;
  29248. indices[ic++] = ti + 1;
  29249. indices[ic++] = ti + 2;
  29250. }
  29251. verticeCount += slices + 1 + 1;
  29252. for (var rv = 0; rv <= slices; rv++) {
  29253. curAngle = rv * sliceAngle;
  29254. posX = Math.cos(curAngle + Math.PI) * radius;
  29255. posY = halfHeight;
  29256. posZ = Math.sin(curAngle + Math.PI) * radius;
  29257. vertices[vc++] = posX;
  29258. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29259. vertices[vc++] = posY;
  29260. vertices[vc + (slices + 1) * 8 - 1] = -posY;
  29261. vertices[vc++] = posZ;
  29262. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29263. vertices[vc++] = posX;
  29264. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29265. vertices[vc++] = 0;
  29266. vertices[vc + (slices + 1) * 8 - 1] = 0;
  29267. vertices[vc++] = posZ;
  29268. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29269. vertices[vc++] = 1 - rv * 1 / slices;
  29270. vertices[vc + (slices + 1) * 8 - 1] = 1 - rv * 1 / slices;
  29271. vertices[vc++] = 0;
  29272. vertices[vc + (slices + 1) * 8 - 1] = 1;
  29273. }
  29274. vc += (slices + 1) * 8;
  29275. for (var ri = 0; ri < slices; ri++) {
  29276. indices[ic++] = ri + verticeCount + (slices + 1);
  29277. indices[ic++] = ri + verticeCount + 1;
  29278. indices[ic++] = ri + verticeCount;
  29279. indices[ic++] = ri + verticeCount + (slices + 1);
  29280. indices[ic++] = ri + verticeCount + (slices + 1) + 1;
  29281. indices[ic++] = ri + verticeCount + 1;
  29282. }
  29283. verticeCount += 2 * (slices + 1);
  29284. for (var bv = 0; bv <= slices; bv++) {
  29285. if (bv === 0) {
  29286. vertices[vc++] = 0;
  29287. vertices[vc++] = -halfHeight;
  29288. vertices[vc++] = 0;
  29289. vertices[vc++] = 0;
  29290. vertices[vc++] = -1;
  29291. vertices[vc++] = 0;
  29292. vertices[vc++] = 0.5;
  29293. vertices[vc++] = 0.5;
  29294. }
  29295. curAngle = bv * sliceAngle;
  29296. posX = Math.cos(curAngle + Math.PI) * radius;
  29297. posY = -halfHeight;
  29298. posZ = Math.sin(curAngle + Math.PI) * radius;
  29299. vertices[vc++] = posX;
  29300. vertices[vc++] = posY;
  29301. vertices[vc++] = posZ;
  29302. vertices[vc++] = 0;
  29303. vertices[vc++] = -1;
  29304. vertices[vc++] = 0;
  29305. vertices[vc++] = 0.5 + Math.cos(curAngle) * 0.5;
  29306. vertices[vc++] = 0.5 + Math.sin(curAngle) * 0.5;
  29307. }
  29308. for (var bi = 0; bi < slices; bi++) {
  29309. indices[ic++] = 0 + verticeCount;
  29310. indices[ic++] = bi + 2 + verticeCount;
  29311. indices[ic++] = bi + 1 + verticeCount;
  29312. }
  29313. verticeCount += slices + 1 + 1;
  29314. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29315. }
  29316. static createPlane(long = 10, width = 10, stacks = 10, slices = 10) {
  29317. var vertexCount = (stacks + 1) * (slices + 1);
  29318. var indexCount = stacks * slices * 2 * 3;
  29319. var indices = new Uint16Array(indexCount);
  29320. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29321. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29322. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29323. var halfLong = long / 2;
  29324. var halfWidth = width / 2;
  29325. var stacksLong = long / stacks;
  29326. var slicesWidth = width / slices;
  29327. var verticeCount = 0;
  29328. for (var i = 0; i <= slices; i++) {
  29329. for (var j = 0; j <= stacks; j++) {
  29330. vertices[verticeCount++] = j * stacksLong - halfLong;
  29331. vertices[verticeCount++] = 0;
  29332. vertices[verticeCount++] = i * slicesWidth - halfWidth;
  29333. vertices[verticeCount++] = 0;
  29334. vertices[verticeCount++] = 1;
  29335. vertices[verticeCount++] = 0;
  29336. vertices[verticeCount++] = j * 1 / stacks;
  29337. vertices[verticeCount++] = i * 1 / slices;
  29338. }
  29339. }
  29340. var indiceIndex = 0;
  29341. for (i = 0; i < slices; i++) {
  29342. for (j = 0; j < stacks; j++) {
  29343. indices[indiceIndex++] = (i + 1) * (stacks + 1) + j;
  29344. indices[indiceIndex++] = i * (stacks + 1) + j;
  29345. indices[indiceIndex++] = (i + 1) * (stacks + 1) + j + 1;
  29346. indices[indiceIndex++] = i * (stacks + 1) + j;
  29347. indices[indiceIndex++] = i * (stacks + 1) + j + 1;
  29348. indices[indiceIndex++] = (i + 1) * (stacks + 1) + j + 1;
  29349. }
  29350. }
  29351. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29352. }
  29353. static createQuad(long = 1, width = 1) {
  29354. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29355. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29356. var halfLong = long / 2;
  29357. var halfWidth = width / 2;
  29358. var vertices = new Float32Array([halfLong, halfWidth, 0, 0, 0, 1, 0, 0, halfLong, halfWidth, 0, 0, 0, 1, 1, 0, -halfLong, -halfWidth, 0, 0, 0, 1, 0, 1, halfLong, -halfWidth, 0, 0, 0, 1, 1, 1]);
  29359. var indices = new Uint16Array([0, 1, 2, 3, 2, 1]);
  29360. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29361. }
  29362. static createSphere(radius = 0.5, stacks = 32, slices = 32) {
  29363. var vertexCount = (stacks + 1) * (slices + 1);
  29364. var indexCount = (3 * stacks * (slices + 1)) * 2;
  29365. var indices = new Uint16Array(indexCount);
  29366. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29367. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29368. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29369. var stackAngle = Math.PI / stacks;
  29370. var sliceAngle = (Math.PI * 2.0) / slices;
  29371. var vertexIndex = 0;
  29372. vertexCount = 0;
  29373. indexCount = 0;
  29374. for (var stack = 0; stack < (stacks + 1); stack++) {
  29375. var r = Math.sin(stack * stackAngle);
  29376. var y = Math.cos(stack * stackAngle);
  29377. for (var slice = 0; slice < (slices + 1); slice++) {
  29378. var x = r * Math.sin(slice * sliceAngle + Math.PI * 1 / 2);
  29379. var z = r * Math.cos(slice * sliceAngle + Math.PI * 1 / 2);
  29380. vertices[vertexCount + 0] = x * radius;
  29381. vertices[vertexCount + 1] = y * radius;
  29382. vertices[vertexCount + 2] = z * radius;
  29383. vertices[vertexCount + 3] = x;
  29384. vertices[vertexCount + 4] = y;
  29385. vertices[vertexCount + 5] = z;
  29386. vertices[vertexCount + 6] = slice / slices;
  29387. vertices[vertexCount + 7] = stack / stacks;
  29388. vertexCount += vertexFloatStride;
  29389. if (stack != (stacks - 1)) {
  29390. indices[indexCount++] = vertexIndex + (slices + 1);
  29391. indices[indexCount++] = vertexIndex;
  29392. indices[indexCount++] = vertexIndex + 1;
  29393. indices[indexCount++] = vertexIndex + (slices);
  29394. indices[indexCount++] = vertexIndex;
  29395. indices[indexCount++] = vertexIndex + (slices + 1);
  29396. vertexIndex++;
  29397. }
  29398. }
  29399. }
  29400. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29401. }
  29402. }
  29403. class VertexPositionTerrain {
  29404. constructor(position, normal, textureCoord0, textureCoord1) {
  29405. this._position = position;
  29406. this._normal = normal;
  29407. this._textureCoord0 = textureCoord0;
  29408. this._textureCoord1 = textureCoord1;
  29409. }
  29410. static __init__() {
  29411. VertexPositionTerrain._vertexDeclaration = new VertexDeclaration(40, [new VertexElement(0, VertexElementFormat.Vector3, VertexPositionTerrain.TERRAIN_POSITION0),
  29412. new VertexElement(12, VertexElementFormat.Vector3, VertexPositionTerrain.TERRAIN_NORMAL0),
  29413. new VertexElement(24, VertexElementFormat.Vector2, VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE0),
  29414. new VertexElement(32, VertexElementFormat.Vector2, VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE1)]);
  29415. }
  29416. static get vertexDeclaration() {
  29417. return VertexPositionTerrain._vertexDeclaration;
  29418. }
  29419. get position() {
  29420. return this._position;
  29421. }
  29422. get normal() {
  29423. return this._normal;
  29424. }
  29425. get textureCoord0() {
  29426. return this._textureCoord0;
  29427. }
  29428. get textureCoord1() {
  29429. return this._textureCoord1;
  29430. }
  29431. get vertexDeclaration() {
  29432. return VertexPositionTerrain._vertexDeclaration;
  29433. }
  29434. }
  29435. VertexPositionTerrain.TERRAIN_POSITION0 = 0;
  29436. VertexPositionTerrain.TERRAIN_NORMAL0 = 1;
  29437. VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE0 = 2;
  29438. VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE1 = 3;
  29439. class Laya3D {
  29440. constructor() {
  29441. }
  29442. static get enbalePhysics() {
  29443. return Physics3D._enbalePhysics;
  29444. }
  29445. static _cancelLoadByUrl(url) {
  29446. Laya.Laya.loader.cancelLoadByUrl(url);
  29447. Laya3D._innerFirstLevelLoaderManager.cancelLoadByUrl(url);
  29448. Laya3D._innerSecondLevelLoaderManager.cancelLoadByUrl(url);
  29449. Laya3D._innerThirdLevelLoaderManager.cancelLoadByUrl(url);
  29450. Laya3D._innerFourthLevelLoaderManager.cancelLoadByUrl(url);
  29451. }
  29452. static _changeWebGLSize(width, height) {
  29453. Laya.WebGL.onStageResize(width, height);
  29454. RenderContext3D.clientWidth = width;
  29455. RenderContext3D.clientHeight = height;
  29456. }
  29457. static __init__(width, height, config) {
  29458. Laya.Config.isAntialias = config.isAntialias;
  29459. Laya.Config.isAlpha = config.isAlpha;
  29460. Laya.Config.premultipliedAlpha = config.premultipliedAlpha;
  29461. Laya.Config.isStencil = config.isStencil;
  29462. if (!Laya.WebGL.enable()) {
  29463. alert("Laya3D init error,must support webGL!");
  29464. return;
  29465. }
  29466. Laya.RunDriver.changeWebGLSize = Laya3D._changeWebGLSize;
  29467. Laya.Render.is3DMode = true;
  29468. Laya.Laya.init(width, height);
  29469. if (!Laya.Render.supportWebGLPlusRendering) {
  29470. Laya.LayaGL.instance = Laya.WebGLContext.mainContext;
  29471. Laya.LayaGL.instance.createCommandEncoder = function (reserveSize = 128, adjustSize = 64, isSyncToRenderThread = false) {
  29472. return new Laya.CommandEncoder(this, reserveSize, adjustSize, isSyncToRenderThread);
  29473. };
  29474. }
  29475. ILaya3D.Scene3D = Scene3D;
  29476. ILaya3D.MeshRenderStaticBatchManager = MeshRenderStaticBatchManager;
  29477. ILaya3D.MeshRenderDynamicBatchManager = MeshRenderDynamicBatchManager;
  29478. ILaya3D.SubMeshDynamicBatch = SubMeshDynamicBatch;
  29479. ILaya3D.Laya3D = Laya3D;
  29480. ILaya3D.Matrix4x4 = Matrix4x4;
  29481. Laya3D.enableNative3D();
  29482. VertexElementFormat.__init__();
  29483. VertexMesh.__init__();
  29484. VertexShurikenParticleBillboard.__init__();
  29485. VertexShurikenParticleMesh.__init__();
  29486. VertexPositionTexture0.__init__();
  29487. VertexTrail.__init__();
  29488. VertexPositionTerrain.__init__();
  29489. PixelLineVertex.__init__();
  29490. SubMeshInstanceBatch.__init__();
  29491. SubMeshDynamicBatch.__init__();
  29492. Physics3D._physics3D = window.Physics3D;
  29493. if (Physics3D._physics3D) {
  29494. StaticPlaneColliderShape.__init__();
  29495. ColliderShape.__init__();
  29496. CompoundColliderShape.__init__();
  29497. PhysicsComponent.__init__();
  29498. PhysicsSimulation.__init__();
  29499. BoxColliderShape.__init__();
  29500. CylinderColliderShape.__init__();
  29501. CharacterController.__init__();
  29502. Rigidbody3D.__init__();
  29503. }
  29504. Mesh.__init__();
  29505. PrimitiveMesh.__init__();
  29506. Sprite3D.__init__();
  29507. RenderableSprite3D.__init__();
  29508. MeshSprite3D.__init__();
  29509. SkinnedMeshSprite3D.__init__();
  29510. ShuriKenParticle3D.__init__();
  29511. TrailSprite3D.__init__();
  29512. PostProcess.__init__();
  29513. Scene3D.__init__();
  29514. MeshRenderStaticBatchManager.__init__();
  29515. BaseMaterial.__initDefine__();
  29516. BlinnPhongMaterial.__initDefine__();
  29517. PBRStandardMaterial.__initDefine__();
  29518. PBRSpecularMaterial.__initDefine__();
  29519. SkyProceduralMaterial.__initDefine__();
  29520. UnlitMaterial.__initDefine__();
  29521. TrailMaterial.__initDefine__();
  29522. EffectMaterial.__initDefine__();
  29523. WaterPrimaryMaterial.__initDefine__();
  29524. ShurikenParticleMaterial.__initDefine__();
  29525. ExtendTerrainMaterial.__initDefine__();
  29526. PixelLineMaterial.__initDefine__();
  29527. SkyBoxMaterial.__initDefine__();
  29528. ShaderInit3D.__init__();
  29529. Command.__init__();
  29530. Laya.ClassUtils.regClass("Laya.EffectMaterial", EffectMaterial);
  29531. Laya.ClassUtils.regClass("Laya.UnlitMaterial", UnlitMaterial);
  29532. Laya.ClassUtils.regClass("Laya.BlinnPhongMaterial", BlinnPhongMaterial);
  29533. Laya.ClassUtils.regClass("Laya.SkyProceduralMaterial", SkyProceduralMaterial);
  29534. Laya.ClassUtils.regClass("Laya.PBRStandardMaterial", PBRStandardMaterial);
  29535. Laya.ClassUtils.regClass("Laya.PBRSpecularMaterial", PBRSpecularMaterial);
  29536. Laya.ClassUtils.regClass("Laya.SkyBoxMaterial", SkyBoxMaterial);
  29537. Laya.ClassUtils.regClass("Laya.WaterPrimaryMaterial", WaterPrimaryMaterial);
  29538. Laya.ClassUtils.regClass("Laya.ExtendTerrainMaterial", ExtendTerrainMaterial);
  29539. Laya.ClassUtils.regClass("Laya.ShurikenParticleMaterial", ShurikenParticleMaterial);
  29540. Laya.ClassUtils.regClass("Laya.TrailMaterial", TrailMaterial);
  29541. Laya.ClassUtils.regClass("Laya.PhysicsCollider", PhysicsCollider);
  29542. Laya.ClassUtils.regClass("Laya.Rigidbody3D", Rigidbody3D);
  29543. Laya.ClassUtils.regClass("Laya.CharacterController", CharacterController);
  29544. Laya.ClassUtils.regClass("Laya.Animator", Animator);
  29545. Laya.ClassUtils.regClass("PhysicsCollider", PhysicsCollider);
  29546. Laya.ClassUtils.regClass("CharacterController", CharacterController);
  29547. Laya.ClassUtils.regClass("Animator", Animator);
  29548. Laya.ClassUtils.regClass("Rigidbody3D", Rigidbody3D);
  29549. PixelLineMaterial.defaultMaterial = new PixelLineMaterial();
  29550. BlinnPhongMaterial.defaultMaterial = new BlinnPhongMaterial();
  29551. EffectMaterial.defaultMaterial = new EffectMaterial();
  29552. PBRStandardMaterial.defaultMaterial = new PBRStandardMaterial();
  29553. PBRSpecularMaterial.defaultMaterial = new PBRSpecularMaterial();
  29554. UnlitMaterial.defaultMaterial = new UnlitMaterial();
  29555. ShurikenParticleMaterial.defaultMaterial = new ShurikenParticleMaterial();
  29556. TrailMaterial.defaultMaterial = new TrailMaterial();
  29557. SkyProceduralMaterial.defaultMaterial = new SkyProceduralMaterial();
  29558. SkyBoxMaterial.defaultMaterial = new SkyBoxMaterial();
  29559. WaterPrimaryMaterial.defaultMaterial = new WaterPrimaryMaterial();
  29560. PixelLineMaterial.defaultMaterial.lock = true;
  29561. BlinnPhongMaterial.defaultMaterial.lock = true;
  29562. EffectMaterial.defaultMaterial.lock = true;
  29563. PBRStandardMaterial.defaultMaterial.lock = true;
  29564. PBRSpecularMaterial.defaultMaterial.lock = true;
  29565. UnlitMaterial.defaultMaterial.lock = true;
  29566. ShurikenParticleMaterial.defaultMaterial.lock = true;
  29567. TrailMaterial.defaultMaterial.lock = true;
  29568. SkyProceduralMaterial.defaultMaterial.lock = true;
  29569. SkyBoxMaterial.defaultMaterial.lock = true;
  29570. WaterPrimaryMaterial.defaultMaterial.lock = true;
  29571. Laya.Texture2D.__init__();
  29572. TextureCube.__init__();
  29573. SkyBox.__init__();
  29574. SkyDome.__init__();
  29575. ScreenQuad.__init__();
  29576. ScreenTriangle.__init__();
  29577. FrustumCulling.__init__();
  29578. HalfFloatUtils.__init__();
  29579. var createMap = Laya.LoaderManager.createMap;
  29580. createMap["lh"] = [Laya3D.HIERARCHY, Scene3DUtils._parse];
  29581. createMap["ls"] = [Laya3D.HIERARCHY, Scene3DUtils._parseScene];
  29582. createMap["lm"] = [Laya3D.MESH, Mesh._parse];
  29583. createMap["lmat"] = [Laya3D.MATERIAL, BaseMaterial._parse];
  29584. createMap["ltc"] = [Laya3D.TEXTURECUBE, TextureCube._parse];
  29585. createMap["jpg"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29586. createMap["jpeg"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29587. createMap["bmp"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29588. createMap["gif"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29589. createMap["png"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29590. createMap["dds"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29591. createMap["ktx"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29592. createMap["pvr"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29593. createMap["lani"] = [Laya3D.ANIMATIONCLIP, AnimationClip._parse];
  29594. createMap["lav"] = [Laya3D.AVATAR, Avatar._parse];
  29595. var parserMap = Laya.Loader.parserMap;
  29596. parserMap[Laya3D.HIERARCHY] = Laya3D._loadHierarchy;
  29597. parserMap[Laya3D.MESH] = Laya3D._loadMesh;
  29598. parserMap[Laya3D.MATERIAL] = Laya3D._loadMaterial;
  29599. parserMap[Laya3D.TEXTURECUBE] = Laya3D._loadTextureCube;
  29600. parserMap[Laya3D.TEXTURE2D] = Laya3D._loadTexture2D;
  29601. parserMap[Laya3D.ANIMATIONCLIP] = Laya3D._loadAnimationClip;
  29602. parserMap[Laya3D.AVATAR] = Laya3D._loadAvatar;
  29603. Laya3D._innerFirstLevelLoaderManager.on(Laya.Event.ERROR, null, Laya3D._eventLoadManagerError);
  29604. Laya3D._innerSecondLevelLoaderManager.on(Laya.Event.ERROR, null, Laya3D._eventLoadManagerError);
  29605. Laya3D._innerThirdLevelLoaderManager.on(Laya.Event.ERROR, null, Laya3D._eventLoadManagerError);
  29606. Laya3D._innerFourthLevelLoaderManager.on(Laya.Event.ERROR, null, Laya3D._eventLoadManagerError);
  29607. }
  29608. static enableNative3D() {
  29609. var shaderData = ShaderData;
  29610. var shader3D = ShaderInstance;
  29611. var skinnedMeshRender = SkinnedMeshRenderer;
  29612. var avatar = Avatar;
  29613. var frustumCulling = FrustumCulling;
  29614. if (Laya.Render.supportWebGLPlusRendering) {
  29615. shaderData.prototype._initData = shaderData.prototype._initDataForNative;
  29616. shaderData.prototype.setBool = shaderData.prototype.setBoolForNative;
  29617. shaderData.prototype.getBool = shaderData.prototype.getBoolForNative;
  29618. shaderData.prototype.setInt = shaderData.prototype.setIntForNative;
  29619. shaderData.prototype.getInt = shaderData.prototype.getIntForNative;
  29620. shaderData.prototype.setNumber = shaderData.prototype.setNumberForNative;
  29621. shaderData.prototype.getNumber = shaderData.prototype.getNumberForNative;
  29622. shaderData.prototype.setVector = shaderData.prototype.setVectorForNative;
  29623. shaderData.prototype.getVector = shaderData.prototype.getVectorForNative;
  29624. shaderData.prototype.setVector2 = shaderData.prototype.setVector2ForNative;
  29625. shaderData.prototype.getVector2 = shaderData.prototype.getVector2ForNative;
  29626. shaderData.prototype.setVector3 = shaderData.prototype.setVector3ForNative;
  29627. shaderData.prototype.getVector3 = shaderData.prototype.getVector3ForNative;
  29628. shaderData.prototype.setQuaternion = shaderData.prototype.setQuaternionForNative;
  29629. shaderData.prototype.getQuaternion = shaderData.prototype.getQuaternionForNative;
  29630. shaderData.prototype.setMatrix4x4 = shaderData.prototype.setMatrix4x4ForNative;
  29631. shaderData.prototype.getMatrix4x4 = shaderData.prototype.getMatrix4x4ForNative;
  29632. shaderData.prototype.setBuffer = shaderData.prototype.setBufferForNative;
  29633. shaderData.prototype.getBuffer = shaderData.prototype.getBufferForNative;
  29634. shaderData.prototype.setTexture = shaderData.prototype.setTextureForNative;
  29635. shaderData.prototype.getTexture = shaderData.prototype.getTextureForNative;
  29636. shaderData.prototype.setAttribute = shaderData.prototype.setAttributeForNative;
  29637. shaderData.prototype.getAttribute = shaderData.prototype.getAttributeForNative;
  29638. shaderData.prototype.cloneTo = shaderData.prototype.cloneToForNative;
  29639. shaderData.prototype.getData = shaderData.prototype.getDataForNative;
  29640. shader3D.prototype._uniformMatrix2fv = shader3D.prototype._uniformMatrix2fvForNative;
  29641. shader3D.prototype._uniformMatrix3fv = shader3D.prototype._uniformMatrix3fvForNative;
  29642. shader3D.prototype._uniformMatrix4fv = shader3D.prototype._uniformMatrix4fvForNative;
  29643. Laya.LayaGLRunner.uploadShaderUniforms = Laya.LayaGLRunner.uploadShaderUniformsForNative;
  29644. }
  29645. if (Laya.Render.supportWebGLPlusCulling) {
  29646. frustumCulling.renderObjectCulling = FrustumCulling.renderObjectCullingNative;
  29647. }
  29648. if (Laya.Render.supportWebGLPlusAnimation) {
  29649. avatar.prototype._cloneDatasToAnimator = avatar.prototype._cloneDatasToAnimatorNative;
  29650. var animationClip = AnimationClip;
  29651. animationClip.prototype._evaluateClipDatasRealTime = animationClip.prototype._evaluateClipDatasRealTimeForNative;
  29652. skinnedMeshRender.prototype._computeSkinnedData = skinnedMeshRender.prototype._computeSkinnedDataForNative;
  29653. }
  29654. if (Laya.Render.isConchApp) {
  29655. Laya.WebGL.shaderHighPrecision = false;
  29656. var gl = Laya.LayaGL.instance;
  29657. var precisionFormat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
  29658. precisionFormat.precision ? Laya.WebGL.shaderHighPrecision = true : Laya.WebGL.shaderHighPrecision = false;
  29659. }
  29660. }
  29661. static formatRelativePath(base, value) {
  29662. var path;
  29663. path = base + value;
  29664. var char1 = value.charAt(0);
  29665. if (char1 === ".") {
  29666. var parts = path.split("/");
  29667. for (var i = 0, len = parts.length; i < len; i++) {
  29668. if (parts[i] == '..') {
  29669. var index = i - 1;
  29670. if (index > 0 && parts[index] !== '..') {
  29671. parts.splice(index, 2);
  29672. i -= 2;
  29673. }
  29674. }
  29675. }
  29676. path = parts.join('/');
  29677. }
  29678. return path;
  29679. }
  29680. static _endLoad(loader, content = null, subResous = null) {
  29681. if (subResous) {
  29682. for (var i = 0, n = subResous.length; i < n; i++) {
  29683. var resou = Laya.Loader.getRes(subResous[i]);
  29684. (resou) && (resou._removeReference());
  29685. }
  29686. }
  29687. loader.endLoad(content);
  29688. }
  29689. static _eventLoadManagerError(msg) {
  29690. Laya.Laya.loader.event(Laya.Event.ERROR, msg);
  29691. }
  29692. static _addHierarchyInnerUrls(urls, urlMap, urlVersion, hierarchyBasePath, path, type, constructParams = null, propertyParams = null) {
  29693. var formatUrl = Laya3D.formatRelativePath(hierarchyBasePath, path);
  29694. (urlVersion) && (formatUrl = formatUrl + urlVersion);
  29695. urls.push({ url: formatUrl, type: type, constructParams: constructParams, propertyParams: propertyParams });
  29696. urlMap.push(formatUrl);
  29697. return formatUrl;
  29698. }
  29699. static _getSprite3DHierarchyInnerUrls(node, firstLevelUrls, secondLevelUrls, thirdLevelUrls, fourthLelUrls, subUrls, urlVersion, hierarchyBasePath) {
  29700. var i, n;
  29701. var props = node.props;
  29702. switch (node.type) {
  29703. case "Scene3D":
  29704. var lightmaps = props.lightmaps;
  29705. for (i = 0, n = lightmaps.length; i < n; i++) {
  29706. var lightMap = lightmaps[i];
  29707. lightMap.path = Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, lightMap.path, Laya3D.TEXTURE2D, lightMap.constructParams, lightMap.propertyParams);
  29708. }
  29709. var reflectionTextureData = props.reflectionTexture;
  29710. (reflectionTextureData) && (props.reflectionTexture = Laya3D._addHierarchyInnerUrls(thirdLevelUrls, subUrls, urlVersion, hierarchyBasePath, reflectionTextureData, Laya3D.TEXTURECUBE));
  29711. if (props.sky) {
  29712. var skyboxMaterial = props.sky.material;
  29713. (skyboxMaterial) && (skyboxMaterial.path = Laya3D._addHierarchyInnerUrls(secondLevelUrls, subUrls, urlVersion, hierarchyBasePath, skyboxMaterial.path, Laya3D.MATERIAL));
  29714. }
  29715. break;
  29716. case "Camera":
  29717. var skyboxMatData = props.skyboxMaterial;
  29718. (skyboxMatData) && (skyboxMatData.path = Laya3D._addHierarchyInnerUrls(secondLevelUrls, subUrls, urlVersion, hierarchyBasePath, skyboxMatData.path, Laya3D.MATERIAL));
  29719. break;
  29720. case "TrailSprite3D":
  29721. case "MeshSprite3D":
  29722. case "SkinnedMeshSprite3D":
  29723. var meshPath = props.meshPath;
  29724. (meshPath) && (props.meshPath = Laya3D._addHierarchyInnerUrls(firstLevelUrls, subUrls, urlVersion, hierarchyBasePath, meshPath, Laya3D.MESH));
  29725. var materials = props.materials;
  29726. if (materials)
  29727. for (i = 0, n = materials.length; i < n; i++)
  29728. materials[i].path = Laya3D._addHierarchyInnerUrls(secondLevelUrls, subUrls, urlVersion, hierarchyBasePath, materials[i].path, Laya3D.MATERIAL);
  29729. break;
  29730. case "ShuriKenParticle3D":
  29731. var parMeshPath = props.meshPath;
  29732. (parMeshPath) && (props.meshPath = Laya3D._addHierarchyInnerUrls(firstLevelUrls, subUrls, urlVersion, hierarchyBasePath, parMeshPath, Laya3D.MESH));
  29733. props.material.path = Laya3D._addHierarchyInnerUrls(secondLevelUrls, subUrls, urlVersion, hierarchyBasePath, props.material.path, Laya3D.MATERIAL);
  29734. break;
  29735. case "Terrain":
  29736. Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, props.dataPath, Laya3D.TERRAINRES);
  29737. break;
  29738. }
  29739. var components = node.components;
  29740. if (components) {
  29741. for (var k = 0, p = components.length; k < p; k++) {
  29742. var component = components[k];
  29743. switch (component.type) {
  29744. case "Animator":
  29745. var avatarPath = component.avatarPath;
  29746. var avatarData = component.avatar;
  29747. (avatarData) && (avatarData.path = Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, avatarData.path, Laya3D.AVATAR));
  29748. var clipPaths = component.clipPaths;
  29749. if (!clipPaths) {
  29750. var layersData = component.layers;
  29751. for (i = 0; i < layersData.length; i++) {
  29752. var states = layersData[i].states;
  29753. for (var j = 0, m = states.length; j < m; j++) {
  29754. var clipPath = states[j].clipPath;
  29755. (clipPath) && (states[j].clipPath = Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, clipPath, Laya3D.ANIMATIONCLIP));
  29756. }
  29757. }
  29758. }
  29759. else {
  29760. for (i = 0, n = clipPaths.length; i < n; i++)
  29761. clipPaths[i] = Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, clipPaths[i], Laya3D.ANIMATIONCLIP);
  29762. }
  29763. break;
  29764. case "PhysicsCollider":
  29765. case "Rigidbody3D":
  29766. case "CharacterController":
  29767. var shapes = component.shapes;
  29768. for (i = 0; i < shapes.length; i++) {
  29769. var shape = shapes[i];
  29770. if (shape.type === "MeshColliderShape") {
  29771. var mesh = shape.mesh;
  29772. (mesh) && (shape.mesh = Laya3D._addHierarchyInnerUrls(firstLevelUrls, subUrls, urlVersion, hierarchyBasePath, mesh, Laya3D.MESH));
  29773. }
  29774. }
  29775. break;
  29776. }
  29777. }
  29778. }
  29779. var children = node.child;
  29780. for (i = 0, n = children.length; i < n; i++)
  29781. Laya3D._getSprite3DHierarchyInnerUrls(children[i], firstLevelUrls, secondLevelUrls, thirdLevelUrls, fourthLelUrls, subUrls, urlVersion, hierarchyBasePath);
  29782. }
  29783. static _loadHierarchy(loader) {
  29784. loader.on(Laya.Event.LOADED, null, Laya3D._onHierarchylhLoaded, [loader]);
  29785. loader.load(loader.url, Laya.Loader.JSON, false, null, true);
  29786. }
  29787. static _onHierarchylhLoaded(loader, lhData) {
  29788. var url = loader.url;
  29789. var urlVersion = Utils3D.getURLVerion(url);
  29790. var hierarchyBasePath = Laya.URL.getPath(url);
  29791. var firstLevUrls = [];
  29792. var secondLevUrls = [];
  29793. var thirdLevUrls = [];
  29794. var forthLevUrls = [];
  29795. var subUrls = [];
  29796. Laya3D._getSprite3DHierarchyInnerUrls(lhData.data, firstLevUrls, secondLevUrls, thirdLevUrls, forthLevUrls, subUrls, urlVersion, hierarchyBasePath);
  29797. var urlCount = firstLevUrls.length + secondLevUrls.length + forthLevUrls.length;
  29798. var totalProcessCount = urlCount + 1;
  29799. var weight = 1 / totalProcessCount;
  29800. Laya3D._onProcessChange(loader, 0, weight, 1.0);
  29801. if (forthLevUrls.length > 0) {
  29802. var processCeil = urlCount / totalProcessCount;
  29803. var processHandler = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, weight, processCeil], false);
  29804. Laya3D._innerFourthLevelLoaderManager._create(forthLevUrls, false, Laya.Handler.create(null, Laya3D._onHierarchyInnerForthLevResouLoaded, [loader, processHandler, lhData, subUrls, firstLevUrls, secondLevUrls, thirdLevUrls, weight + processCeil * forthLevUrls.length, processCeil]), processHandler, null, null, null, 1, true);
  29805. }
  29806. else {
  29807. Laya3D._onHierarchyInnerForthLevResouLoaded(loader, null, lhData, subUrls, firstLevUrls, secondLevUrls, thirdLevUrls, weight, processCeil);
  29808. }
  29809. }
  29810. static _onHierarchyInnerForthLevResouLoaded(loader, processHandler, lhData, subUrls, firstLevUrls, secondLevUrls, thirdLevUrls, processOffset, processCeil) {
  29811. (processHandler) && (processHandler.recover());
  29812. if (thirdLevUrls.length > 0) {
  29813. var process = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, processOffset, processCeil], false);
  29814. Laya3D._innerThirdLevelLoaderManager._create(thirdLevUrls, false, Laya.Handler.create(null, Laya3D._onHierarchyInnerThirdLevResouLoaded, [loader, process, lhData, subUrls, firstLevUrls, secondLevUrls, processOffset + processCeil * secondLevUrls.length, processCeil]), processHandler, null, null, null, 1, true);
  29815. }
  29816. else {
  29817. Laya3D._onHierarchyInnerThirdLevResouLoaded(loader, null, lhData, subUrls, firstLevUrls, secondLevUrls, processOffset, processCeil);
  29818. }
  29819. }
  29820. static _onHierarchyInnerThirdLevResouLoaded(loader, processHandler, lhData, subUrls, firstLevUrls, secondLevUrls, processOffset, processCeil) {
  29821. (processHandler) && (processHandler.recover());
  29822. if (secondLevUrls.length > 0) {
  29823. var process = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, processOffset, processCeil], false);
  29824. Laya3D._innerSecondLevelLoaderManager._create(secondLevUrls, false, Laya.Handler.create(null, Laya3D._onHierarchyInnerSecondLevResouLoaded, [loader, process, lhData, subUrls, firstLevUrls, processOffset + processCeil * secondLevUrls.length, processCeil]), processHandler, null, null, null, 1, true);
  29825. }
  29826. else {
  29827. Laya3D._onHierarchyInnerSecondLevResouLoaded(loader, null, lhData, subUrls, firstLevUrls, processOffset, processCeil);
  29828. }
  29829. }
  29830. static _onHierarchyInnerSecondLevResouLoaded(loader, processHandler, lhData, subUrls, firstLevUrls, processOffset, processCeil) {
  29831. (processHandler) && (processHandler.recover());
  29832. if (firstLevUrls.length > 0) {
  29833. var process = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, processOffset, processCeil], false);
  29834. Laya3D._innerFirstLevelLoaderManager._create(firstLevUrls, false, Laya.Handler.create(null, Laya3D._onHierarchyInnerFirstLevResouLoaded, [loader, process, lhData, subUrls]), processHandler, null, null, null, 1, true);
  29835. }
  29836. else {
  29837. Laya3D._onHierarchyInnerFirstLevResouLoaded(loader, null, lhData, subUrls);
  29838. }
  29839. }
  29840. static _onHierarchyInnerFirstLevResouLoaded(loader, processHandler, lhData, subUrls) {
  29841. (processHandler) && (processHandler.recover());
  29842. loader._cache = loader._createCache;
  29843. var item = lhData.data.type === "Scene3D" ? Scene3DUtils._parseScene(lhData, loader._propertyParams, loader._constructParams) : Scene3DUtils._parse(lhData, loader._propertyParams, loader._constructParams);
  29844. Laya3D._endLoad(loader, item, subUrls);
  29845. }
  29846. static _loadMesh(loader) {
  29847. loader.on(Laya.Event.LOADED, null, Laya3D._onMeshLmLoaded, [loader]);
  29848. loader.load(loader.url, Laya.Loader.BUFFER, false, null, true);
  29849. }
  29850. static _onMeshLmLoaded(loader, lmData) {
  29851. loader._cache = loader._createCache;
  29852. var mesh = Mesh._parse(lmData, loader._propertyParams, loader._constructParams);
  29853. Laya3D._endLoad(loader, mesh);
  29854. }
  29855. static _loadMaterial(loader) {
  29856. loader.on(Laya.Event.LOADED, null, Laya3D._onMaterilLmatLoaded, [loader]);
  29857. loader.load(loader.url, Laya.Loader.JSON, false, null, true);
  29858. }
  29859. static _onMaterilLmatLoaded(loader, lmatData) {
  29860. var url = loader.url;
  29861. var urlVersion = Utils3D.getURLVerion(url);
  29862. var materialBasePath = Laya.URL.getPath(url);
  29863. var urls = [];
  29864. var subUrls = [];
  29865. var customProps = lmatData.customProps;
  29866. var formatSubUrl;
  29867. var version = lmatData.version;
  29868. switch (version) {
  29869. case "LAYAMATERIAL:01":
  29870. case "LAYAMATERIAL:02":
  29871. var i, n;
  29872. var textures = lmatData.props.textures;
  29873. if (textures) {
  29874. for (i = 0, n = textures.length; i < n; i++) {
  29875. var tex2D = textures[i];
  29876. var tex2DPath = tex2D.path;
  29877. if (tex2DPath) {
  29878. formatSubUrl = Laya3D.formatRelativePath(materialBasePath, tex2DPath);
  29879. (urlVersion) && (formatSubUrl = formatSubUrl + urlVersion);
  29880. urls.push({ url: formatSubUrl, constructParams: tex2D.constructParams, propertyParams: tex2D.propertyParams });
  29881. subUrls.push(formatSubUrl);
  29882. tex2D.path = formatSubUrl;
  29883. }
  29884. }
  29885. }
  29886. break;
  29887. default:
  29888. throw new Error("Laya3D:unkonwn version.");
  29889. }
  29890. var urlCount = urls.length;
  29891. var totalProcessCount = urlCount + 1;
  29892. var lmatWeight = 1 / totalProcessCount;
  29893. Laya3D._onProcessChange(loader, 0, lmatWeight, 1.0);
  29894. if (urlCount > 0) {
  29895. var processHandler = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, lmatWeight, urlCount / totalProcessCount], false);
  29896. Laya3D._innerFourthLevelLoaderManager._create(urls, false, Laya.Handler.create(null, Laya3D._onMateialTexturesLoaded, [loader, processHandler, lmatData, subUrls]), processHandler, null, null, null, 1, true);
  29897. }
  29898. else {
  29899. Laya3D._onMateialTexturesLoaded(loader, null, lmatData, null);
  29900. }
  29901. }
  29902. static _onMateialTexturesLoaded(loader, processHandler, lmatData, subUrls) {
  29903. loader._cache = loader._createCache;
  29904. var mat = BaseMaterial._parse(lmatData, loader._propertyParams, loader._constructParams);
  29905. Laya3D._endLoad(loader, mat, subUrls);
  29906. (processHandler) && (processHandler.recover());
  29907. }
  29908. static _loadAvatar(loader) {
  29909. loader.on(Laya.Event.LOADED, null, function (data) {
  29910. loader._cache = loader._createCache;
  29911. var avatar = Avatar._parse(data, loader._propertyParams, loader._constructParams);
  29912. Laya3D._endLoad(loader, avatar);
  29913. });
  29914. loader.load(loader.url, Laya.Loader.JSON, false, null, true);
  29915. }
  29916. static _loadAnimationClip(loader) {
  29917. loader.on(Laya.Event.LOADED, null, function (data) {
  29918. loader._cache = loader._createCache;
  29919. var clip = AnimationClip._parse(data, loader._propertyParams, loader._constructParams);
  29920. Laya3D._endLoad(loader, clip);
  29921. });
  29922. loader.load(loader.url, Laya.Loader.BUFFER, false, null, true);
  29923. }
  29924. static _loadTexture2D(loader) {
  29925. var url = loader.url;
  29926. var index = url.lastIndexOf('.') + 1;
  29927. var verIndex = url.indexOf('?');
  29928. var endIndex = verIndex == -1 ? url.length : verIndex;
  29929. var ext = url.substr(index, endIndex - index);
  29930. var type;
  29931. switch (ext) {
  29932. case "jpg":
  29933. case "jpeg":
  29934. case "bmp":
  29935. case "gif":
  29936. case "png":
  29937. type = "nativeimage";
  29938. break;
  29939. case "dds":
  29940. case "ktx":
  29941. case "pvr":
  29942. type = Laya.Loader.BUFFER;
  29943. break;
  29944. }
  29945. loader.on(Laya.Event.LOADED, null, function (image) {
  29946. loader._cache = loader._createCache;
  29947. var tex = Laya.Texture2D._parse(image, loader._propertyParams, loader._constructParams);
  29948. Laya3D._endLoad(loader, tex);
  29949. });
  29950. loader.load(loader.url, type, false, null, true);
  29951. }
  29952. static _loadTextureCube(loader) {
  29953. loader.on(Laya.Event.LOADED, null, Laya3D._onTextureCubeLtcLoaded, [loader]);
  29954. loader.load(loader.url, Laya.Loader.JSON, false, null, true);
  29955. }
  29956. static _onTextureCubeLtcLoaded(loader, ltcData) {
  29957. var ltcBasePath = Laya.URL.getPath(loader.url);
  29958. var urls = [Laya3D.formatRelativePath(ltcBasePath, ltcData.front), Laya3D.formatRelativePath(ltcBasePath, ltcData.back), Laya3D.formatRelativePath(ltcBasePath, ltcData.left), Laya3D.formatRelativePath(ltcBasePath, ltcData.right), Laya3D.formatRelativePath(ltcBasePath, ltcData.up), Laya3D.formatRelativePath(ltcBasePath, ltcData.down)];
  29959. var ltcWeight = 1.0 / 7.0;
  29960. Laya3D._onProcessChange(loader, 0, ltcWeight, 1.0);
  29961. var processHandler = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, ltcWeight, 6 / 7], false);
  29962. Laya3D._innerFourthLevelLoaderManager.load(urls, Laya.Handler.create(null, Laya3D._onTextureCubeImagesLoaded, [loader, urls, processHandler]), processHandler, "nativeimage");
  29963. }
  29964. static _onTextureCubeImagesLoaded(loader, urls, processHandler) {
  29965. var images = new Array(6);
  29966. for (var i = 0; i < 6; i++)
  29967. images[i] = Laya.Loader.getRes(urls[i]);
  29968. loader._cache = loader._createCache;
  29969. var tex = TextureCube._parse(images, loader._propertyParams, loader._constructParams);
  29970. processHandler.recover();
  29971. for (i = 0; i < 6; i++)
  29972. Laya.Loader.clearRes(urls[i]);
  29973. Laya3D._endLoad(loader, tex);
  29974. }
  29975. static _onProcessChange(loader, offset, weight, process) {
  29976. process = offset + process * weight;
  29977. (process < 1.0) && (loader.event(Laya.Event.PROGRESS, process));
  29978. }
  29979. static init(width, height, config = null, compolete = null) {
  29980. if (Laya3D._isInit)
  29981. return;
  29982. Laya3D._isInit = true;
  29983. config = config || Config3D._default;
  29984. config.cloneTo(Laya3D._config);
  29985. FrustumCulling.debugFrustumCulling = config.debugFrustumCulling;
  29986. Laya3D._editerEnvironment = Laya3D._config._editerEnvironment;
  29987. Scene3D.octreeCulling = config.octreeCulling;
  29988. Scene3D.octreeInitialSize = config.octreeInitialSize;
  29989. Scene3D.octreeInitialCenter = config.octreeInitialCenter;
  29990. Scene3D.octreeMinNodeSize = config.octreeMinNodeSize;
  29991. Scene3D.octreeLooseness = config.octreeLooseness;
  29992. var physics3D = window.Physics3D;
  29993. if (physics3D == null) {
  29994. Physics3D._enbalePhysics = false;
  29995. Laya3D.__init__(width, height, Laya3D._config);
  29996. compolete && compolete.run();
  29997. }
  29998. else {
  29999. Physics3D._enbalePhysics = true;
  30000. physics3D(Laya3D._config.defaultPhysicsMemory * 1024 * 1024).then(function () {
  30001. Laya3D.__init__(width, height, Laya3D._config);
  30002. compolete && compolete.run();
  30003. });
  30004. }
  30005. }
  30006. }
  30007. Laya3D.HIERARCHY = "HIERARCHY";
  30008. Laya3D.MESH = "MESH";
  30009. Laya3D.MATERIAL = "MATERIAL";
  30010. Laya3D.TEXTURE2D = "TEXTURE2D";
  30011. Laya3D.TEXTURECUBE = "TEXTURECUBE";
  30012. Laya3D.ANIMATIONCLIP = "ANIMATIONCLIP";
  30013. Laya3D.AVATAR = "AVATAR";
  30014. Laya3D.TERRAINHEIGHTDATA = "TERRAINHEIGHTDATA";
  30015. Laya3D.TERRAINRES = "TERRAIN";
  30016. Laya3D._innerFirstLevelLoaderManager = new Laya.LoaderManager();
  30017. Laya3D._innerSecondLevelLoaderManager = new Laya.LoaderManager();
  30018. Laya3D._innerThirdLevelLoaderManager = new Laya.LoaderManager();
  30019. Laya3D._innerFourthLevelLoaderManager = new Laya.LoaderManager();
  30020. Laya3D._isInit = false;
  30021. Laya3D._editerEnvironment = false;
  30022. Laya3D._config = new Config3D();
  30023. Laya3D.physicsSettings = new PhysicsSettings();
  30024. window.Laya3D = Laya3D;
  30025. class AnimatorStateScript {
  30026. constructor() {
  30027. }
  30028. onStateEnter() {
  30029. }
  30030. onStateUpdate() {
  30031. }
  30032. onStateExit() {
  30033. }
  30034. }
  30035. class Script3D extends Laya.Component {
  30036. constructor() {
  30037. super(...arguments);
  30038. this._indexInPool = -1;
  30039. }
  30040. get isSingleton() {
  30041. return false;
  30042. }
  30043. _checkProcessTriggers() {
  30044. var prototype = Script3D.prototype;
  30045. if (this.onTriggerEnter !== prototype.onTriggerEnter)
  30046. return true;
  30047. if (this.onTriggerStay !== prototype.onTriggerStay)
  30048. return true;
  30049. if (this.onTriggerExit !== prototype.onTriggerExit)
  30050. return true;
  30051. return false;
  30052. }
  30053. _checkProcessCollisions() {
  30054. var prototype = Script3D.prototype;
  30055. if (this.onCollisionEnter !== prototype.onCollisionEnter)
  30056. return true;
  30057. if (this.onCollisionStay !== prototype.onCollisionStay)
  30058. return true;
  30059. if (this.onCollisionExit !== prototype.onCollisionExit)
  30060. return true;
  30061. return false;
  30062. }
  30063. _onAwake() {
  30064. this.onAwake();
  30065. if (this.onStart !== Script3D.prototype.onStart)
  30066. Laya.Laya.startTimer.callLater(this, this.onStart);
  30067. }
  30068. _onEnable() {
  30069. this.owner._scene._addScript(this);
  30070. var proto = Script3D.prototype;
  30071. if (this.onKeyDown !== proto.onKeyDown) {
  30072. Laya.Laya.stage.on(Laya.Event.KEY_DOWN, this, this.onKeyDown);
  30073. }
  30074. if (this.onKeyPress !== proto.onKeyPress) {
  30075. Laya.Laya.stage.on(Laya.Event.KEY_PRESS, this, this.onKeyUp);
  30076. }
  30077. if (this.onKeyUp !== proto.onKeyUp) {
  30078. Laya.Laya.stage.on(Laya.Event.KEY_UP, this, this.onKeyUp);
  30079. }
  30080. }
  30081. _onDisable() {
  30082. this.owner._scene._removeScript(this);
  30083. this.owner.offAllCaller(this);
  30084. Laya.Laya.stage.offAllCaller(this);
  30085. }
  30086. _isScript() {
  30087. return true;
  30088. }
  30089. _onAdded() {
  30090. var sprite = this.owner;
  30091. var scripts = sprite._scripts;
  30092. scripts || (sprite._scripts = scripts = []);
  30093. scripts.push(this);
  30094. if (!sprite._needProcessCollisions)
  30095. sprite._needProcessCollisions = this._checkProcessCollisions();
  30096. if (!sprite._needProcessTriggers)
  30097. sprite._needProcessTriggers = this._checkProcessTriggers();
  30098. }
  30099. _onDestroy() {
  30100. var scripts = this.owner._scripts;
  30101. scripts.splice(scripts.indexOf(this), 1);
  30102. var sprite = this.owner;
  30103. sprite._needProcessTriggers = false;
  30104. for (var i = 0, n = scripts.length; i < n; i++) {
  30105. if (scripts[i]._checkProcessTriggers()) {
  30106. sprite._needProcessTriggers = true;
  30107. break;
  30108. }
  30109. }
  30110. sprite._needProcessCollisions = false;
  30111. for (i = 0, n = scripts.length; i < n; i++) {
  30112. if (scripts[i]._checkProcessCollisions()) {
  30113. sprite._needProcessCollisions = true;
  30114. break;
  30115. }
  30116. }
  30117. this.onDestroy();
  30118. }
  30119. onAwake() {
  30120. }
  30121. onEnable() {
  30122. }
  30123. onStart() {
  30124. }
  30125. onTriggerEnter(other) {
  30126. }
  30127. onTriggerStay(other) {
  30128. }
  30129. onTriggerExit(other) {
  30130. }
  30131. onCollisionEnter(collision) {
  30132. }
  30133. onCollisionStay(collision) {
  30134. }
  30135. onCollisionExit(collision) {
  30136. }
  30137. onMouseDown() {
  30138. }
  30139. onMouseDrag() {
  30140. }
  30141. onMouseClick() {
  30142. }
  30143. onMouseUp() {
  30144. }
  30145. onMouseEnter() {
  30146. }
  30147. onMouseOver() {
  30148. }
  30149. onMouseOut() {
  30150. }
  30151. onKeyDown(e) {
  30152. }
  30153. onKeyPress(e) {
  30154. }
  30155. onKeyUp(e) {
  30156. }
  30157. onUpdate() {
  30158. }
  30159. onLateUpdate() {
  30160. }
  30161. onPreRender() {
  30162. }
  30163. onPostRender() {
  30164. }
  30165. onDisable() {
  30166. }
  30167. onDestroy() {
  30168. }
  30169. }
  30170. class HeightMap {
  30171. constructor(width, height, minHeight, maxHeight) {
  30172. this._datas = [];
  30173. this._w = width;
  30174. this._h = height;
  30175. this._minHeight = minHeight;
  30176. this._maxHeight = maxHeight;
  30177. }
  30178. static creatFromMesh(mesh, width, height, outCellSize) {
  30179. var vertices = [];
  30180. var indexs = [];
  30181. var submesheCount = mesh.subMeshCount;
  30182. for (var i = 0; i < submesheCount; i++) {
  30183. var subMesh = mesh.getSubMesh(i);
  30184. var vertexBuffer = subMesh._vertexBuffer;
  30185. var verts = vertexBuffer.getFloat32Data();
  30186. var subMeshVertices = [];
  30187. for (var j = 0; j < verts.length; j += vertexBuffer.vertexDeclaration.vertexStride / 4) {
  30188. var position = new Vector3(verts[j + 0], verts[j + 1], verts[j + 2]);
  30189. subMeshVertices.push(position);
  30190. }
  30191. vertices.push(subMeshVertices);
  30192. var ib = subMesh._indexBuffer;
  30193. indexs.push(ib.getData());
  30194. }
  30195. var bounds = mesh.bounds;
  30196. var minX = bounds.getMin().x;
  30197. var minZ = bounds.getMin().z;
  30198. var maxX = bounds.getMax().x;
  30199. var maxZ = bounds.getMax().z;
  30200. var minY = bounds.getMin().y;
  30201. var maxY = bounds.getMax().y;
  30202. var widthSize = maxX - minX;
  30203. var heightSize = maxZ - minZ;
  30204. var cellWidth = outCellSize.x = widthSize / (width - 1);
  30205. var cellHeight = outCellSize.y = heightSize / (height - 1);
  30206. var heightMap = new HeightMap(width, height, minY, maxY);
  30207. var ray = HeightMap._tempRay;
  30208. var rayDir = ray.direction;
  30209. rayDir.x = 0;
  30210. rayDir.y = -1;
  30211. rayDir.z = 0;
  30212. const heightOffset = 0.1;
  30213. var rayY = maxY + heightOffset;
  30214. ray.origin.y = rayY;
  30215. for (var h = 0; h < height; h++) {
  30216. var posZ = minZ + h * cellHeight;
  30217. heightMap._datas[h] = [];
  30218. for (var w = 0; w < width; w++) {
  30219. var posX = minX + w * cellWidth;
  30220. var rayOri = ray.origin;
  30221. rayOri.x = posX;
  30222. rayOri.z = posZ;
  30223. var closestIntersection = HeightMap._getPosition(ray, vertices, indexs);
  30224. heightMap._datas[h][w] = (closestIntersection === Number.MAX_VALUE) ? NaN : rayY - closestIntersection;
  30225. }
  30226. }
  30227. return heightMap;
  30228. }
  30229. static createFromImage(texture, minHeight, maxHeight) {
  30230. var textureWidth = texture.width;
  30231. var textureHeight = texture.height;
  30232. var heightMap = new HeightMap(textureWidth, textureHeight, minHeight, maxHeight);
  30233. var compressionRatio = (maxHeight - minHeight) / 254;
  30234. var pixelsInfo = texture.getPixels();
  30235. var index = 0;
  30236. for (var h = 0; h < textureHeight; h++) {
  30237. var colDatas = heightMap._datas[h] = [];
  30238. for (var w = 0; w < textureWidth; w++) {
  30239. var r = pixelsInfo[index++];
  30240. var g = pixelsInfo[index++];
  30241. var b = pixelsInfo[index++];
  30242. var a = pixelsInfo[index++];
  30243. if (r == 255 && g == 255 && b == 255 && a == 255)
  30244. colDatas[w] = NaN;
  30245. else {
  30246. colDatas[w] = (r + g + b) / 3 * compressionRatio + minHeight;
  30247. }
  30248. }
  30249. }
  30250. return heightMap;
  30251. }
  30252. static _getPosition(ray, vertices, indexs) {
  30253. var closestIntersection = Number.MAX_VALUE;
  30254. for (var i = 0; i < vertices.length; i++) {
  30255. var subMeshVertices = vertices[i];
  30256. var subMeshIndexes = indexs[i];
  30257. for (var j = 0; j < subMeshIndexes.length; j += 3) {
  30258. var vertex1 = subMeshVertices[subMeshIndexes[j + 0]];
  30259. var vertex2 = subMeshVertices[subMeshIndexes[j + 1]];
  30260. var vertex3 = subMeshVertices[subMeshIndexes[j + 2]];
  30261. var intersection = Picker.rayIntersectsTriangle(ray, vertex1, vertex2, vertex3);
  30262. if (!isNaN(intersection) && intersection < closestIntersection) {
  30263. closestIntersection = intersection;
  30264. }
  30265. }
  30266. }
  30267. return closestIntersection;
  30268. }
  30269. get width() {
  30270. return this._w;
  30271. }
  30272. get height() {
  30273. return this._h;
  30274. }
  30275. get maxHeight() {
  30276. return this._maxHeight;
  30277. }
  30278. get minHeight() {
  30279. return this._minHeight;
  30280. }
  30281. _inBounds(row, col) {
  30282. return row >= 0 && row < this._h && col >= 0 && col < this._w;
  30283. }
  30284. getHeight(row, col) {
  30285. if (this._inBounds(row, col))
  30286. return this._datas[row][col];
  30287. else
  30288. return NaN;
  30289. }
  30290. }
  30291. HeightMap._tempRay = new Ray(new Vector3(), new Vector3());
  30292. class MeshTerrainSprite3D extends MeshSprite3D {
  30293. constructor(mesh, heightMap, name = null) {
  30294. super(mesh, name);
  30295. this._heightMap = heightMap;
  30296. this._cellSize = new Vector2();
  30297. }
  30298. static createFromMesh(mesh, heightMapWidth, heightMapHeight, name = null) {
  30299. var meshTerrainSprite3D = new MeshTerrainSprite3D(mesh, null, name);
  30300. meshTerrainSprite3D._initCreateFromMesh(heightMapWidth, heightMapHeight);
  30301. return meshTerrainSprite3D;
  30302. }
  30303. static createFromMeshAndHeightMap(mesh, texture, minHeight, maxHeight, name = null) {
  30304. var meshTerrainSprite3D = new MeshTerrainSprite3D(mesh, null, name);
  30305. meshTerrainSprite3D._initCreateFromMeshHeightMap(texture, minHeight, maxHeight);
  30306. return meshTerrainSprite3D;
  30307. }
  30308. get minX() {
  30309. var worldMat = this.transform.worldMatrix;
  30310. var worldMatE = worldMat.elements;
  30311. return this._minX * this._getScaleX() + worldMatE[12];
  30312. }
  30313. get minZ() {
  30314. var worldMat = this.transform.worldMatrix;
  30315. var worldMatE = worldMat.elements;
  30316. return this._minZ * this._getScaleZ() + worldMatE[14];
  30317. }
  30318. get width() {
  30319. return (this._heightMap.width - 1) * this._cellSize.x * this._getScaleX();
  30320. }
  30321. get depth() {
  30322. return (this._heightMap.height - 1) * this._cellSize.y * this._getScaleZ();
  30323. }
  30324. _disableRotation() {
  30325. var rotation = this.transform.rotation;
  30326. rotation.x = 0;
  30327. rotation.y = 0;
  30328. rotation.z = 0;
  30329. rotation.w = 1;
  30330. this.transform.rotation = rotation;
  30331. }
  30332. _getScaleX() {
  30333. var worldMat = this.transform.worldMatrix;
  30334. var worldMatE = worldMat.elements;
  30335. var m11 = worldMatE[0];
  30336. var m12 = worldMatE[1];
  30337. var m13 = worldMatE[2];
  30338. return Math.sqrt((m11 * m11) + (m12 * m12) + (m13 * m13));
  30339. }
  30340. _getScaleZ() {
  30341. var worldMat = this.transform.worldMatrix;
  30342. var worldMatE = worldMat.elements;
  30343. var m31 = worldMatE[8];
  30344. var m32 = worldMatE[9];
  30345. var m33 = worldMatE[10];
  30346. return Math.sqrt((m31 * m31) + (m32 * m32) + (m33 * m33));
  30347. }
  30348. _initCreateFromMesh(heightMapWidth, heightMapHeight) {
  30349. this._heightMap = HeightMap.creatFromMesh(this.meshFilter.sharedMesh, heightMapWidth, heightMapHeight, this._cellSize);
  30350. var boundingBox = this.meshFilter.sharedMesh.bounds;
  30351. var min = boundingBox.getMin();
  30352. var max = boundingBox.getMax();
  30353. this._minX = min.x;
  30354. this._minZ = min.z;
  30355. }
  30356. _initCreateFromMeshHeightMap(texture, minHeight, maxHeight) {
  30357. var boundingBox = this.meshFilter.sharedMesh.bounds;
  30358. this._heightMap = HeightMap.createFromImage(texture, minHeight, maxHeight);
  30359. this._computeCellSize(boundingBox);
  30360. var min = boundingBox.getMin();
  30361. var max = boundingBox.getMax();
  30362. this._minX = min.x;
  30363. this._minZ = min.z;
  30364. }
  30365. _computeCellSize(boundingBox) {
  30366. var min = boundingBox.getMin();
  30367. var max = boundingBox.getMax();
  30368. var minX = min.x;
  30369. var minZ = min.z;
  30370. var maxX = max.x;
  30371. var maxZ = max.z;
  30372. var widthSize = maxX - minX;
  30373. var heightSize = maxZ - minZ;
  30374. this._cellSize.x = widthSize / (this._heightMap.width - 1);
  30375. this._cellSize.y = heightSize / (this._heightMap.height - 1);
  30376. }
  30377. _update(state) {
  30378. this._disableRotation();
  30379. }
  30380. getHeight(x, z) {
  30381. MeshTerrainSprite3D._tempVector3.x = x;
  30382. MeshTerrainSprite3D._tempVector3.y = 0;
  30383. MeshTerrainSprite3D._tempVector3.z = z;
  30384. this._disableRotation();
  30385. var worldMat = this.transform.worldMatrix;
  30386. worldMat.invert(MeshTerrainSprite3D._tempMatrix4x4);
  30387. Vector3.transformCoordinate(MeshTerrainSprite3D._tempVector3, MeshTerrainSprite3D._tempMatrix4x4, MeshTerrainSprite3D._tempVector3);
  30388. x = MeshTerrainSprite3D._tempVector3.x;
  30389. z = MeshTerrainSprite3D._tempVector3.z;
  30390. var c = (x - this._minX) / this._cellSize.x;
  30391. var d = (z - this._minZ) / this._cellSize.y;
  30392. var row = Math.floor(d);
  30393. var col = Math.floor(c);
  30394. var s = c - col;
  30395. var t = d - row;
  30396. var uy;
  30397. var vy;
  30398. var worldMatE = worldMat.elements;
  30399. var m21 = worldMatE[4];
  30400. var m22 = worldMatE[5];
  30401. var m23 = worldMatE[6];
  30402. var scaleY = Math.sqrt((m21 * m21) + (m22 * m22) + (m23 * m23));
  30403. var translateY = worldMatE[13];
  30404. var h01 = this._heightMap.getHeight(row, col + 1);
  30405. var h10 = this._heightMap.getHeight((row + 1), col);
  30406. if (isNaN(h01) || isNaN(h10))
  30407. return NaN;
  30408. if (s + t <= 1.0) {
  30409. var h00 = this._heightMap.getHeight(row, col);
  30410. if (isNaN(h00))
  30411. return NaN;
  30412. uy = h01 - h00;
  30413. vy = h10 - h00;
  30414. return (h00 + s * uy + t * vy) * scaleY + translateY;
  30415. }
  30416. else {
  30417. var h11 = this._heightMap.getHeight((row + 1), col + 1);
  30418. if (isNaN(h11))
  30419. return NaN;
  30420. uy = h10 - h11;
  30421. vy = h01 - h11;
  30422. return (h11 + (1.0 - s) * uy + (1.0 - t) * vy) * scaleY + translateY;
  30423. }
  30424. }
  30425. }
  30426. MeshTerrainSprite3D._tempVector3 = new Vector3();
  30427. MeshTerrainSprite3D._tempMatrix4x4 = new Matrix4x4();
  30428. class GradientDataVector2 {
  30429. constructor() {
  30430. this._currentLength = 0;
  30431. this._elements = new Float32Array(12);
  30432. }
  30433. get gradientCount() {
  30434. return this._currentLength / 3;
  30435. }
  30436. add(key, value) {
  30437. if (this._currentLength < 8) {
  30438. if ((this._currentLength === 6) && ((key !== 1))) {
  30439. key = 1;
  30440. console.log("GradientDataVector2 warning:the forth key is be force set to 1.");
  30441. }
  30442. this._elements[this._currentLength++] = key;
  30443. this._elements[this._currentLength++] = value.x;
  30444. this._elements[this._currentLength++] = value.y;
  30445. }
  30446. else {
  30447. console.log("GradientDataVector2 warning:data count must lessEqual than 4");
  30448. }
  30449. }
  30450. cloneTo(destObject) {
  30451. var destGradientDataVector2 = destObject;
  30452. destGradientDataVector2._currentLength = this._currentLength;
  30453. var destElements = destGradientDataVector2._elements;
  30454. for (var i = 0, n = this._elements.length; i < n; i++) {
  30455. destElements[i] = this._elements[i];
  30456. }
  30457. }
  30458. clone() {
  30459. var destGradientDataVector2 = new GradientDataVector2();
  30460. this.cloneTo(destGradientDataVector2);
  30461. return destGradientDataVector2;
  30462. }
  30463. }
  30464. class PixelLineData {
  30465. constructor() {
  30466. this.startPosition = new Vector3();
  30467. this.endPosition = new Vector3();
  30468. this.startColor = new Color();
  30469. this.endColor = new Color();
  30470. }
  30471. cloneTo(destObject) {
  30472. this.startPosition.cloneTo(destObject.startPosition);
  30473. this.endPosition.cloneTo(destObject.endPosition);
  30474. this.startColor.cloneTo(destObject.startColor);
  30475. this.endColor.cloneTo(destObject.endColor);
  30476. }
  30477. }
  30478. class PostProcessEffect {
  30479. constructor() {
  30480. }
  30481. render(context) {
  30482. }
  30483. }
  30484. class BloomEffect extends PostProcessEffect {
  30485. constructor() {
  30486. super();
  30487. this._shader = null;
  30488. this._shaderData = new ShaderData();
  30489. this._linearColor = new Color();
  30490. this._bloomTextureTexelSize = new Vector4();
  30491. this._shaderThreshold = new Vector4();
  30492. this._shaderParams = new Vector4();
  30493. this._pyramid = null;
  30494. this._intensity = 0.0;
  30495. this._threshold = 1.0;
  30496. this._softKnee = 0.5;
  30497. this._diffusion = 7.0;
  30498. this._anamorphicRatio = 0.0;
  30499. this._dirtIntensity = 0.0;
  30500. this._shaderSetting = new Vector4();
  30501. this._dirtTileOffset = new Vector4();
  30502. this.clamp = 65472.0;
  30503. this.color = new Color(1.0, 1.0, 1.0, 1.0);
  30504. this.fastMode = false;
  30505. this.dirtTexture = null;
  30506. this._shader = Shader3D.find("PostProcessBloom");
  30507. this._pyramid = new Array(BloomEffect.MAXPYRAMIDSIZE * 2);
  30508. }
  30509. get intensity() {
  30510. return this._intensity;
  30511. }
  30512. set intensity(value) {
  30513. this._intensity = Math.max(value, 0.0);
  30514. }
  30515. get threshold() {
  30516. return this._threshold;
  30517. }
  30518. set threshold(value) {
  30519. this._threshold = Math.max(value, 0.0);
  30520. }
  30521. get softKnee() {
  30522. return this._softKnee;
  30523. }
  30524. set softKnee(value) {
  30525. this._softKnee = Math.min(Math.max(value, 0.0), 1.0);
  30526. }
  30527. get diffusion() {
  30528. return this._diffusion;
  30529. }
  30530. set diffusion(value) {
  30531. this._diffusion = Math.min(Math.max(value, 1), 10);
  30532. }
  30533. get anamorphicRatio() {
  30534. return this._anamorphicRatio;
  30535. }
  30536. set anamorphicRatio(value) {
  30537. this._anamorphicRatio = Math.min(Math.max(value, -1.0), 1.0);
  30538. }
  30539. get dirtIntensity() {
  30540. return this._dirtIntensity;
  30541. }
  30542. set dirtIntensity(value) {
  30543. this._dirtIntensity = Math.max(value, 0.0);
  30544. }
  30545. render(context) {
  30546. var cmd = context.command;
  30547. var viewport = context.camera.viewport;
  30548. this._shaderData.setTexture(BloomEffect.SHADERVALUE_AUTOEXPOSURETEX, Laya.Texture2D.whiteTexture);
  30549. var ratio = this._anamorphicRatio;
  30550. var rw = ratio < 0 ? -ratio : 0;
  30551. var rh = ratio > 0 ? ratio : 0;
  30552. var tw = Math.floor(viewport.width / (2 - rw));
  30553. var th = Math.floor(viewport.height / (2 - rh));
  30554. var s = Math.max(tw, th);
  30555. var logs;
  30556. logs = Math.log2(s) + this._diffusion - 10;
  30557. var logsInt = Math.floor(logs);
  30558. var iterations = Math.min(Math.max(logsInt, 1), BloomEffect.MAXPYRAMIDSIZE);
  30559. var sampleScale = 0.5 + logs - logsInt;
  30560. this._shaderData.setNumber(BloomEffect.SHADERVALUE_SAMPLESCALE, sampleScale);
  30561. var lthresh = Color.gammaToLinearSpace(this.threshold);
  30562. var knee = lthresh * this._softKnee + 1e-5;
  30563. this._shaderThreshold.setValue(lthresh, lthresh - knee, knee * 2, 0.25 / knee);
  30564. this._shaderData.setVector(BloomEffect.SHADERVALUE_THRESHOLD, this._shaderThreshold);
  30565. var lclamp = Color.gammaToLinearSpace(this.clamp);
  30566. this._shaderParams.setValue(lclamp, 0, 0, 0);
  30567. this._shaderData.setVector(BloomEffect.SHADERVALUE_PARAMS, this._shaderParams);
  30568. var qualityOffset = this.fastMode ? 1 : 0;
  30569. var lastDownTexture = context.source;
  30570. for (var i = 0; i < iterations; i++) {
  30571. var downIndex = i * 2;
  30572. var upIndex = downIndex + 1;
  30573. var subShader = i == 0 ? BloomEffect.SUBSHADER_PREFILTER13 + qualityOffset : BloomEffect.SUBSHADER_DOWNSAMPLE13 + qualityOffset;
  30574. var mipDownTexture = RenderTexture.createFromPool(tw, th, Laya.BaseTexture.FORMAT_R8G8B8, Laya.BaseTexture.FORMAT_DEPTHSTENCIL_NONE, Laya.BaseTexture.FILTERMODE_BILINEAR);
  30575. this._pyramid[downIndex] = mipDownTexture;
  30576. if (i !== iterations - 1) {
  30577. var mipUpTexture = RenderTexture.createFromPool(tw, th, Laya.BaseTexture.FORMAT_R8G8B8, Laya.BaseTexture.FORMAT_DEPTHSTENCIL_NONE, Laya.BaseTexture.FILTERMODE_BILINEAR);
  30578. this._pyramid[upIndex] = mipUpTexture;
  30579. }
  30580. cmd.blitScreenTriangle(lastDownTexture, mipDownTexture, this._shader, this._shaderData, subShader);
  30581. lastDownTexture = mipDownTexture;
  30582. tw = Math.max(Math.floor(tw / 2), 1);
  30583. th = Math.max(Math.floor(th / 2), 1);
  30584. }
  30585. var lastUpTexture = this._pyramid[(iterations - 1) * 2];
  30586. for (i = iterations - 2; i >= 0; i--) {
  30587. downIndex = i * 2;
  30588. upIndex = downIndex + 1;
  30589. mipDownTexture = this._pyramid[downIndex];
  30590. mipUpTexture = this._pyramid[upIndex];
  30591. cmd.setShaderDataTexture(this._shaderData, BloomEffect.SHADERVALUE_BLOOMTEX, mipDownTexture);
  30592. cmd.blitScreenTriangle(lastUpTexture, mipUpTexture, this._shader, this._shaderData, BloomEffect.SUBSHADER_UPSAMPLETENT + qualityOffset);
  30593. lastUpTexture = mipUpTexture;
  30594. }
  30595. var linearColor = this._linearColor;
  30596. this.color.toLinear(linearColor);
  30597. var intensity = Math.pow(2, this._intensity / 10.0) - 1.0;
  30598. var shaderSettings = this._shaderSetting;
  30599. this._shaderSetting.setValue(sampleScale, intensity, this._dirtIntensity, iterations);
  30600. var dirtTexture = this.dirtTexture ? this.dirtTexture : Laya.Texture2D.blackTexture;
  30601. var dirtRatio = dirtTexture.width / dirtTexture.height;
  30602. var screenRatio = viewport.width / viewport.height;
  30603. var dirtTileOffset = this._dirtTileOffset;
  30604. if (dirtRatio > screenRatio)
  30605. dirtTileOffset.setValue(screenRatio / dirtRatio, 1.0, (1.0 - dirtTileOffset.x) * 0.5, 0.0);
  30606. else if (dirtRatio < screenRatio)
  30607. dirtTileOffset.setValue(1.0, dirtRatio / screenRatio, 0.0, (1.0 - dirtTileOffset.y) * 0.5);
  30608. var compositeShaderData = context.compositeShaderData;
  30609. if (this.fastMode)
  30610. compositeShaderData.addDefine(PostProcess.SHADERDEFINE_BLOOM_LOW);
  30611. else
  30612. compositeShaderData.addDefine(PostProcess.SHADERDEFINE_BLOOM);
  30613. this._bloomTextureTexelSize.setValue(1.0 / lastUpTexture.width, 1.0 / lastUpTexture.height, lastUpTexture.width, lastUpTexture.height);
  30614. compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_DIRTTILEOFFSET, dirtTileOffset);
  30615. compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_SETTINGS, shaderSettings);
  30616. compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_COLOR, new Vector4(linearColor.r, linearColor.g, linearColor.b, linearColor.a));
  30617. compositeShaderData.setTexture(PostProcess.SHADERVALUE_BLOOM_DIRTTEX, dirtTexture);
  30618. compositeShaderData.setTexture(PostProcess.SHADERVALUE_BLOOMTEX, lastUpTexture);
  30619. compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOMTEX_TEXELSIZE, this._bloomTextureTexelSize);
  30620. for (i = 0; i < iterations; i++) {
  30621. downIndex = i * 2;
  30622. upIndex = downIndex + 1;
  30623. RenderTexture.recoverToPool(this._pyramid[downIndex]);
  30624. (i !== 0 && i !== iterations - 1) && (RenderTexture.recoverToPool(this._pyramid[upIndex]));
  30625. }
  30626. context.deferredReleaseTextures.push(lastUpTexture);
  30627. }
  30628. }
  30629. BloomEffect.SHADERVALUE_MAINTEX = Shader3D.propertyNameToID("u_MainTex");
  30630. BloomEffect.SHADERVALUE_AUTOEXPOSURETEX = Shader3D.propertyNameToID("u_AutoExposureTex");
  30631. BloomEffect.SHADERVALUE_SAMPLESCALE = Shader3D.propertyNameToID("u_SampleScale");
  30632. BloomEffect.SHADERVALUE_THRESHOLD = Shader3D.propertyNameToID("u_Threshold");
  30633. BloomEffect.SHADERVALUE_PARAMS = Shader3D.propertyNameToID("u_Params");
  30634. BloomEffect.SHADERVALUE_BLOOMTEX = Shader3D.propertyNameToID("u_BloomTex");
  30635. BloomEffect.SUBSHADER_PREFILTER13 = 0;
  30636. BloomEffect.SUBSHADER_PREFILTER4 = 1;
  30637. BloomEffect.SUBSHADER_DOWNSAMPLE13 = 2;
  30638. BloomEffect.SUBSHADER_DOWNSAMPLE4 = 3;
  30639. BloomEffect.SUBSHADER_UPSAMPLETENT = 4;
  30640. BloomEffect.SUBSHADER_UPSAMPLEBOX = 5;
  30641. BloomEffect.MAXPYRAMIDSIZE = 16;
  30642. class SceneManager {
  30643. constructor() {
  30644. }
  30645. }
  30646. class RandX {
  30647. constructor(seed) {
  30648. if (!(seed instanceof Array) || seed.length !== 4)
  30649. throw new Error('Rand:Seed must be an array with 4 numbers');
  30650. this._state0U = seed[0] | 0;
  30651. this._state0L = seed[1] | 0;
  30652. this._state1U = seed[2] | 0;
  30653. this._state1L = seed[3] | 0;
  30654. }
  30655. randomint() {
  30656. var s1U = this._state0U, s1L = this._state0L;
  30657. var s0U = this._state1U, s0L = this._state1L;
  30658. var sumL = (s0L >>> 0) + (s1L >>> 0);
  30659. var resU = (s0U + s1U + (sumL / 2 >>> 31)) >>> 0;
  30660. var resL = sumL >>> 0;
  30661. this._state0U = s0U;
  30662. this._state0L = s0L;
  30663. var t1U = 0, t1L = 0;
  30664. var t2U = 0, t2L = 0;
  30665. var a1 = 23;
  30666. var m1 = 0xFFFFFFFF << (32 - a1);
  30667. t1U = (s1U << a1) | ((s1L & m1) >>> (32 - a1));
  30668. t1L = s1L << a1;
  30669. s1U = s1U ^ t1U;
  30670. s1L = s1L ^ t1L;
  30671. t1U = s1U ^ s0U;
  30672. t1L = s1L ^ s0L;
  30673. var a2 = 18;
  30674. var m2 = 0xFFFFFFFF >>> (32 - a2);
  30675. t2U = s1U >>> a2;
  30676. t2L = (s1L >>> a2) | ((s1U & m2) << (32 - a2));
  30677. t1U = t1U ^ t2U;
  30678. t1L = t1L ^ t2L;
  30679. var a3 = 5;
  30680. var m3 = 0xFFFFFFFF >>> (32 - a3);
  30681. t2U = s0U >>> a3;
  30682. t2L = (s0L >>> a3) | ((s0U & m3) << (32 - a3));
  30683. t1U = t1U ^ t2U;
  30684. t1L = t1L ^ t2L;
  30685. this._state1U = t1U;
  30686. this._state1L = t1L;
  30687. return [resU, resL];
  30688. }
  30689. random() {
  30690. var t2 = this.randomint();
  30691. var t2U = t2[0];
  30692. var t2L = t2[1];
  30693. var eU = 0x3FF << (52 - 32);
  30694. var eL = 0;
  30695. var a1 = 12;
  30696. var m1 = 0xFFFFFFFF >>> (32 - a1);
  30697. var sU = t2U >>> a1;
  30698. var sL = (t2L >>> a1) | ((t2U & m1) << (32 - a1));
  30699. var xU = eU | sU;
  30700. var xL = eL | sL;
  30701. RandX._CONVERTION_BUFFER.setUint32(0, xU, false);
  30702. RandX._CONVERTION_BUFFER.setUint32(4, xL, false);
  30703. var d = RandX._CONVERTION_BUFFER.getFloat64(0, false);
  30704. return d - 1;
  30705. }
  30706. }
  30707. RandX._CONVERTION_BUFFER = new DataView(new ArrayBuffer(8));
  30708. RandX.defaultRand = new RandX([0, Date.now() / 65536, 0, Date.now() % 65536]);
  30709. class Constraint3D {
  30710. constructor() {
  30711. }
  30712. }
  30713. class ConstraintComponent extends Laya.Component {
  30714. constructor() {
  30715. super();
  30716. this._feedbackEnabled = false;
  30717. }
  30718. get enabled() {
  30719. return super.enabled;
  30720. }
  30721. set enabled(value) {
  30722. this._nativeConstraint.IsEnabled = value;
  30723. super.enabled = value;
  30724. }
  30725. get breakingImpulseThreshold() {
  30726. return this._breakingImpulseThreshold;
  30727. }
  30728. set breakingImpulseThreshold(value) {
  30729. this._nativeConstraint.BreakingImpulseThreshold = value;
  30730. this._breakingImpulseThreshold = value;
  30731. }
  30732. get appliedImpulse() {
  30733. if (!this._feedbackEnabled) {
  30734. this._nativeConstraint.EnableFeedback(true);
  30735. this._feedbackEnabled = true;
  30736. }
  30737. return this._nativeConstraint.AppliedImpulse;
  30738. }
  30739. get connectedBody() {
  30740. return this._connectedBody;
  30741. }
  30742. set connectedBody(value) {
  30743. this._connectedBody = value;
  30744. }
  30745. _onDestroy() {
  30746. var physics3D = Physics3D._physics3D;
  30747. physics3D.destroy(this._nativeConstraint);
  30748. this._nativeConstraint = null;
  30749. }
  30750. }
  30751. class Point2PointConstraint {
  30752. constructor() {
  30753. this._pivotInA = new Vector3();
  30754. this._pivotInB = new Vector3();
  30755. }
  30756. get pivotInA() {
  30757. return this._pivotInA;
  30758. }
  30759. set pivotInA(value) {
  30760. this._pivotInA = value;
  30761. }
  30762. get pivotInB() {
  30763. return this._pivotInB;
  30764. }
  30765. set pivotInB(value) {
  30766. this._pivotInB = value;
  30767. }
  30768. get damping() {
  30769. return this._damping;
  30770. }
  30771. set damping(value) {
  30772. this._damping = value;
  30773. }
  30774. get impulseClamp() {
  30775. return this._impulseClamp;
  30776. }
  30777. set impulseClamp(value) {
  30778. this._impulseClamp = value;
  30779. }
  30780. get tau() {
  30781. return this._tau;
  30782. }
  30783. set tau(value) {
  30784. this._tau = value;
  30785. }
  30786. }
  30787. class HeightfieldColliderShape {
  30788. constructor() {
  30789. }
  30790. }
  30791. class TextMesh {
  30792. get text() {
  30793. return this._text;
  30794. }
  30795. set text(value) {
  30796. this._text = value;
  30797. }
  30798. get fontSize() {
  30799. return this._fontSize;
  30800. }
  30801. set fontSize(value) {
  30802. this._fontSize = value;
  30803. }
  30804. get color() {
  30805. return this._color;
  30806. }
  30807. set color(value) {
  30808. this._color = value;
  30809. }
  30810. constructor() {
  30811. }
  30812. _createVertexBuffer(charCount) {
  30813. }
  30814. _resizeVertexBuffer(charCount) {
  30815. }
  30816. _addChar() {
  30817. }
  30818. }
  30819. class Size {
  30820. constructor(width, height) {
  30821. this._width = 0;
  30822. this._height = 0;
  30823. this._width = width;
  30824. this._height = height;
  30825. }
  30826. static get fullScreen() {
  30827. return new Size(-1, -1);
  30828. }
  30829. get width() {
  30830. if (this._width === -1)
  30831. return RenderContext3D.clientWidth;
  30832. return this._width;
  30833. }
  30834. get height() {
  30835. if (this._height === -1)
  30836. return RenderContext3D.clientHeight;
  30837. return this._height;
  30838. }
  30839. }
  30840. exports.AnimationClip = AnimationClip;
  30841. exports.AnimationClipParser03 = AnimationClipParser03;
  30842. exports.AnimationClipParser04 = AnimationClipParser04;
  30843. exports.AnimationEvent = AnimationEvent;
  30844. exports.AnimationNode = AnimationNode;
  30845. exports.AnimationTransform3D = AnimationTransform3D;
  30846. exports.Animator = Animator;
  30847. exports.AnimatorControllerLayer = AnimatorControllerLayer;
  30848. exports.AnimatorPlayState = AnimatorPlayState;
  30849. exports.AnimatorState = AnimatorState;
  30850. exports.AnimatorStateScript = AnimatorStateScript;
  30851. exports.Avatar = Avatar;
  30852. exports.BaseCamera = BaseCamera;
  30853. exports.BaseMaterial = BaseMaterial;
  30854. exports.BaseRender = BaseRender;
  30855. exports.BaseShape = BaseShape;
  30856. exports.BatchMark = BatchMark;
  30857. exports.BlinnPhongMaterial = BlinnPhongMaterial;
  30858. exports.BlitScreenQuadCMD = BlitScreenQuadCMD;
  30859. exports.BloomEffect = BloomEffect;
  30860. exports.BoundBox = BoundBox;
  30861. exports.BoundFrustum = BoundFrustum;
  30862. exports.BoundSphere = BoundSphere;
  30863. exports.Bounds = Bounds;
  30864. exports.BoundsOctree = BoundsOctree;
  30865. exports.BoundsOctreeNode = BoundsOctreeNode;
  30866. exports.BoxColliderShape = BoxColliderShape;
  30867. exports.BoxShape = BoxShape;
  30868. exports.BufferState = BufferState;
  30869. exports.Burst = Burst;
  30870. exports.Camera = Camera;
  30871. exports.CapsuleColliderShape = CapsuleColliderShape;
  30872. exports.CastShadowList = CastShadowList;
  30873. exports.CharacterController = CharacterController;
  30874. exports.CircleShape = CircleShape;
  30875. exports.ColliderShape = ColliderShape;
  30876. exports.Collision = Collision;
  30877. exports.CollisionTool = CollisionTool;
  30878. exports.CollisionUtils = CollisionUtils;
  30879. exports.Color = Color;
  30880. exports.ColorOverLifetime = ColorOverLifetime;
  30881. exports.Command = Command;
  30882. exports.CommandBuffer = CommandBuffer;
  30883. exports.CompoundColliderShape = CompoundColliderShape;
  30884. exports.ConchQuaternion = ConchQuaternion;
  30885. exports.ConchVector3 = ConchVector3;
  30886. exports.ConchVector4 = ConchVector4;
  30887. exports.ConeColliderShape = ConeColliderShape;
  30888. exports.ConeShape = ConeShape;
  30889. exports.Config3D = Config3D;
  30890. exports.Constraint3D = Constraint3D;
  30891. exports.ConstraintComponent = ConstraintComponent;
  30892. exports.ContactPoint = ContactPoint;
  30893. exports.ContainmentType = ContainmentType;
  30894. exports.CylinderColliderShape = CylinderColliderShape;
  30895. exports.DefineDatas = DefineDatas;
  30896. exports.DirectionLight = DirectionLight;
  30897. exports.DynamicBatchManager = DynamicBatchManager;
  30898. exports.EffectMaterial = EffectMaterial;
  30899. exports.Emission = Emission;
  30900. exports.ExtendTerrainMaterial = ExtendTerrainMaterial;
  30901. exports.FloatKeyframe = FloatKeyframe;
  30902. exports.FrameOverTime = FrameOverTime;
  30903. exports.FrustumCulling = FrustumCulling;
  30904. exports.GeometryElement = GeometryElement;
  30905. exports.Gradient = Gradient;
  30906. exports.GradientAngularVelocity = GradientAngularVelocity;
  30907. exports.GradientColor = GradientColor;
  30908. exports.GradientDataInt = GradientDataInt;
  30909. exports.GradientDataNumber = GradientDataNumber;
  30910. exports.GradientDataVector2 = GradientDataVector2;
  30911. exports.GradientMode = GradientMode;
  30912. exports.GradientSize = GradientSize;
  30913. exports.GradientVelocity = GradientVelocity;
  30914. exports.HalfFloatUtils = HalfFloatUtils;
  30915. exports.HeightMap = HeightMap;
  30916. exports.HeightfieldColliderShape = HeightfieldColliderShape;
  30917. exports.HemisphereShape = HemisphereShape;
  30918. exports.HitResult = HitResult;
  30919. exports.ILaya3D = ILaya3D;
  30920. exports.IndexBuffer3D = IndexBuffer3D;
  30921. exports.Input3D = Input3D;
  30922. exports.Keyframe = Keyframe;
  30923. exports.KeyframeNode = KeyframeNode;
  30924. exports.KeyframeNodeList = KeyframeNodeList;
  30925. exports.KeyframeNodeOwner = KeyframeNodeOwner;
  30926. exports.Laya3D = Laya3D;
  30927. exports.LightSprite = LightSprite;
  30928. exports.LoadModelV04 = LoadModelV04;
  30929. exports.LoadModelV05 = LoadModelV05;
  30930. exports.MathUtils3D = MathUtils3D;
  30931. exports.Matrix3x3 = Matrix3x3;
  30932. exports.Matrix4x4 = Matrix4x4;
  30933. exports.Mesh = Mesh;
  30934. exports.MeshColliderShape = MeshColliderShape;
  30935. exports.MeshFilter = MeshFilter;
  30936. exports.MeshReader = MeshReader;
  30937. exports.MeshRenderDynamicBatchManager = MeshRenderDynamicBatchManager;
  30938. exports.MeshRenderStaticBatchManager = MeshRenderStaticBatchManager;
  30939. exports.MeshRenderer = MeshRenderer;
  30940. exports.MeshSprite3D = MeshSprite3D;
  30941. exports.MeshSprite3DShaderDeclaration = MeshSprite3DShaderDeclaration;
  30942. exports.MeshTerrainSprite3D = MeshTerrainSprite3D;
  30943. exports.MouseTouch = MouseTouch;
  30944. exports.OctreeMotionList = OctreeMotionList;
  30945. exports.PBRSpecularMaterial = PBRSpecularMaterial;
  30946. exports.PBRStandardMaterial = PBRStandardMaterial;
  30947. exports.ParallelSplitShadowMap = ParallelSplitShadowMap;
  30948. exports.Physics3D = Physics3D;
  30949. exports.Physics3DUtils = Physics3DUtils;
  30950. exports.PhysicsCollider = PhysicsCollider;
  30951. exports.PhysicsComponent = PhysicsComponent;
  30952. exports.PhysicsSettings = PhysicsSettings;
  30953. exports.PhysicsSimulation = PhysicsSimulation;
  30954. exports.PhysicsTriggerComponent = PhysicsTriggerComponent;
  30955. exports.PhysicsUpdateList = PhysicsUpdateList;
  30956. exports.Picker = Picker;
  30957. exports.PixelLineData = PixelLineData;
  30958. exports.PixelLineFilter = PixelLineFilter;
  30959. exports.PixelLineMaterial = PixelLineMaterial;
  30960. exports.PixelLineRenderer = PixelLineRenderer;
  30961. exports.PixelLineSprite3D = PixelLineSprite3D;
  30962. exports.PixelLineVertex = PixelLineVertex;
  30963. exports.Plane = Plane;
  30964. exports.Point2PointConstraint = Point2PointConstraint;
  30965. exports.PointLight = PointLight;
  30966. exports.PostProcess = PostProcess;
  30967. exports.PostProcessEffect = PostProcessEffect;
  30968. exports.PostProcessRenderContext = PostProcessRenderContext;
  30969. exports.PrimitiveMesh = PrimitiveMesh;
  30970. exports.Quaternion = Quaternion;
  30971. exports.QuaternionKeyframe = QuaternionKeyframe;
  30972. exports.Rand = Rand;
  30973. exports.RandX = RandX;
  30974. exports.Ray = Ray;
  30975. exports.RenderContext3D = RenderContext3D;
  30976. exports.RenderElement = RenderElement;
  30977. exports.RenderQueue = RenderQueue;
  30978. exports.RenderState = RenderState;
  30979. exports.RenderTexture = RenderTexture;
  30980. exports.RenderableSprite3D = RenderableSprite3D;
  30981. exports.Rigidbody3D = Rigidbody3D;
  30982. exports.RotationOverLifetime = RotationOverLifetime;
  30983. exports.Scene3D = Scene3D;
  30984. exports.Scene3DShaderDeclaration = Scene3DShaderDeclaration;
  30985. exports.Scene3DUtils = Scene3DUtils;
  30986. exports.SceneManager = SceneManager;
  30987. exports.ScreenQuad = ScreenQuad;
  30988. exports.ScreenTriangle = ScreenTriangle;
  30989. exports.Script3D = Script3D;
  30990. exports.SetRenderTargetCMD = SetRenderTargetCMD;
  30991. exports.SetShaderDataTextureCMD = SetShaderDataTextureCMD;
  30992. exports.Shader3D = Shader3D;
  30993. exports.ShaderData = ShaderData;
  30994. exports.ShaderDefines = ShaderDefines;
  30995. exports.ShaderInit3D = ShaderInit3D;
  30996. exports.ShaderInstance = ShaderInstance;
  30997. exports.ShaderPass = ShaderPass;
  30998. exports.ShaderVariable = ShaderVariable;
  30999. exports.ShapeUtils = ShapeUtils;
  31000. exports.ShuriKenParticle3D = ShuriKenParticle3D;
  31001. exports.ShuriKenParticle3DShaderDeclaration = ShuriKenParticle3DShaderDeclaration;
  31002. exports.ShurikenParticleData = ShurikenParticleData;
  31003. exports.ShurikenParticleMaterial = ShurikenParticleMaterial;
  31004. exports.ShurikenParticleRenderer = ShurikenParticleRenderer;
  31005. exports.ShurikenParticleSystem = ShurikenParticleSystem;
  31006. exports.SimpleSingletonList = SimpleSingletonList;
  31007. exports.SingletonList = SingletonList;
  31008. exports.Size = Size;
  31009. exports.SizeOverLifetime = SizeOverLifetime;
  31010. exports.SkinnedMeshRenderer = SkinnedMeshRenderer;
  31011. exports.SkinnedMeshSprite3D = SkinnedMeshSprite3D;
  31012. exports.SkinnedMeshSprite3DShaderDeclaration = SkinnedMeshSprite3DShaderDeclaration;
  31013. exports.SkyBox = SkyBox;
  31014. exports.SkyBoxMaterial = SkyBoxMaterial;
  31015. exports.SkyDome = SkyDome;
  31016. exports.SkyMesh = SkyMesh;
  31017. exports.SkyProceduralMaterial = SkyProceduralMaterial;
  31018. exports.SkyRenderer = SkyRenderer;
  31019. exports.SphereColliderShape = SphereColliderShape;
  31020. exports.SphereShape = SphereShape;
  31021. exports.SpotLight = SpotLight;
  31022. exports.Sprite3D = Sprite3D;
  31023. exports.StartFrame = StartFrame;
  31024. exports.StaticBatchManager = StaticBatchManager;
  31025. exports.StaticPlaneColliderShape = StaticPlaneColliderShape;
  31026. exports.SubMesh = SubMesh;
  31027. exports.SubMeshDynamicBatch = SubMeshDynamicBatch;
  31028. exports.SubMeshInstanceBatch = SubMeshInstanceBatch;
  31029. exports.SubMeshRenderElement = SubMeshRenderElement;
  31030. exports.SubMeshStaticBatch = SubMeshStaticBatch;
  31031. exports.SubShader = SubShader;
  31032. exports.TextMesh = TextMesh;
  31033. exports.TextureCube = TextureCube;
  31034. exports.TextureGenerator = TextureGenerator;
  31035. exports.TextureMode = TextureMode;
  31036. exports.TextureSheetAnimation = TextureSheetAnimation;
  31037. exports.Touch = Touch;
  31038. exports.TrailFilter = TrailFilter;
  31039. exports.TrailGeometry = TrailGeometry;
  31040. exports.TrailMaterial = TrailMaterial;
  31041. exports.TrailRenderer = TrailRenderer;
  31042. exports.TrailSprite3D = TrailSprite3D;
  31043. exports.Transform3D = Transform3D;
  31044. exports.UnlitMaterial = UnlitMaterial;
  31045. exports.Utils3D = Utils3D;
  31046. exports.Vector2 = Vector2;
  31047. exports.Vector3 = Vector3;
  31048. exports.Vector3Keyframe = Vector3Keyframe;
  31049. exports.Vector4 = Vector4;
  31050. exports.VelocityOverLifetime = VelocityOverLifetime;
  31051. exports.VertexBuffer3D = VertexBuffer3D;
  31052. exports.VertexDeclaration = VertexDeclaration;
  31053. exports.VertexElement = VertexElement;
  31054. exports.VertexElementFormat = VertexElementFormat;
  31055. exports.VertexMesh = VertexMesh;
  31056. exports.VertexPositionTerrain = VertexPositionTerrain;
  31057. exports.VertexPositionTexture0 = VertexPositionTexture0;
  31058. exports.VertexShuriKenParticle = VertexShuriKenParticle;
  31059. exports.VertexShurikenParticleBillboard = VertexShurikenParticleBillboard;
  31060. exports.VertexShurikenParticleMesh = VertexShurikenParticleMesh;
  31061. exports.VertexTrail = VertexTrail;
  31062. exports.Viewport = Viewport;
  31063. exports.WaterPrimaryMaterial = WaterPrimaryMaterial;
  31064. }(window.Laya = window.Laya|| {}, Laya));